diff options
-rw-r--r-- | phpfspot.class.php | 94 | ||||
-rw-r--r-- | phpfspot_db.php | 23 | ||||
-rw-r--r-- | phpfspot_img.php | 5 | ||||
-rw-r--r-- | themes/default/templates/credits.tpl | 2 |
4 files changed, 93 insertions, 31 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php index 841da50..5e64117 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -32,6 +32,7 @@ class PHPFSPOT { var $tmpl; var $tags; var $avail_tags; + private $dbver; /** * class constructor @@ -58,7 +59,9 @@ class PHPFSPOT { print $this->cfg->fspot_db ." is not writeable for user ". $this->getuid() ."\n"; exit(1); } - + + $this->dbver = $this->getFspotDBVersion(); + if(!is_writeable(dirname($this->cfg->phpfspot_db))) { print dirname($this->cfg->phpfspot_db) .": directory is not writeable!"; exit(1); @@ -266,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 @@ -290,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 @@ -304,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() /** @@ -383,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)) { @@ -431,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]); @@ -1051,6 +1071,7 @@ class PHPFSPOT { { $this->tmpl->assign('version', $this->cfg->version); $this->tmpl->assign('product', $this->cfg->product); + $this->tmpl->assign('db_version', $this->dbver); $this->tmpl->show("credits.tpl"); } // showCredits() @@ -1253,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"); @@ -1267,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:"); $changes = false; @@ -1778,13 +1799,13 @@ class PHPFSPOT { <br> ". $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); ?> <item> - <title><?php print htmlspecialchars($details['name']); ?></title> + <title><?php print htmlspecialchars($this->parse_uri($details['uri'], 'filename')); ?></title> <link><?php print htmlspecialchars($orig_url); ?></link> <guid><?php print htmlspecialchars($orig_url); ?></guid> <dc:date.Taken><?php print strftime("%Y-%m-%dT%H:%M:%S+00:00", $meta_date); ?></dc:date.Taken> @@ -2111,6 +2132,51 @@ class PHPFSPOT { } // checkDbIndices() -} + /** + * retrive F-Spot database version + * + * this function will return the F-Spot database version number + * It is stored within the sqlite3 database in the table meta + */ + public function getFspotDBVersion() + { + if($result = $this->db->db_fetchSingleRow(" + SELECT data as version + FROM meta + WHERE + name LIKE 'F-Spot Database Version' + ")) + return $result['version']; + + return null; + + } // 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_db.php b/phpfspot_db.php index 1f7d597..e9c99ce 100644 --- a/phpfspot_db.php +++ b/phpfspot_db.php @@ -28,6 +28,7 @@ class PHPFSPOT_DB { private $parent; private $is_connected; private $last_error; + private $last_query; /** * PHPFSPOT_DB class constructor @@ -42,7 +43,7 @@ class PHPFSPOT_DB { /* We are starting disconnected */ $this->setConnStatus(false); - /* Connect to MySQL Database */ + /* Connect to database */ $this->db_connect(); } // __construct() @@ -118,6 +119,8 @@ class PHPFSPOT_DB { public function db_query($query = "") { if($this->getConnStatus()) { + + $this->last_query = $query; switch($this->parent->cfg->db_access) { case 'native': @@ -153,6 +156,8 @@ class PHPFSPOT_DB { { if($this->getConnStatus()) { + $this->last_query = $query; + switch($this->parent->cfg->db_access) { case 'native': if(($result = sqlite3_exec($this->db, $query)) === false) @@ -197,7 +202,7 @@ class PHPFSPOT_DB { $result = $this->db_query($query); switch($this->parent->cfg->db_access) { case 'native': - $row = $result->fetchRow(); + $row = $this->db_fetch_object($result); break; case 'pdo': $row = $result[0]; @@ -230,19 +235,6 @@ class PHPFSPOT_DB { } // db_getNumRows() /** - * PHPFSPOT_DB get primary key - * - * This function returns the primary key of the last - * operated insert SQL query. - */ - public function db_getid() - { - /* Get the last primary key ID from execute query */ - return mysql_insert_id($this->db->connection); - - } // db_getid() - - /** * PHPFSPOT_DB check table exists * * This function checks if the given table exists in the @@ -308,6 +300,7 @@ class PHPFSPOT_DB { private function ThrowError($string) { if(!defined('DB_NOERROR')) { + print "Error during query: ". $this->last_query ."<br /><br />\n"; print "<br /><br />". $string ."<br /><br />\n"; try { throw new Exception; 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"); diff --git a/themes/default/templates/credits.tpl b/themes/default/templates/credits.tpl index becdeef..cb01edb 100644 --- a/themes/default/templates/credits.tpl +++ b/themes/default/templates/credits.tpl @@ -17,6 +17,8 @@ <a href="http://wiki.bluga.net/HTML_AJAX/HomePage">HTML_AJAX</a> <hr /> PHP tag-cloud code by <a href="http://prism-perfect.net/archive/php-tag-cloud-tutorial/">Jenny Ferenc</a>. + <hr /> + F-Spot database version: {$db_version} </td> </tr> </table> |