[pLog-svn] r6868 - in plugins/branches/lifetype-1.2: . contact contact/class contact/class/action contact/class/view contact/locale contact/templates

Jon Daley plogworld at jon.limedaley.com
Mon Apr 20 18:43:17 EDT 2009


 	woah.  The bayesian filter alone is definitely not good enough.  I 
launched my site last night, and I've gotten about 10 spams today.  All 
last year (just using hidden input) I got three or something.
 	I'll have to see if there is some cool way of using hiddeninput's 
code, if it is installed.

On Sat, 18 Apr 2009, jondaley at devel.lifetype.net wrote:

> Author: jondaley
> Date: 2009-04-18 17:03:37 -0400 (Sat, 18 Apr 2009)
> New Revision: 6868
>
> Added:
>   plugins/branches/lifetype-1.2/contact/
>   plugins/branches/lifetype-1.2/contact/class/
>   plugins/branches/lifetype-1.2/contact/class/action/
>   plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginsettingsaction.class.php
>   plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginupdatesettingsaction.class.php
>   plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php
>   plugins/branches/lifetype-1.2/contact/class/view/
>   plugins/branches/lifetype-1.2/contact/class/view/admincontactpluginsettingsview.class.php
>   plugins/branches/lifetype-1.2/contact/locale/
>   plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php
>   plugins/branches/lifetype-1.2/contact/plugincontact.class.php
>   plugins/branches/lifetype-1.2/contact/readme.txt
>   plugins/branches/lifetype-1.2/contact/templates/
>   plugins/branches/lifetype-1.2/contact/templates/accepted.template
>   plugins/branches/lifetype-1.2/contact/templates/pluginsettings.template
> Log:
> plugin that allows visitors to contact the blog owner privately via a form, rather than leaving a public comment.  The message will be sent to the blog owner via email
>
> Added: plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginsettingsaction.class.php
> ===================================================================
> --- plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginsettingsaction.class.php	                        (rev 0)
> +++ plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginsettingsaction.class.php	2009-04-18 21:03:37 UTC (rev 6868)
> @@ -0,0 +1,24 @@
> +<?php
> +	lt_include(PLOG_CLASS_PATH."class/action/admin/adminaction.class.php");
> +	lt_include(PLOG_CLASS_PATH."plugins/contact/class/view/admincontactpluginsettingsview.class.php");
> +
> +    class AdminContactPluginSettingsAction extends AdminAction
> +	{
> +    	/**
> +         * Constructor. If nothing else, it also has to call the constructor of the parent
> +         * class, BlogAction with the same parameters
> +         */
> +        function AdminContactPluginSettingsAction($actionInfo, $request){
> +        	$this->AdminAction($actionInfo, $request);
> +			$this->requirePermission("manage_plugins");
> +        }
> +
> +        /**
> +         * Carries out the specified action
> +         */
> +        function perform(){
> +            $this->_view = new AdminContactPluginSettingsView($this->_blogInfo);
> +			$this->setCommonData();
> +			return true;
> +        }
> +    }
>
> Added: plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginupdatesettingsaction.class.php
> ===================================================================
> --- plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginupdatesettingsaction.class.php	                        (rev 0)
> +++ plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginupdatesettingsaction.class.php	2009-04-18 21:03:37 UTC (rev 6868)
> @@ -0,0 +1,62 @@
> +<?php
> +
> +	lt_include(PLOG_CLASS_PATH."class/action/admin/adminaction.class.php");
> +	lt_include(PLOG_CLASS_PATH."plugins/contact/class/view/admincontactpluginsettingsview.class.php");
> +	lt_include(PLOG_CLASS_PATH."class/dao/blogs.class.php");
> +	lt_include(PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php");
> +
> +    class AdminContactPluginUpdateSettingsAction extends AdminAction
> +	{
> +		var $_pluginEnabled;
> +
> +        function AdminContactPluginUpdateSettingsAction($actionInfo, $request){
> +        	$this->AdminAction($actionInfo, $request);
> +			$this->requirePermission("manage_plugins");
> +        	$this->registerFieldValidator("pluginEnabled", new IntegerValidator(), true);
> +
> +			$view = new AdminContactPluginSettingsView($this->_blogInfo, $this->_userInfo);
> +        	$view->setErrorMessage($this->_locale->tr("plugin_contact_error_updating_settings"));
> +        	$this->setValidationErrorView($view);
> +        }
> +
> +		function validate(){
> +            if(!parent::validate())
> +                return false;
> +
> +            $this->_pluginEnabled = $this->_request->getValue("pluginEnabled");
> +            $this->_pluginEnabled = ($this->_pluginEnabled != "");
> +			return true;
> +		}
> +
> +        function perform(){
> +        	// update the plugin configurations to blog setting
> +			$blogSettings = $this->_blogInfo->getSettings();
> +			$blogSettings->setValue("plugin_contact_enabled", $this->_pluginEnabled);
> +			$this->_blogInfo->setSettings($blogSettings);
> +
> +			// update the settings in the db, and make sure that everything went fine
> +			$blogs = new Blogs();
> +			if(!$blogs->updateBlog($this->_blogInfo)) {
> +                $this->_view = new AdminContactPluginSettingsView($this->_blogInfo);
> +                $this->_view->setErrorMessage($this->_locale->tr("plugin_contact_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 AdminContactPluginSettingsView($this->_blogInfo);
> +			$this->_view->setSuccessMessage($this->_locale->tr("plugin_contact_settings_saved_ok"));
> +			$this->setCommonData();
> +
> +			// clear the cache
> +			CacheControl::resetBlogCache($this->_blogInfo->getId());
> +
> +            return true;
> +        }
> +    }
> +?>
>
> Added: plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php
> ===================================================================
> --- plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php	                        (rev 0)
> +++ plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php	2009-04-18 21:03:37 UTC (rev 6868)
> @@ -0,0 +1,54 @@
> +<?php
> +    lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
> +    lt_include( PLOG_CLASS_PATH."class/view/plugintemplatedview.class.php" );
> +    lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
> +    lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
> +    lt_include( PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );
> +	lt_include( PLOG_CLASS_PATH."class/mail/emailservice.class.php" );
> +
> +    /**
> +     * Checks the data and sends an email if everything validates
> +     */
> +    class ContactPluginSendAction extends BlogAction
> +    {
> +        function ContactPluginSendAction($actionInfo, $request){
> +            $this->BlogAction($actionInfo, $request);
> +
> +        	$this->registerFieldValidator("userName", new StringValidator());
> +        	$this->registerFieldValidator("userEmailAddress", new EmailValidator());
> +        	$this->registerFieldValidator("contactTopic", new StringValidator());
> +        	$this->registerFieldValidator("contactText", new StringValidator( true ));
> +
> +			$view = new ErrorView($this->_blogInfo);
> +        	$view->setErrorMessage($this->_locale->tr("plugin_contact_error_data"));
> +        	$this->setValidationErrorView($view);
> +        }
> +
> +
> +        function perform(){
> +            $postText =
> +                $this->_locale->pr("plugin_contact_contact_from",
> +                                   $this->_request->getValue("userName") . " <".
> +                                   $this->_request->getValue("userEmailAddress").">").
> +                $this->_request->getValue("contactText");
> +
> +            $config =& Config::getConfig();
> +
> +            $message = new EmailMessage();
> +            $message->setFrom($config->getValue( "post_notification_source_address"));
> +            $message->setSubject($this->_request->getValue("contactTopic"));
> +            $message->setCharset($this->_locale->getCharset());
> +            $message->setBody($postText);
> +
> +            $user =& $this->_blogInfo->getOwnerInfo();
> +            $message->setTo($user->getEmail());
> +
> +            $service = new EmailService();
> +            $service->sendMessage($message);
> +
> +            $this->_view = new PluginTemplatedView( $this->_blogInfo, "contact", "accepted" );
> +            $this->setCommonData();
> +
> +            return true;
> +        }
> +    }
>
> Added: plugins/branches/lifetype-1.2/contact/class/view/admincontactpluginsettingsview.class.php
> ===================================================================
> --- plugins/branches/lifetype-1.2/contact/class/view/admincontactpluginsettingsview.class.php	                        (rev 0)
> +++ plugins/branches/lifetype-1.2/contact/class/view/admincontactpluginsettingsview.class.php	2009-04-18 21:03:37 UTC (rev 6868)
> @@ -0,0 +1,20 @@
> +<?php
> +	lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
> +
> +	/**
> +	 * implements the main view of the contact plugin
> +	 */
> +	class AdminContactPluginSettingsView extends AdminPluginTemplatedView
> +	{
> +		function AdminContactPluginSettingsView($blogInfo){
> +			$this->AdminPluginTemplatedView($blogInfo, "contact", "pluginsettings");
> +		}
> +
> +		function render(){
> +			// load some configuration settings
> +			$blogSettings = $this->_blogInfo->getSettings();
> +			$this->setValue( "pluginEnabled", $blogSettings->getValue("plugin_contact_enabled"));
> +			parent::render();
> +		}
> +	}
> +?>
>
> Added: plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php
> ===================================================================
> --- plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php	                        (rev 0)
> +++ plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php	2009-04-18 21:03:37 UTC (rev 6868)
> @@ -0,0 +1,15 @@
> +<?php
> +$messages["plugin_contact"] = "Contact";
> +$messages["plugin_contact_enabled"] = "Enable this plugin";
> +
> +$messages["plugin_contact_name"] = "Your Name";
> +$messages["plugin_contact_email_address"] = "Your Email Address";
> +$messages["plugin_contact_contact_from"] = "Blog contact from: %s\n\n";
> +
> +$messages["plugin_contact_error_updating_settings"] = "There was an error updating the settings.";
> +$messages["plugin_contact_settings_saved_ok"] = "The settings were updated successfully.";
> +
> +$messages["plugin_contact_error_data"] = "Error sending message.  Please click <a href='javascript:history.go(-1)'>'back'</a> and try again.";
> +
> +$messages["plugin_contact_email_accepted"] = "Your message was sent successfully!";
> +
>
> Added: plugins/branches/lifetype-1.2/contact/plugincontact.class.php
> ===================================================================
> --- plugins/branches/lifetype-1.2/contact/plugincontact.class.php	                        (rev 0)
> +++ plugins/branches/lifetype-1.2/contact/plugincontact.class.php	2009-04-18 21:03:37 UTC (rev 6868)
> @@ -0,0 +1,81 @@
> +<?php
> +
> +	lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
> +    lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
> +
> +	/**
> +	 * allows visitors to submit a message that will be
> +     *   emailed to the blog owner.
> +	 */
> +	class PluginContact extends PluginBase
> +	{
> +
> +		function PluginContact( $source = "")
> +		{
> +			$this->PluginBase($source);
> +			$this->id = "contact";
> +			$this->desc = "Allows visitors to submit a message to the blog owner (via email)";
> +			$this->author = "Jon Daley";
> +			$this->version = "20090418beta";
> +
> +			if( $source == "admin" )
> +				$this->initAdmin();
> +			else
> +				$this->init();
> +		}
> +
> +		/**
> +		 * registers all the filters and actions that we're going to use on the admin side
> +		 */
> +		function initAdmin(){
> +			$this->registerAdminAction( "pluginContactSettings", "AdminContactPluginSettingsAction" );
> +			$this->registerAdminAction( "pluginContactUpdateSettings", "AdminContactPluginUpdateSettingsAction" );
> +			$this->addMenuEntry( "/menu/controlCenter/manageSettings", "plugin_contact",
> +                                 "admin.php?op=pluginContactSettings");
> +        }
> +
> +        /**
> +		 * registers all the filters and actions that we're going to use on the public side
> +		 */
> +		function init(){
> +		    $this->registerBlogAction( "pluginContactSendEmail", "ContactPluginSendAction" );
> +		}
> +
> +        function showForm(){
> +		    $blogSettings = $this->blogInfo->getSettings();
> +		    if(!$blogSettings->getValue("plugin_contact_enabled"))
> +                return "";
> +
> +            $locale =& $this->blogInfo->getLocale();
> +
> +            return "<div id='contact'>
> +<form name='contactForm' method='post' action='{$this->blogInfo->getBlogRequestGenerator()->getIndexUrl()}'>
> + <label for='userName'>{$locale->tr('plugin_contact_name')}: </label>
> + <input type='text' name='userName'  /><br/>
> +
> + <label for='userEmailAddress'>{$locale->tr('plugin_contact_email_address')}: </label>
> + <input type='text' name='userEmailAddress' /><br/>
> +
> + <label for='contactTopic'>{$locale->tr('comment_topic')}: </label>
> + <input type='text' name='contactTopic' /><br/>
> +
> +  <label for='contactText'>{$locale->tr('comment_text')}: </label>
> +  <script type='text/javascript'>var ed1 = new Lifetype.UI.Editor('contactText','ed1');</script>
> +  <textarea rows='15' id='contactText' name='contactText' style='width:100%'></textarea><br/>
> +
> + <input type='hidden' name='op' value='pluginContactSendEmail' />
> + <input type='hidden' name='blogId' value='{$this->blogInfo->getId()}' />
> + <input type='submit' value='{$locale->tr('comment_send')}' />
> +</form>
> +</div>";
> +        }
> +
> +        function getPluginConfigurationKeys(){
> +
> +            return (Array(
> +                        Array("name" => "plugin_contact_enabled",
> +                              "type" => "boolean")
> +                        ));
> +        }
> +	}
> +?>
>
> Added: plugins/branches/lifetype-1.2/contact/readme.txt
> ===================================================================
> --- plugins/branches/lifetype-1.2/contact/readme.txt	                        (rev 0)
> +++ plugins/branches/lifetype-1.2/contact/readme.txt	2009-04-18 21:03:37 UTC (rev 6868)
> @@ -0,0 +1,24 @@
> +Plugin: Contact
> +Author: Jon Daley
> +Release Date: 2009/04/18
> +
> +This plugin offers a method for visitors to privately contact blog
> +owners via form/email.
> +
> +Install:
> +1. Configure and enable the plugin in your LifeType control center
> +
> +Template code - note this plugin will take care of checking if the
> +                plugin is enabled or not, and won't show the form if
> +                it is disabled for the blog
> + {if $contact}
> +   {$contact->showContactForm()}
> + {/if}
> +
> +
> +TODO:
> +  It will use the bayesian filter if it is enabled
> +  Can we use authimage and hiddeninput if they are installed?
> +
> +
> +
>
> Added: plugins/branches/lifetype-1.2/contact/templates/accepted.template
> ===================================================================
> --- plugins/branches/lifetype-1.2/contact/templates/accepted.template	                        (rev 0)
> +++ plugins/branches/lifetype-1.2/contact/templates/accepted.template	2009-04-18 21:03:37 UTC (rev 6868)
> @@ -0,0 +1,4 @@
> +{include file="$blogtemplate/header.template"}
> +<p>{$locale->tr("plugin_contact_email_accepted")}</p>
> +<p><a href="javascript:history.go(-1)">{$locale->tr("back")}</a></p>
> +{include file="$blogtemplate/footer.template"}
>
> Added: plugins/branches/lifetype-1.2/contact/templates/pluginsettings.template
> ===================================================================
> --- plugins/branches/lifetype-1.2/contact/templates/pluginsettings.template	                        (rev 0)
> +++ plugins/branches/lifetype-1.2/contact/templates/pluginsettings.template	2009-04-18 21:03:37 UTC (rev 6868)
> @@ -0,0 +1,25 @@
> +{include file="$admintemplatepath/header.template"}
> +{include file="$admintemplatepath/navigation.template" showOpt=plugin_contact title=$locale->tr("plugin_contact")}
> +<form action="admin.php" 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}
> +     {user_cannot_override key=plugin_contact_enabled}disabled="disabled"{/user_cannot_override}
> +     value="1" />{$locale->tr("plugin_contact_enabled")}
> +   </div>
> +  </div>
> + </fieldset>
> +
> + <div class="buttons">
> +  <input type="hidden" name="op" value="pluginContactUpdateSettings" />
> +  <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
> + </div>
> +</form>
> +{include file="$admintemplatepath/footernavigation.template"}
> +{include file="$admintemplatepath/footer.template"}
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn
>

-- 
Jon Daley
http://jon.limedaley.com
~~
It's better to speak truth that hurts and then helps than
falsehood that comforts and then kills.
-- Joyce Rogers


More information about the pLog-svn mailing list