functions.php 3.8 KB

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