[pLog-svn] r5847 - in plog/trunk/class: action/admin template/editor

oscar at devel.lifetype.net oscar at devel.lifetype.net
Mon Aug 20 16:01:47 EDT 2007


Author: oscar
Date: 2007-08-20 16:01:47 -0400 (Mon, 20 Aug 2007)
New Revision: 5847

Added:
   plog/trunk/class/action/admin/adminbasetemplateeditoraction.class.php
Modified:
   plog/trunk/class/action/admin/adminaddtemplatefolderaction.class.php
   plog/trunk/class/action/admin/admincopytemplatefileaction.class.php
   plog/trunk/class/action/admin/admincopytemplatesetaction.class.php
   plog/trunk/class/action/admin/admindeletetemplatefileaction.class.php
   plog/trunk/class/action/admin/adminedittemplateaction.class.php
   plog/trunk/class/action/admin/adminedittemplatefileaction.class.php
   plog/trunk/class/action/admin/adminupdatetemplatefileaction.class.php
   plog/trunk/class/template/editor/templatetools.class.php
Log:
Refactored the code for the template editor a bit, and all common code has now been moved to its own class.


Modified: plog/trunk/class/action/admin/adminaddtemplatefolderaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminaddtemplatefolderaction.class.php	2007-08-20 20:01:06 UTC (rev 5846)
+++ plog/trunk/class/action/admin/adminaddtemplatefolderaction.class.php	2007-08-20 20:01:47 UTC (rev 5847)
@@ -1,6 +1,6 @@
 <?php
 
-	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminbasetemplateeditoraction.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );		
 	lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );		
@@ -9,17 +9,17 @@
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminsitetemplateslistview.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminerrordialogview.class.php" );
 	
-	class AdminAddTemplateFolderAction extends AdminAction
+	class AdminAddTemplateFolderAction extends AdminBaseTemplateEditorAction
 	{
 		function __construct( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->AdminBaseTemplateEditorAction( $actionInfo, $request );
 			
 			$this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
 			$this->registerFieldValidator( "path", new StringValidator(), true );
 			$this->registerFieldValidator( "folderName", new StringValidator(), true );
 			$view = new AdminSiteTemplatesListView( $this->_blogInfo );
-			$view->setErrorMessage( $this->_locale->tr( "error_loading_template" ));
+			$view->setErrorMessage( $this->_locale->tr( "error_loading_template_set" ));
 			$this->setValidationErrorView( $view );
 
 			$this->requireAdminPermission( "edit_global_templates" );
@@ -27,32 +27,12 @@
 		
 		function validate()
 		{
-			if( !parent::validate()) 
-				return false;
-
-			// check that the template really exists
-			$this->_templateId = $this->_request->getFilteredValue( "templateId", new RegexpFilter( "/[^A-Za-z0-9_]/" ));
-			if( !TemplateSets::isTemplate( $this->_templateId )) {
-				$this->_form->setFieldValidationStatus( "templateId", false );
-				$this->validationErrorProcessing();
-				return( false );
-			}
-
-			// if the template exists, check that the path exists too
-			$this->_path = $this->_request->getFilteredValue( "path", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
-			if( !TemplateTools::isValidTemplatePath( $this->_templateId, $this->_path )) {
-				$this->_form->setFieldValidationStatus( "path", false );
-				$this->validationErrorProcessing();
-				return( false );				
-			}
-
-			// otherwise everything is peachy
-			return( true );
+			return( parent::validate( Array( "templateId", "path" )));
 		}
 		
 		function createFolder()
 		{
-			$folderName = $this->_request->getFilteredValue( "folderName", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
+			$folderName = $this->_request->getFilteredValue( "folderName", TemplateTools::getTemplateNameFilter());
 			$folder = TemplateSetStorage::getTemplateFolder( $this->_templateId) . "/" . $this->_path . "/" . $folderName;
 			
 			return( File::createDir( $folder, File::FILE_DEFAULT_DIRECTORY_CREATION_MODE, false ));

Added: plog/trunk/class/action/admin/adminbasetemplateeditoraction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminbasetemplateeditoraction.class.php	                        (rev 0)
+++ plog/trunk/class/action/admin/adminbasetemplateeditoraction.class.php	2007-08-20 20:01:47 UTC (rev 5847)
@@ -0,0 +1,96 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );	
+
+	/**
+	 * \ingroup Action
+	 *
+	 * This is a base abstract class that all methods that are part of the 
+	 * template editor extend. This class simply provides a few convenience methods
+	 * for a bunch of operations and validations that are repeatedly performed
+	 * in all classes that implement the template editor.
+	 *
+	 * Outside of the template editor this class has no use.
+	 */
+	abstract class AdminBaseTemplateEditorAction extends AdminAction
+	{
+		protected $blogId;
+		
+		const GLOBAL_BLOG_ID = 0;
+		
+		function AdminBaseTemplateEditorAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+			
+			// by default we're dealing with global templates
+			$this->blogId = 0;
+		}
+		
+		function validateTemplateName()
+		{
+			// check that the template really exists
+			$this->_templateId = $this->_request->getFilteredValue( "templateId", TemplateTools::getTemplateNameFilter());
+			
+			if( $this->blogId == AdminBaseTemplateEditorAction::GLOBAL_BLOG_ID )				
+				$result = TemplateSets::isTemplate( $this->_templateId );
+			else
+				$result = TemplateSets::isBlogTemplate( $this->_templateId, $this->blogId );
+				
+			if( !$result ) {
+				$this->_form->setFieldValidationStatus( "templateId", false );
+				$this->validationErrorProcessing();
+				return( false );
+			}
+			
+			return( true );			
+		}
+		
+		function validateTemplatePath()
+		{
+			$this->_path = $this->_request->getFilteredValue( "path", TemplateTools::getTemplatePathFilter());
+			if( !TemplateTools::isValidTemplatePath( $this->_templateId, $this->_path, $this->blogId )) {
+				$this->_form->setFieldValidationStatus( "path", false );
+				$this->validationErrorProcessing();
+				return( false );				
+			}
+			
+			return( true );			
+		}
+		
+		function validateTemplateFileName()
+		{
+			$this->_file = $this->_request->getFilteredValue( "file", TemplateTools::getTemplateFileNameFilter());
+			if( !TemplateTools::isValidTemplateFile( $this->_templateId, $this->_path, $this->_file, $this->blogId ) ||
+			    !TemplateTools::isEditable( $this->_file )) {
+				$this->_form->setFieldValidationStatus( "file", false );
+				$this->validationErrorProcessing();
+				return( false );				
+			}
+			
+			return( true );			
+		}
+		
+		function validate( Array $fields )
+		{
+			if( !parent::validate())
+				return( false );
+			
+			if( in_array( "templateId", $fields )) {
+				if( !$this->validateTemplateName())
+					return( false );
+			}
+			
+			if( in_array( "path", $fields )) {
+				if( !$this->validateTemplatePath())
+					return( false );				
+			}
+			
+			if( in_array( "file", $fields )) {
+				if( !$this->validateTemplateFileName())
+					return( false );
+			}
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/trunk/class/action/admin/admincopytemplatefileaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincopytemplatefileaction.class.php	2007-08-20 20:01:06 UTC (rev 5846)
+++ plog/trunk/class/action/admin/admincopytemplatefileaction.class.php	2007-08-20 20:01:47 UTC (rev 5847)
@@ -1,6 +1,6 @@
 <?php
 
-	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminbasetemplateeditoraction.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );		
 	lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );		
@@ -9,14 +9,14 @@
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminsitetemplateslistview.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminerrordialogview.class.php" );
 	
-	class AdminCopyTemplateFileAction extends AdminAction
+	class AdminCopyTemplateFileAction extends AdminBaseTemplateEditorAction
 	{
-		var $_template;
-		var $_path;
+		protected $_template;
+		protected $_path;
 		
 		function __construct( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->AdminBaseTemplateEditorAction( $actionInfo, $request );
 			
 			$this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
 			$this->registerFieldValidator( "path", new StringValidator(), true );
@@ -31,33 +31,13 @@
 		
 		function validate()
 		{
-			if( !parent::validate()) 
-				return false;
-
-			// check that the template really exists
-			$this->_templateId = $this->_request->getFilteredValue( "templateId", new RegexpFilter( "/[^A-Za-z0-9_]/" ));
-			if( !TemplateSets::isTemplate( $this->_templateId )) {
-				$this->_form->setFieldValidationStatus( "templateId", false );
-				$this->validationErrorProcessing();
-				return( false );
-			}
-
-			// if the template exists, check that the path exists too
-			$this->_path = $this->_request->getFilteredValue( "path", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
-			if( !TemplateTools::isValidTemplatePath( $this->_templateId, $this->_path )) {
-				$this->_form->setFieldValidationStatus( "path", false );
-				$this->validationErrorProcessing();
-				return( false );				
-			}
-
-			// otherwise everything is peachy
-			return( true );
+			return( parent::validate( Array( "templateId", "path" )));
 		}
 		
 		function createFolder()
 		{
-			$sourceFileName = $this->_request->getFilteredValue( "sourceFileName", new RegexpFilter( "/[^A-Za-z0-9_\/\-\.]/" ));
-			$destFileName = $this->_request->getFilteredValue( "destFileName", new RegexpFilter( "/[^A-Za-z0-9_\/\-\.]/" ));
+			$sourceFileName = $this->_request->getFilteredValue( "sourceFileName", TemplateTools::getTemplatePathFilter());
+			$destFileName = $this->_request->getFilteredValue( "destFileName", TemplateTools::getTemplateFileNameFilter());
 			
 			// clean up all ".." and just leave ".", to avoid potential relative path attacks
 			$sourceFileName = preg_replace( "/\.+/", ".", $sourceFileName );

Modified: plog/trunk/class/action/admin/admincopytemplatesetaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincopytemplatesetaction.class.php	2007-08-20 20:01:06 UTC (rev 5846)
+++ plog/trunk/class/action/admin/admincopytemplatesetaction.class.php	2007-08-20 20:01:47 UTC (rev 5847)
@@ -1,6 +1,6 @@
 <?php
 
-	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminbasetemplateeditoraction.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );		
 	lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );		
@@ -9,14 +9,14 @@
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminsitetemplateslistview.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminerrordialogview.class.php" );
 	
-	class AdminCopyTemplateSetAction extends AdminAction
+	class AdminCopyTemplateSetAction extends AdminBaseTemplateEditorAction
 	{
-		var $_templateId;
-		var $_destTemplate;
+		protected $_templateId;
+		protected $_destTemplate;
 		
 		function __construct( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->AdminBaseTemplateEditorAction( $actionInfo, $request );
 			
 			$this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
 			$this->registerFieldValidator( "destTemplate", new StringValidator(), true );			
@@ -32,16 +32,11 @@
 			if( !parent::validate()) 
 				return false;
 
-			// check that the template really exists
-			$this->_templateId = $this->_request->getFilteredValue( "templateId", new RegexpFilter( "/[^A-Za-z0-9_\-]/" ));
-			if( !TemplateSets::isTemplate( $this->_templateId )) {
-				$this->_form->setFieldValidationStatus( "templateId", false );
-				$this->validationErrorProcessing();
+			if( !$this->validateTemplateName())
 				return( false );
-			}
 
 			// check that the destination template does not exist
-			$this->_destTemplate = $this->_request->getFilteredValue( "destTemplate", new RegexpFilter( "/[^A-Za-z0-9_\-]/" ));
+			$this->_destTemplate = $this->_request->getFilteredValue( "destTemplate", TemplateTools::getTemplateNameFilter());
 			if( TemplateSets::isTemplate( $this->_destTemplate )) {
 				// show a more specific error message
 				$this->_validationErrorView->setErrorMessage( $this->_locale->tr( "error_template_set_already_exists" ));

Modified: plog/trunk/class/action/admin/admindeletetemplatefileaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admindeletetemplatefileaction.class.php	2007-08-20 20:01:06 UTC (rev 5846)
+++ plog/trunk/class/action/admin/admindeletetemplatefileaction.class.php	2007-08-20 20:01:47 UTC (rev 5847)
@@ -1,6 +1,6 @@
 <?php
 
-	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminbasetemplateeditoraction.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );		
 	lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );		
@@ -11,12 +11,13 @@
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminerrordialogview.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/file/file.class.php" );
 	
-	class AdminDeleteTemplateFileAction extends AdminAction
+	class AdminDeleteTemplateFileAction extends AdminBaseTemplateEditorAction
 	{
 		
 		function __construct( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->AdminBaseTemplateEditorAction( $actionInfo, $request );
+			
 			$this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
 			$this->registerFieldValidator( "path", new StringValidator(), true );
 			$this->registerFieldValidator( "file", new StringValidator(), false );			
@@ -28,35 +29,7 @@
 
 		function validate()
 		{
-			if( !parent::validate()) 
-				return false;
-
-			// check that the template really exists
-			$this->_templateId = $this->_request->getFilteredValue( "templateId", new RegexpFilter( "/[^A-Za-z0-9_]/" ));
-			if( !TemplateSets::isTemplate( $this->_templateId )) {
-				$this->_form->setFieldValidationStatus( "templateId", false );
-				$this->validationErrorProcessing();
-				return( false );
-			}
-
-			// if the template exists, check that the path exists too
-			$this->_path = $this->_request->getFilteredValue( "path", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
-			if( !TemplateTools::isValidTemplatePath( $this->_templateId, $this->_path )) {
-				$this->_form->setFieldValidationStatus( "path", false );
-				$this->validationErrorProcessing();
-				return( false );				
-			}
-
-			// if the template exists, check that the path exists too
-			$this->_file = $this->_request->getFilteredValue( "file", new RegexpFilter( "/[^A-Za-z0-9_\/\-.]/" ));
-			if( !TemplateTools::isValidTemplateFile( $this->_templateId, $this->_path, $this->_file )) {
-				$this->_form->setFieldValidationStatus( "file", false );
-				$this->validationErrorProcessing();
-				return( false );				
-			}			
-
-			// otherwise everything is peachy
-			return( true );
+			return( parent::validate( Array( "templateId", "path", "file" )));
 		}
 		
 		function deleteFile()

Modified: plog/trunk/class/action/admin/adminedittemplateaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminedittemplateaction.class.php	2007-08-20 20:01:06 UTC (rev 5846)
+++ plog/trunk/class/action/admin/adminedittemplateaction.class.php	2007-08-20 20:01:47 UTC (rev 5847)
@@ -1,6 +1,6 @@
 <?php
 	
-	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminbasetemplateeditoraction.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );		
 	lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
@@ -8,14 +8,14 @@
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminsitetemplateslistview.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminedittemplateview.class.php" );	
 	
-	class AdminEditTemplateAction extends AdminAction
+	class AdminEditTemplateAction extends AdminBaseTemplateEditorAction
 	{
-		private $_templateId;
-		private $_path;
+		protected $_templateId;
+		protected $_path;
 		
 		function __construct( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->AdminBaseTemplateEditorAction( $actionInfo, $request );
 			
 			$this->registerFieldValidator( "templateId", new TemplateNameValidator());
 			$view = new AdminSiteTemplatesListView( $this->_blogInfo );
@@ -27,27 +27,7 @@
 		
 		function validate()
 		{
-			if( !parent::validate()) 
-				return false;
-				
-			// check that the template really exists
-			$this->_templateId = $this->_request->getFilteredValue( "templateId", new RegexpFilter( "/[^A-Za-z0-9_]/" ));
-			if( !TemplateSets::isTemplate( $this->_templateId )) {
-				$this->_form->setFieldValidationStatus( "templateId", false );
-				$this->validationErrorProcessing();
-				return( false );
-			}
-			
-			// if the template exists, check that the path exists too
-			$this->_path = $this->_request->getFilteredValue( "path", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
-			if( !TemplateTools::isValidTemplatePath( $this->_templateId, $this->_path )) {
-				$this->_form->setFieldValidationStatus( "path", false );
-				$this->validationErrorProcessing();
-				return( false );				
-			}
-			
-			// otherwise everything is peachy
-			return( true );
+			return( parent::validate( Array( "templateId", "path" )));
 		}
 		
 		function perform()

Modified: plog/trunk/class/action/admin/adminedittemplatefileaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminedittemplatefileaction.class.php	2007-08-20 20:01:06 UTC (rev 5846)
+++ plog/trunk/class/action/admin/adminedittemplatefileaction.class.php	2007-08-20 20:01:47 UTC (rev 5847)
@@ -1,6 +1,6 @@
 <?php
 	
-	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminbasetemplateeditoraction.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );		
 	lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );		
@@ -11,21 +11,21 @@
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminerrordialogview.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/file/file.class.php" );		
 	
-	class AdminEditTemplateFileAction extends AdminAction
+	class AdminEditTemplateFileAction extends AdminBaseTemplateEditorAction
 	{
-		private $_templateId;
-		private $_path;
-		private $_file;
+		protected $_templateId;
+		protected $_path;
+		protected $_file;
 		
 		function __construct( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->AdminBaseTemplateEditorAction( $actionInfo, $request );
 			
 			$this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
 			$this->registerFieldValidator( "path", new StringValidator(), true );
 			$this->registerFieldValidator( "file", new StringValidator(), false );			
 			$view = new AdminSiteTemplatesListView( $this->_blogInfo );
-			$view->setErrorMessage( $this->_locale->tr( "error_loading_template" ));			
+			$view->setErrorMessage( $this->_locale->tr( "error_loading_template_set" ));			
 			$this->setValidationErrorView( $view );
 			
 			$this->requirePermission( "edit_site_template" );
@@ -33,37 +33,7 @@
 		
 		function validate()
 		{
-			if( !parent::validate()) 
-				return false;
-				
-				
-			// check that the template really exists
-			$this->_templateId = $this->_request->getFilteredValue( "templateId", new RegexpFilter( "/[^A-Za-z0-9_]/" ));
-			if( !TemplateSets::isTemplate( $this->_templateId )) {
-				$this->_form->setFieldValidationStatus( "templateId", false );
-				$this->validationErrorProcessing();
-				return( false );
-			}
-			
-			// if the template exists, check that the path exists too
-			$this->_path = $this->_request->getFilteredValue( "path", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
-			if( !TemplateTools::isValidTemplatePath( $this->_templateId, $this->_path )) {
-				$this->_form->setFieldValidationStatus( "path", false );
-				$this->validationErrorProcessing();
-				return( false );				
-			}
-			
-			// if the template exists, check that the path exists too
-			$this->_file = $this->_request->getFilteredValue( "file", new RegexpFilter( "/[^A-Za-z0-9_\/\-.]/" ));
-			if( !TemplateTools::isValidTemplateFile( $this->_templateId, $this->_path, $this->_file ) ||
-			    !TemplateTools::isEditable( $this->_file )) {
-				$this->_form->setFieldValidationStatus( "file", false );
-				$this->validationErrorProcessing();
-				return( false );				
-			}			
-			
-			// otherwise everything is peachy
-			return( true );
+			return( parent::validate( Array( "templateId", "path", "file" )));
 		}
 		
 		function perform()

Modified: plog/trunk/class/action/admin/adminupdatetemplatefileaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminupdatetemplatefileaction.class.php	2007-08-20 20:01:06 UTC (rev 5846)
+++ plog/trunk/class/action/admin/adminupdatetemplatefileaction.class.php	2007-08-20 20:01:47 UTC (rev 5847)
@@ -1,9 +1,9 @@
 <?php
 
-	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminbasetemplateeditoraction.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );		
-	lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );		
+	lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/template/editor/templatetools.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminsitetemplateslistview.class.php" );
@@ -11,11 +11,11 @@
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminedittemplatefileview.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/file/file.class.php" );
 
-	class AdminUpdateTemplateFileAction extends AdminAction
+	class AdminUpdateTemplateFileAction extends AdminBaseTemplateEditorAction
 	{
 		function __construct( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->AdminBaseTemplateEditorAction( $actionInfo, $request );
 			
 			$this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
 			$this->registerFieldValidator( "path", new StringValidator(), true );
@@ -29,37 +29,7 @@
 
 		function validate()
 		{
-			if( !parent::validate()) 
-				return false;
-
-
-			// check that the template really exists
-			$this->_templateId = $this->_request->getFilteredValue( "templateId", new RegexpFilter( "/[^A-Za-z0-9_]/" ));
-			if( !TemplateSets::isTemplate( $this->_templateId )) {
-				$this->_form->setFieldValidationStatus( "templateId", false );
-				$this->validationErrorProcessing();
-				return( false );
-			}
-
-			// if the template exists, check that the path exists too
-			$this->_path = $this->_request->getFilteredValue( "path", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
-			if( !TemplateTools::isValidTemplatePath( $this->_templateId, $this->_path )) {
-				$this->_form->setFieldValidationStatus( "path", false );
-				$this->validationErrorProcessing();
-				return( false );				
-			}
-
-			// if the template exists, check that the path exists too
-			$this->_file = $this->_request->getFilteredValue( "file", new RegexpFilter( "/[^A-Za-z0-9_\/\-.]/" ));
-			if( !TemplateTools::isValidTemplateFile( $this->_templateId, $this->_path, $this->_file ) ||
-			    !TemplateTools::isEditable( $this->_file )) {
-				$this->_form->setFieldValidationStatus( "file", false );
-				$this->validationErrorProcessing();
-				return( false );				
-			}			
-
-			// otherwise everything is peachy
-			return( true );
+			return( parent::validate( Array( "templateId", "path", "file" )));
 		}
 		
 		function writeFile()

Modified: plog/trunk/class/template/editor/templatetools.class.php
===================================================================
--- plog/trunk/class/template/editor/templatetools.class.php	2007-08-20 20:01:06 UTC (rev 5846)
+++ plog/trunk/class/template/editor/templatetools.class.php	2007-08-20 20:01:47 UTC (rev 5847)
@@ -120,5 +120,47 @@
 				
 			return( $path );
 		}
+		
+		/**
+		 * Returns the Filter object that should be used to extract
+		 * template names from HTTP requests.
+		 * This method is probably useless for generic usage, but it is used by all
+		 * classes that are part of the template edito feature.
+		 *
+		 * @return A RegexpFilter object.
+		 */
+		static function getTemplateNameFilter()
+		{
+			lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );			
+			return( new RegexpFilter( "/[^A-Za-z0-9_\-]/" ));
+		}
+		
+		/**
+		 * Returns the Filter object that should be used to extract
+		 * template paths from HTTP requests.
+		 * This method is probably useless for generic usage, but it is used by all
+		 * classes that are part of the template edito feature.
+		 *
+		 * @return A RegexpFilter object.
+		 */		
+		static function getTemplatePathFilter()
+		{
+			lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );			
+			return( new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
+		}
+		
+		/**
+		 * Returns the Filter object that should be used to extract
+		 * template file names from HTTP requests.
+		 * This method is probably useless for generic usage, but it is used by all
+		 * classes that are part of the template edito feature.
+		 *
+		 * @return A RegexpFilter object.
+		 */		
+		static function getTemplateFileNameFilter()
+		{
+			lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );			
+			return( new RegexpFilter( "/[^A-Za-z0-9_\/\-\.]/" ));
+		}
 	}
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list