[pLog-svn] r1457 - in plugins/trunk: . hiddeninput
hiddeninput/class hiddeninput/class/action
hiddeninput/class/security hiddeninput/class/view
hiddeninput/locale hiddeninput/templates
mark at devel.plogworld.net
mark at devel.plogworld.net
Sun Mar 13 07:54:38 GMT 2005
Author: mark
Date: 2005-03-13 07:54:37 +0000 (Sun, 13 Mar 2005)
New Revision: 1457
Added:
plugins/trunk/hiddeninput/
plugins/trunk/hiddeninput/class/
plugins/trunk/hiddeninput/class/action/
plugins/trunk/hiddeninput/class/action/pluginhiddeninputconfigaction.class.php
plugins/trunk/hiddeninput/class/action/pluginhiddeninputupdateconfigaction.class.php
plugins/trunk/hiddeninput/class/security/
plugins/trunk/hiddeninput/class/security/hiddeninputfilter.class.php
plugins/trunk/hiddeninput/class/view/
plugins/trunk/hiddeninput/class/view/pluginhiddeninputconfigview.class.php
plugins/trunk/hiddeninput/locale/
plugins/trunk/hiddeninput/locale/locale_en_UK.php
plugins/trunk/hiddeninput/locale/locale_zh_TW.php
plugins/trunk/hiddeninput/pluginhiddeninput.class.php
plugins/trunk/hiddeninput/readme.txt
plugins/trunk/hiddeninput/templates/
plugins/trunk/hiddeninput/templates/hiddeninput.template
Log:
Added: plugins/trunk/hiddeninput/class/action/pluginhiddeninputconfigaction.class.php
===================================================================
--- plugins/trunk/hiddeninput/class/action/pluginhiddeninputconfigaction.class.php 2005-03-13 03:05:14 UTC (rev 1456)
+++ plugins/trunk/hiddeninput/class/action/pluginhiddeninputconfigaction.class.php 2005-03-13 07:54:37 UTC (rev 1457)
@@ -0,0 +1,26 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/hiddeninput/class/view/pluginhiddeninputconfigview.class.php" );
+
+ /**
+ * shows a form with the current configuration
+ */
+ class PluginHiddenInputConfigAction extends AdminAction
+ {
+
+ function PluginHiddenInputConfigAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+ }
+
+ function perform()
+ {
+ $this->_view = new PluginHiddenInputConfigView( $this->_blogInfo );
+
+ $this->setCommonData();
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/hiddeninput/class/action/pluginhiddeninputupdateconfigaction.class.php
===================================================================
--- plugins/trunk/hiddeninput/class/action/pluginhiddeninputupdateconfigaction.class.php 2005-03-13 03:05:14 UTC (rev 1456)
+++ plugins/trunk/hiddeninput/class/action/pluginhiddeninputupdateconfigaction.class.php 2005-03-13 07:54:37 UTC (rev 1457)
@@ -0,0 +1,69 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/hiddeninput/class/view/pluginhiddeninputconfigview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+
+ /**
+ * updates the plugin configuration
+ */
+ class PluginHiddenInputUpdateConfigAction extends AdminAction
+ {
+ var $_pluginEnabled;
+ var $_hiddenFields;
+
+ function PluginHiddenInputUpdateConfigAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+ }
+
+ function validate()
+ {
+ $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+ $this->_pluginEnabled = ($this->_pluginEnabled != "" );
+ $this->_hiddenFields = $this->_request->getValue( "hiddenFields" );
+ $val = new StringValidator();
+ if( !$val->validate($this->_hiddenFields) ) {
+ $this->_view = new PluginHiddenInputConfigView( $this->_blogInfo );
+ $this->_view->setErrorMessage( $this->_locale->tr("hiddeninput_error_hiddenfields"));
+ $this->setCommonData();
+
+ return false;
+ }
+ return true;
+ }
+
+ function perform()
+ {
+ // update the plugin configurations to blog setting
+ $blogSettings = $this->_blogInfo->getSettings();
+ $blogSettings->setValue( "plugin_hiddeninput_enabled", $this->_pluginEnabled );
+ $blogSettings->setValue( "plugin_hiddeninput_hiddenfields", $this->_hiddenFields );
+ $this->_blogInfo->setSettings( $blogSettings );
+
+ // save the blogs settings
+ $blogs = new Blogs();
+ if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
+ $this->_view = new PluginHiddenInputConfigView( $this->_blogInfo );
+ $this->_view->setErrorMessage( $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 PluginHiddenInputConfigView( $this->_blogInfo );
+ $this->_view->setSuccessMessage( $this->_locale->tr("hiddeninput_settings_saved_ok"));
+ $this->setCommonData();
+
+ // clear the cache
+ CacheControl::resetBlogCache( $this->_blogInfo->getId());
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/hiddeninput/class/security/hiddeninputfilter.class.php
===================================================================
--- plugins/trunk/hiddeninput/class/security/hiddeninputfilter.class.php 2005-03-13 03:05:14 UTC (rev 1456)
+++ plugins/trunk/hiddeninput/class/security/hiddeninputfilter.class.php 2005-03-13 07:54:37 UTC (rev 1457)
@@ -0,0 +1,67 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/security/pipelinefilter.class.php" );
+
+ // custom error code that will be returned to the pipeline whenever an
+ // error is found... Be careful so as to not to have two different modules
+ // use the same code!!
+
+ /**
+ * Filters the text posted in a comment by a user, to prevent spam-bots. 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.
+ */
+ define( "HIDDEN_INPUT_MATCH_FOUND", 700 );
+
+ class HiddenInputFilter extends PipelineFilter
+ {
+
+ function HiddenInputFilter( $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();
+ $locale = $blogInfo->getLocale();
+ $pluginEnabled = $blogSettings->getValue( "plugin_hiddeninput_enabled" );
+ if( !$pluginEnabled) {
+ // if not, nothing to do here...
+ //_debug("ip address filter not enabled! quitting...<br/>");
+ 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" ) {
+ $result = new PipelineResult();
+ return $result;
+ }
+
+ $hiddenFields = $blogSettings->getValue( "plugin_hiddeninput_hiddenfields" );
+ $hiddenFieldsList = explode(",", $hiddenFields);
+
+ foreach( $hiddenFieldsList as $hiddenField ) {
+ $commentHiddenField = $request->getValue( trim($hiddenField) );
+ if( empty($commentHiddenField) ) {
+ // if there is a match, we can quit and reject this request
+ $result = new PipelineResult( false, HIDDEN_INPUT_MATCH_FOUND, $locale->tr("error_hiddeninput_field_missing"));
+ return $result;
+ }
+ }
+
+ // if everything went fine, we can say so by returning
+ // a positive PipelineResult object
+ $result = new PipelineResult( true );
+
+ return $result;
+ }
+ }
+?>
Added: plugins/trunk/hiddeninput/class/view/pluginhiddeninputconfigview.class.php
===================================================================
--- plugins/trunk/hiddeninput/class/view/pluginhiddeninputconfigview.class.php 2005-03-13 03:05:14 UTC (rev 1456)
+++ plugins/trunk/hiddeninput/class/view/pluginhiddeninputconfigview.class.php 2005-03-13 07:54:37 UTC (rev 1457)
@@ -0,0 +1,30 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+ /**
+ * implements the main view of the feed reader plugin
+ */
+ class PluginHiddenInputConfigView extends AdminPluginTemplatedView
+ {
+
+ function PluginHiddenInputConfigView( $blogInfo )
+ {
+ $this->AdminPluginTemplatedView( $blogInfo, "hiddeninput", "hiddeninput" );
+ }
+
+ function render()
+ {
+ $blogSettings = $this->_blogInfo->getSettings();
+ $pluginEnabled = $blogSettings->getValue( "plugin_hiddeninput_enabled" );
+ $hiddenFields = $blogSettings->getValue( "plugin_hiddeninput_hiddenfields" );
+ if ($hiddenFields == "") $hiddenFields = "GetOutSpammer,GoHellSpammer";
+
+ // create a view and export the settings to the template
+ $this->setValue( "pluginEnabled", $pluginEnabled );
+ $this->setValue( "hiddenFields", $hiddenFields );
+
+ parent::render();
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/hiddeninput/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/hiddeninput/locale/locale_en_UK.php 2005-03-13 03:05:14 UTC (rev 1456)
+++ plugins/trunk/hiddeninput/locale/locale_en_UK.php 2005-03-13 07:54:37 UTC (rev 1457)
@@ -0,0 +1,16 @@
+<?php
+$messages["manageAntiSpamPlugins"] = "Anti Spam Management";
+$messages["ArticleReferers"] = "Hidden Input";
+
+$messages["hiddeninput_hiddenfields"] = 'Hidden fields for comment form, use "," to seperate different field name';
+$messages["hiddeninput_plugin_enabled"] = "Enable this plugin";
+$messages["hiddeninput_plugin"] = "Hidden Input Plugin";
+
+$messages["hiddeninput_settings_saved_ok"] = "Hidden Input settings saved successfully!";
+$messages["hiddeninput_error_hiddenfields"] = "Fields name can not be empty, at least one field!";
+$messages["error_hiddeninput_field_missing"] = "You can not leave comment here, becasue lack of hidden fields.";
+
+$messages["label_configuration"] = "Configuration";
+$messages["label_enable"] = "Enable";
+$messages["label_hiddenfields"] = "Hidden Fields";
+?>
\ No newline at end of file
Added: plugins/trunk/hiddeninput/locale/locale_zh_TW.php
===================================================================
--- plugins/trunk/hiddeninput/locale/locale_zh_TW.php 2005-03-13 03:05:14 UTC (rev 1456)
+++ plugins/trunk/hiddeninput/locale/locale_zh_TW.php 2005-03-13 07:54:37 UTC (rev 1457)
@@ -0,0 +1,16 @@
+<?php
+$messages["manageAntiSpamPlugins"] = "防制垃圾干擾管理";
+$messages["HiddenInput"] = "迴響隱藏欄位設定";
+
+$messages["hiddeninput_hiddenfields"] = '表單中迴響隱藏欄位的名稱。可以插入多個隱藏欄位到迴響的表單中,請用 "," 隔開。';
+$messages["hiddeninput_plugin_enabled"] = "啟動外掛程式";
+$messages["hiddeninput_plugin"] = "迴響隱藏欄位外掛程式";
+
+$messages["hiddeninput_settings_saved_ok"] = "迴響隱藏欄位設定儲存成功。";
+$messages["hiddeninput_error_hiddenfields"] = "迴響隱藏欄位不可為空白,至少要有一個欄位!";
+$messages["error_hiddeninput_field_missing"] = "您無法在本網誌迴響!因為隱藏欄位輸入錯誤。";
+
+$messages["label_configuration"] = "設定";
+$messages["label_enable"] = "啟動";
+$messages["label_hiddenfields"] = "迴響隱藏欄位";
+?>
\ No newline at end of file
Added: plugins/trunk/hiddeninput/pluginhiddeninput.class.php
===================================================================
--- plugins/trunk/hiddeninput/pluginhiddeninput.class.php 2005-03-13 03:05:14 UTC (rev 1456)
+++ plugins/trunk/hiddeninput/pluginhiddeninput.class.php 2005-03-13 07:54:37 UTC (rev 1457)
@@ -0,0 +1,68 @@
+<?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."plugins/hiddeninput/class/security/hiddeninputfilter.class.php" );
+
+ /**
+ * Plugin that offers hidden fields to comment form to prevent spammer post from spam robot
+ */
+ class PluginHiddenInput extends PluginBase
+ {
+ var $prefix;
+ var $pluginEnabled;
+ var $hiddenFields;
+
+ function PluginHiddenInput()
+ {
+ $this->PluginBase();
+
+ $this->id = "hiddeninput";
+ $this->author = "Mark Wu";
+ $this->desc = "This plugin offers hidden fields to comment form to prevent spammer post from spam robot.";
+
+ $this->prefix = Db::getPrefix();
+
+ $this->locales = Array( "en_UK" , "zh_TW" );
+
+ $this->init();
+ }
+
+ function init()
+ {
+ // register the filter
+ $this->registerFilter( "HiddenInputFilter" );
+
+ $this->registerAdminAction( "hiddeninput", "PluginHiddenInputConfigAction" );
+ $this->registerAdminAction( "updateHiddenInputConfig", "PluginHiddenInputUpdateConfigAction" );
+
+ $menu =& Menu::getMenu();
+ if( !$menu->entryExists( "/menu/controlCenter/manageAntiSpamPlugins" ))
+ $this->addMenuEntry( "/menu/controlCenter", "manageAntiSpamPlugins", "", "", true, false );
+ $this->addMenuEntry( "/menu/controlCenter/manageAntiSpamPlugins", "HiddenInput", "?op=hiddeninput", "" );
+ }
+
+ function register()
+ {
+ $blogSettings = $this->blogInfo->getSettings();
+ $this->pluginEnabled = $blogSettings->getValue( "plugin_hiddeninput_enabled" );
+ $this->hiddenFields = $blogSettings->getValue( "plugin_hiddeninput_hiddenfields" );
+ }
+
+ function isEnabled()
+ {
+ return $this->pluginEnabled;
+ }
+
+ function getHiddenFields()
+ {
+ $hiddenFieldsList = explode(",", $this->hiddenFields);
+
+ $commentHiddenFields = Array();
+ foreach( $hiddenFieldsList as $hiddenField ) {
+ array_push($commentHiddenFields, trim($hiddenField));
+ }
+ return $commentHiddenFields;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/hiddeninput/readme.txt
===================================================================
--- plugins/trunk/hiddeninput/readme.txt 2005-03-13 03:05:14 UTC (rev 1456)
+++ plugins/trunk/hiddeninput/readme.txt 2005-03-13 07:54:37 UTC (rev 1457)
@@ -0,0 +1,20 @@
+Plugin: Hidden Input
+Author: Mark Wu
+Release Date: 2005/03/13
+Version: 1.0
+
+This plugin offers you add hidden fields to your comment form to prevent spam robot. Usage as followed:
+
+You can use:
+1. $hiddeninput->isEnabled() to check the plugin is enabled or not.
+2. $hiddeninput->getHiddenFields() to get the hidden fields.
+
+Example:
+Add the following code to commentform.template inside <form> ... </form>:
+{if !empty($hiddeninput)}
+{if $hiddeninput->isEnabled()}
+{foreach from=$hiddeninput->getHiddenFields() item=hiddenField}
+<input type="hidden" name="{$hiddenField}" value="GetOut!" />
+{/foreach}
+{/if}
+{/if}
\ No newline at end of file
Added: plugins/trunk/hiddeninput/templates/hiddeninput.template
===================================================================
--- plugins/trunk/hiddeninput/templates/hiddeninput.template 2005-03-13 03:05:14 UTC (rev 1456)
+++ plugins/trunk/hiddeninput/templates/hiddeninput.template 2005-03-13 07:54:37 UTC (rev 1457)
@@ -0,0 +1,32 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=HiddenInput title=$locale->tr("hiddeninput_plugin")}
+<form name="hiddeninputPluginConfig" 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("hiddeninput_plugin_enabled")}
+ </div>
+ </div>
+
+ <div class="field">
+ <label for="hiddenFields">{$locale->tr("label_hiddenfields")}</label>
+ <span class="required">*</span>
+ <div class="formHelp">{$locale->tr("hiddeninput_hiddenfields")}</div>
+ <input class="text" type="text" name="hiddenFields" id="hiddenFields" value="{$hiddenFields}" width="10" />
+ </div>
+
+ </fieldset>
+
+ <div class="buttons">
+ <input type="hidden" name="op" value="updateHiddenInputConfig" />
+ <input type="reset" name="{$locale->tr("reset")}" />
+ <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
+ </div>
+</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