3 require_once "phpfspot_cfg.php";
4 require_once "phpfspot_db.php";
5 require_once "phpfspot_tmpl.php";
19 public function __construct()
21 $this->cfg = new PHPFSPOT_CFG;
23 $this->db = new PHPFSPOT_DB(&$this, $this->cfg->db);
24 $this->tmpl = new PHPFSPOT_TMPL($this);
29 if(isset($_GET['id']) && is_numeric($_GET['id']))
30 $this->current_photo = $_GET['id'];
34 public function __destruct()
39 public function show()
41 $this->tmpl->assign('page_title', $this->cfg->page_title);
42 $this->tmpl->show("index.tpl");
46 private function get_tags()
48 $this->avail_tags = Array();
51 $result = $this->db->db_query("
54 ORDER BY sort_priority ASC
57 while($row = $this->db->db_fetch_object($result)) {
60 $tag_name = $row['name'];
62 $this->tags[$tag_id] = $tag_name;
63 $this->avail_tags[$count] = $tag_id;
71 private function get_photos()
73 $this->avail_photos = Array();
76 $result = $this->db->db_query("
82 while($row = $this->db->db_fetch_object($result)) {
84 $photo_id = $row['id'];
85 $photo_name = $row['name'];
87 $this->photos[$photo_id] = $photo_name;
88 $this->avail_photos[$count] = $photo_id;
90 if(!isset($this->current_photo))
91 $this->current_photo = $count;
99 public function get_photo_details($idx)
101 $result = $this->db->db_query("
104 WHERE id='". $idx ."'
107 return $this->db->db_fetch_object($result);
109 } // get_photo_details
111 public function translate_path($path, $width = 0)
113 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
117 public function showPhoto($photo)
119 $all_photos = $this->getAllTagPhotos();
121 foreach($all_photos as $all_photo) {
124 $next_img = $all_photo;
128 if($all_photo == $photo) {
132 $previous_img = $all_photo;
137 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
141 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
145 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
148 $this->tmpl->show("single_photo.tpl");
152 public function getAvailableTags()
154 foreach($this->avail_tags as $tag)
156 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags']))
159 // return all available (= not selected) tags
160 print "<a href=\"javascript:Tags('add', ". $tag .");\">". $this->tags[$tag] ."</a> ";
164 } // getAvailableTags()
166 public function getSelectedTags()
168 foreach($this->avail_tags as $tag)
170 // return all selected tags
171 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
172 print "<a href=\"javascript:Tags('del', ". $tag .");\">". $this->tags[$tag] ."</a> ";
177 } // getSelectedTags()
179 public function addTag($tag)
181 if(!isset($_SESSION['selected_tags']))
182 $_SESSION['selected_tags'] = Array();
184 array_push($_SESSION['selected_tags'], $tag);
188 public function delTag($tag)
190 if(isset($_SESSION['selected_tags'])) {
191 $key = array_search($tag, $_SESSION['selected_tags']);
192 unset($_SESSION['selected_tags'][$key]);
197 public function resetTags()
199 unset($_SESSION['selected_tags']);
203 public function getAllTagPhotos()
205 $tagged_photos = Array();
207 if(isset($_SESSION['selected_tags'])) {
209 foreach($_SESSION['selected_tags'] as $tag)
210 $selected.= $tag .",";
211 $selected = substr($selected, 0, strlen($selected)-1);
212 $result = $this->db->db_query("
213 SELECT DISTINCT photo_id
215 WHERE tag_id IN (". $selected .")
219 $result = $this->db->db_query("
220 SELECT DISTINCT photo_id
225 while($row = $this->db->db_fetch_object($result)) {
226 array_push($tagged_photos, $row['photo_id']);
229 return $tagged_photos;
231 } // getAllTagPhotos()
233 public function showPhotoIndex()
235 $photos = $this->getAllTagPhotos();
236 $count = count($photos);
240 $images[$rows] = Array();
242 for($i = 0; $i < $count; $i++) {
244 $images[$rows][$cols] = $photos[$i];
246 if($cols == $this->cfg->thumbs_per_row-1) {
249 $images[$rows] = Array();
256 // +1 for for smarty's selection iteration
259 //$images.= "<img src=\"phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->thumb_width ."\" /><br />\n";
261 $this->tmpl->assign('count', $count);
262 $this->tmpl->assign('width', $this->cfg->thumb_width);
263 $this->tmpl->assign('images', $images);
264 $this->tmpl->assign('rows', $rows);
265 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
266 $this->tmpl->show("photo_index.tpl");
269 } // showPhotoIndex()