[pLog-svn] r5472 - in plog/branches/lifetype-1.2/class: action data/filter
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Thu May 31 17:07:51 EDT 2007
Author: oscar
Date: 2007-05-31 17:07:51 -0400 (Thu, 31 May 2007)
New Revision: 5472
Added:
plog/branches/lifetype-1.2/class/data/filter/allowedhtmlfilter.class.php
plog/branches/lifetype-1.2/class/data/filter/xhtmlizefilter.class.php
Modified:
plog/branches/lifetype-1.2/class/action/addcommentaction.class.php
Log:
Modified AddCommentAction to use input filters, which I think makes the code a little bit cleaner (in my opinion)
Modified: plog/branches/lifetype-1.2/class/action/addcommentaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/addcommentaction.class.php 2007-05-31 20:48:19 UTC (rev 5471)
+++ plog/branches/lifetype-1.2/class/action/addcommentaction.class.php 2007-05-31 21:07:51 UTC (rev 5472)
@@ -10,6 +10,9 @@
lt_include( PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );
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/allowedhtmlfilter.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/filter/xhtmlizefilter.class.php" );
lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
lt_include( PLOG_CLASS_PATH."class/view/redirectview.class.php" );
lt_include( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
@@ -40,7 +43,18 @@
function AddCommentAction( $blogInfo, $request )
{
$this->BlogAction( $blogInfo, $request );
-
+
+ // input filters
+ $f = new HtmlFilter( true );
+ $this->_request->registerFilter( "userEmail", $f );
+ $this->_request->registerFilter( "userUrl", $f );
+ $this->_request->registerFilter( "userName", $f );
+ $this->_request->registerFilter( "commentTopic", $f );
+ $f = new AllowedHtmlFilter();
+ $f->addFilter( new HtmlEntitiesFilter());
+ $f->addFilter( new XhtmlizeFilter());
+ $this->_request->registerFilter( "commentText", $f );
+
// change the validation mode of the form
$this->registerFieldValidator( "articleId", new IntegerValidator());
$this->_form->setFieldErrorMessage( "articleId", $this->_locale->tr("error_incorrect_article_id" ));
@@ -67,26 +81,27 @@
{
lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+ $f = new HtmlFilter( true );
+
$this->_articleId = $this->_request->getValue( "articleId" );
$this->_blogId = $this->_request->getValue( "blogId" );
$this->_opId = $this->_request->getValue( "op" );
$this->_parentId = $this->_request->getValue( "parentId" );
if( $this->_parentId == null || $this->_parentId == "" )
$this->_parentId = 0;
- $this->_userEmail = Textfilter::filterAllHTML($this->_request->getValue( "userEmail" ));
- $this->_userUrl = Textfilter::filterAllHTML($this->_request->getValue( "userUrl" ));
+ $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 = Textfilter::filterAllHTML($this->_request->getValue( "userName" ));
+ $this->_userName = $this->_request->getValue( "userName" );
$this->_commentText = trim($this->_request->getValue( "commentText" ));
- $this->_commentTopic = Textfilter::filterAllHTML($this->_request->getValue( "commentTopic" ));
- // remove all weird stuff from the comment text
- $tf = new TextFilter();
- $this->_commentText = $tf->xhtmlize($tf->filterHTML( $this->_commentText ));
+ $this->_commentTopic = $this->_request->getValue( "commentTopic" );
+
// now, if the option is set, we 'beautify' the text typed by users
if( $this->_config->getValue( "beautify_comments_text" )) {
+ $tf = new TextFilter();
$this->_commentText = $tf->autop($this->_commentText);
}
}
Added: plog/branches/lifetype-1.2/class/data/filter/allowedhtmlfilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/filter/allowedhtmlfilter.class.php (rev 0)
+++ plog/branches/lifetype-1.2/class/data/filter/allowedhtmlfilter.class.php 2007-05-31 21:07:51 UTC (rev 5472)
@@ -0,0 +1,26 @@
+<?php
+
+ lt_include( PLOG_CLASS_PATH."class/data/filter/filterbase.class.php" );
+
+ /**
+ * \ingroup Filter
+ *
+ * This class extends the FilterBase interface to filter all HTML
+ * code in the given string except the allowed tags
+ */
+ class AllowedHtmlFilter extends FilterBase
+ {
+ /**
+ * Filters out all HTML code except the allowed tags
+ *
+ * @param data
+ * @return The input string without HTML code
+ */
+ function filter( $data )
+ {
+ lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+ $tf = new Textfilter();
+ return( parent::filter( $tf->filterHTML( $data )));
+ }
+ }
+?>
\ No newline at end of file
Added: plog/branches/lifetype-1.2/class/data/filter/xhtmlizefilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/filter/xhtmlizefilter.class.php (rev 0)
+++ plog/branches/lifetype-1.2/class/data/filter/xhtmlizefilter.class.php 2007-05-31 21:07:51 UTC (rev 5472)
@@ -0,0 +1,26 @@
+<?php
+
+ lt_include( PLOG_CLASS_PATH."class/data/filter/filterbase.class.php" );
+
+ /**
+ * \ingroup Filter
+ *
+ * This class extends the FilterBase interface to try to "fix"
+ * and upconvert HTML strings to XHTML
+ */
+ class XhtmlizeFilter extends FilterBase
+ {
+ /**
+ * Filters out all HTML code except the allowed tags
+ *
+ * @param data
+ * @return The input string converted to XHTML
+ */
+ function filter( $data )
+ {
+ lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+ $t = new Textfilter();
+ return( parent::filter( $t->xhtmlize( $data )));
+ }
+ }
+?>
\ No newline at end of file
More information about the pLog-svn
mailing list