X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot.class.php;h=d7a76c3a50d9cfd80830dda1553a87f6007d9b52;hp=b5034e72026704cbb3014891c2b4d7eaac98ffe3;hb=5d95b196f7993398d68ad67179eb2d2b2ce1b0f1;hpb=b7a43526958fc12ce7d0e42b8023db52cb25f140;ds=sidebyside
diff --git a/phpfspot.class.php b/phpfspot.class.php
index b5034e7..d7a76c3 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -2,8 +2,9 @@
/***************************************************************************
*
- * Copyright (c) by Andreas Unterkircher, unki@netshadow.at
- * All rights reserved
+ * phpfspot, presents your F-Spot photo collection in Web browsers.
+ *
+ * Copyright (c) by Andreas Unterkircher
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,20 +25,79 @@
require_once "phpfspot_cfg.php";
require_once "phpfspot_db.php";
+/**
+ * PHPFSPOT main class
+ *
+ * this class contains the most functions which will to the major
+ * work for phpfspot.
+ *
+ * @package phpfspot
+ */
class PHPFSPOT {
+ /**
+ * phpfspot configuration
+ * @access public
+ * @see PHPFSPOT_CFG()
+ * @var PHPFSPOT_CFG
+ */
var $cfg;
+
+ /**
+ * SQLite database handle to f-spot database
+ * @see PHPFSPOT_DB()
+ * @access public
+ * @var PHPFSPOT_DB
+ */
var $db;
+
+ /**
+ * SQLite database handle to phpfspot database
+ * @see PHPFSPOT_DB()
+ * @access public
+ * @var PHPFSPOT_DB
+ */
var $cfg_db;
+
+ /**
+ * Smarty template engine
+ * @link http://smarty.php.net smarty.php.net
+ * @see PHPFSPOT_TMPL()
+ * @access public
+ * @var PHPFSPOT_TMPL
+ */
var $tmpl;
+
+ /**
+ * full tag - list
+ * @access public
+ * @var array
+ */
var $tags;
+
+ /**
+ * list of available, not-selected, tags
+ * @access public
+ * @var array
+ */
var $avail_tags;
+ /**
+ * true if runtime error occued
+ * @access private
+ * @var boolean
+ */
private $runtime_error = false;
+
+ /**
+ * F-Spot database version
+ * @access private
+ * @var integer
+ */
private $dbver;
/**
- * class constructor
+ * class constructor ($cfg, $db, $cfg_db, $tmpl, $db_ver)
*
* this function will be called on class construct
* and will check requirements, loads configuration,
@@ -45,6 +105,14 @@ class PHPFSPOT {
*/
public function __construct()
{
+ /**
+ * register PHPFSPOT class global
+ *
+ * @global PHPFSPOT $GLOBALS['phpfspot']
+ * @name $phpfspot
+ */
+ $GLOBALS['phpfspot'] =& $this;
+
$this->cfg = new PHPFSPOT_CFG;
/* verify config settings */
@@ -54,7 +122,7 @@ class PHPFSPOT {
/* set application name and version information */
$this->cfg->product = "phpfspot";
- $this->cfg->version = "1.4";
+ $this->cfg->version = "1.6";
$this->sort_orders= array(
'date_asc' => 'Date ↑',
@@ -74,7 +142,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);
}
@@ -89,6 +159,7 @@ class PHPFSPOT {
");
}
+ /* get F-Spot database version */
$this->dbver = $this->getFspotDBVersion();
if(!is_writeable($this->cfg->base_path ."/templates_c")) {
@@ -105,13 +176,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);
}
@@ -131,7 +204,18 @@ class PHPFSPOT {
/* overload Smarty class with our own template handler */
require_once "phpfspot_tmpl.php";
- $this->tmpl = new PHPFSPOT_TMPL($this);
+ $this->tmpl = new PHPFSPOT_TMPL();
+
+ $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();
@@ -143,8 +227,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'] = '';
@@ -153,6 +238,11 @@ class PHPFSPOT {
if(isset($_SESSION['begin_with']) && $this->cfg->thumbs_per_page == 0)
unset($_SESSION['begin_with']);
+ // if user-friendly-url's are enabled, set also a flag for the template handler
+ if($this->is_user_friendly_url()) {
+ $this->tmpl->assign('user_friendly_url', 'true');
+ }
+
} // __construct()
public function __destruct()
@@ -176,6 +266,11 @@ class PHPFSPOT {
$this->tmpl->assign('current_condition', $_SESSION['tag_condition']);
$this->tmpl->assign('template_path', 'themes/'. $this->cfg->theme_name);
+ /* parse URL */
+ if($this->is_user_friendly_url()) {
+ $content = $this->parse_user_friendly_url($_SERVER['REQUEST_URI']);
+ }
+
if(isset($_GET['mode'])) {
$_SESSION['start_action'] = $_GET['mode'];
@@ -209,11 +304,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':
@@ -232,13 +331,47 @@ 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('from_date', $this->get_calendar('from'));
- $this->tmpl->assign('to_date', $this->get_calendar('to'));
- $this->tmpl->assign('content_page', 'welcome.tpl');
+ $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 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 {
+ /* 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);
+
$this->tmpl->show("index.tpl");
} // show()
@@ -259,6 +392,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
@@ -321,9 +459,12 @@ class PHPFSPOT {
*
* retrieve all available details from f-spot's
* database and return them as object
+ * @param integer $idx
+ * @return object|null
*/
public function get_photo_details($idx)
{
+ /* ~ F-Spot version 0.3.x */
if($this->dbver < 9) {
$query_str = "
SELECT p.id, p.name, p.time, p.directory_path, p.description
@@ -331,14 +472,23 @@ 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
- 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.= "
@@ -359,6 +509,9 @@ class PHPFSPOT {
$row = $this->db->db_fetch_object($result);
+ /* before F-Spot db version 9 there was no uri column but seperated
+ columns for directory_path and name (= filename).
+ */
if($this->dbver < 9) {
$row['uri'] = "file://". $row['directory_path'] ."/". $row['name'];
}
@@ -374,9 +527,13 @@ class PHPFSPOT {
/**
* 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
*/
public function getPhotoName($idx, $limit = 0)
{
@@ -391,12 +548,84 @@ 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
*/
private function shrink_text($text, $limit)
{
@@ -414,8 +643,10 @@ class PHPFSPOT {
* as the full-qualified path recorded in the f-spot database
* is usally not the same as on the webserver, this function
* will replace the path with that one specified in the cfg
+ * @param string $path
+ * @return string
*/
- public function translate_path($path, $width = 0)
+ public function translate_path($path)
{
return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
@@ -426,6 +657,7 @@ class PHPFSPOT {
*
* this function provides all the necessary information
* for the single photo template.
+ * @param integer photo
*/
public function showPhoto($photo)
{
@@ -483,8 +715,11 @@ class PHPFSPOT {
$thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo);
}
+ /* get mime-type, height and width from the original photo */
+ $info = getimagesize($orig_path);
+
/* get EXIF information if JPEG */
- if($details['mime'] == "image/jpeg") {
+ if(isset($info['mime']) && $info['mime'] == "image/jpeg") {
$meta = $this->get_meta_informations($orig_path);
}
@@ -492,11 +727,9 @@ class PHPFSPOT {
if(isset($meta['ExifImageWidth'])) {
$meta_res = $meta['ExifImageWidth'] ."x". $meta['ExifImageLength'];
} else {
- $info = getimagesize($orig_path);
$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";
@@ -516,41 +749,50 @@ class PHPFSPOT {
return;
}
- $info = getimagesize($thumb_path);
+ $info_thumb = getimagesize($thumb_path);
$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[0]);
- $this->tmpl->assign('height', $info[1]);
- $this->tmpl->assign('ExifMadeOn', $meta_date);
+ $this->tmpl->assign('width', $info_thumb[0]);
+ $this->tmpl->assign('height', $info_thumb[1]);
+ $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);
- $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
- $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
+ if($this->is_user_friendly_url()) {
+ $this->tmpl->assign('image_url', '/photo/'. $photo ."/". $this->cfg->photo_width);
+ $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_full', 'phpfspot_img.php?idx='. $photo);
+ }
+
$this->tmpl->assign('image_filename', $this->parse_uri($details['uri'], 'filename'));
$this->tmpl->assign('tags', $this->get_photo_tags($photo));
$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->show("single_photo.tpl");
+ return $this->tmpl->fetch("single_photo.tpl");
} // showPhoto()
@@ -609,6 +851,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;
@@ -617,7 +862,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;
@@ -627,13 +872,25 @@ class PHPFSPOT {
$b = '88';
if(isset($this->tags[$key])) {
- $output.= "". $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] .", ";
+ }
}
-
}
$output = substr($output, 0, strlen($output)-2);
- print $output;
+ return $output;
} // getAvailableTags()
@@ -643,8 +900,9 @@ class PHPFSPOT {
* this function output all tags which have been selected
* by the user. the selected tags are stored in the
* session-variable $_SESSION['selected_tags']
+ * @return string
*/
- public function getSelectedTags()
+ public function getSelectedTags($type = 'link')
{
/* retrive tags from database */
$this->get_tags();
@@ -655,7 +913,22 @@ class PHPFSPOT {
{
// return all selected tags
if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
- $output.= "". $this->tags[$tag] .", ";
+
+ switch($type) {
+ default:
+ case 'link':
+ $output.= "". $this->tags[$tag] .", ";
+ break;
+ case 'img':
+ $output.= "
+