[pLog-svn] r7271 - in plugins/branches/lifetype-1.2/subscribe: . locale

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Thu Feb 8 09:52:19 EST 2024


Author: jondaley
Date: 2024-02-08 09:52:19 -0500 (Thu, 08 Feb 2024)
New Revision: 7271

Modified:
   plugins/branches/lifetype-1.2/subscribe/locale/locale_en_UK.php
   plugins/branches/lifetype-1.2/subscribe/pluginsubscribe.class.php
Log:
add a 'continue reading text before the text to make it obvious that the blog post doesn't contain the full text.  subscribers now get notified when changing from draft (or anything) to published

Modified: plugins/branches/lifetype-1.2/subscribe/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/subscribe/locale/locale_en_UK.php	2024-02-08 14:42:06 UTC (rev 7270)
+++ plugins/branches/lifetype-1.2/subscribe/locale/locale_en_UK.php	2024-02-08 14:52:19 UTC (rev 7271)
@@ -41,5 +41,4 @@
 $messages["subscribe_email_removal"] = "Click on the following link to remove all subscriptions to this blog:\n%s";
 
 $messages['subscribe_email_help'] = 'Email address where notifications will be sent.';
-
-?>
\ No newline at end of file
+$messages['subscribe_continue_reading'] = 'Continue reading at %s';

Modified: plugins/branches/lifetype-1.2/subscribe/pluginsubscribe.class.php
===================================================================
--- plugins/branches/lifetype-1.2/subscribe/pluginsubscribe.class.php	2024-02-08 14:42:06 UTC (rev 7270)
+++ plugins/branches/lifetype-1.2/subscribe/pluginsubscribe.class.php	2024-02-08 14:52:19 UTC (rev 7271)
@@ -10,7 +10,8 @@
 class PluginSubscribe extends PluginBase
 {
   var $_pluginEnabled;
-        
+  var $_oldArticleStatus = false;
+  
   function PluginSubscribe($source = ""){
     $this->PluginBase($source);
             
@@ -42,6 +43,8 @@
                         "subscribe_subscriptions",
                         "?op=subscribe", "");
     $this->registerNotification(EVENT_POST_POST_ADD);
+    $this->registerNotification(EVENT_POST_POST_UPDATE);
+    $this->registerNotification(EVENT_PRE_POST_UPDATE);
   }
         
   function init(){
@@ -54,7 +57,7 @@
     $this->registerBlogAction("subscribeRemove",
                               "PluginSubscribeRemoveAction");
         // we care about when posts and comments are posted
-    $this->registerNotification(EVENT_POST_POST_ADD);
+        // TODO: this doesn't need to be on the front end?? $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.
@@ -110,6 +113,9 @@
        */        
   function process($eventType, $params){        
     $this->register();
+    if(!$this->isEnabled())
+      return true;
+    
     lt_include( PLOG_CLASS_PATH."class/logger/loggermanager.class.php" );
     $logger =& LoggerManager::getLogger( "debug" );
 
@@ -120,10 +126,58 @@
     $locale = $this->blogInfo->getLocale();
 
     switch($eventType){
+          // save old state of the article
+     case EVENT_PRE_POST_UPDATE:
+      $newArticle = $params["article"];
+      if(!$newArticle)
+        return;
+
+      $articles =new Articles();
+      $oldArticle = $articles->getBlogArticle($newArticle->getId(), $newArticle->getBlogId());
+      if(!$oldArticle){
+        $logger->debug("Couldn't get old article??   (".$newArticle->getId().", ".$newArticle->getBlogId().")");
+      }
+      else{ 
+            // save status of article before the current change
+        $this->_oldArticleStatus = $oldArticle->getStatus();
+        $logger->debug("old state: ".$this->_oldArticleStatus);
+      }
+      
+      break;
+
+     case EVENT_POST_POST_UPDATE:
+      $article = $params["article"];
+          // don't send emails for non-published articles
+      if(!$article || $article->getStatus() != POST_STATUS_PUBLISHED)
+        return;
+
+          // if we had an invalid status or we were already published, don't send another email
+      if(!$this->_oldArticleStatus || $this->_oldArticleStatus == POST_STATUS_PUBLISHED)
+        return;
+
+          // don't send notifications for future posts
+      $now = new Timestamp();
+      if($article->getDateObject() > $now)
+        return;
+
+      $rg = RequestGenerator::getRequestGenerator($this->blogInfo);
+      $subscribers = Subscriptions::getSubscriptions($article->getCategoryIds(),
+                                             SUBSCRIBE_POSTS_IN_CATEGORY);
+      $subject = $locale->pr("subscribe_article_published", $article->getTopic());
+      $message = Textfilter::htmlDecode(Textfilter::filterAllHTML($article->getIntroText())) .
+        "\n\n".$locale->pr("subscribe_continue_reading", $rg->postPermalink($article)).
+        "\n\n".$locale->pr("subscribe_email_removal",
+                           Subscriptions::generateConfirmUrl(
+                             $this->blogInfo,
+                             "subscribeRemove",
+                             $email));
+      
+      foreach($subscribers as $email)
+        Subscriptions::sendMessage($email, $subject, $message);
+
+      break;
+      
      case EVENT_POST_POST_ADD:
-      if(!$this->isEnabled())
-        return true;
-               
       $article = $params["article"];
       if(!$article || $article->getStatus() != POST_STATUS_PUBLISHED)
         return;
@@ -134,36 +188,25 @@
         return;
                 
       $rg = RequestGenerator::getRequestGenerator($this->blogInfo);
-      $arr = Subscriptions::getSubscriptions($article->getCategoryIds(),
+      $subscribers = 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)));
-      }
+      $subject = $locale->pr("subscribe_article_published", $article->getTopic());
+      $message = Textfilter::htmlDecode(Textfilter::filterAllHTML($article->getIntroText())) .
+        "\n\n".$locale->pr("subscribe_continue_reading", $rg->postPermalink($article)).
+        "\n\n".$locale->pr("subscribe_email_removal",
+                           Subscriptions::generateConfirmUrl(
+                             $this->blogInfo,
+                             "subscribeRemove",
+                             $email));
+      
+      foreach($subscribers as $email)
+        Subscriptions::sendMessage($email, $subject, $message);
       break;
-
+      
      case EVENT_POST_COMMENT_ADD:
-      if(!$this->isEnabled())
-        return;
-               
-      lt_include(PLOG_CLASS_PATH.
-                 "class/dao/usercomment.class.php");
-      lt_include(PLOG_CLASS_PATH.
-                 "class/net/requestgenerator.class.php");
+      lt_include(PLOG_CLASS_PATH."class/dao/usercomment.class.php");
+      lt_include(PLOG_CLASS_PATH."class/net/requestgenerator.class.php");
       $comment = $params["comment"];
       if($comment->getStatus() != COMMENT_STATUS_NONSPAM)
         return;
@@ -170,30 +213,20 @@
       $article = $comment->getArticle();
 
       $rg = RequestGenerator::getRequestGenerator($this->blogInfo);
-      $arr = Subscriptions::getSubscriptions(
-        array($comment->getArticleId()),
-        SUBSCRIBE_COMMENTS_IN_POST);
+      $subscribers = Subscriptions::getSubscriptions(array($comment->getArticleId()), SUBSCRIBE_COMMENTS_IN_POST);
+      $subject = $locale->pr("subscribe_comment_on", $article->getTopic());
+      $message = $locale->pr("subscribe_posted_by", $comment->getUserName())."\n".
+        Textfilter::htmlDecode(Textfilter::filterAllHTML($comment->getText())) .
+        $locale->pr("subscribe_continue_reading", $rg->postPermalink($article)).
+        "\n\n".$locale->pr("subscribe_email_removal",
+                           Subscriptions::generateConfirmUrl(
+                             $this->blogInfo, "subscribeRemove", $email));
+      
+      foreach($subscribers as $email)
+        Subscriptions::sendMessage($email, $subject, $message);
 
-      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
@@ -224,8 +257,9 @@
               // TODO: can we do anything if there was an error?
         }
       }
-                
+          ///////////////////////////////////////////////
       break;
+      
      default:
       return;
     }



More information about the pLog-svn mailing list