[pLog-svn] r5633 - in plog/branches/lifetype-1.2/class: action data/filter

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Mon Jul 9 16:53:15 EDT 2007


Author: jondaley
Date: 2007-07-09 16:53:15 -0400 (Mon, 09 Jul 2007)
New Revision: 5633

Added:
   plog/branches/lifetype-1.2/class/data/filter/urlconverter.class.php
Modified:
   plog/branches/lifetype-1.2/class/action/addcommentaction.class.php
Log:
add a new type of 'filter', a converter that doesn't just filter the data, but adds stuff to it - this fixes the issue where if you inserted a URL when leaving a comment and didn't add the http:// the comment would be rejected.  I had a couple people complain about this.

Modified: plog/branches/lifetype-1.2/class/action/addcommentaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/addcommentaction.class.php	2007-07-08 13:02:40 UTC (rev 5632)
+++ plog/branches/lifetype-1.2/class/action/addcommentaction.class.php	2007-07-09 20:53:15 UTC (rev 5633)
@@ -11,6 +11,7 @@
     lt_include( PLOG_CLASS_PATH."class/data/validator/httpurlvalidator.class.php" );    
     lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/filter/htmlfilter.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/filter/urlconverter.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/filter/allowedhtmlfilter.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/filter/xhtmlizefilter.class.php" );
     lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
@@ -47,9 +48,14 @@
 			// input filters
 			$f = new HtmlFilter();
 			$this->_request->registerFilter( "userEmail", $f );
-			$this->_request->registerFilter( "userUrl", $f );
 			$this->_request->registerFilter( "userName", $f );
 			$this->_request->registerFilter( "commentTopic", $f );
+
+                // userUrl is a regular HTML filter, in addition to
+                // being forced to look like a URL
+			$f->addFilter( new UrlConverter());
+			$this->_request->registerFilter( "userUrl", $f );
+
 			$f = new AllowedHtmlFilter();
 			$f->addFilter( new XhtmlizeFilter());			
 			$this->_request->registerFilter( "commentText", $f );			
@@ -90,10 +96,6 @@
                 $this->_parentId = 0;
             $this->_userEmail = $this->_request->getValue( "userEmail" );
             $this->_userUrl   = $this->_request->getValue( "userUrl" );
-            if( (strlen($this->_userUrl) != 0) &&
-                  ereg('^https{0,1}://',$this->_userUrl) == false){
-                $this->_userUrl = "http://".$this->_userUrl;
-            }
             $this->_userName  = $this->_request->getValue( "userName" );
             $this->_commentText = trim($this->_request->getValue( "commentText" ));
             $this->_commentTopic = $this->_request->getValue( "commentTopic" );

Copied: plog/branches/lifetype-1.2/class/data/filter/urlconverter.class.php (from rev 5626, plog/branches/lifetype-1.2/class/data/filter/htmlfilter.class.php)
===================================================================
--- plog/branches/lifetype-1.2/class/data/filter/urlconverter.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.2/class/data/filter/urlconverter.class.php	2007-07-09 20:53:15 UTC (rev 5633)
@@ -0,0 +1,36 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/data/filter/filterbase.class.php" );
+
+	/**
+	 * \ingroup Filter	
+	 *
+	 * This class extends the FilterBase interface to force the
+     * given string to be a proper URL.     
+	 */
+	class UrlConverter extends FilterBase
+	{
+		/**
+		 * Constructor
+		 */
+		function UrlConverter()
+        {
+			$this->FilterBase();
+		}
+		
+		/**
+		 * Forces a given string to look at least sort of like a URL
+         *   currently all it does is prepend http:// if it isn't there.
+		 *
+		 * @param data
+		 * @return The input string with http:// prepended
+		 */
+		function filter( $data )
+		{
+            if((strlen($data) != 0) && ereg('^https?://', $data) == false){
+                $data = "http://" . $data;
+            }
+			return(parent::filter($data));
+		}	
+	}
+?>
\ No newline at end of file



More information about the pLog-svn mailing list