OSDN Git Service

本家Nucleus CMSの開発を補助するためにコミット
[nucleus-jp/nucleus-next.git] / nucleus / libs / NOTIFICATION.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2009 The Nucleus Group
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * (see nucleus/documentation/index.html#license for more info)
11  */
12 /**
13  * Class used to represent a collection of e-mail addresses, to which a
14  * message can be sent (e.g. comment or karma vote notification).
15  *
16  * @license http://nucleuscms.org/license.txt GNU General Public License
17  * @copyright Copyright (C) 2002-2009 The Nucleus Group
18  * @version $Id: NOTIFICATION.php 1534 2011-06-22 06:13:23Z sakamocchi $
19  */
20 class NOTIFICATION {
21
22         // array of addresses that need to get a notification
23         var $addresses = array();
24
25         /**
26           * takes one string as argument, containing multiple e-mail addresses
27           * separated by semicolons
28           * eg: site@demuynck.org;nucleus@demuynck.org;foo@bar.com
29           */
30         function NOTIFICATION($addresses) {
31                 $this->addresses = i18n::explode(';' , $addresses);
32         }
33
34         /**
35           * returns true if all addresses are valid
36           */
37         function validAddresses() {
38                 foreach ( $this->addresses as $address ) {
39                         if (!isValidMailAddress(trim($address)))
40                                 return 0;
41                 }
42                 return 1;
43         }
44
45         /**
46           * Sends email messages to all the email addresses
47           */
48         function notify($title, $message, $from)
49         {
50                 global $member;
51                 $addresses = array();
52                 
53                 foreach ($this->addresses as $address)
54                 {
55                         if ( $member->isLoggedIn() && ($member->getEmail() == $address) )
56                         {
57                                 continue;
58                         }
59                         $addresses[] = $address;
60                 }
61                 
62                 i18n::mail(implode(',', $addresses), $title, $message , $from);
63                 return;
64         }
65 }
66