[pLog-svn] r7127 - plugins/branches/lifetype-1.2/templateeditor/class/action

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Thu Sep 1 09:06:19 EDT 2011


Author: jondaley
Date: 2011-09-01 09:06:19 -0400 (Thu, 01 Sep 2011)
New Revision: 7127

Modified:
   plugins/branches/lifetype-1.2/templateeditor/class/action/pluginblogcopytemplatesetaction.class.php
   plugins/branches/lifetype-1.2/templateeditor/class/action/pluginsitecopytemplatesetaction.class.php
Log:
use core validators rather than rewriting our own for simpler and more accurate code.  fixes server side of http://bugs.lifetype.net/view.php?id=1656

Modified: plugins/branches/lifetype-1.2/templateeditor/class/action/pluginblogcopytemplatesetaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/templateeditor/class/action/pluginblogcopytemplatesetaction.class.php	2011-09-01 13:05:36 UTC (rev 7126)
+++ plugins/branches/lifetype-1.2/templateeditor/class/action/pluginblogcopytemplatesetaction.class.php	2011-09-01 13:06:19 UTC (rev 7127)
@@ -4,57 +4,43 @@
 	lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );		
 	lt_include( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginblogtemplatesetslistview.class.php" );
     lt_include( PLOG_CLASS_PATH."plugins/templateeditor/class/file/myfile.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/validator/integerrangevalidator.class.php" );
 
     /**
      * Removes global templates from disk.
      */
     class PluginBlogCopyTemplateSetAction extends AdminAction
     {
-
-    	var $_templateId;
-    	var $_newTemplateId;
-    	var $_type;
-
         function PluginBlogCopyTemplateSetAction( $actionInfo, $request )
         {
         	$this->AdminAction( $actionInfo, $request );
 
 			$this->requirePermission( "edit_blog_templates" );
-        }
 
-		function validate()
-		{
-            $this->_templateId = $this->_request->getValue( "templateId" );
-            $this->_newTemplateId = $this->_request->getValue( "newTemplateId" );
-            if( !$this->isValidTemplateSetName( $this->_newTemplateId ) || !$this->isValidTemplateSetName( $this->_templateId )) {
-                $this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
-                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_templateset_name"));
-                $this->setCommonData();
+            $this->registerFieldValidator( "templateId", new TemplateNameValidator());
+            $this->registerFieldValidator( "newTemplateId", new TemplateNameValidator());
+            $this->registerFieldValidator( "type", new IntegerRangeValidator(1, 2));
 
-                return false;
-            }
-            
-            $this->_type = $this->_request->getValue( "type" );
-            if( $this->_type != 1 && $this->_type != 2) {
-                $this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
-                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_templateset_type"));
-                $this->setCommonData();
-
-                return false;
-            }
-            
-            return true;
-		}        
-
+            $view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
+                // Note, error message will be wrong if the type value is incorrect
+            $view->setErrorMessage( $this->_locale->tr("templateeditor_error_templateset_name"));
+            $this->setValidationErrorView( $view );
+        }
+        
         function perform()
         {
-			// get a list with all the global template sets
-			if ( $this->_type == 1 ) {
+            $templateId = $this->_request->getValue( "templateId" );
+            $newTemplateId = $this->_request->getValue( "newTemplateId" );
+            $type = $this->_request->getValue( "type" );
+            
+                // get a list with all the global template sets
+			if ( $type == 1 ) {
             	$ts = new TemplateSets();
                 $blogTemplateSets = $ts->getBlogTemplateSets( $this->_blogInfo->getId(), false );
                                 
                 foreach ($blogTemplateSets as $template) {
-                    if ( $template->getName() == $this->_newTemplateId ) {
+                    if ( $template->getName() == $newTemplateId ) {
                     	$this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
                     	$this->_view->setErrorMessage( $this->_locale->tr("error_duplicate_templateset_name"));
                         $this->setCommonData();
@@ -64,11 +50,11 @@
     
             	$ts = new TemplateSetStorage();
                 $blogId = $this->_blogInfo->getId();
-                $sourceTemplateFolder = $ts->getTemplateFolder($this->_templateId);
-                $newTemplateFolder = $ts->getBlogBaseTemplateFolder($blogId) . $this->_newTemplateId;
+                $sourceTemplateFolder = $ts->getTemplateFolder($templateId);
+                $newTemplateFolder = $ts->getBlogBaseTemplateFolder($blogId) . $newTemplateId;
                 
                 if ( MyFile::copyDir($sourceTemplateFolder, $newTemplateFolder) ) {
-                    $ts->addTemplate($this->_newTemplateId, $blogId);
+                    $ts->addTemplate($newTemplateId, $blogId);
                 } else {
                     File::deleteDir($newTemplateFolder);
                     $this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
@@ -81,7 +67,7 @@
                 $blogTemplateSets = $ts->getBlogTemplateSets( $this->_blogInfo->getId(), false );
                 
                 foreach ($blogTemplateSets as $template) {
-                    if ( $template->getName() == $this->_newTemplateId ) {
+                    if ( $template->getName() == $newTemplateId ) {
                     	$this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
                     	$this->_view->setErrorMessage( $this->_locale->tr("error_duplicate_templateset_name"));
                         $this->setCommonData();
@@ -91,11 +77,11 @@
     
             	$ts = new TemplateSetStorage();
                 $blogId = $this->_blogInfo->getId();
-                $sourceTemplateFolder = $ts->getTemplateFolder($this->_templateId, $blogId);
-                $newTemplateFolder = $ts->getBlogBaseTemplateFolder($blogId) . $this->_newTemplateId;
+                $sourceTemplateFolder = $ts->getTemplateFolder($templateId, $blogId);
+                $newTemplateFolder = $ts->getBlogBaseTemplateFolder($blogId) . $newTemplateId;
                 
                 if ( MyFile::copyDir($sourceTemplateFolder, $newTemplateFolder) ) {
-                    $ts->addTemplate($this->_newTemplateId, $blogId);
+                    $ts->addTemplate($newTemplateId, $blogId);
                 } else {
                     File::deleteDir($newTemplateFolder);
                     $this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );

Modified: plugins/branches/lifetype-1.2/templateeditor/class/action/pluginsitecopytemplatesetaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/templateeditor/class/action/pluginsitecopytemplatesetaction.class.php	2011-09-01 13:05:36 UTC (rev 7126)
+++ plugins/branches/lifetype-1.2/templateeditor/class/action/pluginsitecopytemplatesetaction.class.php	2011-09-01 13:06:19 UTC (rev 7127)
@@ -4,6 +4,7 @@
 	lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );		
 	lt_include( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginsitetemplatesetslistview.class.php" );
     lt_include( PLOG_CLASS_PATH."plugins/templateeditor/class/file/myfile.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );
 
     /**
      * Removes global templates from disk.
@@ -11,38 +12,32 @@
     class PluginSiteCopyTemplateSetAction extends AdminAction
     {
 
-    	var $_templateId;
-    	var $_newTemplateId;
-
         function PluginSiteCopyTemplateSetAction( $actionInfo, $request )
         {
         	$this->AdminAction( $actionInfo, $request );
 
 			$this->requireAdminPermission( "edit_global_templates" );
-        }
 
-		function validate()
-		{
-            $this->_templateId = $this->_request->getValue( "templateId" );
-            $this->_newTemplateId = $this->_request->getValue( "newTemplateId" );
-            if( !$this->isValidTemplateSetName( $this->_newTemplateId ) || !$this->isValidTemplateSetName( $this->_templateId )) {
-                $this->_view = new PluginSiteTemplateSetsListView( $this->_blogInfo );
-                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_templateset_name"));
-                $this->setCommonData();
+            $this->registerFieldValidator( "templateId", new TemplateNameValidator());
+            $this->registerFieldValidator( "newTemplateId", new TemplateNameValidator());
 
-                return false;
-            }        	                
-			return true;
-		}        
+            $view = new PluginSiteTemplateSetsListView( $this->_blogInfo );
+                // Note, error message will be wrong if the type value is incorrect
+            $view->setErrorMessage( $this->_locale->tr("templateeditor_error_templateset_name"));
+            $this->setValidationErrorView( $view );
+        }
 
         function perform()
         {
-			// get a list with all the global template sets
+            $templateId = $this->_request->getValue( "templateId" );
+            $newTemplateId = $this->_request->getValue( "newTemplateId" );
+
+                // get a list with all the global template sets
         	$ts = new TemplateSets();
             $globalTemplates = $ts->getGlobalTemplateSets();
             
             foreach ($globalTemplates as $template) {
-                if ( $template->getName() == $this->_newTemplateId ) {
+                if ( $template->getName() == $newTemplateId ) {
                 	$this->_view = new PluginSiteTemplateSetsListView( $this->_blogInfo );
                 	$this->_view->setErrorMessage( $this->_locale->tr("error_duplicate_templateset_name"));
                     $this->setCommonData();
@@ -52,11 +47,11 @@
 
         	$ts = new TemplateSetStorage();
             $blogId = $this->_blogInfo->getId();
-            $sourceTemplateFolder = $ts->getTemplateFolder($this->_templateId);
-            $newTemplateFolder = $ts->getBaseTemplateFolder() . "/" . $this->_newTemplateId;
+            $sourceTemplateFolder = $ts->getTemplateFolder($templateId);
+            $newTemplateFolder = $ts->getBaseTemplateFolder() . "/" . $newTemplateId;
             
             if ( MyFile::copyDir($sourceTemplateFolder, $newTemplateFolder) ) {
-                $ts->addTemplate($this->_newTemplateId);
+                $ts->addTemplate($newTemplateId);
             } else {
                 File::deleteDir($newTemplateFolder);
                 $this->_view = new PluginSiteTemplateSetsListView( $this->_blogInfo );



More information about the pLog-svn mailing list