root/trunk/dotnode-id.php

Revision 24, 6.8 kB (checked in by alexx, 3 years ago)
  • add Meta Album feature (to link .node profile with external album on Flickr or interAlbum.com)
  • change method to find BASEPATH (to be more reliable)
  • add Meta Album link to profile page (to be modified later)
  • modify default data for db (old data isn't good with cache)
  • add is_valid function to .... valid things ;)
  • add config param for flickr api_key
  • DB: modify database structure to add metalbum table
    CREATE TABLE `metalbum` (
    `id` varchar(32) NOT NULL default '',
    `type` varchar(16) NOT NULL default '',
    `login` varchar(64) NOT NULL default '',
    `nb_items` int(10) unsigned default NULL,
    PRIMARY KEY  (`id`,`type`,`login`)
    ) TYPE=MyISAM;
    
Line 
1 <?php
2 /****************************************************** Open .node ***
3  * Description:   
4  * Status:        Stable.
5  * Author:        Alexandre Dath <alexandre@dotnode.com>
6  * $Id$
7  *
8  * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  ******************** http://opensource.ikse.net/projects/dotnode ***/
24
25 include('../includes/includes.inc.php');
26 include('../includes/config/global.inc.php');
27
28 if(ereg('www', $_SERVER['HTTP_HOST']))
29 {
30     header('Location: http://'.$config['domain'].$_SERVER['PHP_SELF']);
31     exit();
32 }
33
34 $smarty = new Smarty_dotnode;
35
36 $smarty->compile_id = 'www';
37
38 $token = retreive_url_info($_SERVER['PHP_SELF']);
39
40 $cache_array['/news/blog']['lifetime']        = 7200;
41 $cache_array['/communities/last']['lifetime']    = 900;
42 $cache_array['/communities/create']['lifetime']    = 86400;
43 $cache_array['/communities/category']['lifetime'] = 86400;
44 $cache_array['/news']['lifetime']        = 3600;
45 $cache_array['/help/faq']['lifetime']        = 86400;
46 $cache_array['/help/about']['lifetime']        = 86400;
47 $cache_array['/help/terms']['lifetime']        = 86400;
48 $cache_array['/help/privacy']['lifetime']    = 86400;
49 $cache_array['/news/statistics']['lifetime']     = 21600;
50 $cache_array['/support']['lifetime']    = 86400;
51 // $cache_array['/search']['lifetime']        = 3600;
52
53 if(array_key_exists($_SERVER['PHP_SELF'], $cache_array))
54     $smarty->caching = 2;
55
56 session_start();
57
58 if($_SESSION['my_login'] == $config['admin_login'])
59     $smarty->debugging_ctrl = true;
60 else
61     $smarty->debugging_ctrl = false;
62     
63 if(is_valid('user_id', $token[1]))
64     list($url_id) = array_splice($token, 1,1);
65 else
66     $url_id = $_SESSION['my_id'];
67
68
69 switch($_SESSION['my_status'])
70 {
71 case 'waiting':
72     header('Location: /new/profile');
73         exit();
74     break;
75 case 'jail':
76     header('Location: /pub/join');
77     exit();
78     break;
79 }
80
81 if(!$_SESSION['my_id'] || $_SESSION['status'] != 'member' || $_SESSION['SecID'] != $_COOKIE['SecID'] )
82 {
83     header('Location: /pub?url='.urlencode($_SERVER['PHP_SELF']));
84     error_log('bye');
85     exit();
86 }
87
88 // Determination de la template d'aide a afficher
89
90 for($idx=(count($token)-1); $idx>=0; $idx--)
91 {
92         $help_tpl = 'help/';
93         for($level=0; $level<=$idx; $level++)
94                 $help_tpl .= $token[$level].'/';
95         $help_tpl = substr($help_tpl,0,-1).'.tpl';
96         if($smarty->template_exists($help_tpl))
97                 break;
98 }
99
100 if(!$smarty->template_exists($help_tpl))
101         unset($help_tpl);
102 else
103         $_SMARTY['help_tpl'] = $help_tpl;
104
105 for($idx=(count($token)-1); $idx>=0; $idx--)
106 {
107         $tpl = '';
108         for($level=0; $level<=$idx; $level++)
109                 $tpl .= $token[$level].'/';
110         $tpl = substr($tpl,0,-1).'.tpl';
111         if($smarty->template_exists($tpl))
112                 break;
113 }
114
115 if(!$smarty->template_exists($tpl))
116         $tpl='default.tpl';
117
118
119
120 // Determination de l'include PHP a inclure
121 if(!$smarty->is_cached($tpl, $lang.'.'.$_SERVER['PHP_SELF']) || isset($_SESSION['error']) || $_POST )
122 {   
123     for($idx=(count($token)-1); $idx>=0; $idx--)
124     {
125         $inc = '';
126         for($level=0; $level<=$idx; $level++)
127             $inc .= $token[$level].'/';
128         $inc = substr($inc,0,-1).'.inc.php';
129         //    error_log($_SERVER['HTTP_HOST'].' | Include:'.$inc);
130         if(file_exists(INCLUDEPATH.'/'.$inc))
131             break;
132     }
133
134     if(!file_exists(INCLUDEPATH.'/'.$inc))
135         $inc = 'index.inc.php';
136
137
138     $db =& DB::connect($dsn);
139     if (DB::isError($db))
140         error_log($_SERVER['HTTP_HOST'].' | '.__FILE__.' | Connexion SQL impossible : '.$db->getMessage());
141     $db->setFetchMode(DB_FETCHMODE_ASSOC);
142
143     // regeneration de la session toutes les 30 min
144     if($_SESSION['sessionid_timestamp'] < time()-1800 )
145     {
146         session_regenerate_id();
147         $_SESSION['sessionid_timestamp'] = time();
148     }
149
150     // Mise a jour de la table session
151     if($_SESSION['lastaction_timestamp']<time()-300)
152     {
153         $_SESSION['lastaction_timestamp'] = time();
154         $tmp_result = $db->query('UPDATE session SET timestamp=?, SecID=? WHERE id=?', array($_SESSION['lastaction_timestamp'], $_COOKIE['SecID'], $_SESSION['my_id']) );
155         if($db->affectedRows() != 1)
156             $db->query('INSERT INTO session SET id=?, SecID=?, timestamp=?', array($_SESSION['my_id'], $_COOKIE['SecID'], $_SESSION['lastaction_timestamp']) );
157     }
158
159     if($_SESSION['nb_new_messages_timestamp']+300 < time())
160     {
161         $_SESSION['nb_new_messages'] = $db->getOne('SELECT COUNT(id_mess) FROM message WHERE id=? AND box=? AND flag=?', array($_SESSION['my_id'], 'inbox', 'new'));
162         $_SESSION['nb_new_messages_timestamp'] = time();
163         error_log($_SESSION['my_login'].' pop: '.$_SESSION['nb_new_messages'].' ;)');
164     }
165     include (INCLUDEPATH.'/'.$inc);
166
167     $db->disconnect();
168 }
169 else
170     error_log('CACHE_DEBUG: '.$_SERVER['PHP_SELF'].', lifetime: '.$cache_array[$_SERVER['PHP_SELF']]['lifetime'].' CACHED !!!');
171
172 // Exportation des donnees pour Smarty
173 $_SMARTY['token'] = $token;
174 $_SMARTY['full_smenu'] = $smenu;
175 $_SMARTY['full_ssmenu'] = $ssmenu;
176 $_SMARTY['menu'] = $menu['main'];
177 $_SMARTY['smenu'] = $smenu[$token[0]];
178 $_SMARTY['ssmenu'] = $ssmenu[$token[0]][$token[1]];
179 $_SMARTY['tpl'] = $tpl;
180
181 $_SMARTY['url_id'] = $url_id;
182 $_SMARTY['nyrk']   = $nyrk;
183 $_SMARTY['labels'] = $labels;
184 $_SMARTY['access_fields'] = $access_fields;
185
186 if($_SESSION['my_login'] == $config['admin_login'])
187 {
188     $debug['session'] = $_SESSION;
189     $_SMARTY['debug'] = $debug;
190     $_SMARTY['lang']  = $lang;
191     $_SMARTY['php_mem']= memory_get_usage()/1024;
192     $_SMARTY['inc']   = $inc;
193 }
194
195 // Assignation of smarty var
196 $smarty->assign($_SMARTY);
197
198 // Affiche du template
199
200 error_log($_SERVER['HTTP_HOST'].' | '.$_SERVER['PHP_SELF'].' | '.$_SESSION['my_login']);
201
202 header('Content-type: text/html; charset=UTF-8');
203 // ob_start('ob_gzhandler');
204
205 $smarty->caching = false;
206 $smarty->display('index_head.tpl', $lang.'.'.$_SERVER['PHP_SELF']);
207
208 if(array_key_exists($_SERVER['PHP_SELF'], $cache_array) && !isset($_SESSION['error']) && !$_POST )
209 {
210     $smarty->caching=2;
211     $smarty->cache_lifetime = $cache_array[$_SERVER['PHP_SELF']]['lifetime'];
212     $smarty->display($tpl, $lang.'.'.$_SERVER['PHP_SELF']);
213     error_log('CACHE_DEBUG: '.$_SERVER['PHP_SELF'].', lifetime: '.$cache_array[$_SERVER['PHP_SELF']]['lifetime'].' CACHED !!!');
214 }
215 else
216     $smarty->display($tpl);
217
218 $smarty->caching = false;
219 $smarty->display('index_foot.tpl', $lang.'.'.$_SERVER['PHP_SELF']);
220
221 unset($_SESSION['error']);
222 session_unregister('error');
223
224 unset($_SESSION['temp']);
225 session_unregister('temp');
226
227 ?>
228
Note: See TracBrowser for help on using the browser.