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()
42 $this->tmpl->assign('tags', $this->tags);
43 $this->tmpl->show("index.tpl");
48 private function get_tags()
50 $this->avail_tags = Array();
53 $result = $this->db->db_query("
56 ORDER BY sort_priority ASC
59 while($row = $this->db->db_fetch_object($result)) {
62 $tag_name = $row['name'];
64 $this->tags[$tag_id] = $tag_name;
65 $this->avail_tags[$count] = $tag_id;
73 private function get_photos()
75 $this->avail_photos = Array();
78 $result = $this->db->db_query("
84 while($row = $this->db->db_fetch_object($result)) {
86 $photo_id = $row['id'];
87 $photo_name = $row['name'];
89 $this->photos[$photo_id] = $photo_name;
90 $this->avail_photos[$count] = $photo_id;
92 if(!isset($this->current_photo))
93 $this->current_photo = $count;
101 public function get_photo_details($idx)
103 $result = $this->db->db_query("
106 WHERE id='". $idx ."'
109 return $this->db->db_fetch_object($result);
111 } // get_photo_details
113 public function translate_path($path, $width = 0)
115 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
119 public function showPhoto($photo)
121 $all_photos = $this->getAllTagPhotos();
123 foreach($all_photos as $all_photo) {
126 $next_img = $all_photo;
130 if($all_photo == $photo) {
134 $previous_img = $all_photo;
139 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
143 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
147 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
150 $this->tmpl->show("single_photo.tpl");
154 public function getAvailableTags()
156 foreach($this->avail_tags as $tag)
158 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags']))
161 // return all available (= not selected) tags
162 print "<a href=\"javascript:Tags('add', ". $tag .");\">". $this->tags[$tag] ."</a> ";
166 } // getAvailableTags()
168 public function getSelectedTags()
170 foreach($this->avail_tags as $tag)
172 // return all selected tags
173 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
174 print "<a href=\"javascript:Tags('del', ". $tag .");\">". $this->tags[$tag] ."</a> ";
179 print "<a href=\"javascript:Tags('reset', 0);\">Reset Tags</a>";
181 } // getSelectedTags()
183 public function addTag($tag)
185 if(!isset($_SESSION['selected_tags']))
186 $_SESSION['selected_tags'] = Array();
188 array_push($_SESSION['selected_tags'], $tag);
192 public function delTag($tag)
194 if(isset($_SESSION['selected_tags'])) {
195 $key = array_search($tag, $_SESSION['selected_tags']);
196 unset($_SESSION['selected_tags'][$key]);
201 public function resetTags()
203 unset($_SESSION['selected_tags']);
207 public function getAllTagPhotos()
209 $tagged_photos = Array();
211 if(isset($_SESSION['selected_tags'])) {
213 foreach($_SESSION['selected_tags'] as $tag)
214 $selected.= $tag .",";
215 $selected = substr($selected, 0, strlen($selected)-1);
216 $result = $this->db->db_query("
217 SELECT DISTINCT photo_id
219 WHERE tag_id IN (". $selected .")
223 $result = $this->db->db_query("
224 SELECT DISTINCT photo_id
229 while($row = $this->db->db_fetch_object($result)) {
230 array_push($tagged_photos, $row['photo_id']);
233 return $tagged_photos;
235 } // getAllTagPhotos()
237 public function showPhotoIndex()
239 $photos = $this->getAllTagPhotos();
240 $count = count($photos);
244 $images[$rows] = Array();
246 for($i = 0; $i < $count; $i++) {
248 $images[$rows][$cols] = $photos[$i];
250 if($cols == $this->cfg->thumbs_per_row-1) {
253 $images[$rows] = Array();
260 // +1 for for smarty's selection iteration
263 //$images.= "<img src=\"phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->thumb_width ."\" /><br />\n";
265 $this->tmpl->assign('count', $count);
266 $this->tmpl->assign('width', $this->cfg->thumb_width);
267 $this->tmpl->assign('images', $images);
268 $this->tmpl->assign('rows', $rows);
269 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
270 $this->tmpl->show("photo_index.tpl");
273 } // showPhotoIndex()