| 1 | <?php |
| 2 | /** |
| 3 | * functions for bug_report plugin |
| 4 | * |
| 5 | * @copyright 2004-2018 The SquirrelMail Project Team |
| 6 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 7 | * @version $Id$ |
| 8 | * @package plugins |
| 9 | * @subpackage bug_report |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | /** |
| 14 | * Initializes the Bug Report plugin |
| 15 | * |
| 16 | * @return boolean FALSE if the plugin is not correctly configured |
| 17 | * or an error in its setup is found; TRUE otherwise |
| 18 | * |
| 19 | * @since 1.5.2 |
| 20 | * |
| 21 | */ |
| 22 | function bug_report_init() { |
| 23 | |
| 24 | // Declare plugin configuration vars |
| 25 | // |
| 26 | global $bug_report_admin_email, $bug_report_allow_users; |
| 27 | |
| 28 | // Load default config |
| 29 | // |
| 30 | if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) { |
| 31 | include_once (SM_PATH . 'plugins/bug_report/config_default.php'); |
| 32 | } else { |
| 33 | // default config was removed. |
| 34 | $bug_report_admin_email = ''; |
| 35 | $bug_report_allow_users = false; |
| 36 | } |
| 37 | |
| 38 | // Load site config |
| 39 | // |
| 40 | if (file_exists(SM_PATH . 'config/bug_report_config.php')) { |
| 41 | include_once (SM_PATH . 'config/bug_report_config.php'); |
| 42 | } elseif (file_exists(SM_PATH . 'plugins/bug_report/config.php')) { |
| 43 | include_once (SM_PATH . 'plugins/bug_report/config.php'); |
| 44 | } |
| 45 | |
| 46 | } |
| 47 | |
| 48 | |
| 49 | /** |
| 50 | * Checks if user can use bug_report plugin |
| 51 | * |
| 52 | * @return boolean |
| 53 | * |
| 54 | * @since 1.5.1 |
| 55 | * |
| 56 | */ |
| 57 | function bug_report_check_user() { |
| 58 | global $username, $bug_report_allow_users, $bug_report_admin_email; |
| 59 | |
| 60 | bug_report_init(); |
| 61 | |
| 62 | if (file_exists(SM_PATH . 'plugins/bug_report/admins')) { |
| 63 | $auths = file(SM_PATH . 'plugins/bug_report/admins'); |
| 64 | array_walk($auths, 'bug_report_array_trim'); |
| 65 | $auth = in_array($username, $auths); |
| 66 | } else if (file_exists(SM_PATH . 'config/admins')) { |
| 67 | $auths = file(SM_PATH . 'config/admins'); |
| 68 | array_walk($auths, 'bug_report_array_trim'); |
| 69 | $auth = in_array($username, $auths); |
| 70 | } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) && |
| 71 | function_exists('posix_getpwuid')) { |
| 72 | $adm = posix_getpwuid( $adm_id ); |
| 73 | $auth = ($username == $adm['name']); |
| 74 | } else { |
| 75 | $auth = false; |
| 76 | } |
| 77 | |
| 78 | if (! empty($bug_report_admin_email) && $bug_report_allow_users) { |
| 79 | $auth = true; |
| 80 | } |
| 81 | |
| 82 | return ($auth); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | /** |
| 87 | * Removes whitespace from array values |
| 88 | * |
| 89 | * @param string $value array value that has to be trimmed |
| 90 | * @param string $key array key |
| 91 | * |
| 92 | * @since 1.5.1 |
| 93 | * |
| 94 | * @todo code reuse. create generic sm function. |
| 95 | * |
| 96 | * @access private |
| 97 | * |
| 98 | */ |
| 99 | function bug_report_array_trim(&$value,$key) { |
| 100 | $value = trim($value); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | * Show the button in the main bar |
| 106 | * |
| 107 | * @access private |
| 108 | * |
| 109 | */ |
| 110 | function bug_report_button_do() { |
| 111 | global $username, $data_dir; |
| 112 | $bug_report_visible = getPref($data_dir, $username, 'bug_report_visible', FALSE); |
| 113 | |
| 114 | if (! $bug_report_visible || ! bug_report_check_user()) { |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | global $oTemplate, $nbsp; |
| 119 | $output = makeInternalLink('plugins/bug_report/bug_report.php', _("Bug"), '') |
| 120 | . $nbsp . $nbsp; |
| 121 | return array('menuline' => $output); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | /** |
| 126 | * Register bug report option block |
| 127 | * |
| 128 | * @since 1.5.1 |
| 129 | * |
| 130 | * @access private |
| 131 | * |
| 132 | */ |
| 133 | function bug_report_block_do() { |
| 134 | if (bug_report_check_user()) { |
| 135 | global $username, $data_dir, $optpage_data, $bug_report_visible; |
| 136 | $bug_report_visible = getPref($data_dir, $username, 'bug_report_visible', FALSE); |
| 137 | $optpage_data['grps']['bug_report'] = _("Bug Reports"); |
| 138 | $optionValues = array(); |
| 139 | // FIXME: option needs refresh in SMOPT_REFRESH_RIGHT (menulinks are built before options are saved/loaded) |
| 140 | $optionValues[] = array( |
| 141 | 'name' => 'bug_report_visible', |
| 142 | 'caption' => _("Show button in toolbar"), |
| 143 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 144 | 'refresh' => SMOPT_REFRESH_ALL, |
| 145 | 'initial_value' => false |
| 146 | ); |
| 147 | $optpage_data['vals']['bug_report'] = $optionValues; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | |