[pLog-svn] r1290 - in plugins/trunk/templateeditor: . class/action class/file class/view locale templates

mark at devel.plogworld.net mark at devel.plogworld.net
Wed Mar 2 19:18:34 GMT 2005


Author: mark
Date: 2005-03-02 19:18:34 +0000 (Wed, 02 Mar 2005)
New Revision: 1290

Added:
   plugins/trunk/templateeditor/class/action/pluginblogcopytemplatefileaction.class.php
   plugins/trunk/templateeditor/class/action/pluginblogcopytemplatesetaction.class.php
   plugins/trunk/templateeditor/class/action/pluginsitecopytemplatefileaction.class.php
   plugins/trunk/templateeditor/class/action/pluginsitecopytemplatesetaction.class.php
Modified:
   plugins/trunk/templateeditor/class/action/plugintemplateeditorupdateconfigaction.class.php
   plugins/trunk/templateeditor/class/file/myfile.class.php
   plugins/trunk/templateeditor/class/view/pluginblogtemplateslistview.class.php
   plugins/trunk/templateeditor/class/view/pluginsitetemplateslistview.class.php
   plugins/trunk/templateeditor/class/view/plugintemplateeditorconfigview.class.php
   plugins/trunk/templateeditor/locale/locale_en_UK.php
   plugins/trunk/templateeditor/locale/locale_zh_TW.php
   plugins/trunk/templateeditor/plugintemplateeditor.class.php
   plugins/trunk/templateeditor/templates/blogtemplatesetslist.template
   plugins/trunk/templateeditor/templates/blogtemplateslist.template
   plugins/trunk/templateeditor/templates/pluginsettings.template
   plugins/trunk/templateeditor/templates/sitetemplatesetslist.template
   plugins/trunk/templateeditor/templates/sitetemplateslist.template
Log:
Add "Copy To" function to TemplateSetList and TemplateFileList. So, now template editor can allow user to create a new file or template set through "copy to" function. Not perfect, but workable.

Added: plugins/trunk/templateeditor/class/action/pluginblogcopytemplatefileaction.class.php
===================================================================
--- plugins/trunk/templateeditor/class/action/pluginblogcopytemplatefileaction.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/class/action/pluginblogcopytemplatefileaction.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -0,0 +1,126 @@
+<?php
+    include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );		
+	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginblogtemplateslistview.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/file/myfile.class.php" );	
+
+    /**
+     * Removes global templates from disk.
+     */
+    class PluginBlogCopyTemplateFileAction extends BlogOwnerAdminAction
+    {
+
+    	var $_templateId;
+    	var $_fileId;
+    	var $_newFileId;
+
+        function PluginBlogCopyTemplateFileAction( $actionInfo, $request )
+        {
+        	$this->BlogOwnerAdminAction( $actionInfo, $request );
+        }
+
+		function validate()
+		{
+            $this->_templateId = $this->_request->getValue( "templateId" );
+            $this->_fileId = $this->_request->getValue( "fileId" );
+            $this->_newFileId = $this->_request->getValue( "newFileId" );
+            if( !$this->isValidTamplateFileName( $this->_newFileId ) ) {
+                $this->_view = new PluginBlogTemplatesListView( $this->_blogInfo , $this->_templateId);
+                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_templatefile_name"));
+                $this->setCommonData();
+
+                return false;
+            }
+            if( !$this->isValidExtension( $this->_newFileId ) ) {
+                $this->_view = new PluginBlogTemplatesListView( $this->_blogInfo , $this->_templateId);
+                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_templatefile_extension"));
+                $this->setCommonData();
+
+                return false;
+            }            
+			return true;
+		}        
+
+        function perform()
+        {
+        	$ts = new TemplateSetStorage();
+            $blogId = $this->_blogInfo->getId();
+            $templateFolder = $ts->getTemplateFolder($this->_templateId, $blogId);
+
+			// Get template files according extension
+            $templateFiles = $this->getTemplateFiles( $templateFolder );            
+            
+            foreach ($templateFiles as $file) {
+                if ( $file['name'] == $this->_newFileId ) {
+                	$this->_view = new PluginBlogTemplatesListView( $this->_blogInfo , $this->_templateId);
+                	$this->_view->setErrorMessage( $this->_locale->tr("error_duplicate_templatefile_name"));
+                    $this->setCommonData();
+                    return false;
+                }
+            }
+
+            $sourceFile = $templateFolder . $this->_fileId;
+            $newFile = $templateFolder . $this->_newFileId;
+            
+            if ( !File::copy($sourceFile, $newFile) ) {
+                $this->_view = new PluginBlogTemplatesListView( $this->_blogInfo , $this->_templateId);
+                $this->_view->setErrorMessage( $this->_locale->tr("error_copying_templatefile"));
+                $this->setCommonData();
+                return false;                
+            }
+
+			// if everything went ok...
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+            
+			$this->_view = new PluginBlogTemplatesListView( $this->_blogInfo , $this->_templateId);
+			$this->_view->setSuccessMessage( $this->_locale->tr("templateeditor_templatefile_copyed_ok"));
+			$this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());			
+            
+            return true;
+        }
+
+        function isValidTamplateFileName( $name )
+        {
+		    $pattern = '/^[a-zA-Z0-9\._-]*$/';
+            if (preg_match($pattern, $name) ) {
+               return true;
+            } else {
+               return false;
+            }
+        }
+        
+        function isValidExtension( $name )
+        {
+			$config =& Config::getConfig();
+			$allowedExtension = $config->getValue( "plugin_templateeditor_allowedextension" );
+		    $extensionList = explode(",", $allowedExtension);            
+            $fileExtension = "*." . array_pop(explode('.', $name));
+            foreach ($extensionList as $extension) {
+                if ( $fileExtension == trim($extension) ) {
+                    return true;   
+                }
+            }
+            return false;
+        }
+
+		function getTemplateFiles( $folder ) {
+			$config =& Config::getConfig();
+			$allowedExtension = $config->getValue( "plugin_templateeditor_allowedextension" );   		    
+		    $extensionList = explode(",", $allowedExtension);
+            $templateFiles = Array();
+		    for ($i = 0; $i < count($extensionList); $i++) {
+                $files = Glob::myGlob( $folder, trim($extensionList[$i]) );
+                foreach ($files as $file) {
+                    $tmp['name'] = basename($file);
+                    $tmp['size'] = filesize($file);
+                    array_push ($templateFiles, $tmp);
+                }
+            }
+            return $templateFiles;
+        }	        
+    }
+?>

Added: plugins/trunk/templateeditor/class/action/pluginblogcopytemplatesetaction.class.php
===================================================================
--- plugins/trunk/templateeditor/class/action/pluginblogcopytemplatesetaction.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/class/action/pluginblogcopytemplatesetaction.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -0,0 +1,90 @@
+<?php
+    include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
+	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );		
+	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginblogtemplatesetslistview.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/file/myfile.class.php" );	
+
+    /**
+     * Removes global templates from disk.
+     */
+    class PluginBlogCopyTemplateSetAction extends BlogOwnerAdminAction
+    {
+
+    	var $_templateId;
+    	var $_newTemplateId;
+
+        function PluginBlogCopyTemplateSetAction( $actionInfo, $request )
+        {
+        	$this->BlogOwnerAdminAction( $actionInfo, $request );
+        }
+
+		function validate()
+		{
+            $this->_templateId = $this->_request->getValue( "templateId" );
+            $this->_newTemplateId = $this->_request->getValue( "newTemplateId" );
+            if( !$this->isValidTamplateSetName( $this->_newTemplateId ) ) {
+                $this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_templateset_name"));
+                $this->setCommonData();
+
+                return false;
+            }        	                
+			return true;
+		}        
+
+        function perform()
+        {
+			// get a list with all the global template sets
+        	$ts = new TemplateSets();
+            $blogTemplateSets = $ts->getBlogTemplateSets( $this->_blogInfo->getId(), false );
+            
+            foreach ($blogTemplateSets as $template) {
+                if ( $template->getName() == $this->_newTemplateId ) {
+                	$this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
+                	$this->_view->setErrorMessage( $this->_locale->tr("error_duplicate_templateset_name"));
+                    $this->setCommonData();
+                    return false;
+                }
+            }
+
+        	$ts = new TemplateSetStorage();
+            $blogId = $this->_blogInfo->getId();
+            $sourceTemplateFolder = $ts->getTemplateFolder($this->_templateId, $blogId);
+            $newTemplateFolder = $ts->getBlogBaseTemplateFolder($blogId) . $this->_newTemplateId;
+            
+            if ( MyFile::copyDir($sourceTemplateFolder, $newTemplateFolder) ) {
+                $ts->addTemplate($this->_newTemplateId, $blogId);
+            } else {
+                File::deleteDir($newTemplateFolder);
+                $this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_copying_templateset"));
+                $this->setCommonData();
+                return false;                
+            }
+
+			// if everything went ok...
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+            
+			$this->_view = new PluginBlogTemplateSetsListView( $this->_blogInfo );
+			$this->_view->setSuccessMessage( $this->_locale->tr("templateeditor_templateset_copyed_ok"));
+			$this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());			
+            
+            return true;
+        }
+
+        function isValidTamplateSetName( $name )
+        {
+		    $pattern = '/^[a-zA-Z0-9_-]*$/';
+            if (preg_match($pattern, $name) ) {
+               return true;
+            } else {
+               return false;
+            }
+        }
+    }
+?>

Added: plugins/trunk/templateeditor/class/action/pluginsitecopytemplatefileaction.class.php
===================================================================
--- plugins/trunk/templateeditor/class/action/pluginsitecopytemplatefileaction.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/class/action/pluginsitecopytemplatefileaction.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -0,0 +1,126 @@
+<?php
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );		
+	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginsitetemplateslistview.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/file/myfile.class.php" );	
+
+    /**
+     * Removes global templates from disk.
+     */
+    class PluginSiteCopyTemplateFileAction extends SiteAdminAction
+    {
+
+    	var $_templateId;
+    	var $_fileId;
+    	var $_newFileId;
+
+        function PluginSiteCopyTemplateFileAction( $actionInfo, $request )
+        {
+        	$this->SiteAdminAction( $actionInfo, $request );
+        }
+
+		function validate()
+		{
+            $this->_templateId = $this->_request->getValue( "templateId" );
+            $this->_fileId = $this->_request->getValue( "fileId" );
+            $this->_newFileId = $this->_request->getValue( "newFileId" );
+            if( !$this->isValidTamplateFileName( $this->_newFileId ) ) {
+                $this->_view = new PluginSiteTemplatesListView( $this->_blogInfo , $this->_templateId);
+                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_templatefile_name"));
+                $this->setCommonData();
+
+                return false;
+            }
+            if( !$this->isValidExtension( $this->_newFileId ) ) {
+                $this->_view = new PluginSiteTemplatesListView( $this->_blogInfo , $this->_templateId);
+                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_templatefile_extension"));
+                $this->setCommonData();
+
+                return false;
+            }            
+			return true;
+		}        
+
+        function perform()
+        {
+        	$ts = new TemplateSetStorage();
+            $blogId = $this->_blogInfo->getId();
+            $templateFolder = $ts->getTemplateFolder($this->_templateId);
+
+			// Get template files according extension
+            $templateFiles = $this->getTemplateFiles( $templateFolder );            
+            
+            foreach ($templateFiles as $file) {
+                if ( $file['name'] == $this->_newFileId ) {
+                	$this->_view = new PluginSiteTemplatesListView( $this->_blogInfo , $this->_templateId);
+                	$this->_view->setErrorMessage( $this->_locale->tr("error_duplicate_templatefile_name"));
+                    $this->setCommonData();
+                    return false;
+                }
+            }
+
+            $sourceFile = $templateFolder . $this->_fileId;
+            $newFile = $templateFolder . $this->_newFileId;
+            
+            if ( !File::copy($sourceFile, $newFile) ) {
+                $this->_view = new PluginSiteTemplatesListView( $this->_blogInfo , $this->_templateId);
+                $this->_view->setErrorMessage( $this->_locale->tr("error_copying_templatefile"));
+                $this->setCommonData();
+                return false;                
+            }
+
+			// if everything went ok...
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+            
+			$this->_view = new PluginSiteTemplatesListView( $this->_blogInfo , $this->_templateId);
+			$this->_view->setSuccessMessage( $this->_locale->tr("templateeditor_templatefile_copyed_ok"));
+			$this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());			
+            
+            return true;
+        }
+
+        function isValidTamplateFileName( $name )
+        {
+		    $pattern = '/^[a-zA-Z0-9\._-]*$/';
+            if (preg_match($pattern, $name) ) {
+               return true;
+            } else {
+               return false;
+            }
+        }
+        
+        function isValidExtension( $name )
+        {
+			$config =& Config::getConfig();
+			$allowedExtension = $config->getValue( "plugin_templateeditor_allowedextension" );
+		    $extensionList = explode(",", $allowedExtension);            
+            $fileExtension = "*." . array_pop(explode('.', $name));
+            foreach ($extensionList as $extension) {
+                if ( $fileExtension == trim($extension) ) {
+                    return true;   
+                }
+            }
+            return false;
+        }
+
+		function getTemplateFiles( $folder ) {
+			$config =& Config::getConfig();
+			$allowedExtension = $config->getValue( "plugin_templateeditor_allowedextension" );   		    
+		    $extensionList = explode(",", $allowedExtension);
+            $templateFiles = Array();
+		    for ($i = 0; $i < count($extensionList); $i++) {
+                $files = Glob::myGlob( $folder, trim($extensionList[$i]) );
+                foreach ($files as $file) {
+                    $tmp['name'] = basename($file);
+                    $tmp['size'] = filesize($file);
+                    array_push ($templateFiles, $tmp);
+                }
+            }
+            return $templateFiles;
+        }	        
+    }
+?>

Added: plugins/trunk/templateeditor/class/action/pluginsitecopytemplatesetaction.class.php
===================================================================
--- plugins/trunk/templateeditor/class/action/pluginsitecopytemplatesetaction.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/class/action/pluginsitecopytemplatesetaction.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -0,0 +1,90 @@
+<?php
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
+	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );		
+	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginsitetemplatesetslistview.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/file/myfile.class.php" );	
+
+    /**
+     * Removes global templates from disk.
+     */
+    class PluginSiteCopyTemplateSetAction extends SiteAdminAction
+    {
+
+    	var $_templateId;
+    	var $_newTemplateId;
+
+        function PluginSiteCopyTemplateSetAction( $actionInfo, $request )
+        {
+        	$this->SiteAdminAction( $actionInfo, $request );
+        }
+
+		function validate()
+		{
+            $this->_templateId = $this->_request->getValue( "templateId" );
+            $this->_newTemplateId = $this->_request->getValue( "newTemplateId" );
+            if( !$this->isValidTamplateSetName( $this->_newTemplateId ) ) {
+                $this->_view = new PluginSiteTemplateSetsListView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_templateset_name"));
+                $this->setCommonData();
+
+                return false;
+            }        	                
+			return true;
+		}        
+
+        function perform()
+        {
+			// get a list with all the global template sets
+        	$ts = new TemplateSets();
+            $globalTemplates = $ts->getGlobalTemplateSets();
+            
+            foreach ($globalTemplates as $template) {
+                if ( $template->getName() == $this->_newTemplateId ) {
+                	$this->_view = new PluginSiteTemplateSetsListView( $this->_blogInfo );
+                	$this->_view->setErrorMessage( $this->_locale->tr("error_duplicate_templateset_name"));
+                    $this->setCommonData();
+                    return false;
+                }
+            }
+
+        	$ts = new TemplateSetStorage();
+            $blogId = $this->_blogInfo->getId();
+            $sourceTemplateFolder = $ts->getTemplateFolder($this->_templateId);
+            $newTemplateFolder = $ts->getBaseTemplateFolder() . "/" . $this->_newTemplateId;
+            
+            if ( MyFile::copyDir($sourceTemplateFolder, $newTemplateFolder) ) {
+                $ts->addTemplate($this->_newTemplateId);
+            } else {
+                File::deleteDir($newTemplateFolder);
+                $this->_view = new PluginSiteTemplateSetsListView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_copying_templateset"));
+                $this->setCommonData();
+                return false;                
+            }
+
+			// if everything went ok...
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+            
+			$this->_view = new PluginSiteTemplateSetsListView( $this->_blogInfo );
+			$this->_view->setSuccessMessage( $this->_locale->tr("templateeditor_templateset_copyed_ok"));
+			$this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());			
+            
+            return true;
+        }
+
+        function isValidTamplateSetName( $name )
+        {
+		    $pattern = '/^[a-zA-Z0-9_-]*$/';
+            if (preg_match($pattern, $name) ) {
+               return true;
+            } else {
+               return false;
+            }
+        }
+    }
+?>

Modified: plugins/trunk/templateeditor/class/action/plugintemplateeditorupdateconfigaction.class.php
===================================================================
--- plugins/trunk/templateeditor/class/action/plugintemplateeditorupdateconfigaction.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/class/action/plugintemplateeditorupdateconfigaction.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -1,7 +1,8 @@
 <?php
 
 	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
-	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/plugintemplateeditorconfigview.class.php" );	
+	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/plugintemplateeditorconfigview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );	
 		
 	/**
 	 * updates the plugin configuration
@@ -10,6 +11,7 @@
 	{
 		var $_pluginEnabled;
 		var $_maxBackupFiles;
+		var $_allowedExtension;
 		
 		function PluginTemplateEditorUpdateConfigAction( $actionInfo, $request )
 		{
@@ -27,7 +29,16 @@
                 $this->setCommonData();
 
                 return false;
-            }        	                
+            }
+            $this->_allowedExtension = $this->_request->getValue( "allowedExtension" );
+            $val = new StringValidator();
+			if ( !$val->validate($this->_allowedExtension) ) {
+                $this->_view = new PluginTemplateEditorConfigView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("templateeditor_error_allowedextension"));
+                $this->setCommonData();
+
+                return false;
+            }			    
 			
 			return true;
 		}
@@ -38,6 +49,7 @@
 			$config =& Config::getConfig();
             $config->setValue( "plugin_templateeditor_enabled", $this->_pluginEnabled );
             $config->setValue( "plugin_templateeditor_maxbackupfiles", $this->_maxBackupFiles );
+            $config->setValue( "plugin_templateeditor_allowedextension", $this->_allowedExtension );
 		
             if( !$config->save() ) {
                 $this->_view = new PluginTemplateEditorConfigView( $this->_blogInfo );

Modified: plugins/trunk/templateeditor/class/file/myfile.class.php
===================================================================
--- plugins/trunk/templateeditor/class/file/myfile.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/class/file/myfile.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -26,5 +26,48 @@
              
              return $bytes;
          }
+         
+         /**
+          * Recursively copy a folder and its contents
+          * http://aidan.dotgeek.org/lib/?file=function.copyr.php
+          *
+          * @author      Aidan Lister <aidan at php.net>
+          * @version     1.0.1
+          * @param       string   $source    Source path
+          * @param       string   $dest      Destination path
+          * @return      bool     Returns TRUE on success, FALSE on failure
+          */
+         function copyDir($source, $dest)
+         {
+             clearstatcache();
+             
+             // Simple copy for a file
+             if (is_file($source)) {
+                 return File::copy($source, $dest);
+             }
+          
+             // Make destination directory
+             if (!File::isDir($dest)) {
+                 File::createDir($dest);
+             }
+          
+             // Loop through the folder
+             $dir = dir($source);
+             while (false !== $entry = $dir->read()) {
+                 // Skip pointers
+                 if ($entry == '.' || $entry == '..') {
+                     continue;
+                 }
+          
+                 // Deep copy directories
+                 if ($dest !== "$source/$entry") {
+                     MyFile::copyDir("$source/$entry", "$dest/$entry");
+                 }
+             }
+          
+             // Clean up
+             $dir->close();
+             return true;
+         }
      }
 ?>

Modified: plugins/trunk/templateeditor/class/view/pluginblogtemplateslistview.class.php
===================================================================
--- plugins/trunk/templateeditor/class/view/pluginblogtemplateslistview.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/class/view/pluginblogtemplateslistview.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -30,28 +30,30 @@
             $blogId = $this->_blogInfo->getId();
             $templateFolder = $ts->getTemplateFolder($this->_templateId, $blogId);
 
-            $cssFiles = Glob::myGlob( $templateFolder, "*.css" );
-            $tplFiles = Glob::myGlob( $templateFolder, "*.template" );
-           
-            $templateFiles = Array();
+			// Get template files according extension
+            $templateFiles = $this->getTemplateFiles( $templateFolder );
 
-            foreach ($cssFiles as $cssFile) {
-                $file['name'] = basename($cssFile);
-                $file['size'] = filesize($cssFile);
-                array_push ($templateFiles, $file);
-            }
-            
-            foreach ($tplFiles as $tplFile) {
-                $file['name'] = basename($tplFile);
-                $file['size'] = filesize($tplFile);
-                array_push ($templateFiles, $file);
-            }
-
             $this->setValue( "currentTemplate", $this->_templateId );
             $this->setValue( "templateSets", $blogTemplateSets );
             $this->setValue( "templateFiles", $templateFiles );
             		
 			parent::render();
 		}
+
+		function getTemplateFiles( $folder ) {
+			$config =& Config::getConfig();
+			$allowedExtension = $config->getValue( "plugin_templateeditor_allowedextension" );   		    
+		    $extensionList = explode(",", $allowedExtension);
+            $templateFiles = Array();
+		    for ($i = 0; $i < count($extensionList); $i++) {
+                $files = Glob::myGlob( $folder, trim($extensionList[$i]) );
+                foreach ($files as $file) {
+                    $tmp['name'] = basename($file);
+                    $tmp['size'] = filesize($file);
+                    array_push ($templateFiles, $tmp);
+                }
+            }
+            return $templateFiles;
+        }		
 	}
 ?>
\ No newline at end of file

Modified: plugins/trunk/templateeditor/class/view/pluginsitetemplateslistview.class.php
===================================================================
--- plugins/trunk/templateeditor/class/view/pluginsitetemplateslistview.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/class/view/pluginsitetemplateslistview.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -30,28 +30,30 @@
             $blogId = $this->_blogInfo->getId();
             $templateFolder = $ts->getTemplateFolder($this->_templateId);
 
-            $cssFiles = Glob::myGlob( $templateFolder, "*.css" );
-            $tplFiles = Glob::myGlob( $templateFolder, "*.template" );
-           
-            $templateFiles = Array();
+			// Get template files according extension
+            $templateFiles = $this->getTemplateFiles( $templateFolder );
 
-            foreach ($cssFiles as $cssFile) {
-                $file['name'] = basename($cssFile);
-                $file['size'] = filesize($cssFile);
-                array_push ($templateFiles, $file);
-            }
-            
-            foreach ($tplFiles as $tplFile) {
-                $file['name'] = basename($tplFile);
-                $file['size'] = filesize($tplFile);
-                array_push ($templateFiles, $file);
-            }
-
             $this->setValue( "currentTemplate", $this->_templateId );
             $this->setValue( "templateSets", $globalTemplates );
             $this->setValue( "templateFiles", $templateFiles );
             		
 			parent::render();
 		}
+		
+		function getTemplateFiles( $folder ) {
+			$config =& Config::getConfig();
+			$allowedExtension = $config->getValue( "plugin_templateeditor_allowedextension" );   		    
+		    $extensionList = explode(",", $allowedExtension);
+            $templateFiles = Array();
+		    for ($i = 0; $i < count($extensionList); $i++) {
+                $files = Glob::myGlob( $folder, trim($extensionList[$i]) );
+                foreach ($files as $file) {
+                    $tmp['name'] = basename($file);
+                    $tmp['size'] = filesize($file);
+                    array_push ($templateFiles, $tmp);
+                }
+            }
+            return $templateFiles;
+        }		    
 	}
 ?>
\ No newline at end of file

Modified: plugins/trunk/templateeditor/class/view/plugintemplateeditorconfigview.class.php
===================================================================
--- plugins/trunk/templateeditor/class/view/plugintemplateeditorconfigview.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/class/view/plugintemplateeditorconfigview.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -20,10 +20,13 @@
 			$pluginEnabled = $config->getValue( "plugin_templateeditor_enabled" );
 			$maxBackupFiles = $config->getValue( "plugin_templateeditor_maxbackupfiles" );
 			if ($maxBackupFiles == "") $maxBackupFiles = 5;
+			$allowedExtension = $config->getValue( "plugin_templateeditor_allowedextension" );
+            if ($allowedExtension == "") $allowedExtension = "*.css,*.inc,*.template,*.txt";
 			
 			// create a view and export the settings to the template
 			$this->setValue( "pluginEnabled", $pluginEnabled );
 			$this->setValue( "maxBackupFiles", $maxBackupFiles );		
+			$this->setValue( "allowedExtension", $allowedExtension );
 			
 			parent::render();
 		}

Modified: plugins/trunk/templateeditor/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/templateeditor/locale/locale_en_UK.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/locale/locale_en_UK.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -10,21 +10,38 @@
 $messages["templateeditor_recover_from"] = "Recover From";
 $messages["templateeditor_plugin_enabled"] = "Allow blog user to use template editor";
 $messages["templateeditor_maxbackupfiles"] = "Max backup files of each template file";
+$messages["templateeditor_allowedextension"] = "Allowed extension for template files";
+$messages["templateeditor_enter_new_templateset_name"] = "Please input your new template name:";
+$messages["templateeditor_enter_new_templatefile_name"] = "Please input your new template file name:";
 
 $messages["error_no_files_selected"] = "No files were selected to delete.";
 $messages["error_removing_template_file"] = "There was an error deleting template file %s.";
 $messages["error_updating_template_file"] = "There was an error updating template file.";
 $messages["error_backup_template_file"] = "There was an error backing up template file.";
 $messages["templateeditor_error_maxbackupfiles"] = "Maximum Backup Files Should > 0!";
+$messages["templateeditor_error_allowedextension"] = "Allowed extension can not be empty.";
+$messages["templateeditor_error_templatefile_name"] = 'Wrong template file name. The file name is limited to a-z, A-Z, "_", "-" and ".", space in file name is not allowed.';
+$messages["templateeditor_error_templatefile_extension"] = "Wrong template extension.";
+$messages["error_duplicate_templatefile_name"] = "Duplicate template file name.";
+$messages["error_copying_templatefile"] = "There was an error copying template file.";
+$messages["templateeditor_error_templateset_name"] = 'Wrong template set name. The set name is limited to a-z, A-Z, "_" and "-", space in set name is not allowed.';
+$messages["error_duplicate_templateset_name"] = "Duplicate template set name.";
+$messages["error_copying_templateset"] = "There was an error copying template set.";
 
 $messages["template_file_removed_ok"] = "Template file %s deleted successfully.";
 $messages["template_files_removed_ok"] = "%s templates files deleted successfully";
 $messages["templateeditor_file_saved_ok"] = "Template file saved successfully.";
 $messages["templateeditor_settings_saved_ok"] = "Templete Editor settings saved successfully!";
+$messages["templateeditor_templatefile_copyed_ok"] = "Template file copyed successfully.";
+$messages["templateeditor_templateset_copyed_ok"] = "Template set copyed successfully.";
 
 $messages["label_configuration"] = "Configuration";
 $messages["label_enable"] = "Enable";
 $messages["label_maxbackupfiles"] = "Backup Files";
+$messages["label_allowedextension"] = "Allowed Extension";
 $messages["label_edit"] = "Edit";
 $messages["label_backupfile"] = "Backup Recover";
+
+$messages["edit"] = "Edit";
+$messages["copy"] = "Copy";
 ?>
\ No newline at end of file

Modified: plugins/trunk/templateeditor/locale/locale_zh_TW.php
===================================================================
--- plugins/trunk/templateeditor/locale/locale_zh_TW.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/locale/locale_zh_TW.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -10,21 +10,38 @@
 $messages["templateeditor_recover_from"] = "回復自";
 $messages["templateeditor_plugin_enabled"] = "允許網誌使用者使用模版編輯器";
 $messages["templateeditor_maxbackupfiles"] = "備份檔案的儲存限制";
+$messages["templateeditor_allowedextension"] = "允許編輯的模版檔案附加檔名";
+$messages["templateeditor_enter_new_templateset_name"] = "請輸入您新的模版名稱:";
+$messages["templateeditor_enter_new_templatefile_name"] = "請輸入您新的模版檔案名稱:";
 
 $messages["error_no_files_selected"] = "您沒有選擇任何模版檔案。";
 $messages["error_removing_template_file"] = "在刪除模版檔案 %s 時發生錯誤。";
 $messages["error_updating_template_file"] = "在更新模版檔案時發生錯誤。";
 $messages["error_backup_template_file"] = "在備份模版檔案時發生錯誤。";
 $messages["templateeditor_error_maxbackupfiles"] = "模版備份檔案儲存限制個數必須要 > 0!";
+$messages["templateeditor_error_allowedextension"] = "允許編輯的模版檔案附加檔名不可為空白。";
+$messages["templateeditor_error_templatefile_name"] = '模版檔案名稱錯誤。必須為英文字、數字、"-"、"_" 與 ".",檔案名稱中也不能有空白。';
+$messages["templateeditor_error_templatefile_extension"] = "模版檔案附加檔名錯誤。";
+$messages["error_duplicate_templatefile_name"] = "重複的模版檔案名稱。";
+$messages["error_copying_templatefile"] = "在複製模版檔案時發生錯誤。";
+$messages["templateeditor_error_templateset_name"] = '模版名稱錯誤。必須為英文字、數字、"-" 與 "_",模版名稱中也不能有空白。';;
+$messages["error_duplicate_templateset_name"] = "重複的模版名稱。";
+$messages["error_copying_templateset"] = "在複製模版時發生錯誤。";
 
 $messages["template_file_removed_ok"] = "模版檔案「%s」已順利刪除。";
 $messages["template_files_removed_ok"] = "已順利刪除「%s」個模版檔案。";
 $messages["templateeditor_file_saved_ok"] = "模版檔案儲存成功。";
 $messages["templateeditor_settings_saved_ok"] = "模版編輯器設定儲存成功。";
+$messages["templateeditor_templatefile_copyed_ok"] = "模版檔案複製成功。";
+$messages["templateeditor_templateset_copyed_ok"] = "模版複製成功。";
 
 $messages["label_configuration"] = "設定";
 $messages["label_enable"] = "啟動";
 $messages["label_maxbackupfiles"] = "模版備份限制";
+$messages["label_allowedextension"] = "附加檔名";
 $messages["label_edit"] = "編輯";
 $messages["label_backupfile"] = "備份回覆";
+
+$messages["edit"] = "編輯";
+$messages["copy"] = "複製";
 ?>
\ No newline at end of file

Modified: plugins/trunk/templateeditor/plugintemplateeditor.class.php
===================================================================
--- plugins/trunk/templateeditor/plugintemplateeditor.class.php	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/plugintemplateeditor.class.php	2005-03-02 19:18:34 UTC (rev 1290)
@@ -27,18 +27,22 @@
             $this->registerAdminAction( "siteTemplateSetsList", "PluginSiteTemplateSetsListAction" );
             $this->registerAdminAction( "siteDeleteTemplateSet", "PluginSiteDeleteTemplateSetsAction" );
             $this->registerAdminAction( "siteDeleteTemplateSets", "PluginSiteDeleteTemplateSetsAction" );
+            $this->registerAdminAction( "siteCopyTemplateSet", "PluginSiteCopyTemplateSetAction" );
             $this->registerAdminAction( "siteTemplatesList", "PluginSiteTemplatesListAction" );
             $this->registerAdminAction( "siteDeleteTemplateFile", "PluginSiteDeleteTemplateFilesAction" );
             $this->registerAdminAction( "siteDeleteTemplateFiles", "PluginSiteDeleteTemplateFilesAction" );
+            $this->registerAdminAction( "siteCopyTemplateFile", "PluginSiteCopyTemplateFileAction" );
             $this->registerAdminAction( "siteEditTemplateFile", "PluginSiteEditTemplateFileAction" );
             $this->registerAdminAction( "siteUpdateTemplateFile", "PluginSiteUpdateTemplateFileAction" );
 
             $this->registerAdminAction( "blogTemplateSetsList", "PluginBlogTemplateSetsListAction" );
             $this->registerAdminAction( "blogDeleteTemplateSet", "PluginBlogDeleteTemplateSetsAction" );
             $this->registerAdminAction( "blogDeleteTemplateSets", "PluginBlogDeleteTemplateSetsAction" );
+            $this->registerAdminAction( "blogCopyTemplateSet", "PluginBlogCopyTemplateSetAction" );
             $this->registerAdminAction( "blogTemplatesList", "PluginBlogTemplatesListAction" );
             $this->registerAdminAction( "blogDeleteTemplateFile", "PluginBlogDeleteTemplateFilesAction" );
             $this->registerAdminAction( "blogDeleteTemplateFiles", "PluginBlogDeleteTemplateFilesAction" );
+            $this->registerAdminAction( "blogCopyTemplateFile", "PluginBlogCopyTemplateFileAction" );
             $this->registerAdminAction( "blogEditTemplateFile", "PluginBlogEditTemplateFileAction" );
             $this->registerAdminAction( "blogUpdateTemplateFile", "PluginBlogUpdateTemplateFileAction" );
             

Modified: plugins/trunk/templateeditor/templates/blogtemplatesetslist.template
===================================================================
--- plugins/trunk/templateeditor/templates/blogtemplatesetslist.template	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/templates/blogtemplatesetslist.template	2005-03-02 19:18:34 UTC (rev 1290)
@@ -1,5 +1,21 @@
 {include file="$admintemplatepath/header.template"}
 {include file="$admintemplatepath/navigation.template" showOpt=BlogTemplateEditor title=$locale->tr("BlogTemplateEditor")}
+<SCRIPT type="text/javascript"> var copyToMessage = '{$locale->tr("templateeditor_enter_new_templateset_name")}'; </SCRIPT>
+{literal}
+<SCRIPT type="text/javascript">
+function copyTemplateSetTo( objId ) {
+    copyToName = prompt(copyToMessage, 'new_' + objId);
+    url = document.getElementById(objId);
+    if (copyToName != '' && copyToName != null) {
+        originUrl = url.getAttribute('href');
+        newUrl = encodeURI(originUrl + '&newTemplateId=' + copyToName);
+        url.setAttribute('href', newUrl);
+    } else {
+        url.setAttribute('href', '?op=blogTemplateSetsList');
+    }
+}
+</SCRIPT>
+{/literal}
  <form id="blogTemplateSetsList" method="post" action="admin.php">
  <div id="list">
   {include file="$admintemplatepath/successmessage.template"}
@@ -29,6 +45,9 @@
       <a href="?op=blogDeleteTemplateSet&amp;templateId={$blogtemplate->getName()}">
         <img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" />
       </a>
+      <a href="?op=blogCopyTemplateSet&amp;templateId={$blogtemplate->getName()}" id="{$blogtemplate->getName()}" onClick="copyTemplateSetTo(this.id)" >
+        <img src="imgs/admin/icon_copy-16.png" alt="{$locale->tr("copy")}" />
+      </a>       
 	  {if $blogtemplate->hasScreenshot()}
 	    <a href="javascript:openScreenshotWindow('{$blogtemplate->getScreenshotUrl()}');">
 		  <img src="imgs/admin/icon_image-16.png" alt="Screenshot" />

Modified: plugins/trunk/templateeditor/templates/blogtemplateslist.template
===================================================================
--- plugins/trunk/templateeditor/templates/blogtemplateslist.template	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/templates/blogtemplateslist.template	2005-03-02 19:18:34 UTC (rev 1290)
@@ -1,6 +1,21 @@
 {include file="$admintemplatepath/header.template"}
 {include file="$admintemplatepath/navigation.template" showOpt=BlogTemplateEditor title=$locale->tr("BlogTemplateEditor")}
-
+<SCRIPT type="text/javascript"> var copyToMessage = '{$locale->tr("templateeditor_enter_new_templatefile_name")}'; </SCRIPT>
+{literal}
+<SCRIPT type="text/javascript">
+function copyTemplateFileTo( objId ) {
+    copyToName = prompt(copyToMessage, 'new_' + objId);
+    url = document.getElementById(objId);
+    if (copyToName != '' && copyToName != null) {
+        originUrl = url.getAttribute('href');
+        newUrl = encodeURI(originUrl + '&newFileId=' + copyToName);
+        url.setAttribute('href', newUrl);
+    } else {
+        url.setAttribute('href', '?op=blogTemplatesList&templateId=' + objId);
+    }
+}
+</SCRIPT>
+{/literal}
 <div id="list_nav_bar">
  <div id="list_nav_select">
   <form id="viewTemplateSets" action="admin.php" method="post">
@@ -59,6 +74,9 @@
       <a href="?op=blogDeleteTemplateFile&amp;templateId={$currentTemplate}&amp;fileId={$file.name}">
         <img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" />
       </a>
+      <a href="?op=blogCopyTemplateFile&amp;templateId={$currentTemplate}&amp;fileId={$file.name}" id="{$file.name}" onClick="copyTemplateFileTo(this.id)" >
+        <img src="imgs/admin/icon_copy-16.png" alt="{$locale->tr("copy")}" />
+      </a>        
      </div>
     </td>
    </tr>

Modified: plugins/trunk/templateeditor/templates/pluginsettings.template
===================================================================
--- plugins/trunk/templateeditor/templates/pluginsettings.template	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/templates/pluginsettings.template	2005-03-02 19:18:34 UTC (rev 1290)
@@ -19,6 +19,13 @@
    <div class="formHelp">{$locale->tr("templateeditor_maxbackupfiles")}</div>
    <input class="text" type="text" name="maxBackupFiles" id="maxBackupFiles" value="{$maxBackupFiles}" width="10" />
   </div>
+
+  <div class="field">
+   <label for="allowedExtension">{$locale->tr("label_allowedextension")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("templateeditor_allowedextension")}</div>
+   <input class="text" type="text" name="allowedExtension" id="allowedExtension" value="{$allowedExtension}" width="10" />
+  </div>  
   
  </fieldset>
  

Modified: plugins/trunk/templateeditor/templates/sitetemplatesetslist.template
===================================================================
--- plugins/trunk/templateeditor/templates/sitetemplatesetslist.template	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/templates/sitetemplatesetslist.template	2005-03-02 19:18:34 UTC (rev 1290)
@@ -1,5 +1,21 @@
 {include file="$admintemplatepath/header.template"}
 {include file="$admintemplatepath/navigation.template" showOpt=SiteTemplateEditor title=$locale->tr("SiteTemplateEditor")}
+<SCRIPT type="text/javascript"> var copyToMessage = '{$locale->tr("templateeditor_enter_new_templateset_name")}'; </SCRIPT>
+{literal}
+<SCRIPT type="text/javascript">
+function copyTemplateSetTo( objId ) {
+    copyToName = prompt(copyToMessage, 'new_' + objId);
+    url = document.getElementById(objId);
+    if (copyToName != '' && copyToName != null) {
+        originUrl = url.getAttribute('href');
+        newUrl = encodeURI(originUrl + '&newTemplateId=' + copyToName);
+        url.setAttribute('href', newUrl);
+    } else {
+        url.setAttribute('href', '?op=siteTemplateSetsList');
+    }
+}
+</SCRIPT>
+{/literal}
  <form id="siteTemplateSetsList" method="post" action="admin.php">
  <div id="list">
   {include file="$admintemplatepath/successmessage.template"}
@@ -29,6 +45,9 @@
       <a href="?op=siteDeleteTemplateSet&amp;templateId={$sitetemplate->getName()}">
         <img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" />
       </a>
+      <a href="?op=siteCopyTemplateSet&amp;templateId={$sitetemplate->getName()}" id="{$sitetemplate->getName()}" onClick="copyTemplateSetTo(this.id)" >
+        <img src="imgs/admin/icon_copy-16.png" alt="{$locale->tr("copy")}" />
+      </a>      
 	  {if $sitetemplate->hasScreenshot()}
 	    <a href="javascript:openScreenshotWindow('{$sitetemplate->getScreenshotUrl()}');">
 		  <img src="imgs/admin/icon_image-16.png" alt="Screenshot" />

Modified: plugins/trunk/templateeditor/templates/sitetemplateslist.template
===================================================================
--- plugins/trunk/templateeditor/templates/sitetemplateslist.template	2005-03-02 18:34:47 UTC (rev 1289)
+++ plugins/trunk/templateeditor/templates/sitetemplateslist.template	2005-03-02 19:18:34 UTC (rev 1290)
@@ -1,6 +1,21 @@
 {include file="$admintemplatepath/header.template"}
 {include file="$admintemplatepath/navigation.template" showOpt=SiteTemplateEditor title=$locale->tr("SiteTemplateEditor")}
-
+<SCRIPT type="text/javascript"> var copyToMessage = '{$locale->tr("templateeditor_enter_new_templatefile_name")}'; </SCRIPT>
+{literal}
+<SCRIPT type="text/javascript">
+function copyTemplateFileTo( objId ) {
+    copyToName = prompt(copyToMessage, 'new_' + objId);
+    url = document.getElementById(objId);
+    if (copyToName != '' && copyToName != null) {
+        originUrl = url.getAttribute('href');
+        newUrl = encodeURI(originUrl + '&newFileId=' + copyToName);
+        url.setAttribute('href', newUrl);
+    } else {
+        url.setAttribute('href', '?op=siteTemplatesList&templateId=' + objId);
+    }
+}
+</SCRIPT>
+{/literal}
 <div id="list_nav_bar">
  <div id="list_nav_select">
   <form id="viewTemplateSets" action="admin.php" method="post">
@@ -59,6 +74,9 @@
       <a href="?op=siteDeleteTemplateFile&amp;templateId={$currentTemplate}&amp;fileId={$file.name}">
         <img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" />
       </a>
+      <a href="?op=siteCopyTemplateFile&amp;templateId={$currentTemplate}&amp;fileId={$file.name}" id="{$file.name}" onClick="copyTemplateFileTo(this.id)" >
+        <img src="imgs/admin/icon_copy-16.png" alt="{$locale->tr("copy")}" />
+      </a>      
      </div>
     </td>
    </tr>




More information about the pLog-svn mailing list