Exemple #1
0
 public function getLocalPath($path_to_media)
 {
     $c = $this->getCollection();
     $subdir = Dase_Util::getSubdir($this->p_serial_number);
     $path = $path_to_media . '/' . $c->ascii_id . '/' . $this->size . '/' . $subdir . '/' . $this->filename;
     if (file_exists($path)) {
         return $path;
     } else {
         $path = $path_to_media . '/' . $c->ascii_id . '/' . $this->size . '/' . $this->filename;
         return $path;
     }
 }
Exemple #2
0
 public function saveAtomFile($path_to_media)
 {
     $subdir = Dase_Util::getSubdir($this->serial_number);
     $path = $path_to_media . '/' . $this->p_collection_ascii_id . '/atom/' . $subdir;
     if (!file_exists($path)) {
         mkdir($path);
     }
     $filename = $this->serial_number . '.atom';
     $app_root = '{APP_ROOT}';
     $entry = new Dase_Atom_Entry_Item();
     $entry = $this->injectAtomEntryData($entry, $app_root);
     if (file_put_contents($path . '/' . $filename, $entry->asXml($entry->root))) {
         return $path . '/' . $filename;
     }
 }
Exemple #3
0
 public function addToCollection($item, $check_for_dups, $path_to_media)
 {
     $c = $item->getCollection();
     $metadata = $this->getMetadata();
     //prevents 2 files in same collection w/ same md5
     if ($check_for_dups) {
         $prefix = $this->db->table_prefix;
         $sql = "\n\t\t\t\tSELECT v.value_text\n\t\t\t\tFROM {$prefix}value v, {$prefix}item i, {$prefix}attribute a\n\t\t\t\tWHERE i.collection_id = ?\n\t\t\t\tAND a.ascii_id = ?\n\t\t\t\tAND v.attribute_id = a.id\n\t\t\t\tAND i.id = v.item_id\n\t\t\t\tAND v.value_text = ?\n\t\t\t\tLIMIT 1\n\t\t\t\t";
         $hash = $metadata['md5'];
         $dbh = $this->db->getDbh();
         $sth = $dbh->prepare($sql);
         $sth->execute(array($c->id, 'admin_checksum', $hash));
         $row = $sth->fetch();
         if ($row && $row['value_text']) {
             throw new Exception('duplicate file');
         }
     }
     $subdir = Dase_Util::getSubdir($item->serial_number);
     $subdir_path = $path_to_media . '/' . $c->ascii_id . '/' . $this->size . '/' . $subdir;
     if (!file_exists($subdir_path)) {
         mkdir($subdir_path);
     }
     $target = $path_to_media . '/' . $c->ascii_id . '/' . $this->size . '/' . $subdir . '/' . $item->serial_number . '.' . $this->ext;
     if (file_exists($target)) {
         //make a timestamped backup
         copy($target, $target . '.bak.' . time());
     }
     //should this be try-catch?
     if ($this->copyTo($target)) {
         $media_file = new Dase_DBO_MediaFile($this->db);
         $mediafile_meta = array('file_size', 'height', 'width', 'mime_type', 'updated', 'md5');
         foreach ($mediafile_meta as $term) {
             if (isset($metadata[$term])) {
                 $media_file->{$term} = $metadata[$term];
             }
         }
         $media_file->item_id = $item->id;
         $media_file->filename = $item->serial_number . '.' . $this->ext;
         $media_file->size = $this->size;
         $media_file->p_serial_number = $item->serial_number;
         $media_file->p_collection_ascii_id = $c->ascii_id;
         $media_file->insert();
         //will only insert item metadata when attribute name matches 'admin_'+att_name
         foreach ($metadata as $term => $text) {
             //catches UTF8 errors in exif/iptc data
             //actually, no it doesn't :(
             try {
                 $item->setValue('admin_' . $term, $text);
             } catch (Exception $e) {
                 Dase_Log::debug(LOG_FILE, "could not write admin {$term}: {$text} ERROR: " . $e->getMessage());
             }
         }
     }
     return $media_file;
 }
Exemple #4
0
 function makeSizes($item, $path_to_media, $rotate)
 {
     $collection = $item->getCollection();
     $image_properties = array('small' => array('geometry' => '640x480', 'max_height' => '480', 'size_tag' => '_640'), 'medium' => array('geometry' => '800x600', 'max_height' => '600', 'size_tag' => '_800'), 'large' => array('geometry' => '1024x768', 'max_height' => '768', 'size_tag' => '_1024'), 'full' => array('geometry' => '3600x2700', 'max_height' => '2700', 'size_tag' => '_3600'));
     $last_width = '';
     $last_height = '';
     $subdir = Dase_Util::getSubdir($item->serial_number);
     foreach ($image_properties as $size => $size_info) {
         $newimage = $path_to_media . '/' . $collection->ascii_id . '/' . $size . '/' . $subdir . '/' . $item->serial_number . $size_info['size_tag'] . '.jpg';
         $subdir_path = $path_to_media . '/' . $collection->ascii_id . '/' . $size . '/' . $subdir;
         if (!file_exists($subdir_path)) {
             mkdir($subdir_path);
         }
         $command = CONVERT . " \"{$this->filepath}\" -format jpeg -rotate {$rotate} -resize '{$size_info['geometry']} >' -colorspace RGB {$newimage}";
         $exec_output = array();
         $results = exec($command, $exec_output);
         if (!file_exists($newimage)) {
             Dase_Log::debug(LOG_FILE, "failed to write {$size} image");
             Dase_Log::debug(LOG_FILE, "UNSUCCESSFUL: {$command}");
         }
         $file_info = getimagesize($newimage);
         //create the media_file entry
         $media_file = new Dase_DBO_MediaFile($this->db);
         $media_file->item_id = $item->id;
         $media_file->filename = $item->serial_number . $size_info['size_tag'] . ".jpg";
         if ($file_info) {
             $media_file->width = $file_info[0];
             $media_file->height = $file_info[1];
         }
         if ($media_file->width <= $last_width && $media_file->height <= $last_height) {
             return;
         }
         $last_width = $media_file->width;
         $last_height = $media_file->height;
         $media_file->mime_type = 'image/jpeg';
         $media_file->size = $size;
         $media_file->md5 = md5_file($newimage);
         $media_file->updated = date(DATE_ATOM);
         $media_file->file_size = filesize($newimage);
         $media_file->p_collection_ascii_id = $collection->ascii_id;
         $media_file->p_serial_number = $item->serial_number;
         $media_file->insert();
         Dase_Log::info(LOG_FILE, "created {$media_file->size} {$media_file->filename}");
     }
     return;
 }
Exemple #5
0
 private function _getFilePath($collection_ascii_id, $serial_number, $size, $format)
 {
     //look first in subdir
     //get serial number w/o size extension
     $subdir = Dase_Util::getSubdir($this->_fixSizeExt($serial_number, $size));
     $path = MEDIA_DIR . '/' . $collection_ascii_id . '/' . $size . '/' . $subdir . '/' . $serial_number . '.' . $format;
     if (file_exists($path)) {
         return $path;
     } else {
         $path = MEDIA_DIR . '/' . $collection_ascii_id . '/' . $size . '/' . $serial_number . '.' . $format;
         return $path;
     }
 }