X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot.class.php;h=5e641172d6c0157cb0ec1d2a3892cb3961bc5a8a;hp=a2ef4661e8f60dcc0129df8e11f0a06d675b4416;hb=431b2c5f99629be3a4d311ce07f9a7d7ebf96375;hpb=1a8de008cd10b695444681c5f0d87514ffbb5e51
diff --git a/phpfspot.class.php b/phpfspot.class.php
index a2ef466..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
@@ -54,7 +55,13 @@ class PHPFSPOT {
}
$this->db = new PHPFSPOT_DB($this, $this->cfg->fspot_db);
-
+ if(!is_writeable($this->cfg->fspot_db)) {
+ 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);
@@ -79,8 +86,6 @@ class PHPFSPOT {
/* check if all necessary indices exist */
$this->checkDbIndices();
- $this->get_tags();
-
session_start();
if(!isset($_SESSION['tag_condition']))
@@ -264,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
@@ -288,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
@@ -302,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()
/**
@@ -381,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)) {
@@ -429,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]);
@@ -475,6 +497,8 @@ class PHPFSPOT {
*/
public function getAvailableTags()
{
+ $this->get_tags();
+
$output = "";
$result = $this->db->db_query("
@@ -544,6 +568,8 @@ class PHPFSPOT {
*/
public function getSelectedTags()
{
+ $this->get_tags();
+
$output = "";
foreach($this->avail_tags as $tag)
{
@@ -1045,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()
@@ -1247,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");
@@ -1261,7 +1288,9 @@ 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;
foreach($resolutions as $resolution) {
@@ -1278,6 +1307,8 @@ class PHPFSPOT {
$this->_debug(" ". $resolution ."px");
if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
$error = 1;
+
+ $changes = true;
}
/* if the file hasn't changed there is no need to regen the thumb */
elseif($file_md5 != $this->getMD5($idx) || $force) {
@@ -1286,9 +1317,14 @@ class PHPFSPOT {
if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
$error = 1;
+ $changes = true;
}
}
+ if(!$changes) {
+ $this->_debug(" already exist");
+ }
+
/* set the new/changed MD5 sum for the current photo */
if(!$error) {
$this->setMD5($idx, $file_md5);
@@ -1355,6 +1391,8 @@ class PHPFSPOT {
*/
public function startSearch($searchfor, $sort_order, $from = 0, $to = 0)
{
+ $this->get_tags();
+
$_SESSION['searchfor'] = $searchfor;
$_SESSION['sort_order'] = $sort_order;
if($from != 0)
@@ -1761,13 +1799,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);
?>
-
-
+ parse_uri($details['uri'], 'filename')); ?>
@@ -2094,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
?>