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->prepare_single_photo($this->current_photo);
43 $this->tmpl->assign('tags', $this->tags);
44 $this->tmpl->show("index.tpl");
49 private function get_tags()
51 $this->avail_tags = Array();
54 $result = $this->db->db_query("
57 ORDER BY sort_priority ASC
60 while($row = $this->db->db_fetch_object($result)) {
63 $tag_name = $row['name'];
65 $this->tags[$tag_id] = $tag_name;
66 $this->avail_tags[$count] = $tag_id;
74 private function get_photos()
76 $this->avail_photos = Array();
79 $result = $this->db->db_query("
85 while($row = $this->db->db_fetch_object($result)) {
87 $photo_id = $row['id'];
88 $photo_name = $row['name'];
90 $this->photos[$photo_id] = $photo_name;
91 $this->avail_photos[$count] = $photo_id;
93 if(!isset($this->current_photo))
94 $this->current_photo = $count;
102 public function get_photo_details($idx)
104 $result = $this->db->db_query("
107 WHERE id='". $idx ."'
110 return $this->db->db_fetch_object($result);
112 } // get_photo_details
114 public function translate_path($path, $width = 0)
116 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
120 public function prepare_single_photo($photo)
123 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $this->avail_photos[$photo] ."&width=". $this->cfg->photo_width);
127 $this->tmpl->assign('previous_url', "javascript:showImage(". ($photo-1) .");");
130 if($photo < count($this->avail_photos)) {
131 $this->tmpl->assign('next_url', "javascript:showImage(". ($photo+1) .");");
134 } // prepare_single_photo()
136 public function getAvailableTags()
138 foreach($this->avail_tags as $tag)
140 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags']))
143 // return all available (= not selected) tags
144 print "<a href=\"javascript:Tags('add', ". $tag .");\">". $this->tags[$tag] ."</a> ";
148 } // getAvailableTags()
150 public function getSelectedTags()
152 foreach($this->avail_tags as $tag)
154 // return all selected tags
155 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
156 print "<a href=\"javascript:Tags('del', ". $tag .");\">". $this->tags[$tag] ."</a> ";
161 print "<a href=\"javascript:Tags('reset', 0);\">Reset Tags</a>";
163 } // getSelectedTags()
165 public function addTag($tag)
167 if(!isset($_SESSION['selected_tags']))
168 $_SESSION['selected_tags'] = Array();
170 array_push($_SESSION['selected_tags'], $tag);
174 public function delTag($tag)
176 if(isset($_SESSION['selected_tags'])) {
177 $key = array_search($tag, $_SESSION['selected_tags']);
178 unset($_SESSION['selected_tags'][$key]);
183 public function resetTags()
185 unset($_SESSION['selected_tags']);