[pLog-svn] r774 - in plugins/trunk: . class class/action locale templates

mark at devel.plogworld.net mark at devel.plogworld.net
Thu Jan 20 15:57:23 GMT 2005


Author: mark
Date: 2005-01-20 15:57:22 +0000 (Thu, 20 Jan 2005)
New Revision: 774

Added:
   plugins/trunk/class/
   plugins/trunk/class/action/
   plugins/trunk/class/action/pluginnofollowconfigaction.class.php
   plugins/trunk/class/action/pluginnofollowupdateconfigaction.class.php
   plugins/trunk/locale/
   plugins/trunk/locale/locale_en_UK.php
   plugins/trunk/locale/locale_zh_TW.php
   plugins/trunk/pluginnofollow.class.php
   plugins/trunk/templates/
   plugins/trunk/templates/nofollow.template
Log:
Recent Comments for pLog 1.0, the plugin should be compatiable with 0.32.

Added: plugins/trunk/class/action/pluginnofollowconfigaction.class.php
===================================================================
--- plugins/trunk/class/action/pluginnofollowconfigaction.class.php	2005-01-20 13:52:05 UTC (rev 773)
+++ plugins/trunk/class/action/pluginnofollowconfigaction.class.php	2005-01-20 15:57:22 UTC (rev 774)
@@ -0,0 +1,32 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );	
+
+	/**
+	 * shows a form with the current configuration
+	 */
+	class PluginNoFollowConfigAction extends AdminAction
+	{
+		
+		function PluginNoFollowConfigAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+		}
+		
+		function perform()
+		{
+			// load some configuration settings
+			$blogSettings = $this->_blogInfo->getSettings();
+			$pluginEnabled = $blogSettings->getValue( "plugin_nofollow_enabled" );
+			
+			// create a view and export the settings to the template
+			$this->_view = new AdminPluginTemplatedView( $this->_blogInfo, "nofollow", "nofollow", true );
+			$this->_view->setValue( "pluginEnabled", $pluginEnabled );
+			
+			$this->setCommonData();
+			
+			return true;
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/class/action/pluginnofollowupdateconfigaction.class.php
===================================================================
--- plugins/trunk/class/action/pluginnofollowupdateconfigaction.class.php	2005-01-20 13:52:05 UTC (rev 773)
+++ plugins/trunk/class/action/pluginnofollowupdateconfigaction.class.php	2005-01-20 15:57:22 UTC (rev 774)
@@ -0,0 +1,56 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+    include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );
+		
+	/**
+	 * updates the plugin configuration
+	 */
+	class PluginNoFollowUpdateConfigAction extends AdminAction
+	{
+		var $_pluginEnabled;
+		
+		function PluginNoFollowUpdateConfigAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+		}
+		
+		function validate()
+		{
+            $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+            $this->_pluginEnabled = ($this->_pluginEnabled != "" );			
+			
+			return true;
+		}
+		        
+		function perform()
+		{
+            // and check which smiley set we should be using, or if none, then the default one
+			$blogSettings = $this->_blogInfo->getSettings();
+            $blogSettings->setValue( "plugin_nofollow_enabled", $this->_pluginEnabled );
+            $this->_blogInfo->setSettings( $blogSettings ); 
+		
+			// save the blogs settings
+			$blogs = new Blogs();
+            if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
+                $this->_view = new AdminErrorView( $this->_blogInfo );
+                $this->_view->setValue( "message", $this->_locale->tr("error_updating_settings"));
+                $this->setCommonData();
+
+                return false;
+            }
+			
+			// if everything went ok...
+            $this->_blogInfo->setSettings( $blogSettings );
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+			
+			$this->_view = new AdminMessageView( $this->_blogInfo );
+			$this->_view->setMessage( $this->_locale->tr("nofollow_settings_saved_ok"));
+			$this->setCommonData();
+            
+            return true;		
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/locale/locale_en_UK.php	2005-01-20 13:52:05 UTC (rev 773)
+++ plugins/trunk/locale/locale_en_UK.php	2005-01-20 15:57:22 UTC (rev 774)
@@ -0,0 +1,6 @@
+<?php
+$messages["nofollow_plugin_configuration"] = "Configuration this plugin";
+$messages["nofollow_plugin_enabled"] = "Enable this plugin";
+$messages["nofollow_plugin"] = "No Follow Plugin";
+$messages["nofollow_settings_saved_ok"] = "No Follow settings saved successfully!";
+?>
\ No newline at end of file

Added: plugins/trunk/locale/locale_zh_TW.php
===================================================================
--- plugins/trunk/locale/locale_zh_TW.php	2005-01-20 13:52:05 UTC (rev 773)
+++ plugins/trunk/locale/locale_zh_TW.php	2005-01-20 15:57:22 UTC (rev 774)
@@ -0,0 +1,6 @@
+<?php
+$messages["nofollow_plugin_configuration"] = "外掛程式設定";
+$messages["nofollow_plugin_enabled"] = "啟動外掛程式";
+$messages["nofollow_plugin"] = "No Follow 外掛程式";
+$messages["nofollow_settings_saved_ok"] = "No Follow 設定儲存成功。";
+?>
\ No newline at end of file

Added: plugins/trunk/pluginnofollow.class.php
===================================================================
--- plugins/trunk/pluginnofollow.class.php	2005-01-20 13:52:05 UTC (rev 773)
+++ plugins/trunk/pluginnofollow.class.php	2005-01-20 15:57:22 UTC (rev 774)
@@ -0,0 +1,88 @@
+<?php
+	include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+	include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+	include_once( PLOG_CLASS_PATH."class/plugin/eventpluginbase.class.php" );
+
+	class PluginNoFollow extends PluginBase
+	{
+		function PluginNoFollow()
+		{
+			$this->PluginBase();
+
+			$this->id      = "nofollow";
+			$this->author  = "Minstrel Chiu";
+			$this->desc    = "Prevents comment spams with 'rel=nofollow'";
+
+			$this->locales = Array( "en_UK" , "zh_TW" );
+
+			$this->init();
+		}
+
+		function init()
+		{
+            $this->registerAdminAction( "nofollow", "PluginNoFollowConfigAction" );
+			$this->registerAdminAction( "updateNoFollowConfig", "PluginNoFollowUpdateConfigAction" );
+			
+			$menu =& Menu::getMenu();
+			if( !$menu->entryExists( "/menu/controlCenter/manageSpamActivities" ))						
+				$this->addMenuEntry( "/menu/controlCenter", "manageSpamActivities", "", "", true, false );			
+            $this->addMenuEntry( "/menu/controlCenter/manageSpamActivities", "NoFollow", "?op=nofollow", "" );            
+
+			$this->registerNotification( EVENT_PRE_COMMENT_ADD );
+		}
+
+		function process($eventType, $params)
+		{
+            if ( $eventType != EVENT_PRE_COMMENT_ADD )
+                return true;
+                
+		    $blogSettings = $this->blogInfo->getSettings();
+		    $pluginEnabled = $blogSettings->getValue( "plugin_nofollow_enabled" );
+            if ( $pluginEnabled != 1 )
+                return true;
+
+			$comment = $params["comment"];
+
+			$text = $comment->getText();
+			$text = $this->nofollow($text);
+
+			$comment->setText($text);
+
+			$params["comment"] = $comment;
+
+			return true;
+		}
+
+		function nofollow($text)
+		{
+			if(!isset($text))
+				return $text;
+
+			return preg_replace_callback('#<a\s([^>]*\s*href\s*=[^>]*)>#i', array(&$this, 'nofollow_process'), $text);
+		}
+
+		function nofollow_process($matches)
+		{
+			$text = $matches[1];
+
+			preg_match_all('/[^=[:space:]]*\s*=\s*"[^"]*"|[^=[:space:]]*\s*=\s*\'[^\']*\'|[^=[:space:]]*\s*=[^[:space:]]*/', $text, $attr);
+			$rel_arr = preg_grep('/^rel\s*=/i', $attr[0]);
+
+			if(count($rel_arr)>0)
+				$rel = array_pop($rel_arr);
+
+			if($rel)
+			{
+				$rel = preg_replace('/^(rel\s*=\s*[\'"]?)/i', '\1nofollow ', $rel);
+			}
+			else
+			{
+				$rel = 'rel="nofollow"';
+			}
+
+			$attr = preg_grep('/^rel\s*=/i', $attr[0], PREG_GREP_INVERT);
+
+			return '<a ' . join(' ', $attr) . ' ' . $rel . '>';
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/templates/nofollow.template
===================================================================
--- plugins/trunk/templates/nofollow.template	2005-01-20 13:52:05 UTC (rev 773)
+++ plugins/trunk/templates/nofollow.template	2005-01-20 15:57:22 UTC (rev 774)
@@ -0,0 +1,11 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=NoFollow title=$locale->tr("nofollow_plugin")}
+<form name="nofollowPluginConfig" method="post">
+ {$locale->tr("nofollow_plugin_enabled")}
+ <input type="checkbox" name="pluginEnabled" {if $pluginEnabled} checked="checked" {/if} value="1" /><br/>
+ <br/>
+ <input type="hidden" name="op" value="updateNoFollowConfig" />
+ <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file




More information about the pLog-svn mailing list