[pLog-svn] r7136 - in plugins/branches/lifetype-1.2/unported/subscribe: . class/action class/dao class/view locale templates

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Tue Sep 20 13:14:50 EDT 2011


Author: jondaley
Date: 2011-09-20 13:14:50 -0400 (Tue, 20 Sep 2011)
New Revision: 7136

Modified:
   plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeconfirmaction.class.php
   plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscriberegisteraction.class.php
   plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeshowconfigaction.class.php
   plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeupdateconfigaction.class.php
   plugins/branches/lifetype-1.2/unported/subscribe/class/dao/subscriptions.class.php
   plugins/branches/lifetype-1.2/unported/subscribe/class/view/pluginsubscribeshowconfigview.class.php
   plugins/branches/lifetype-1.2/unported/subscribe/class/view/pluginsubscribeshowview.class.php
   plugins/branches/lifetype-1.2/unported/subscribe/locale/locale_en_UK.php
   plugins/branches/lifetype-1.2/unported/subscribe/pluginsubscribe.class.php
   plugins/branches/lifetype-1.2/unported/subscribe/readme.txt
   plugins/branches/lifetype-1.2/unported/subscribe/templates/config.template
Log:
plugin updated for public use

Modified: plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeconfirmaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeconfirmaction.class.php	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeconfirmaction.class.php	2011-09-20 17:14:50 UTC (rev 7136)
@@ -34,7 +34,7 @@
             if(!Subscriptions::confirmSubscription($confirmation)){
                 $this->_view = new ErrorView($this->_blogInfo);
                 $this->_view->setErrorMessage(
-                    $this->_locale->tr("subscribe_error_incorrect_confirmation_code"));
+                    $this->_locale->tr("subscribe_error_confirming"));
                 $this->setCommonData();
                 return false;
 

Modified: plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscriberegisteraction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscriberegisteraction.class.php	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscriberegisteraction.class.php	2011-09-20 17:14:50 UTC (rev 7136)
@@ -36,7 +36,8 @@
             $emailAddress = $this->_request->getValue("subscribeEmail");
 
                 // save subscription info to database
-            if(!Subscriptions::addSubscriptions($registerCategories,
+            if(!Subscriptions::addSubscriptions($this->_blogInfo,
+                                                $registerCategories,
                                                 SUBSCRIBE_POSTS_IN_CATEGORY,
                                                 $emailAddress)){
                 $this->_view = new ErrorView($this->_blogInfo);

Modified: plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeshowconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeshowconfigaction.class.php	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeshowconfigaction.class.php	2011-09-20 17:14:50 UTC (rev 7136)
@@ -9,6 +9,15 @@
         }
         
         function perform(){
+			$blogSettings = $this->_blogInfo->getSettings();
+			$key = $blogSettings->getValue( "plugin_subscribe_key" );
+
+                // If the user never set the configuration key, set it now
+            if($key == ""){
+                $key = Subscriptions::generateNewKey($this->_blogInfo);
+            }
+
+
             $this->_view = new PluginSubscribeShowConfigView($this->_blogInfo);
             $this->setCommonData();
             return true;

Modified: plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeupdateconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeupdateconfigaction.class.php	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/class/action/pluginsubscribeupdateconfigaction.class.php	2011-09-20 17:14:50 UTC (rev 7136)
@@ -2,6 +2,7 @@
 
     lt_include(PLOG_CLASS_PATH."class/action/admin/adminaction.class.php");
     lt_include(PLOG_CLASS_PATH."plugins/subscribe/class/view/pluginsubscribeshowconfigview.class.php");
+    lt_include(PLOG_CLASS_PATH."plugins/subscribe/class/dao/subscriptions.class.php");
     lt_include(PLOG_CLASS_PATH."class/config/config.class.php");
     lt_include(PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php");
     lt_include(PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php");
@@ -9,6 +10,7 @@
     class PluginSubscribeUpdateConfigAction extends AdminAction
     {
         var $_pluginEnabled;
+        var $_key;
         
         function PluginSubscribeUpdateConfigAction($actionInfo, $request){
             $this->AdminAction( $actionInfo, $request );
@@ -17,13 +19,27 @@
         function validate(){
             $this->_pluginEnabled = $this->_request->getValue("pluginEnabled");
             $this->_pluginEnabled = ($this->_pluginEnabled != "");
+
+            $this->_key = $this->_request->getValue( "key" );
+/*            if( $this->_key == "" ) {
+                $this->_view = new PluginSubscribeShowConfigView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("subscribe_error_key"));
+                $this->setCommonData();
+                return false;
+            }
+*/          
             return true;
         }            
         
 		function perform(){
                 // update the plugin configurations to blog setting
 			$blogSettings = $this->_blogInfo->getSettings();
+
+            $oldKey = $blogSettings->getValue("plugin_subscribe_key");
+            $oldEnabled = $blogSettings->getValue("plugin_subscribe_enabled");
+
             $blogSettings->setValue("plugin_subscribe_enabled", $this->_pluginEnabled);
+            $blogSettings->setValue("plugin_subscribe_key", $this->_key);
             $this->_blogInfo->setSettings( $blogSettings ); 
                         
                 // save the blog's settings
@@ -44,8 +60,11 @@
 			$this->_view->setSuccessMessage( $this->_locale->tr("subscribe_settings_saved_ok"));
 			$this->setCommonData();
 			
-			// clear the cache
-			CacheControl::resetBlogCache( $this->_blogInfo->getId());			
+			// clear the cache and reset confirmation codes if something changed
+            if(($oldKey != $this->_key) || ($oldEnabled != $this->_pluginEnabled)){
+                Subscriptions::resetConfirmationCodes($this->_blogInfo);
+                CacheControl::resetBlogCache($this->_blogInfo->getId());
+            }
             
             return true;		
         }

Modified: plugins/branches/lifetype-1.2/unported/subscribe/class/dao/subscriptions.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/class/dao/subscriptions.class.php	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/class/dao/subscriptions.class.php	2011-09-20 17:14:50 UTC (rev 7136)
@@ -7,12 +7,15 @@
 
 class Subscriptions{
 
-        // Generate confirmation code and send confirmation email
+        /**
+         * Generate confirmation URL and send confirmation email
+         */
     function sendConfirmationEmail($blogInfo, $emailAddress){
         $confirmationUrl = Subscriptions::generateConfirmUrl($blogInfo,
                                                      "subscribeConfirm",
                                                      $emailAddress);
-        $confirmationCode = Subscriptions::_getConfirmationCode($emailAddress);
+        $confirmationCode = Subscriptions::_getConfirmationCode($blogInfo,
+                                                                $emailAddress);
 
         $locale = $blogInfo->getLocale();
         $ipAddress = Client::getIp();
@@ -27,9 +30,11 @@
         return $ret;
     }
 
-        // generate confirmation URL
+        /**
+         * Generate confirmation URL
+         */
     function generateConfirmUrl($blogInfo, $op, $address){
-        $confirmationCode = Subscriptions::_getConfirmationCode($address);
+        $confirmationCode = Subscriptions::_getConfirmationCode($blogInfo, $address);
 
         lt_include(PLOG_CLASS_PATH."class/net/rawrequestgenerator.class.php");
         $rg = new RawRequestGenerator($blogInfo);
@@ -40,8 +45,12 @@
         return ($rg->getIndexUrl().$rg->getRequest());
     }
 
-    
-    function resetConfirmationCodes(){
+        /**
+         * Reset all confirmation codes in the database
+         * Note, this will cause all previously emailed confirmation codes to no longer work,
+         * so, this operation should not be called often
+         */
+    function resetConfirmationCodes($blogInfo){
         lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
         $prefix = Db::getPrefix();
 
@@ -56,7 +65,8 @@
         
         while($row = $result->FetchRow()){
             $address = $row["address"];
-            $code = Subscriptions::_getConfirmationCode($address);
+            if(!$code = Subscriptions::_getConfirmationCode($blogInfo, $address))
+                return false;
             $query = "UPDATE ${prefix}subscribe SET confirm='$code' WHERE address='$address'";
             if(!$db->Execute($query))
                 return false;
@@ -65,19 +75,45 @@
         
         return true;
     }
+
+        /**
+         * User never typed in a security code, let's make one for him
+         */
+    function generateNewKey($blogInfo){
+        $key = md5(rand().time().filectime(__FILE__));
+        $blogSettings = $blogInfo->getSettings();
+        $blogSettings->setValue( "plugin_subscribe_key", $key );
+
+        $blogInfo->setSettings( $blogSettings ); 
+                        
+            // save the blog's settings
+        $blogs = new Blogs();
+        if(!$blogs->updateBlog($blogInfo))
+            return false;
+        
+        Subscriptions::resetConfirmationCodes($blogInfo);
+        return $key;
+    }
     
-        // calculate a secret hash used for confirmation of the email address
-    function _getConfirmationCode($address){
-//        $key = $blogSettings->getValue( "plugin_subscribe_key" );
-        $key = "JDKey";
+        /**
+         * calculate a secret hash used for confirmation of the email address
+         */
+    function _getConfirmationCode($blogInfo, $address){
+        $blogSettings = $blogInfo->getSettings();
+        $key = $blogSettings->getValue( "plugin_subscribe_key" );
 
+        if($key == ""){
+            if(!($key = Subscriptions::generateNewKey($blogInfo)))
+                return false;
+        }
+
+        // TODO: once we are on PHP5, use hash() instead        
         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
+        /**
+         * Activate a given subscription
+         */
     function confirmSubscription($confirmation){
         lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
         $db =& Db::getDb();
@@ -94,31 +130,34 @@
         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){
+        /**
+         * 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($blogInfo, $ids, $type, $address){
         lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
 
-        $confirmation = Subscriptions::_getConfirmationCode($address);
+        $confirmation = Subscriptions::_getConfirmationCode($blogInfo, $address);
 
         foreach($ids as $id){
             $db =& Db::getDb();
             $prefix = Db::getPrefix();
 
-            $query = "INSERT INTO ${prefix}subscribe (objid, active, type, address, confirm) ".
+            $query = "INSERT IGNORE INTO ${prefix}subscribe (objid, active, type, address, confirm) ".
                 "VALUES('$id', 0, '$type', '$address', '$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
+        
+        /**
+         * remove all subscriptions sent using this confirmation code
+         */
     function removeSubscriptions($confirmation){
         lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
 
@@ -136,8 +175,10 @@
         return true;
     }
 
-        // Based on the $type of object, search for $ids
-        // and return an array of subscribed email addresses
+        /**
+         * Based on the $type of object, search for $ids
+         * and return an array of subscribed email addresses
+         */
     function getSubscriptions($ids, $type){
         lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
         $prefix = Db::getPrefix();
@@ -167,8 +208,9 @@
     
         /**
          * Sends an email
+         * @param to The address to send the email to
          * @param subject The subject of the email
-         * @param message The message to be sent
+         * @param text The message to be sent
          */
     function sendMessage($to, $subject, $text){
         lt_include(PLOG_CLASS_PATH."class/mail/emailservice.class.php");
@@ -178,8 +220,7 @@
             // build the message
         $message = new EmailMessage();
         $config =& Config::getConfig();
-        $message->setFrom($config->getValue(
-                              "post_notification_source_address"));
+        $message->setFrom($config->getValue("post_notification_source_address"));
         $message->setSubject($subject);
         $message->setBody($text);
         $message->addTo($to);

Modified: plugins/branches/lifetype-1.2/unported/subscribe/class/view/pluginsubscribeshowconfigview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/class/view/pluginsubscribeshowconfigview.class.php	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/class/view/pluginsubscribeshowconfigview.class.php	2011-09-20 17:14:50 UTC (rev 7136)
@@ -1,6 +1,7 @@
 <?php
     lt_include(PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php");
     lt_include(PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php");
+    lt_include(PLOG_CLASS_PATH."plugins/subscribe/class/dao/subscriptions.class.php");
     
     class PluginSubscribeShowConfigView extends AdminPluginTemplatedView
     {
@@ -12,8 +13,10 @@
         function render(){
 			$blogSettings = $this->_blogInfo->getSettings();
 			$pluginEnabled = $blogSettings->getValue( "plugin_subscribe_enabled" );
+			$key = $blogSettings->getValue( "plugin_subscribe_key" );
 
             $this->setValue( "pluginEnabled", $pluginEnabled );
+            $this->setValue( "key", $key );
         
             parent::render();
         }

Modified: plugins/branches/lifetype-1.2/unported/subscribe/class/view/pluginsubscribeshowview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/class/view/pluginsubscribeshowview.class.php	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/class/view/pluginsubscribeshowview.class.php	2011-09-20 17:14:50 UTC (rev 7136)
@@ -9,10 +9,11 @@
         
         function render(){
 			$blogSettings = $this->_blogInfo->getSettings();
-			$pluginEnabled = $blogSettings->getValue("plugin_subscribe_enabled");
 
+            $pluginEnabled = $blogSettings->getValue("plugin_subscribe_enabled");
+            $this->setValue("pluginEnabled", $pluginEnabled);
+
             $categories = $this->_getArticleCategories();
-            $this->setValue("pluginEnabled", $pluginEnabled);
             $this->setValue("availableCategories", $categories);
 
             parent::render();

Modified: plugins/branches/lifetype-1.2/unported/subscribe/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/locale/locale_en_UK.php	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/locale/locale_en_UK.php	2011-09-20 17:14:50 UTC (rev 7136)
@@ -2,9 +2,11 @@
 
 $messages["subscribe"] = "Subscribe";
 $messages["subscribe_settings_saved_ok"] = "Settings saved successfully";
-$messages["subscribe_enabled"] = "Enable this plugin";
 $messages["subscribe_subscriptions"] = "Subscriptions";
 
+$messages["subscribe_enabled"] = "Enable this plugin";
+$messages["subscribe_key"] = "Random unique list of characters to secure your installation.  (Note, if you change this value, any existing confirmation codes will be reset and visitors won't be able to unsubscribe until they get another email from this system)";
+
 $messages["subscribe_posted_by"] = "Posted by: %s";
 $messages["subscribe_comment_on"] = "Comment on: %s";
 $messages["subscribe_article_published"] = "Article Published: %s";
@@ -20,6 +22,7 @@
 $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_error_confirming"] = "There was an error while subscribing, either the confirmation code was incorrect or 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.";
@@ -29,6 +32,7 @@
 $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_error_key"] = "Sorry, the random key must not be blank.  Type a handful of keystrokes in the box below.";
 
 $messages["subscribe_code_help"] = "Look in your inbox for the confirmation code and enter it below.";
 

Modified: plugins/branches/lifetype-1.2/unported/subscribe/pluginsubscribe.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/pluginsubscribe.class.php	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/pluginsubscribe.class.php	2011-09-20 17:14:50 UTC (rev 7136)
@@ -19,7 +19,7 @@
                 "sign up for them.";
             $this->author = "Jon Daley";
             $this->locales = Array("en_UK");
-            $this->version = "20090131";
+            $this->version = "20110920";
 			if( $source == "admin" )
 				$this->initAdmin();
 			else
@@ -41,7 +41,7 @@
             $this->addMenuEntry("/menu/controlCenter/manageRecentPlugins",
                                 "subscribe_subscriptions",
                                 "?op=subscribe", "");
-            $this->init(); // TODO: only needed for the POST_ADD, maybe just do that here instead of calling init()?
+            $this->registerNotification(EVENT_POST_POST_ADD);
         }
         
         function init(){
@@ -81,8 +81,7 @@
                   confirm VARCHAR(32)";
 
             $db =& Db::getDb();
-            $dbPrefix = Db::getPrefix();
-            $tableName = $dbPrefix."subscribe";
+            $tableName = Db::getPrefix()."subscribe";
             
                 // create the data dictionary and create
                 // the table if necessary
@@ -103,12 +102,6 @@
                 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;
         }
 
@@ -206,7 +199,8 @@
                     }
                     
                         // save subscription info to database
-                    if(Subscriptions::addSubscriptions(array($comment->getArticleId()),
+                    if(Subscriptions::addSubscriptions($this->blogInfo,
+                                                       array($comment->getArticleId()),
                                                         SUBSCRIBE_COMMENTS_IN_POST,
                                                         $emailAddress))
                     {

Modified: plugins/branches/lifetype-1.2/unported/subscribe/readme.txt
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/readme.txt	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/readme.txt	2011-09-20 17:14:50 UTC (rev 7136)
@@ -1,6 +1,5 @@
 Plugin: Subscribe
 Author: Jon Daley
-Release Date: 2007/03/03
 
 This plugin allows visitors to sign up for email notifications for
 future comments when posting a comments, and to also sign up for new
@@ -12,18 +11,18 @@
 Use:
 1. For new comment notifications, add this to your comment form:
 {if $subscribe && $subscribe->isEnabled()}
-<input type="checkbox" name="subscribe" />
-E-mail me when comments occur on this article
+  <input type="checkbox" name="subscribe" />
+  E-mail me when comments occur on this article
 {/if}
 
 2. For post/category notifications, add a link to:
-http://blog/?op=subscribe
+http://blog.url.../?op=subscribe
 
 
 
 TODO:
-Add a configuration key for the md5() call, so spammers can't sign
-  other people up for notifications.
-Make the subscribers get a notification when unmoderating the comments
+* Make the subscribers get a notification when unmoderating the comments
   (right now, only non-spams get subscriptions notices, and they don't
    get a notice after the blog owner marks it as non-spam)
+
+* Unsubscribe spammers when comments are marked as spam

Modified: plugins/branches/lifetype-1.2/unported/subscribe/templates/config.template
===================================================================
--- plugins/branches/lifetype-1.2/unported/subscribe/templates/config.template	2011-09-20 16:27:03 UTC (rev 7135)
+++ plugins/branches/lifetype-1.2/unported/subscribe/templates/config.template	2011-09-20 17:14:50 UTC (rev 7136)
@@ -13,6 +13,14 @@
      <input class="checkbox" type="checkbox" name="pluginEnabled" id="pluginEnabled" {if $pluginEnabled} checked="checked" {/if} value="1" {user_cannot_override key=plugin_subscribe_enabled}disabled="disabled"{/user_cannot_override} />{$locale->tr("subscribe_enabled")}
    </div>
   </div> 
+
+  <div class="field">
+   <label for="key">{$locale->tr("label_key")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("subscribe_key")}</div>
+   <input class="text" type="text" name="key" id="key" value="{$key}" {user_cannot_override key=plugin_subscribe_key}readonly="readonly"{/user_cannot_override} />
+  </div>
+
  </fieldset>
  <div class="buttons">
   <input type="hidden" name="op" value="subscribeUpdate" />



More information about the pLog-svn mailing list