BLOG:CMS :: Support Forum

Support Forum for BLOG:CMS

You are not logged in.

#1 21.07.2004 23:03

AdeasTridae
BLOG:CMS Junior
Registered: 15.07.2004
Posts: 20

NP_NotifyMeBetter

I've modified the usual NP_NotifyMe plugin to be a bit better :-)

First, I've included  MULTIPLE BLOGS!. All you people who've wanted multiple  blogs, here you go :-) I've tested it across 2 blogs with 2 users - should work well with more.

Also, i've modified the mailer to work with the regular PHP mail() function, instead of the NOTIFICATION

E-mails are also formatted in HTML, instead of plain text. I've removed the \r from the headers that some anti-virus programs target on.

Besides that, the options and stuff are all the same. It's still not v1.0 but it's close.

To be added: Theme support, more dynamic labeling options, anything else people suggest! Let me know how it works.

Link to plugin: http://weblog.studiooblivion.net/extra/ … Better.php

Here's the code:

Code:

<?

// Modded by Adeas to allow multiple blogs & better e-mails
// http://weblog.studiooblivion.net

class NP_NotifyMe extends NucleusPlugin {
    function getMinNucleusVersion() {return 155;}
    function getName() {return 'Notify Subscribers';}
    function getAuthor() {return '-=Xiffy=- (Appie Verschoor) - Modded by Adeas';}
    function getURL() {return 'http://xiffy.nl/weblog/';}
    function getVersion() {return '0.9.1';}

    function install() {
        // create the table to hold the addresses ...    //Adeas:
                                                        //Table modified to hold a unique key # and a blog id #
                                                        //The blogID is the blog # of the blog the person wishes to
                                                        //subscribe to (As if it wasnt obvious)
                                                        //This allows us to pull all the people subscribed
                                                        //to one blog out when a post is made to that blog
        sql_query('CREATE TABLE IF NOT EXISTS nucleus_plugin_notifyaddress (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
                                                                            email varchar(100) not null,
                                                                            blogID int(3) not null)');
        $this->createOption('SendEnabled','Is sending notification enabled?','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 -=Xiffy=- :');
        $this->createOption('updateSender','This is the email address that will be used as the sender','text','updateNotify@xiffy.nl');
        $this->createOption('Formlabel','The label displayed on the form','text','Subscribe for updates');
    }

    // a description to be shown on the installed plugins listing
    function getDescription() {
        return 'Enables a notify me by email form on your website and sends the new items to subscribed users. Modded by Adeas to allo wmultiple blogs and to use HTML e-mail';
    }
    // subscribe to PostAddItem and AddItemFormExtras
    function getEventList() {
        return array('PostAddItem','AddItemFormExtras');
    }

    function event_PostAddItem($data) {
        global $manager, $CONF, $blog;

        $query=mysql_query('select iblog from '.    //This block of code pulls the blog ID# from the mySQL database - Adeas
          sql_table('item').                        //Thanks Radek for the code
          ' where inumber='.$data['itemid']);
        $row=mysql_fetch_object($query);
        $IDnum=$row->iblog;
        $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');
        // if this event occurs, send an email to all subscribers
        if ($send_email == "on") {
            $this->setOption('SendEnabled','yes');
//            echo "<h3>Sending subscribers an email</h3>";
            // get a handle to notify object
            // add all email adress to a semicolon seperated list ..
            //Adeas:
            //SQL query changed to pull records where the e-mail address is listed with this blog ID #
            $emailquery = "SELECT email FROM nucleus_plugin_notifyaddress WHERE blogID = '" .$IDnum. "'";
            $address = mysql_query($emailquery);
            $list = "";
            while ($row = mysql_fetch_object($address)){
                $list .= "," .$row->email;
            }
        $itemid = $data['itemid'];
        $item =& $manager->getItem($itemid, 0, 0);
            $title = $this->getOption('Titleprefix') ." ". stripslashes($item['title'])." - ".$BlogName;
            $body  = "<h3>".stripslashes($item['title'])."</h3>\n\n";
            $body  .= stripslashes($item['body']);
            $url   = $CONF['IndexURL'] .createItemLink($itemid);
            $body .= "\n\nURL: <a href=\"".$url."\">".$url."</a>";
            $sender = $this->getOption('updateSender');
        // email notification
        $headers = "Content-type: text/html; charset=iso-8859-1\n";
        $headers .= "From: ".$sender."\n";
        $headers .= "X-Mailer: PHP/" . phpversion();

        $return = mail($list,$title,$body,$headers);
        } else {
            $this->setOption('SendEnabled','no');
        }
    }
    // add the option send / not send email ...
    function event_AddItemFormExtras($data) {
        $on = $this->getOption('SendEnabled');
        ?>
            <h3>Send notification to subscribers</h3>

            <p>
                <label for="plug_send_email">Send notifiction:</label>
                <input type="checkbox" <? if ($on=="yes") { echo 'checked="checked"';} ?> id="plug_send_email" name="send_email" />
            </p>
        <?
    }


    function doAction($type) {
        global $CONF;

        //Adeas:
        //All of these SQL statements have been changed to reflect the blog id# for the blogs people subscribed to
        $IDnum = requestVar('currBlogId');
        $email = requestVar('emailaddress');
        $pluginquery = "SELECT email FROM nucleus_plugin_notifyaddress WHERE email = '" .$email. "' 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 nucleus_plugin_notifyaddress (id, email, blogID) VALUES ('NULL', '" . $email . "', '" . $IDnum . "')";
                $type = "subscribe";
            } else {return ("This is not a valid email address!");}
        } else {
            // sorry to see you go ...
            $actionquery = "DELETE FROM nucleus_plugin_notifyaddress WHERE email = '" .$email . "' AND blogID = '" .$IDnum . "'";
            $type = "unsubscribe";
        }
        // execute actionquery

        // show some sitespecific comments, so get this from the options TODO
        // this->getOption($type);
        switch ($type) {
            case "subscribe":
                mysql_query($actionquery);
                // send confirmation email
                break;
            case "unsubscribe":
                // send confirmation email
                mysql_query($actionquery);
                break;
        }
        // And return to the original location
        global $HTTP_REFERER;
        header('Location: ' . $HTTP_REFERER);
   }

   // Now for the backend: We need a skinvar so we can enable the form
   // form: emailaddress + button subscribe / unsubscribe.
   // then we need a followup screen to show that we are subscribed / unsubscribed ...
   // follow up screen returns to the original screen ...
   // --------------------------------------------------------------------------------

    function doSkinVar($skinType) {
        global $manager, $blog, $CONF, $DIR_PLUGINS;
        $ButtonCaption = $this->getOption('SubscribeButtonText');
        $Formlabel     = $this->getOption('Formlabel');
        $currBlogId    = $blog->getID();
        $this->doForm($ButtonCaption,$Formlabel,$currBlogId);
    }


    // We know users will ask for this if we don't implement it:
    // 1, to be able to set send-notification on off when submitting a new entry: Done !!!!
    // 2, to be able to edit the subscribed memebers by themselves ...
    // so maybe i'll implement this too.
    // first the core functionality.

    // HTML Functions
    function doForm($ButtonLabel,$Label,$currBlogId) {
        global $CONF;
        // note to xiffy: get action.php location from global settings!
        // ------------------------------------------------------------
        // emailaddress will be used in doAction for further processing
        echo "<div class=\"NotifyMe\">\n"
           . "<form name=\"notifyme\" method=\"POST\" action=\"action.php\">\n"
           . "<input type=\"hidden\" name=\"action\" value=\"plugin\" />\n"
           . "<input type=\"hidden\" name=\"name\" value=\"NotifyMe\" /> \n"
           . "<input type=\"hidden\" name=\"type\" value=\"subscribe\" /> \n"
           . $Label
           . "<input type=\"text\" id=\"xp\" name=\"emailaddress\" width=\"40\">\n"
           . "<input type=\"hidden\" name=\"indexurl\" value=\"" .$CONF['Self'] . "\">"
           //Added the blog id# for this blog so that doAction knows which blog to put into the table
           . "<input type=\"hidden\" name=\"currBlogId\" value=\"" .$currBlogId . "\">"
           . "<input type=\"submit\" value=\"" .$ButtonLabel ."\">"
           . "</form> <!-- notifyme -->\n"
           . "</div>\n";
    }
}
?>

Last edited by AdeasTridae (22.07.2004 16:30)

Offline

 

#2 20.03.2005 09:46

empiryk
BLOG:CMS PhD
From: Poland
Registered: 03.10.2004
Posts: 166
Website

Re: NP_NotifyMeBetter

Hmmm ....
Fatal error: Class np_notifyme: Cannot inherit from undefined class nucleusplugin in /home/studioo/public_html/weblog/extra/NP_NotifyMeBetter.php on line 6


[ I apologize for my poor english sad ]

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson

TOPlist