예제 #1
0
 function Comment($fields, $referenced = false)
 {
     parent::PersistentObject($fields, $referenced);
     if (!$this->date) {
         $this->update(array("date" => time()));
     }
 }
예제 #2
0
 function FileReference($fileRef, $referenced = false)
 {
     global $user;
     if (is_int($fileRef)) {
         parent::PersistentObject($fileRef, $referenced);
         $this->baseDir .= "{$this->publicationId}/";
         return $this;
     }
     $fields = array('mimeType' => $fileRef['type'], 'size' => $fileRef['size'], 'publicationId' => $fileRef['publicationId'], 'fileName' => $fileRef['name']);
     parent::PersistentObject($fields, $referenced);
     $this->baseDir .= "{$this->publicationId}/";
     if (!file_exists($this->baseDir)) {
         mkdir($this->baseDir, 0755);
     }
     if ($fileRef['tmp_name'] != $fileRef['name']) {
         if (!move_uploaded_file($fileRef['tmp_name'], $this->fullPath())) {
             // should never happen, unless the file directory (baseDir) doesn't exist
             $this->delete();
             trigger_error("Impossible to move file to {$path}.", E_USER_ERROR);
         }
     }
     $this->extractFileInfo();
     $this->generateThumb();
 }
예제 #3
0
 /**
  * Constructor for a comment
  *
  * @param int $id set to the ID of the comment if not a new one.
  * @return Comment
  */
 function Comment($id = NULL)
 {
     $new = parent::PersistentObject('comments', array('id' => $id), NULL, true, is_null($id));
 }
예제 #4
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)
 {
     // $album is an Album object; it should already be created.
     if (!is_object($album)) {
         return NULL;
     }
     $this->classSetup($album, $filename);
     // Check if the file exists.
     if (!file_exists($this->localpath) || is_dir($this->localpath)) {
         $this->exists = false;
         return NULL;
     }
     // 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));
     $this->getExifData();
     // prime the exif fields
     if ($new) {
         $this->updateDimensions();
         $metadata = getImageMetadata($this->localpath);
         $this->set('EXIFValid', 1);
         $newDate = '';
         if (isset($metadata['date'])) {
             $dt = dateTimeConvert($metadata['date']);
             if ($dt !== false) {
                 // flaw in exif/iptc data?
                 $newDate = $dt;
             }
         }
         if (empty($newDate)) {
             $newDate = strftime('%Y/%m/%d %T', filemtime($this->localpath));
         }
         $this->setDateTime($newDate);
         $alb = $this->album;
         if (!is_null($alb)) {
             if (is_null($alb->getDateTime()) || getOption('album_use_new_image_date')) {
                 $this->album->setDateTime($newDate);
                 //  not necessarily the right one, but will do. Can be changed in Admin
                 $this->album->save();
             }
         }
         if (isset($metadata['title'])) {
             $title = $metadata['title'];
         } else {
             $title = $this->getDefaultTitle();
         }
         $this->set('title', sanitize($title, 2));
         if (isset($metadata['desc'])) {
             $this->set('desc', sanitize($metadata['desc'], 1));
         }
         if (isset($metadata['tags'])) {
             $this->setTags(sanitize($metadata['tags'], 3));
         }
         if (isset($metadata['location'])) {
             $this->setLocation(sanitize($metadata['location'], 3));
         }
         if (isset($metadata['city'])) {
             $this->setCity(sanitize($metadata['city'], 3));
         }
         if (isset($metadata['state'])) {
             $this->setState(sanitize($metadata['state'], 3));
         }
         if (isset($metadata['country'])) {
             $this->setCountry(sanitize($metadata['country'], 3));
         }
         if (isset($metadata['credit'])) {
             $this->setCredit(sanitize($metadata['credit'], 1));
         }
         if (isset($metadata['copyright'])) {
             $this->setCopyright(sanitize($metadata['copyright'], 1));
         }
         $this->set('mtime', filemtime($this->localpath));
         apply_filter('new_image', $this);
         $this->save();
     }
 }
예제 #5
0
 /**
  * Constructor for an Administrator
  *
  * @param string $user.
  * @param int $valid used to signal kind of admin object
  * @return Administrator
  */
 function Zenphoto_Administrator($user, $valid)
 {
     global $_zp_authority;
     parent::PersistentObject('administrators', array('user' => $user, 'valid' => $valid), NULL, false, empty($user));
     if ($valid && $user == $_zp_authority->master_user) {
         $this->setRights($this->getRights() | ADMIN_RIGHTS);
         $this->master = true;
     }
 }
예제 #6
0
 /**
  * Constructor for albums
  *
  * @param object &$gallery The parent gallery
  * @param string $folder folder name of the album
  * @param bool $cache load from cache if present
  * @return Album
  */
 function Album(&$gallery, $folder, $cache = true)
 {
     $folder = sanitize_path($folder);
     $this->name = $folder;
     $this->gallery =& $gallery;
     if (empty($folder)) {
         $this->localpath = getAlbumFolder();
     } else {
         $this->localpath = getAlbumFolder() . UTF8ToFilesystem($folder) . "/";
     }
     if (hasDyanmicAlbumSuffix($folder)) {
         $this->localpath = substr($this->localpath, 0, -1);
     }
     // Second defense against upward folder traversal:
     if (!file_exists($this->localpath) || strpos($this->localpath, '..') !== false) {
         $this->exists = false;
         return NULL;
     }
     $new = parent::PersistentObject('albums', array('folder' => $this->name), 'folder', $cache, empty($folder));
     if (hasDyanmicAlbumSuffix($folder)) {
         if ($new || filemtime($this->localpath) > $this->get('mtime')) {
             $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 (!empty($words)) {
                 if (empty($fields)) {
                     $fields = '&searchfields=4';
                 }
                 $this->set('search_params', $words . $fields);
             }
             $this->set('dynamic', 1);
             $this->set('mtime', filemtime($this->localpath));
             if ($new) {
                 $title = $this->get('title');
                 $this->set('title', substr($title, 0, -4));
                 $this->setDateTime(strftime('%Y/%m/%d %T', filemtime($this->localpath)));
             }
             $this->folder = $folder;
             $this->save();
         }
     }
     if ($new) {
         apply_filter('new_album', $this);
     }
 }