1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of Newsletter, a plugin for Dotclear. |
---|
4 | # |
---|
5 | # Copyright (c) 2009-2010 Benoit de Marne. |
---|
6 | # benoit.de.marne@gmail.com |
---|
7 | # Many thanks to Association Dotclear and special thanks to Olivier Le Bris |
---|
8 | # |
---|
9 | # Licensed under the GPL version 2.0 license. |
---|
10 | # A copy of this license is available in LICENSE file or at |
---|
11 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
12 | # -- END LICENSE BLOCK ------------------------------------ |
---|
13 | |
---|
14 | require dirname(__FILE__).'/_widgets.php'; |
---|
15 | |
---|
16 | // loading librairies |
---|
17 | require_once dirname(__FILE__).'/inc/class.captcha.php'; |
---|
18 | require_once dirname(__FILE__).'/inc/class.newsletter.settings.php'; |
---|
19 | require_once dirname(__FILE__).'/inc/class.newsletter.tools.php'; |
---|
20 | require_once dirname(__FILE__).'/inc/class.newsletter.plugin.php'; |
---|
21 | require_once dirname(__FILE__).'/inc/class.newsletter.core.php'; |
---|
22 | require_once dirname(__FILE__).'/inc/class.newsletter.letter.php'; |
---|
23 | |
---|
24 | // adding templates |
---|
25 | $core->tpl->addValue('Newsletter', array('tplNewsletter', 'Newsletter')); |
---|
26 | $core->tpl->addValue('NewsletterPageTitle', array('tplNewsletter', 'NewsletterPageTitle')); |
---|
27 | $core->tpl->addValue('NewsletterTemplateNotSet', array('tplNewsletter', 'NewsletterTemplateNotSet')); |
---|
28 | $core->tpl->addBlock('NewsletterBlock', array('tplNewsletter', 'NewsletterBlock')); |
---|
29 | $core->tpl->addBlock('NewsletterMessageBlock', array('tplNewsletter', 'NewsletterMessageBlock')); |
---|
30 | $core->tpl->addBlock('NewsletterFormBlock', array('tplNewsletter', 'NewsletterFormBlock')); |
---|
31 | $core->tpl->addValue('NewsletterFormSubmit', array('tplNewsletter', 'NewsletterFormSubmit')); |
---|
32 | $core->tpl->addValue('NewsletterFormRandom', array('tplNewsletter', 'NewsletterFormRandom')); |
---|
33 | $core->tpl->addValue('NewsletterFormCaptchaImg', array('tplNewsletter', 'NewsletterFormCaptchaImg')); |
---|
34 | $core->tpl->addValue('NewsletterFormCaptchaInput', array('tplNewsletter', 'NewsletterFormCaptchaInput')); |
---|
35 | $core->tpl->addValue('NewsletterFormLabel', array('tplNewsletter', 'NewsletterFormLabel')); |
---|
36 | $core->tpl->addValue('NewsletterMsgPresentationForm', array('tplNewsletter', 'NewsletterMsgPresentationForm')); |
---|
37 | $core->tpl->addBlock('NewsletterIfUseDefaultFormat',array('tplNewsletter','NewsletterIfUseDefaultFormat')); |
---|
38 | $core->tpl->addValue('NewsletterFormFormatSelect', array('tplNewsletter', 'NewsletterFormFormatSelect')); |
---|
39 | $core->tpl->addValue('NewsletterFormActionSelect', array('tplNewsletter', 'NewsletterFormActionSelect')); |
---|
40 | $core->tpl->addBlock('NewsletterIfUseCaptcha',array('tplNewsletter','NewsletterIfUseCaptcha')); |
---|
41 | |
---|
42 | // adding behaviors |
---|
43 | $core->addBehavior('publicBeforeContentFilter', array('dcBehaviorsNewsletterPublic', 'translateKeywords')); |
---|
44 | $core->addBehavior('publicHeadContent', array('dcBehaviorsNewsletterPublic', 'publicHeadContent')); |
---|
45 | |
---|
46 | class tplNewsletter |
---|
47 | { |
---|
48 | /** |
---|
49 | * Select the newsletter to send |
---|
50 | * |
---|
51 | * @return: string msg |
---|
52 | */ |
---|
53 | public static function Newsletter() |
---|
54 | { |
---|
55 | global $core; |
---|
56 | |
---|
57 | if (isset($GLOBALS['newsletter']['cmd'])) |
---|
58 | $cmd = (string) html::clean($GLOBALS['newsletter']['cmd']); |
---|
59 | else |
---|
60 | $cmd = 'about'; |
---|
61 | |
---|
62 | if (isset($GLOBALS['newsletter']['email'])) |
---|
63 | $email = (string) html::clean($GLOBALS['newsletter']['email']); |
---|
64 | else |
---|
65 | $email = null; |
---|
66 | |
---|
67 | if (isset($GLOBALS['newsletter']['code'])) |
---|
68 | $code = (string) html::clean($GLOBALS['newsletter']['code']); |
---|
69 | else |
---|
70 | $code = null; |
---|
71 | |
---|
72 | if (isset($GLOBALS['newsletter']['modesend'])) |
---|
73 | $modesend = (string) html::clean($GLOBALS['newsletter']['modesend']); |
---|
74 | else |
---|
75 | $modesend = null; |
---|
76 | |
---|
77 | switch ($cmd) { |
---|
78 | case 'test': |
---|
79 | $msg = __('Test display template'); |
---|
80 | break; |
---|
81 | |
---|
82 | case 'about': |
---|
83 | $msg = '<ul><strong>'.__('About Newsletter ...').'</strong>'; |
---|
84 | $msg .= '<li>'.__('Version').' : ' . newsletterPlugin::dcVersion().'</li>'; |
---|
85 | $msg .= '<li>'.__('Author').' : ' . newsletterPlugin::dcAuthor().'</li>'; |
---|
86 | $msg .= '<li>'.__('Description').' : ' . newsletterPlugin::dcDesc().'</li>'; |
---|
87 | $msg .= '</ul>'; |
---|
88 | |
---|
89 | $msg = html::escapeHTML($msg); |
---|
90 | break; |
---|
91 | |
---|
92 | case 'confirm': |
---|
93 | if ($email == null || $code == null) |
---|
94 | $msg = __('Missing informations'); |
---|
95 | else { |
---|
96 | $rs = newsletterCore::getemail($email); |
---|
97 | if ($rs == null || $rs->regcode != $code) |
---|
98 | $msg = __('Your subscription code is invalid.'); |
---|
99 | else if ($rs->state == 'enabled') |
---|
100 | $msg = __('Account already confirmed.'); |
---|
101 | else { |
---|
102 | newsletterCore::send($rs->subscriber_id,'enable'); |
---|
103 | $msg = __('Your subscription is confirmed.').'<br />'.__('You will soon receive an email.'); |
---|
104 | } |
---|
105 | } |
---|
106 | break; |
---|
107 | |
---|
108 | case 'enable': |
---|
109 | if ($email == null) |
---|
110 | $msg = __('Missing informations'); |
---|
111 | else { |
---|
112 | $rs = newsletterCore::getemail($email); |
---|
113 | if ($rs == null) |
---|
114 | $msg = __('Unable to find your account informations.'); |
---|
115 | else if ($rs->state == 'enabled') |
---|
116 | $msg = __('Account already enabled.'); |
---|
117 | else { |
---|
118 | newsletterCore::send($rs->subscriber_id,'enable'); |
---|
119 | $msg = __('Your account is enabled.').'<br />'.__('You will soon receive an email.'); |
---|
120 | } |
---|
121 | } |
---|
122 | break; |
---|
123 | |
---|
124 | case 'disable': |
---|
125 | if ($email == null) |
---|
126 | $msg = __('Missing informations'); |
---|
127 | else { |
---|
128 | $rs = newsletterCore::getemail($email); |
---|
129 | if ($rs == null) |
---|
130 | $msg = __('Unable to find your account informations.'); |
---|
131 | else if ($rs->state == 'disabled') |
---|
132 | $msg = __('Account already disabled.'); |
---|
133 | else { |
---|
134 | newsletterCore::send($rs->subscriber_id,'disable'); |
---|
135 | $msg = __('Your account is disabled.').'<br />'.__('You will soon receive an email.'); |
---|
136 | } |
---|
137 | } |
---|
138 | break; |
---|
139 | |
---|
140 | case 'suspend': |
---|
141 | if ($email == null) |
---|
142 | $msg = __('Missing informations'); |
---|
143 | else { |
---|
144 | $rs = newsletterCore::getemail($email); |
---|
145 | if ($rs == null) |
---|
146 | $msg = __('Unable to find you account informations.'); |
---|
147 | else if ($rs->state == 'suspended') |
---|
148 | $msg = __('Account already suspended.'); |
---|
149 | else { |
---|
150 | newsletterCore::send($rs->subscriber_id,'suspend'); |
---|
151 | $msg = __('Your account is suspended.').'<br />'.__('You will soon receive an email.'); |
---|
152 | } |
---|
153 | } |
---|
154 | break; |
---|
155 | |
---|
156 | case 'changemode': |
---|
157 | if ($email == null) |
---|
158 | $msg = __('Missing informations'); |
---|
159 | else { |
---|
160 | $rs = newsletterCore::getemail($email); |
---|
161 | if ($rs == null) |
---|
162 | $msg = __('Unable to find you account informations.'); |
---|
163 | else { |
---|
164 | newsletterCore::send($rs->subscriber_id,'changemode'); |
---|
165 | $msg = __('Your sending format is').$modesend.'<br />'.__('You will soon receive an email.'); |
---|
166 | } |
---|
167 | } |
---|
168 | break; |
---|
169 | |
---|
170 | case 'submit': |
---|
171 | $email = (string)html::clean($_POST['nl_email']); |
---|
172 | $option = (string)html::clean($_POST['nl_option']); |
---|
173 | //$modesend = (string)html::clean($_POST['nl_modesend']); |
---|
174 | $check = true; |
---|
175 | $newsletter_settings = new newsletterSettings($core); |
---|
176 | if ($newsletter_settings->getCaptcha()) { |
---|
177 | $captcha = (string)html::clean($_POST['nl_captcha']); |
---|
178 | $read = Captcha::read(); |
---|
179 | if ($read != $captcha) { |
---|
180 | $check = false; |
---|
181 | $ca = new Captcha(80, 30, 5); |
---|
182 | $ca->generate(); |
---|
183 | $ca->file(); |
---|
184 | $ca->write(); |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | if (!$check) { |
---|
189 | $msg = __('Bad captcha code'); |
---|
190 | } else switch ($option) { |
---|
191 | case 'subscribe': |
---|
192 | $msg = newsletterCore::accountCreate($email,null,$modesend); |
---|
193 | break; |
---|
194 | |
---|
195 | case 'unsubscribe': |
---|
196 | $msg = newsletterCore::accountDelete($email); |
---|
197 | break; |
---|
198 | |
---|
199 | case 'suspend': |
---|
200 | $msg = newsletterCore::accountSuspend($email); |
---|
201 | break; |
---|
202 | |
---|
203 | case 'resume': |
---|
204 | $msg = newsletterCore::accountResume($email); |
---|
205 | break; |
---|
206 | |
---|
207 | case 'changemode': |
---|
208 | $msg = newsletterCore::accountChangeMode($email,$modesend); |
---|
209 | break; |
---|
210 | |
---|
211 | default: |
---|
212 | $msg = __('Error in formular.').' option = '.$option; |
---|
213 | //$msg = __('Error in formular.'); |
---|
214 | break; |
---|
215 | } |
---|
216 | break; |
---|
217 | |
---|
218 | default: |
---|
219 | $msg = ''; |
---|
220 | break; |
---|
221 | } |
---|
222 | |
---|
223 | return $msg; |
---|
224 | } |
---|
225 | |
---|
226 | /** |
---|
227 | * title page |
---|
228 | */ |
---|
229 | public static function NewsletterPageTitle() |
---|
230 | { |
---|
231 | global $core; |
---|
232 | $newsletter_settings = new newsletterSettings($core); |
---|
233 | //return __('Newsletter'); |
---|
234 | return $newsletter_settings->getFormTitlePage(); |
---|
235 | } |
---|
236 | |
---|
237 | /** |
---|
238 | * indication à l'utilisateur que la page newsletter n'a pas été initialisée |
---|
239 | */ |
---|
240 | public static function NewsletterTemplateNotSet() |
---|
241 | { |
---|
242 | return '<?php echo newsletterCore::TemplateNotSet(); ?>'; |
---|
243 | } |
---|
244 | |
---|
245 | public static function NewsletterBlock($attr, $content) |
---|
246 | { |
---|
247 | return $content; |
---|
248 | } |
---|
249 | |
---|
250 | public static function NewsletterMessageBlock($attr, $content) |
---|
251 | { |
---|
252 | $text = '<?php echo "'. |
---|
253 | '<form action=\"'.newsletterCore::url('form').'\" method=\"post\" id=\"comment-form\" class=\"newsletter\">'. |
---|
254 | '<fieldset>'. |
---|
255 | '<p class=\"field\">'. |
---|
256 | '" ?>'. |
---|
257 | html::decodeEntities($content). |
---|
258 | '<?php echo "'. |
---|
259 | '</p>'. |
---|
260 | '<p>'. |
---|
261 | '<input type=\"submit\" name=\"nl_back\" id=\"nl_back\" value=\"'.__('Back').'\" class=\"submit\" />'. |
---|
262 | '</p>'. |
---|
263 | '</fieldset>'. |
---|
264 | '</form>'. |
---|
265 | '" ?>'; |
---|
266 | |
---|
267 | return '<?php if (!empty($GLOBALS[\'newsletter\'][\'msg\'])) { ?>'.$text.'<?php } ?>'; |
---|
268 | } |
---|
269 | |
---|
270 | public static function NewsletterFormBlock($attr, $content) |
---|
271 | { |
---|
272 | return '<?php if (!empty($GLOBALS[\'newsletter\'][\'form\'])) { ?>'.$content.'<?php } ?>'; |
---|
273 | } |
---|
274 | |
---|
275 | public static function NewsletterFormSubmit() |
---|
276 | { |
---|
277 | return '<?php echo newsletterCore::url(\'submit\'); ?>'; |
---|
278 | } |
---|
279 | |
---|
280 | public static function NewsletterFormRandom() |
---|
281 | { |
---|
282 | return '<?php echo "'.newsletterTools::getRandom().'" ?>'; |
---|
283 | } |
---|
284 | |
---|
285 | public static function NewsletterFormCaptchaImg() |
---|
286 | { |
---|
287 | return '<?php echo "<img src=\"'.Captcha::www().'/captcha.img.png\" style=\"vertical-align: middle;\" alt=\"'.__('Captcha').'\" />" ?>'; |
---|
288 | } |
---|
289 | |
---|
290 | public static function NewsletterFormCaptchaInput() |
---|
291 | { |
---|
292 | return '<?php echo "<p><input type=\"text\" name=\"nl_captcha\" id=\"nl_captcha\" value=\"\" style=\"width:90px; vertical-align:top;\" /></p>" ?>'; |
---|
293 | } |
---|
294 | |
---|
295 | public static function NewsletterFormLabel($attr, $content) |
---|
296 | { |
---|
297 | switch ($attr['id']) |
---|
298 | { |
---|
299 | case 'ok': |
---|
300 | return '<?php echo __(\'Send\') ?>'; |
---|
301 | |
---|
302 | case 'subscribe': |
---|
303 | return '<?php echo __(\'Subscribe\') ?>'; |
---|
304 | |
---|
305 | case 'unsubscribe': |
---|
306 | return '<?php echo __(\'Unsubscribe\') ?>'; |
---|
307 | |
---|
308 | case 'suspend': |
---|
309 | return '<?php echo __(\'Suspend\') ?>'; |
---|
310 | // __('Suspend') |
---|
311 | |
---|
312 | case 'resume': |
---|
313 | return '<?php echo __(\'Resume\') ?>'; |
---|
314 | // __('Resume') |
---|
315 | |
---|
316 | case 'nl_email': |
---|
317 | return '<?php echo __(\'Email\') ?>'; |
---|
318 | |
---|
319 | case 'nl_option': |
---|
320 | return '<?php echo __(\'Action\') ?>'; |
---|
321 | |
---|
322 | case 'nl_captcha': |
---|
323 | return '<?php echo \'<label for="nl_captcha">\'. __(\'Captcha\') .\'</label>\' ?>'; |
---|
324 | |
---|
325 | case 'nl_submit': |
---|
326 | return ''; |
---|
327 | |
---|
328 | case 'html': |
---|
329 | return '<?php echo __(\'html\') ?>'; |
---|
330 | |
---|
331 | case 'text': |
---|
332 | return '<?php echo __(\'text\') ?>'; |
---|
333 | // __('text') |
---|
334 | |
---|
335 | case 'nl_modesend': |
---|
336 | return '<?php echo __(\'Format\') ?>'; |
---|
337 | |
---|
338 | case 'changemode': |
---|
339 | return '<?php echo __(\'Change format\') ?>'; |
---|
340 | // __('Change format') |
---|
341 | |
---|
342 | case 'back': |
---|
343 | return '<?php echo __(\'Back\') ?>'; |
---|
344 | |
---|
345 | } |
---|
346 | } |
---|
347 | |
---|
348 | public static function NewsletterMsgPresentationForm() |
---|
349 | { |
---|
350 | global $core; |
---|
351 | $newsletter_settings = new newsletterSettings($core); |
---|
352 | return $newsletter_settings->getMsgPresentationForm(); |
---|
353 | } |
---|
354 | |
---|
355 | public static function NewsletterIfUseDefaultFormat($attr,$content) |
---|
356 | { |
---|
357 | global $core; |
---|
358 | $newsletter_settings = new newsletterSettings($core); |
---|
359 | return (!$newsletter_settings->getUseDefaultFormat()? $content : ''); |
---|
360 | } |
---|
361 | |
---|
362 | public static function NewsletterFormFormatSelect($attr,$content) |
---|
363 | { |
---|
364 | $text = '<?php echo "'. |
---|
365 | '<label for=\"nl_modesend\">'.__('Format').' :</label>'. |
---|
366 | '<select style=\"border:1px inset silver; width:150px;\" name=\"nl_modesend\" id=\"nl_modesend\" size=\"1\">'. |
---|
367 | '<option value=\"html\" selected=\"selected\">'.__('html').'</option>'. |
---|
368 | '<option value=\"text\">'.__('text').'</option>'. |
---|
369 | '</select>'. |
---|
370 | '" ?>'; |
---|
371 | |
---|
372 | return $text; |
---|
373 | } |
---|
374 | |
---|
375 | public static function NewsletterFormActionSelect($attr,$content) |
---|
376 | { |
---|
377 | global $core; |
---|
378 | $newsletter_settings = new newsletterSettings($core); |
---|
379 | |
---|
380 | $text = '<?php echo "'. |
---|
381 | '<label for=\"nl_option\">'.__('Action').' :</label>'. |
---|
382 | '<select style=\"border:1px inset silver; width:150px;\" name=\"nl_option\" id=\"nl_option\" size=\"1\">'. |
---|
383 | '<option value=\"subscribe\" selected=\"selected\">'.__('Subscribe').'</option>'; |
---|
384 | |
---|
385 | if(!$newsletter_settings->getUseDefaultFormat()) { |
---|
386 | $text .= '<option value=\"changemode\">'.__('Change format').'</option>'; |
---|
387 | } |
---|
388 | |
---|
389 | if($newsletter_settings->getCheckUseSuspend()) { |
---|
390 | $text .= '<option value=\"suspend\">'.__('Suspend').'</option>'; |
---|
391 | } |
---|
392 | |
---|
393 | $text .= '<option value=\"resume\">'.__('Resume').'</option>'. |
---|
394 | '<option value=\"\">---</option>'. |
---|
395 | '<option value=\"unsubscribe\">'.__('Unsubscribe').'</option>'. |
---|
396 | '</select>'. |
---|
397 | '" ?>'; |
---|
398 | return $text; |
---|
399 | } |
---|
400 | |
---|
401 | public static function NewsletterIfUseCaptcha($attr,$content) |
---|
402 | { |
---|
403 | global $core; |
---|
404 | $newsletter_settings = new newsletterSettings($core); |
---|
405 | if (!empty($GLOBALS['newsletter']['form']) && $newsletter_settings->getCaptcha()) { |
---|
406 | $ca = new Captcha(80, 30, 5); |
---|
407 | $ca->generate(); |
---|
408 | $ca->file(); |
---|
409 | $ca->write(); |
---|
410 | } |
---|
411 | return ($newsletter_settings->getCaptcha()? $content : ''); |
---|
412 | } |
---|
413 | |
---|
414 | } |
---|
415 | |
---|
416 | class publicWidgetsNewsletter |
---|
417 | { |
---|
418 | /** |
---|
419 | * initialize widget |
---|
420 | */ |
---|
421 | public static function initWidgets($w) |
---|
422 | { |
---|
423 | global $core; |
---|
424 | |
---|
425 | # Settings compatibility test |
---|
426 | if (version_compare(DC_VERSION,'2.2-alpha','>=')) { |
---|
427 | $blog_settings =& $core->blog->settings->newsletter; |
---|
428 | $system_settings =& $core->blog->settings->system; |
---|
429 | } else { |
---|
430 | $blog_settings =& $core->blog->settings; |
---|
431 | $system_settings =& $core->blog->settings; |
---|
432 | } |
---|
433 | |
---|
434 | try { |
---|
435 | $newsletter_flag = (boolean)$blog_settings->newsletter_flag; |
---|
436 | |
---|
437 | // prise en compte de l'état d'activation du plugin |
---|
438 | if (!$newsletter_flag) |
---|
439 | return; |
---|
440 | |
---|
441 | // prise en compte paramètre: uniquement sur la page d'accueil |
---|
442 | $url = &$core->url; |
---|
443 | if ($w->homeonly && $url->type != 'default') { |
---|
444 | return; |
---|
445 | } |
---|
446 | |
---|
447 | // paramétrage des variables |
---|
448 | $plugin_name = __('Newsletter'); |
---|
449 | $title = ($w->title) ? html::escapeHTML($w->title) : $plugin_name; |
---|
450 | $showTitle = ($w->showtitle) ? true : false; |
---|
451 | $subscription_link = ($w->subscription_link) ? html::escapeHTML($w->subscription_link) : __('Subscription link'); |
---|
452 | |
---|
453 | $text = ''; |
---|
454 | |
---|
455 | $newsletter_settings = new newsletterSettings($core); |
---|
456 | |
---|
457 | // mise en place du contenu du widget dans $text |
---|
458 | if ($w->inwidget) { |
---|
459 | $link = newsletterCore::url('submit'); |
---|
460 | $text .= |
---|
461 | '<form action="'.$link.'" method="post" id="nl_form">'."\n". |
---|
462 | "<p>\n". |
---|
463 | $core->formNonce(). |
---|
464 | form::hidden(array('nl_random'),newsletterTools::getRandom()). |
---|
465 | "</p>\n". |
---|
466 | '<p>'. |
---|
467 | '<label for="nl_email">'.__('Email').'</label> : '. |
---|
468 | form::field(array('nl_email','nl_email'),15,255). |
---|
469 | '</p>'; |
---|
470 | |
---|
471 | if(!$newsletter_settings->getUseDefaultFormat()) { |
---|
472 | $text .= '<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 | } |
---|
478 | |
---|
479 | $text .= '<p><label for="nl_submit">'.__('Actions').'</label> : '. |
---|
480 | '<select style="border:1px inset silver; width:140px;" name="nl_option" id="nl_option" size="1">'. |
---|
481 | '<option value="subscribe" selected="selected">'.__('Subscribe').'</option>'; |
---|
482 | |
---|
483 | if(!$newsletter_settings->getUseDefaultFormat()) { |
---|
484 | $text .= '<option value="changemode">'.__('Change format').'</option>'; |
---|
485 | } |
---|
486 | |
---|
487 | if($newsletter_settings->getCheckUseSuspend()) { |
---|
488 | $text .= '<option value=\"suspend\">'.__('Suspend').'</option>'; |
---|
489 | } |
---|
490 | |
---|
491 | $text .= |
---|
492 | '<option value="resume">'.__('Resume').'</option>'. |
---|
493 | '<option value="">---</option>'. |
---|
494 | '<option value="unsubscribe">'.__('Unsubscribe').'</option>'. |
---|
495 | '</select>'. |
---|
496 | /* |
---|
497 | '<li><label for="nl_submit">'.__('Actions').'</label> :<br />'. |
---|
498 | form::radio(array('nl_option'),'subscribe', true).__('Subscribe').'<br />'. |
---|
499 | form::radio(array('nl_option'),'unsubscribe').__('Unsubscribe').'<br />'. |
---|
500 | //*/ |
---|
501 | '</p>'; |
---|
502 | |
---|
503 | if ($newsletter_settings->getCaptcha()) { |
---|
504 | require_once dirname(__FILE__).'/inc/class.captcha.php'; |
---|
505 | $as = new Captcha(80, 30, 5); |
---|
506 | $as->generate(); |
---|
507 | $as->file(); |
---|
508 | $as->write(); |
---|
509 | |
---|
510 | $text .= |
---|
511 | //'<p>'. |
---|
512 | '<p><label for="nl_captcha">'.__('Captcha').'</label> :<br />'. |
---|
513 | '<img src="'.Captcha::www().'/captcha.img.png" alt="'.__('Captcha').'" /><br />'. |
---|
514 | form::field(array('nl_captcha','nl_captcha'),9,30). |
---|
515 | '</p>'; |
---|
516 | //'</p>'. |
---|
517 | } |
---|
518 | |
---|
519 | $text .= |
---|
520 | '<p><input class="submit" type="submit" name="nl_submit" id="nl_submit" value="'.__('Send').'" /></p>'. |
---|
521 | |
---|
522 | //'</ul>'. |
---|
523 | //'</fieldset>'. |
---|
524 | '</form>'; |
---|
525 | |
---|
526 | } else { |
---|
527 | $link = newsletterCore::url('form'); |
---|
528 | if ($w->insublink) { |
---|
529 | $title = str_replace('%I', '<img src="?pf=newsletter/icon.png" alt="" width="16" height="16" style="margin: 0 3px; vertical-align: middle;" />', $title); |
---|
530 | $text = $w->text ? $w->text : ''; |
---|
531 | |
---|
532 | $text .= '<ul><li><a href="'.$link.'">'.$subscription_link.'</a></li></ul>'; |
---|
533 | } else { |
---|
534 | $title = '<a href="'.$link.'">'.$title.'</a>'; |
---|
535 | $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); |
---|
536 | } |
---|
537 | } |
---|
538 | |
---|
539 | // renvoi du code à afficher pour le widget |
---|
540 | if ($showTitle === true) |
---|
541 | $title = '<h2>'.$title.'</h2>'; |
---|
542 | else |
---|
543 | $title = ''; |
---|
544 | |
---|
545 | return "\n".'<div class="'.newsletterPlugin::pname().'">'.$title.$text.'</div>'."\n"; |
---|
546 | //return "\n".'<div class="categories">'.$title.$text.'</div>'."\n"; |
---|
547 | |
---|
548 | } catch (Exception $e) { |
---|
549 | $core->error->add($e->getMessage()); |
---|
550 | } |
---|
551 | } |
---|
552 | } |
---|
553 | |
---|
554 | // URL handler |
---|
555 | class urlNewsletter extends dcUrlHandlers |
---|
556 | { |
---|
557 | public static function newsletter($args) |
---|
558 | { |
---|
559 | $core = $GLOBALS['core']; |
---|
560 | $_ctx = $GLOBALS['_ctx']; |
---|
561 | |
---|
562 | if($args == '') { |
---|
563 | # The specified Preview URL is malformed. |
---|
564 | self::p404(); |
---|
565 | } |
---|
566 | |
---|
567 | // initialisation des variables |
---|
568 | $flag = 0; |
---|
569 | $cmd = null; |
---|
570 | $GLOBALS['newsletter']['cmd'] = null; |
---|
571 | $GLOBALS['newsletter']['msg'] = false; |
---|
572 | $GLOBALS['newsletter']['form'] = false; |
---|
573 | $GLOBALS['newsletter']['email'] = null; |
---|
574 | $GLOBALS['newsletter']['code'] = null; |
---|
575 | $GLOBALS['newsletter']['modesend'] = null; |
---|
576 | |
---|
577 | // décomposition des arguments et aiguillage |
---|
578 | $params = explode('/', $args); |
---|
579 | if (isset($params[0]) && !empty($params[0])) |
---|
580 | $cmd = (string)html::clean($params[0]); |
---|
581 | else |
---|
582 | $cmd = null; |
---|
583 | |
---|
584 | if (isset($params[1]) && !empty($params[1])) { |
---|
585 | $email = newsletterTools::base64_url_decode((string)html::clean($params[1])); |
---|
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 | switch ($cmd) { |
---|
600 | case 'test': |
---|
601 | case 'about': |
---|
602 | $GLOBALS['newsletter']['msg'] = true; |
---|
603 | break; |
---|
604 | |
---|
605 | case 'form': |
---|
606 | $GLOBALS['newsletter']['form'] = true; |
---|
607 | break; |
---|
608 | |
---|
609 | case 'submit': |
---|
610 | $GLOBALS['newsletter']['msg'] = true; |
---|
611 | break; |
---|
612 | |
---|
613 | case 'confirm': |
---|
614 | case 'enable': |
---|
615 | case 'disable': |
---|
616 | case 'suspend': |
---|
617 | case 'changemode': |
---|
618 | case 'resume': |
---|
619 | { |
---|
620 | if ($email == null) { |
---|
621 | self::p404(); |
---|
622 | } |
---|
623 | $GLOBALS['newsletter']['msg'] = true; |
---|
624 | break; |
---|
625 | } |
---|
626 | |
---|
627 | default: |
---|
628 | { |
---|
629 | $flag = 1; |
---|
630 | self::letter($args); |
---|
631 | break; |
---|
632 | } |
---|
633 | } |
---|
634 | |
---|
635 | if (!$flag) { |
---|
636 | |
---|
637 | $GLOBALS['newsletter']['cmd'] = $cmd; |
---|
638 | $GLOBALS['newsletter']['email'] = $email; |
---|
639 | $GLOBALS['newsletter']['code'] = $regcode; |
---|
640 | $GLOBALS['newsletter']['modesend'] = $modesend; |
---|
641 | |
---|
642 | // Affichage du formulaire |
---|
643 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
644 | $file = $core->tpl->getFilePath('subscribe.newsletter.html'); |
---|
645 | files::touch($file); |
---|
646 | //self::serveDocument('subscribe.newsletter.html'); |
---|
647 | self::serveDocument('subscribe.newsletter.html','text/html',false,false); |
---|
648 | } |
---|
649 | } |
---|
650 | |
---|
651 | public static function letterpreview($args) |
---|
652 | { |
---|
653 | $core = $GLOBALS['core']; |
---|
654 | $_ctx = $GLOBALS['_ctx']; |
---|
655 | |
---|
656 | if (!preg_match('#^(.+?)/([0-9a-z]{40})/(.+?)$#',$args,$m)) { |
---|
657 | # The specified Preview URL is malformed. |
---|
658 | self::p404(); |
---|
659 | } |
---|
660 | else |
---|
661 | { |
---|
662 | $user_id = $m[1]; |
---|
663 | $user_key = $m[2]; |
---|
664 | $post_url = $m[3]; |
---|
665 | if (!$core->auth->checkUser($user_id,null,$user_key)) { |
---|
666 | # The user has no access to the entry. |
---|
667 | self::p404(); |
---|
668 | } |
---|
669 | else |
---|
670 | { |
---|
671 | $_ctx->preview = true; |
---|
672 | self::letter($post_url); |
---|
673 | } |
---|
674 | } |
---|
675 | } |
---|
676 | |
---|
677 | public static function letter($args) |
---|
678 | { |
---|
679 | if ($args == '') { |
---|
680 | # No page was specified. |
---|
681 | self::p404(); |
---|
682 | } |
---|
683 | else |
---|
684 | { |
---|
685 | $_ctx =& $GLOBALS['_ctx']; |
---|
686 | $core =& $GLOBALS['core']; |
---|
687 | |
---|
688 | $core->blog->withoutPassword(false); |
---|
689 | |
---|
690 | $params = new ArrayObject(); |
---|
691 | $params['post_type'] = 'newsletter'; |
---|
692 | $params['post_url'] = $args; |
---|
693 | |
---|
694 | $_ctx->posts = $core->blog->getPosts($params); |
---|
695 | |
---|
696 | $_ctx->comment_preview = new ArrayObject(); |
---|
697 | $_ctx->comment_preview['content'] = ''; |
---|
698 | $_ctx->comment_preview['rawcontent'] = ''; |
---|
699 | $_ctx->comment_preview['name'] = ''; |
---|
700 | $_ctx->comment_preview['mail'] = ''; |
---|
701 | $_ctx->comment_preview['site'] = ''; |
---|
702 | $_ctx->comment_preview['preview'] = false; |
---|
703 | $_ctx->comment_preview['remember'] = false; |
---|
704 | |
---|
705 | $core->blog->withoutPassword(true); |
---|
706 | |
---|
707 | |
---|
708 | if ($_ctx->posts->isEmpty()) |
---|
709 | { |
---|
710 | # The specified page does not exist. |
---|
711 | self::p404(); |
---|
712 | } |
---|
713 | else |
---|
714 | { |
---|
715 | $post_id = $_ctx->posts->post_id; |
---|
716 | $post_password = $_ctx->posts->post_password; |
---|
717 | |
---|
718 | # Password protected entry |
---|
719 | if ($post_password != '' && !$_ctx->preview) |
---|
720 | { |
---|
721 | # Get passwords cookie |
---|
722 | if (isset($_COOKIE['dc_passwd'])) { |
---|
723 | $pwd_cookie = unserialize($_COOKIE['dc_passwd']); |
---|
724 | } else { |
---|
725 | $pwd_cookie = array(); |
---|
726 | } |
---|
727 | |
---|
728 | # Check for match |
---|
729 | if ((!empty($_POST['password']) && $_POST['password'] == $post_password) |
---|
730 | || (isset($pwd_cookie[$post_id]) && $pwd_cookie[$post_id] == $post_password)) |
---|
731 | { |
---|
732 | $pwd_cookie[$post_id] = $post_password; |
---|
733 | setcookie('dc_passwd',serialize($pwd_cookie),0,'/'); |
---|
734 | } |
---|
735 | else |
---|
736 | { |
---|
737 | self::serveDocument('password-form.html','text/html',false); |
---|
738 | return; |
---|
739 | } |
---|
740 | } |
---|
741 | |
---|
742 | |
---|
743 | # The entry |
---|
744 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
745 | //self::serveDocument('letter.html'); |
---|
746 | self::serveDocument('letter.html'); |
---|
747 | //self::serveDocument('subscribe.newsletter.html'); |
---|
748 | } |
---|
749 | } |
---|
750 | } |
---|
751 | } |
---|
752 | |
---|
753 | // Define behaviors |
---|
754 | class dcBehaviorsNewsletterPublic |
---|
755 | { |
---|
756 | public static function publicHeadContent(dcCore $core,$_ctx) |
---|
757 | { |
---|
758 | if($core->url->type == "newsletter") { |
---|
759 | $letter_css = new newsletterCSS($core); |
---|
760 | $css_style = '<style type="text/css" media="screen">'; |
---|
761 | $css_style .= $letter_css->getLetterCSS(); |
---|
762 | $css_style .= '</style>'; |
---|
763 | echo $css_style; |
---|
764 | } |
---|
765 | } |
---|
766 | |
---|
767 | //public static function translateKeywords(dcCore $core, $tag, $args, $attr,$content) |
---|
768 | public static function translateKeywords(dcCore $core, $tag, $args) |
---|
769 | { |
---|
770 | global $_ctx; |
---|
771 | if($tag != 'EntryContent' //tpl value |
---|
772 | || $args[0] == '' //content |
---|
773 | || $args[2] // remove html |
---|
774 | || $core->url->type != 'newsletter' |
---|
775 | ) return; |
---|
776 | |
---|
777 | $nltr = new newsletterLetter($core,(integer)$_ctx->posts->post_id); |
---|
778 | $body = $args[0]; |
---|
779 | |
---|
780 | $body = $nltr->rendering($body, $_ctx->posts->getURL()); |
---|
781 | $args[0] = $nltr->renderingSubscriber($body, ''); |
---|
782 | |
---|
783 | return; |
---|
784 | } |
---|
785 | |
---|
786 | } |
---|
787 | |
---|
788 | ?> |
---|