3 require_once "phpfspot_cfg.php";
4 require_once "phpfspot_db.php";
5 require_once "phpfspot_tmpl.php";
16 public function __construct()
18 $this->cfg = new PHPFSPOT_CFG;
20 $this->db = new PHPFSPOT_DB(&$this, $this->cfg->db);
21 $this->tmpl = new PHPFSPOT_TMPL($this);
27 public function __destruct()
32 public function show()
34 $this->tmpl->assign('page_title', $this->cfg->page_title);
35 $this->tmpl->show("index.tpl");
39 private function get_tags()
41 $this->avail_tags = Array();
44 $result = $this->db->db_query("
47 ORDER BY sort_priority ASC
50 while($row = $this->db->db_fetch_object($result)) {
53 $tag_name = $row['name'];
55 $this->tags[$tag_id] = $tag_name;
56 $this->avail_tags[$count] = $tag_id;
64 public function get_photo_details($idx)
66 $result = $this->db->db_query("
72 return $this->db->db_fetch_object($result);
74 } // get_photo_details
76 public function translate_path($path, $width = 0)
78 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
82 public function showPhoto($photo)
84 $all_photos = $this->getAllTagPhotos();
86 foreach($all_photos as $all_photo) {
89 $next_img = $all_photo;
93 if($all_photo == $photo) {
97 $previous_img = $all_photo;
102 $details = $this->get_photo_details($photo);
104 $this->tmpl->assign('image_name', $details['name']);
105 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
108 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
112 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
115 $this->tmpl->show("single_photo.tpl");
119 public function getAvailableTags()
121 foreach($this->avail_tags as $tag)
123 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags']))
126 // return all available (= not selected) tags
127 print "<a href=\"javascript:Tags('add', ". $tag .");\">". $this->tags[$tag] ."</a> ";
131 } // getAvailableTags()
133 public function getSelectedTags()
135 foreach($this->avail_tags as $tag)
137 // return all selected tags
138 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
139 print "<a href=\"javascript:Tags('del', ". $tag .");\">". $this->tags[$tag] ."</a> ";
144 } // getSelectedTags()
146 public function addTag($tag)
148 if(!isset($_SESSION['selected_tags']))
149 $_SESSION['selected_tags'] = Array();
151 array_push($_SESSION['selected_tags'], $tag);
155 public function delTag($tag)
157 if(isset($_SESSION['selected_tags'])) {
158 $key = array_search($tag, $_SESSION['selected_tags']);
159 unset($_SESSION['selected_tags'][$key]);
164 public function resetTags()
166 unset($_SESSION['selected_tags']);
170 public function getAllTagPhotos()
172 $tagged_photos = Array();
174 if(isset($_SESSION['selected_tags'])) {
176 foreach($_SESSION['selected_tags'] as $tag)
177 $selected.= $tag .",";
178 $selected = substr($selected, 0, strlen($selected)-1);
179 $result = $this->db->db_query("
180 SELECT DISTINCT photo_id
184 WHERE pt.tag_id IN (". $selected .")
189 $result = $this->db->db_query("
190 SELECT DISTINCT photo_id
198 while($row = $this->db->db_fetch_object($result)) {
199 array_push($tagged_photos, $row['photo_id']);
202 return $tagged_photos;
204 } // getAllTagPhotos()
206 public function showPhotoIndex()
208 $photos = $this->getAllTagPhotos();
209 $count = count($photos);
213 $images[$rows] = Array();
215 for($i = 0; $i < $count; $i++) {
217 $images[$rows][$cols] = $photos[$i];
219 if($cols == $this->cfg->thumbs_per_row-1) {
222 $images[$rows] = Array();
229 // +1 for for smarty's selection iteration
232 //$images.= "<img src=\"phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->thumb_width ."\" /><br />\n";
234 $this->tmpl->assign('count', $count);
235 $this->tmpl->assign('width', $this->cfg->thumb_width);
236 $this->tmpl->assign('images', $images);
237 $this->tmpl->assign('rows', $rows);
238 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
239 $this->tmpl->show("photo_index.tpl");
242 } // showPhotoIndex()
244 public function showBubbleDetails($photo, $direction)
246 if($direction == "up")
247 $direction = "bubbleimg_up";
249 $direction = "bubbleimg_down";
251 $details = $this->get_photo_details($photo);
253 $image_url = "phpfspot_img.php?idx=". $photo ."&width=200";
255 $filesize = filesize($this->translate_path($details['directory_path']) ."/". $details['name']);
256 $filesize = rand($filesize/1024, 2);
258 $img = getimagesize($this->translate_path($details['directory_path']) ."/". $details['name']);
260 $this->tmpl->assign('file_size', $filesize);
261 $this->tmpl->assign('width', $img[0]);
262 $this->tmpl->assign('height', $img[1]);
263 $this->tmpl->assign('file_name', $details['name']);
264 $this->tmpl->assign('image_id', $direction);
265 $this->tmpl->assign('image_url', $image_url);
266 $this->tmpl->show("bubble_details.tpl");
268 } // showBubbleDetails()
270 public function showCredits()
272 $this->tmpl->assign('version', $this->cfg->version);
273 $this->tmpl->assign('product', $this->cfg->product);
274 $this->tmpl->show("credits.tpl");