OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / libs / NOTIFICATION.php
1 <<<<<<< HEAD
2 <?php\r
3 /*\r
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
5  * Copyright (C) 2002-2012 The Nucleus Group\r
6  *\r
7  * This program is free software; you can redistribute it and/or\r
8  * modify it under the terms of the GNU General Public License\r
9  * as published by the Free Software Foundation; either version 2\r
10  * of the License, or (at your option) any later version.\r
11  * (see nucleus/documentation/index.html#license for more info)\r
12  */\r
13 /**\r
14  * Class used to represent a collection of e-mail addresses, to which a\r
15  * message can be sent (e.g. comment or karma vote notification).\r
16  *\r
17  * @license http://nucleuscms.org/license.txt GNU General Public License\r
18  * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
19  * @version $Id: NOTIFICATION.php 1534 2011-06-22 06:13:23Z sakamocchi $\r
20  */\r
21 class Notification\r
22 {\r
23         static private $charset;\r
24         static private $scheme = 'B';\r
25         \r
26         /**\r
27          * NOTIFICATION::address_validation()\r
28          * Validating the string as address\r
29          * \r
30          * FIXME: this is just migrated from globalfunctions.php\r
31          *  we should confirm this regular expression refering to RFC 5322\r
32          * \r
33          * @link        http://www.ietf.org/rfc/rfc5322.txt\r
34          * @see         3.4. Address Specification\r
35          * \r
36          * @static\r
37          * @param       String  $address        Address\r
38          * @return      Boolean valid or not\r
39          */\r
40         static public function address_validation($address)\r
41         {\r
42                 return (boolean) preg_match('#^(?!\\.)(?:\\.?[-a-zA-Z0-9!\\#$%&\'*+/=?^_`{|}~]+)+@(?!\\.)(?:\\.?(?!-)[-a-zA-Z0-9]+(?<!-)){2,}$#', $address);\r
43         }\r
44         \r
45         /**\r
46          * NOTIFICATION::get_mail_footer()\r
47          * Return mail footer with Nucleus CMS singnature\r
48          * \r
49          * @static\r
50          * @param       void\r
51          * @return      String  Message body with \r
52          */\r
53         static public function get_mail_footer()\r
54         {\r
55                 $message  = "\n";\r
56                 $message .= "\n";\r
57                 $message .= "-----------------------------\n";\r
58                 $message .=  "   Powered by Nucleus CMS\n";\r
59                 $message .=  "(http://www.nucleuscms.org/)\n";\r
60                 return $message;\r
61         }\r
62         \r
63         /**\r
64          * NOTIFICATION::mail\r
65          * Send mails with headers including 7bit-encoded multibyte string\r
66          * \r
67          * @static\r
68          * @param       string  $to             receivers including singlebyte and multibyte strings, based on RFC 5322\r
69          * @param       string  $subject        subject including singlebyte and multibyte strings\r
70          * @param       string  $message        message including singlebyte and multibyte strings\r
71          * @param       string  $from           senders including singlebyte and multibyte strings, based on RFC 5322\r
72          * @param       string(B/Q)     $scheme 7bit-encoder scheme based on RFC 2047\r
73          * @return      boolean accepted delivery or not\r
74          */\r
75         static public function mail($to, $subject, $message, $from, $charset, $scheme='B')\r
76         {\r
77                 self::$charset = $charset;\r
78                 self::$scheme = $scheme;\r
79                 \r
80                 $to = self::mailbox_list_encoder($to);\r
81                 $subject = self::seven_bit_characters_encoder($subject);\r
82                 $from = 'From: ' . self::mailbox_list_encoder($from);\r
83                 \r
84                 /*\r
85                  * All of 7bit character encoding derives from ISO/IEC 646\r
86                  * So we can decide the body's encoding bit count by this regular expression.\r
87                  * \r
88                  */\r
89                 $bitcount = '8bit';\r
90                 if ( preg_match('#\A[\x00-\x7f]*\z#', $message) )\r
91                 {\r
92                         $bitcount = '7bit';\r
93                 }\r
94                 \r
95                 $header  = 'Content-Type: text/html; charset=' . self::$charset . "; format=flowed; delsp=yes\n";\r
96                 $header .= "Content-Transfer-Encoding: {$bitcount}\n";\r
97                 $header .= "X-Mailer: Nucleus CMS NOTIFICATION class\n";\r
98                 \r
99                 return mail($to, $subject, $message, "{$from}\n{$header}");\r
100         }\r
101         \r
102         /**\r
103          * NOTIFICATION::mailbox_list_encoder\r
104          * Encode multi byte strings included in mailbox.\r
105          * The format of mailbox is based on RFC 5322, which obsoletes RFC 2822\r
106          * \r
107          * @link        http://www.ietf.org/rfc/rfc5322.txt\r
108          * @see         3.4. Address Specification\r
109          * \r
110          * @static\r
111          * @param       string  $mailbox_list           mailbox list\r
112          * @return      string  encoded string  \r
113          * \r
114          */\r
115         static private function mailbox_list_encoder ($mailbox_list)\r
116         {\r
117                 $encoded_mailboxes = array();\r
118                 $mailboxes = preg_split('#,#', $mailbox_list);\r
119                 foreach ( $mailboxes as $mailbox )\r
120                 {\r
121                         if ( preg_match("#^([^,]+)?<([^,]+)?@([^,]+)?>$#", $mailbox, $match) )\r
122                         {\r
123                                 $display_name = self::seven_bit_characters_encoder(trim($match[1]));\r
124                                 $local_part = trim($match[2]);\r
125                                 $domain = trim($match[3]);\r
126                                 $encoded_mailboxes[] = "{$display_name} <{$local_part}@{$domain}>";\r
127                         }\r
128                         else if ( preg_match("#([^,]+)?@([^,]+)?#", $mailbox) )\r
129                         {\r
130                                 $encoded_mailboxes[] = $mailbox;\r
131                         }\r
132                         else\r
133                         {\r
134                                 continue;\r
135                         }\r
136                 }\r
137                 if ( $encoded_mailboxes == array() )\r
138                 {\r
139                         return FALSE;\r
140                 }\r
141                 return implode(',', $encoded_mailboxes);\r
142         }\r
143         \r
144         /**\r
145          * NOTIFICATION::seven_bit_characters_encoder\r
146          * Encoder into 7bit ASCII expression for Non-ASCII Text based on RFC 2047.\r
147          * \r
148          * @link http://www.ietf.org/rfc/rfc2047.txt\r
149          * @see 2. Syntax of encoded-words\r
150          * \r
151          * NOTE: RFC 2047 has a ambiguousity for dealing with 'linear-white-space'.\r
152          *  This causes a trouble related to line breaking between single byte and multi-byte strings.\r
153          *  To avoid this, single byte string is encoded as well as multi byte string here.\r
154          * \r
155          * NOTE: RFC 2231 also defines the way to use non-ASCII characters in MIME header.\r
156          * http://www.ietf.org/rfc/rfc2231.txt\r
157          * \r
158          * NOTE: iconv extension give the same functions as this in PHP5\r
159          * iconv_mime_encode():\r
160          * http://www.php.net/manual/en/function.iconv-mime-encode.php\r
161          * \r
162          * @static\r
163          * @param       string  $charset        Character set encoding\r
164          * @param       string  $type   type of 7 bit encoding, should be 'B' or 'Q'\r
165          * @param       string  $string Target string with header field\r
166          * @return      string  encoded string\r
167          * \r
168          */\r
169         static private function seven_bit_characters_encoder($string)\r
170         {\r
171                 $header = chr(13) . chr(10) . chr(32) . '=?' . self::$charset . '?' . self::$scheme . '?';\r
172                 $footer = "?=";\r
173                 $restriction = 78 - strlen($header) - strlen($footer) ;\r
174                 \r
175                 $encoded_words = array();\r
176                 for ( $i = 0; $i < i18n::strlen($string); $i++ )\r
177                 {\r
178                         if ( self::$scheme == 'B' )\r
179                         {\r
180                                 if ( $i == 0 )\r
181                                 {\r
182                                         $letters = '';\r
183                                 }\r
184                                 \r
185                                 $letter = i18n::substr($string, $i, 1);\r
186                                 $expected_length = strlen($letters) + strlen($letter) * 4 / 3;\r
187                                 \r
188                                 if ( $expected_length > $restriction )\r
189                                 {\r
190                                         $encoded_text = self::b_encoder($letters);\r
191                                         $encoded_words[] = "{$header}{$encoded_text}{$footer}";\r
192                                         $letters = '';\r
193                                 }\r
194                                 \r
195                                 $letters .= $letter;\r
196                                 \r
197                                 if ( $i == i18n::strlen($string) - 1 )\r
198                                 {\r
199                                         $encoded_text = self::b_encoder($letters);\r
200                                         $encoded_words[] = "{$header}{$encoded_text}{$footer}";\r
201                                         break;\r
202                                 }\r
203                                 continue;\r
204                         }\r
205                         else\r
206                         {\r
207                                 if ( $i == 0 )\r
208                                 {\r
209                                         $encoded_text = '';\r
210                                 }\r
211                                 \r
212                                 $encoded_letter = self::q_encoder(i18n::substr($string, $i, 1));\r
213                                 $expected_length = strlen($encoded_text) + strlen($encoded_letter);\r
214                                 \r
215                                 if ( $expected_length > $restriction )\r
216                                 {\r
217                                         $encoded_words[] = "{$header}{$encoded_text}{$footer}";\r
218                                         $letters = '';\r
219                                 }\r
220                                 \r
221                                 $encoded_text .= $encoded_letter;\r
222                                 \r
223                                 if ( $i == i18n::strlen($string) - 1 )\r
224                                 {\r
225                                         $encoded_words[] = "{$header}{$encoded_text}{$footer}";\r
226                                         break;\r
227                                 }\r
228                                 continue;\r
229                         }\r
230                 }\r
231                 \r
232                 return implode('', $encoded_words);\r
233         }\r
234         \r
235         /**\r
236          * NOTIFICATION::b_encoder()\r
237          * \r
238          * B encoder according to RFC 2047.\r
239          * The "B" encoding is identical to the "BASE64" encoding defined by RFC 4648.\r
240          * \r
241          * @link http://www.ietf.org/rfc/rfc4648.txt\r
242          * @see 6.8. Base64 Content-Transfer-Encoding\r
243          * \r
244          * NOTE: According to RFC 4648\r
245          * (1)  The final quantum of encoding input is an integral multiple of 24 bits;\r
246          *              here, the final unit of encoded output will be an integral multiple\r
247          *              of 4 characters with no "=" padding.\r
248          * (2)  The final quantum of encoding input is exactly 8 bits; here,\r
249          *              the final unit of encoded output will be two characters followed\r
250          *              by two "=" padding characters.\r
251          * (3)  The final quantum of encoding input is exactly 16 bits; here,\r
252          *              the final unit of encoded output will be three characters followed\r
253          *              by one "=" padding character.\r
254          * \r
255          * @static\r
256          * @param       string  $target targetted string\r
257          * @return      string  encoded string\r
258          */\r
259         static private function b_encoder($target)\r
260         {\r
261                 return base64_encode($target);\r
262         }\r
263         \r
264         /**\r
265          * NOTIFICATION::q_encoder()\r
266          * \r
267          * Q encoder according to RFC 2047.\r
268          * The "Q" encoding is similar to "Quoted-Printable" content-transfer-encoding defined in RFC 2045,\r
269          *  but the "Q" encoding and the "Quoted-Printable" are different a bit.\r
270          * \r
271          * @link http://www.ietf.org/rfc/rfc2047.txt\r
272          * @see 4.2. The "Q" encoding\r
273          * \r
274          * NOTE: According to RFC 2047\r
275          * (1)  Any 8-bit value may be represented by a "=" followed by two hexadecimal digits.\r
276          *              For example, if the character set in use were ISO-8859-1,\r
277          *              the "=" character would thus be encoded as "=3D", and a SPACE by "=20".\r
278          *              (Upper case should be used for hexadecimal digits "A" through "F".)\r
279          * (2)  The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be\r
280          *              represented as "_" (underscore, ASCII 95.).\r
281          *              (This character may not pass through some internetwork mail gateways,\r
282          *              but its use will greatly enhance readability of "Q" encoded data\r
283          *              with mail readers that do not support this encoding.)\r
284          *              Note that the "_" always represents hexadecimal 20,\r
285          *              even if the SPACE character occupies a different code position\r
286          *              in the character set in use.\r
287          * (3)  8-bit values which correspond to printable ASCII characters\r
288          *              other than "=", "?", and "_" (underscore), MAY be represented as those characters.\r
289          *              (But see section 5 for restrictions.)\r
290          *              In particular, SPACE and TAB MUST NOT be represented as themselves within encoded words.\r
291          * \r
292          * @static\r
293          * @param       string  $target targetted string\r
294          * @return      string  encoded string\r
295          */\r
296         static private function q_encoder($target)\r
297         {\r
298                 $string = '';\r
299                 \r
300                 for ( $i = 0; $i < strlen($target); $i++ )\r
301                 {\r
302                         $letter = substr ($target, $i, 1);\r
303                         $order = ord($letter);\r
304                         \r
305                         // Printable ASCII characters without "=", "?", "_"\r
306                         if ((33 <= $order && $order <= 60)\r
307                          || (62 == $order)\r
308                          || (64 <= $order && $order <= 94)\r
309                          || (96 <= $order && $order <= 126))\r
310                         {\r
311                                 $string .= strtoupper(dechex($order));\r
312                         }\r
313                         // Space shuold be encoded as the same strings as "_"\r
314                         else if ($order == 32)\r
315                         {\r
316                                 $string .= '_';\r
317                         }\r
318                         // Other characters\r
319                         else\r
320                         {\r
321                                 $string .= '=' . strtoupper(dechex($order));\r
322                         }\r
323                 }\r
324                 \r
325                 return $string;\r
326         }\r
327         \r
328         /**\r
329          * NOTICE: Deprecated\r
330          * NOTIFICATION::$addresses\r
331          * \r
332          * @deprecated\r
333          */\r
334         private $addresses = array();\r
335         \r
336         /**\r
337          * NOTICE: Deprecated\r
338          * takes one string as argument, containing multiple e-mail addresses\r
339          * separated by semicolons\r
340          * eg: site@demuynck.org;nucleus@demuynck.org;foo@bar.com\r
341          * \r
342          * @deprecated\r
343          */\r
344         function __construct($addresses)\r
345         {\r
346                 $this->addresses = preg_split('#;#' , $addresses);\r
347         }\r
348         \r
349         /**\r
350          * NOTICE: Deprecated\r
351          * NOTIFICATION::validAddresses()\r
352          * \r
353          * returns true if all addresses are valid\r
354          * \r
355          * @deprecated\r
356          * @param       Void\r
357          * @return      Boolean\r
358          */\r
359         function validAddresses()\r
360         {\r
361                 foreach ( $this->addresses as $address )\r
362                 {\r
363                         if ( !self::address_validation(trim($address)) )\r
364                         {\r
365                                 return 0;\r
366                         }\r
367                 }\r
368                 return 1;\r
369         }\r
370         \r
371         /**\r
372          * NOTICE: Deprecated\r
373          * NOTIFICATION::notify()\r
374          * \r
375          * Sends email messages to all the email addresses\r
376          * \r
377          * @deprecated\r
378          * @param       String  $title  \r
379          * @param       String  $message        \r
380          * @param       String  $from   \r
381          * @return      Void\r
382          */\r
383         function notify($title, $message, $from)\r
384         {\r
385                 global $member;\r
386                 $addresses = array();\r
387                 \r
388                 foreach ($this->addresses as $address)\r
389                 {\r
390                         if ( $member->isLoggedIn() && ($member->getEmail() == $address) )\r
391                         {\r
392                                 continue;\r
393                         }\r
394                         $addresses[] = $address;\r
395                 }\r
396                 \r
397                 self::mail(implode(',', $addresses), $title, $message , $from);\r
398                 return;\r
399         }\r
400 }\r
401 =======
402 <?php
403 /*
404  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
405  * Copyright (C) 2002-2009 The Nucleus Group
406  *
407  * This program is free software; you can redistribute it and/or
408  * modify it under the terms of the GNU General Public License
409  * as published by the Free Software Foundation; either version 2
410  * of the License, or (at your option) any later version.
411  * (see nucleus/documentation/index.html#license for more info)
412  */
413 /**
414  * Class used to represent a collection of e-mail addresses, to which a
415  * message can be sent (e.g. comment or karma vote notification).
416  *
417  * @license http://nucleuscms.org/license.txt GNU General Public License
418  * @copyright Copyright (C) 2002-2009 The Nucleus Group
419  * @version $Id: NOTIFICATION.php 1836 2012-05-12 10:38:31Z sakamocchi $
420  */
421 class Notification
422 {
423         static private $charset;
424         static private $scheme = 'B';
425         
426         /**
427          * NOTIFICATION::address_validation()
428          * Validating the string as address
429          * 
430          * FIXME: this is just migrated from globalfunctions.php
431          *  we should confirm this regular expression refering to RFC 5322
432          * 
433          * @link        http://www.ietf.org/rfc/rfc5322.txt
434          * @see         3.4. Address Specification
435          * 
436          * @static
437          * @param       String  $address        Address
438          * @return      Boolean valid or not
439          */
440         static public function address_validation($address)
441         {
442                 return (boolean) preg_match('#^(?!\\.)(?:\\.?[-a-zA-Z0-9!\\#$%&\'*+/=?^_`{|}~]+)+@(?!\\.)(?:\\.?(?!-)[-a-zA-Z0-9]+(?<!-)){2,}$#', $address);
443         }
444         
445         /**
446          * NOTIFICATION::get_mail_footer()
447          * Return mail footer with Nucleus CMS singnature
448          * 
449          * @static
450          * @param       void
451          * @return      String  Message body with 
452          */
453         static public function get_mail_footer()
454         {
455                 $message  = "\n";
456                 $message .= "\n";
457                 $message .= "-----------------------------\n";
458                 $message .=  "   Powered by Nucleus CMS\n";
459                 $message .=  "(http://www.nucleuscms.org/)\n";
460                 return $message;
461         }
462         
463         /**
464          * NOTIFICATION::mail
465          * Send mails with headers including 7bit-encoded multibyte string
466          * 
467          * @static
468          * @param       string  $to             receivers including singlebyte and multibyte strings, based on RFC 5322
469          * @param       string  $subject        subject including singlebyte and multibyte strings
470          * @param       string  $message        message including singlebyte and multibyte strings
471          * @param       string  $from           senders including singlebyte and multibyte strings, based on RFC 5322
472          * @param       string(B/Q)     $scheme 7bit-encoder scheme based on RFC 2047
473          * @return      boolean accepted delivery or not
474          */
475         static public function mail($to, $subject, $message, $from, $charset, $scheme='B')
476         {
477                 self::$charset = $charset;
478                 self::$scheme = $scheme;
479                 
480                 $to = self::mailbox_list_encoder($to);
481                 $subject = self::seven_bit_characters_encoder($subject);
482                 $from = 'From: ' . self::mailbox_list_encoder($from);
483                 
484                 /*
485                  * All of 7bit character encoding derives from ISO/IEC 646
486                  * So we can decide the body's encoding bit count by this regular expression.
487                  * 
488                  */
489                 $bitcount = '8bit';
490                 if ( preg_match('#\A[\x00-\x7f]*\z#', $message) )
491                 {
492                         $bitcount = '7bit';
493                 }
494                 
495                 $header  = 'Content-Type: text/plain; charset=' . self::$charset . "; format=flowed; delsp=yes\n";
496                 $header .= "Content-Transfer-Encoding: {$bitcount}\n";
497                 $header .= "X-Mailer: Nucleus CMS NOTIFICATION class\n";
498                 
499                 return mail($to, $subject, $message, "{$from}\n{$header}");
500         }
501         
502         /**
503          * NOTIFICATION::mailbox_list_encoder
504          * Encode multi byte strings included in mailbox.
505          * The format of mailbox is based on RFC 5322, which obsoletes RFC 2822
506          * 
507          * @link        http://www.ietf.org/rfc/rfc5322.txt
508          * @see         3.4. Address Specification
509          * 
510          * @static
511          * @param       string  $mailbox_list           mailbox list
512          * @return      string  encoded string  
513          * 
514          */
515         static private function mailbox_list_encoder ($mailbox_list)
516         {
517                 $encoded_mailboxes = array();
518                 $mailboxes = preg_split('#,#', $mailbox_list);
519                 foreach ( $mailboxes as $mailbox )
520                 {
521                         if ( preg_match("#^([^,]+)?<([^,]+)?@([^,]+)?>$#", $mailbox, $match) )
522                         {
523                                 $display_name = self::seven_bit_characters_encoder(trim($match[1]));
524                                 $local_part = trim($match[2]);
525                                 $domain = trim($match[3]);
526                                 $encoded_mailboxes[] = "{$display_name} <{$local_part}@{$domain}>";
527                         }
528                         else if ( preg_match("#([^,]+)?@([^,]+)?#", $mailbox) )
529                         {
530                                 $encoded_mailboxes[] = $mailbox;
531                         }
532                         else
533                         {
534                                 continue;
535                         }
536                 }
537                 if ( $encoded_mailboxes == array() )
538                 {
539                         return FALSE;
540                 }
541                 return implode(',', $encoded_mailboxes);
542         }
543         
544         /**
545          * NOTIFICATION::seven_bit_characters_encoder
546          * Encoder into 7bit ASCII expression for Non-ASCII Text based on RFC 2047.
547          * 
548          * @link http://www.ietf.org/rfc/rfc2047.txt
549          * @see 2. Syntax of encoded-words
550          * 
551          * NOTE: RFC 2047 has a ambiguousity for dealing with 'linear-white-space'.
552          *  This causes a trouble related to line breaking between single byte and multi-byte strings.
553          *  To avoid this, single byte string is encoded as well as multi byte string here.
554          * 
555          * NOTE: RFC 2231 also defines the way to use non-ASCII characters in MIME header.
556          * http://www.ietf.org/rfc/rfc2231.txt
557          * 
558          * NOTE: iconv extension give the same functions as this in PHP5
559          * iconv_mime_encode():
560          * http://www.php.net/manual/en/function.iconv-mime-encode.php
561          * 
562          * @static
563          * @param       string  $charset        Character set encoding
564          * @param       string  $type   type of 7 bit encoding, should be 'B' or 'Q'
565          * @param       string  $string Target string with header field
566          * @return      string  encoded string
567          * 
568          */
569         static private function seven_bit_characters_encoder($string)
570         {
571                 $header = chr(13) . chr(10) . chr(32) . '=?' . self::$charset . '?' . self::$scheme . '?';
572                 $footer = "?=";
573                 $restriction = 78 - strlen($header) - strlen($footer) ;
574                 
575                 $encoded_words = array();
576                 for ( $i = 0; $i < i18n::strlen($string); $i++ )
577                 {
578                         if ( self::$scheme == 'B' )
579                         {
580                                 if ( $i == 0 )
581                                 {
582                                         $letters = '';
583                                 }
584                                 
585                                 $letter = i18n::substr($string, $i, 1);
586                                 $expected_length = strlen($letters) + strlen($letter) * 4 / 3;
587                                 
588                                 if ( $expected_length > $restriction )
589                                 {
590                                         $encoded_text = self::b_encoder($letters);
591                                         $encoded_words[] = "{$header}{$encoded_text}{$footer}";
592                                         $letters = '';
593                                 }
594                                 
595                                 $letters .= $letter;
596                                 
597                                 if ( $i == i18n::strlen($string) - 1 )
598                                 {
599                                         $encoded_text = self::b_encoder($letters);
600                                         $encoded_words[] = "{$header}{$encoded_text}{$footer}";
601                                         break;
602                                 }
603                                 continue;
604                         }
605                         else
606                         {
607                                 if ( $i == 0 )
608                                 {
609                                         $encoded_text = '';
610                                 }
611                                 
612                                 $encoded_letter = self::q_encoder(i18n::substr($string, $i, 1));
613                                 $expected_length = strlen($encoded_text) + strlen($encoded_letter);
614                                 
615                                 if ( $expected_length > $restriction )
616                                 {
617                                         $encoded_words[] = "{$header}{$encoded_text}{$footer}";
618                                         $letters = '';
619                                 }
620                                 
621                                 $encoded_text .= $encoded_letter;
622                                 
623                                 if ( $i == i18n::strlen($string) - 1 )
624                                 {
625                                         $encoded_words[] = "{$header}{$encoded_text}{$footer}";
626                                         break;
627                                 }
628                                 continue;
629                         }
630                 }
631                 
632                 return implode('', $encoded_words);
633         }
634         
635         /**
636          * NOTIFICATION::b_encoder()
637          * 
638          * B encoder according to RFC 2047.
639          * The "B" encoding is identical to the "BASE64" encoding defined by RFC 4648.
640          * 
641          * @link http://www.ietf.org/rfc/rfc4648.txt
642          * @see 6.8. Base64 Content-Transfer-Encoding
643          * 
644          * NOTE: According to RFC 4648
645          * (1)  The final quantum of encoding input is an integral multiple of 24 bits;
646          *              here, the final unit of encoded output will be an integral multiple
647          *              of 4 characters with no "=" padding.
648          * (2)  The final quantum of encoding input is exactly 8 bits; here,
649          *              the final unit of encoded output will be two characters followed
650          *              by two "=" padding characters.
651          * (3)  The final quantum of encoding input is exactly 16 bits; here,
652          *              the final unit of encoded output will be three characters followed
653          *              by one "=" padding character.
654          * 
655          * @static
656          * @param       string  $target targetted string
657          * @return      string  encoded string
658          */
659         static private function b_encoder($target)
660         {
661                 return base64_encode($target);
662         }
663         
664         /**
665          * NOTIFICATION::q_encoder()
666          * 
667          * Q encoder according to RFC 2047.
668          * The "Q" encoding is similar to "Quoted-Printable" content-transfer-encoding defined in RFC 2045,
669          *  but the "Q" encoding and the "Quoted-Printable" are different a bit.
670          * 
671          * @link http://www.ietf.org/rfc/rfc2047.txt
672          * @see 4.2. The "Q" encoding
673          * 
674          * NOTE: According to RFC 2047
675          * (1)  Any 8-bit value may be represented by a "=" followed by two hexadecimal digits.
676          *              For example, if the character set in use were ISO-8859-1,
677          *              the "=" character would thus be encoded as "=3D", and a SPACE by "=20".
678          *              (Upper case should be used for hexadecimal digits "A" through "F".)
679          * (2)  The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be
680          *              represented as "_" (underscore, ASCII 95.).
681          *              (This character may not pass through some internetwork mail gateways,
682          *              but its use will greatly enhance readability of "Q" encoded data
683          *              with mail readers that do not support this encoding.)
684          *              Note that the "_" always represents hexadecimal 20,
685          *              even if the SPACE character occupies a different code position
686          *              in the character set in use.
687          * (3)  8-bit values which correspond to printable ASCII characters
688          *              other than "=", "?", and "_" (underscore), MAY be represented as those characters.
689          *              (But see section 5 for restrictions.)
690          *              In particular, SPACE and TAB MUST NOT be represented as themselves within encoded words.
691          * 
692          * @static
693          * @param       string  $target targetted string
694          * @return      string  encoded string
695          */
696         static private function q_encoder($target)
697         {
698                 $string = '';
699                 
700                 for ( $i = 0; $i < strlen($target); $i++ )
701                 {
702                         $letter = substr ($target, $i, 1);
703                         $order = ord($letter);
704                         
705                         // Printable ASCII characters without "=", "?", "_"
706                         if ((33 <= $order && $order <= 60)
707                          || (62 == $order)
708                          || (64 <= $order && $order <= 94)
709                          || (96 <= $order && $order <= 126))
710                         {
711                                 $string .= strtoupper(dechex($order));
712                         }
713                         // Space shuold be encoded as the same strings as "_"
714                         else if ($order == 32)
715                         {
716                                 $string .= '_';
717                         }
718                         // Other characters
719                         else
720                         {
721                                 $string .= '=' . strtoupper(dechex($order));
722                         }
723                 }
724                 
725                 return $string;
726         }
727         
728         /**
729          * NOTICE: Deprecated
730          * NOTIFICATION::$addresses
731          * 
732          * @deprecated
733          */
734         private $addresses = array();
735         
736         /**
737          * NOTICE: Deprecated
738          * takes one string as argument, containing multiple e-mail addresses
739          * separated by semicolons
740          * eg: site@demuynck.org;nucleus@demuynck.org;foo@bar.com
741          * 
742          * @deprecated
743          */
744         function __construct($addresses)
745         {
746                 $this->addresses = preg_split('#;#' , $addresses);
747         }
748         
749         /**
750          * NOTICE: Deprecated
751          * NOTIFICATION::validAddresses()
752          * 
753          * returns true if all addresses are valid
754          * 
755          * @deprecated
756          * @param       Void
757          * @return      Boolean
758          */
759         function validAddresses()
760         {
761                 foreach ( $this->addresses as $address )
762                 {
763                         if ( !self::address_validation(trim($address)) )
764                         {
765                                 return 0;
766                         }
767                 }
768                 return 1;
769         }
770         
771         /**
772          * NOTICE: Deprecated
773          * NOTIFICATION::notify()
774          * 
775          * Sends email messages to all the email addresses
776          * 
777          * @deprecated
778          * @param       String  $title  
779          * @param       String  $message        
780          * @param       String  $from   
781          * @return      Void
782          */
783         function notify($title, $message, $from)
784         {
785                 global $member;
786                 $addresses = array();
787                 
788                 foreach ($this->addresses as $address)
789                 {
790                         if ( $member->isLoggedIn() && ($member->getEmail() == $address) )
791                         {
792                                 continue;
793                         }
794                         $addresses[] = $address;
795                 }
796                 
797                 self::mail(implode(',', $addresses), $title, $message , $from);
798                 return;
799         }
800 }
801 >>>>>>> skinnable-master