X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=plugins%2Fbug_report%2Ffunctions.php;h=5b4626da9ffdcd5cae9904dffb6449cc9d60e8b2;hp=a560ae4c424b94436298824232f334e9a425850a;hb=c4faef335b2362c81b8ebf026d4066c12d70536c;hpb=6c84ba1ec45ab854c37b6f65c5b4d84ab1c7aad4 diff --git a/plugins/bug_report/functions.php b/plugins/bug_report/functions.php index a560ae4c..5b4626da 100644 --- a/plugins/bug_report/functions.php +++ b/plugins/bug_report/functions.php @@ -2,127 +2,150 @@ /** * functions for bug_report plugin * - * functions/forms.php and functions/html.php have to be loaded before including this file. - * - * @copyright (c) 2004-2005 The SquirrelMail Project Team + * @copyright 2004-2020 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package plugins * @subpackage bug_report */ + +/** + * Initializes the Bug Report plugin + * + * @return boolean FALSE if the plugin is not correctly configured + * or an error in its setup is found; TRUE otherwise + * + * @since 1.5.2 + * + */ +function bug_report_init() { + + // Declare plugin configuration vars + // + global $bug_report_admin_email, $bug_report_allow_users; + + // Load default config + // + if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) { + include_once (SM_PATH . 'plugins/bug_report/config_default.php'); + } else { + // default config was removed. + $bug_report_admin_email = ''; + $bug_report_allow_users = false; + } + + // Load site config + // + if (file_exists(SM_PATH . 'config/bug_report_config.php')) { + include_once (SM_PATH . 'config/bug_report_config.php'); + } elseif (file_exists(SM_PATH . 'plugins/bug_report/config.php')) { + include_once (SM_PATH . 'plugins/bug_report/config.php'); + } + +} + + +/** + * Checks if user can use bug_report plugin + * + * @return boolean + * + * @since 1.5.1 + * + */ +function bug_report_check_user() { + global $username, $bug_report_allow_users, $bug_report_admin_email; + + bug_report_init(); + + if (file_exists(SM_PATH . 'plugins/bug_report/admins')) { + $auths = file(SM_PATH . 'plugins/bug_report/admins'); + array_walk($auths, 'bug_report_array_trim'); + $auth = in_array($username, $auths); + } else if (file_exists(SM_PATH . 'config/admins')) { + $auths = file(SM_PATH . 'config/admins'); + array_walk($auths, 'bug_report_array_trim'); + $auth = in_array($username, $auths); + } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) && + function_exists('posix_getpwuid')) { + $adm = posix_getpwuid( $adm_id ); + $auth = ($username == $adm['name']); + } else { + $auth = false; + } + + if (! empty($bug_report_admin_email) && $bug_report_allow_users) { + $auth = true; + } + + return ($auth); +} + + +/** + * Removes whitespace from array values + * + * @param string $value array value that has to be trimmed + * @param string $key array key + * + * @since 1.5.1 + * + * @todo code reuse. create generic sm function. + * + * @access private + * + */ +function bug_report_array_trim(&$value,$key) { + $value = trim($value); +} + + /** - * Creates gmane search form + * Show the button in the main bar + * + * @access private * - * Requires html v.4.0 compatible browser - * @return string html formated form */ -function add_gmane_form() { - // Start form (need target="_blank" element) - $ret=addForm('http://search.gmane.org/search.php','get','mform'); - - // Add visible options - $ret.=html_tag('table', - html_tag('tr', - html_tag('td',_("Search for words:"),'right') . - html_tag('td',addInput('query','',50),'left') - ) . - html_tag('tr', - html_tag('td',_("Written by:") . '
' . - '' . _("Email addresses only") . '','right') . - html_tag('td',addInput('email','',40),'left') - ) . - html_tag('tr', - html_tag('td',_("Mailing list:"),'right') . - html_tag('td',addSelect('group',array('gmane.mail.squirrelmail.user' - => _("SquirrelMail users list"), - 'gmane.mail.squirrelmail.plugins' - => _("SquirrelMail plugins list"), - 'gmane.mail.squirrelmail.devel' - => _("SquirrelMail developers list"), - 'gmane.mail.squirrelmail.internationalization' - => _("SquirrelMail internationalization list")) - ,'gmane.mail.squirrelmail.user',true),'left') - ) . - html_tag('tr', - html_tag('td',_("Sort by:"),'right') . - html_tag('td',addSelect('sort',array('date' => _("Date"), - 'relevance' => _("Relevance")) - ,'date',true),'left') - ) . - html_tag('tr', - html_tag('td', - '\n" . - '\n" - ,'center','','colspan="2"') - ), - 'center'); - - // Close form - $ret.="\n"; - - // Return form - return $ret; +function bug_report_button_do() { + global $username, $data_dir; + $bug_report_visible = getPref($data_dir, $username, 'bug_report_visible', FALSE); + + if (! $bug_report_visible || ! bug_report_check_user()) { + return; + } + + global $oTemplate, $nbsp; + $output = makeInternalLink('plugins/bug_report/bug_report.php', _("Bug"), '') + . $nbsp . $nbsp; + return array('menuline' => $output); } + /** - * Creates SquirrelMail SF bugtracker search form + * Register bug report option block + * + * @since 1.5.1 + * + * @access private * - * Requires html v.4.0 compatible browser - * @return string html formated form */ -function add_sf_bug_form() { - // Start form - $ret=addForm('http://sourceforge.net/tracker/index.php','post'); - - // Add hidden options (some input fields are hidden from end user) - $ret.=addHidden('group_id','311') . - addHidden('atid','100311') . - addHidden('set','custom') . - addHidden('_assigned_to','0') . - addHidden('_status','100') . - addHidden('_category','100') . - addHidden('_group','100') . - addHidden('by_submitter',''); - - // Add visible input fields and buttons - $ret.=html_tag('table', - html_tag('tr', - html_tag('td',_("Summary keyword:"),'right') . - html_tag('td',addInput('summary_keyword','',20,80),'left') - ) . - html_tag('tr', - html_tag('td',_("Sort By:"),'right') . - html_tag('td', - addSelect('order',array('artifact_id' => _("ID"), - 'priority' => _("Priority"), - 'summary' => _("Summary"), - 'open_date' => _("Open Date"), - 'close_date' => _("Close Date"), - 'submitted_by' => _("Submitter"), - 'assigned_to' => _("Assignee")), - 'artifact_id',true),'left') - ) . - html_tag('tr', - html_tag('td',_("Order:"),'right') . - html_tag('td', - addSelect('sort',array('ASC'=>_("Ascending"), - 'DESC'=>_("Descending")), - 'DESC',true), - 'left') - ) . - html_tag('tr', - html_tag('td', - '\n" . - '\n" - ,'center','','colspan="2"') - ) - ,'center'); - - // Close form - $ret.="\n"; - - // Return form - return $ret; +function bug_report_block_do() { + if (bug_report_check_user()) { + global $username, $data_dir, $optpage_data, $bug_report_visible; + $bug_report_visible = getPref($data_dir, $username, 'bug_report_visible', FALSE); + $optpage_data['grps']['bug_report'] = _("Bug Reports"); + $optionValues = array(); +// FIXME: option needs refresh in SMOPT_REFRESH_RIGHT (menulinks are built before options are saved/loaded) + $optionValues[] = array( + 'name' => 'bug_report_visible', + 'caption' => _("Show button in toolbar"), + 'type' => SMOPT_TYPE_BOOLEAN, + 'refresh' => SMOPT_REFRESH_ALL, + 'initial_value' => false + ); + $optpage_data['vals']['bug_report'] = $optionValues; + } } -?> + +