Ejemplo n.º 1
0
 /**
  * Constructor for albums
  *
  * @param object &$gallery The parent gallery
  * @param string $folder8 folder name (UTF8) of the album
  * @param bool $cache load from cache if present
  * @return Album
  */
 function Album(&$gallery, $folder8, $cache = true, $quiet = false)
 {
     if (!is_object($gallery) || strtolower(get_class($gallery)) != 'gallery') {
         $msg = sprintf(gettext('Bad gallery in instantiation of album %s.'), $folder8);
         debugLogBacktrace($msg);
         trigger_error(html_encode($msg), E_USER_NOTICE);
         $gallery = new Gallery();
     }
     $folder8 = sanitize_path($folder8);
     $folderFS = internalToFilesystem($folder8);
     $this->gallery =& $gallery;
     if (empty($folder8)) {
         $localpath = ALBUM_FOLDER_SERVERPATH;
     } else {
         $localpath = ALBUM_FOLDER_SERVERPATH . $folderFS . "/";
     }
     if (filesystemToInternal($folderFS) != $folder8) {
         // an attempt to spoof the album name.
         $this->exists = false;
         $msg = sprintf(gettext('Zenphoto encountered an album name spoof attempt: %1$s=>%2$s.'), filesystemToInternal($folderFS), $folder8);
         debugLogBacktrace($msg);
         trigger_error(html_encode($msg), E_USER_NOTICE);
         return;
     }
     if ($dynamic = hasDynamicAlbumSuffix($folder8)) {
         $localpath = substr($localpath, 0, -1);
         $this->set('dynamic', 1);
     }
     // Must be a valid (local) folder:
     if (!file_exists($localpath) || !($dynamic || is_dir($localpath))) {
         $this->exists = false;
         if (!$quiet) {
             $msg = sprintf(gettext('class-album detected an invalid folder name: %s.'), $folder8);
             debugLogBacktrace($msg);
             trigger_error(html_encode($msg), E_USER_NOTICE);
         }
         return;
     }
     $this->localpath = $localpath;
     $this->name = $folder8;
     $new = parent::PersistentObject('albums', array('folder' => $this->name), 'folder', $cache, empty($folder8));
     if ($dynamic) {
         $new = !$this->get('search_params');
         if ($new || filemtime($this->localpath) > $this->get('mtime')) {
             $constraints = '';
             $data = file_get_contents($this->localpath);
             while (!empty($data)) {
                 $data1 = trim(substr($data, 0, $i = strpos($data, "\n")));
                 if ($i === false) {
                     $data1 = $data;
                     $data = '';
                 } else {
                     $data = substr($data, $i + 1);
                 }
                 if (strpos($data1, 'WORDS=') !== false) {
                     $words = "words=" . urlencode(substr($data1, 6));
                 }
                 if (strpos($data1, 'THUMB=') !== false) {
                     $thumb = trim(substr($data1, 6));
                     $this->set('thumb', $thumb);
                 }
                 if (strpos($data1, 'FIELDS=') !== false) {
                     $fields = "&searchfields=" . trim(substr($data1, 7));
                 }
                 if (strpos($data1, 'CONSTRAINTS=') !== false) {
                     $constraints = '&' . trim(substr($data1, 12));
                 }
             }
             if (!empty($words)) {
                 if (empty($fields)) {
                     $fields = '&searchfields=tags';
                 }
                 $this->set('search_params', $words . $fields . $constraints);
             }
             $this->set('mtime', filemtime($this->localpath));
             if ($new) {
                 $title = $this->get('title');
                 $this->set('title', substr($title, 0, -4));
                 // Strip the .'.alb' suffix
                 $this->setDateTime(strftime('%Y-%m-%d %H:%M:%S', $this->get('mtime')));
             }
             $this->set('dynamic', 1);
         }
     }
     if ($new) {
         $this->save();
         zp_apply_filter('new_album', $this);
     }
     zp_apply_filter('album_instantiate', $this);
 }
Ejemplo n.º 2
0
 /**
  * Constructor for class-image
  *
  * Do not call this constructor directly unless you really know what you are doing!
  * Use instead the function newImage() which will instantiate an object of the
  * correct class for the file type.
  *
  * @param object &$album the owning album
  * @param sting $filename the filename of the image
  * @return Image
  */
 function _Image(&$album, $filename)
 {
     global $_zp_current_admin_obj;
     // $album is an Album object; it should already be created.
     if (!is_object($album)) {
         return NULL;
     }
     if (!$this->classSetup($album, $filename)) {
         // spoof attempt
         $this->exists = false;
         return;
     }
     // Check if the file exists.
     if (!file_exists($this->localpath) || is_dir($this->localpath)) {
         $this->exists = false;
         return;
     }
     // This is where the magic happens...
     $album_name = $album->name;
     $new = parent::PersistentObject('images', array('filename' => $filename, 'albumid' => $this->album->id), 'filename', false, empty($album_name));
     $mtime = filemtime($this->localpath);
     if ($new || $mtime != $this->get('mtime')) {
         $this->setShow(getOption('image_publish'));
         $this->set('mtime', $mtime);
         $this->updateMetaData();
         // extract info from image
         $this->updateDimensions();
         // deal with rotation issues
         $this->save();
         if ($new) {
             zp_apply_filter('new_image', $this);
         }
     }
 }