Author: mstralka Date: 2010-04-11 00:23:25 +0200 (Sun, 11 Apr 2010) New Revision: 29067
Added: plugins/WebPurifyPlugin/trunk/LICENSE plugins/WebPurifyPlugin/trunk/README plugins/WebPurifyPlugin/trunk/lib/ plugins/WebPurifyPlugin/trunk/lib/model/ plugins/WebPurifyPlugin/trunk/lib/model/AbstractWebPurifyCommand.class.php plugins/WebPurifyPlugin/trunk/lib/model/WebPurifyLiveCheckCommand.class.php plugins/WebPurifyPlugin/trunk/lib/validator/ plugins/WebPurifyPlugin/trunk/lib/validator/WebPurifyProfanityValidator.class.php plugins/WebPurifyPlugin/trunk/package.xml plugins/WebPurifyPlugin/trunk/package.xml.tmpl Log: checking in version 1.0 to trunk Added: plugins/WebPurifyPlugin/trunk/LICENSE =================================================================== --- plugins/WebPurifyPlugin/trunk/LICENSE (rev 0) +++ plugins/WebPurifyPlugin/trunk/LICENSE 2010-04-10 22:23:25 UTC (rev 29067) @@ -0,0 +1,7 @@ +Copyright (c) 2010 Mark Stralka + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Added: plugins/WebPurifyPlugin/trunk/README =================================================================== --- plugins/WebPurifyPlugin/trunk/README (rev 0) +++ plugins/WebPurifyPlugin/trunk/README 2010-04-10 22:23:25 UTC (rev 29067) @@ -0,0 +1,36 @@ +# WebPurify Plugin + +## Introduction +[WebPurify](http://www.webpurify.com) provides a cost-effective real-time profanity filtering service. + +This plugin provides *sfWebPurifyProfanityValidator*, which rejects a value if it contains profanity. + +Future versions may implement the [other methods](http://www.webpurify.com/profanity/filter/documentation.php) available from WebPurify + +## Configuration + +Purchase an API key from WebPurify. You can signup for a test license by entering *localhost* for the IP address. + +Add the following to your *app.yml* file: + + all: + webpurify: + api_key: YOUR API KEY HERE + + +To use it in your forms, combine it with the existing validator for a given field by using *sfValidatorAnd*: + + [php] + $this->validatorSchema['name'] = new sfValidatorAnd(array( + $this->validatorSchema['name'] + , new WebPurifyProfanityValidator() + )); + +You could also invoke the *LiveCheck* method without the validator by doing this: + + [php] + $command = new WebPurifyLiveCheckCommand(sfConfig::get('app_webpurify_api_key'), 'Text to check for profanity'); + $isClean = $command->isClean(); //returns TRUE or FALSE + +## Support +We developed and released this plugin, but we are not affiliated with WebPurify so do not contact us for WP support issues. \ No newline at end of file Added: plugins/WebPurifyPlugin/trunk/lib/model/AbstractWebPurifyCommand.class.php =================================================================== --- plugins/WebPurifyPlugin/trunk/lib/model/AbstractWebPurifyCommand.class.php (rev 0) +++ plugins/WebPurifyPlugin/trunk/lib/model/AbstractWebPurifyCommand.class.php 2010-04-10 22:23:25 UTC (rev 29067) @@ -0,0 +1,68 @@ +<?php +/** + * Abstract class representing a WebPurify command + * @author Mark Stralka, Kazaam Interactive + * @see http://www.webpurify.com/profanity/filter/documentation.php + */ +abstract class AbstractWebPurifyCommand +{ + private $restEndpointUrl = 'http://www.webpurify.com/services/rest/'; + protected $apiKey = ''; + protected $parameters = array( + 'lang' => 'en' + ); + protected $response = null; + + public function __construct($apiKey, $language = 'en') + { + if (trim($apiKey) == '') + { + die('WebPurify API key not provided.'); + } + $this->parameters['api_key'] = $apiKey; + $this->parameters['lang'] = $language; + } + + protected final function getRestEndpointUrl() + { + return $this->restEndpointUrl; + } + + protected final function getParameters() + { + return $this->parameters; + } + + public final function buildUrl() + { + $ret = $this->getRestEndpointUrl(); + $ret .= '?'; + $ret .= http_build_query($this->getParameters()); + return $ret; + } + + /** + * Perform the WebPurify query and return a SimpleXMLElement object as the response. + * @return SimpleXMLElement + */ + public final function execute() + { + if (is_null($this->response)) + { + try + { + $this->response = simplexml_load_file($this->buildUrl(),'SimpleXMLElement'); + } catch (Exception $e) + { + //TODO: do something with the exception + $this->response = $e; + } + } + return $this->response; + } + + /** + * Perform the query and return the response + */ + public abstract function getResponse(); +} \ No newline at end of file Added: plugins/WebPurifyPlugin/trunk/lib/model/WebPurifyLiveCheckCommand.class.php =================================================================== --- plugins/WebPurifyPlugin/trunk/lib/model/WebPurifyLiveCheckCommand.class.php (rev 0) +++ plugins/WebPurifyPlugin/trunk/lib/model/WebPurifyLiveCheckCommand.class.php 2010-04-10 22:23:25 UTC (rev 29067) @@ -0,0 +1,43 @@ +<?php +/** + * Implementation fo WP's LiveCheck method. + * Basically if profanity is found it returns 1. + * If the text is clean 0 (zero) is returned. + * @author Mark Stralka, Kazaam Interactive + */ +class WebPurifyLiveCheckCommand extends AbstractWebPurifyCommand +{ + public function __construct($apiKey, $text, $language = 'en') + { + parent::__construct($apiKey, $language); + $this->parameters['method'] = 'webpurify.live.check'; + $this->parameters['text'] = $text; + } + + /** + * if profanity is found it returns 1. If the text is clean 0 (zero) is returned. + */ + public function getResponse() + { + $response = $this->execute(); + if ($response) + { + return $response->found; + } + return 0; + } + + /** + * Return TRUE if the text is clean, false if it has profanity + * @return boolean + */ + public function isClean() + { + $response = $this->getResponse(); + if ($response != 0) + { + return false; + } + return true; + } +} \ No newline at end of file Added: plugins/WebPurifyPlugin/trunk/lib/validator/WebPurifyProfanityValidator.class.php =================================================================== --- plugins/WebPurifyPlugin/trunk/lib/validator/WebPurifyProfanityValidator.class.php (rev 0) +++ plugins/WebPurifyPlugin/trunk/lib/validator/WebPurifyProfanityValidator.class.php 2010-04-10 22:23:25 UTC (rev 29067) @@ -0,0 +1,48 @@ +<?php + +/** + * WebPurifyProfanityValidator validates that a string does not + * contain profanity. + * + * @author Mark Stralka, Kazaam Interactive + * + */ +class WebPurifyProfanityValidator extends sfValidatorBase +{ + /** + * Configures the current validator. + * + * Available options: + * + * * api_key: Your WebPurify API key. The default value will be pulled from app.yml + * + * Available error codes: + * + * * profanity + * + * @param array $options An array of options + * @param array $messages An array of error messages + */ + protected function configure($options = array(), $messages = array()) + { + $this->addMessage('profanity', 'Profanity is not allowed.'); + + $this->addOption('api_key', sfConfig::get('app_webpurify_api_key')); + } + + /** + * @see sfValidatorBase + */ + protected function doClean($value) + { + $clean = (string) $value; + + $command = new WebPurifyLiveCheckCommand($this->getOption('api_key'), $clean); + if ($command->isClean() === false) + { + throw new sfValidatorError($this, 'profanity'); + } + + return $clean; + } +} \ No newline at end of file Added: plugins/WebPurifyPlugin/trunk/package.xml =================================================================== --- plugins/WebPurifyPlugin/trunk/package.xml (rev 0) +++ plugins/WebPurifyPlugin/trunk/package.xml 2010-04-10 22:23:25 UTC (rev 29067) @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.4.1" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> + <name>WebPurifyPlugin</name> + <channel>pear.symfony-project.com</channel> + <summary>Powerful profanity filter for symfony</summary> + <description>Uses the WebPurify service to check for profanity</description> + <lead> + <name>Mark Stralka</name> + <user>mstralka</user> + <email>[email protected]</email> + <active>yes</active> + </lead> + <date>2010-04-10</date> + <version> + <release>1.0</release> + <api>1.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.symfony-project.org/license">MIT license</license> + <notes>-</notes> + <contents> + <dir name="/"> + <file role="data" name="README" /> + <file role="data" name="LICENSE" /> + <dir name="lib"> + <dir name="model"> + <file role="data" name="AbstractWebPurifyCommand.class.php" /> + <file role="data" name="WebPurifyLiveCheckCommand.class.php" /> + </dir> + <dir name="validator"> + <file role="data" name="WebPurifyProfanityValidator.class.php" /> + </dir> + </dir> + </dir> + </contents> + <dependencies> + <required> + <php> + <min>5.2.4</min> + </php> + <pearinstaller> + <min>1.4.1</min> + </pearinstaller> + <package> + <name>symfony</name> + <channel>pear.symfony-project.com</channel> + <min>1.3.0</min> + <max>1.5.0</max> + <exclude>1.5.0</exclude> + </package> + </required> + </dependencies> + <phprelease></phprelease> + <changelog> + <release> + <version> + <release>1.0</release> + <api>1.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.symfony-project.com/license">MIT license</license> + <license>MIT</license> + <date>2010-04-10</date> + <notes> + * First release of the plugin providing WebPurifyProfanityValidator + </notes> + </release> + </changelog> +</package> Added: plugins/WebPurifyPlugin/trunk/package.xml.tmpl =================================================================== --- plugins/WebPurifyPlugin/trunk/package.xml.tmpl (rev 0) +++ plugins/WebPurifyPlugin/trunk/package.xml.tmpl 2010-04-10 22:23:25 UTC (rev 29067) @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.4.1" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> + <name>WebPurifyPlugin</name> + <channel>pear.symfony-project.com</channel> + <summary>Powerful profanity filter for symfony</summary> + <description>Uses the WebPurify service to check for profanity</description> + <lead> + <name>Mark Stralka</name> + <user>mstralka</user> + <email>[email protected]</email> + <active>yes</active> + </lead> + <date>##CURRENT_DATE##</date> + <version> + <release>##PLUGIN_VERSION##</release> + <api>##API_VERSION##</api> + </version> + <stability> + <release>##STABILITY##</release> + <api>##STABILITY##</api> + </stability> + <license uri="http://www.symfony-project.org/license">MIT license</license> + <notes>-</notes> + <contents> + ##CONTENTS## + </contents> + <dependencies> + <required> + <php> + <min>5.2.4</min> + </php> + <pearinstaller> + <min>1.4.1</min> + </pearinstaller> + <package> + <name>symfony</name> + <channel>pear.symfony-project.com</channel> + <min>1.3.0</min> + <max>1.5.0</max> + <exclude>1.5.0</exclude> + </package> + </required> + </dependencies> + <phprelease></phprelease> + <changelog> + <release> + <version> + <release>1.0</release> + <api>1.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.symfony-project.com/license">MIT license</license> + <license>MIT</license> + <date>2010-04-10</date> + <notes> + * First release of the plugin providing WebPurifyProfanityValidator + </notes> + </release> + </changelog> +</package> -- You received this message because you are subscribed to the Google Groups "symfony SVN" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-svn?hl=en.
