From aab7d4d07c16dc78a6d2a41223d469a1a60e5022 Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Fri, 23 May 2008 20:05:38 +0200 Subject: issue121, initial support for F-Spot's rating system and sort-by rating Signed-off-by: Andreas Unterkircher --- CHANGELOG | 1 + phpfspot.class.php | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c0befcb..e6fee40 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ phpfspot (1.5) * feature, display tag-selection with preview-icons in photo index. * feature, support for Nikon's NEF RAW photo format (via dcraw and ImageMagick). * feature, auto-scroll in photo index if thumbnails are out of sight. + * feature, support F-Spot's rating values. * bug, if tag added to hide-tags, don't show up in photo-details box (single-photo). * bug, if tag added to hide-tags, don't allow adding to selected-tags list. * bug, if tag added to hide-tags, random-photo needs to take care of it. diff --git a/phpfspot.class.php b/phpfspot.class.php index 1d20ab1..e6c4aff 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -157,6 +157,7 @@ class PHPFSPOT { "); } + /* get F-Spot database version */ $this->dbver = $this->getFspotDBVersion(); if(!is_writeable($this->cfg->base_path ."/templates_c")) { @@ -203,6 +204,14 @@ 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->sort_orders = array_merge($this->sort_orders, array( + 'rate_asc' => 'Rate ↑', + 'rate_desc' => 'Rate ↓', + )); + } + /* check if all necessary indices exist */ $this->checkDbIndices(); @@ -425,10 +434,19 @@ 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 { + $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 @@ -2538,6 +2556,12 @@ class PHPFSPOT { case 'tags_desc': return " ORDER BY t.name DESC ,p.time ASC"; break; + case 'rate_asc': + return " ORDER BY t.name ASC, p.rating ASC"; + break; + case 'rate_desc': + return " ORDER BY t.name DESC, p.rating DESC"; + break; } } // get_sort_order() -- cgit v1.2.3-18-g5258 From 2ea665ef86c5573c244ebbba797fb31cadf6752b Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 24 May 2008 09:26:11 +0200 Subject: issue121, show rating value in photo-index- and single-photo-view Signed-off-by: Andreas Unterkircher --- phpfspot.class.php | 26 ++++++++++++++++++++++++++ resources/rating.png | Bin 0 -> 686 bytes resources/star.png | Bin 0 -> 670 bytes themes/default/templates/photo_index.tpl | 8 ++++++++ themes/default/templates/single_photo.tpl | 7 +++++++ 5 files changed, 41 insertions(+) create mode 100644 resources/rating.png create mode 100644 resources/star.png diff --git a/phpfspot.class.php b/phpfspot.class.php index e6c4aff..0711499 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -506,6 +506,28 @@ class PHPFSPOT { } // getPhotoName() + /** + * get photo rating level + * + * this function will return the integer-based rating + * level of the photo. This can only be done, if the F-Spot + * database is at a specific level. 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() + /** * shrink text according provided limit * @@ -643,6 +665,7 @@ 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]); @@ -1232,6 +1255,7 @@ class PHPFSPOT { $img_name[$thumbs] = Array(); $img_fullname[$thumbs] = Array(); $img_title = Array(); + $img_rating = Array(); for($i = $begin_with; $i < $end_with; $i++) { @@ -1242,6 +1266,7 @@ class PHPFSPOT { $img_name[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 15)); $img_fullname[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 0)); $img_title[$thumbs] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0)); + $img_rating[$thumbs] = $this->get_photo_rating($photos[$i]); $thumb_path = $this->get_thumb_path($this->cfg->thumb_width, $photos[$i]); @@ -1389,6 +1414,7 @@ class PHPFSPOT { $this->tmpl->assign('img_name', $img_name); $this->tmpl->assign('img_fullname', $img_fullname); $this->tmpl->assign('img_title', $img_title); + $this->tmpl->assign('img_rating', $img_rating); $this->tmpl->assign('thumbs', $thumbs); $this->tmpl->assign('selected_tags', $this->getSelectedTags('img')); diff --git a/resources/rating.png b/resources/rating.png new file mode 100644 index 0000000..c39b428 Binary files /dev/null and b/resources/rating.png differ diff --git a/resources/star.png b/resources/star.png new file mode 100644 index 0000000..b88c857 Binary files /dev/null and b/resources/star.png differ diff --git a/themes/default/templates/photo_index.tpl b/themes/default/templates/photo_index.tpl index c9da477..7fe04ab 100644 --- a/themes/default/templates/photo_index.tpl +++ b/themes/default/templates/photo_index.tpl @@ -78,9 +78,17 @@
{$img_name[thumb]} + { if $use_lightbox } { /if } + + { if $img_rating[thumb] } +
+ {section name="rating" loop=$img_rating[thumb] step=1} + + {/section} + { /if } {/if} diff --git a/themes/default/templates/single_photo.tpl b/themes/default/templates/single_photo.tpl index 97ef0cf..b141517 100644 --- a/themes/default/templates/single_photo.tpl +++ b/themes/default/templates/single_photo.tpl @@ -42,6 +42,13 @@ {$ExifOrigResolution}
{ /if } Size: {$ExifFileSize}
+ { if $image_rating } + rating Rating:
+ {section name="rating" loop=$image_rating step=1} + + {/section} +
+ { /if } { if $tags }
available tags Tagged with:
-- cgit v1.2.3-18-g5258 From 6da6a0bae7001a35ac6530fbd6ff9aeab140983f Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 24 May 2008 09:27:22 +0200 Subject: add unit-name to exif-resolution-field Signed-off-by: Andreas Unterkircher --- themes/default/templates/single_photo.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/default/templates/single_photo.tpl b/themes/default/templates/single_photo.tpl index b141517..20b59f8 100644 --- a/themes/default/templates/single_photo.tpl +++ b/themes/default/templates/single_photo.tpl @@ -39,7 +39,7 @@ { /if } { if $ExifOrigResolution } resolution icon Original resolution:
- {$ExifOrigResolution}
+ {$ExifOrigResolution}px
{ /if } Size: {$ExifFileSize}
{ if $image_rating } -- cgit v1.2.3-18-g5258 From f36faab3aed613fc0e1e10a34a88bf1065c80f79 Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 24 May 2008 11:39:39 +0200 Subject: issue121, search for a specific rate-limit Signed-off-by: Andreas Unterkircher --- phpfspot.class.php | 134 +++++++++++++++++++++++++++++++++--- phpfspot.js | 69 ++++++++++++++++++- resources/empty_rate.png | Bin 0 -> 218 bytes rpc.php | 1 + themes/default/templates/search.tpl | 23 +++++++ 5 files changed, 218 insertions(+), 9 deletions(-) create mode 100644 resources/empty_rate.png diff --git a/phpfspot.class.php b/phpfspot.class.php index 0711499..58cda4e 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -206,6 +206,7 @@ class PHPFSPOT { /* 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 ↓', @@ -321,15 +322,26 @@ 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('preset_selected_tags', $this->getSelectedTags()); $this->tmpl->assign('preset_available_tags', $this->getAvailableTags()); + $this->tmpl->assign('rate_search', $this->get_rate_search()); if(!isset($content)) { if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) @@ -528,6 +540,53 @@ class PHPFSPOT { } // 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 * @@ -997,8 +1056,7 @@ class PHPFSPOT { /** * reset date search * - * if any date search has taken place, reset - * it now + * if any date search has taken place, reset it now. */ public function resetDateSearch() { @@ -1009,6 +1067,20 @@ class PHPFSPOT { } // resetDateSearch(); + /** + * reset rate search + * + * if any rate search has taken place, reset it now. + */ + public function resetRateSearch() + { + if(isset($_SESSION['rate_from'])) + unset($_SESSION['rate_from']); + if(isset($_SESSION['rate_to'])) + unset($_SESSION['rate_to']); + + } // resetRateSearch(); + /** * return all photo according selection * @@ -1034,6 +1106,12 @@ class PHPFSPOT { } if(isset($_SESSION['searchfor_name'])) { + + /* check for previous conditions. if so add 'AND' */ + if(!empty($additional_where_cond)) { + $additional_where_cond.= " AND "; + } + if($this->dbver < 9) { $additional_where_cond.= " ( @@ -1054,6 +1132,24 @@ class PHPFSPOT { } } + /* limit result based on rate-search */ + if(isset($_SESSION['rate_from']) && isset($_SESSION['rate_to'])) { + + if($this->dbver > 10) { + + /* check for previous conditions. if so add 'AND' */ + if(!empty($additional_where_cond)) { + $additional_where_cond.= " AND "; + } + + $additional_where_cond.= " + p.rating >= ". $_SESSION['rate_from'] ." + AND + p.rating <= ". $_SESSION['rate_to'] ." + "; + } + } + if(isset($_SESSION['sort_order'])) { $order_str = $this->get_sort_order(); } @@ -1073,7 +1169,7 @@ class PHPFSPOT { ON pt2.tag_id=t2.id WHERE t.name LIKE '%". $_SESSION['searchfor_tag'] ."%' "; - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "AND ". $additional_where_cond ." "; if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { @@ -1110,7 +1206,7 @@ class PHPFSPOT { ON pt1.photo_id=p.id WHERE pt1.tag_id IN (". $selected .") "; - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "AND ". $additional_where_cond ." "; if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { @@ -1166,7 +1262,7 @@ class PHPFSPOT { AND pt". ($i+2) .".tag_id=". $_SESSION['selected_tags'][$i] ." "; } - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "AND ". $additional_where_cond; if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { @@ -1195,11 +1291,11 @@ class PHPFSPOT { ON pt.tag_id=t.id "; - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "WHERE ". $additional_where_cond ." "; if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "AND t.name IN ('".implode("','",$this->cfg->show_tags). "')"; else $query_str.= "WHERE t.name IN ('".implode("','",$this->cfg->show_tags). "')"; @@ -1890,6 +1986,7 @@ class PHPFSPOT { */ public function startSearch() { + /* date search */ if(isset($_POST['from']) && $this->isValidDate($_POST['from'])) { $from = $_POST['from']; } @@ -1897,15 +1994,36 @@ class PHPFSPOT { $to = $_POST['to']; } + /* tag-name search */ if(isset($_POST['for_tag']) && is_string($_POST['for_tag'])) { $searchfor_tag = $_POST['for_tag']; $_SESSION['searchfor_tag'] = $_POST['for_tag']; } + else { + unset($_SESSION['searchfor_tag']); + } + /* file-name search */ if(isset($_POST['for_name']) && is_string($_POST['for_name'])) { - $searchfor_name = $_POST['for_name']; $_SESSION['searchfor_name'] = $_POST['for_name']; } + else { + unset($_SESSION['searchfor_name']); + } + + /* rate-search */ + if(isset($_POST['rate_from']) && is_numeric($_POST['rate_from'])) { + + $_SESSION['rate_from'] = $_POST['rate_from']; + + if(isset($_POST['rate_to']) && is_numeric($_POST['rate_to'])) { + $_SESSION['rate_to'] = $_POST['rate_to']; + } + } + else { + /* delete any previously set value */ + unset($_SESSION['rate_to'], $_SESSION['rate_from']); + } $this->get_tags(); diff --git a/phpfspot.js b/phpfspot.js index 2aee155..be62cfb 100644 --- a/phpfspot.js +++ b/phpfspot.js @@ -287,6 +287,10 @@ function startSearch() objTemp['from'] = from; objTemp['to'] = to; } + if(document.getElementsByName('consider_rate')[0].checked == true) { + objTemp['rate_from'] = rate_search['from']; + objTemp['rate_to'] = rate_search['to']; + } var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp); if(retr == "ok") { @@ -348,7 +352,11 @@ function clearSearch() if(document.getElementsByName('consider_date')[0].checked == true) { document.getElementsByName('consider_date')[0].checked = false; datesearch(); - } + } + if(document.getElementsByName('consider_rate')[0].checked == true) { + document.getElementsByName('consider_rate')[0].checked = false; + datesearch(); + } } // clearSearch() @@ -799,6 +807,64 @@ function update_sort_order(obj) } // update_sort_order() +/** + * show rate stars + * + * this function will show the requested amount of + * rate-stars. + * + * @param string mode + * @param int level + */ +function show_rate(mode, level) +{ + var i; + + for(i = 1; i <= 5; i++) { + if(i <= level) { + document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/star.png'; + } + else { + document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/empty_rate.png'; + } + } + +} // show_rate() + +/** + * set rate stars + * + * + * this function will set the requested rate-stars-amount into a global + * variable (which will then later be used on form-submit) and will also + * update the display. + * + * @param string mode + * @param int level + */ +function set_rate(mode, level) +{ + rate_search[mode] = level; + show_rate(mode, level); + +} // set_rate() + +/** + * reset rate stars + * + * this function will reset the rate-star to their initial value. + * + * @param string mode + */ +function reset_rate(mode) +{ + if(rate_search[mode] == undefined) + rate_search[mode] = 0; + + show_rate(mode, rate_search[mode]); + +} // reset_rate() + /** * handle key events */ @@ -858,3 +924,4 @@ var origWidth; // position of the last shown photo in photo-index var photo_details_pos; var web_path; +var rate_search = new Array(); diff --git a/resources/empty_rate.png b/resources/empty_rate.png new file mode 100644 index 0000000..dcf5feb Binary files /dev/null and b/resources/empty_rate.png differ diff --git a/rpc.php b/rpc.php index f4a93ce..ada2857 100644 --- a/rpc.php +++ b/rpc.php @@ -98,6 +98,7 @@ class PHPFSPOT_RPC { $phpfspot->resetNameSearch(); $phpfspot->resetTags(); $phpfspot->resetDateSearch(); + $phpfspot->resetRateSearch(); $phpfspot->resetPhotoView(); break; diff --git a/themes/default/templates/search.tpl b/themes/default/templates/search.tpl index c1d152c..672bb35 100644 --- a/themes/default/templates/search.tpl +++ b/themes/default/templates/search.tpl @@ -60,6 +60,29 @@ + { if $has_rating } + + Rating: + + { if ! $rate_search_enabled } + + { else } + + { /if } + consider rate-range + +   + + +   + + { $rate_search } + + + + + + { /if } Sort-Order:  -- cgit v1.2.3-18-g5258 From 99dd0b5d5e19d565088595a9fd9d164bcd4834ae Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 24 May 2008 12:46:37 +0200 Subject: issue121, add some js-checks if objects are there Signed-off-by: Andreas Unterkircher --- phpfspot.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/phpfspot.js b/phpfspot.js index be62cfb..8db1f65 100644 --- a/phpfspot.js +++ b/phpfspot.js @@ -277,17 +277,21 @@ function startSearch() var objTemp = new Object(); objTemp['action'] = 'search'; - if(document.getElementsByName('searchfor_tag')[0].value != "") { + if(document.getElementsByName('searchfor_tag')[0] != undefined && + document.getElementsByName('searchfor_tag')[0].value != "") { objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value; } - if(document.getElementsByName('searchfor_name')[0].value != "") { + if(document.getElementsByName('searchfor_name')[0] != undefined && + document.getElementsByName('searchfor_name')[0].value != "") { objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value; } - if(document.getElementsByName('consider_date')[0].checked == true) { + if(document.getElementsByName('consider_date')[0] != undefined && + document.getElementsByName('consider_date')[0].checked == true) { objTemp['from'] = from; objTemp['to'] = to; } - if(document.getElementsByName('consider_rate')[0].checked == true) { + if(document.getElementsByName('consider_rate')[0] != undefined && + document.getElementsByName('consider_rate')[0].checked == true) { objTemp['rate_from'] = rate_search['from']; objTemp['rate_to'] = rate_search['to']; } @@ -346,16 +350,19 @@ function setViewMode(mode) */ function clearSearch() { - document.getElementsByName('searchfor_tag')[0].value = ''; - document.getElementsByName('searchfor_name')[0].value = ''; + if(document.getElementsByName('searchfor_tag')[0] != undefined) + document.getElementsByName('searchfor_tag')[0].value = ''; + if(document.getElementsByName('searchfor_name')[0] != undefined) + document.getElementsByName('searchfor_name')[0].value = ''; - if(document.getElementsByName('consider_date')[0].checked == true) { + if(document.getElementsByName('consider_date')[0] != undefined && + document.getElementsByName('consider_date')[0].checked == true) { document.getElementsByName('consider_date')[0].checked = false; datesearch(); } - if(document.getElementsByName('consider_rate')[0].checked == true) { + if(document.getElementsByName('consider_rate')[0] != undefined && + document.getElementsByName('consider_rate')[0].checked == true) { document.getElementsByName('consider_rate')[0].checked = false; - datesearch(); } } // clearSearch() -- cgit v1.2.3-18-g5258