3 require_once "phpfspot_cfg.php";
4 require_once "phpfspot_db.php";
5 require_once "phpfspot_tmpl.php";
17 public function __construct()
19 $this->cfg = new PHPFSPOT_CFG;
21 $this->db = new PHPFSPOT_DB(&$this, $this->cfg->fspot_db);
22 $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db);
23 $this->tmpl = new PHPFSPOT_TMPL($this);
29 public function __destruct()
34 public function show()
36 $this->tmpl->assign('page_title', $this->cfg->page_title);
37 $this->tmpl->show("index.tpl");
41 private function get_tags()
43 $this->avail_tags = Array();
46 $result = $this->db->db_query("
49 ORDER BY sort_priority ASC
52 while($row = $this->db->db_fetch_object($result)) {
55 $tag_name = $row['name'];
57 $this->tags[$tag_id] = $tag_name;
58 $this->avail_tags[$count] = $tag_id;
66 public function get_photo_details($idx)
68 $result = $this->db->db_query("
74 return $this->db->db_fetch_object($result);
76 } // get_photo_details
78 public function translate_path($path, $width = 0)
80 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
84 public function showPhoto($photo)
86 $all_photos = $this->getAllTagPhotos();
88 foreach($all_photos as $all_photo) {
91 $next_img = $all_photo;
95 if($all_photo == $photo) {
99 $previous_img = $all_photo;
104 $details = $this->get_photo_details($photo);
105 $meta = $this->get_meta_informations($this->translate_path($details['directory_path']) ."/". $details['name']);
107 $this->tmpl->assign('c_date', $meta['DateTime']);
108 $this->tmpl->assign('madewith', $meta['Make'] ." ". $meta['Model']);
109 $this->tmpl->assign('image_name', $details['name']);
110 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
113 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
117 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
120 $this->tmpl->show("single_photo.tpl");
124 public function getAvailableTags()
126 foreach($this->avail_tags as $tag)
128 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags']))
131 // return all available (= not selected) tags
132 print "<a href=\"javascript:Tags('add', ". $tag .");\">". $this->tags[$tag] ."</a> ";
136 } // getAvailableTags()
138 public function getSelectedTags()
140 foreach($this->avail_tags as $tag)
142 // return all selected tags
143 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
144 print "<a href=\"javascript:Tags('del', ". $tag .");\">". $this->tags[$tag] ."</a> ";
149 } // getSelectedTags()
151 public function addTag($tag)
153 if(!isset($_SESSION['selected_tags']))
154 $_SESSION['selected_tags'] = Array();
156 array_push($_SESSION['selected_tags'], $tag);
160 public function delTag($tag)
162 if(isset($_SESSION['selected_tags'])) {
163 $key = array_search($tag, $_SESSION['selected_tags']);
164 unset($_SESSION['selected_tags'][$key]);
169 public function resetTags()
171 unset($_SESSION['selected_tags']);
175 public function getAllTagPhotos()
177 $tagged_photos = Array();
179 if(isset($_SESSION['selected_tags'])) {
181 foreach($_SESSION['selected_tags'] as $tag)
182 $selected.= $tag .",";
183 $selected = substr($selected, 0, strlen($selected)-1);
184 $result = $this->db->db_query("
185 SELECT DISTINCT photo_id
189 WHERE pt.tag_id IN (". $selected .")
194 $result = $this->db->db_query("
195 SELECT DISTINCT photo_id
203 while($row = $this->db->db_fetch_object($result)) {
204 array_push($tagged_photos, $row['photo_id']);
207 return $tagged_photos;
209 } // getAllTagPhotos()
211 public function showPhotoIndex()
213 $photos = $this->getAllTagPhotos();
214 $count = count($photos);
218 $images[$rows] = Array();
220 for($i = 0; $i < $count; $i++) {
222 $images[$rows][$cols] = $photos[$i];
224 if($cols == $this->cfg->thumbs_per_row-1) {
227 $images[$rows] = Array();
234 // +1 for for smarty's selection iteration
237 //$images.= "<img src=\"phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->thumb_width ."\" /><br />\n";
239 $this->tmpl->assign('count', $count);
240 $this->tmpl->assign('width', $this->cfg->thumb_width);
241 $this->tmpl->assign('images', $images);
242 $this->tmpl->assign('rows', $rows);
243 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
244 $this->tmpl->show("photo_index.tpl");
247 } // showPhotoIndex()
249 public function showBubbleDetails($photo, $direction)
251 if($direction == "up")
252 $direction = "bubbleimg_up";
254 $direction = "bubbleimg_down";
256 $details = $this->get_photo_details($photo);
258 $image_url = "phpfspot_img.php?idx=". $photo ."&width=200";
260 $filesize = filesize($this->translate_path($details['directory_path']) ."/". $details['name']);
261 $filesize = rand($filesize/1024, 2);
263 $img = getimagesize($this->translate_path($details['directory_path']) ."/". $details['name']);
265 $this->tmpl->assign('file_size', $filesize);
266 $this->tmpl->assign('width', $img[0]);
267 $this->tmpl->assign('height', $img[1]);
268 $this->tmpl->assign('file_name', $details['name']);
269 $this->tmpl->assign('image_id', $direction);
270 $this->tmpl->assign('image_url', $image_url);
271 $this->tmpl->show("bubble_details.tpl");
273 } // showBubbleDetails()
275 public function showCredits()
277 $this->tmpl->assign('version', $this->cfg->version);
278 $this->tmpl->assign('product', $this->cfg->product);
279 $this->tmpl->show("credits.tpl");
283 public function resize_image($image, $width)
285 // if thumbnail already exists, don't recreate it
286 if(file_exists(dirname($image) ."/thumbs/". $width ."_". basename($image)))
289 $src_img = @imagecreatefromjpeg($image);
293 /* grabs the height and width */
294 $new_w = imagesx($src_img);
295 $new_h = imagesy($src_img);
297 // If requested width is more then the actual image width,
298 // do not generate a thumbnail
300 if($width >= $new_w) {
301 imagedestroy($src_img);
305 /* calculates aspect ratio */
306 $aspect_ratio = $new_h / $new_w;
310 $new_h = abs($new_w * $aspect_ratio);
312 /* creates new image of that size */
313 $dst_img = imagecreatetruecolor($new_w,$new_h);
315 imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
317 /* copies resized portion of original image into new image */
318 imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
320 /* write down new generated file */
322 if(!file_exists(dirname($image) ."/thumbs"))
323 mkdir(dirname($image) ."/thumbs");
325 $newfile = dirname($image) ."/thumbs/". $width ."_". basename($image);
326 imagejpeg($dst_img, $newfile, 75);
329 imagedestroy($dst_img);
330 imagedestroy($src_img);
335 public function get_meta_informations($file)
338 return exif_read_data($file);
340 } // get_meta_informations()