display event optimization (removed useless query)
[mirrors/Kyberia-bloodline.git] / wwwroot / inc / eventz / display.inc
CommitLineData
65c78def
H
1<?php
2function 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'];
13826e4f 9 $user_id=(empty($_SESSION['user_id'])) ? "" : $_SESSION['user_id'];
65c78def
H
10
11if ($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
21if ((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
28if ($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
56if (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
387da281 98 //mail node //OMG remove constant
99 if ($node['node_id']==MAIL_NODE) {
65c78def
H
100
101 //clear new mail message
387da281 102 if ($new_mail) {
103 //set messages as delivered
104 $db->query("update users set user_mail=0 where user_id='$user_id'");
105 $db->query("update mail set mail_read='yes' where mail_to='$user_id' and mail_read='no'");
65c78def 106 }
65c78def 107
65c78def
H
108 }
109}
110
111
112
113if ($node['node_system_access']=='crypto') {
114 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
115}
116
117$smarty->assign('error',$error);
118$smarty->assign('permissions',$permissions);
119$smarty->assign('current_vector',$node['node_vector']);
120if ($permissions['r']) {
121 $smarty->assign('node',$node);
122 $smarty->assign('node_json',json_encode($node));
123}
124else {
65c78def
H
125 $smarty->assign('node',$node);
126 //new templates by Dark matter
127 $smarty->template_dir=OWN_TEMPLATE_DIR;
128
129 $smarty->display('1549864.tpl');
130 $smarty->display('1549885.tpl');
131 $smarty->display('630526.tpl');
132 die();
133
134 //redirect to mainpage
135// looks like poeple totaly hate this redirect!
136// header("Location: /id/1");
137}
138
139
140// XXX into function
0498dea1 141if (isset($_SESSION['user_id']) && ($_SESSION['user_id']!='')){
142 //setting user location
143 $q="update users set last_action=NOW(),user_location_vector='".
144 $node['node_vector']."',user_action='".addslashes($node['node_name']).
145 "',user_action_id='".$node['node_id']."' where user_id='".$_SESSION['user_id']."'";
41b53a98 146 $db->query($q);
65c78def
H
147}
148
149$whole_time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
150$smarty->assign('whole_time',$whole_time);
151
152
41b53a98 153if ($template_id=='data') {
65c78def 154 if ($permissions['r']) {
41b53a98
DH
155 $linkname = FILE_DIR."/".$node['node_id'];
156 $filename= readlink($linkname);
157 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
158
159 $ext = substr( $filename,-3 );
160 if( $filename == "" ) {
161 echo "ERROR: Empty file to download. ";
162 exit;
163 } elseif ( ! file_exists( $filename ) ) {
164 exit;
65c78def
H
165 };
166 switch( strtolower($ext) ){
167 case "pdf": $ctype="application/pdf"; break;
168 case "exe": $ctype="application/octet-stream"; break;
169 case "zip": $ctype="application/zip"; break;
170 case "doc": $ctype="application/msword"; break;
171 case "xls": $ctype="application/vnd.ms-excel"; break;
172 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
173 case "gif": $ctype="image/gif"; break;
174 case "png": $ctype="image/png"; break;
175 case "jpg": $ctype="image/jpg"; break;
176 default: $ctype="application/force-download";
177 }
178 $file=str_replace(" ","_",$node['node_name']).".$ext";
179 header("Pragma: public");
180 header("Expires: 0");
181 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
182 header("Content-Type: $ctype");
183 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
184 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
185 (strpos($user_agent, "win")))) {
186 header( "Content-Disposition: filename=$file;" );
187 } else {
188 header( "Content-Disposition: attachment;
189 filename=$file;" );
190 }
191 header("Content-Transfer-Encoding: binary");
192 header("Content-Length: ".filesize($filename));
193 readfile("$filename");
194 exit();
195 }
41b53a98
DH
196 else {
197 echo "you don't have permissions for downloading this data";
198 die();
199 }
65c78def
H
200}
201
65c78def
H
202
203
204//for cases like search & preview
205 $smarty->assign('post_vars',$_POST);
206if (!empty($_POST['template_event'])) {
207 $smarty->assign('template_event',$_POST['template_event']);
208
209}
210
211//setting listing parameters
212 $children_count=$node['node_children_count'];
213 $descendant_count=$node['node_descendant_count'];
214
215 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
78f1a5f4 216 $listing_amount=db_escape_string($_POST['listing_amount']);
65c78def
H
217 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
218 else $listing_amount=DEFAULT_LISTING_AMOUNT;
219 $smarty->assign('listing_amount',$listing_amount);
220
221 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
78f1a5f4 222 $listing_order=db_escape_string($_POST['listing_order']);
65c78def
H
223 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
224 else $listing_order=DEFAULT_LISTING_ORDER;
225 $smarty->assign('listing_order',$listing_order);
226
227 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
228 $offset=$_POST['get_children_offset'];
229 } else { $offset=0; }
230
231
232 //movement forward and backward
233// if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
234
b17a1e9b 235 if (isset($_POST['get_children_move'])) {
236 if ($_POST['get_children_move']=='<') {
237 $offset=$offset-$listing_amount;
238 if ($offset<0) $offset=0;
239 }
240 elseif ($_POST['get_children_move']=='>') {
241 $offset=$offset+$listing_amount;
242 }
243 elseif ($_POST['get_children_move']=='>>') {
244 $offset=$descendant_count-$listing_amount;
245 }
246
247 elseif ($_POST['get_children_move']=='<<') {
248 $offset=0;
249 }
250 }
251 if ($offset<0) $offset=0;
252 $_POST['offset']=$offset; // XXX sqli?
253 $smarty->assign('offset',$offset);
65c78def 254
65c78def
H
255if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
256 header("Content-Type: image/svg+xml");
257}
258
259//show own header
260elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
261 $smarty->assign('header_id',$_SESSION['header_id']);
262 $smarty->template_dir=OWN_TEMPLATE_DIR;
263 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
264 $smarty->template_dir = TEMPLATE_DIR.TEMPLATE_SET;
265 //not registered user
266 if ($_SESSION['header_id']==2091520) {
267 echo $content;
268 session_destroy();
269 die();
270 }
271}
272
273$smarty->template_dir=OWN_TEMPLATE_DIR;
274
275if (is_numeric($template_id)) {
276 $content.=$smarty->fetch($template_id.".tpl");
277}
278
279else {
280 $template_id=$node['template_id'];
281 $content.=$smarty->fetch($node['template_id'].".tpl");
282}
283
b17a1e9b 284// XXX remove constant
65c78def
H
285if ($template_id=='2019721'){
286 $content=$smarty->fetch($template_id.".tpl");
287 echo $content;
288}else{
289 $time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
290 echo $content;
291// echo "<center>page generation took: $time second</center>";
292}
293//end of displaying
294
cc43b45f 295 return true;
80ce65a7 296}
This page took 0.702787 seconds and 4 git commands to generate.