Source for file functions.php

Documentation is available at functions.php

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

Documentation generated on Mon, 13 Jan 2020 04:22:33 +0100 by phpDocumentor 1.4.3