Exemplo n.º 1
0
 /**
  * Moves a file or folder from destination to target
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return	
  */
 public function move($source, $target)
 {
     $sourceUri = EasyBlogMediaManager::getUri($source);
     $targetUri = EasyBlogMediaManager::getUri($target);
     // Get the absolute paths
     $sourcePath = EasyBlogMediaManager::getPath($sourceUri);
     $targetPath = EasyBlogMediaManager::getPath($targetUri);
     // Get the new filename
     $newFileName = basename($sourcePath);
     // Get the absolute path to the target file / folder
     $newTargetPath = $targetPath . '/' . $newFileName;
     $newTargetUri = $targetUri . '/' . $newFileName;
     // Get the item details
     $item = $this->getItem($sourceUri);
     // Test if the source items really exists
     if ($item->type == 'folder' && !JFolder::exists($sourcePath)) {
         return EB::exception('Unable to locate source folder to move.');
     }
     // Test if the source items really exists
     if ($item->type != 'folder' && !JFile::exists($sourcePath)) {
         return EB::exception('Unable to locate source file to move.');
     }
     // Test for target path
     if ($item->type == 'folder' && JFolder::exists($newTargetPath)) {
         return EB::exception('A folder with the same name exists on the specified target path.');
     }
     if ($item->type != 'folder' && JFile::exists($newTargetPath)) {
         return EB::exception('A file with the same name exists on the specified target path.');
     }
     // If this is a folder, just move the folder
     if ($item->type == 'folder') {
         $state = JFolder::move($sourcePath, $newTargetPath);
         if (!$state) {
             return EB::exception('Unable to move folder.');
         }
     }
     // Move the file
     if ($item->type != 'folder') {
         JFile::move($sourcePath, $newTargetPath);
         // Move variations
         if ($item->type == 'image') {
             // For images, we want to rename the variations as well.
             if ($item->type == 'image' && isset($item->variations)) {
                 foreach ($item->variations as $key => $variation) {
                     if ($key == 'system/original') {
                         continue;
                     }
                     // Get the new uri
                     $newUri = $targetUri . '/' . EBLOG_SYSTEM_VARIATION_PREFIX . '_' . $variation->name . '_' . $newFileName;
                     $target = EasyBlogMediaManager::getPath($newUri);
                     // Get the original file for the variation
                     $source = EasyBlogMediaManager::getPath($variation->uri);
                     // Check if the file exists first
                     if (!JFile::exists($source)) {
                         continue;
                     }
                     // Try to move the file now
                     $state = JFile::move($source, $target);
                 }
             }
         }
     }
     // Get the new item info about the moved object
     $item = $this->getItem($newTargetUri);
     return $item;
 }