[pLog-svn] r6032 - in plugins/branches/lifetype-1.2: . recaptcha recaptcha/class recaptcha/class/action recaptcha/class/security recaptcha/class/view recaptcha/library recaptcha/locale recaptcha/templates

reto at devel.lifetype.net reto at devel.lifetype.net
Sat Nov 10 16:26:32 EST 2007


Author: reto
Date: 2007-11-10 16:26:32 -0500 (Sat, 10 Nov 2007)
New Revision: 6032

Added:
   plugins/branches/lifetype-1.2/recaptcha/
   plugins/branches/lifetype-1.2/recaptcha/TODO
   plugins/branches/lifetype-1.2/recaptcha/changelog
   plugins/branches/lifetype-1.2/recaptcha/class/
   plugins/branches/lifetype-1.2/recaptcha/class/action/
   plugins/branches/lifetype-1.2/recaptcha/class/action/pluginrecaptchaconfigaction.class.php
   plugins/branches/lifetype-1.2/recaptcha/class/action/pluginrecaptchaupdateconfigaction.class.php
   plugins/branches/lifetype-1.2/recaptcha/class/security/
   plugins/branches/lifetype-1.2/recaptcha/class/security/recaptchafilter.class.php
   plugins/branches/lifetype-1.2/recaptcha/class/view/
   plugins/branches/lifetype-1.2/recaptcha/class/view/pluginrecaptchaconfigview.class.php
   plugins/branches/lifetype-1.2/recaptcha/copyright
   plugins/branches/lifetype-1.2/recaptcha/library/
   plugins/branches/lifetype-1.2/recaptcha/library/LICENSE
   plugins/branches/lifetype-1.2/recaptcha/library/README
   plugins/branches/lifetype-1.2/recaptcha/library/example-captcha.php
   plugins/branches/lifetype-1.2/recaptcha/library/example-mailhide.php
   plugins/branches/lifetype-1.2/recaptcha/library/recaptchalib.php
   plugins/branches/lifetype-1.2/recaptcha/locale/
   plugins/branches/lifetype-1.2/recaptcha/locale/locale_de_DE.php
   plugins/branches/lifetype-1.2/recaptcha/locale/locale_en_UK.php
   plugins/branches/lifetype-1.2/recaptcha/pluginrecaptcha.class.php
   plugins/branches/lifetype-1.2/recaptcha/readme.txt
   plugins/branches/lifetype-1.2/recaptcha/templates/
   plugins/branches/lifetype-1.2/recaptcha/templates/recaptcha.template
Log:
adding recaptcha plugin - thx to cold tobi for writing this one!

Added: plugins/branches/lifetype-1.2/recaptcha/TODO
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/TODO	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/TODO	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,4 @@
+* If in the admin-section a private key is entered, do not display it in the
+user-config-section.
+ 
+* Let the user decide about which style of the recaptcha-let to use.

Added: plugins/branches/lifetype-1.2/recaptcha/changelog
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/changelog	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/changelog	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,13 @@
+recaptcha_plugin (20071102) 
+
+  * Added German locale
+  * Fixed some file-headers, which were forgotten.
+  * Changed version number to more common scheme (yyyymmdd)
+
+ -- Tobiasa Frost <tobi at coldtobi.de>  Fri Nov  2 11:10:34 CET 2007
+
+recaptcha_plugin (1.00) 
+
+  * First Version
+
+ -- Tobiasa Frost <tobi at coldtobi.de>  Thu Nov  1 13:03:36 CET 2007

Added: plugins/branches/lifetype-1.2/recaptcha/class/action/pluginrecaptchaconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/class/action/pluginrecaptchaconfigaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/class/action/pluginrecaptchaconfigaction.class.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,48 @@
+<?php
+
+    /* Copyright 2007 Tobias Frost <tobi at coldtobi.de> http://blog.coldtobi.de
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+    
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+    
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    */
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."plugins/recaptcha/class/view/pluginrecaptchaconfigview.class.php" );  
+
+    	class PluginRecaptchaConfigAction extends AdminAction 
+	{
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function PluginRecaptchaConfigAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+			$this->_view = new PluginRecaptchaConfigView( $this->_blogInfo );
+
+            $this->setCommonData();
+
+            // better to return true if everything fine
+            return true;
+        }
+    }
+?>

Added: plugins/branches/lifetype-1.2/recaptcha/class/action/pluginrecaptchaupdateconfigaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/class/action/pluginrecaptchaupdateconfigaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/class/action/pluginrecaptchaupdateconfigaction.class.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,98 @@
+<?php
+
+    /*  Copyright 2007 Tobias Frost <tobi at coldtobi.de> http://blog.coldtobi.de
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+    
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+    
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    */
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+    lt_include( PLOG_CLASS_PATH."plugins/recaptcha/class/view/pluginrecaptchaconfigview.class.php" ); 
+    
+    class PluginRecaptchaUpdateConfigAction extends AdminAction 
+	{
+	
+		var $_pluginEnabled;
+		var $_pubkey;
+		var $_privkey;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function PluginRecaptchaUpdateConfigAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+        }
+		
+		function validate()
+		{
+	        $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+            $this->_pluginEnabled = ($this->_pluginEnabled != "" );			
+            
+            $this->_pubkey  = $this->_request->GetValue( "PubKey");
+            $this->_privkey = $this->_request->GetValue( "PrivKey");
+            
+            if ( $_pluginEnabled)
+            {
+                if ( trim($_pubkey) == "" || trim($_privkey) == "" )    
+                {
+                    $this->_view = new PluginRecaptchaConfigView( $this->_blogInfo );
+                    $this->_view->setErrorMessage($this->_locale->tr("recaptcha_error_key"));
+                    $this->setCommonData();
+                    return false;                
+                }    
+            }
+			return true;
+		}
+		
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+            // update the plugin configurations to blog setting
+	    $blogSettings = $this->_blogInfo->getSettings();
+            $blogSettings->setValue( "plugin_recaptcha_enabled", $this->_pluginEnabled );
+            $blogSettings->setValue( "plugin_recaptcha_pubkey", $this-> _pubkey);
+            $blogSettings->setValue( "plugin_recaptcha_privkey", $this-> _privkey);
+
+            $this->_blogInfo->setSettings( $blogSettings ); 
+
+ 	// save the blogs settings
+	    $blogs = new Blogs();
+            if( !$blogs->updateBlog( $this->_blogInfo )) {
+                $this->_view = new PluginRecaptchaConfigView( $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 PluginRecaptchaConfigView( $this->_blogInfo );
+			$this->_view->setSuccessMessage( $this->_locale->tr("recaptcha_settings_saved_ok"));
+			$this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());	
+
+            return true;		
+        }
+    }
+ 
+?>

Added: plugins/branches/lifetype-1.2/recaptcha/class/security/recaptchafilter.class.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/class/security/recaptchafilter.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/class/security/recaptchafilter.class.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,84 @@
+<?php
+
+    /* Copyright 2007 Tobias Frost <tobi at coldtobi.de> http://blog.coldtobi.de
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+    
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+    
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    */
+
+lt_include( PLOG_CLASS_PATH."class/security/pipelinefilter.class.php" );
+
+require_once(PLOG_CLASS_PATH."plugins/recaptcha/library/recaptchalib.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!!
+define( "RECAPTCHA_SPAM", 43534 );
+
+
+class ReCaptchaFilter extends PipelineFilter 
+{
+
+    function ReCaptchaFilter( $pipelineRequest )
+	{
+		$this->PipelineFilter( $pipelineRequest );
+	}
+
+	function filter()
+	{
+
+		$blogInfo = $this->_pipelineRequest->getBlogInfo();
+		// check if this section has been enabled or disabled
+		$blogSettings = $blogInfo->getSettings();
+		$pluginEnabled = $blogSettings->getValue( "plugin_recaptcha_enabled" );
+		if( !$pluginEnabled) {
+			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		
+		$request  = $this->_pipelineRequest->getHttpRequest();
+		if( $request->getValue( "op" ) != "AddComment" ) {
+			return new PipelineResult();
+		}
+
+		// if this is already rejected, there is no reason to do anything here
+		if ( $this->_pipelineRequest->getRejectedState() )
+		{
+			return new PipelineResult();
+		}
+
+		// Obtain all parameters needed for the response checking. 
+		$clientIp = Client::getIp();
+		$challenge= $request->getValue("recaptcha_challenge_field");
+		$response = $request->getValue("recaptcha_response_field");
+		$privatekey = $blogSettings->getValue("plugin_recaptcha_privkey");
+
+		$resp = recaptcha_check_answer ($privatekey, $clientIp, $challenge, $response);
+
+		if (! $resp->is_valid)
+		{
+			$locale = $blogInfo->getLocale();
+			return new PipelineResult( false, RECAPTCHA_SPAM, $locale->tr("recaptcha_captcha_wrong"));
+		}
+		
+		// truing test passed ! 
+		return new PipelineResult();	
+	}
+
+}  
+
+?>

Added: plugins/branches/lifetype-1.2/recaptcha/class/view/pluginrecaptchaconfigview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/class/view/pluginrecaptchaconfigview.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/class/view/pluginrecaptchaconfigview.class.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,50 @@
+<?php
+	
+    /* Copyright 2007 Tobias Frost <tobi at coldtobi.de> http://blog.coldtobi.de
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+    
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+    
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    */
+
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+	/**
+	 * implements the main view of the validate trackback plugin
+	 */
+	class PluginRecaptchaConfigView extends AdminPluginTemplatedView
+	{
+
+		function PluginRecaptchaConfigView( $blogInfo )
+		{
+			$this->AdminPluginTemplatedView( $blogInfo, "recaptcha", "recaptcha" );
+		}
+		
+		function render()
+		{
+			// load some configuration settings
+			$blogSettings 	= $this->_blogInfo->getSettings();
+			
+			$pluginEnabled 	= $blogSettings->getValue( "plugin_recaptcha_enabled"  );
+			$PubKey 	   	= $blogSettings->getValue( "plugin_recaptcha_pubkey"   );
+			$PrivKey 		= $blogSettings->getValue( "plugin_recaptcha_privkey"  );
+			
+			// create a view and export the settings to the template
+			$this->setValue( "pluginEnabled", $pluginEnabled );
+			$this->setValue( "PubKey"		, $PubKey );
+			$this->setValue( "PrivKey"		, $PrivKey );
+			
+			parent::render();
+		}
+	}
+?>

Added: plugins/branches/lifetype-1.2/recaptcha/copyright
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/copyright	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/copyright	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,27 @@
+This plugin was written by Tobias Frot <tobi at coldtobi.de> on
+Thu Nov  1 13:03:36 CET 2007
+
+Copyright: 
+# plugin_recaptcha -- Read Books not Spam for Lifetype 
+#   Written by Tobias Frost <tobi at coldtobi.de>
+#   (C) 2007 Tobias Frost
+#
+# This program is freely distributable per the following license:
+#
+#  Permission to use, copy, modify, and distribute this software and its
+#  documentation for any purpose and without fee is hereby granted,
+#  provided that the above copyright notice appears in all copies and that
+#  both that copyright notice and this permission notice appear in
+#  supporting documentation.
+#
+#  I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I
+#  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+#  DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+#  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+#  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+#  SOFTWARE.
+
+The redistributed "recaptcha-library" in the directory recaptcha/library is 
+published under its own license. Please read recaptcha/library/license for the terms
+of the library.
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/recaptcha/library/LICENSE
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/library/LICENSE	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/library/LICENSE	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,22 @@
+Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
+AUTHORS:
+  Mike Crawford
+  Ben Maurer
+
+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/branches/lifetype-1.2/recaptcha/library/README
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/library/README	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/library/README	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,7 @@
+reCAPTCHA README
+================
+
+The reCAPTCHA PHP Lirary helps you use the reCAPTCHA API. Documentation
+for this library can be found at
+
+	http://recaptcha.net/plugins/php

Added: plugins/branches/lifetype-1.2/recaptcha/library/example-captcha.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/library/example-captcha.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/library/example-captcha.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,37 @@
+<html>
+  <body>
+    <form action="" method="post">
+<?php
+
+require_once('recaptchalib.php');
+
+// Get a key from http://recaptcha.net/api/getkey
+$publickey = "";
+$privatekey = "";
+
+# the response from reCAPTCHA
+$resp = null;
+# the error code from reCAPTCHA, if any
+$error = null;
+
+# was there a reCAPTCHA response?
+if ($_POST["recaptcha_response_field"]) {
+        $resp = recaptcha_check_answer ($privatekey,
+                                        $_SERVER["REMOTE_ADDR"],
+                                        $_POST["recaptcha_challenge_field"],
+                                        $_POST["recaptcha_response_field"]);
+
+        if ($resp->is_valid) {
+                echo "You got it!";
+        } else {
+                # set the error code so that we can display it
+                $error = $resp->error;
+        }
+}
+echo recaptcha_get_html($publickey, $error);
+?>
+    <br/>
+    <input type="submit" value="submit" />
+    </form>
+  </body>
+</html>

Added: plugins/branches/lifetype-1.2/recaptcha/library/example-mailhide.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/library/example-mailhide.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/library/example-mailhide.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,17 @@
+<html><body>
+<?
+require_once ("recaptchalib.php");
+
+// get a key at http://mailhide.recaptcha.net/apikey
+$mailhide_pubkey = '';
+$mailhide_privkey = '';
+
+?>
+
+The Mailhide version of example at example.com is
+<? echo recaptcha_mailhide_html ($mailhide_pubkey, $mailhide_privkey, "example at example.com"); ?>. <br>
+
+The url for the email is:
+<? echo recaptcha_mailhide_url ($mailhide_pubkey, $mailhide_privkey, "example at example.com"); ?> <br>
+
+</body></html>

Added: plugins/branches/lifetype-1.2/recaptcha/library/recaptchalib.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/library/recaptchalib.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/library/recaptchalib.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,276 @@
+<?php
+/*
+ * This is a PHP library that handles calling reCAPTCHA.
+ *    - Documentation and latest version
+ *          http://recaptcha.net/plugins/php/
+ *    - Get a reCAPTCHA API Key
+ *          http://recaptcha.net/api/getkey
+ *    - Discussion group
+ *          http://groups.google.com/group/recaptcha
+ *
+ * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
+ * AUTHORS:
+ *   Mike Crawford
+ *   Ben Maurer
+ *
+ * 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.
+ */
+
+/**
+ * The reCAPTCHA server URL's
+ */
+define("RECAPTCHA_API_SERVER", "http://api.recaptcha.net");
+define("RECAPTCHA_API_SECURE_SERVER", "https://api-secure.recaptcha.net");
+define("RECAPTCHA_VERIFY_SERVER", "api-verify.recaptcha.net");
+
+/**
+ * Encodes the given data into a query string format
+ * @param $data - array of string elements to be encoded
+ * @return string - encoded request
+ */
+function _recaptcha_qsencode ($data) {
+        $req = "";
+        foreach ( $data as $key => $value )
+                $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
+
+        // Cut the last '&'
+        $req=substr($req,0,strlen($req)-1);
+        return $req;
+}
+
+
+
+/**
+ * Submits an HTTP POST to a reCAPTCHA server
+ * @param string $host
+ * @param string $path
+ * @param array $data
+ * @param int port
+ * @return array response
+ */
+function _recaptcha_http_post($host, $path, $data, $port = 80) {
+
+        $req = _recaptcha_qsencode ($data);
+
+        $http_request  = "POST $path HTTP/1.0\r\n";
+        $http_request .= "Host: $host\r\n";
+        $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
+        $http_request .= "Content-Length: " . strlen($req) . "\r\n";
+        $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
+        $http_request .= "\r\n";
+        $http_request .= $req;
+
+        $response = '';
+        if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
+                die ('Could not open socket');
+        }
+
+        fwrite($fs, $http_request);
+
+        while ( !feof($fs) )
+                $response .= fgets($fs, 1160); // One TCP-IP packet
+        fclose($fs);
+        $response = explode("\r\n\r\n", $response, 2);
+
+        return $response;
+}
+
+
+
+/**
+ * Gets the challenge HTML (javascript and non-javascript version).
+ * This is called from the browser, and the resulting reCAPTCHA HTML widget
+ * is embedded within the HTML form it was called from.
+ * @param string $pubkey A public key for reCAPTCHA
+ * @param string $error The error given by reCAPTCHA (optional, default is null)
+ * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
+
+ * @return string - The HTML to be embedded in the user's form.
+ */
+function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
+{
+	if ($pubkey == null || $pubkey == '') {
+		die ("To use reCAPTCHA you must get an API key from <a href='http://recaptcha.net/api/getkey'>http://recaptcha.net/api/getkey</a>");
+	}
+	
+	if ($use_ssl) {
+                $server = RECAPTCHA_API_SECURE_SERVER;
+        } else {
+                $server = RECAPTCHA_API_SERVER;
+        }
+
+        $errorpart = "";
+        if ($error) {
+           $errorpart = "&amp;error=" . $error;
+        }
+        return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
+
+	<noscript>
+  		<iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br>
+  		<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
+  		<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
+	</noscript>';
+}
+
+
+
+
+/**
+ * A ReCaptchaResponse is returned from recaptcha_check_answer()
+ */
+class ReCaptchaResponse {
+        var $is_valid;
+        var $error;
+}
+
+
+/**
+  * Calls an HTTP POST function to verify if the user's guess was correct
+  * @param string $privkey
+  * @param string $remoteip
+  * @param string $challenge
+  * @param string $response
+  * @return ReCaptchaResponse
+  */
+function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response)
+{
+	if ($privkey == null || $privkey == '') {
+		die ("To use reCAPTCHA you must get an API key from <a href='http://recaptcha.net/api/getkey'>http://recaptcha.net/api/getkey</a>");
+	}
+
+	if ($remoteip == null || $remoteip == '') {
+		die ("For security reasons, you must pass the remote ip to reCAPTCHA");
+	}
+
+	
+	
+        //discard spam submissions
+        if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
+                $recaptcha_response = new ReCaptchaResponse();
+                $recaptcha_response->is_valid = false;
+                $recaptcha_response->error = 'incorrect-captcha-sol';
+                return $recaptcha_response;
+        }
+
+        $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/verify",
+                                          array (
+                                                 'privatekey' => $privkey,
+                                                 'remoteip' => $remoteip,
+                                                 'challenge' => $challenge,
+                                                 'response' => $response
+                                                 )
+                                          );
+
+        $answers = explode ("\n", $response [1]);
+        $recaptcha_response = new ReCaptchaResponse();
+
+        if (trim ($answers [0]) == 'true') {
+                $recaptcha_response->is_valid = true;
+        }
+        else {
+                $recaptcha_response->is_valid = false;
+                $recaptcha_response->error = $answers [1];
+        }
+        return $recaptcha_response;
+
+}
+
+/**
+ * gets a URL where the user can sign up for reCAPTCHA. If your application
+ * has a configuration page where you enter a key, you should provide a link
+ * using this function.
+ * @param string $domain The domain where the page is hosted
+ * @param string $appname The name of your application
+ */
+function recaptcha_get_signup_url ($domain = null, $appname = null) {
+	return "http://recaptcha.net/api/getkey?" .  _recaptcha_qsencode (array ('domain' => $domain, 'app' => $appname));
+}
+
+function _recaptcha_aes_pad($val) {
+	$block_size = 16;
+	$numpad = $block_size - (strlen ($val) % $block_size);
+	return str_pad($val, strlen ($val) + $numpad, chr($numpad));
+}
+
+/* Mailhide related code */
+
+function _recaptcha_aes_encrypt($val,$ky) {
+	if (! function_exists ("mcrypt_encrypt")) {
+		die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
+	}
+	$mode=MCRYPT_MODE_CBC;   
+	$enc=MCRYPT_RIJNDAEL_128;
+	$val=_recaptcha_aes_pad($val);
+	return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
+}
+
+
+function _recaptcha_mailhide_urlbase64 ($x) {
+	return strtr(base64_encode ($x), '+/', '-_');
+}
+
+/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
+function recaptcha_mailhide_url($pubkey, $privkey, $email) {
+	if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
+		die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
+		     "you can do so at <a href='http://mailhide.recaptcha.net/apikey'>http://mailhide.recaptcha.net/apikey</a>");
+	}
+	
+
+	$ky = pack('H*', $privkey);
+	$cryptmail = _recaptcha_aes_encrypt ($email, $ky);
+	
+	return "http://mailhide.recaptcha.net/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
+}
+
+/**
+ * gets the parts of the email to expose to the user.
+ * eg, given johndoe at example,com return ["john", "example.com"].
+ * the email is then displayed as john... at example.com
+ */
+function _recaptcha_mailhide_email_parts ($email) {
+	$arr = preg_split("/@/", $email );
+
+	if (strlen ($arr[0]) <= 4) {
+		$arr[0] = substr ($arr[0], 0, 1);
+	} else if (strlen ($arr[0]) <= 6) {
+		$arr[0] = substr ($arr[0], 0, 3);
+	} else {
+		$arr[0] = substr ($arr[0], 0, 4);
+	}
+	return $arr;
+}
+
+/**
+ * Gets html to display an email address given a public an private key.
+ * to get a key, go to:
+ *
+ * http://mailhide.recaptcha.net/apikey
+ */
+function recaptcha_mailhide_html($pubkey, $privkey, $email) {
+	$emailparts = _recaptcha_mailhide_email_parts ($email);
+	$url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
+	
+	return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
+		"' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
+
+}
+
+
+?>

Added: plugins/branches/lifetype-1.2/recaptcha/locale/locale_de_DE.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/locale/locale_de_DE.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/locale/locale_de_DE.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,21 @@
+<?php
+$messages["plugin_recaptcha"] = "reCAPTCHA";
+$messages["recaptcha_captcha_wrong"] = "Das Captcha war falsch."; 
+$messages["recaptcha_plugin_enabled"] = "Dieses Plugin aktivieren";
+$messages["recaptcha_privatekey"] 	= "Privater ReCaptcha-Schlüssel (private key)";
+$messages["recaptcha_pubkey"] 	 	= "&Ouml;ffentlicher ReCaptcha-Schl&uuml;ssel (public key)";
+$messages["recaptcha_type_code"] = "Bitte Captcha l&ouml;sen (erforderlich)";
+
+$messages["label_configuration"] = "Konfiguration";
+$messages["label_enable"]  = "Aktivieren";
+$messages["label_pubkey"]  = "Privater ReCaptcha-Schl&uuml;ssel";
+$messages["label_privkey"] = "&Ouml;ffentlicher ReCaptcha-Schl&uuml;ssel";
+
+$messages["recaptcha_error_key"] = "Fehler: &Ouml;ffentlicher oder Privater Schl&uuml;ssel nicht konfiguriert.";
+
+$messages["recaptcha_settings_saved_ok"] = "ReCaptcha Einstellungen erfolgreich gespeichert.";
+
+
+$messages["manageAntiSpamPlugins"] = "Anti Spam Management";
+
+?>

Added: plugins/branches/lifetype-1.2/recaptcha/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/locale/locale_en_UK.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/locale/locale_en_UK.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,21 @@
+<?php
+$messages["plugin_recaptcha"] = "reCAPTCHA";
+$messages["recaptcha_captcha_wrong"] = "The captcha you have entered is wrong."; 
+$messages["recaptcha_plugin_enabled"] = "Enable this plugin";
+$messages["recaptcha_privatekey"] 	= "Your ReCaptcha private key.";
+$messages["recaptcha_pubkey"] 	 	= "Your ReCaptcha public key";
+$messages["recaptcha_type_code"] = "Please solve the puzzle (required)";
+
+$messages["label_configuration"] = "Configuration";
+$messages["label_enable"]  = "Enable";
+$messages["label_pubkey"]  = "ReCaptcha Public Key";
+$messages["label_privkey"] = "ReCaptcha Private Key";
+
+$messages["recaptcha_error_key"] = "Error: Public and Private Key must be set.";
+
+$messages["recaptcha_settings_saved_ok"] = "ReCaptcha Settings saved successfully.";
+
+/* alt starts here: */
+$messages["manageAntiSpamPlugins"] = "Anti Spam Management";
+
+?>

Added: plugins/branches/lifetype-1.2/recaptcha/pluginrecaptcha.class.php
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/pluginrecaptcha.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/pluginrecaptcha.class.php	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,97 @@
+<?php
+
+    /*   Copyright 2007 Tobias Frost <tobi at coldtobi.de> http://blog.coldtobi.de
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    */
+
+	lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+
+	require_once(PLOG_CLASS_PATH."plugins/recaptcha/library/recaptchalib.php");
+
+	class PluginRecaptcha extends PluginBase
+	{
+		var $pluginEnabled;
+		var $PubKey;
+		var $PrivKey; 
+ 	
+		function PluginReCaptcha( $source = "" )
+		{
+			$this->PluginBase($source);
+
+			$this->id      = "recaptcha";
+			$this->desc    = "This plugin implements the recaptcha captcha generation. See http://recaptcha.net/ for details and how to obtain the API Key.";
+			$this->author  = "Tobias Frost";
+			$this->locales = Array( "en_UK","de" );
+            		$this->version = "20071102";
+
+
+			if( $source == "admin" )
+				$this->initAdmin();
+			else
+				$this->init();
+		}
+
+		function init()
+		{
+			lt_include(PLOG_CLASS_PATH."plugins/recaptcha/class/security/recaptchafilter.class.php"); 
+			$this->registerFilter( "ReCaptchaFilter" ); 
+		}
+
+		function initAdmin()
+		{
+			$this->init();
+			
+			$this->registerAdminAction( "recaptcha", "PluginRecaptchaConfigAction" ); // TODO ACTION
+			$this->registerAdminAction( "updateRecaptchaConfig", "PluginRecaptchaUpdateConfigAction" ); // TODO CONFIG
+			
+			$menu =& Menu::getMenu();
+			if( !$menu->entryExists( "/menu/controlCenter/manageAntiSpamPlugins" ))
+				$this->addMenuEntry( "/menu/controlCenter", "manageAntiSpamPlugins", "", "", true, false );
+				$this->addMenuEntry( "/menu/controlCenter/manageAntiSpamPlugins", "plugin_recaptcha", "?op=recaptcha", "" ); 
+		}
+	
+		function register()
+		{
+			$blogSettings 		= $this->blogInfo->getSettings();
+			$this->pluginEnabled 	= $blogSettings->getValue( "plugin_recaptcha_enabled" );
+			$this->PubKey 	     	= $blogSettings->getValue( "plugin_recaptcha_pubkey" );
+			$this->PrivKey 		= $blogSettings->getValue( "plugin_recaptcha_privkey" );
+		}
+			
+		function show() {
+	                $result = recaptcha_get_html ($this->PubKey) . "<p style=\"font-size:6pt;padding-left:2em;width:500px;\">&nbsp;<a href=\"http://blog.coldtobi.de\">This is the ReCaptcha Plugin for Lifetype </a></p>";
+			return $result;
+		}
+
+		function isEnabled()
+		{
+			return $this->pluginEnabled;
+		}
+	
+		function getPluginConfigurationKeys()
+		{
+			lt_include(PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php");
+			lt_include(PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php");
+
+			return( Array(
+				Array( "name" => "plugin_recaptcha_enabled", "type" => "boolean" ),
+				Array( "name" => "plugin_recaptcha_privkey", "validator" => new
+StringValidator(),  "type" => "string", "allowEmpty" => true ),
+				Array( "name" => "plugin_recaptcha_pubkey", "validator" => new StringValidator(), "type" => 	"string", "allowEmpty" => true )));
+		}
+
+}
+?>

Added: plugins/branches/lifetype-1.2/recaptcha/readme.txt
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/readme.txt	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/readme.txt	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,93 @@
+Plugin: ReCaptcha
+Author: Tobias Frost (blog.coldtobi.de)
+Release Date: 2007/11/02
+Version: 20071102
+
+
+
+LICENSE
+========
+
+Recaptcha Library (folder recaptcha/library)
+
+The recaptcha library redistributed in this packages is not by me, and has its 
+own LICENSE file. Please read it carefully. The library also be downloaded at
+http://recaptcha.net/plugins/php/
+
+ReCaptcha Plugin
+The plugin is licensed under the GPL v2. See the file copyright for details.
+
+ABSTRACT
+=========
+
+This plugin implements the ReCaptcha Captcha authentification. 
+
+Recaptcha is like regular captchas, but in contrast to regular captchas
+these are from scanned books and they already failed being recognized by 
+a OCR, so according to the authors of recaptcha this method is far more
+effecive than "regular" captcha.
+For details on  ReCaptcha, please visit http://recaptcha.net.
+
+
+WARNING
+=======
+
+I am not a php programmer. I have strong programming knowledge, but I do not
+really know php. There could be security issues in the code, so please make
+sure to check the code for safety and give me feedback on any findings.
+
+RECAPTCHA API KEY
+=================
+
+You can obtain your recaptcha API Keys from recaptcha.org. Please note that it is only
+good for one domain including all subdomains.
+
+If you host serveral blogs on different domains, you might want to let the blog owners 
+enter their codes individually, and do not enter anything in the Administration Settings.
+
+WARNING: If the code is entered in the Admin section, all blog users can see it! I still have to
+figure out how to avoid it. Please mail me hints/patches.
+
+
+MOTIVIATION, FEEDBACK
+=====================
+Some time ago, I stumbled upon recaptcha. 
+(Story http://blog.coldtobi.de/1_coldtobis_blog/archive/89_recaptcha_--_stop_spam_read_books.html)
+However, as lifetype currently does not have a well performing captcha plugin,
+leading to a lots of automated spam, I decided to implement this. 
+
+Please send me your feedback using my blog or mail me at tobi at coldtobi.de.
+
+You will probably notice, that I placed a link to my blog at the bottom of the 
+captcha. If you like the plugin, I ask you let it intact.
+
+
+SETUP & CONFIGURATION
+=====================
+
+In order to employ the plugin, do the following
+1. Obtain your API Key at recaptcha.net
+2. Unzip the zip-file 
+3. Configure the plugin with the keys. (See section "Rechapta API Key" for details")
+4. Add the code to the commentform.template:
+
+    { ** Plugin_Recaptcha Code start. ** }
+    { ** VERSION plugin_recaptcha 1.00 ** }
+    {if $recaptcha && $recaptcha->isEnabled()}
+        <div>
+            <label for="recaptcha">{$locale->tr("recaptcha_type_code")}</label>
+            <div style="float:left" id=recaptcha>
+                {$recaptcha->show()}
+            </div>
+            <div style="clear:left"></div>
+        </div>
+    {/if}
+    { ** Plugin_Recaptcha Code end  ** }
+
+
+
+
+
+
+
+

Added: plugins/branches/lifetype-1.2/recaptcha/templates/recaptcha.template
===================================================================
--- plugins/branches/lifetype-1.2/recaptcha/templates/recaptcha.template	                        (rev 0)
+++ plugins/branches/lifetype-1.2/recaptcha/templates/recaptcha.template	2007-11-10 21:26:32 UTC (rev 6032)
@@ -0,0 +1,40 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=plugin_recaptcha title=$locale->tr("plugin_recaptcha")}
+
+<form name="recaptchapluginConfig" 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>
+   <div class="formHelp">
+     <input class="checkbox" type="checkbox" name="pluginEnabled" id="pluginEnabled" {if $pluginEnabled}checked="checked"{/if} value="1" {user_cannot_override key=plugin_recaptcha_enabled}disabled="disabled"{/user_cannot_override} />{$locale->tr("recaptcha_plugin_enabled")}
+   </div>
+  </div> 
+
+  <div class="field">
+   <label for="label_pubkey">{$locale->tr("label_pubkey")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("recaptcha_pubkey")}</div>
+   <input class="text" type="text" name="PubKey" id="PubKey" value="{$PubKey}" {user_cannot_override key=plugin_recaptcha_pubkey}readonly="readonly"{/user_cannot_override} />
+  </div>
+
+  <div class="field">
+   <label for="label_privkey">{$locale->tr("label_privkey")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("recaptcha_privatekey")}</div>
+   <input class="text" type="text" name="PrivKey" id="PrivKey" value="{$PrivKey}" {user_cannot_override key=plugin_recaptcha_privkey}readonly="readonly"{/user_cannot_override} />
+  </div>
+
+ </fieldset>
+  
+ <div class="buttons">
+  <input type="hidden" name="op" value="updateRecaptchaConfig" />
+  <input type="reset" name="{$locale->tr("reset")}" />
+  <input type="submit" name="{$locale->tr("settings")}" value="{$locale->tr("update")}" />
+ </div>
+</form>
+
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}



More information about the pLog-svn mailing list