1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | /** |
---|
5 | * Include class file |
---|
6 | * @param $aClassName |
---|
7 | */ |
---|
8 | function cf_require_class($aClassName) { |
---|
9 | require_once CF_CLASSES .strtolower($aClassName) . '.class.php'; |
---|
10 | } |
---|
11 | |
---|
12 | include_once(PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'); |
---|
13 | |
---|
14 | function cf_switch_to_default_lang() { |
---|
15 | global $switch_lang,$user; |
---|
16 | if (!isset($switch_lang['stack']) or |
---|
17 | !in_array($user['language'], $switch_lang['stack'])) { |
---|
18 | $switch_lang['stack'][] = $user['language']; |
---|
19 | } |
---|
20 | switch_lang_to(get_default_language()); |
---|
21 | // Include language advices |
---|
22 | load_language('plugin.lang', CF_PATH); |
---|
23 | } |
---|
24 | function cf_switch_back_to_user_lang() { |
---|
25 | switch_lang_back(); |
---|
26 | } |
---|
27 | function cf_validate_mail_format($email) { |
---|
28 | $atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; // before arobase |
---|
29 | $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name |
---|
30 | $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*'; |
---|
31 | $regex .= '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i'; |
---|
32 | if ( !preg_match( $regex, $email ) ) { |
---|
33 | return l10n('cf_mail_format_error'); |
---|
34 | } |
---|
35 | return null; |
---|
36 | } |
---|
37 | |
---|
38 | function cf_get_admins_emails($webmaster_email) { |
---|
39 | global $conf, $user; |
---|
40 | $admins = array(); |
---|
41 | |
---|
42 | $query = ' |
---|
43 | select |
---|
44 | U.'.$conf['user_fields']['username'].' as username, |
---|
45 | U.'.$conf['user_fields']['email'].' as mail_address |
---|
46 | from |
---|
47 | '.USERS_TABLE.' as U, |
---|
48 | '.USER_INFOS_TABLE.' as I |
---|
49 | where |
---|
50 | I.user_id = U.'.$conf['user_fields']['id'].' and |
---|
51 | I.status in (\'webmaster\', \'admin\') and |
---|
52 | I.adviser = \'false\' and |
---|
53 | '.$conf['user_fields']['email'].' is not null and |
---|
54 | I.user_id <> '.$user['id'].' |
---|
55 | order by |
---|
56 | username |
---|
57 | '; |
---|
58 | |
---|
59 | $datas = pwg_query($query); |
---|
60 | if (!empty($datas)) { |
---|
61 | while ($admin = mysql_fetch_array($datas)) { |
---|
62 | if (!empty($admin['mail_address']) and |
---|
63 | (0!=strcasecmp($admin['mail_address'], $webmaster_email))) { |
---|
64 | array_push( $admins, |
---|
65 | format_email($admin['username'], $admin['mail_address']) |
---|
66 | ); |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | return $admins; |
---|
71 | } |
---|
72 | |
---|
73 | /* Return template for user template/theme*/ |
---|
74 | function cf_get_template($file, $dir=CF_TEMPLATE) { |
---|
75 | global $user, $template; |
---|
76 | |
---|
77 | $theme_file = $dir.$user['template'].'/'.$user['theme'].'/'.$file; |
---|
78 | $template_file = $dir.$user['template'].'/'.$file; |
---|
79 | |
---|
80 | if (file_exists($theme_file)) |
---|
81 | { |
---|
82 | return $theme_file; |
---|
83 | } |
---|
84 | elseif (file_exists($template_file)) |
---|
85 | { |
---|
86 | return $template_file; |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | return $dir.$file; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | function cf_clean_obsolete_files($obsolete_file_list) { |
---|
95 | if (!file_exists(CF_PATH.$obsolete_file_list)) { |
---|
96 | return TRUE; |
---|
97 | } |
---|
98 | $obsolete = file(CF_PATH.$obsolete_file_list); |
---|
99 | array_push($obsolete, $obsolete_file_list); |
---|
100 | return cf_clean_obsolete_list($obsolete); |
---|
101 | } |
---|
102 | |
---|
103 | function cf_clean_obsolete_list($file_list = array(), &$errors = array()) { |
---|
104 | // Include language advices |
---|
105 | load_language('plugin.lang', CF_PATH); |
---|
106 | |
---|
107 | if (!function_exists('unlink')) { |
---|
108 | // No unlink available... |
---|
109 | array_push($errors, l10n('cf_no_unlink')); |
---|
110 | return FALSE; |
---|
111 | } |
---|
112 | $success = TRUE; |
---|
113 | foreach ($file_list as $file) { |
---|
114 | $file = CF_PATH . $file; |
---|
115 | if (file_exists($file)) { |
---|
116 | // Remove obsolete file |
---|
117 | $success &= unlink($file); |
---|
118 | } |
---|
119 | } |
---|
120 | if (!$success) { |
---|
121 | array_push($errors, l10n('cf_unlink_errors')); |
---|
122 | } |
---|
123 | return $success; |
---|
124 | } |
---|
125 | |
---|
126 | ?> |
---|