1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of Newsletter, a plugin for Dotclear. |
---|
4 | # |
---|
5 | # Copyright (c) 2009 Benoit de Marne |
---|
6 | # benoit.de.marne@gmail.com |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | require dirname(__FILE__).'/_widgets.php'; |
---|
14 | |
---|
15 | // chargement des librairies |
---|
16 | require_once dirname(__FILE__).'/inc/class.captcha.php'; |
---|
17 | require_once dirname(__FILE__).'/inc/class.newsletter.settings.php'; |
---|
18 | require_once dirname(__FILE__).'/inc/class.newsletter.tools.php'; |
---|
19 | require_once dirname(__FILE__).'/inc/class.newsletter.plugin.php'; |
---|
20 | require_once dirname(__FILE__).'/inc/class.newsletter.core.php'; |
---|
21 | |
---|
22 | // ajout des templates |
---|
23 | $core->tpl->addValue('Newsletter', array('tplNewsletter', 'Newsletter')); |
---|
24 | $core->tpl->addValue('NewsletterPageTitle', array('tplNewsletter', 'NewsletterPageTitle')); |
---|
25 | $core->tpl->addValue('NewsletterTemplateNotSet', array('tplNewsletter', 'NewsletterTemplateNotSet')); |
---|
26 | $core->tpl->addBlock('NewsletterBlock', array('tplNewsletter', 'NewsletterBlock')); |
---|
27 | $core->tpl->addBlock('NewsletterMessageBlock', array('tplNewsletter', 'NewsletterMessageBlock')); |
---|
28 | $core->tpl->addBlock('NewsletterFormBlock', array('tplNewsletter', 'NewsletterFormBlock')); |
---|
29 | $core->tpl->addValue('NewsletterFormSubmit', array('tplNewsletter', 'NewsletterFormSubmit')); |
---|
30 | $core->tpl->addValue('NewsletterFormRandom', array('tplNewsletter', 'NewsletterFormRandom')); |
---|
31 | $core->tpl->addValue('NewsletterFormCaptchaImg', array('tplNewsletter', 'NewsletterFormCaptchaImg')); |
---|
32 | $core->tpl->addValue('NewsletterFormCaptchaInput', array('tplNewsletter', 'NewsletterFormCaptchaInput')); |
---|
33 | $core->tpl->addValue('NewsletterFormLabel', array('tplNewsletter', 'NewsletterFormLabel')); |
---|
34 | $core->tpl->addValue('NewsletterMsgPresentationForm', array('tplNewsletter', 'NewsletterMsgPresentationForm')); |
---|
35 | $core->tpl->addBlock('NewsletterIfUseDefaultFormat',array('tplNewsletter','NewsletterIfUseDefaultFormat')); |
---|
36 | $core->tpl->addValue('NewsletterFormFormatSelect', array('tplNewsletter', 'NewsletterFormFormatSelect')); |
---|
37 | $core->tpl->addValue('NewsletterFormActionSelect', array('tplNewsletter', 'NewsletterFormActionSelect')); |
---|
38 | $core->tpl->addBlock('NewsletterIfUseCaptcha',array('tplNewsletter','NewsletterIfUseCaptcha')); |
---|
39 | |
---|
40 | // ajout des fonctions |
---|
41 | $core->rest->addFunction('newsletterSending', array('newsletterRest','newsletterSending')); |
---|
42 | |
---|
43 | class tplNewsletter |
---|
44 | { |
---|
45 | /** |
---|
46 | * Select the newsletter to send |
---|
47 | * |
---|
48 | * @return: string msg |
---|
49 | */ |
---|
50 | public static function Newsletter() |
---|
51 | { |
---|
52 | global $core; |
---|
53 | |
---|
54 | if (isset($GLOBALS['newsletter']['cmd'])) |
---|
55 | $cmd = (string) html::clean($GLOBALS['newsletter']['cmd']); |
---|
56 | else |
---|
57 | $cmd = 'about'; |
---|
58 | |
---|
59 | if (isset($GLOBALS['newsletter']['email'])) |
---|
60 | $email = (string) html::clean($GLOBALS['newsletter']['email']); |
---|
61 | else |
---|
62 | $email = null; |
---|
63 | |
---|
64 | if (isset($GLOBALS['newsletter']['code'])) |
---|
65 | $code = (string) html::clean($GLOBALS['newsletter']['code']); |
---|
66 | else |
---|
67 | $code = null; |
---|
68 | |
---|
69 | if (isset($GLOBALS['newsletter']['modesend'])) |
---|
70 | $modesend = (string) html::clean($GLOBALS['newsletter']['modesend']); |
---|
71 | else |
---|
72 | $modesend = null; |
---|
73 | |
---|
74 | switch ($cmd) { |
---|
75 | case 'test': |
---|
76 | $msg = __('Test display template'); |
---|
77 | break; |
---|
78 | |
---|
79 | case 'about': |
---|
80 | $msg = __('About Newsletter ...'); |
---|
81 | //$msg = __('About'). ' ' . newsletterPlugin::dcName() . ' ...' ; |
---|
82 | $msg .= '<br />'. __('Version'). ' : ' . newsletterPlugin::dcVersion(); |
---|
83 | $msg .= '<br />'. __('Authors'). ' : ' . newsletterPlugin::dcAuthor(); |
---|
84 | $msg .= '<br />'. __('Description'). ' : ' . newsletterPlugin::dcDesc(); |
---|
85 | break; |
---|
86 | |
---|
87 | case 'confirm': |
---|
88 | if ($email == null || $code == null) |
---|
89 | $msg = __('Missing informations'); |
---|
90 | else { |
---|
91 | $rs = newsletterCore::getemail($email); |
---|
92 | if ($rs == null || $rs->regcode != $code) |
---|
93 | $msg = __('Your subscription code is invalid.'); |
---|
94 | else if ($rs->state == 'enabled') |
---|
95 | $msg = __('Account already confirmed.'); |
---|
96 | else { |
---|
97 | newsletterCore::send($rs->subscriber_id,'enable'); |
---|
98 | $msg = __('Your subscription is confirmed.').'<br />'.__('You will soon receive an email.'); |
---|
99 | } |
---|
100 | } |
---|
101 | break; |
---|
102 | |
---|
103 | case 'enable': |
---|
104 | if ($email == null) |
---|
105 | $msg = __('Missing informations'); |
---|
106 | else { |
---|
107 | $rs = newsletterCore::getemail($email); |
---|
108 | if ($rs == null) |
---|
109 | $msg = __('Unable to find you account informations.'); |
---|
110 | else if ($rs->state == 'enabled') |
---|
111 | $msg = __('Account already enabled.'); |
---|
112 | else { |
---|
113 | newsletterCore::send($rs->subscriber_id,'enable'); |
---|
114 | $msg = __('Your account is enabled.').'<br />'.__('You will soon receive an email.'); |
---|
115 | } |
---|
116 | } |
---|
117 | break; |
---|
118 | |
---|
119 | case 'disable': |
---|
120 | if ($email == null) |
---|
121 | $msg = __('Missing informations'); |
---|
122 | else { |
---|
123 | $rs = newsletterCore::getemail($email); |
---|
124 | if ($rs == null) |
---|
125 | $msg = __('Unable to find you account informations.'); |
---|
126 | else if ($rs->state == 'disabled') |
---|
127 | $msg = __('Account already disabled.'); |
---|
128 | else { |
---|
129 | newsletterCore::send($rs->subscriber_id,'disable'); |
---|
130 | $msg = __('Your account is disabled.').'<br />'.__('You will soon receive an email.'); |
---|
131 | } |
---|
132 | } |
---|
133 | break; |
---|
134 | |
---|
135 | case 'suspend': |
---|
136 | if ($email == null) |
---|
137 | $msg = __('Missing informations'); |
---|
138 | else { |
---|
139 | $rs = newsletterCore::getemail($email); |
---|
140 | if ($rs == null) |
---|
141 | $msg = __('Unable to find you account informations.'); |
---|
142 | else if ($rs->state == 'suspended') |
---|
143 | $msg = __('Account already suspended.'); |
---|
144 | else { |
---|
145 | newsletterCore::send($rs->subscriber_id,'suspend'); |
---|
146 | $msg = __('Your account is suspended.').'<br />'.__('You will soon receive an email.'); |
---|
147 | } |
---|
148 | } |
---|
149 | break; |
---|
150 | |
---|
151 | case 'changemode': |
---|
152 | if ($email == null) |
---|
153 | $msg = __('Missing informations'); |
---|
154 | else { |
---|
155 | $rs = newsletterCore::getemail($email); |
---|
156 | if ($rs == null) |
---|
157 | $msg = __('Unable to find you account informations.'); |
---|
158 | else { |
---|
159 | newsletterCore::send($rs->subscriber_id,'changemode'); |
---|
160 | $msg = __('Your sending format is').$modesend.'<br />'.__('You will soon receive an email.'); |
---|
161 | } |
---|
162 | } |
---|
163 | break; |
---|
164 | |
---|
165 | case 'submit': |
---|
166 | $email = (string)html::clean($_POST['nl_email']); |
---|
167 | $option = (string)html::clean($_POST['nl_option']); |
---|
168 | //$modesend = (string)html::clean($_POST['nl_modesend']); |
---|
169 | $check = true; |
---|
170 | $newsletter_settings = new newsletterSettings($core); |
---|
171 | if ($newsletter_settings->getCaptcha()) { |
---|
172 | $captcha = (string)html::clean($_POST['nl_captcha']); |
---|
173 | $read = Captcha::read(); |
---|
174 | if ($read != $captcha) { |
---|
175 | $check = false; |
---|
176 | $ca = new Captcha(80, 30, 5); |
---|
177 | $ca->generate(); |
---|
178 | $ca->file(); |
---|
179 | $ca->write(); |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | if (!$check) { |
---|
184 | $msg = __('Bad captcha code'); |
---|
185 | } else switch ($option) { |
---|
186 | case 'subscribe': |
---|
187 | $msg = newsletterCore::accountCreate($email,null,$modesend); |
---|
188 | break; |
---|
189 | |
---|
190 | case 'unsubscribe': |
---|
191 | $msg = newsletterCore::accountDelete($email); |
---|
192 | break; |
---|
193 | |
---|
194 | case 'suspend': |
---|
195 | $msg = newsletterCore::accountSuspend($email); |
---|
196 | break; |
---|
197 | |
---|
198 | case 'resume': |
---|
199 | $msg = newsletterCore::accountResume($email); |
---|
200 | break; |
---|
201 | |
---|
202 | case 'changemode': |
---|
203 | $msg = newsletterCore::accountChangeMode($email,$modesend); |
---|
204 | break; |
---|
205 | |
---|
206 | default: |
---|
207 | $msg = __('Error in formular.'); |
---|
208 | break; |
---|
209 | } |
---|
210 | break; |
---|
211 | |
---|
212 | default: |
---|
213 | $msg = ''; |
---|
214 | break; |
---|
215 | } |
---|
216 | |
---|
217 | return $msg; |
---|
218 | } |
---|
219 | |
---|
220 | /** |
---|
221 | * titre de la page html |
---|
222 | */ |
---|
223 | public static function NewsletterPageTitle() |
---|
224 | { |
---|
225 | global $core; |
---|
226 | $newsletter_settings = new newsletterSettings($core); |
---|
227 | //return __('Newsletter'); |
---|
228 | return $newsletter_settings->getFormTitlePage(); |
---|
229 | } |
---|
230 | |
---|
231 | /** |
---|
232 | * indication à l'utilisateur que la page newsletter n'a pas été initialisée |
---|
233 | */ |
---|
234 | public static function NewsletterTemplateNotSet() |
---|
235 | { |
---|
236 | return '<?php echo newsletterCore::TemplateNotSet(); ?>'; |
---|
237 | } |
---|
238 | |
---|
239 | public static function NewsletterBlock($attr, $content) |
---|
240 | { |
---|
241 | return $content; |
---|
242 | } |
---|
243 | |
---|
244 | public static function NewsletterMessageBlock($attr, $content) |
---|
245 | { |
---|
246 | // ajout d'un bouton retour quelque soit l'evenement |
---|
247 | $text = '<?php echo "'. |
---|
248 | '<form action=\"'.newsletterCore::url('form').'\" method=\"post\" id=\"comment-form\" class=\"newsletter\">'. |
---|
249 | '<fieldset>'. |
---|
250 | '<p class=\"field\">'. |
---|
251 | (string) html::clean($content). |
---|
252 | '</p>'. |
---|
253 | '<p>'. |
---|
254 | '<input type=\"submit\" name=\"nl_back\" id=\"nl_back\" value=\"'.__('Back').'\" class=\"submit\" />'. |
---|
255 | '</p>'. |
---|
256 | '</fieldset>'. |
---|
257 | '</form>'. |
---|
258 | '" ?>'; |
---|
259 | |
---|
260 | return '<?php if (!empty($GLOBALS[\'newsletter\'][\'msg\'])) { ?>'.$text.'<?php } ?>'; |
---|
261 | } |
---|
262 | |
---|
263 | public static function NewsletterFormBlock($attr, $content) |
---|
264 | { |
---|
265 | return '<?php if (!empty($GLOBALS[\'newsletter\'][\'form\'])) { ?>'.$content.'<?php } ?>'; |
---|
266 | } |
---|
267 | |
---|
268 | /** |
---|
269 | * adresse de soumission du formulaire |
---|
270 | */ |
---|
271 | public static function NewsletterFormSubmit() |
---|
272 | { |
---|
273 | return '<?php echo newsletterCore::url(\'submit\'); ?>'; |
---|
274 | } |
---|
275 | |
---|
276 | public static function NewsletterFormRandom() |
---|
277 | { |
---|
278 | return '<?php echo "'.newsletterTools::getRandom().'" ?>'; |
---|
279 | } |
---|
280 | |
---|
281 | public static function NewsletterFormCaptchaImg() |
---|
282 | { |
---|
283 | return '<?php echo "<img src=\"'.Captcha::www().'/captcha.img.png\" style=\"vertical-align: middle;\" alt=\"'.__('Captcha').'\" />" ?>'; |
---|
284 | } |
---|
285 | |
---|
286 | public static function NewsletterFormCaptchaInput() |
---|
287 | { |
---|
288 | return '<?php echo "<p><input type=\"text\" name=\"nl_captcha\" id=\"nl_captcha\" value=\"\" style=\"width:90px; vertical-align:top;\" /></p>" ?>'; |
---|
289 | } |
---|
290 | |
---|
291 | /* |
---|
292 | * labels du formulaire |
---|
293 | */ |
---|
294 | public static function NewsletterFormLabel($attr, $content) |
---|
295 | { |
---|
296 | switch ($attr['id']) |
---|
297 | { |
---|
298 | case 'ok': |
---|
299 | return '<?php echo __(\'Send\') ?>'; |
---|
300 | |
---|
301 | case 'subscribe': |
---|
302 | return '<?php echo __(\'Subscribe\') ?>'; |
---|
303 | |
---|
304 | case 'unsubscribe': |
---|
305 | return '<?php echo __(\'Unsubscribe\') ?>'; |
---|
306 | |
---|
307 | case 'suspend': |
---|
308 | return '<?php echo __(\'Suspend\') ?>'; |
---|
309 | // __('Suspend') |
---|
310 | |
---|
311 | case 'resume': |
---|
312 | return '<?php echo __(\'Resume\') ?>'; |
---|
313 | // __('Resume') |
---|
314 | |
---|
315 | case 'nl_email': |
---|
316 | return '<?php echo __(\'Email\') ?>'; |
---|
317 | |
---|
318 | case 'nl_option': |
---|
319 | return '<?php echo __(\'Action\') ?>'; |
---|
320 | |
---|
321 | case 'nl_captcha': |
---|
322 | return '<?php echo \'<label for="nl_captcha">\'. __(\'Captcha\') .\'</label>\' ?>'; |
---|
323 | |
---|
324 | case 'nl_submit': |
---|
325 | return ''; |
---|
326 | |
---|
327 | case 'html': |
---|
328 | return '<?php echo __(\'html\') ?>'; |
---|
329 | |
---|
330 | case 'text': |
---|
331 | return '<?php echo __(\'text\') ?>'; |
---|
332 | // __('text') |
---|
333 | |
---|
334 | case 'nl_modesend': |
---|
335 | return '<?php echo __(\'Format\') ?>'; |
---|
336 | |
---|
337 | case 'changemode': |
---|
338 | return '<?php echo __(\'Change format\') ?>'; |
---|
339 | // __('Change format') |
---|
340 | |
---|
341 | case 'back': |
---|
342 | return '<?php echo __(\'Back\') ?>'; |
---|
343 | |
---|
344 | } |
---|
345 | } |
---|
346 | |
---|
347 | /* |
---|
348 | * message de présentation du formulaire |
---|
349 | */ |
---|
350 | public static function NewsletterMsgPresentationForm() |
---|
351 | { |
---|
352 | global $core; |
---|
353 | $newsletter_settings = new newsletterSettings($core); |
---|
354 | return $newsletter_settings->getMsgPresentationForm(); |
---|
355 | } |
---|
356 | |
---|
357 | /* |
---|
358 | * affichage du choix du format si le mode par défaut n'est pas défini |
---|
359 | */ |
---|
360 | public static function NewsletterIfUseDefaultFormat($attr,$content) |
---|
361 | { |
---|
362 | global $core; |
---|
363 | $newsletter_settings = new newsletterSettings($core); |
---|
364 | return (!$newsletter_settings->getUseDefaultFormat()? $content : ''); |
---|
365 | } |
---|
366 | |
---|
367 | /* |
---|
368 | * affichage du choix du format si le mode par défaut n'est pas défini |
---|
369 | */ |
---|
370 | public static function NewsletterFormFormatSelect($attr,$content) |
---|
371 | { |
---|
372 | $text = '<?php echo "'. |
---|
373 | '<label for=\"nl_modesend\">'.__('Format').' :</label>'. |
---|
374 | '<select style=\"border:1px inset silver; width:150px;\" name=\"nl_modesend\" id=\"nl_modesend\" size=\"1\">'. |
---|
375 | '<option value=\"html\" selected=\"selected\">'.__('html').'</option>'. |
---|
376 | '<option value=\"text\">'.__('text').'</option>'. |
---|
377 | '</select>'. |
---|
378 | '" ?>'; |
---|
379 | |
---|
380 | return $text; |
---|
381 | } |
---|
382 | |
---|
383 | public static function NewsletterFormActionSelect($attr,$content) |
---|
384 | { |
---|
385 | global $core; |
---|
386 | $newsletter_settings = new newsletterSettings($core); |
---|
387 | |
---|
388 | $text = '<?php echo "'. |
---|
389 | '<label for=\"nl_option\">'.__('Action').' :</label>'. |
---|
390 | '<select style=\"border:1px inset silver; width:150px;\" name=\"nl_option\" id=\"nl_option\" size=\"1\">'. |
---|
391 | '<option value=\"subscribe\" selected=\"selected\">'.__('Subscribe').'</option>'; |
---|
392 | |
---|
393 | if(!$newsletter_settings->getUseDefaultFormat()) { |
---|
394 | $text .= '<option value=\"changemode\">'.__('Change format').'</option>'; |
---|
395 | } |
---|
396 | |
---|
397 | if($newsletter_settings->getCheckUseSuspend()) { |
---|
398 | $text .= '<option value=\"suspend\">'.__('Suspend').'</option>'; |
---|
399 | } |
---|
400 | |
---|
401 | $text .= '<option value=\"resume\">'.__('Resume').'</option>'. |
---|
402 | '<option value=\"\">---</option>'. |
---|
403 | '<option value=\"unsubscribe\">'.__('Unsubscribe').'</option>'. |
---|
404 | '</select>'. |
---|
405 | '" ?>'; |
---|
406 | return $text; |
---|
407 | } |
---|
408 | |
---|
409 | /* |
---|
410 | * affichage du choix du format si le mode par défaut n'est pas défini |
---|
411 | */ |
---|
412 | public static function NewsletterIfUseCaptcha($attr,$content) |
---|
413 | { |
---|
414 | global $core; |
---|
415 | $newsletter_settings = new newsletterSettings($core); |
---|
416 | if (!empty($GLOBALS['newsletter']['form']) && $newsletter_settings->getCaptcha()) { |
---|
417 | $ca = new Captcha(80, 30, 5); |
---|
418 | $ca->generate(); |
---|
419 | $ca->file(); |
---|
420 | $ca->write(); |
---|
421 | } |
---|
422 | return ($newsletter_settings->getCaptcha()? $content : ''); |
---|
423 | } |
---|
424 | |
---|
425 | } |
---|
426 | |
---|
427 | /* |
---|
428 | * classe pour l'affichage du widget public |
---|
429 | */ |
---|
430 | class publicWidgetsNewsletter |
---|
431 | { |
---|
432 | /** |
---|
433 | * initialisation du widget |
---|
434 | */ |
---|
435 | public static function initWidgets(&$w) |
---|
436 | { |
---|
437 | global $core; |
---|
438 | try { |
---|
439 | // prise en compte de l'état d'activation du plugin |
---|
440 | if (!newsletterPlugin::isActive()) |
---|
441 | return; |
---|
442 | |
---|
443 | // prise en compte paramètre: uniquement sur la page d'accueil |
---|
444 | $url = &$core->url; |
---|
445 | if ($w->homeonly && $url->type != 'default') { |
---|
446 | return; |
---|
447 | } |
---|
448 | |
---|
449 | // paramétrage des variables |
---|
450 | $plugin_name = __('Newsletter'); |
---|
451 | $title = ($w->title) ? html::escapeHTML($w->title) : $plugin_name; |
---|
452 | $showTitle = ($w->showtitle) ? true : false; |
---|
453 | $subscription_link = ($w->subscription_link) ? html::escapeHTML($w->subscription_link) : __('Subscription link'); |
---|
454 | |
---|
455 | $text = ''; |
---|
456 | |
---|
457 | $newsletter_settings = new newsletterSettings($core); |
---|
458 | |
---|
459 | // mise en place du contenu du widget dans $text |
---|
460 | if ($w->inwidget) { |
---|
461 | $link = newsletterCore::url('submit'); |
---|
462 | $text .= |
---|
463 | '<form action="'.$link.'" method="post" id="nl_form">'."\n". |
---|
464 | "<p>\n". |
---|
465 | $core->formNonce(). |
---|
466 | form::hidden(array('nl_random'),newsletterTools::getRandom()). |
---|
467 | "</p>\n". |
---|
468 | '<p>'. |
---|
469 | '<label for="nl_email">'.__('Email').'</label> : '. |
---|
470 | form::field(array('nl_email','nl_email'),15,255). |
---|
471 | '</p>'. |
---|
472 | '<p><label for="nl_modesend">'.__('Format').'</label> : '. |
---|
473 | '<select style="border:1px inset silver; width:140px;" name="nl_modesend" id="nl_modesend" size="1">'. |
---|
474 | '<option value="html" selected="selected">'.__('html').'</option>'. |
---|
475 | '<option value="text">'.__('text').'</option>'. |
---|
476 | '</select></p>'. |
---|
477 | '<p><label for="nl_submit">'.__('Actions').'</label> : '. |
---|
478 | '<select style="border:1px inset silver; width:140px;" name="nl_option" id="nl_option" size="1">'. |
---|
479 | '<option value="subscribe" selected="selected">'.__('Subscribe').'</option>'; |
---|
480 | |
---|
481 | if(!$newsletter_settings->getUseDefaultFormat()) { |
---|
482 | $text .= '<option value="changemode">'.__('Change format').'</option>'; |
---|
483 | } |
---|
484 | |
---|
485 | if($newsletter_settings->getCheckUseSuspend()) { |
---|
486 | $text .= '<option value=\"suspend\">'.__('Suspend').'</option>'; |
---|
487 | } |
---|
488 | |
---|
489 | $text .= |
---|
490 | '<option value="resume">'.__('Resume').'</option>'. |
---|
491 | '<option value="">---</option>'. |
---|
492 | '<option value="unsubscribe">'.__('Unsubscribe').'</option>'. |
---|
493 | '</select>'. |
---|
494 | /* |
---|
495 | '<li><label for="nl_submit">'.__('Actions').'</label> :<br />'. |
---|
496 | form::radio(array('nl_option'),'subscribe', true).__('Subscribe').'<br />'. |
---|
497 | form::radio(array('nl_option'),'unsubscribe').__('Unsubscribe').'<br />'. |
---|
498 | //*/ |
---|
499 | '</p>'; |
---|
500 | |
---|
501 | if ($newsletter_settings->getCaptcha()) { |
---|
502 | require_once dirname(__FILE__).'/inc/class.captcha.php'; |
---|
503 | $as = new Captcha(80, 30, 5); |
---|
504 | $as->generate(); |
---|
505 | $as->file(); |
---|
506 | $as->write(); |
---|
507 | |
---|
508 | $text .= |
---|
509 | //'<p>'. |
---|
510 | '<p><label for="nl_captcha">'.__('Captcha').'</label> :<br />'. |
---|
511 | '<img src="'.Captcha::www().'/captcha.img.png" alt="'.__('Captcha').'" /><br />'. |
---|
512 | form::field(array('nl_captcha','nl_captcha'),9,30). |
---|
513 | '</p>'; |
---|
514 | //'</p>'. |
---|
515 | } |
---|
516 | |
---|
517 | $text .= |
---|
518 | '<p><input class="submit" type="submit" name="nl_submit" id="nl_submit" value="'.__('Send').'" /></p>'. |
---|
519 | |
---|
520 | //'</ul>'. |
---|
521 | //'</fieldset>'. |
---|
522 | '</form>'; |
---|
523 | |
---|
524 | } else { |
---|
525 | $link = newsletterCore::url('form'); |
---|
526 | if ($w->insublink) { |
---|
527 | $title = str_replace('%I', '<img src="?pf=newsletter/icon.png" alt="" width="16" height="16" style="margin: 0 3px; vertical-align: middle;" />', $title); |
---|
528 | $text = $w->text ? $w->text : ''; |
---|
529 | |
---|
530 | $text .= '<ul><li><a href="'.$link.'">'.$subscription_link.'</a></li></ul>'; |
---|
531 | } else { |
---|
532 | $title = '<a href="'.$link.'">'.$title.'</a>'; |
---|
533 | $title = str_replace('%I', '</a><img src="?pf=newsletter/icon.png" alt="newsletter" width="16" height="16" style="margin:0 3px; vertical-align:middle;" /> <a href="'.$link.'">', $title); |
---|
534 | } |
---|
535 | } |
---|
536 | |
---|
537 | // renvoi du code à afficher pour le widget |
---|
538 | if ($showTitle === true) |
---|
539 | $title = '<h2>'.$title.'</h2>'; |
---|
540 | else |
---|
541 | $title = ''; |
---|
542 | |
---|
543 | return "\n".'<div class="'.newsletterPlugin::pname().'">'.$title.$text.'</div>'."\n"; |
---|
544 | //return "\n".'<div class="categories">'.$title.$text.'</div>'."\n"; |
---|
545 | |
---|
546 | } catch (Exception $e) { |
---|
547 | $core->error->add($e->getMessage()); |
---|
548 | } |
---|
549 | } |
---|
550 | } |
---|
551 | |
---|
552 | // gestionnaire d'url |
---|
553 | class urlNewsletter extends dcUrlHandlers |
---|
554 | { |
---|
555 | // gestion des paramètres |
---|
556 | public static function newsletter($args) |
---|
557 | { |
---|
558 | global $core; |
---|
559 | try { |
---|
560 | // tests des arguments |
---|
561 | if (empty($args) || $args == '') { |
---|
562 | self::p404(); |
---|
563 | return; |
---|
564 | } |
---|
565 | |
---|
566 | // initialisation des variables |
---|
567 | $tpl = &$core->tpl; |
---|
568 | $cmd = null; |
---|
569 | $GLOBALS['newsletter']['cmd'] = null; |
---|
570 | $GLOBALS['newsletter']['msg'] = false; |
---|
571 | $GLOBALS['newsletter']['form'] = false; |
---|
572 | $GLOBALS['newsletter']['email'] = null; |
---|
573 | $GLOBALS['newsletter']['code'] = null; |
---|
574 | $GLOBALS['newsletter']['modesend'] = null; |
---|
575 | |
---|
576 | // décomposition des arguments et aiguillage |
---|
577 | $params = explode('/', $args); |
---|
578 | if (isset($params[0]) && !empty($params[0])) |
---|
579 | $cmd = (string)html::clean($params[0]); |
---|
580 | else |
---|
581 | $cmd = null; |
---|
582 | |
---|
583 | if (isset($params[1]) && !empty($params[1])) { |
---|
584 | $email = newsletterTools::base64_url_decode((string)html::clean($params[1])); |
---|
585 | } |
---|
586 | else |
---|
587 | $email = null; |
---|
588 | |
---|
589 | if (isset($params[2]) && !empty($params[2])) |
---|
590 | $regcode = (string)html::clean($params[2]); |
---|
591 | else |
---|
592 | $regcode = null; |
---|
593 | |
---|
594 | if (isset($params[3]) && !empty($params[3])) |
---|
595 | $modesend = newsletterTools::base64_url_decode((string)html::clean($params[3])); |
---|
596 | else |
---|
597 | $modesend = null; |
---|
598 | |
---|
599 | |
---|
600 | switch ($cmd) { |
---|
601 | case 'test': |
---|
602 | case 'about': |
---|
603 | $GLOBALS['newsletter']['msg'] = true; |
---|
604 | break; |
---|
605 | |
---|
606 | case 'form': |
---|
607 | $GLOBALS['newsletter']['form'] = true; |
---|
608 | break; |
---|
609 | |
---|
610 | case 'submit': |
---|
611 | $GLOBALS['newsletter']['msg'] = true; |
---|
612 | break; |
---|
613 | |
---|
614 | case 'confirm': |
---|
615 | case 'enable': |
---|
616 | case 'disable': |
---|
617 | case 'suspend': |
---|
618 | case 'changemode': |
---|
619 | case 'resume': |
---|
620 | { |
---|
621 | if ($email == null) { |
---|
622 | self::p404(); |
---|
623 | return; |
---|
624 | } |
---|
625 | $GLOBALS['newsletter']['msg'] = true; |
---|
626 | } |
---|
627 | break; |
---|
628 | } |
---|
629 | |
---|
630 | $GLOBALS['newsletter']['cmd'] = $cmd; |
---|
631 | $GLOBALS['newsletter']['email'] = $email; |
---|
632 | $GLOBALS['newsletter']['code'] = $regcode; |
---|
633 | $GLOBALS['newsletter']['modesend'] = $modesend; |
---|
634 | |
---|
635 | // Affichage du formulaire |
---|
636 | $tpl->setPath($tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
637 | $file = $tpl->getFilePath('subscribe.newsletter.html'); |
---|
638 | |
---|
639 | header('Pragma: no-cache'); |
---|
640 | header('Cache-Control: no-cache'); |
---|
641 | self::serveDocument('subscribe.newsletter.html','text/html',false,false); |
---|
642 | return; |
---|
643 | } catch (Exception $e) { |
---|
644 | $core->error->add($e->getMessage()); |
---|
645 | } |
---|
646 | } |
---|
647 | } |
---|
648 | |
---|
649 | /* |
---|
650 | * classe des fonctions rest |
---|
651 | */ |
---|
652 | class restNewsletter |
---|
653 | { |
---|
654 | |
---|
655 | |
---|
656 | } |
---|
657 | |
---|
658 | |
---|
659 | ?> |
---|