functions.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * functions for bug_report plugin
  4. *
  5. * @copyright &copy; 2004-2007 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. * do not allow to call this file directly
  13. */
  14. if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) {
  15. header("Location: ../../src/login.php");
  16. die();
  17. }
  18. /** Declare plugin configuration vars */
  19. global $bug_report_admin_email, $bug_report_allow_users;
  20. /** Load default config */
  21. if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) {
  22. include_once (SM_PATH . 'plugins/bug_report/config_default.php');
  23. } else {
  24. // default config was removed.
  25. $bug_report_admin_email = '';
  26. $bug_report_allow_users = false;
  27. }
  28. /** Load site config */
  29. if (file_exists(SM_PATH . 'config/bug_report_config.php')) {
  30. include_once (SM_PATH . 'config/bug_report_config.php');
  31. } elseif (file_exists(SM_PATH . 'plugins/bug_report/config.php')) {
  32. include_once (SM_PATH . 'plugins/bug_report/config.php');
  33. }
  34. /**
  35. * Checks if user can use bug_report plugin
  36. * @return boolean
  37. * @since 1.5.1
  38. */
  39. function bug_report_check_user() {
  40. global $username, $bug_report_allow_users, $bug_report_admin_email;
  41. if (file_exists(SM_PATH . 'plugins/bug_report/admins')) {
  42. $auths = file(SM_PATH . 'plugins/bug_report/admins');
  43. array_walk($auths, 'bug_report_array_trim');
  44. $auth = in_array($username, $auths);
  45. } else if (file_exists(SM_PATH . 'config/admins')) {
  46. $auths = file(SM_PATH . 'config/admins');
  47. array_walk($auths, 'bug_report_array_trim');
  48. $auth = in_array($username, $auths);
  49. } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) &&
  50. function_exists('posix_getpwuid')) {
  51. $adm = posix_getpwuid( $adm_id );
  52. $auth = ($username == $adm['name']);
  53. } else {
  54. $auth = false;
  55. }
  56. if (! empty($bug_report_admin_email) && $bug_report_allow_users) {
  57. $auth = true;
  58. }
  59. return ($auth);
  60. }
  61. /**
  62. * Removes whitespace from array values
  63. * @param string $value array value that has to be trimmed
  64. * @param string $key array key
  65. * @since 1.5.1
  66. * @todo code reuse. create generic sm function.
  67. * @access private
  68. */
  69. function bug_report_array_trim(&$value,$key) {
  70. $value=trim($value);
  71. }