X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot.class.php;h=92c0fd2e69da2efa3c1d5a86a82f087f346d43dd;hp=d2bb907009a9a29d98809247f7699b1aecb65425;hb=37d9c8bf7eb7c4244f93d9ed780333ec1fa4ae86;hpb=f3f12303def5f19118f086ca465d67032dc57706
diff --git a/phpfspot.class.php b/phpfspot.class.php
index d2bb907..92c0fd2 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -122,7 +122,8 @@ class PHPFSPOT {
/* set application name and version information */
$this->cfg->product = "phpfspot";
- $this->cfg->version = "1.5";
+ $this->cfg->version = "1.7";
+ $this->cfg->db_version = 2;
$this->sort_orders= array(
'date_asc' => 'Date ↑',
@@ -142,7 +143,9 @@ class PHPFSPOT {
/* Check if database file is writeable */
if(!is_writeable($this->cfg->fspot_db)) {
- print $this->cfg->fspot_db ." is not writeable for user ". $this->getuid() ."\n";
+ print "Error: ". $this->cfg->fspot_db ." is not writeable for user ". $this->getuid() .".\n";
+ print "Please fix permissions so phpfspot can create indices within the F-Spot database to"
+ ." speed up some database operations.\n";
exit(1);
}
@@ -157,6 +160,7 @@ class PHPFSPOT {
");
}
+ /* get F-Spot database version */
$this->dbver = $this->getFspotDBVersion();
if(!is_writeable($this->cfg->base_path ."/templates_c")) {
@@ -173,13 +177,15 @@ class PHPFSPOT {
/* Check if directory where the database file is stored is writeable */
if(!is_writeable(dirname($this->cfg->phpfspot_db))) {
- print dirname($this->cfg->phpfspot_db) .": directory is not writeable for user ". $this->getuid() ."\n";
+ print "Error: ". dirname($this->cfg->phpfspot_db) .": directory is not writeable for user ". $this->getuid() .".\n";
+ print "Please fix permissions so phpfspot can create its own sqlite database to store some settings.\n";
exit(1);
}
/* Check if database file is writeable */
if(!is_writeable($this->cfg->phpfspot_db)) {
- print $this->cfg->phpfspot_db ." is not writeable for user ". $this->getuid() ."\n";
+ print "Error: ". $this->cfg->phpfspot_db ." is not writeable for user ". $this->getuid() .".\n";
+ print "Please fix permissions so phpfspot can create its own sqlite database to store some settings.\n";
exit(1);
}
@@ -195,7 +201,7 @@ class PHPFSPOT {
}
/* Check if some tables need to be created */
- $this->check_config_table();
+ $this->check_phpfspot_db();
/* overload Smarty class with our own template handler */
require_once "phpfspot_tmpl.php";
@@ -203,6 +209,15 @@ class PHPFSPOT {
$this->tmpl->assign('web_path', $this->cfg->web_path);
+ /* Starting with F-Spot 0.4.2, the rating-feature was available */
+ if($this->dbver > 10) {
+ $this->tmpl->assign('has_rating', true);
+ $this->sort_orders = array_merge($this->sort_orders, array(
+ 'rate_asc' => 'Rate ↑',
+ 'rate_desc' => 'Rate ↓',
+ ));
+ }
+
/* check if all necessary indices exist */
$this->checkDbIndices();
@@ -213,8 +228,9 @@ class PHPFSPOT {
if(!isset($_SESSION['tag_condition']))
$_SESSION['tag_condition'] = 'or';
+ /* if sort-order has not been set yet, get the one specified in the config */
if(!isset($_SESSION['sort_order']))
- $_SESSION['sort_order'] = 'date_desc';
+ $_SESSION['sort_order'] = $this->cfg->sort_order;
if(!isset($_SESSION['searchfor_tag']))
$_SESSION['searchfor_tag'] = '';
@@ -278,6 +294,8 @@ class PHPFSPOT {
$_SESSION['start_action'] = 'showp';
}
if(isset($_GET['id']) && is_numeric($_GET['id'])) {
+ if($_SESSION['current_photo'] != $_GET['id'])
+ unset($_SESSION['current_version']);
$_SESSION['current_photo'] = $_GET['id'];
$_SESSION['start_action'] = 'showp';
}
@@ -289,11 +307,15 @@ class PHPFSPOT {
}
break;
case 'export':
- $this->tmpl->show("export.tpl");
+ /* fetch export template */
+ print $this->tmpl->fetch("export.tpl");
+ /* no further execution necessary. */
return;
break;
case 'slideshow':
- $this->tmpl->show("slideshow.tpl");
+ /* fetch slideshow template */
+ print $this->tmpl->show("slideshow.tpl");
+ /* no further execution necessary. */
return;
break;
case 'rss':
@@ -312,21 +334,43 @@ class PHPFSPOT {
}
}
+ /* if date-search variables are registered in the session, set the check
+ for "consider date-range" in the html output
+ */
if(isset($_SESSION['from_date']) && isset($_SESSION['to_date']))
$this->tmpl->assign('date_search_enabled', true);
+ /* if rate-search variables are registered in the session, set the check
+ for "consider rate-range" in the html output
+ */
+ if(isset($_SESSION['rate_from']) && isset($_SESSION['rate_to'])) {
+ $this->tmpl->assign('rate_search_enabled', true);
+ }
+
$this->tmpl->register_function("sort_select_list", array(&$this, "smarty_sort_select_list"), false);
- $this->tmpl->assign('search_from_date', $this->get_calendar('from'));
- $this->tmpl->assign('search_to_date', $this->get_calendar('to'));
+ $this->tmpl->assign('search_from_date', $this->get_date_text_field('from'));
+ $this->tmpl->assign('search_to_date', $this->get_date_text_field('to'));
$this->tmpl->assign('preset_selected_tags', $this->getSelectedTags());
$this->tmpl->assign('preset_available_tags', $this->getAvailableTags());
+ $this->tmpl->assign('rate_search', $this->get_rate_search());
+ /* if no site-content has been set yet... */
if(!isset($content)) {
- if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags']))
+ /* if tags are already selected, we can immediately display photo-index */
+ if((isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags']) &&
+ isset($_SESSION['start_action']) && $_SESSION['start_action'] != 'showp') ||
+ (isset($_SESSION['start_action']) && $_SESSION['start_action'] == 'showpi'))
$this->tmpl->assign('initial_content', $this->showPhotoIndex());
- else
- $this->tmpl->assign('initial_content', $this->tmpl->fetch('welcome.tpl'));
+ else {
+ /* if a photo is already selected, we can immediately display single-photo */
+ if(isset($_SESSION['current_photo']) && !empty($_SESSION['current_photo']))
+ $this->tmpl->assign('initial_content', $this->showPhoto($_SESSION['current_photo']));
+ else {
+ /* ok, then let us show the welcome page... */
+ $this->tmpl->assign('initial_content', $this->tmpl->fetch('welcome.tpl'));
+ }
+ }
}
else
$this->tmpl->assign('initial_content', $content);
@@ -351,6 +395,11 @@ class PHPFSPOT {
$this->avail_tags = Array();
$count = 0;
+ /* if show_tags has been set in the configuration (only show photos
+ which are tagged by these tags) they following will take care,
+ that only these other tags are displayed where the photo is also
+ tagged with one of show_tags.
+ */
if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
$query_str="
SELECT
@@ -409,15 +458,21 @@ class PHPFSPOT {
} // get_tags()
/**
- * extract all photo details
+ * get all photo details from F-Spot database
*
- * retrieve all available details from f-spot's
- * database and return them as object
+ * this function queries the F-Spot database for all available
+ * details of the requested photo. It returns them as a object.
+ *
+ * Furthermore it takes care of the photo version to be requested.
+ * If photo version is not yet, it queries information for the
+ * original photo.
+ *
* @param integer $idx
* @return object|null
*/
- public function get_photo_details($idx)
+ public function get_photo_details($idx, $version_idx = NULL)
{
+ /* ~ F-Spot version 0.3.x */
if($this->dbver < 9) {
$query_str = "
SELECT p.id, p.name, p.time, p.directory_path, p.description
@@ -425,14 +480,24 @@ class PHPFSPOT {
";
}
else {
- $query_str = "
- SELECT p.id, p.uri, p.time, p.description
- FROM photos p
- ";
+ /* till F-Spot version 0.4.1 */
+ if($this->dbver < 11) {
+ $query_str = "
+ SELECT p.id, p.uri, p.time, p.description
+ FROM photos p
+ ";
+ }
+ else {
+ /* rating value got introduced */
+ $query_str = "
+ SELECT p.id, p.uri, p.time, p.description, p.rating
+ FROM photos p
+ ";
+ }
}
- /* if show_tags is set, only return details for photos which
- are specified to be shown
+ /* if show_tags is set, only return details of photos which are
+ tagged with a tag that has been specified to be shown.
*/
if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
$query_str.= "
@@ -449,28 +514,55 @@ class PHPFSPOT {
";
}
- if($result = $this->db->db_query($query_str)) {
-
- $row = $this->db->db_fetch_object($result);
+ if($row = $this->db->db_fetchSingleRow($query_str)) {
+ /* before F-Spot db version 9 there was no uri column but
+ seperated fields for directory_path and name (= filename).
+ */
if($this->dbver < 9) {
$row['uri'] = "file://". $row['directory_path'] ."/". $row['name'];
}
+ /* if version-idx has not yet been set, get the latest photo version */
+ if(!isset($version_idx) || !$this->is_valid_version($idx, $version_idx))
+ $version_idx = $this->get_latest_version($idx);
+
+ /* if an alternative version has been requested */
+ if($version_idx > 0) {
+
+ /* check for alternative versions */
+ if($version = $this->db->db_fetchSingleRow("
+ SELECT
+ version_id, name, uri
+ FROM
+ photo_versions
+ WHERE
+ photo_id LIKE '". $idx ."'
+ AND
+ version_id LIKE '". $version_idx ."'
+ ")) {
+
+ $row['name'] = $version['name'];
+ $row['uri'] = $version['uri'];
+
+ }
+ }
+
return $row;
}
-
+
return null;
- } // get_photo_details
+ } // get_photo_details()
/**
* returns aligned photo names
*
- * this function returns aligned (length) names for
- * an specific photo. If the length of the name exceeds
- * $limit the name will be shrinked (...)
+ * this function returns aligned (length) names for a specific photo.
+ * If the length of the name exceeds $limit the name will bei
+ * shrinked (...).
+ *
* @param integer $idx
* @param integer $limit
* @return string|null
@@ -488,12 +580,81 @@ class PHPFSPOT {
} // getPhotoName()
+ /**
+ * get photo rating level
+ *
+ * this function will return the integer-based rating level of a
+ * photo. This can only be done, if the F-Spot database is at a
+ * specific version. If rating value can not be found, zero will
+ * be returned indicating no rating value is available.
+ *
+ * @param integer idx
+ * @return integer
+ */
+ public function get_photo_rating($idx)
+ {
+ if($detail = $this->get_photo_details($idx)) {
+ if(isset($detail['rating']))
+ return $detail['rating'];
+ }
+
+ return 0;
+
+ } // get_photo_rating()
+
+ /**
+ * get rate-search bars
+ *
+ * this function will return the rating-bars for the search field.
+ *
+ * @return string
+ */
+ public function get_rate_search()
+ {
+ $bar = "";
+
+ for($i = 1; $i <= 5; $i++) {
+
+ $bar.= "cfg->web_path ."/resources/star.png";
+ else
+ $bar.= $this->cfg->web_path ."/resources/empty_rate.png";
+
+ $bar.= "\"
+ onmouseover=\"show_rate('from', ". $i .");\"
+ onmouseout=\"reset_rate('from');\"
+ onclick=\"set_rate('from', ". $i .")\" />";
+ }
+
+ $bar.= " \n";
+
+ for($i = 1; $i <= 5; $i++) {
+
+ $bar.= "cfg->web_path ."/resources/star.png";
+ else
+ $bar.= $this->cfg->web_path ."/resources/empty_rate.png";
+
+ $bar.= "\"
+ onmouseover=\"show_rate('to', ". $i .");\"
+ onmouseout=\"reset_rate('to');\"
+ onclick=\"set_rate('to', ". $i .");\" />";
+ }
+
+ return $bar;
+
+ } // get_rate_search()
+
/**
* shrink text according provided limit
*
- * If the length of the name exceeds $limit the
- * text will be shortend and some content in between
- * will be replaced with "..."
+ * If the length of the name exceeds $limit, text will be shortend
+ * and inner content will be replaced with "...".
+ *
* @param string $ext
* @param integer $limit
* @return string
@@ -568,7 +729,16 @@ class PHPFSPOT {
}
$orig_path = $this->translate_path($this->parse_uri($details['uri'], 'fullpath'));
- $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo);
+
+ /* if current version is already set, use it */
+ if($this->get_current_version() !== false)
+ $version = $this->get_current_version();
+
+ /* if version not set yet, we assume to display the latest version */
+ if(!isset($version) || !$this->is_valid_version($photo, $version))
+ $version = $this->get_latest_version($photo);
+
+ $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo, $version);
if(!file_exists($orig_path)) {
$this->_error("Photo ". $orig_path ." does not exist! \n");
@@ -583,14 +753,14 @@ class PHPFSPOT {
/* If the thumbnail doesn't exist yet, try to create it */
if(!file_exists($thumb_path)) {
$this->gen_thumb($photo, true);
- $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo);
+ $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo, $version);
}
/* get mime-type, height and width from the original photo */
$info = getimagesize($orig_path);
/* get EXIF information if JPEG */
- if($info['mime'] == "image/jpeg") {
+ if(isset($info['mime']) && $info['mime'] == "image/jpeg") {
$meta = $this->get_meta_informations($orig_path);
}
@@ -601,7 +771,6 @@ class PHPFSPOT {
$meta_res = $info[0] ."x". $info[1];
}
- $meta_date = isset($meta['FileDateTime']) ? strftime("%a %x %X", $meta['FileDateTime']) : "n/a";
$meta_make = isset($meta['Make']) ? $meta['Make'] ." / ". $meta['Model'] : "n/a";
$meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a";
@@ -625,20 +794,21 @@ class PHPFSPOT {
$this->tmpl->assign('description', $details['description']);
$this->tmpl->assign('image_name', $this->parse_uri($details['uri'], 'filename'));
+ $this->tmpl->assign('image_rating', $this->get_photo_rating($photo));
$this->tmpl->assign('width', $info_thumb[0]);
$this->tmpl->assign('height', $info_thumb[1]);
- $this->tmpl->assign('ExifMadeOn', $meta_date);
+ $this->tmpl->assign('ExifMadeOn', strftime("%a %x %X", $details['time']));
$this->tmpl->assign('ExifMadeWith', $meta_make);
$this->tmpl->assign('ExifOrigResolution', $meta_res);
$this->tmpl->assign('ExifFileSize', $meta_size);
if($this->is_user_friendly_url()) {
- $this->tmpl->assign('image_url', '/photo/'. $photo ."/". $this->cfg->photo_width);
+ $this->tmpl->assign('image_url', '/photo/'. $photo ."/". $this->cfg->photo_width .'/'. $version);
$this->tmpl->assign('image_url_full', '/photo/'. $photo);
}
else {
- $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
+ $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width ."&version=". $version);
$this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
}
@@ -648,19 +818,28 @@ class PHPFSPOT {
$this->tmpl->assign('current_page', $this->getCurrentPage($current, $count));
$this->tmpl->assign('current_img', $photo);
- if($previous_img) {
- $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
+ if(isset($previous_img)) {
+ $this->tmpl->assign('previous_url', "javascript:showPhoto(". $previous_img .");");
$this->tmpl->assign('prev_img', $previous_img);
}
- if($next_img) {
- $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
+ if(isset($next_img)) {
+ $this->tmpl->assign('next_url', "javascript:showPhoto(". $next_img .");");
$this->tmpl->assign('next_img', $next_img);
}
+
$this->tmpl->assign('mini_width', $this->cfg->mini_width);
$this->tmpl->assign('photo_width', $this->cfg->photo_width);
$this->tmpl->assign('photo_number', $i);
$this->tmpl->assign('photo_count', count($all_photos));
+ $this->tmpl->assign('photo', $photo);
+ $this->tmpl->assign('version', $version);
+
+ /* if the photo as alternative versions, set a flag for the template */
+ if($this->get_photo_versions($photo))
+ $this->tmpl->assign('has_versions', true);
+
+ $this->tmpl->register_function("photo_version_select_list", array(&$this, "smarty_photo_version_select_list"), false);
return $this->tmpl->fetch("single_photo.tpl");
@@ -721,6 +900,9 @@ class PHPFSPOT {
// loop through our tag array
foreach ($tags as $key => $value) {
+ /* has the currently processed tag already been added to
+ the selected tag list? if so, ignore it here...
+ */
if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags']))
continue;
@@ -729,7 +911,7 @@ class PHPFSPOT {
// multiply by the font-size increment ($size)
// and add the $min_size set above
$size = $min_size + (($value - $min_qty) * $step);
- // uncomment if you want sizes in whole %:
+ // uncomment if you want sizes in whole %:
$size = ceil($size);
$color = $min_sat + ($value - $min_qty) * $step_sat;
@@ -739,10 +921,20 @@ class PHPFSPOT {
$b = '88';
if(isset($this->tags[$key])) {
- if($this->is_user_friendly_url())
- $output.= "cfg->web_path ."/tag/". $key ."\" onclick=\"Tags('add', ". $key ."); return false;\" class=\"tag\" style=\"font-size: ". $size ."%; color: #". $r.$g.$b .";\">". $this->tags[$key] .", ";
- else
- $output.= "cfg->web_path ."/index.php?mode=showpi\" onclick=\"Tags('add', ". $key ."); return false;\" class=\"tag\" style=\"font-size: ". $size ."%; color: #". $r.$g.$b .";\">". $this->tags[$key] .", ";
+ if($this->is_user_friendly_url()) {
+ $output.= "cfg->web_path ."/tag/". $key ."\"
+ onclick=\"Tags('add', ". $key ."); return false;\"
+ class=\"tag\"
+ style=\"font-size: ". $size ."%; color: #". $r.$g.$b .";\"
+ title=\"Tag ". $this->tags[$key] .", ". $tags[$key] ." picture(s)\">". $this->tags[$key] .", ";
+ }
+ else {
+ $output.= "cfg->web_path ."/index.php?mode=showpi\"
+ onclick=\"Tags('add', ". $key ."); return false;\"
+ class=\"tag\"
+ style=\"font-size: ". $size ."%; color: #". $r.$g.$b .";\"
+ title=\"Tag ". $this->tags[$key] .", ". $tags[$key] ." picture(s)\">". $this->tags[$key] .", ";
+ }
}
}
@@ -778,17 +970,10 @@ class PHPFSPOT {
break;
case 'img':
$output.= "
-