From: Andreas Unterkircher Date: Sun, 30 Dec 2007 11:01:31 +0000 (+0100) Subject: issue82, switch picture handling to URI which is necessary for newer f-spot version's. X-Git-Tag: phpfspot-1.2~16 X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=commitdiff_plain;h=18ff7e0419aebe37fcebdbfb180550acb118c0cb;ds=sidebyside issue82, switch picture handling to URI which is necessary for newer f-spot version's. for older database version's (< 9), the URI will be generated with file:///dir/name. Still needs to be tested with a older database version --- diff --git a/phpfspot.class.php b/phpfspot.class.php index 6d357e5..ea91b01 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -269,10 +269,18 @@ class PHPFSPOT { */ public function get_photo_details($idx) { - $query_str = " - SELECT p.id, p.name, p.time, p.directory_path, p.description - FROM photos p - "; + if($this->dbver < 9) { + $query_str = " + SELECT p.id, p.name, p.time, p.directory_path, p.description + FROM photos p + "; + } + else { + $query_str = " + SELECT p.id, p.uri, p.time, p.description + FROM photos p + "; + } /* if show_tags is set, only return details for photos which are specified to be shown @@ -293,6 +301,11 @@ class PHPFSPOT { } $result = $this->db->db_query($query_str); + + if($this->dbver < 9) { + $result['uri'] = "file://". $result['directory_path'] ."/". $result['name']; + } + return $this->db->db_fetch_object($result); } // get_photo_details @@ -307,10 +320,14 @@ class PHPFSPOT { public function getPhotoName($idx, $limit = 0) { if($details = $this->get_photo_details($idx)) { - $name = $this->shrink_text($details['name'], $limit); - return $name; + if($long_name = $this->parse_uri($details['uri'], 'filename')) { + $name = $this->shrink_text($long_name, $limit); + return $name; + } } + return null; + } // getPhotoName() /** @@ -386,7 +403,7 @@ class PHPFSPOT { return; } - $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name']; + $orig_path = $this->translate_path($this->parse_uri($details['uri'], 'fullpath')); $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo); if(!file_exists($orig_path)) { @@ -434,7 +451,7 @@ class PHPFSPOT { $info = getimagesize($thumb_path); $this->tmpl->assign('description', $details['description']); - $this->tmpl->assign('image_name', $details['name']); + $this->tmpl->assign('image_name', $this->parse_uri($details['uri'], 'filename')); $this->tmpl->assign('width', $info[0]); $this->tmpl->assign('height', $info[1]); @@ -1257,7 +1274,7 @@ class PHPFSPOT { $details = $this->get_photo_details($idx); /* calculate file MD5 sum */ - $full_path = $this->translate_path($details['directory_path']) ."/". $details['name']; + $full_path = $this->translate_path($this->parse_uri($details['uri'], 'fullpath')); if(!file_exists($full_path)) { $this->_error("File ". $full_path ." does not exist\n"); @@ -1271,7 +1288,7 @@ class PHPFSPOT { $file_md5 = md5_file($full_path); - $this->_debug("Image [". $idx ."] ". $this->shrink_text($details['name'], 20) ." Thumbnails:"); + $this->_debug("Image [". $idx ."] ". $this->shrink_text($this->parse_uri($details['uri'], 'filename'), 20) ." Thumbnails:"); foreach($resolutions as $resolution) { @@ -1773,13 +1790,13 @@ class PHPFSPOT {
". $details['description']); - $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name']; + $orig_path = $this->translate_path($this->parse_uri($details['uri'], 'fullpath')); $meta = $this->get_meta_informations($orig_path); $meta_date = isset($meta['FileDateTime']) ? $meta['FileDateTime'] : filemtime($orig_path); ?> - <?php print htmlspecialchars($details['name']); ?> + <?php print htmlspecialchars($this->parse_uri($details['uri'], 'filename')); ?> @@ -2126,6 +2143,31 @@ class PHPFSPOT { } // getFspotDBVersion() + /** + * parse the provided URI and will returned the + * requested chunk + */ + public function parse_uri($uri, $mode) + { + if(($components = parse_url($uri)) !== false) { + + switch($mode) { + case 'filename': + return basename($components['path']); + break; + case 'dirname': + return dirname($components['path']); + break; + case 'fullpath': + return $components['path']; + break; + } + } + + return $uri; + + } // parse_uri() + } // class PHPFSPOT ?> diff --git a/phpfspot_img.php b/phpfspot_img.php index ce3731b..8251b8e 100644 --- a/phpfspot_img.php +++ b/phpfspot_img.php @@ -68,7 +68,7 @@ class PHPFSPOT_IMG { /* no width specified - show photo in its original size */ if($width == 0) { - $fullpath = $this->parent->translate_path($details['directory_path']) ."/". $details['name']; + $fullpath = $this->parent->translate_path($this->parent->parse_uri($details['uri'], 'fullpath')); } /* show thumbnail */ else { @@ -103,7 +103,8 @@ class PHPFSPOT_IMG { Header("Content-Type: ". $mime); Header("Content-Length: ". filesize($fullpath)); Header("Content-Transfer-Encoding: binary\n"); - Header("Content-Disposition: inline; filename=\"". $details['name'] ."\""); + Header("Content-Disposition: inline; filename=\"". $this->parent->parse_uri($details['uri'], 'filename') ."\""); + Header("Content-Description: ". $this->parent->parse_uri($details['uri'], 'filename')); Header("Accept-Ranges: bytes"); Header("Connection: close"); Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");