t12n of fortune output
[squirrelmail.git] / plugins / bug_report / functions.php
1 <?php
2 /**
3 * functions for bug_report plugin
4 *
5 * @copyright &copy; 2004-2006 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 * do not allow to call this file directly
15 */
16 if ((isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) ||
17 (isset($HTTP_SERVER_SERVER['SCRIPT_FILENAME']) && $HTTP_SERVER_SERVER['SCRIPT_FILENAME'] == __FILE__) ) {
18 header("Location: ../../src/login.php");
19 die();
20 }
21
22 /** Declare plugin configuration vars */
23 global $bug_report_admin_email, $bug_report_allow_users;
24
25 /** Load default config */
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
34 /** Load site config */
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 * @return boolean
44 * @since 1.5.1
45 */
46 function bug_report_check_user() {
47 global $username, $bug_report_allow_users, $bug_report_admin_email;
48
49 if (file_exists(SM_PATH . 'plugins/bug_report/admins')) {
50 $auths = file(SM_PATH . 'plugins/bug_report/admins');
51 array_walk($auths, 'bug_report_array_trim');
52 $auth = in_array($username, $auths);
53 } else if (file_exists(SM_PATH . 'config/admins')) {
54 $auths = file(SM_PATH . 'config/admins');
55 array_walk($auths, 'bug_report_array_trim');
56 $auth = in_array($username, $auths);
57 } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) &&
58 function_exists('posix_getpwuid')) {
59 $adm = posix_getpwuid( $adm_id );
60 $auth = ($username == $adm['name']);
61 } else {
62 $auth = false;
63 }
64
65 if (! empty($bug_report_admin_email) && $bug_report_allow_users) {
66 $auth = true;
67 }
68
69 return ($auth);
70 }
71
72 /**
73 * Removes whitespace from array values
74 * @param string $value array value that has to be trimmed
75 * @param string $key array key
76 * @since 1.5.1
77 * @todo code reuse. create generic sm function.
78 * @access private
79 */
80 function bug_report_array_trim(&$value,$key) {
81 $value=trim($value);
82 }