1dd3b9369e33f87d377c83fb2a624fd863ce1072
[phpfspot.git] / phpfspot.class.php
1 <?php
2
3 require_once "phpfspot_cfg.php";
4 require_once "phpfspot_db.php";
5 require_once "phpfspot_tmpl.php";
6
7 class PHPFSPOT {
8
9    var $cfg;
10    var $db;
11    var $tmpl;
12    var $tags;
13    var $avail_photos;
14    var $photos;
15    var $current_photo;
16    var $current_tags;
17
18    public function __construct()
19    {
20       $this->cfg = new PHPFSPOT_CFG;
21
22       $this->db = new PHPFSPOT_DB(&$this, $this->cfg->db);
23       $this->tmpl = new PHPFSPOT_TMPL(&$this);
24
25       $this->get_tags();
26       $this->get_photos();
27
28       if(isset($_GET['id']) && is_numeric($_GET['id']))
29          $this->current_photo = $_GET['id'];
30
31    } // __construct()
32
33    public function __destruct()
34    {
35
36    } // __destruct()
37
38    public function show()
39    {
40       if(isset($this->current_photo)) {
41          $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $this->avail_photos[$this->current_photo] ."&amp;width=". $this->cfg->photo_width);
42       }
43
44       if($this->current_photo > 0) {
45          $this->tmpl->assign('previous_url', "javascript:showImage(". ($this->current_photo-1) .");");
46       }
47
48       if($this->current_photo < count($this->avail_photos)) {
49          $this->tmpl->assign('next_url', "javascript:showImage(". ($this->current_photo+1) .");");
50       }
51
52       $this->tmpl->assign('tags', $this->tags);
53       $this->tmpl->show("index.tpl");
54
55
56    } // show()
57
58    private function get_tags()
59    {
60       $result = $this->db->db_query("
61          SELECT id,name
62          FROM tags
63          ORDER BY sort_priority ASC
64       ");
65       
66       while($row = $this->db->db_fetch_object($result)) {
67
68          $tag_id = $row['id'];
69          $tag_name = $row['name'];
70
71          $this->tags[$tag_id] = $tag_name; 
72
73       }
74    } // get_tags()
75
76    private function get_photos()
77    {
78       $this->avail_photos = Array();
79       $count = 0;
80
81       $result = $this->db->db_query("
82          SELECT id, name
83          FROM photos
84          ORDER BY time ASC
85       ");
86       
87       while($row = $this->db->db_fetch_object($result)) {
88
89          $photo_id = $row['id'];
90          $photo_name = $row['name'];
91
92          $this->photos[$photo_id] = $photo_name;
93          $this->avail_photos[$count] = $photo_id;
94
95          if(!isset($this->current_photo))
96             $this->current_photo = $count;
97
98          $count++;
99
100       }
101
102    } // get_photos()
103
104    public function get_photo_details($idx)
105    {
106       $result = $this->db->db_query("
107          SELECT *
108          FROM photos
109          WHERE id='". $idx ."'
110       ");
111       
112       return $this->db->db_fetch_object($result);
113
114    } // get_photo_details
115
116    public function translate_path($path, $width = 0)
117    {  
118       return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
119
120    } // translate_path
121
122 }
123
124 ?>