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