1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | // Include language advices |
---|
5 | load_language('plugin.lang', CF_PATH); |
---|
6 | |
---|
7 | /** |
---|
8 | * Include class file |
---|
9 | * @param $aClassName |
---|
10 | */ |
---|
11 | function cf_require_class($aClassName) { |
---|
12 | require_once CF_CLASSES .strtolower($aClassName) . '.class.php'; |
---|
13 | } |
---|
14 | |
---|
15 | include_once(PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'); |
---|
16 | |
---|
17 | function cf_switch_to_default_lang() { |
---|
18 | global $switch_lang,$user; |
---|
19 | if (!isset($switch_lang['stack']) or |
---|
20 | !in_array($user['language'], $switch_lang['stack'])) { |
---|
21 | $switch_lang['stack'][] = $user['language']; |
---|
22 | } |
---|
23 | switch_lang_to(get_default_language()); |
---|
24 | // Include language advices |
---|
25 | load_language('plugin.lang', CF_PATH); |
---|
26 | } |
---|
27 | function cf_switch_back_to_user_lang() { |
---|
28 | switch_lang_back(); |
---|
29 | } |
---|
30 | function cf_validate_mail_format($email) { |
---|
31 | $atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; // before arobase |
---|
32 | $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name |
---|
33 | $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*'; |
---|
34 | $regex .= '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i'; |
---|
35 | if ( !preg_match( $regex, $email ) ) { |
---|
36 | return l10n('cf_mail_format_error'); |
---|
37 | } |
---|
38 | return null; |
---|
39 | } |
---|
40 | |
---|
41 | function cf_get_admins_emails($webmaster_email) { |
---|
42 | global $conf, $user; |
---|
43 | $admins = array(); |
---|
44 | |
---|
45 | $query = ' |
---|
46 | select |
---|
47 | U.'.$conf['user_fields']['username'].' as username, |
---|
48 | U.'.$conf['user_fields']['email'].' as mail_address |
---|
49 | from |
---|
50 | '.USERS_TABLE.' as U, |
---|
51 | '.USER_INFOS_TABLE.' as I |
---|
52 | where |
---|
53 | I.user_id = U.'.$conf['user_fields']['id'].' and |
---|
54 | I.status in (\'webmaster\', \'admin\') and |
---|
55 | '.$conf['user_fields']['email'].' is not null and |
---|
56 | I.user_id <> '.$user['id'].' |
---|
57 | order by |
---|
58 | username |
---|
59 | '; |
---|
60 | |
---|
61 | $datas = pwg_query($query); |
---|
62 | if (!empty($datas)) { |
---|
63 | while ($admin = mysql_fetch_array($datas)) { |
---|
64 | if (!empty($admin['mail_address']) and |
---|
65 | (0!=strcasecmp($admin['mail_address'], $webmaster_email))) { |
---|
66 | array_push( $admins, |
---|
67 | format_email($admin['username'], $admin['mail_address']) |
---|
68 | ); |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | return $admins; |
---|
73 | } |
---|
74 | |
---|
75 | function cf_get_admins_contacts() { |
---|
76 | global $conf, $user; |
---|
77 | $admins = array(); |
---|
78 | |
---|
79 | $query = ' |
---|
80 | select |
---|
81 | U.'.$conf['user_fields']['username'].' as username, |
---|
82 | U.'.$conf['user_fields']['email'].' as mail_address |
---|
83 | from |
---|
84 | '.USERS_TABLE.' as U, |
---|
85 | '.USER_INFOS_TABLE.' as I |
---|
86 | where |
---|
87 | I.user_id = U.'.$conf['user_fields']['id'].' and |
---|
88 | I.status in (\'webmaster\', \'admin\') and |
---|
89 | '.$conf['user_fields']['email'].' is not null |
---|
90 | order by |
---|
91 | username |
---|
92 | '; |
---|
93 | |
---|
94 | $webmaster_mail = get_webmaster_mail_address(); |
---|
95 | $datas = pwg_query($query); |
---|
96 | if (!empty($datas)) { |
---|
97 | while ($admin = mysql_fetch_array($datas)) { |
---|
98 | if (!empty($admin['mail_address'])) { |
---|
99 | $name = $admin['username']; |
---|
100 | $webmaster = 0; |
---|
101 | if (0 == strcasecmp($webmaster_mail, $admin['mail_address'])) { |
---|
102 | $name = l10n('Webmaster'); |
---|
103 | $webmaster = 1; |
---|
104 | } |
---|
105 | $admins[$admin['mail_address']] = array( |
---|
106 | 'NAME' => $name, |
---|
107 | 'EMAILSTR' => format_email($name, |
---|
108 | $admin['mail_address']), |
---|
109 | 'ACTIVE' => 1, |
---|
110 | 'WEBMASTER'=> $webmaster, |
---|
111 | ); |
---|
112 | } |
---|
113 | } |
---|
114 | } |
---|
115 | return $admins; |
---|
116 | |
---|
117 | } |
---|
118 | |
---|
119 | /* Return template for user template/theme */ |
---|
120 | function cf_get_template($file, $dir=CF_TEMPLATE, $prefix='') { |
---|
121 | global $user, $template; |
---|
122 | |
---|
123 | $theme_file = $dir. |
---|
124 | //$user[$prefix.'template'].'/'. |
---|
125 | $user['theme'].'/'. |
---|
126 | $file; |
---|
127 | $template_file = $dir. |
---|
128 | //$user[$prefix.'template'].'/'. |
---|
129 | $file; |
---|
130 | |
---|
131 | if (file_exists($theme_file)) |
---|
132 | { |
---|
133 | return $theme_file; |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | return $dir.$file; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | function contactForm_prefilter($content, &$smarty) { |
---|
142 | $search = '#{if\s+isset\s*\(\s*\$CONTACT_MAIL\s*\)\s*}.*?{/if}#s'; |
---|
143 | $replacement = '{if isset($ContactFormLink)}{$ContactFormLink}{/if}'; |
---|
144 | |
---|
145 | return preg_replace($search, $replacement, $content); |
---|
146 | } |
---|
147 | |
---|
148 | function cf_clean_obsolete_files($obsolete_file_list) { |
---|
149 | if (!file_exists(CF_PATH.$obsolete_file_list)) { |
---|
150 | return TRUE; |
---|
151 | } |
---|
152 | $obsolete = file(CF_PATH.$obsolete_file_list); |
---|
153 | array_push($obsolete, $obsolete_file_list); |
---|
154 | return cf_clean_obsolete_list($obsolete); |
---|
155 | } |
---|
156 | |
---|
157 | function cf_clean_obsolete_list($file_list = array(), &$errors = array()) { |
---|
158 | // Include language advices |
---|
159 | load_language('plugin.lang', CF_PATH); |
---|
160 | |
---|
161 | if (!function_exists('unlink')) { |
---|
162 | // No unlink available... |
---|
163 | array_push($errors, l10n('cf_no_unlink')); |
---|
164 | return FALSE; |
---|
165 | } |
---|
166 | $success = TRUE; |
---|
167 | foreach ($file_list as $file) { |
---|
168 | $file = CF_PATH . $file; |
---|
169 | if (file_exists($file)) { |
---|
170 | // Remove obsolete file |
---|
171 | $success &= unlink($file); |
---|
172 | } |
---|
173 | } |
---|
174 | if (!$success) { |
---|
175 | array_push($errors, l10n('cf_unlink_errors')); |
---|
176 | } |
---|
177 | return $success; |
---|
178 | } |
---|
179 | |
---|
180 | function cf_format_date($year, $month, $day, $format='%M %D, %Y') { |
---|
181 | $format = str_ireplace('%Y', $year, $format); |
---|
182 | $format = str_ireplace('%M', $month, $format); |
---|
183 | $format = str_ireplace('%D', $day, $format); |
---|
184 | return $format; |
---|
185 | } |
---|
186 | |
---|
187 | ?> |
---|