[pLog-svn] r1172 - in plugins/trunk: . validatetrackback
validatetrackback/class validatetrackback/class/action
validatetrackback/class/view validatetrackback/locale
validatetrackback/templates
mark at devel.plogworld.net
mark at devel.plogworld.net
Wed Feb 23 15:08:14 GMT 2005
Author: mark
Date: 2005-02-23 15:08:14 +0000 (Wed, 23 Feb 2005)
New Revision: 1172
Added:
plugins/trunk/validatetrackback/
plugins/trunk/validatetrackback/class/
plugins/trunk/validatetrackback/class/action/
plugins/trunk/validatetrackback/class/action/adminvalidatetrackbackpluginsettingsaction.class.php
plugins/trunk/validatetrackback/class/action/adminvalidatetrackbackpluginupdatesettingsaction.class.php
plugins/trunk/validatetrackback/class/view/
plugins/trunk/validatetrackback/class/view/adminvalidatetrackbackpluginsettingsview.class.php
plugins/trunk/validatetrackback/locale/
plugins/trunk/validatetrackback/locale/locale_en_UK.php
plugins/trunk/validatetrackback/locale/locale_zh_TW.php
plugins/trunk/validatetrackback/pluginvalidatetrackback.class.php
plugins/trunk/validatetrackback/templates/
plugins/trunk/validatetrackback/templates/pluginsettings.template
Log:
Update the validatetrackback UI to follow the plog 1.0 UI guideline.
Added: plugins/trunk/validatetrackback/class/action/adminvalidatetrackbackpluginsettingsaction.class.php
===================================================================
--- plugins/trunk/validatetrackback/class/action/adminvalidatetrackbackpluginsettingsaction.class.php 2005-02-23 13:47:41 UTC (rev 1171)
+++ plugins/trunk/validatetrackback/class/action/adminvalidatetrackbackpluginsettingsaction.class.php 2005-02-23 15:08:14 UTC (rev 1172)
@@ -0,0 +1,31 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/validatetrackback/class/view/adminvalidatetrackbackpluginsettingsview.class.php" );
+
+ class AdminValidateTrackbackPluginSettingsAction extends BlogOwnerAdminAction
+ {
+
+ /**
+ * Constructor. If nothing else, it also has to call the constructor of the parent
+ * class, BlogAction with the same parameters
+ */
+ function AdminValidateTrackbackPluginSettingsAction( $actionInfo, $request )
+ {
+ $this->BlogOwnerAdminAction( $actionInfo, $request );
+ }
+
+ /**
+ * Carries out the specified action
+ */
+ function perform()
+ {
+ $this->_view = new AdminValidateTrackbackPluginSettingsView( $this->_blogInfo );
+
+ $this->setCommonData();
+
+ // better to return true if everything fine
+ return true;
+ }
+ }
+?>
Added: plugins/trunk/validatetrackback/class/action/adminvalidatetrackbackpluginupdatesettingsaction.class.php
===================================================================
--- plugins/trunk/validatetrackback/class/action/adminvalidatetrackbackpluginupdatesettingsaction.class.php 2005-02-23 13:47:41 UTC (rev 1171)
+++ plugins/trunk/validatetrackback/class/action/adminvalidatetrackbackpluginupdatesettingsaction.class.php 2005-02-23 15:08:14 UTC (rev 1172)
@@ -0,0 +1,63 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/validatetrackback/class/view/adminvalidatetrackbackpluginsettingsview.class.php" );
+
+ class AdminValidateTrackbackPluginUpdateSettingsAction extends BlogOwnerAdminAction
+ {
+
+ var $_pluginEnabled;
+
+ /**
+ * Constructor. If nothing else, it also has to call the constructor of the parent
+ * class, BlogAction with the same parameters
+ */
+ function AdminValidateTrackbackPluginUpdateSettingsAction( $actionInfo, $request )
+ {
+ $this->BlogOwnerAdminAction( $actionInfo, $request );
+ }
+
+ function validate()
+ {
+ $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+ $this->_pluginEnabled = ($this->_pluginEnabled != "" );
+
+ return true;
+ }
+
+ /**
+ * Carries out the specified action
+ */
+ function perform()
+ {
+ // update the plugin configurations to blog setting
+ $blogSettings = $this->_blogInfo->getSettings();
+ $blogSettings->setValue( "plugin_validatetrackback_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 AdminValidateTrackbackPluginSettingsView( $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 AdminValidateTrackbackPluginSettingsView( $this->_blogInfo );
+ $this->_view->setSuccessMessage( $this->_locale->tr("validatetrackback_settings_saved_ok"));
+ $this->setCommonData();
+
+ // clear the cache
+ CacheControl::resetBlogCache( $this->_blogInfo->getId());
+
+ return true;
+ }
+ }
+?>
Added: plugins/trunk/validatetrackback/class/view/adminvalidatetrackbackpluginsettingsview.class.php
===================================================================
--- plugins/trunk/validatetrackback/class/view/adminvalidatetrackbackpluginsettingsview.class.php 2005-02-23 13:47:41 UTC (rev 1171)
+++ plugins/trunk/validatetrackback/class/view/adminvalidatetrackbackpluginsettingsview.class.php 2005-02-23 15:08:14 UTC (rev 1172)
@@ -0,0 +1,28 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+ /**
+ * implements the main view of the feed reader plugin
+ */
+ class AdminValidateTrackbackPluginSettingsView extends AdminPluginTemplatedView
+ {
+
+ function AdminValidateTrackbackPluginSettingsView( $blogInfo )
+ {
+ $this->AdminPluginTemplatedView( $blogInfo, "validatetrackback", "pluginsettings" );
+ }
+
+ function render()
+ {
+ // load some configuration settings
+ $blogSettings = $this->_blogInfo->getSettings();
+ $pluginEnabled = $blogSettings->getValue( "plugin_validatetrackback_enabled" );
+
+ // create a view and export the settings to the template
+ $this->setValue( "pluginEnabled", $pluginEnabled );
+
+ parent::render();
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/validatetrackback/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/validatetrackback/locale/locale_en_UK.php 2005-02-23 13:47:41 UTC (rev 1171)
+++ plugins/trunk/validatetrackback/locale/locale_en_UK.php 2005-02-23 15:08:14 UTC (rev 1172)
@@ -0,0 +1,5 @@
+<?php
+
+$messages["validatetrackbackPluginSettings"] = "Validate Trackbacks";
+
+?>
\ No newline at end of file
Added: plugins/trunk/validatetrackback/locale/locale_zh_TW.php
===================================================================
--- plugins/trunk/validatetrackback/locale/locale_zh_TW.php 2005-02-23 13:47:41 UTC (rev 1171)
+++ plugins/trunk/validatetrackback/locale/locale_zh_TW.php 2005-02-23 15:08:14 UTC (rev 1172)
@@ -0,0 +1,5 @@
+<?php
+
+$messages["validatetrackbackPluginSettings"] = "引用網址驗證設定";
+
+?>
\ No newline at end of file
Added: plugins/trunk/validatetrackback/pluginvalidatetrackback.class.php
===================================================================
--- plugins/trunk/validatetrackback/pluginvalidatetrackback.class.php 2005-02-23 13:47:41 UTC (rev 1171)
+++ plugins/trunk/validatetrackback/pluginvalidatetrackback.class.php 2005-02-23 15:08:14 UTC (rev 1172)
@@ -0,0 +1,126 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/trackbackclient.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/http/httpclient.class.php" );
+
+ /**
+ * implements moderation of comments
+ */
+ class PluginValidateTrackback extends PluginBase
+ {
+ var $pluginEnabled;
+
+ function PluginValidateTrackback()
+ {
+ $this->PluginBase();
+
+ $this->id = "validatetrackback";
+ $this->desc = "Provides validation of trackbacks.";
+ $this->author = "Paul Westbrook";
+ $this->locales = Array( "en_UK", "zh_TW" );
+
+ $this->init();
+ }
+
+ /**
+ * registers all the filters and actions that we're going to use
+ */
+ function init()
+ {
+ // register the events we want
+ $this->registerNotification( EVENT_POST_TRACKBACK_ADD );
+
+ // register an action that will allow users to see which comments have not been
+ // accepted yet
+ $this->registerAdminAction( "validatetrackbackPluginSettings", "AdminValidateTrackbackPluginSettingsAction" );
+ $this->registerAdminAction( "validatetrackbackPluginUpdateSettings", "AdminValidateTrackbackPluginUpdateSettingsAction" );
+
+ // add a menu entry
+ $menu =& Menu::getMenu();
+ if( !$menu->entryExists( "/menu/controlCenter/manageAntiSpamPlugins" ))
+ $this->addMenuEntry( "/menu/controlCenter", "manageAntiSpamPlugins", "", "", true, false );
+ $this->addMenuEntry( "/menu/controlCenter/manageAntiSpamPlugins", "validatetrackbackPluginSettings", "admin.php?op=validatetrackbackPluginSettings", "", true, false );
+ }
+
+ function register()
+ {
+ $blogSettings = $this->blogInfo->getSettings();
+ $this->pluginEnabled = $blogSettings->getValue( "plugin_validatetrackback_enabled" );
+ }
+
+ function isEnabled()
+ {
+ return $this->pluginEnabled;
+ }
+
+ /**
+ * process the events that we have registered
+ *
+ * @see PluginBase::process
+ * @see PluginManager
+ */
+ function process( $eventType, $params )
+ {
+ // make sure we're processing the right event!
+ if( $eventType != EVENT_POST_TRACKBACK_ADD )
+ return true;
+
+ // do nothing if the plugin is not enabled!
+ $blogSettings = $this->blogInfo->getSettings();
+ if( !$blogSettings->getValue( "plugin_validatetrackback_enabled" ))
+ return true;
+
+ // change the stauts of the comment, as is easy as it seems...
+ $trackback = $params["trackback"];
+ $this->Validate( $trackback );
+
+ return true;
+ }
+
+ /**
+ * Fetches a page from the given url.
+ *
+ * @param url The url with the page we would like to fetch.
+ * @return Returns a string with the contents of the page or an empty string if the page
+ * could not be fetched.
+ */
+ function fetchPage( $url )
+ {
+ $s = new HttpClient();
+ $result = $s->fetch( $url );
+
+ if( !$result ) {
+ if($s->timed_out)
+ //print("timed out!!!");
+ return "";
+
+ }
+ else
+ return $s->results;
+ }
+
+ function Validate( $trackback )
+ {
+ // Get the page
+ $page = $this->fetchPage( $trackback->_url );
+
+ // Get the trackback client
+ $tbClient = new TrackbackClient();
+
+ // get the trackback url
+ $tbLinks = $tbClient->getTrackbackLinks( $page, $link );
+ if( empty( $tbLinks)) {
+ // there were no trackback links in the page
+ // error_log( "Found no trackback urls" );
+
+ // Delete this trackback
+ $trackbacks = new Trackbacks();
+
+ $trackbacks->deletePostTrackback( $trackback->_id, $trackback->_articleId );
+ //print("Error: trackback unavailable<br/>");
+ }
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/validatetrackback/templates/pluginsettings.template
===================================================================
--- plugins/trunk/validatetrackback/templates/pluginsettings.template 2005-02-23 13:47:41 UTC (rev 1171)
+++ plugins/trunk/validatetrackback/templates/pluginsettings.template 2005-02-23 15:08:14 UTC (rev 1172)
@@ -0,0 +1,24 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=validatetrackbackPluginSettings title=$locale->tr("validatetrackbackPluginSettings")}
+<form name="validatetrackbackPluginSettings" 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>
+ <div class="formHelp">
+ <input class="checkbox" type="checkbox" name="pluginEnabled" id="pluginEnabled" {if $pluginEnabled} checked="checked" {/if} value="1" />{$locale->tr("validatetrackback_plugin_enabled")}
+ </div>
+ </div>
+
+ </fieldset>
+
+ <div class="buttons">
+ <input type="hidden" name="op" value="validatetrackbackPluginUpdateSettings" />
+ <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