functions.php 2.5 KB

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