[pLog-svn] r6204 - in plog/trunk/class: action/admin file

mark at devel.lifetype.net mark at devel.lifetype.net
Mon Mar 3 04:02:26 EST 2008


Author: mark
Date: 2008-03-03 04:02:26 -0500 (Mon, 03 Mar 2008)
New Revision: 6204

Modified:
   plog/trunk/class/action/admin/admincopyblogtemplatesetaction.class.php
   plog/trunk/class/action/admin/admincopytemplatesetaction.class.php
   plog/trunk/class/file/file.class.php
Log:
Fixed copy function in template editor.

Modified: plog/trunk/class/action/admin/admincopyblogtemplatesetaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincopyblogtemplatesetaction.class.php	2008-03-03 07:06:19 UTC (rev 6203)
+++ plog/trunk/class/action/admin/admincopyblogtemplatesetaction.class.php	2008-03-03 09:02:26 UTC (rev 6204)
@@ -96,35 +96,16 @@
 				$this->_message = $this->_locale->tr( "error_blog_template_folder_not_writable" );
 				return false;				
 			}
-
-			if( !File::createDir( $newTemplateFolder ))
-				return( false );
-			
-			$ts = new TemplateSetStorage();
-			
-			$dir = new DirectoryTreeIterator( $path );
-			foreach( $dir as $file ) {
-				// prepare the destination file name
-				$destFile = $newTemplateFolder . "/" . str_replace( $path, "", $file );
-				
-				// check if the destination folder exists
-				if( !File::exists( dirname( $destFile ))) {
-					if( !File::createDir( dirname( $destFile ), File::FILE_DEFAULT_DIRECTORY_CREATION_MODE, true )) {
-						return false;
-					}
-				}
-				
-				// and finally perform the copy
-				if( !File::isDir( $file, $destFile )) {
-					if( !File::copy( $file, $destFile )) {		
-							return false;
-					}
-				}
+		
+			if( File::copyDir($path, $newTemplateFolder) )
+				$ts = new TemplateSetStorage();
+				$ts->addTemplate( $this->_destTemplate, $this->_blogInfo->getId());
+			} else
+				File::deleteDir($newTemplateFolder);
+				$this->_message = $this->_locale->tr( "error_copying_template_set" );
+				return false;
 			}
 			
-			// add the new template as a global one
-			$ts->addTemplate( $this->_destTemplate, $this->_blogInfo->getId());
-			
 			return( true );
 		}	
 		

Modified: plog/trunk/class/action/admin/admincopytemplatesetaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincopytemplatesetaction.class.php	2008-03-03 07:06:19 UTC (rev 6203)
+++ plog/trunk/class/action/admin/admincopytemplatesetaction.class.php	2008-03-03 09:02:26 UTC (rev 6204)
@@ -59,38 +59,18 @@
 		
 		function copyTemplateSet()
 		{
-			
-			
 			$path = TemplateSetStorage::getTemplateFolder( $this->_templateId);
 			$newTemplateFolder = TemplateSetStorage::getBaseTemplateFolder() . "/" . $this->_destTemplate;
-			if( !File::createDir( $newTemplateFolder ))
-				return( false );
-			
-			$ts = new TemplateSetStorage();
-			
-			$dir = new DirectoryTreeIterator( $path );
-			foreach( $dir as $file ) {
-				// prepare the destination file name
-				$destFile = $newTemplateFolder . "/" . str_replace( $path, "", $file );
-				
-				// check if the destination folder exists
-				if( !File::exists( dirname( $destFile ))) {
-					if( !File::createDir( dirname( $destFile ), File::FILE_DEFAULT_DIRECTORY_CREATION_MODE, true )) {
-						return false;
-					}
-				}
-				
-				// and finally perform the copy
-				if( !File::isDir( $file, $destFile )) {
-					if( !File::copy( $file, $destFile )) {		
-							return false;
-					}
-				}
+
+			if( File::copyDir($path, $newTemplateFolder) )
+				$ts = new TemplateSetStorage();
+				$ts->addTemplate( $this->_destTemplate, 0);
+			} else
+				File::deleteDir($newTemplateFolder);
+				$this->_message = $this->_locale->tr( "error_copying_template_set" );
+				return false;
 			}
 			
-			// add the new template as a global one
-			$ts->addTemplate( $this->_destTemplate, 0 );
-			
 			return( true );
 		}	
 		

Modified: plog/trunk/class/file/file.class.php
===================================================================
--- plog/trunk/class/file/file.class.php	2008-03-03 07:06:19 UTC (rev 6203)
+++ plog/trunk/class/file/file.class.php	2008-03-03 09:02:26 UTC (rev 6204)
@@ -539,5 +539,48 @@
 
 			return( $result );
 		}
+
+         /**
+          * 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, File::FILE_DEFAULT_DIRECTORY_CREATION_MODE, true);
+             }
+          
+             // 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") {
+                     File::copyDir("$source/$entry", "$dest/$entry");
+                 }
+             }
+          
+             // Clean up
+             $dir->close();
+             return true;
+         }
 	 }
 ?>



More information about the pLog-svn mailing list