[pLog-svn] r958 - in plog/trunk: . class/summary/action class/summary/data class/summary/data/validator

oscar at devel.plogworld.net oscar at devel.plogworld.net
Sun Feb 6 13:06:33 GMT 2005


Author: oscar
Date: 2005-02-06 13:06:32 +0000 (Sun, 06 Feb 2005)
New Revision: 958

Added:
   plog/trunk/class/summary/action/summarycustompageaction.class.php
   plog/trunk/class/summary/data/validator/
   plog/trunk/class/summary/data/validator/customsummarypagevalidator.class.php
Removed:
   plog/trunk/class/summary/action/faqaction.class.php
Modified:
   plog/trunk/summary.php
Log:
now it is possible to specify custom pages in the summary via the url ?op=display&page=xxx, where 'xxx' is the name of the page which should be found under templates/summary/xxx.template.

This action will check the following things before displaying the page:

1) that the "page" parameter is a valid string
2) that it contains only letters, numbers or the characters '-' and '_'
3) that the name of the page is not the name of one of the default pages such as 'index', 'recent' or similar, so that we don't get weird smarty errors
4) that the file exists and it can be read

If the checks above return false, it will display the main page of the summary instead of an error.

Deleted: plog/trunk/class/summary/action/faqaction.class.php
===================================================================
--- plog/trunk/class/summary/action/faqaction.class.php	2005-02-06 01:23:31 UTC (rev 957)
+++ plog/trunk/class/summary/action/faqaction.class.php	2005-02-06 13:06:32 UTC (rev 958)
@@ -1,32 +0,0 @@
-<?php
-
-	include_once( PLOG_CLASS_PATH."class/summary/action/summaryaction.class.php" );
-
-     class FaqAction extends SummaryAction
-     {
-        var $_locale;
-
-        function FaqAction( $actionInfo, $request )
-        {
-            $this->SummaryAction( $actionInfo, $request );
-        }
-
-        /**
-         * Loads the posts and shows them.
-         */
-        function perform()
-        {
-            $show = $this->_request->getValue( "show" );
-
-            if (!$show)
-            {
-                $show = "faq";
-            }
-
-            $this->_view = new SummaryCachedView( $show, Array( "summary" => "faq" ));
-            $this->_view->setValue( "locale", $this->_locale );
-
-            return true;
-        }
-     }
-?>
\ No newline at end of file

Added: plog/trunk/class/summary/action/summarycustompageaction.class.php
===================================================================
--- plog/trunk/class/summary/action/summarycustompageaction.class.php	2005-02-06 01:23:31 UTC (rev 957)
+++ plog/trunk/class/summary/action/summarycustompageaction.class.php	2005-02-06 13:06:32 UTC (rev 958)
@@ -0,0 +1,39 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/summary/action/summaryaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/summary/view/summarycachedview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/summary/data/validator/customsummarypagevalidator.class.php" );
+
+	/**
+	 * displays custom pages in the summary.php, in case users would like
+	 * to add something extra to the whole set of pages
+	 *
+	 * It will check whether the page requested is one of the default ones and in that
+	 * case, it will *not* show it. It will also perform some sanity checks on the file
+	 * name.
+	 */
+	class SummaryCustomPageAction extends SummaryAction
+	{
+	
+		var $_page;
+		
+		function perform()
+		{
+			$this->_page = $this->_request->getValue( "page" );
+			
+			$val = new CustomSummaryPageValidator();
+			if( !$val->validate( $this->_page )) {
+				// instead of showing an ugly smarty error, let's forward processing
+				// to the default action so that at least we can show something!
+				SummaryController::setForwardAction( "Default" );
+			}
+			else {
+				// let's cache the page... After all, we're not expecting much dynamic context in here!
+				$this->_view = new SummaryCachedView( $this->_page, Array( "page" => $this->_page ));
+				$this->setCommonData();
+			}
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Added: plog/trunk/class/summary/data/validator/customsummarypagevalidator.class.php
===================================================================
--- plog/trunk/class/summary/data/validator/customsummarypagevalidator.class.php	2005-02-06 01:23:31 UTC (rev 957)
+++ plog/trunk/class/summary/data/validator/customsummarypagevalidator.class.php	2005-02-06 13:06:32 UTC (rev 958)
@@ -0,0 +1,70 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/data/validator/validator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );	
+	include_once( PLOG_CLASS_PATH."class/data/validator/rules/regexprule.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/rules/filteredwordsrule.class.php" );
+	include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+
+	/**
+	 * custom summary page validator that does:
+	 *
+	 * 1) check whether the page is a valid string
+	 * 2) whether it has the correct characters
+	 * 3) whether the page exists under templates/summary/ and it is readable
+	 *
+	 * If all the checks above are successful, it will return true
+	 */
+	class CustomSummaryPageValidator extends Validator
+	{
+	
+		function CustomSummaryPageValidator()
+		{
+			// check that the page has the right characters
+			$this->addRule( new RegExpRule( "[A-Za-z0-9\-_]" ));
+			// and that it is a string at all
+			$this->addValidator( new StringValidator());
+			// and that it is not any of the default templates...
+			$this->addRule( new FilteredWordsRule( Array( "summaryerror",
+			                                              "agreement",
+														  "email_confirm",
+														  "registerfinished",
+														  "registerstep0",
+														  "registerstep1",
+														  "registerstep2",
+														  "registerstep3",
+														  "registerstep4",
+														  "registerstep5",
+														  "blogprofile",
+														  "formvalidate",
+														  "pager",
+														  "userlist",
+														  "userprofile",
+														  "validate",
+														  "changepassword",
+														  "message",
+														  "resetpassword",
+														  "resetpasswordemail",
+														  "searchresults",
+														  "bloglist",
+														  "index",
+														  "recent",
+														  "registererror",
+														  "footer",
+														  "header",
+														  "summary" )));														
+		}
+		
+		function validate( $data )
+		{
+			// check the rules created in the constructor
+			if( !parent::validate( $data ))
+				return false;
+				
+			// and if they succeeded, check if the file exists. If not, return false
+			// and go to the main page...
+			$filePath = "templates/summary/$data.template";
+			return( File::isReadable( $filePath ));
+		}		
+	}
+?>
\ No newline at end of file

Modified: plog/trunk/summary.php
===================================================================
--- plog/trunk/summary.php	2005-02-06 01:23:31 UTC (rev 957)
+++ plog/trunk/summary.php	2005-02-06 13:06:32 UTC (rev 958)
@@ -69,6 +69,7 @@
 	$_actionMap["rss"] = "SummaryRssAction";
 	$_actionMap["summarySearch"] = "SummarySearchAction";
 	$_actionMap["activeAccount"] = "ActiveAccountAction";
+	$_actionMap["display"] = "SummaryCustomPageAction";
 
     //// main part ////
     $controller = new SummaryController();




More information about the pLog-svn mailing list