X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot.class.php;h=92c0fd2e69da2efa3c1d5a86a82f087f346d43dd;hp=b1093fc8fa1281fd2cb6460acb0ad7cd495c15e7;hb=37d9c8bf7eb7c4244f93d9ed780333ec1fa4ae86;hpb=ae99d62da68f045e253c21f4db1ccee8d68b29ca
diff --git a/phpfspot.class.php b/phpfspot.class.php
index b1093fc..92c0fd2 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -25,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,
@@ -63,7 +122,8 @@ class PHPFSPOT {
/* set application name and version information */
$this->cfg->product = "phpfspot";
- $this->cfg->version = "1.4";
+ $this->cfg->version = "1.7";
+ $this->cfg->db_version = 2;
$this->sort_orders= array(
'date_asc' => 'Date ↑',
@@ -83,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);
}
@@ -98,6 +160,7 @@ class PHPFSPOT {
");
}
+ /* get F-Spot database version */
$this->dbver = $this->getFspotDBVersion();
if(!is_writeable($this->cfg->base_path ."/templates_c")) {
@@ -114,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);
}
@@ -136,12 +201,23 @@ 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";
$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();
@@ -152,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'] = '';
@@ -162,6 +239,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()
@@ -185,6 +267,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'];
@@ -207,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';
}
@@ -218,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':
@@ -241,13 +334,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()
@@ -268,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
@@ -326,13 +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
@@ -340,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.= "
@@ -364,28 +514,58 @@ 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
*/
public function getPhotoName($idx, $limit = 0)
{
@@ -400,12 +580,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)
{
@@ -423,8 +675,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);
@@ -435,6 +689,7 @@ class PHPFSPOT {
*
* this function provides all the necessary information
* for the single photo template.
+ * @param integer photo
*/
public function showPhoto($photo)
{
@@ -474,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");
@@ -489,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);
}
@@ -507,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";
@@ -531,37 +794,54 @@ 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);
- $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 .'/'. $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 ."&version=". $version);
+ $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->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->show("single_photo.tpl");
+ $this->tmpl->register_function("photo_version_select_list", array(&$this, "smarty_photo_version_select_list"), false);
+
+ return $this->tmpl->fetch("single_photo.tpl");
} // showPhoto()
@@ -620,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;
@@ -628,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;
@@ -638,13 +921,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()
@@ -654,8 +949,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();
@@ -666,7 +962,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.= "
+