for comment subscription - use Bcc: for receiver list - send extended body in notification email - override sending notification when add new post if it is saved as draft - fix XHTML 1.0 - Added comment notification to author in add/edit item, default option to yes - Fixed form action redirection bug - Fixed future post bug (ignore future post) v0.16 - Added plugin quick menu (currently empty menu) - Improved comment subscription email - Fixed sql_table - Fixed subscribe over subscribe bug (wrong subscribe message sent) - Set minimum Nucleus version to 2.5 - Fixed subscribe/unsubscribe message v0.17 - no comment subscription for closed item - subscriber management: list all subscription w/ delete action v0.18 - do not send email when there is no one to sent to - Fixed subscription management access problem in fancyURL mode - Fixed 2nd blog subscription bug - Improved accesskey id code in subscription - remove <%image%> tag and such - list subscribers in admin menu - delete subscribers from admin management - notify skin for customisible subscribe/unsubscribe message - fixes comment notification bug v0.20 - mail() empty $to warning/error - fix comment notification missing itemid problem (compatibility issue with Nucleus 3.0??) admun TODO: - tested &$comment passed from the PostAddComment event - paged the admin menu (instead of show all) Other ideas ============= - edit subscribers from user or admin management - per blog default notification setting - action parameter should be lower case - optimize code, eliminate clone code (ie sending mail) - fix FancyURL link - address blacklist function (need new plugin_notify_block table) some idea to deal with future post... - add warning to notice that when this post is available?? - batch the notification for future post (need NP_Batch... coming in the future) - or future post "appearing" event */ // to make this plugin works on Nucleus versions <=2.0 as well if (!function_exists('sql_table')) { function sql_table($name) { return 'nucleus_' . $name; } } class NP_NotifyMe extends NucleusPlugin { function getMinNucleusVersion() {return 250;} function getName() {return 'Notify subscribers by mail';} function getAuthor() {return '-=Xiffy=- (Appie Verschoor), mod by Adeas, admun (Edmond Hui)';} function getURL() {return 'http://xiffy.nl/weblog/';} function getVersion() {return '0.20c';} function getTableList () { return sql_table('plugin_notifyaddress'); } function supportsFeature($feature) { switch($feature) { case 'SqlTablePrefix': return 1; default: return 0; } } function install() { // create the table to hold the addresses ... // Table structure: unique key#, blog id#, itemid, email address // Note: itemid of 0 == invalid, used as a null value for blog item subscription (cannot be null) sql_query('CREATE TABLE IF NOT EXISTS ' . sql_table('plugin_notifyaddress') . '(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, email varchar(100) not null, blogID int(3) not null, itemid int(11) not null) '); $this->createOption('SendEnabled','Is sending notification enabled by default when adding new item?','yesno','yes'); $this->createOption('SendCommEnabled','Subscribe comment notification for author when adding new item?','yesno','yes'); $this->createOption('SubscribeButtonText','The caption on the button (label)','text','[Un-] Subscribe'); $this->createOption('Titleprefix','This will be prefixed to the itemtitle as the title for the email','text','Updated:'); $this->createOption('updateSender','This is the email address that will be used as the sender','text','updateNotify@me.com'); $this->createOption('Formlabel','The label displayed on the form','text','Subscribe for updates'); } function unInstall() { sql_query('DROP TABLE '.sql_table('plugin_notifyaddress')); } // a description to be shown on the installed plugins listing function getDescription() { return 'This plugin provides a notify me by email function to your blog, which sends the new/edited items to subscribed users. It also supports per blog subscription and per item comment notification.'; } // subscribe to PostAddItem and AddItemFormExtras function getEventList() { return array('PreAddItem', 'PostAddItem', 'PreUpdateItem', 'AddItemFormExtras','EditItemFormExtras', 'PostAddComment', 'QuickMenu'); } function hasAdminArea() { return 1; } function event_QuickMenu(&$data) { global $member; if (!($member->isLoggedIn() && $member->isAdmin())) return; array_push( $data['options'], array( 'title' => 'Notification Management', 'url' => $this->getAdminURL(), 'tooltip' => 'Manage comment/blog notification subscription.' ) ); } function event_PreAddItem($data) { $this->itime = $data['timestamp']; $this->draft = "no"; if ($data['draft'] == '1') { $this->draft = "yes"; } } // Send mail notification when new item added function event_PostAddItem($data) { global $manager, $CONF, $blog, $DIR_PLUGINS; $query=mysql_query('SELECT iblog,iauthor FROM '. // pulls the blog ID# from the mySQL database sql_table('item'). // Thanks Radek for the code ' WHERE inumber='.$data['itemid']); $row=mysql_fetch_object($query); $IDnum=$row->iblog; $author=$row->iauthor; $query=mysql_query('SELECT bname FROM '. sql_table('blog'). ' WHERE bnumber='.$IDnum); $row=mysql_fetch_object($query); $BlogName=$row->bname; $send_email = requestVar('send_email'); $sub_comm = requestVar('sub_comm'); if ($sub_comm == "on") { $mem = new MEMBER; $mem->readFromID($author); $a_email = $mem->getEmail(); $query = "INSERT INTO ".sql_table('plugin_notifyaddress')." (id, email, blogID, itemid) VALUES ('NULL', '" . $a_email . "', '" . $IDnum . "', '" . $data['itemid'] . "')"; sql_query($query); } $future = "no"; $time = strftime("%Y-%m-%d %H:%M:%S", time()); if ($this->itime > $time) $future = "yes"; if ($send_email == "on" && $this->draft == "no" && $future == "no") { // get a handle to notify object // add all email adress to a semicolon seperated list .. $emailquery = "SELECT email FROM ".sql_table('plugin_notifyaddress')." WHERE blogID='" .$IDnum. "' AND itemid='0'"; $address = mysql_query($emailquery); $list = $row->email; while ($row = mysql_fetch_object($address)){ $list .= "," . $row->email; } // don't sent email if there is no one to sent to if ($list == "") { return; } $itemid = $data['itemid']; $item =& $manager->getItem($itemid, 0, 0); $title = $this->getOption('Titleprefix') ." ". stripslashes($item['title'])." - ".$BlogName; $body = file_get_contents($DIR_PLUGINS.'notifyme/addItemMail.templete'); $body = str_replace('%##TITLE##%', stripslashes($item['title']), $body); $body = str_replace('%##BODY##%', stripslashes($item['body']), $body); $body = str_replace('%##MORE##%', stripslashes($item['more']), $body); $url = $CONF['IndexURL'] .createItemLink($itemid); $body = str_replace('%##URL##%', $url, $body); $sender = $this->getOption('updateSender'); // replace image/popup/media tags in body $body = eregi_replace('<\%image\(.*>', '[image]', $body); $body = eregi_replace('<\%popup\(.*>', '[image]', $body); $body = eregi_replace('<\%media\(.*>', '[media]', $body); // email notification $headers = "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: ".$sender."\r\n"; $headers .= "Bcc: ".$list."\r\n"; $headers .= "X-Mailer: PHP/".phpversion()."\r\n"; $return = mail("$sender","$title","$body","$headers"); } } // Send mail notification when item edited function event_PreUpdateItem($data) { global $manager, $CONF, $blog, $DIR_PLUGINS; $query=mysql_query('SELECT iblog,iauthor FROM '. // pulls the blog ID# from the mySQL database sql_table('item'). // Thanks Radek for the code ' WHERE inumber='.$data['itemid']); $row=mysql_fetch_object($query); $IDnum=$row->iblog; $author=$row->iauthor; $query=mysql_query('SELECT bname FROM '. sql_table('blog'). ' WHERE bnumber='.$IDnum); $row=mysql_fetch_object($query); $BlogName=$row->bname; $send_email = requestVar('send_email'); $sub_comm = requestVar('sub_comm'); if ($sub_comm == "on") { $mem = new MEMBER; $mem->readFromID($author); $a_email = $mem->getEmail(); $query = "SELECT * FROM ".sql_table('plugin_notifyaddress')." WHERE email='" . $a_email . "' AND itemid=" . $data['itemid']; $res = sql_query($query); // Do not add email address if already exist.... maybe should use ignore from MySQL 4.1.*?? if (mysql_num_rows($res) == 0) { $query = "INSERT INTO ".sql_table('plugin_notifyaddress')." (id, email, blogID, itemid) VALUES ('NULL', '" . $a_email . "', '" . $IDnum . "', '" . $data['itemid'] . "')"; sql_query($query); } } // if this event occurs, send an email to all subscribers if ($send_email == "on") { // get a handle to notify object // add all email adress to a semicolon seperated list .. $emailquery = "SELECT email FROM ". sql_table('plugin_notifyaddress') . " WHERE blogID = '" .$IDnum. "' AND itemid='0'"; $address = mysql_query($emailquery); $row = mysql_fetch_object($address); $list = $row->email; while ($row = mysql_fetch_object($address)){ $list .= "," . $row->email; } // don't sent email if there is no one to sent to if ($list == "") { return; } // Note: It would be nice to be able to include the message in the email, but there is no PostUpdateItem event.... $itemid = $data['itemid']; $ititle = $data['title']; $title = $this->getOption('Titleprefix') . stripslashes($ititle)." - ".$BlogName; $url = $CONF['IndexURL'] .createItemLink($itemid); $body = file_get_contents($DIR_PLUGINS.'notifyme/editItemMail.templete'); $body = str_replace('%##TITLE##%', $title, $body); $body = str_replace('%##URL##%', $url, $body); $sender = $this->getOption('updateSender'); // email notification $headers = "Content-type: text/html; charset=iso-8859-1\n"; $headers .= "From: ".$sender."\n"; $headers .= "Bcc: ".$list."\n"; $headers .= "X-Mailer: PHP/" . phpversion(); $return = mail("$sender","$title","$body","$headers"); } } // add the option send / not send email during item edit... function event_EditItemFormExtras($data) { $on = $this->getOption('SendEnabled'); ?>
id="plug_send_comm_email" name="sub_comm" />
id="plug_send_email" name="send_email" />
id="plug_send_comm_email" name="sub_comm" />
Name | Type | "; while($row = mysql_fetch_object($rows)) { $redirecturl = 'noredirect'; echo " | |||
blogID) . "\">" . getBlogNameFromID($row->blogID) . " | Blog | [unsubscribe] | \n"; } else { $item =& $manager->getItem($row->itemid, 0, 0); $delAction = $CONF['ActionURL'] . '?action=plugin&name=NotifyMe&type=form&emailaddress=' . $row->email . '&redirecturl=' . $redirecturl . '&currBlogId=' . $row->blogID . '&itemid=' . $row->itemid . $emailenabled; echo "itemid) ."\">". $item['title'] . " | Item (".$row->itemid.") | [unsubscribe] | \n"; } echo "