initial import
[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
41       $this->prepare_single_photo($this->current_photo);
42       $this->tmpl->assign('tags', $this->tags);
43       $this->tmpl->show("index.tpl");
44
45
46    } // show()
47
48    private function get_tags()
49    {
50       $result = $this->db->db_query("
51          SELECT id,name
52          FROM tags
53          ORDER BY sort_priority ASC
54       ");
55       
56       while($row = $this->db->db_fetch_object($result)) {
57
58          $tag_id = $row['id'];
59          $tag_name = $row['name'];
60
61          $this->tags[$tag_id] = $tag_name; 
62
63       }
64    } // get_tags()
65
66    private function get_photos()
67    {
68       $this->avail_photos = Array();
69       $count = 0;
70
71       $result = $this->db->db_query("
72          SELECT id, name
73          FROM photos
74          ORDER BY time ASC
75       ");
76       
77       while($row = $this->db->db_fetch_object($result)) {
78
79          $photo_id = $row['id'];
80          $photo_name = $row['name'];
81
82          $this->photos[$photo_id] = $photo_name;
83          $this->avail_photos[$count] = $photo_id;
84
85          if(!isset($this->current_photo))
86             $this->current_photo = $count;
87
88          $count++;
89
90       }
91
92    } // get_photos()
93
94    public function get_photo_details($idx)
95    {
96       $result = $this->db->db_query("
97          SELECT *
98          FROM photos
99          WHERE id='". $idx ."'
100       ");
101       
102       return $this->db->db_fetch_object($result);
103
104    } // get_photo_details
105
106    public function translate_path($path, $width = 0)
107    {  
108       return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
109
110    } // translate_path
111
112    public function prepare_single_photo($photo)
113    {
114       if(isset($photo)) {
115          $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $this->avail_photos[$photo] ."&amp;width=". $this->cfg->photo_width);
116       }
117
118       if($photo > 0) {
119          $this->tmpl->assign('previous_url', "javascript:showImage(". ($photo-1) .");");
120       }
121
122       if($photo < count($this->avail_photos)) {
123          $this->tmpl->assign('next_url', "javascript:showImage(". ($photo+1) .");");
124       }
125
126    } // prepare_single_photo()
127
128 }
129
130 ?>