1 | <?php |
---|
2 | /***************************************************************\ |
---|
3 | * This is 'Not Evil Ads', a plugin for Dotclear 2 * |
---|
4 | * * |
---|
5 | * Copyright (c) 2007 * |
---|
6 | * Oleksandr Syenchuk and contributors. * |
---|
7 | * * |
---|
8 | * This is an open source software, distributed under the GNU * |
---|
9 | * General Public License (version 2) terms and conditions. * |
---|
10 | * * |
---|
11 | * You should have received a copy of the GNU General Public * |
---|
12 | * License along 'Not evil ads' (see COPYING.txt); * |
---|
13 | * if not, write to the Free Software Foundation, Inc., * |
---|
14 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
15 | \***************************************************************/ |
---|
16 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
17 | |
---|
18 | try |
---|
19 | { |
---|
20 | $fatal_error = false; |
---|
21 | $messages = array(); |
---|
22 | $default_tab = empty($_GET['tab']) ? false : html::escapeHTML($_GET['tab']); |
---|
23 | |
---|
24 | /* Initialisation |
---|
25 | --------------------------------------------------- */ |
---|
26 | |
---|
27 | // Vérification de l'installation |
---|
28 | /* |
---|
29 | $nea_Iversion = $core->getVersion('notEvilAds'); |
---|
30 | if (!$nea_Iversion) |
---|
31 | throw new Exception(__('Not Evil Ads is not installed. '. |
---|
32 | 'Please go to your dashboard to install this plugin.')); |
---|
33 | elseif ($core->plugins->moduleInfo('notEvilAds','version') |
---|
34 | != $core->getVersion('notEvilAds')) |
---|
35 | throw new Exception(__('Not Evil Ads settings must be updated. '. |
---|
36 | 'Please go to your dashboard to update settings.')); |
---|
37 | //*/ |
---|
38 | |
---|
39 | // Chargement |
---|
40 | include_once dirname(__FILE__).'/lib/class.notevilads.php'; |
---|
41 | $nea_settings = notEvilAds::loadSettings($core->blog->settings->get('nea_settings')); |
---|
42 | $nea_ads = notEvilAds::loadAds($core->blog->settings->get('nea_ads')); |
---|
43 | |
---|
44 | // Paramètres du plugin corrompus (mince alors) |
---|
45 | include_once dirname(__FILE__).'/functions.php'; |
---|
46 | if ($nea_settings === 'MISSING') |
---|
47 | { |
---|
48 | $fatal_error = true; |
---|
49 | nea_install($core->blog->settings,true); |
---|
50 | throw new Exception(__('A setting was missing.'). |
---|
51 | __('Please refresh this page to continue. This should be fixed now.')); |
---|
52 | } |
---|
53 | elseif ($nea_settings === 'CORRUPTED') |
---|
54 | { |
---|
55 | $fatal_error = true; |
---|
56 | nea_install($core->blog->settings,true); |
---|
57 | throw new Exception(__('Not Evil Ads settings were not installed or were corrupted.'). |
---|
58 | __('Please refresh this page to continue. This should be fixed now.')); |
---|
59 | } |
---|
60 | elseif ($nea_ads === 'CORRUPTED') |
---|
61 | { |
---|
62 | nea_install($core->blog->settings,true,'ads'); |
---|
63 | throw new Exception(__('Ads data were corrupted.'). |
---|
64 | __('Please refresh this page to continue. This should be fixed now.')); |
---|
65 | } |
---|
66 | |
---|
67 | /* Paramètres par défaut pour les formulaires |
---|
68 | --------------------------------------------------- */ |
---|
69 | |
---|
70 | // Pour l'ajout d'une nouvelle publicité |
---|
71 | if (empty($_REQUEST['edit'])) |
---|
72 | $nea_newad = array( |
---|
73 | 'title'=>__('Ads'), |
---|
74 | 'identifier'=>'', |
---|
75 | 'attr'=>'', |
---|
76 | 'htmlcode'=>'', |
---|
77 | 'nothome'=>$nea_settings['nothome'], |
---|
78 | 'notevil'=>true, |
---|
79 | 'notajax'=>false); |
---|
80 | |
---|
81 | // Pour l'édition d'une publicité existante |
---|
82 | else |
---|
83 | $nea_newad = array( |
---|
84 | 'title'=>$nea_ads[$_REQUEST['edit']]['title'], |
---|
85 | 'identifier'=>$nea_ads[$_REQUEST['edit']]['identifier'], |
---|
86 | 'attr'=>$nea_ads[$_REQUEST['edit']]['attr'], |
---|
87 | 'htmlcode'=>$nea_ads[$_REQUEST['edit']]['htmlcode'], |
---|
88 | 'nothome'=>$nea_ads[$_REQUEST['edit']]['nothome'], |
---|
89 | 'notevil'=>$nea_ads[$_REQUEST['edit']]['notevil'], |
---|
90 | 'notajax'=>$nea_ads[$_REQUEST['edit']]['notajax'], |
---|
91 | 'disable'=>$nea_ads[$_REQUEST['edit']]['disable']); |
---|
92 | |
---|
93 | // Rappeller les publicités séléctionnées |
---|
94 | if (empty($_POST['nea_selected'])) |
---|
95 | $nea_selected = array(); |
---|
96 | else |
---|
97 | $nea_selected = $_POST['nea_selected']; |
---|
98 | |
---|
99 | /* Réception des données depuis les formulaires |
---|
100 | --------------------------------------------------- */ |
---|
101 | |
---|
102 | // Mis à jour de la configuration |
---|
103 | if (isset($_POST['nea_action_config'])) |
---|
104 | { |
---|
105 | $nea_settings['default'] = empty($_POST['nea_default']) ? false : true; |
---|
106 | $nea_settings['nothome'] = empty($_POST['nea_nothome']) ? false : true; |
---|
107 | $nea_settings['notajax'] = empty($_POST['nea_nothome']) ? false : true; |
---|
108 | // $nea_settings['identifiers'] = $_POST['nea_identifiers']; |
---|
109 | $nea_settings['cookiename'] = $_POST['nea_cookiename']; |
---|
110 | $nea_settings['cookiedays'] = (int) $_POST['nea_cookiedays']; |
---|
111 | if (isset($_POST['nea_cookiepath'])) |
---|
112 | $nea_settings['cookiepath'] = $_POST['nea_cookiepath']; |
---|
113 | if (isset($_POST['nea_cookiedome'])) |
---|
114 | $nea_settings['cookiedome'] = $_POST['nea_cookiedome']; |
---|
115 | $nea_settings['easycookie'] = empty($_POST['nea_easycookie']) ? false : true; |
---|
116 | } |
---|
117 | |
---|
118 | // Édition ou ajout d'une nouvelle publicité |
---|
119 | elseif (isset($_POST['nea_action_add']) || isset($_POST['nea_action_edit'])) |
---|
120 | { |
---|
121 | $nea_newad['title'] = $_POST['nea_title']; |
---|
122 | $nea_newad['identifier'] = $_POST['nea_identifier']; |
---|
123 | $nea_newad['attr'] = $_POST['nea_attr']; |
---|
124 | $nea_newad['htmlcode'] = $_POST['nea_htmlcode']; |
---|
125 | $nea_newad['nothome'] = empty($_POST['nea_nothome']) ? false : true; |
---|
126 | $nea_newad['notevil'] = empty($_POST['nea_notevil']) ? false : true; |
---|
127 | $nea_newad['notajax'] = empty($_POST['nea_notajax']) ? false : true; |
---|
128 | } |
---|
129 | |
---|
130 | /* Traitement des requêtes |
---|
131 | --------------------------------------------------- */ |
---|
132 | |
---|
133 | $core->blog->settings->setNameSpace('notevilads'); |
---|
134 | |
---|
135 | // Mis à jour de la configuration |
---|
136 | if (isset($_POST['nea_action_config'])) |
---|
137 | { |
---|
138 | $default_tab = 'nea_config'; |
---|
139 | |
---|
140 | //if (!ereg('^[a-zA-Z0-9_-,]+$',$nea_settings['identifiers'])) |
---|
141 | // throw new Exception(__('Invalid format for ads identifiers')); |
---|
142 | |
---|
143 | $core->blog->settings->put('nea_settings',notEvilAds::storeSettings($nea_settings)); |
---|
144 | |
---|
145 | http::redirect($p_url.'&up=settings'); |
---|
146 | } |
---|
147 | |
---|
148 | // Création d'une nouvelle publicité |
---|
149 | elseif (isset($_POST['nea_action_add'])) |
---|
150 | { |
---|
151 | $default_tab = 'nea_edit'; |
---|
152 | |
---|
153 | if (empty($nea_newad['identifier'])) |
---|
154 | throw new Exception(__('Identifier required.')); |
---|
155 | |
---|
156 | if (!ereg('^[a-zA-Z0-9_-]+$',$nea_newad['identifier'])) |
---|
157 | throw new Exception(__('Invalid ad identifier format.')); |
---|
158 | |
---|
159 | if (empty($nea_newad['htmlcode'])) |
---|
160 | throw new Exception(__('HTML code required.')); |
---|
161 | |
---|
162 | if (isset($nea_ads[$nea_newad['identifier']])) |
---|
163 | throw new Exception(__('This identifier is already used.')); |
---|
164 | |
---|
165 | $nea_newad['disable'] = false; |
---|
166 | $nea_ads[$nea_newad['identifier']] = $nea_newad; |
---|
167 | $nea_settings['identifiers'] = notEvilAds::getUpdatedIdentifiers($nea_ads); |
---|
168 | $core->blog->settings->put('nea_ads',notEvilAds::storeAds($nea_ads)); |
---|
169 | $core->blog->settings->put('nea_settings',notEvilAds::storeSettings($nea_settings)); |
---|
170 | |
---|
171 | http::redirect($p_url.'&up=newad'); |
---|
172 | } |
---|
173 | |
---|
174 | // Édition d'une publicité existante |
---|
175 | elseif (isset($_POST['nea_action_edit']) && !empty($_REQUEST['edit'])) |
---|
176 | { |
---|
177 | if (empty($nea_newad['identifier'])) |
---|
178 | throw new Exception(__('Identifier required.')); |
---|
179 | |
---|
180 | if (!ereg('^[a-zA-Z0-9_-]+$',$nea_newad['identifier'])) |
---|
181 | throw new Exception(__('Invalid ad identifier format.')); |
---|
182 | |
---|
183 | if (empty($nea_newad['htmlcode'])) |
---|
184 | throw new Exception(__('HTML code required.')); |
---|
185 | |
---|
186 | if ($nea_newad['identifier'] != $_REQUEST['edit'] && isset($nea_ads[$nea_newad['identifier']])) |
---|
187 | throw new Exception(sprintf(__('You tried to change identifier from \'%s\' to \'%s\', but \'%s\' is already used.'), |
---|
188 | $_REQUEST['edit'],$nea_newad['identifier'],$nea_newad['identifier'])); |
---|
189 | |
---|
190 | if (!isset($nea_ads[$nea_newad['identifier']])) |
---|
191 | { |
---|
192 | unset($nea_ads[$_REQUEST['edit']]); |
---|
193 | $messages[] = sprintf(__('Warning ! Identifier changed from \'%s\' to \'%s\'.'), |
---|
194 | $_REQUEST['edit'],$nea_newad['identifier']); |
---|
195 | $_REQUEST['edit'] = $nea_newad['identifier']; |
---|
196 | } |
---|
197 | |
---|
198 | $nea_ads[$nea_newad['identifier']] = $nea_newad; |
---|
199 | $nea_settings['identifiers'] = notEvilAds::getUpdatedIdentifiers($nea_ads); |
---|
200 | $core->blog->settings->put('nea_ads',notEvilAds::storeAds($nea_ads)); |
---|
201 | $core->blog->settings->put('nea_settings',notEvilAds::storeSettings($nea_settings)); |
---|
202 | |
---|
203 | $messages[] = __('Ad successfully updated.'); |
---|
204 | } |
---|
205 | |
---|
206 | // Édition groupée des propriétées |
---|
207 | elseif (isset($_POST['nea_action_fromlist'])) |
---|
208 | { |
---|
209 | $default_tab = 'nea_list'; |
---|
210 | |
---|
211 | if (empty($_POST['nea_selected'])) |
---|
212 | throw new Exception(__('No ads selected.')); |
---|
213 | |
---|
214 | if ($_POST['nea_action'] == 'delete') |
---|
215 | { |
---|
216 | foreach ($_POST['nea_selected'] as $v) |
---|
217 | { |
---|
218 | if (isset($nea_ads[$v])) |
---|
219 | unset($nea_ads[$v]); |
---|
220 | } |
---|
221 | |
---|
222 | $nea_settings['identifiers'] = notEvilAds::getUpdatedIdentifiers($nea_ads); |
---|
223 | $core->blog->settings->put('nea_settings',notEvilAds::storeSettings($nea_settings)); |
---|
224 | |
---|
225 | $messages[] = __('Selected ads deleted.'); |
---|
226 | } |
---|
227 | elseif ($_POST['nea_action'] == 'mknotevil') |
---|
228 | { |
---|
229 | foreach ($_POST['nea_selected'] as $v) |
---|
230 | { |
---|
231 | if (isset($nea_ads[$v])) |
---|
232 | $nea_ads[$v]['notevil'] = true; |
---|
233 | } |
---|
234 | $messages[] = __('Selected ads are now not evil.'); |
---|
235 | } |
---|
236 | elseif ($_POST['nea_action'] == 'mkevil') |
---|
237 | { |
---|
238 | foreach ($_POST['nea_selected'] as $v) |
---|
239 | { |
---|
240 | if (isset($nea_ads[$v])) |
---|
241 | $nea_ads[$v]['notevil'] = false; |
---|
242 | } |
---|
243 | $messages[] = __('Selected ads are now evil.'); |
---|
244 | } |
---|
245 | elseif ($_POST['nea_action'] == 'disable') |
---|
246 | { |
---|
247 | foreach ($_POST['nea_selected'] as $v) |
---|
248 | { |
---|
249 | if (isset($nea_ads[$v])) |
---|
250 | $nea_ads[$v]['disable'] = true; |
---|
251 | } |
---|
252 | $messages[] = __('Selected ads are now disabled.'); |
---|
253 | } |
---|
254 | elseif ($_POST['nea_action'] == 'enable') |
---|
255 | { |
---|
256 | foreach ($_POST['nea_selected'] as $v) |
---|
257 | { |
---|
258 | if (isset($nea_ads[$v])) |
---|
259 | $nea_ads[$v]['disable'] = false; |
---|
260 | } |
---|
261 | $messages[] = __('Selected ads are now enabled.'); |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | throw new Exception(__('Unfortunately, I do not understand your request.')); |
---|
266 | } |
---|
267 | |
---|
268 | $core->blog->settings->put('nea_ads',notEvilAds::storeAds($nea_ads)); |
---|
269 | } |
---|
270 | else |
---|
271 | { |
---|
272 | $default_tab = $default_tab ? $default_tab : 'nea_config'; |
---|
273 | } |
---|
274 | } |
---|
275 | |
---|
276 | catch (Exception $e) |
---|
277 | { |
---|
278 | $core->error->add($e->getMessage()); |
---|
279 | } |
---|
280 | |
---|
281 | /* DISPLAY |
---|
282 | --------------------------------------------------- */ |
---|
283 | |
---|
284 | // Some messages |
---|
285 | if (!empty($_GET['up'])) |
---|
286 | { |
---|
287 | switch ($_GET['up']): |
---|
288 | case 'settings': |
---|
289 | $messages[] = __('Configuration updated.'); |
---|
290 | break; |
---|
291 | case 'newad': |
---|
292 | $messages[] = __('New ad added.'); |
---|
293 | $default_tab = 'nea_list'; |
---|
294 | break; |
---|
295 | default: |
---|
296 | $messages[] = __('Something was maybe updated. But what?'); |
---|
297 | endswitch; |
---|
298 | } |
---|
299 | |
---|
300 | // Headers |
---|
301 | echo ' |
---|
302 | <html><head> |
---|
303 | <title>'.__('Not Evil Ads').'</title> |
---|
304 | <script type="text/javascript"> |
---|
305 | //<![CDATA[ |
---|
306 | dotclear.nea_xmlresponsefile = "'.$core->blog->url.'notEvilAdsXML"; |
---|
307 | //]]> |
---|
308 | </script> |
---|
309 | '.dcPage::jsToolMan().dcPage::jsLoad('index.php?pf=notEvilAds/js/admin.js'). |
---|
310 | ($default_tab ? dcPage::jsPageTabs($default_tab) : '').' |
---|
311 | |
---|
312 | </head><body> |
---|
313 | <h2>'.__('Not Evil Ads configuration page').'</h2>'."\n\n"; |
---|
314 | |
---|
315 | if (!empty($messages)) |
---|
316 | { |
---|
317 | foreach ($messages as $message) |
---|
318 | { |
---|
319 | echo ' <p class="message">'.$message."</p>\n"; |
---|
320 | } |
---|
321 | } |
---|
322 | |
---|
323 | // Content |
---|
324 | include dirname(__FILE__).'/forms.php'; |
---|
325 | |
---|
326 | if ($fatal_error) |
---|
327 | echo '<p class="message">'.__('Fatal error occured. Can not continue.').'</p>'; |
---|
328 | elseif (!empty($_REQUEST['edit'])) |
---|
329 | |
---|
330 | echo |
---|
331 | '<p><a href="'.$p_url.'&tab=nea_list" title="'.__('Return to the main configuration page').'">'. |
---|
332 | __('Go back').'</a></p>'. |
---|
333 | $nea_forms['edit']; |
---|
334 | else |
---|
335 | echo |
---|
336 | '<div class="multi-part" id="nea_config" title="'.__('Configuration').'">'. |
---|
337 | $nea_forms['config']. |
---|
338 | "</div>\n\n". |
---|
339 | '<div class="multi-part" id="nea_list" title="'.__('Ads').'">'. |
---|
340 | $nea_forms['list']. |
---|
341 | "</div>\n\n". |
---|
342 | '<div class="multi-part" id="nea_edit" title="'.__('New ad').'">'. |
---|
343 | $nea_forms['edit']. |
---|
344 | "</div>\n\n". |
---|
345 | '<div class="multi-part" id="nea_help" title="'.__('Help').'">'. |
---|
346 | $nea_forms['help']. |
---|
347 | "</div>\n\n"; |
---|
348 | |
---|
349 | echo '</body></html>'; |
---|
350 | ?> |
---|