summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Unterkircher <unki@netshadow.at>2008-05-24 13:01:13 +0200
committerAndreas Unterkircher <unki@netshadow.at>2008-05-24 13:01:13 +0200
commit6c98040d5b5f29f3952b8222d5cf256007347e5d (patch)
tree31f781bf71e0fc431328d163c4361f07e2f9ffb2
parente75b25313a062eaac262f504397b1b75c092a6cd (diff)
parent99dd0b5d5e19d565088595a9fd9d164bcd4834ae (diff)
Merge branch 'rating'
-rw-r--r--CHANGELOG1
-rw-r--r--phpfspot.class.php192
-rw-r--r--phpfspot.js88
-rw-r--r--resources/empty_rate.pngbin0 -> 218 bytes
-rw-r--r--resources/rating.pngbin0 -> 686 bytes
-rw-r--r--resources/star.pngbin0 -> 670 bytes
-rw-r--r--rpc.php1
-rw-r--r--themes/default/templates/photo_index.tpl8
-rw-r--r--themes/default/templates/search.tpl23
-rw-r--r--themes/default/templates/single_photo.tpl7
10 files changed, 301 insertions, 19 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..58cda4e 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,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 &uarr;',
+ 'rate_desc' => 'Rate &darr;',
+ ));
+ }
+
/* check if all necessary indices exist */
$this->checkDbIndices();
@@ -312,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']))
@@ -425,10 +446,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
@@ -489,6 +519,75 @@ 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()
+
+ /**
+ * 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.= "<img id=\"rate_from_". $i ."\" src=\"";
+
+ if(isset($_SESSION['rate_from']) && $i <= $_SESSION['rate_from'])
+ $bar.= $this->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.= "<br />\n";
+
+ for($i = 1; $i <= 5; $i++) {
+
+ $bar.= "<img id=\"rate_to_". $i ."\" src=\"";
+
+ if(isset($_SESSION['rate_to']) && $i <= $_SESSION['rate_to'])
+ $bar.= $this->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
@@ -625,6 +724,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]);
@@ -956,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()
{
@@ -969,6 +1068,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
*
* this function returns all photos based on
@@ -993,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.= "
(
@@ -1013,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();
}
@@ -1032,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)) {
@@ -1069,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)) {
@@ -1125,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)) {
@@ -1154,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). "')";
@@ -1214,6 +1351,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++) {
@@ -1224,6 +1362,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]);
@@ -1371,6 +1510,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'));
@@ -1846,6 +1986,7 @@ class PHPFSPOT {
*/
public function startSearch()
{
+ /* date search */
if(isset($_POST['from']) && $this->isValidDate($_POST['from'])) {
$from = $_POST['from'];
}
@@ -1853,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();
@@ -2538,6 +2700,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()
diff --git a/phpfspot.js b/phpfspot.js
index 2aee155..8db1f65 100644
--- a/phpfspot.js
+++ b/phpfspot.js
@@ -277,16 +277,24 @@ 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] != undefined &&
+ 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") {
@@ -342,13 +350,20 @@ 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] != undefined &&
+ document.getElementsByName('consider_rate')[0].checked == true) {
+ document.getElementsByName('consider_rate')[0].checked = false;
+ }
} // clearSearch()
@@ -800,6 +815,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
*/
function keyDown(e) {
@@ -858,3 +931,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
--- /dev/null
+++ b/resources/empty_rate.png
Binary files differ
diff --git a/resources/rating.png b/resources/rating.png
new file mode 100644
index 0000000..c39b428
--- /dev/null
+++ b/resources/rating.png
Binary files differ
diff --git a/resources/star.png b/resources/star.png
new file mode 100644
index 0000000..b88c857
--- /dev/null
+++ b/resources/star.png
Binary files 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/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 @@
<br />
{$img_name[thumb]}
</a>
+ <!-- show lightbox eyes, if enabled -->
{ if $use_lightbox }
<a href="{$web_path}/phpfspot_img.php?idx={$images[thumb]}&amp;width={$preview_width}" alt="thumb_{$images[thumb]}" rel="lightbox[photoidx]" title="Preview of {$img_fullname[thumb]}"><img src="{$web_path}/resources/eyes.png" /></a>
{ /if }
+ <!-- show F-Spot photo rating value, if available -->
+ { if $img_rating[thumb] }
+ <br />
+ {section name="rating" loop=$img_rating[thumb] step=1}
+ <img src="{$web_path}/resources/star.png" />
+ {/section}
+ { /if }
</div>
{/if}
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 @@
<input type="image" class="submit" src="{$web_path}/resources/doit.png" alt="start search" title="start search" onclick="click(this);" />
</td>
</tr>
+ { if $has_rating }
+ <tr>
+ <td>Rating:</td>
+ <td class="nowarp">
+ { if ! $rate_search_enabled }
+ <input type="checkbox" class="checkbox" name="consider_rate" value="Y" />
+ { else }
+ <input type="checkbox" class="checkbox" name="consider_rate" value="Y" checked="checked" />
+ { /if }
+ consider rate-range
+ </td>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td>&nbsp;</td>
+ <td>
+ { $rate_search }
+ </td>
+ <td>
+ <input type="image" class="submit" src="{$web_path}/resources/doit.png" alt="start search" title="start search" onclick="click(this);" />
+ </td>
+ </tr>
+ { /if }
<tr>
<td>
Sort-Order:&nbsp;
diff --git a/themes/default/templates/single_photo.tpl b/themes/default/templates/single_photo.tpl
index 9b690ff..20b59f8 100644
--- a/themes/default/templates/single_photo.tpl
+++ b/themes/default/templates/single_photo.tpl
@@ -42,6 +42,13 @@
{$ExifOrigResolution}px<br />
{ /if }
<u>Size:</u>&nbsp;{$ExifFileSize}<br />
+ { if $image_rating }
+ <u><img src="{$web_path}/resources/rating.png" alt="rating" />&nbsp;Rating:</u><br />
+ {section name="rating" loop=$image_rating step=1}
+ <img src="{$web_path}/resources/star.png" />
+ {/section}
+ <br />
+ { /if }
{ if $tags }
<br />
<u><img src="{$web_path}/resources/small_available_tags.png" alt="available tags" />&nbsp;Tagged with:</u><br />