Commit | Line | Data |
---|---|---|
65c78def H |
1 | <?php |
2 | function display() { | |
cc43b45f | 3 | global $node,$db,$error,$referer_id,$smarty,$permissions,$template_id; |
b17a1e9b | 4 | global $timer_start; |
65c78def H |
5 | if (!$referer_id) $referer_id=1; |
6 | ||
7 | $node_id=$node['node_id']; | |
80ce65a7 | 8 | $user_id=$_SESSION['user_id']; |
65c78def H |
9 | |
10 | if ($permissions['r']) { | |
11 | ||
12 | // these 4 lines are not the source of kyberia lagging problems. | |
13 | // leave them. started on the 10.4. | |
14 | // data gained will be used for scientific purposes | |
15 | ||
16 | // if (isset($_SESSION['user_id']) { | |
17 | // log_levenshtein($_SESSION['user_id'],$node['node_id']); | |
18 | // } | |
19 | ||
20 | if ((isset($_SESSION['user_id'])) && ($_SESSION['user_id'])) { | |
21 | $q="insert delayed into levenshtein set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."'"; | |
22 | $db->update($q); | |
23 | } | |
24 | ||
25 | //if node is css | |
26 | //XXX into function | |
27 | if ($node['template_id']!='2019721'){ | |
28 | ||
29 | logger::log('enter',$node['node_id'],'ok',$node['node_user_subchild_count']); | |
30 | if (!empty($_SESSION['user_id']) && is_numeric($node['node_id'])) { | |
31 | $q="update node_access set visits=visits+1,node_user_subchild_count='0',last_visit=NOW() where node_id='".$node['node_id']."' and user_id='".$_SESSION['user_id']."'"; | |
32 | // echo $q; | |
33 | $result=$db->update($q); | |
34 | ||
35 | if (!$result) { | |
36 | $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()"; | |
37 | $db->query($q); | |
38 | } | |
39 | }//end of if node os css | |
40 | } | |
41 | ||
42 | } | |
43 | ||
44 | //XXX into function | |
45 | // if (isset($_SESSION['user_id']) { | |
46 | // if (isset($referer_id)) { | |
47 | // update_nodes($_SESSION['user_id'],$node['node_id'],$referer_id); | |
48 | // } else { | |
49 | // update_nodes($_SESSION['user_id'],$node['node_id'],0); | |
50 | // } | |
51 | // } | |
52 | ||
65c78def H |
53 | |
54 | //assigning user data to smarty if user logged in | |
55 | if (isset($_SESSION['user_id'])&&($user_id=$_SESSION['user_id'])) { | |
56 | $smarty->assign('_POST',$_POST); | |
57 | $smarty->assign('bookmarks',$_SESSION['bookmarks']); | |
b17a1e9b | 58 | if (isset($_SESSION['ignore'])) { $smarty->assign('ignore',$_SESSION['ignore']); }; |
65c78def | 59 | $smarty->assign('bookstyl',$_SESSION['bookstyl']); |
b17a1e9b | 60 | if (isset($_SESSION['fook'])) {$smarty->assign('fook',$_SESSION['fook']); }; |
65c78def H |
61 | $smarty->assign('user_id',$_SESSION['user_id']); |
62 | $smarty->assign('user_name',$_SESSION['user_name']); | |
63 | if (!empty($_SESSION['cube_vector'])) | |
64 | $smarty->assign('cube_vector',$_SESSION['cube_vector']); | |
65 | $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural | |
b17a1e9b | 66 | if (isset($_SESSION['user_quota'])) {$smarty->assign('user_quota',$_SESSION['user_quota']);}; |
65c78def H |
67 | |
68 | // XXX into function | |
69 | $newmail_q = sprintf('select u.user_mail_id | |
70 | , u.user_k | |
71 | , u.k_wallet | |
72 | , u.user_mail | |
73 | , ms.user_id as mail_sender_id | |
74 | , ms.login as mail_sender | |
75 | from users u | |
76 | left join users ms on ms.user_id = u.user_mail_id | |
77 | where u.user_id = %d', | |
78 | $user_id); | |
79 | $newmailset = $db->query($newmail_q); | |
80 | ||
81 | ||
82 | $newmailset->next(); | |
83 | $new_mail=$newmailset->getString('user_mail'); | |
84 | // XXX into function | |
85 | $newmailset2 = $db->query("select users.user_mail_id,mailsender.login | |
86 | from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'"); | |
87 | $newmailset2->next(); | |
88 | $smarty->assign('new_mail',$new_mail); | |
89 | $smarty->assign('new_mail_name',$newmailset->getString('mail_sender')); | |
90 | $smarty->assign('new_mail_name2',$newmailset2->getString('login')); | |
91 | $user_k=$newmailset->getString('user_k'); | |
92 | $smarty->assign('user_k',$user_k); | |
93 | $k_wallet=$newmailset->getString('k_wallet'); | |
94 | $smarty->assign('k_wallet',$k_wallet); | |
95 | $user_id=$_SESSION['user_id']; | |
96 | ||
97 | //mail node | |
98 | if ($node['node_name']=='mail') { | |
99 | ||
100 | //clear new mail message | |
101 | ||
102 | if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'"); | |
103 | ||
104 | //set messages as delivered to recipient | |
105 | $set=$db->query("select mail_id,mail_duplicate_id from mail where mail_user='$user_id' and mail_to='$user_id' and mail_read='no'"); | |
106 | while($set->next()) { | |
107 | $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'"); | |
108 | $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'"); | |
109 | ||
110 | $new_messages[$set->getString('mail_id')]=true; | |
111 | } | |
112 | /* | |
113 | if (count($new_messages)) { | |
114 | $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'"); | |
115 | $smarty->assign('new_messages',$new_messages); | |
116 | ||
117 | } | |
118 | */ | |
119 | } | |
120 | } | |
121 | ||
122 | ||
123 | ||
124 | if ($node['node_system_access']=='crypto') { | |
125 | $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]); | |
126 | } | |
127 | ||
128 | $smarty->assign('error',$error); | |
129 | $smarty->assign('permissions',$permissions); | |
130 | $smarty->assign('current_vector',$node['node_vector']); | |
131 | if ($permissions['r']) { | |
132 | $smarty->assign('node',$node); | |
133 | $smarty->assign('node_json',json_encode($node)); | |
134 | } | |
135 | else { | |
65c78def H |
136 | $smarty->assign('node',$node); |
137 | //new templates by Dark matter | |
138 | $smarty->template_dir=OWN_TEMPLATE_DIR; | |
139 | ||
140 | $smarty->display('1549864.tpl'); | |
141 | $smarty->display('1549885.tpl'); | |
142 | $smarty->display('630526.tpl'); | |
143 | die(); | |
144 | ||
145 | //redirect to mainpage | |
146 | // looks like poeple totaly hate this redirect! | |
147 | // header("Location: /id/1"); | |
148 | } | |
149 | ||
150 | ||
151 | // XXX into function | |
152 | if (($node['template_id']!='2019721') && (isset($_SESSION['user_id']))){ | |
153 | //setting user location | |
154 | $q="update users set last_action=NOW(),user_location_vector='".$node['node_vector']."',user_action='".addslashes($node['node_name'])."',user_action_id='".$node['node_id']."' where user_id='".$_SESSION['user_id']."'"; | |
d068d94b | 155 | $db->query($q); |
65c78def H |
156 | } |
157 | ||
158 | $whole_time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7); | |
159 | $smarty->assign('whole_time',$whole_time); | |
160 | ||
161 | ||
162 | if ($template_id=='download' OR $template_id=='download.jpg') { | |
163 | if ($permissions['r']) { | |
164 | $linkname = SYSTEM_ROOT."/files/".$node['node_id']; | |
165 | $filename= readlink($linkname); | |
166 | $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename); | |
167 | ||
168 | $ext = substr( $filename,-3 ); | |
169 | if( $filename == "" ) { | |
170 | echo "ERROR: Empty file to download. "; | |
171 | exit; | |
172 | } elseif ( ! file_exists( $filename ) ) { | |
173 | exit; | |
174 | }; | |
175 | switch( strtolower($ext) ){ | |
176 | case "pdf": $ctype="application/pdf"; break; | |
177 | case "exe": $ctype="application/octet-stream"; break; | |
178 | case "zip": $ctype="application/zip"; break; | |
179 | case "doc": $ctype="application/msword"; break; | |
180 | case "xls": $ctype="application/vnd.ms-excel"; break; | |
181 | case "ppt": $ctype="application/vnd.ms-powerpoint"; break; | |
182 | case "gif": $ctype="image/gif"; break; | |
183 | case "png": $ctype="image/png"; break; | |
184 | case "jpg": $ctype="image/jpg"; break; | |
185 | default: $ctype="application/force-download"; | |
186 | } | |
187 | $file=str_replace(" ","_",$node['node_name']).".$ext"; | |
188 | header("Pragma: public"); | |
189 | header("Expires: 0"); | |
190 | header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
191 | header("Content-Type: $ctype"); | |
192 | $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]); | |
193 | if ((is_integer (strpos($user_agent, "msie"))) && (is_integer | |
194 | (strpos($user_agent, "win")))) { | |
195 | header( "Content-Disposition: filename=$file;" ); | |
196 | } else { | |
197 | header( "Content-Disposition: attachment; | |
198 | filename=$file;" ); | |
199 | } | |
200 | header("Content-Transfer-Encoding: binary"); | |
201 | header("Content-Length: ".filesize($filename)); | |
202 | readfile("$filename"); | |
203 | exit(); | |
204 | } | |
205 | else { echo "you don't have permissions for downloading this data"; die(); } | |
206 | } | |
207 | ||
208 | if ($node['template_id']=='2019721'){ | |
209 | Header("Cache-control: max-age=3600"); | |
210 | }else{ | |
211 | Header("Cache-control: no-cache"); | |
212 | Header("Expires:".gmdate("D, d M Y H:i:s")." GMT"); | |
213 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); | |
214 | } | |
215 | ||
216 | ||
217 | //for cases like search & preview | |
218 | $smarty->assign('post_vars',$_POST); | |
219 | if (!empty($_POST['template_event'])) { | |
220 | $smarty->assign('template_event',$_POST['template_event']); | |
221 | ||
222 | } | |
223 | ||
224 | //setting listing parameters | |
225 | $children_count=$node['node_children_count']; | |
226 | $descendant_count=$node['node_descendant_count']; | |
227 | ||
228 | if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) { | |
229 | $listing_amount=mysql_real_escape_string($_POST['listing_amount']); | |
230 | }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount']; | |
231 | else $listing_amount=DEFAULT_LISTING_AMOUNT; | |
232 | $smarty->assign('listing_amount',$listing_amount); | |
233 | ||
234 | if (isset($_POST['listing_order']) && $_POST['listing_order']) { | |
235 | $listing_order=mysql_real_escape_string($_POST['listing_order']); | |
236 | } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order']; | |
237 | else $listing_order=DEFAULT_LISTING_ORDER; | |
238 | $smarty->assign('listing_order',$listing_order); | |
239 | ||
240 | if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) { | |
241 | $offset=$_POST['get_children_offset']; | |
242 | } else { $offset=0; } | |
243 | ||
244 | ||
245 | //movement forward and backward | |
246 | // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount; | |
247 | ||
b17a1e9b | 248 | if (isset($_POST['get_children_move'])) { |
249 | if ($_POST['get_children_move']=='<') { | |
250 | $offset=$offset-$listing_amount; | |
251 | if ($offset<0) $offset=0; | |
252 | } | |
253 | elseif ($_POST['get_children_move']=='>') { | |
254 | $offset=$offset+$listing_amount; | |
255 | } | |
256 | elseif ($_POST['get_children_move']=='>>') { | |
257 | $offset=$descendant_count-$listing_amount; | |
258 | } | |
259 | ||
260 | elseif ($_POST['get_children_move']=='<<') { | |
261 | $offset=0; | |
262 | } | |
263 | } | |
264 | if ($offset<0) $offset=0; | |
265 | $_POST['offset']=$offset; // XXX sqli? | |
266 | $smarty->assign('offset',$offset); | |
65c78def H |
267 | |
268 | ||
269 | if ($node['external_link']=='header://svg' && !is_numeric($template_id)) { | |
270 | header("Content-Type: image/svg+xml"); | |
271 | } | |
272 | ||
273 | //show own header | |
274 | elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) { | |
275 | $smarty->assign('header_id',$_SESSION['header_id']); | |
276 | $smarty->template_dir=OWN_TEMPLATE_DIR; | |
277 | $content=$smarty->fetch($_SESSION['header_id'].".tpl"); | |
278 | $smarty->template_dir = TEMPLATE_DIR.TEMPLATE_SET; | |
279 | //not registered user | |
280 | if ($_SESSION['header_id']==2091520) { | |
281 | echo $content; | |
282 | session_destroy(); | |
283 | die(); | |
284 | } | |
285 | } | |
286 | ||
287 | $smarty->template_dir=OWN_TEMPLATE_DIR; | |
288 | ||
289 | if (is_numeric($template_id)) { | |
290 | $content.=$smarty->fetch($template_id.".tpl"); | |
291 | } | |
292 | ||
293 | else { | |
294 | $template_id=$node['template_id']; | |
295 | $content.=$smarty->fetch($node['template_id'].".tpl"); | |
296 | } | |
297 | ||
b17a1e9b | 298 | // XXX remove constant |
65c78def H |
299 | if ($template_id=='2019721'){ |
300 | $content=$smarty->fetch($template_id.".tpl"); | |
301 | echo $content; | |
302 | }else{ | |
303 | $time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7); | |
304 | echo $content; | |
305 | // echo "<center>page generation took: $time second</center>"; | |
306 | } | |
307 | //end of displaying | |
308 | ||
cc43b45f | 309 | return true; |
80ce65a7 | 310 | } |