[pLog-svn] r4953 - in plugins/branches/lifetype-1.1: . class class/action class/dao class/security class/view locale templates

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Sat Mar 3 16:59:10 EST 2007


Author: jondaley
Date: 2007-03-03 16:59:09 -0500 (Sat, 03 Mar 2007)
New Revision: 4953

Added:
   plugins/branches/lifetype-1.1/class/
   plugins/branches/lifetype-1.1/class/action/
   plugins/branches/lifetype-1.1/class/action/pluginsubscribeconfirmaction.class.php
   plugins/branches/lifetype-1.1/class/action/pluginsubscriberegisteraction.class.php
   plugins/branches/lifetype-1.1/class/action/pluginsubscriberemoveaction.class.php
   plugins/branches/lifetype-1.1/class/action/pluginsubscribeshowaction.class.php
   plugins/branches/lifetype-1.1/class/action/pluginsubscribeshowconfigaction.class.php
   plugins/branches/lifetype-1.1/class/action/pluginsubscribeupdateconfigaction.class.php
   plugins/branches/lifetype-1.1/class/dao/
   plugins/branches/lifetype-1.1/class/dao/codevalidator.class.php
   plugins/branches/lifetype-1.1/class/dao/subscriptions.class.php
   plugins/branches/lifetype-1.1/class/security/
   plugins/branches/lifetype-1.1/class/security/subscribefilter.class.php
   plugins/branches/lifetype-1.1/class/view/
   plugins/branches/lifetype-1.1/class/view/pluginsubscriberequestconfirmationview.class.php
   plugins/branches/lifetype-1.1/class/view/pluginsubscribeshowconfigview.class.php
   plugins/branches/lifetype-1.1/class/view/pluginsubscribeshowview.class.php
   plugins/branches/lifetype-1.1/locale/
   plugins/branches/lifetype-1.1/locale/locale_en_UK.php
   plugins/branches/lifetype-1.1/pluginsubscribe.class.php
   plugins/branches/lifetype-1.1/templates/
   plugins/branches/lifetype-1.1/templates/config.template
   plugins/branches/lifetype-1.1/templates/register.template
   plugins/branches/lifetype-1.1/templates/requestconfirmation.template
Log:
subscription plugin for visitors to sign up to get emails when comments
and posts are posted.


Added: plugins/branches/lifetype-1.1/class/action/pluginsubscribeconfirmaction.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/action/pluginsubscribeconfirmaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/action/pluginsubscribeconfirmaction.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,51 @@
+<?php
+
+    include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/subscribe/class/view/pluginsubscribeshowview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/subscribe/class/dao/codevalidator.class.php" );
+
+    class PluginSubscribeConfirmAction extends BlogAction
+    {
+        function PluginSubscribeConfirmAction($actionInfo, $request){
+            $this->BlogAction($actionInfo, $request);
+
+            $this->registerFieldValidator("code", new CodeValidator());
+
+            $view = new ErrorView($this->_blogInfo);
+			$view->setErrorMessage($this->_locale->tr("subscribe_error_incorrect_confirmation_code"));
+			$this->setValidationErrorView($view);
+            return true;
+        }
+
+		function perform(){
+			$blogSettings = $this->_blogInfo->getSettings();
+            $enabled = $blogSettings->getValue("plugin_subscribe_enabled", false);
+            if(!$enabled){
+                $this->_view = new ErrorView($this->_blogInfo);
+                $this->_view->setErrorMessage($this->_locale->tr("subscribe_disabled"));
+                $this->setCommonData();
+                return false;
+            }                        
+
+            $confirmation = $this->_request->getValue("code");
+
+            if(!Subscriptions::confirmSubscription($confirmation)){
+                $this->_view = new ErrorView($this->_blogInfo);
+                $this->_view->setErrorMessage(
+                    $this->_locale->tr("subscribe_error_incorrect_confirmation_code"));
+                $this->setCommonData();
+                return false;
+
+            }
+
+			$this->_view = new PluginSubscribeShowView($this->_blogInfo, false);
+			$this->_view->setSuccessMessage(
+                $this->_locale->tr("subscribe_subscription_saved_ok"));
+			$this->setCommonData();
+			
+            return true;		
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/action/pluginsubscriberegisteraction.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/action/pluginsubscriberegisteraction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/action/pluginsubscriberegisteraction.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,67 @@
+<?php
+
+    include_once(PLOG_CLASS_PATH."class/action/blogaction.class.php");
+    include_once(PLOG_CLASS_PATH."plugins/subscribe/class/view/pluginsubscriberequestconfirmationview.class.php");
+    include_once(PLOG_CLASS_PATH."class/view/errorview.class.php");
+    include_once(PLOG_CLASS_PATH."class/config/config.class.php");
+    include_once(PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php");
+    include_once(PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php");
+
+    class PluginSubscribeRegisterAction extends BlogAction
+    {
+        function PluginSubscribeRegisterAction($actionInfo, $request){
+            $this->BlogAction($actionInfo, $request);
+
+            $this->registerFieldValidator("subscribeEmail", new EmailValidator());
+            $this->registerFieldValidator("subscribeCategories", new ArrayValidator());
+                // todo: check if at least one category is selected
+
+            $view = new ErrorView($this->_blogInfo);
+			$view->setErrorMessage($this->_locale->tr("subscribe_missing_required_info"));
+			$this->setValidationErrorView($view);
+            return true;
+        }
+
+		function perform(){
+			$blogSettings = $this->_blogInfo->getSettings();
+            $enabled = $blogSettings->getValue("plugin_subscribe_enabled", false);
+            if(!$enabled){
+                $this->_view = new ErrorView($this->_blogInfo);
+                $this->_view->setErrorMessage($this->_locale->tr("subscribe_disabled"));
+                $this->setCommonData();
+                return false;
+            }                        
+
+            $registerCategories = $this->_request->getValue("subscribeCategories");
+            $emailAddress = $this->_request->getValue("subscribeEmail");
+
+                // save subscription info to database
+            if(!Subscriptions::addSubscriptions($registerCategories,
+                                                SUBSCRIBE_POSTS_IN_CATEGORY,
+                                                $emailAddress)){
+                $this->_view = new ErrorView($this->_blogInfo);
+                $this->_view->setErrorMessage($this->_locale->tr("subscribe_error_subscribing"));
+                $this->setCommonData();
+                return false;
+
+            }
+
+            if(Subscriptions::sendConfirmationEmail($this->_blogInfo,
+                                               $emailAddress))
+            {
+                $this->_view = new PluginSubscribeRequestConfirmationView($this->_blogInfo);
+                $this->_view->setSuccessMessage(
+                    $this->_locale->tr("subscribe_confirm_subscription"));
+                $this->setCommonData();
+                return true;
+            }
+            else{
+                $this->_view = new ErrorView($this->_blogInfo);
+                $this->_view->setErrorMessage(
+                    $this->_locale->tr("subscribe_couldnt_send_confirmation"));
+                $this->setCommonData();
+                return false;
+            }
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/action/pluginsubscriberemoveaction.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/action/pluginsubscriberemoveaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/action/pluginsubscriberemoveaction.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,51 @@
+<?php
+
+    include_once(PLOG_CLASS_PATH."class/action/blogaction.class.php");
+    include_once(PLOG_CLASS_PATH."plugins/subscribe/class/view/pluginsubscribeshowview.class.php");
+    include_once(PLOG_CLASS_PATH."class/view/errorview.class.php");
+    include_once(PLOG_CLASS_PATH."class/config/config.class.php");
+    include_once(PLOG_CLASS_PATH."plugins/subscribe/class/dao/codevalidator.class.php");
+
+    class PluginSubscribeRemoveAction extends BlogAction
+    {
+        function PluginSubscribeRemoveAction($actionInfo, $request){
+            $this->BlogAction($actionInfo, $request);
+
+            $this->registerFieldValidator("code", new CodeValidator());
+
+            $view = new ErrorView($this->_blogInfo);
+			$view->setErrorMessage($this->_locale->tr("subscribe_error_incorrect_confirmation_code"));
+			$this->setValidationErrorView($view);
+            return true;
+        }
+
+		function perform(){
+			$blogSettings = $this->_blogInfo->getSettings();
+            $enabled = $blogSettings->getValue("plugin_subscribe_enabled", false);
+            if(!$enabled){
+                $this->_view = new ErrorView($this->_blogInfo);
+                $this->_view->setErrorMessage($this->_locale->tr("subscribe_disabled"));
+                $this->setCommonData();
+                return false;
+            }
+
+            $confirmation = $this->_request->getValue("code");
+
+            if(!Subscriptions::removeSubscriptions($confirmation)){
+                $this->_view = new ErrorView($this->_blogInfo);
+                $this->_view->setErrorMessage(
+                    $this->_locale->tr("subscribe_error_incorrect_confirmation_code"));
+                $this->setCommonData();
+                return false;
+
+            }
+
+			$this->_view = new PluginSubscribeShowView($this->_blogInfo, false);
+			$this->_view->setSuccessMessage(
+                $this->_locale->tr("subscribe_subscription_removed_ok"));
+			$this->setCommonData();
+			
+            return true;		
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/action/pluginsubscribeshowaction.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/action/pluginsubscribeshowaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/action/pluginsubscribeshowaction.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,17 @@
+<?php
+    include_once(PLOG_CLASS_PATH."class/action/blogaction.class.php");
+    include_once(PLOG_CLASS_PATH."plugins/subscribe/class/view/pluginsubscribeshowview.class.php");
+
+    class PluginSubscribeShowAction extends BlogAction
+    {
+        function PluginSubscribeShowAction($actionInfo, $request){
+            $this->BlogAction($actionInfo, $request);
+        }
+        
+        function perform(){
+            $this->_view = new PluginSubscribeShowView($this->_blogInfo, true);
+            $this->setCommonData();
+            return true;
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/action/pluginsubscribeshowconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/action/pluginsubscribeshowconfigaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/action/pluginsubscribeshowconfigaction.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,17 @@
+<?php
+
+    include_once(PLOG_CLASS_PATH."class/action/admin/adminaction.class.php");
+    include_once(PLOG_CLASS_PATH."plugins/subscribe/class/view/pluginsubscribeshowconfigview.class.php");
+
+    class PluginSubscribeShowConfigAction extends AdminAction{
+        function PluginSubscribeShowConfigAction($actionInfo, $request){
+            $this->AdminAction($actionInfo, $request);
+        }
+        
+        function perform(){
+            $this->_view = new PluginSubscribeShowConfigView($this->_blogInfo);
+            $this->setCommonData();
+            return true;
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/action/pluginsubscribeupdateconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/action/pluginsubscribeupdateconfigaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/action/pluginsubscribeupdateconfigaction.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,53 @@
+<?php
+
+    include_once(PLOG_CLASS_PATH."class/action/admin/adminaction.class.php");
+    include_once(PLOG_CLASS_PATH."plugins/subscribe/class/view/pluginsubscribeshowconfigview.class.php");
+    include_once(PLOG_CLASS_PATH."class/config/config.class.php");
+    include_once(PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php");
+    include_once(PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php");
+
+    class PluginSubscribeUpdateConfigAction extends AdminAction
+    {
+        var $_pluginEnabled;
+        
+        function PluginSubscribeUpdateConfigAction($actionInfo, $request){
+            $this->AdminAction( $actionInfo, $request );
+        }
+
+        function validate(){
+            $this->_pluginEnabled = $this->_request->getValue("pluginEnabled");
+            $this->_pluginEnabled = ($this->_pluginEnabled != "");
+            return true;
+        }            
+        
+		function perform(){
+                // update the plugin configurations to blog setting
+			$blogSettings = $this->_blogInfo->getSettings();
+            $blogSettings->setValue("plugin_subscribe_enabled", $this->_pluginEnabled);
+            $this->_blogInfo->setSettings( $blogSettings ); 
+                        
+                // save the blog's settings
+			$blogs = new Blogs();
+            if( !$blogs->updateBlog( $this->_blogInfo )) {
+                $this->_view = new PluginSubscribeShowConfigView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
+                $this->setCommonData();
+
+                return false;
+            }
+			
+			// if everything went ok...
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+			
+			$this->_view = new PluginSubscribeShowConfigView($this->_blogInfo);
+			$this->_view->setSuccessMessage( $this->_locale->tr("subscribe_settings_saved_ok"));
+			$this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());			
+            
+            return true;		
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/dao/codevalidator.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/dao/codevalidator.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/dao/codevalidator.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,21 @@
+<?php
+
+	include_once(PLOG_CLASS_PATH."class/data/validator/validator.class.php");
+	include_once(PLOG_CLASS_PATH."class/data/validator/rules/regexprule.class.php");
+
+    define("HEXADECIMAL_RULE_REG_EXP", "^[a-z0-9]+$");
+
+    /**
+     * \ingroup Validator
+     *
+     * Checks that a string only contains hexadecimal characters
+     *
+     * @see RegExpRule
+     */
+    class CodeValidator extends Validator {
+    	function CodeValidator(){
+        	$this->Validator();
+            $this->addRule(new RegExpRule(HEXADECIMAL_RULE_REG_EXP));
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/dao/subscriptions.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/dao/subscriptions.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/dao/subscriptions.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,206 @@
+<?php
+
+    include_once( PLOG_CLASS_PATH."class/net/client.class.php" );
+
+define("SUBSCRIBE_POSTS_IN_CATEGORY", 0);
+define("SUBSCRIBE_COMMENTS_IN_POST", 1);
+
+class Subscriptions{
+
+        // Generate confirmation code and send confirmation email
+    function sendConfirmationEmail($blogInfo, $emailAddress){
+        $confirmationUrl = Subscriptions::generateConfirmUrl($blogInfo,
+                                                     "subscribeConfirm",
+                                                     $emailAddress);
+        $confirmationCode = Subscriptions::_getConfirmationCode($emailAddress);
+
+        $locale = $blogInfo->getLocale();
+        $ipAddress = Client::getIp();
+        if(!$ipAddress)
+            $ipAddress = "Unknown";
+        $ret = Subscriptions::sendMessage($emailAddress,
+                                          $locale->tr("subscribe_email_confirm_subject"),
+                                          $locale->pr("subscribe_email_confirm_body",
+                                                      $confirmationCode,
+                                                      $confirmationUrl,
+                                                      $ipAddress));
+        return $ret;
+    }
+
+        // generate confirmation URL
+    function generateConfirmUrl($blogInfo, $op, $address){
+        $confirmationCode = Subscriptions::_getConfirmationCode($address);
+
+        include_once(PLOG_CLASS_PATH."class/net/rawrequestgenerator.class.php");
+        $rg = new RawRequestGenerator($blogInfo);
+        $rg->addParameter("op", $op);
+        $rg->addParameter("blogId", $blogInfo->getId());
+        $rg->addParameter("code", $confirmationCode);
+        $rg->setXHTML(false);
+        return ($rg->getIndexUrl().$rg->getRequest());
+    }
+
+    
+    function resetConfirmationCodes(){
+        include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+        $prefix = Db::getPrefix();
+
+        $query = "SELECT type,address ".
+            "FROM {$prefix}subscribe";
+
+        $db =& Db::getDb();
+
+        $result = $db->Execute($query);
+        if(!$result)
+            return false;
+        
+        while($row = $result->FetchRow()){
+            $address = $row["address"];
+            $code = Subscriptions::_getConfirmationCode($address);
+            
+            $query = Db::buildUpdateQuery("subscribe",
+                                          array("confirm" => $code),
+                                          array("address" => $address));
+            
+            if(!$db->Execute($query))
+                return false;
+
+        }
+
+        
+        return true;
+    }
+    
+        // calculate a secret hash used for confirmation of the email address
+    function _getConfirmationCode($address){
+            // TODO: make a configuration option to set this key
+        $key = "JDKey";
+        
+        return md5($address . $key);
+            // PHP5 has a faster version (according to a commenter on the
+            // php docs for md5 - and I think a LT user...
+            // $confirmation = bin2hex(md5($type.$address."JDKey", true));
+    }
+    
+        // activate a given subscription
+    function confirmSubscription($confirmation){
+        include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+        $db =& Db::getDb();
+        $query = Db::buildUpdateQuery("subscribe",
+                                      array("active" => 1),
+                                      array("confirm" => $confirmation));
+        
+        if(!$db->Execute($query))
+            return false;
+
+            // check to make sure that at least one row was updated
+        if($db->Affected_Rows() < 1)
+            return false;
+            
+        return true;
+    }
+
+        // add an email address to the database with the
+        // associated type, for each id, but leave it disabled
+        // until it is confirmed later
+    function addSubscriptions($ids, $type, $address){
+        include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+
+        $confirmation = Subscriptions::_getConfirmationCode($address);
+
+        foreach($ids as $id){
+            $db =& Db::getDb();
+            $query = Db::buildInsertQuery("subscribe",
+                                          array("objid" => $id,
+                                                "active" => 0,
+                                                "type" => $type,
+                                                "address" => $address,
+                                                "confirm" => $confirmation));
+            $result = $db->Execute($query);
+            if(!$result)
+                return false;
+                // TODO: check what happens if already registered.
+                // if Affected_Rows < 1, perhaps they want a new confirmation code?
+        }
+
+        return true;
+    }
+
+        // remove all subscriptions sent using this confirmation code
+    function removeSubscriptions($confirmation){
+        include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+
+        $db =& Db::getDb();
+        $query = Db::buildDeleteQuery("subscribe",
+                                      "confirm",
+                                      $confirmation);
+        $result = $db->Execute($query);
+        if(!$result)
+            return false;
+
+            // check to make sure that at least one row was updated
+        if($db->Affected_Rows() < 1)
+            return false;
+
+        return true;
+    }
+
+        // Based on the $type of object, search for $ids
+        // and return an array of subscribed email addresses
+    function getSubscriptions($ids, $type){
+        include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+        $prefix = Db::getPrefix();
+
+        $query = "SELECT address ".
+            "FROM {$prefix}subscribe ".
+            "WHERE active=1 AND ".
+            "type=".$type." AND (";
+        foreach($ids as $id)
+            $query .= "objid=$id OR ";
+        $query .= "objid=0)";
+
+        $db =& Db::getDb();
+//        $query = Db::buildSelectQuery("subscribe",
+//                                      "address",
+//                                      array("active" => 1,
+//                                            "type" => $type,
+
+        $result = $db->Execute($query);
+        if( !$result )
+            return Array();
+        
+        $addresses = Array();
+        while($row = $result->FetchRow()){
+            $addresses[] = $row["address"];
+        }
+        
+        return($addresses);
+    }
+    
+    
+        /**
+         * Sends an email
+         * @param subject The subject of the email
+         * @param message The message to be sent
+         */
+    function sendMessage($to, $subject, $text){
+        include_once(PLOG_CLASS_PATH."class/mail/emailservice.class.php");
+        include_once(PLOG_CLASS_PATH."class/mail/emailmessage.class.php");
+        include_once(PLOG_CLASS_PATH."class/config/config.class.php");
+        
+            // build the message
+        $message = new EmailMessage();
+        $config =& Config::getConfig();
+        $message->setFrom($config->getValue(
+                              "post_notification_source_address"));
+        $message->setSubject($subject);
+        $message->setBody($text);
+        $message->addTo($to);
+        
+            // once the message is ready, send it out
+        $service = new EmailService();
+        return($service->sendMessage($message));
+    }
+}
+
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/security/subscribefilter.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/security/subscribefilter.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/security/subscribefilter.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,61 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/security/pipelinefilter.class.php" );
+    include_once( PLOG_CLASS_PATH."class/file/file.class.php" );	
+    include_once( PLOG_CLASS_PATH."class/config/config.class.php" );	
+
+
+    /**
+     * Checks to see if the subscription checkbox was checked, and if so,
+     * requires the email address to be valid. This
+     * filter only works if the incoming request has the "op" parameter as
+     * "AddComment", because then it means that we're posting a comment. If it's not
+     * like that, then we'll quit. Otherwise, the process will continue as normally.
+     */
+	class SubscribeFilter extends PipelineFilter{
+    	function SubscribeFilter($pipelineRequest){
+        	$this->PipelineFilter($pipelineRequest);
+        }
+
+        function filter(){
+        	// get some info
+            $blogInfo = $this->_pipelineRequest->getBlogInfo();
+            $request  = $this->_pipelineRequest->getHttpRequest();
+
+        	// check if this section has been enabled or disabled
+            $blogSettings = $blogInfo->getSettings();
+		    $pluginEnabled = $blogSettings->getValue( "plugin_authimage_enabled" );
+            if(!$pluginEnabled)
+            	return new PipelineResult();
+
+            // we only have to filter the contents if the user is posting a comment
+            // so there's no point in doing anything else if that's not the case
+            if($request->getValue("op") != "AddComment")
+            	return new PipelineResult();
+
+            // if this is already rejected, there is no reason to do anything here
+            if($this->_pipelineRequest->getRejectedState())
+                return new PipelineResult();
+
+                // checkbox not active, don't do anything
+            if(!$request->getValue("subscribe"))
+                return new PipelineResult();
+
+                // email is required: validate it.
+            $emailAddress = $request->getValue("userEmail");
+
+            include_once( PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );
+
+            $emailValidator = new EmailValidator();
+            if(!$emailValidator->validate($emailAddress)){
+                $locale = $blogInfo->getLocale();
+                return new PipelineResult(false, 500,
+                                          $locale->tr("error_incorrect_email_address"));
+            }
+
+                // if everything went fine, we can say so by returning
+                // a positive PipelineResult object
+            return new PipelineResult();
+        }
+    }
+?>

Added: plugins/branches/lifetype-1.1/class/view/pluginsubscriberequestconfirmationview.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/view/pluginsubscriberequestconfirmationview.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/view/pluginsubscriberequestconfirmationview.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,20 @@
+<?php
+    include_once( PLOG_CLASS_PATH."class/view/plugintemplatedview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+    
+    class PluginSubscribeRequestConfirmationView extends PluginTemplatedView{
+        function PluginSubscribeRequestConfirmationView($blogInfo){
+            $this->PluginTemplatedView($blogInfo, "subscribe", "requestconfirmation",
+                                       SMARTY_VIEW_CACHE_DISABLED);
+        }
+        
+        function render(){
+			$blogSettings = $this->_blogInfo->getSettings();
+			$pluginEnabled = $blogSettings->getValue("plugin_subscribe_enabled");
+
+            $this->setValue("pluginEnabled", $pluginEnabled);
+
+            parent::render();
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/view/pluginsubscribeshowconfigview.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/view/pluginsubscribeshowconfigview.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/view/pluginsubscribeshowconfigview.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,21 @@
+<?php
+    include_once(PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php");
+    include_once(PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php");
+    
+    class PluginSubscribeShowConfigView extends AdminPluginTemplatedView
+    {
+    
+        function PluginSubscribeShowConfigView($blogInfo){
+            $this->AdminPluginTemplatedView($blogInfo, "subscribe", "config");
+        }
+        
+        function render(){
+			$blogSettings = $this->_blogInfo->getSettings();
+			$pluginEnabled = $blogSettings->getValue( "plugin_subscribe_enabled" );
+
+            $this->setValue( "pluginEnabled", $pluginEnabled );
+        
+            parent::render();
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/class/view/pluginsubscribeshowview.class.php
===================================================================
--- plugins/branches/lifetype-1.1/class/view/pluginsubscribeshowview.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/class/view/pluginsubscribeshowview.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,21 @@
+<?php
+    include_once( PLOG_CLASS_PATH."class/view/plugintemplatedview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+    
+    class PluginSubscribeShowView extends PluginTemplatedView{
+        function PluginSubscribeShowView($blogInfo){
+            $this->PluginTemplatedView($blogInfo, "subscribe", "register", SMARTY_VIEW_CACHE_DISABLED);
+        }
+        
+        function render(){
+			$blogSettings = $this->_blogInfo->getSettings();
+			$pluginEnabled = $blogSettings->getValue("plugin_subscribe_enabled");
+
+            $categories = $this->_getArticleCategories();
+            $this->setValue("pluginEnabled", $pluginEnabled);
+            $this->setValue("availableCategories", $categories);
+
+            parent::render();
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.1/locale/locale_en_UK.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/locale/locale_en_UK.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,39 @@
+<?php
+
+$messages["subscribe"] = "Subscribe";
+$messages["subscribe_settings_saved_ok"] = "Settings saved successfully";
+$messages["subscribe_enabled"] = "Enable this plugin";
+$messages["subscribe_subscriptions"] = "Subscriptions";
+
+$messages["subscribe_posted_by"] = "Posted by: %s";
+$messages["subscribe_comment_on"] = "Comment on: %s";
+$messages["subscribe_article_published"] = "Article Published: %s";
+
+$messages["subscribe_disabled"] = "Sorry, this feature has been disabled";
+$messages["subscribe_subscriptions_saved_ok"] = "Your subscription has been saved!";
+
+$messages["subscribe_label_configuration"] = "Configure your subscriptions";
+
+$messages["subscribe_label_pick_category"] = "For each category you check, you will receive an email each time a post is made";
+
+$messages["subscribe_confirm_subscription"] = "Your subscription needs to be confirmed.  Check your email for your confirmation code.";
+$messages["subscribe_subscription_saved_ok"] = "Your subscription was saved successfully.";
+$messages["subscribe_subscription_removed_ok"] = "Your subscriptions have been removed successfully.";
+$messages["subscribe_error_subscribing"] = "There was an error while subscribing - perhaps you are already subscribed?";
+
+$messages["subscribe_email_confirm_subject"] = "Confirm your blog subscription";
+$messages["subscribe_email_confirm_body"] = "Someone (presumably you) requested an email subscription notification for a blog.\n\nIf you did not request this notification, you can safely ignore this message.\n\nIf you have trouble clicking on the link, and still have your web browser open to the confirmation page, you can enter this code in directly:\n\t%s\n\nTo activate your subscription, authorizing us to send you further emails, click here:\n%s\n\nThis request was initiated from the IP address: %s.\n\nHave a nice day.";
+
+$messages["subscribe_couldnt_send_confirmation"] = "Couldn't send confirmation email.  Try confirming with a different email address, or check with the site owner to see if there is a problem with the SMTP server.";
+
+$messages["subscribe_missing_required_info"] = "Sorry, please try again.  There was some missing information.";
+
+$messages["subscribe_error_incorrect_confirmation_code"] = "Sorry, that confirmation code appears to be incorrect.  Please try again";
+
+$messages["subscribe_code_help"] = "Look in your inbox for the confirmation code and enter it below.";
+
+$messages["confirm"] = "Confirm";
+
+$messages["subscribe_email_removal"] = "Click on the following link to remove all subscriptions to this blog:\n%s";
+
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/pluginsubscribe.class.php
===================================================================
--- plugins/branches/lifetype-1.1/pluginsubscribe.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.1/pluginsubscribe.class.php	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,215 @@
+<?php
+    include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/subscribe/class/dao/subscriptions.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/subscribe/class/security/subscribefilter.class.php" );	
+
+    /**
+     * Sends notifications to visitors if they sign up for them, such as
+     * new comments to a post, new post to a particular category, etc.
+     */
+    class PluginSubscribe extends PluginBase
+    {
+        var $_pluginEnabled;
+        
+        function PluginSubscribe(){
+            $this->PluginBase();
+            
+            $this->id = "subscribe";
+            $this->desc = "Sends email notifications to visitors if they ".
+                "sign up for them.";
+            $this->author = "Jon Daley";
+            $this->locales = Array("en_UK");
+            
+                // register our actions
+            $this->registerAdminAction("subscribe",
+                                       "PluginSubscribeShowConfigAction");
+            $this->registerAdminAction("subscribeUpdate",
+                                       "PluginSubscribeUpdateConfigAction");
+			$this->registerBlogAction("subscribe",
+                                      "PluginSubscribeShowAction");
+			$this->registerBlogAction("subscribeRegister",
+                                      "PluginSubscribeRegisterAction");
+			$this->registerBlogAction("subscribeConfirm",
+                                      "PluginSubscribeConfirmAction");
+			$this->registerBlogAction("subscribeRemove",
+                                      "PluginSubscribeRemoveAction");
+            
+                // register our menu options
+			include_once(PLOG_CLASS_PATH."class/template/menu/menu.class.php");
+            
+			$menu =& Menu::getMenu();
+			if(!$menu->entryExists("/menu/controlCenter/manageRecentPlugins"))
+				$this->addMenuEntry("/menu/controlCenter",
+                                    "manageRecentPlugins", "", "",
+                                    true, false);
+            $this->addMenuEntry("/menu/controlCenter/manageRecentPlugins",
+                                "subscribe_subscriptions",
+                                "?op=subscribe", "");
+
+                // we care about when posts and comments are posted
+            $this->registerNotification(EVENT_POST_POST_ADD);
+            $this->registerNotification(EVENT_POST_COMMENT_ADD);
+                // We need a filter because the email address is required
+                // if the subscribe checkbox is checked.
+			$this->registerFilter("SubscribeFilter");
+        }
+
+	    function isEnabled(){
+	        return $this->_pluginEnabled;
+	    }
+
+        function register(){
+            $this->_pluginEnabled = $this->blogSettings->getValue("plugin_subscribe_enabled");
+            return true;
+        }
+        
+            // create the sql table
+        function install(){
+            include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+            
+            $fields = "objid INT(10) UNSIGNED NOTNULL,
+                  active TINYINT(1) DEFAULT 0,
+                  type TINYINT(1) NOTNULL,
+                  address VARCHAR(255) NOTNULL,
+                  confirm VARCHAR(32)";
+
+            $db =& Db::getDb();
+            $dbPrefix = Db::getPrefix();
+            $tableName = $dbPrefix."subscribe";
+            
+                // create the data dictionary and create
+                // the table if necessary
+            $dict = NewPDbDataDictionary($db);
+            $sqlArray = $dict->ChangeTableSQL($tableName, $fields);
+            $result = $dict->ExecuteSQLArray($sqlArray);
+            if(!$result)
+                die("There was an error creating the tables ".
+                    "for the subscribe plugin!");
+
+            $sqlArray = $dict->CreateIndexSQL("id_type_address",
+                                              $tableName,
+                                              array("objid","type","address"),
+                                              array("REPLACE", "UNIQUE"));
+                // create the primary key
+            $result = $dict->ExecuteSQLArray($sqlArray);
+            if(!$result)
+                die("There was an error creating the index ".
+                    "for the subscribe plugin!");
+
+                // In the early stages of this plugin, the
+                // confirmation codes were erased.  This will
+                // recalculate them, though you shouldn't ever
+                // need this any more.
+                // Subscriptions::resetConfirmationCodes();
+            
+            return true;
+        }
+
+        
+        /**
+         * This method processes our event notifications
+         */        
+        function process($eventType, $params){        
+            include_once(PLOG_CLASS_PATH."class/data/textfilter.class.php");
+            include_once(PLOG_CLASS_PATH."class/dao/article.class.php");
+
+            $locale = $this->blogInfo->getLocale();
+            
+            switch($eventType){
+              case EVENT_POST_POST_ADD:
+                $article = $params["article"];
+                if($article->getStatus() != POST_STATUS_PUBLISHED)
+                    return;
+
+                    // don't send notifications for future posts
+                $now = new Timestamp();
+                if($article->getDateObject() > $now)
+                    return;
+                
+                $rg = RequestGenerator::getRequestGenerator($this->blogInfo);
+                $arr = Subscriptions::getSubscriptions($article->getCategoryIds(),
+                                        SUBSCRIBE_POSTS_IN_CATEGORY);
+                foreach($arr as $email){
+                        // TODO: provide a templating
+                        // mechanism for the body of the email
+                    Subscriptions::sendMessage($email,
+                                               $locale->pr("subscribe_article_published",
+                                                           $article->getTopic()),
+                                               Textfilter::htmlDecode(
+                                                   Textfilter::filterAllHTML(
+                                                       $article->getIntroText())) .
+                                               "\n\n".$rg->postPermalink($article).
+                                               "\n\n".
+                                               $locale->pr("subscribe_email_removal",
+                                                           Subscriptions::generateConfirmUrl(
+                                                               $this->blogInfo,
+                                                               "subscribeRemove",
+                                                               $email)));
+                }
+                break;
+
+              case EVENT_POST_COMMENT_ADD:
+                include_once(PLOG_CLASS_PATH.
+                             "class/dao/usercomment.class.php");
+                include_once(PLOG_CLASS_PATH.
+                             "class/net/requestgenerator.class.php");
+                $comment = $params["comment"];
+                if($comment->getStatus() != COMMENT_STATUS_NONSPAM)
+                    return;
+                $article = $comment->getArticle();
+
+                $rg = RequestGenerator::getRequestGenerator($this->blogInfo);
+                $arr = Subscriptions::getSubscriptions(
+                    array($comment->getArticleId()),
+                    SUBSCRIBE_COMMENTS_IN_POST);
+
+                foreach($arr as $email){
+                        // TODO: provide a templating
+                        // mechanism for the body of the email
+                    Subscriptions::sendMessage($email,
+                                               $locale->pr("subscribe_comment_on",
+                                                           $article->getTopic()),
+                                               $locale->pr("subscribe_posted_by",
+                                                           $comment->getUserName())."\n".
+                                               Textfilter::htmlDecode(
+                                                   Textfilter::filterAllHTML(
+                                                       $comment->getText())) .
+                                               "\n\n".$rg->postPermalink($article).
+                                               "\n\n".
+                                               $locale->pr("subscribe_email_removal",
+                                                           Subscriptions::generateConfirmUrl(
+                                                               $this->blogInfo,
+                                                               "subscribeRemove",
+                                                               $email)));
+                }
+
+                $request = HttpVars::getRequest();
+
+                    // Now check to see if this guy wants to receive
+                    // future notifications of comments
+                if(isset($request["subscribe"])){
+                        // We already validated this
+                    $emailAddress = $request["userEmail"];
+                        // save subscription info to database
+                    if(Subscriptions::addSubscriptions(array($comment->getArticleId()),
+                                                        SUBSCRIBE_COMMENTS_IN_POST,
+                                                        $emailAddress))
+                    {
+                            // send confirmation email
+                        if(!Subscriptions::sendConfirmationEmail($this->blogInfo,
+                                                                 $emailAddress)){
+                                // TODO: can we do anything if there was an error?
+                        }
+                    }
+                    else{
+                            // TODO: can we do anything if there was an error?
+                    }
+                }
+                
+                break;
+              default:
+                return;
+            }
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.1/templates/config.template
===================================================================
--- plugins/branches/lifetype-1.1/templates/config.template	                        (rev 0)
+++ plugins/branches/lifetype-1.1/templates/config.template	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,23 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=subscribe_subscriptions
+        title=$locale->tr("subscribe_subscriptions")}
+<form name="subscribepluginConfig" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("label_configuration")}</legend> 
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}
+  <div class="field">
+   <label for="pluginEnabled">{$locale->tr("label_enable")}</label>
+   <span class="required"></span>
+   <div class="formHelp">
+     <input class="checkbox" type="checkbox" name="pluginEnabled" id="pluginEnabled" {if $pluginEnabled} checked="checked" {/if} value="1" />{$locale->tr("subscribe_enabled")}
+   </div>
+  </div> 
+ </fieldset>
+ <div class="buttons">
+  <input type="hidden" name="op" value="subscribeUpdate" />
+  <input type="submit" name="{$locale->tr("settings")}" value="{$locale->tr("update")}" />
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}

Added: plugins/branches/lifetype-1.1/templates/register.template
===================================================================
--- plugins/branches/lifetype-1.1/templates/register.template	                        (rev 0)
+++ plugins/branches/lifetype-1.1/templates/register.template	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,50 @@
+{include file="$blogtemplate/header.template"}
+<script type="text/javascript" src="js/ui/default.js"></script>
+
+{if $subscribe && $subscribe->isEnabled()}
+<form method='post' id="subscribeCategories">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("subscribe_label_configuration")}</legend> 
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}
+
+    <div class="field">
+      <div class="formHelp">{$locale->tr("email_help")}</div>
+      <input type="text" name="subscribeEmail" value="{$subscribeEmail}" 
+             id="subscribeEmail" />
+      {include file="$admintemplatepath/validate.template" field=subscribeEmail
+               message=$locale->tr("error_incorrect_email_address")}
+    </div>
+
+  <br />
+  <label for="subscribeCategories">{$locale->tr("subscribe_label_pick_category")}</label>
+  <div class="field">
+   <div class="formHelp">
+      <input class="checkbox" type="checkbox" name="all" id="all" value="1"
+          onclick="toggleAllChecks('subscribeCategories');" />
+      All
+   </div>
+  </div> 
+  {foreach from=$availableCategories item=availableCategory name=availableCategory}
+  <div class="field">
+   <div class="formHelp">
+    <input class="checkbox" type="checkbox" name="subscribeCategories[]"
+          value="{$availableCategory->getId()}" />
+     {$availableCategory->getName()}
+   </div>
+  </div> 
+  {/foreach}
+
+
+ </fieldset>
+ <div class="buttons">
+  <input type="hidden" name="op" value="subscribeRegister" />
+  <input type="hidden" name="blogId" value="{$blog->getId()}" />
+  <input type="submit" value="{$locale->tr("subscribe")}" />
+ </div>
+</form>
+{else}
+   {$locale->tr("subscribe_disabled")}
+{/if}
+<br />
+{include file="$blogtemplate/footer.template"}

Added: plugins/branches/lifetype-1.1/templates/requestconfirmation.template
===================================================================
--- plugins/branches/lifetype-1.1/templates/requestconfirmation.template	                        (rev 0)
+++ plugins/branches/lifetype-1.1/templates/requestconfirmation.template	2007-03-03 21:59:09 UTC (rev 4953)
@@ -0,0 +1,29 @@
+{include file="$blogtemplate/header.template"}
+
+{if $subscribe && $subscribe->isEnabled()}
+<form method='post'>
+ <fieldset class="inputField">
+  <legend>{$locale->tr("subscribe_label_configuration")}</legend> 
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}
+
+    <div class="field">
+      <div class="formHelp">{$locale->tr("subscribe_code_help")}</div>
+      <input type="text" name="code" value="{$code}" 
+             id="code" />
+      {include file="$admintemplatepath/validate.template" field=code
+               message=$locale->tr("subscribe_error_incorrect_confirmation_code")}
+    </div>
+ </fieldset>
+
+ <div class="buttons">
+  <input type="hidden" name="op" value="subscribeConfirm" />
+  <input type="hidden" name="blogId" value="{$blog->getId()}" />
+  <input type="submit" value="{$locale->tr("confirm")}" />
+ </div>
+</form>
+{else}
+   {$locale->tr("subscribe_disabled")}
+{/if}
+<br />
+{include file="$blogtemplate/footer.template"}



More information about the pLog-svn mailing list