Author: Keri Henare Date: 2010-02-07 22:28:46 +0100 (Sun, 07 Feb 2010) New Revision: 27678
Added: plugins/sfAkismetPlugin/trunk/LICENSE plugins/sfAkismetPlugin/trunk/README plugins/sfAkismetPlugin/trunk/config/ plugins/sfAkismetPlugin/trunk/config/sfAkismetPluginConfiguration.class.php plugins/sfAkismetPlugin/trunk/lib/ plugins/sfAkismetPlugin/trunk/lib/sfAkismet.class.php plugins/sfAkismetPlugin/trunk/package.xml Log: Initial import Added: plugins/sfAkismetPlugin/trunk/LICENSE =================================================================== --- plugins/sfAkismetPlugin/trunk/LICENSE (rev 0) +++ plugins/sfAkismetPlugin/trunk/LICENSE 2010-02-07 21:28:46 UTC (rev 27678) @@ -0,0 +1,7 @@ +Copyright (c) 2010 Pixel Fusion Ltd (http://pixelfusion.co.nz) + +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. \ No newline at end of file Property changes on: plugins/sfAkismetPlugin/trunk/README ___________________________________________________________________ Added: svn:mime-type + text/plain Added: plugins/sfAkismetPlugin/trunk/config/sfAkismetPluginConfiguration.class.php =================================================================== --- plugins/sfAkismetPlugin/trunk/config/sfAkismetPluginConfiguration.class.php (rev 0) +++ plugins/sfAkismetPlugin/trunk/config/sfAkismetPluginConfiguration.class.php 2010-02-07 21:28:46 UTC (rev 27678) @@ -0,0 +1,21 @@ +<?php + +/** + * sfAkismetPlugin configuration. + * + * @package sfAkismetPlugin + * @subpackage config + * @author Keri Henare <[email protected]> + * @version SVN: $Id$ + */ +class sfAkismetPluginConfiguration extends sfPluginConfiguration +{ + const VERSION = '1.0.0-DEV'; + + /** + * @see sfPluginConfiguration + */ + public function initialize() + { + } +} Property changes on: plugins/sfAkismetPlugin/trunk/config/sfAkismetPluginConfiguration.class.php ___________________________________________________________________ Added: svn:mime-type + text/x-php Added: svn:keywords + Id Rev Date Added: svn:eol-style + native Added: plugins/sfAkismetPlugin/trunk/lib/sfAkismet.class.php =================================================================== --- plugins/sfAkismetPlugin/trunk/lib/sfAkismet.class.php (rev 0) +++ plugins/sfAkismetPlugin/trunk/lib/sfAkismet.class.php 2010-02-07 21:28:46 UTC (rev 27678) @@ -0,0 +1,80 @@ +<?php + +class sfAkismet { + + private $browser; + private $host; + private $key; + + protected $api_version = '1.1'; + + public function __construct() { + + $this->host = sfConfig::get('app_akismet_host', 'rest.akismet.com'); + $this->key = sfConfig::get('app_akismet_key', null); + + if (!$this->key) { + throw new sfException('No Akismet key has been set'); + } + + $this->browser = new sfWebBrowser(array( + 'timeout' => 5, + 'user_agent' => 'Symfony/'.sfConfig::get('sf_version').' | sfAkismet/1.0' + )); + + } + + public function isValid() { + + $request = sfContext::getInstance()->getRequest(); + $params = array( + 'blog' => 'http://'.$request->getHost(), + 'key' => $this->key + ); + + try { + if ($this->browser->post('http://'.$this->host.'/'.$this->api_version.'/verify-key', $params)->responseIsError()) { + throw new sfException(sprintf('The given URL (%s) returns an error (%s: %s)', 'http://'.$this->host.'/'.$this->api_version.'/verify-key', $this->browser->getResponseCode(), $this->browser->getResponseMessage())); + } + } + catch (Exception $e) { + throw new sfException('Could not contact Akismet server '.$e); + } + + return strtolower($this->browser->getResponseText()) == 'valid'; + } + + public function isSpam(array $params) { + return strtolower($this->submit($params, 'comment-check')) == 'true'; + } + + public function setSpam(array $params) { + $this->submit($params, 'submit-spam'); + } + + public function setHam(array $params) { + $this->submit($params, 'submit-ham'); + } + + private function submit(array $params, $url) { + + $request = sfContext::getInstance()->getRequest(); + $params = array_merge($_SERVER, array( + 'blog' => 'http://'.$request->getHost(), + 'user_ip' => $request->getRemoteAddress(), + 'user_agent' => $request->getHttpHeader('User-Agent') + ), $params); + + try { + if ($this->browser->post('http://'.$this->key.'.'.$this->host.'/'.$this->api_version.'/'.$url, $params)->responseIsError()) { + throw new sfException(sprintf('The given URL (%s) returns an error (%s: %s)', 'http://'.$this->key.'.'.$this->host.'/'.$this->api_version.'/'.$url, $this->browser->getResponseCode(), $this->browser->getResponseMessage())); + } + } + catch (Exception $e) { + throw new sfException('Could not contact Akismet server '.$e); + } + + return $this->browser->getResponseText(); + } + +} \ No newline at end of file Property changes on: plugins/sfAkismetPlugin/trunk/lib/sfAkismet.class.php ___________________________________________________________________ Added: svn:mime-type + text/x-php Added: svn:keywords + Id Rev Date Added: svn:eol-style + native Added: plugins/sfAkismetPlugin/trunk/package.xml =================================================================== --- plugins/sfAkismetPlugin/trunk/package.xml (rev 0) +++ plugins/sfAkismetPlugin/trunk/package.xml 2010-02-07 21:28:46 UTC (rev 27678) @@ -0,0 +1,72 @@ +<?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>sfAkismetPlugin</name> + <channel>pear.symfony-project.com</channel> + <summary>sfAkismetPlugin is an interface for the Akismet spam detection API.</summary> + <description>sfAkismetPlugin is an interface for the Akismet spam detection API.</description> + <lead> + <name>Keri Henare</name> + <user>Keri Henare</user> + <email>[email protected]</email> + <active>yes</active> + </lead> + <date>2010-02-08</date> + <version> + <release>0.1.0</release> + <api>0.1.0</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <license uri="http://www.symfony-project.org/license">MIT license</license> + <notes>-</notes> + <contents> + <dir name="/"> + <dir name="lib"> + <file name="sfAkismet.class.php" role="data"/> + </dir> + <dir name="config"> + <file name="sfAkismetPluginConfiguration.class.php" role="data"/> + </dir> + <file name="README" role="data"/> + <file name="LICENSE" role="data"/> + </dir> + </contents> + <dependencies> + <required> + <php> + <min>5.1.0</min> + </php> + <pearinstaller> + <min>1.4.1</min> + </pearinstaller> + <package> + <name>symfony</name> + <channel>pear.symfony-project.com</channel> + <min>1.1.0</min> + <max>2.0.0</max> + <exclude>2.0.0</exclude> + </package> + </required> + </dependencies> + + <phprelease></phprelease> + + <changelog> + <release> + <date>2010-02-08</date> + <version> + <release>0.1</release> + <api>0.1</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <license uri="http://www.symfony-project.org/license">MIT license</license> + <notes>* Keri Henare: Created plugin</notes> + </release> + </changelog> + +</package> Property changes on: plugins/sfAkismetPlugin/trunk/package.xml ___________________________________________________________________ Added: svn:executable + Added: svn:mime-type + text/xml -- 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.
