+ /**
+ * cleanup phpfspot own database
+ *
+ * When photos are getting delete from F-Spot, there will remain
+ * remain some residues in phpfspot own database. This function
+ * will try to wipe them out.
+ */
+ public function cleanup_phpfspot_db()
+ {
+ $to_delete = Array();
+
+ $result = $this->cfg_db->db_query("
+ SELECT img_idx
+ FROM images
+ ORDER BY img_idx ASC
+ ");
+
+ while($row = $this->cfg_db->db_fetch_object($result)) {
+ if(!$this->db->db_fetchSingleRow("
+ SELECT id
+ FROM photos
+ WHERE id='". $row['img_idx'] ."'")) {
+
+ array_push($to_delete, $row['img_idx'], ',');
+ }
+ }
+
+ print count($to_delete) ." unnecessary objects will be removed from phpfspot's database.\n";
+
+ $this->cfg_db->db_exec("
+ DELETE FROM images
+ WHERE img_idx IN (". implode($to_delete) .")
+ ");
+
+ } // cleanup_phpfspot_db()
+
+ /**
+ * return first image of the page, the $current photo
+ * lies in.
+ *
+ * this function is used to find out the first photo of the
+ * current page, in which the $current photo lies. this is
+ * used to display the correct photo, when calling showPhotoIndex()
+ * from showImage()
+ * @param integer $current
+ * @param integer $max
+ * @return integer
+ */
+ private function getCurrentPage($current, $max)
+ {
+ if(isset($this->cfg->thumbs_per_page) && !empty($this->cfg->thumbs_per_page)) {
+ for($page_start = 0; $page_start <= $max; $page_start+=$this->cfg->thumbs_per_page) {
+ if($current >= $page_start && $current < ($page_start+$this->cfg->thumbs_per_page))
+ return $page_start;
+ }
+ }
+ return 0;
+
+ } // getCurrentPage()
+
+ /**
+ * return mime info
+ *
+ * this function tries to find out the correct mime-type
+ * for the provided file.
+ * @param string $file
+ * @return string
+ */
+ public function get_mime_info($file)
+ {
+ $details = getimagesize($file);
+
+ /* if getimagesize() returns empty, try at least to find out the
+ mime type.
+ */
+ if(empty($details) && function_exists('mime_content_type')) {
+
+ // mime_content_type is marked as deprecated in the documentation,
+ // but is it really necessary to force users to install a PECL
+ // extension?
+ $details['mime'] = mime_content_type($file);
+ }
+
+ return $details['mime'];
+
+ } // get_mime_info()
+
+ /**
+ * return tag-name by tag-idx
+ *
+ * this function returns the tag-name for the requested
+ * tag specified by tag-idx.
+ * @param integer $idx
+ * @return string
+ */
+ public function get_tag_name($idx)
+ {
+ if($result = $this->db->db_fetchSingleRow("
+ SELECT name
+ FROM tags
+ WHERE
+ id LIKE '". $idx ."'")) {
+
+ return $result['name'];
+
+ }
+
+ return 0;
+
+ } // get_tag_name()
+
+ /**
+ * parse user friendly url which got rewritten by the websever
+ * @param string $request_uri
+ * @return string
+ */
+ private function parse_user_friendly_url($request_uri)
+ {
+ if(preg_match('/\/photoview\/|\/photo\/|\/tag\//', $request_uri)) {
+
+ $options = explode('/', $request_uri);
+
+ switch($options[1]) {
+ case 'photoview':
+ if(is_numeric($options[2])) {
+ $this->session_cleanup();
+ //unset($_SESSION['start_action']);
+ //unset($_SESSION['selected_tags']);
+ $_GET['mode'] = 'showp';
+ return $this->showPhoto($options[2]);
+ }
+ break;
+ case 'photo':
+ if(is_numeric($options[2])) {
+ require_once "phpfspot_img.php";
+ $img = new PHPFSPOT_IMG;
+ if(isset($options[3]) && is_numeric($options[3]))
+ $img->showImg($options[2], $options[3]);
+ else
+ $img->showImg($options[2]);
+ }
+ exit;
+ break;
+ case 'tag':
+ if(is_numeric($options[2])) {
+ $this->session_cleanup();
+ $_GET['tags'] = $options[2];
+ $_SESSION['selected_tags'] = Array($options[2]);
+ if(isset($options[3]) && is_numeric($options[3]))
+ $_SESSION['begin_with'] = $options[3];
+ return $this->showPhotoIndex();
+ }
+ break;
+ }
+ }
+
+ } // parse_user_friendly_url()
+
+ /**
+ * check if user-friendly-urls are enabled
+ *
+ * this function will return true, if the config option
+ * $user_friendly_url has been set. Otherwise false.
+ * @return boolean
+ */
+ private function is_user_friendly_url()
+ {
+ if(isset($this->cfg->user_friendly_url) && $this->cfg->user_friendly_url)
+ return true;
+
+ return false;
+
+ } // is_user_friendly_url()
+
+ /**
+ * session cleanup
+ *
+ * this function will cleanup user's session information
+ */
+ private function session_cleanup()
+ {
+ unset($_SESSION['begin_with']);
+ $this->resetDateSearch();
+ $this->resetPhotoView();
+ $this->resetTagSearch();
+ $this->resetNameSearch();
+ $this->resetDateSearch();
+ $this->resetTags();
+
+ } // session_cleanup()
+