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 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
106 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
110 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
113 $this->tmpl->show("single_photo.tpl");
117 public function getAvailableTags()
119 foreach($this->avail_tags as $tag)
121 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags']))
124 // return all available (= not selected) tags
125 print "<a href=\"javascript:Tags('add', ". $tag .");\">". $this->tags[$tag] ."</a> ";
129 } // getAvailableTags()
131 public function getSelectedTags()
133 foreach($this->avail_tags as $tag)
135 // return all selected tags
136 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
137 print "<a href=\"javascript:Tags('del', ". $tag .");\">". $this->tags[$tag] ."</a> ";
142 } // getSelectedTags()
144 public function addTag($tag)
146 if(!isset($_SESSION['selected_tags']))
147 $_SESSION['selected_tags'] = Array();
149 array_push($_SESSION['selected_tags'], $tag);
153 public function delTag($tag)
155 if(isset($_SESSION['selected_tags'])) {
156 $key = array_search($tag, $_SESSION['selected_tags']);
157 unset($_SESSION['selected_tags'][$key]);
162 public function resetTags()
164 unset($_SESSION['selected_tags']);
168 public function getAllTagPhotos()
170 $tagged_photos = Array();
172 if(isset($_SESSION['selected_tags'])) {
174 foreach($_SESSION['selected_tags'] as $tag)
175 $selected.= $tag .",";
176 $selected = substr($selected, 0, strlen($selected)-1);
177 $result = $this->db->db_query("
178 SELECT DISTINCT photo_id
180 WHERE tag_id IN (". $selected .")
184 $result = $this->db->db_query("
185 SELECT DISTINCT photo_id
190 while($row = $this->db->db_fetch_object($result)) {
191 array_push($tagged_photos, $row['photo_id']);
194 return $tagged_photos;
196 } // getAllTagPhotos()
198 public function showPhotoIndex()
200 $photos = $this->getAllTagPhotos();
201 $count = count($photos);
205 $images[$rows] = Array();
207 for($i = 0; $i < $count; $i++) {
209 $images[$rows][$cols] = $photos[$i];
211 if($cols == $this->cfg->thumbs_per_row-1) {
214 $images[$rows] = Array();
221 // +1 for for smarty's selection iteration
224 //$images.= "<img src=\"phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->thumb_width ."\" /><br />\n";
226 $this->tmpl->assign('count', $count);
227 $this->tmpl->assign('width', $this->cfg->thumb_width);
228 $this->tmpl->assign('images', $images);
229 $this->tmpl->assign('rows', $rows);
230 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
231 $this->tmpl->show("photo_index.tpl");
234 } // showPhotoIndex()