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