[pLog-svn] r5116 - in plugins/branches/lifetype-1.2: . closecomments closecomments/class closecomments/class/action closecomments/class/security closecomments/class/view closecomments/locale closecomments/templates

oscar at devel.lifetype.net oscar at devel.lifetype.net
Fri Mar 16 18:44:47 EDT 2007


Author: oscar
Date: 2007-03-16 18:44:47 -0400 (Fri, 16 Mar 2007)
New Revision: 5116

Added:
   plugins/branches/lifetype-1.2/closecomments/
   plugins/branches/lifetype-1.2/closecomments/class/
   plugins/branches/lifetype-1.2/closecomments/class/action/
   plugins/branches/lifetype-1.2/closecomments/class/action/adminclosecommentssettingsaction.class.php
   plugins/branches/lifetype-1.2/closecomments/class/action/adminupdateclosecommentssettingsaction.class.php
   plugins/branches/lifetype-1.2/closecomments/class/security/
   plugins/branches/lifetype-1.2/closecomments/class/security/closecomments.class.php
   plugins/branches/lifetype-1.2/closecomments/class/view/
   plugins/branches/lifetype-1.2/closecomments/class/view/adminclosecommentssettingsview.class.php
   plugins/branches/lifetype-1.2/closecomments/locale/
   plugins/branches/lifetype-1.2/closecomments/locale/locale_en_UK.php
   plugins/branches/lifetype-1.2/closecomments/pluginclosecomments.class.php
   plugins/branches/lifetype-1.2/closecomments/templates/
   plugins/branches/lifetype-1.2/closecomments/templates/settings.template
Log:
very simple plugin that allows to automatically close comments after a certain configurable amount of time has happened. The time is configurable only on a per-blog setting, so different posts cannot have their comments closed at different times in the future.


Added: plugins/branches/lifetype-1.2/closecomments/class/action/adminclosecommentssettingsaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/closecomments/class/action/adminclosecommentssettingsaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/closecomments/class/action/adminclosecommentssettingsaction.class.php	2007-03-16 22:44:47 UTC (rev 5116)
@@ -0,0 +1,23 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."plugins/closecomments/class/view/adminclosecommentssettingsview.class.php" );
+
+	class AdminCloseCommentsSettingsAction extends AdminAction
+	{
+		function AdminCloseCommentsSettingsAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+			
+			$this->requirePermission( "manage_plugins" );
+		}
+		
+		function perform()
+		{
+			$this->_view = new AdminCloseCommentsSettingsView( $this->_blogInfo );
+			$this->setCommonData();
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/closecomments/class/action/adminupdateclosecommentssettingsaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/closecomments/class/action/adminupdateclosecommentssettingsaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/closecomments/class/action/adminupdateclosecommentssettingsaction.class.php	2007-03-16 22:44:47 UTC (rev 5116)
@@ -0,0 +1,58 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+	lt_include( PLOG_CLASS_PATH."plugins/closecomments/class/view/adminclosecommentssettingsview.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );	
+
+	class AdminUpdateCloseCommentsSettingsAction extends AdminAction
+	{
+		function AdminUpdateCloseCommentsSettingsAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+			
+			$this->registerField( "pluginEnabled" );
+			$this->registerFieldValidator( "period", new IntegerValidator(), true );
+			$view = new AdminCloseCommentsSettingsView( $this->_blogInfo );
+			$view->setErrorMessage( $this->_locale->tr("error_updating_closecomments_settings" ));
+			$this->setValidationErrorView( $view );
+			
+			$this->requirePermission( "manage_plugins" );
+		}
+		
+		function perform()
+		{						
+			$pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+			$period = $this->_request->getValue( "period" );
+			
+			$blogSettings = $this->_blogInfo->getSettings();
+            $blogSettings->setValue( "plugin_closecomments_enabled", $pluginEnabled );
+            $blogSettings->setValue( "plugin_closecomments_period", $period );
+            $this->_blogInfo->setSettings( $blogSettings );
+			
+			// save the blogs settings
+			$blogs = new Blogs();
+            if( !$blogs->updateBlog( $this->_blogInfo )) {
+                $this->_view = new AdminCloseCommentsSettingsView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_updating_closecomments_settings"));
+                $this->setCommonData();
+
+                return false;
+            }
+
+			// if everything went ok...
+            $this->_blogInfo->setSettings( $blogSettings );
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+
+			$this->_view = new AdminCloseCommentsSettingsView( $this->_blogInfo );
+			$this->_view->setSuccessMessage( $this->_locale->tr("closecomment_settings_saved_ok"));
+			$this->setCommonData();
+			
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/closecomments/class/security/closecomments.class.php
===================================================================
--- plugins/branches/lifetype-1.2/closecomments/class/security/closecomments.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/closecomments/class/security/closecomments.class.php	2007-03-16 22:44:47 UTC (rev 5116)
@@ -0,0 +1,71 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/security/pipelinefilter.class.php" );
+
+	/**
+	 * This is a filter for the pipe line that performs exactly the same action as
+	 * the code in the PluginCloseComments::process() method. The problem is that when 
+	 * caching is enabled, no events are thrown and the only place where we can catch
+	 * this kind of events is in here, as filters are always executed regardless
+	 * of the template caching settings
+	 */
+	class CloseComments extends PipelineFilter
+	{
+    	function CloseComments( $pipelineRequest )
+        {
+        	$this->PipelineFilter( $pipelineRequest );
+        }
+
+        function filter()
+        {
+        	// get some info
+            $request  = $this->_pipelineRequest->getHttpRequest();
+            $blogInfo = $this->_pipelineRequest->getBlogInfo();
+
+            if( $request->getValue( "op" ) != "AddComment" && $request->getValue( "op" ) != "ViewArticle" ) {
+            	$result = new PipelineResult();
+                return $result;
+            }
+
+			// otherwise let's proceed
+			lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );			
+			$articles = new Articles();
+			if( isset( $_REQUEST["articleId"] )) {
+				$artId = $request->getValue( "articleId" );
+				$article = $articles->getBlogArticle( $artId, $blogInfo->getId());
+			}
+			else {
+				$artName = $request->getValue( "articleName" );
+				$article = $articles->getBlogArticleByTitle( $artName, $blogInfo->getId());
+			}
+			
+			if( !$article ) {
+				// quit if there was no article to load
+            	$result = new PipelineResult();
+                return $result;
+			}
+
+			$postDate = $article->getDateObject();
+			$settings = $blogInfo->getSettings();
+			$period = $settings->getValue( "plugin_closecomments_period", DEFAULT_CLOSECOMMENTS_PERIOD );
+			$postDate->addSeconds( $period * 24 * 3600 );
+			$now = new Timestamp();
+			
+			//print("date+period = ".$postDate->getTimestamp()." - now = ".$now->getTimestamp()."<br/>");
+			
+			if( $postDate->getTimestamp() < $now->getTimestamp()) {
+				//print( "Closing comments!" );
+				lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
+				if( $article->getCommentsEnabled()) {
+					$article->setCommentsEnabled( false );
+					$articles = new Articles();
+					$articles->updateArticle( $article );				
+					CacheControl::resetBlogCache( $blogInfo->getId());
+				}
+			}
+			
+        	$result = new PipelineResult();
+            return $result;			
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/closecomments/class/view/adminclosecommentssettingsview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/closecomments/class/view/adminclosecommentssettingsview.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/closecomments/class/view/adminclosecommentssettingsview.class.php	2007-03-16 22:44:47 UTC (rev 5116)
@@ -0,0 +1,21 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+	class AdminCloseCommentsSettingsView extends AdminPluginTemplatedView
+	{
+		function AdminCloseCommentsSettingsView( $blogInfo )
+		{
+			$this->AdminPluginTemplatedView( $blogInfo, "closecomments", "settings" );
+		}
+		
+		function render()
+		{
+			$blogSettings = $this->_blogInfo->getSettings();
+			$this->setValue( "pluginEnabled", $blogSettings->getValue( "plugin_closecomments_enabled" ));
+			$this->setValue( "period", $blogSettings->getValue( "plugin_closecomments_period" ));
+			
+			return( parent::render());
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/closecomments/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/closecomments/locale/locale_en_UK.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/closecomments/locale/locale_en_UK.php	2007-03-16 22:44:47 UTC (rev 5116)
@@ -0,0 +1,13 @@
+<?php
+$messages['closeComments'] = 'Automatically close comments';
+$messages['plugin_closecomments_enabled'] = 'Automatically close comments after the period selected below';
+$messages['closecomments_1_day'] = '1 day';
+$messages['closecomments_1_week'] = '1 week';
+$messages['closecomments_2_weeks'] = '2 weeks';
+$messages['closecomments_1_month'] = '1 month';
+$messages['enable_plugin'] = 'Enable';
+$messages['closecomments_period'] = 'Period';
+$messages['closecomments_period_help'] = 'How many days after an article is published should comments be allowed? Comments will be closed after this period.';
+$messages['error_updating_closecomments_settings'] = 'There was an error updating the plugin settings';
+$messages['closecomment_settings_saved_ok'] = 'Plugin settings saved successfully';
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/closecomments/pluginclosecomments.class.php
===================================================================
--- plugins/branches/lifetype-1.2/closecomments/pluginclosecomments.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/closecomments/pluginclosecomments.class.php	2007-03-16 22:44:47 UTC (rev 5116)
@@ -0,0 +1,87 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+	lt_include( PLOG_CLASS_PATH."plugins/closecomments/class/security/closecomments.class.php" );
+	
+	//
+	// if no value was defined, let's close comments after 14 days
+	//
+	define( "DEFAULT_CLOSECOMMENTS_PERIOD", 14 );
+	
+	class PluginCloseComments extends PluginBase
+	{
+		function PluginCloseComments( $source )
+		{
+			$this->PluginBase( $source );
+	
+			$this->id = "closecomments";
+			$this->author = "The LifeType Team";
+			$this->version = "20070316";
+			$this->desc = "Allows to automatically close comments for posts that are older than a configurable certain date";
+			
+			// register our admin actions and menu entries			
+			if( $this->getSource() == "admin" ) {
+				$this->registerAdminAction( "closeCommentsSettings", "AdminCloseCommentsSettingsAction" );
+				$this->registerAdminAction( "updateCloseCommentsSettings", "AdminUpdateCloseCommentsSettingsAction" );				
+				$this->addMenuEntry( "/menu/controlCenter/manageSettings", "closeComments", "?op=closeCommentsSettings" );
+							
+				// register the needed event
+				$this->registerNotification( EVENT_POST_LOADED );
+			}
+
+			$this->registerFilter( "CloseComments" );
+		}
+		
+		/**
+		 * process the EVENT_POST_LOADED event and deactivate the comments
+		 * if necessary
+		 */
+		function process( $event, $params )
+		{
+			if( $event != EVENT_POST_LOADED )
+				return( false );
+				
+			$settings = $this->blogInfo->getSettings();
+			if( !$settings->getValue( "plugin_closecomments_enabled", false ))
+				return false;
+			
+			// get the post and check if we should close its comments, based on the current settings
+			$article = $params["article"];
+			$postDate = $article->getDateObject();
+			$period = $settings->getValue( "plugin_closecomments_period", DEFAULT_CLOSECOMMENTS_PERIOD );
+			$postDate->addSeconds( $period * 24 * 3600 );
+			$now = new Timestamp();
+			
+			//print("date+period = ".$postDate->getTimestamp()." - now = ".$now->getTimestamp()."<br/>");
+			
+			if( $postDate->getTimestamp() < $now->getTimestamp()) {
+				//print( "Closing comments!" );
+				lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+				if( $article->getCommentsEnabled()) {
+					$article->setCommentsEnabled( false );
+					$articles = new Articles();
+					$articles->updateArticle( $article );				
+				}
+			}
+			
+			$params["article"] = $article;			
+		}
+		
+		/**
+		 * Report our global configuration keys, in case administrators want to 
+		 * globally enable this plugin
+		 */
+		function getPluginConfigurationKeys()
+		{
+			lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );			
+			
+			return( Array(
+				Array( "name" => "plugin_closecomments_enabled", "type" => "boolean" ),
+				Array( "name" => "plugin_closecomments_period", 
+				       "validator" => new IntegerValidator(), 
+				       "type" => "list",
+				       "options" => Array( "1" => "1 day", "7" => "1 week" , "14" => "2 weeks", "30" => "1 month" ))
+			));			
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/closecomments/templates/settings.template
===================================================================
--- plugins/branches/lifetype-1.2/closecomments/templates/settings.template	                        (rev 0)
+++ plugins/branches/lifetype-1.2/closecomments/templates/settings.template	2007-03-16 22:44:47 UTC (rev 5116)
@@ -0,0 +1,36 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=closeComments title=$locale->tr("closeComments")}
+
+<form name="authimageluginConfig" action="admin.php" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("enable_plugin")}</legend> 
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}
+  <div class="field">
+   <label for="pluginEnabled">{$locale->tr("enable_plugin")}</label>
+   <div class="formHelp">
+     <input class="checkbox" type="checkbox" name="pluginEnabled" id="pluginEnabled" {if $pluginEnabled}checked="checked"{/if} value="1" {user_cannot_override key=plugin_closecomments_enabled}disabled="disabled"{/user_cannot_override} />{$locale->tr("plugin_closecomments_enabled")}
+   </div>
+  </div> 
+
+  <div class="field">
+   <label for="length">{$locale->tr("closecomments_period")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("closecomments_period_help")}</div>
+   <select name="period" {user_cannot_override key=plugin_closecomments_enabled}disabled="disabled"{/user_cannot_override}>
+	<option value="1" {if $period==1}selected="selected"{/if}>{$locale->tr("closecomments_1_day")}</option>
+	<option value="7" {if $period==7}selected="selected"{/if}>{$locale->tr("closecomments_1_week")}</option>
+	<option value="14" {if $period==14}selected="selected"{/if}>{$locale->tr("closecomments_2_weeks")}</option>
+	<option value="30" {if $period==30}selected="selected"{/if}>{$locale->tr("closecomments_1_month")}</option>			
+   </select>
+  </div>
+  
+ </fieldset>
+ <div class="buttons">
+  <input type="hidden" name="op" value="updateCloseCommentsSettings" />
+  <input type="reset" name="{$locale->tr("reset")}" />
+  <input type="submit" name="{$locale->tr("settings")}" value="{$locale->tr("update")}" />
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}



More information about the pLog-svn mailing list