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