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)
122 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
126 $this->tmpl->assign('previous_url', "javascript:showImage(". ($photo-1) .");");
129 if($photo < count($this->photos)) {
130 $this->tmpl->assign('next_url', "javascript:showImage(". ($photo+1) .");");
133 $this->tmpl->show("single_photo.tpl");
137 public function getAvailableTags()
139 foreach($this->avail_tags as $tag)
141 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags']))
144 // return all available (= not selected) tags
145 print "<a href=\"javascript:Tags('add', ". $tag .");\">". $this->tags[$tag] ."</a> ";
149 } // getAvailableTags()
151 public function getSelectedTags()
153 foreach($this->avail_tags as $tag)
155 // return all selected tags
156 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
157 print "<a href=\"javascript:Tags('del', ". $tag .");\">". $this->tags[$tag] ."</a> ";
162 print "<a href=\"javascript:Tags('reset', 0);\">Reset Tags</a>";
164 } // getSelectedTags()
166 public function addTag($tag)
168 if(!isset($_SESSION['selected_tags']))
169 $_SESSION['selected_tags'] = Array();
171 array_push($_SESSION['selected_tags'], $tag);
175 public function delTag($tag)
177 if(isset($_SESSION['selected_tags'])) {
178 $key = array_search($tag, $_SESSION['selected_tags']);
179 unset($_SESSION['selected_tags'][$key]);
184 public function resetTags()
186 unset($_SESSION['selected_tags']);
190 public function getAllTagPhotos()
192 $tagged_photos = Array();
194 if(isset($_SESSION['selected_tags'])) {
196 foreach($_SESSION['selected_tags'] as $tag)
197 $selected.= $tag .",";
198 $selected = substr($selected, 0, strlen($selected)-1);
199 $result = $this->db->db_query("
200 SELECT DISTINCT photo_id
202 WHERE tag_id IN (". $selected .")
206 $result = $this->db->db_query("
207 SELECT DISTINCT photo_id
212 while($row = $this->db->db_fetch_object($result)) {
213 array_push($tagged_photos, $row['photo_id']);
216 return $tagged_photos;
218 } // getAllTagPhotos()
220 public function showPhotoIndex()
222 $photos = $this->getAllTagPhotos();
223 $count = count($photos);
227 $images[$rows] = Array();
229 for($i = 0; $i < $count; $i++) {
231 $images[$rows][$cols] = $photos[$i];
233 if($cols == $this->cfg->thumbs_per_row-1) {
236 $images[$rows] = Array();
243 // +1 for for smarty's selection iteration
246 //$images.= "<img src=\"phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->thumb_width ."\" /><br />\n";
248 $this->tmpl->assign('count', $count);
249 $this->tmpl->assign('width', $this->cfg->thumb_width);
250 $this->tmpl->assign('images', $images);
251 $this->tmpl->assign('rows', $rows);
252 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
253 $this->tmpl->show("photo_index.tpl");
256 } // showPhotoIndex()