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'); ?>

NotifyMe


id="plug_send_comm_email" name="sub_comm" />

getOption('SendEnabled'); $con = $this->getOption('SendCommEnabled'); ?>

NotifyMe

id="plug_send_email" name="send_email" />
id="plug_send_comm_email" name="sub_comm" />

citem; } $emailquery = "SELECT email FROM ".sql_table('plugin_notifyaddress')." WHERE itemid='".$itemid."'"; $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; } global $CONF, $manager, $blog, $DIR_PLUGINS; $blog =& $manager->getBlog(getBlogIDFromItemID($itemid)); if (!$CONF['ItemURL']) $CONF['ItemURL'] = $blog->getURL(); $title = $this->getOption('Titleprefix') ." - new comment for " . $blog->getName(); $comment = stripslashes($comment['comment']['body']); if (!$CONF['ItemURL']) { $url = createItemLink($itemid); } else { $url = $CONF['IndexURL'] . createItemLink($itemid); } $body = file_get_contents($DIR_PLUGINS.'notifyme/commentMail.templete'); $body = str_replace('%##COMMENT##%', $comment, $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"); } // action handling function doAction($actionType) { global $CONF, $blog, $manager, $DIR_PLUGINS; $email = requestVar('emailaddress'); // Show the subscriber login form if ($actionType == "subadmin") { echo "Please enter the email address and access key (provided in the subscription email)" . "
\n" . "\n" . " \n" . " \n" . "Email:
\n" . "Access Key:
\n" . "" . "
\n"; return; } // Show the list of subscription for a subscriber if ($actionType == "subadmin2") { $key = requestVar('key'); $query = "SELECT * FROM ".sql_table('plugin_notifyaddress')." WHERE email = '" .$email."' AND id = '" . $key . "'"; $result = mysql_query($query); if (mysql_num_rows($result) < 1) { echo "Login failed, invalid email/key"; return; } echo "

Notification Management

"; echo "Here's a list of all notification subscriptions for " . $email . ":
"; $query = "SELECT * FROM ".sql_table('plugin_notifyaddress')." WHERE email = '" .$email."'"; $rows = mysql_query($query); echo "\n"; echo ""; while($row = mysql_fetch_object($rows)) { $redirecturl = 'noredirect'; echo ""; if ($row->itemid == 0) { $delAction = $CONF['ActionURL'] . '?action=plugin&name=NotifyMe&type=form&emailaddress=' . $row->email . '&redirecturl=' . $redirecturl . '&currBlogId=' . $row->blogID; echo "\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 "\n"; } echo ""; } echo "
NameType
blogID) . "\">" . getBlogNameFromID($row->blogID) . "Blog[unsubscribe]itemid) ."\">". $item['title'] . "Item (".$row->itemid.")[unsubscribe]
\n"; return; } // Defualt subscribe/unsubscribe action $IDnum = intRequestVar('currBlogId'); // IDnum = 0 if no such var $redirect = requestVar('redirecturl'); $itemid = intRequestVar('itemid'); // itemid = 0 if no such var if ($itemid == '0') { $subType = 'blogSub'; } else { $subType = 'itemSub'; } $pluginquery = "SELECT email FROM ".sql_table('plugin_notifyaddress')." WHERE email= '" .$email. "' AND itemid='".$itemid."' and BlogId='" . $IDnum . "'"; $check = mysql_query($pluginquery); // no errors please ... if (mysql_num_rows($check) == 0) { // new subscriber, Welcome ... $ok = isValidMailAddress($email); if ($ok) { $actionquery = "INSERT INTO ".sql_table('plugin_notifyaddress')." (id, email, blogID, itemid) VALUES ('NULL', '" . $email . "', '" . $IDnum . "', '" . $itemid . "')"; $sub = 0; } else { return ("This is not a valid email address!"); } } else { // sorry to see you go ... $actionquery = "DELETE FROM ".sql_table('plugin_notifyaddress')." WHERE email = '" .$email . "' AND blogID='" .$IDnum ."' AND itemid='" . $itemid . "'"; $sub = 1; } // execute actionquery mysql_query($actionquery); $insertid = mysql_insert_id(); $blogName = getBlogNameFromID($IDnum); if ($redirect != 'noredirect') { $sender = $this->getOption('updateSender'); if ($sub == '0') { $title = "$blogName - NotifyMe subscription"; if ($subType == 'itemSub') { $item =& $manager->getItem($itemid, 0, 0); $ititle = $item['title']; $unSubLink = $CONF['ActionURL'] . '?action=plugin&name=NotifyMe&type=form&emailaddress=' . $email . '&redirecturl=noredirect&currBlogId=' . $IDnum . '&itemid=' . $itemid; $body = file_get_contents($DIR_PLUGINS.'notifyme/subscribeItemMail.templete'); $body = str_replace('%##TITLE##%', $ititle, $body); $body = str_replace('%##LINK##%', $unSubLink, $body); $body = str_replace('%##EMAIL##%', $email, $body); } else { $unSubLink = $CONF['ActionURL'] . '?action=plugin&name=NotifyMe&type=form&emailaddress=' . $email . '&redirecturl=noredirect&currBlogId=' . $IDnum; $manLink = $CONF['ActionURL']."?action=plugin&name=NotifyMe&type=subadmin"; $body = file_get_contents($DIR_PLUGINS.'notifyme/subscribeBlogMail.templete'); $body = str_replace('%##EMAIL##%', $email, $body); $body = str_replace('%##BLOG##%', $blogName, $body); $body = str_replace('%##KEY##%', $insertid, $body); $body = str_replace('%##LINK##%', $unSubLink, $body); $body = str_replace('%##MLINK##%', $manLink, $body); } } else { $title = "$blogName - NotifyMe unsubscription"; $body = file_get_contents($DIR_PLUGINS.'notifyme/unsubscribeMail.templete'); $body = str_replace('%##EMAIL##%', $email, $body); if ($subType == 'itemSub') { $item =& $manager->getItem($itemid, 0, 0); $ititle = $item['title']; $body = str_replace('%##TITLE##%', $ititle, $body); } else { $body = str_replace('%##TITLE##%', $blogName, $body); } } $headers = "Content-type: text/html; charset=iso-8859-1\n"; $headers .= "From: ".$sender."\n"; $headers .= "X-Mailer: PHP/" . phpversion(); $return = mail($email,$title,$body,$headers); // strip parameters from previous action... $redirect = preg_replace("/\?.subscribe=./", "", $redirect); $redirect = preg_replace("/.subscribe=./", "", $redirect); $redirect = preg_replace("/&subtype=(itemSub|blogSub)/", "", $redirect); $redirect = preg_replace("/&add=(.*)/", "", $redirect); if (strstr('?', $redirect) == '') { $sub_string = "?&subscribe="; } else { $sub_string = "subscribe="; } header('Location: ' . $redirect . $sub_string . $sub . '&subtype=' . $subType . '&add=' . $email); } else { echo "You are now unsubscribed from $blogName"; } } // generate the subscribe box, and display subscription status function doSkinVar($skinType, $form) { global $manager, $blog, $CONF, $DIR_PLUGINS; $ButtonCaption = $this->getOption('SubscribeButtonText'); $Formlabel = $this->getOption('Formlabel'); $currBlogId = $blog->getID(); $sub = RequestVar('subscribe'); $add = RequestVar('add'); $subType = RequestVar('subtype'); if ($form == '') $form = 'blogSub'; $this->doForm($ButtonCaption,$Formlabel,$currBlogId,$sub,$add,$form,$subType); } // HTML Functions function doForm($ButtonLabel,$Label, $currBlogId, $sub, $add, $form,$subType) { global $CONF, $itemid, $manager; // echo "sub=" . $sub . " subType=" . $subType . " form=" . $form . "
"; if ($form == 'itemSub') { $item =& $manager->getItem($itemid, 0, 0); if ($item['closed'] == '1') { return; } } // display subscribe/unsubscribe message if ($sub != '' && $subType != '' && $subType == $form) { if ($sub == '0') $message = 'Thank you, ' . $add . ' subscribes successfully

'; else if ($sub == '1') $message = 'Thank you, ' . $add . ' unsubscribes successfully

'; else $message = 'No action perfromed
'; echo $message; } $redirect = serverVar('REQUEST_URI'); if ($form == 'itemSub') { echo "
\n" . "Enter email address to subscribe to comment on this item
" . "
\n" . "\n" . " \n" . " \n" . "\n" . "" . "" . "" . "" . "
" . "
\n"; } else { echo "
\n" . "
\n" . "\n" . " \n" . " \n" . $Label . "\n" . "" . "" . "" . "
" . "
\n"; } echo "Click here to manage subscription"; } } ?>