Esempio n. 1
0
 /**
  * Copy this album to the location specified by $newfolder, copying all
  * metadata, subalbums, and subalbums' metadata with it.
  * @param $newfolder string the folder to copy to, including the name of the current folder (possibly renamed).
  * @return int 0 on success and error indicator on failure.
  *
  */
 function copy($newfolder)
 {
     // album name to destination folder
     if (substr($newfolder, -1, 1) != '/') {
         $newfolder .= '/';
     }
     $newfolder .= basename($this->localpath);
     // First, ensure the new base directory exists.
     $oldfolder = $this->name;
     $dest = ALBUM_FOLDER_SERVERPATH . internalToFilesystem($newfolder);
     // Check to see if the destination directory already exists
     if (file_exists($dest)) {
         // Disallow moving an album over an existing one.
         return 3;
     }
     if (substr($newfolder, count($oldfolder)) == $oldfolder) {
         // Disallow copying to a subfolder of the current folder (infinite loop).
         return 4;
     }
     $success = $this->succeed($dest);
     $filemask = substr($this->localpath, 0, -1) . '.*';
     if ($success) {
         //	replicate the album metadata and sub-files
         $uniqueset = array('folder' => $newfolder);
         $parentname = dirname($newfolder);
         if (empty($parentname) || $parentname == '/' || $parentname == '.') {
             $uniqueset['parentid'] = NULL;
         } else {
             $parent = newAlbum($parentname);
             $uniqueset['parentid'] = $parent->getID();
         }
         $newID = parent::copy($uniqueset);
         if ($newID) {
             //	replicate the tags
             storeTags(readTags($this->getID(), 'albums'), $newID, 'albums');
             //	copy the sidecar files
             $filestocopy = safe_glob($filemask);
             foreach ($filestocopy as $file) {
                 if (in_array(strtolower(getSuffix($file)), $this->sidecars)) {
                     $success = $success && @copy($file, dirname($dest) . '/' . basename($file));
                 }
             }
         }
     }
     if ($success) {
         return 0;
     } else {
         return 1;
     }
 }
Esempio n. 2
0
 /**
  * Copies the image to a new album, along with all metadata.
  *
  * @param string $newalbum the destination album
  */
 function copy($newalbum)
 {
     if (is_string($newalbum)) {
         $newalbum = new Album($this->album->gallery, $newalbum, false);
     }
     if ($newalbum->id == $this->album->id) {
         // Nothing to do - moving the file to the same place.
         return 2;
     }
     $newpath = $newalbum->localpath . internalToFilesystem($this->filename);
     if (file_exists($newpath)) {
         // If the file exists, don't overwrite it.
         return 2;
     }
     $filename = basename($this->localpath);
     $result = @copy($this->localpath, $newpath);
     if ($result) {
         $filestocopy = safe_glob(substr($this->localpath, 0, strrpos($this->localpath, '.')) . '.*');
         foreach ($filestocopy as $file) {
             if (in_array(strtolower(getSuffix($file)), $this->sidecars)) {
                 $result = $result && @copy($file, $newalbum->localpath . basename($file));
             }
         }
     }
     if ($result) {
         if ($newID = parent::copy(array('filename' => $filename, 'albumid' => $newalbum->id))) {
             storeTags(readTags($this->getID(), 'images'), $newID, 'images');
             query('UPDATE ' . prefix('images') . ' SET `mtime`=' . filemtime($newpath) . ' WHERE `filename`="' . $filename . '" AND `albumid`=' . $newalbum->id);
             return 0;
         }
     }
     return 1;
 }