3 global $node,$db,$error,$referer_id,$smarty,$permissions;
4 if (!$referer_id) $referer_id=1;
6 $node_id=$node['node_id'];
7 $user_id=$_SESSION['user_id'];
9 if ($permissions['r']) {
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
15 // if (isset($_SESSION['user_id']) {
16 // log_levenshtein($_SESSION['user_id'],$node['node_id']);
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']."'";
26 if ($node['template_id']!='2019721'){
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']."'";
32 $result=$db->update($q);
35 $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()";
38 }//end of if node os css
44 // if (isset($_SESSION['user_id']) {
45 // if (isset($referer_id)) {
46 // update_nodes($_SESSION['user_id'],$node['node_id'],$referer_id);
48 // update_nodes($_SESSION['user_id'],$node['node_id'],0);
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);
59 $q="insert into neurons set synapse_creator='".$_SESSION['user_id']."',dst='".$node['node_id']."',src='$referer_id',synapse=1";
63 logger::log('enter',$node['node_id'],'failed');
68 //assigning user data to smarty if user logged in
69 if (isset($_SESSION['user_id'])&&($user_id=$_SESSION['user_id'])) {
70 $smarty->assign('_POST',$_POST);
71 $smarty->assign('bookmarks',$_SESSION['bookmarks']);
72 $smarty->assign('ignore',$_SESSION['ignore']);
73 $smarty->assign('bookstyl',$_SESSION['bookstyl']);
74 $smarty->assign('fook',$_SESSION['fook']);
75 $smarty->assign('user_id',$_SESSION['user_id']);
76 $smarty->assign('user_name',$_SESSION['user_name']);
77 if (!empty($_SESSION['cube_vector']))
78 $smarty->assign('cube_vector',$_SESSION['cube_vector']);
79 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
80 $smarty->assign('user_quota',$_SESSION['user_quota']);
83 $newmail_q = sprintf('select u.user_mail_id
87 , ms.user_id as mail_sender_id
88 , ms.login as mail_sender
90 left join users ms on ms.user_id = u.user_mail_id
91 where u.user_id = %d',
93 $newmailset = $db->query($newmail_q);
97 $new_mail=$newmailset->getString('user_mail');
99 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
100 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
101 $newmailset2->next();
102 $smarty->assign('new_mail',$new_mail);
103 $smarty->assign('new_mail_name',$newmailset->getString('mail_sender'));
104 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
105 $user_k=$newmailset->getString('user_k');
106 $smarty->assign('user_k',$user_k);
107 $k_wallet=$newmailset->getString('k_wallet');
108 $smarty->assign('k_wallet',$k_wallet);
109 $user_id=$_SESSION['user_id'];
112 if ($node['node_name']=='mail') {
114 //clear new mail message
116 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
118 //set messages as delivered to recipient
119 $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'");
120 while($set->next()) {
121 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
122 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
124 $new_messages[$set->getString('mail_id')]=true;
127 if (count($new_messages)) {
128 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
129 $smarty->assign('new_messages',$new_messages);
138 if ($node['node_system_access']=='crypto') {
139 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
142 $smarty->assign('error',$error);
143 $smarty->assign('permissions',$permissions);
144 $smarty->assign('current_vector',$node['node_vector']);
145 if ($permissions['r']) {
146 $smarty->assign('node',$node);
147 $smarty->assign('node_json',json_encode($node));
151 $smarty->assign('node',$node);
152 //new templates by Dark matter
153 $smarty->template_dir=OWN_TEMPLATE_DIR;
155 $smarty->display('1549864.tpl');
156 $smarty->display('1549885.tpl');
157 $smarty->display('630526.tpl');
160 //redirect to mainpage
161 // looks like poeple totaly hate this redirect!
162 // header("Location: /id/1");
167 if (($node['template_id']!='2019721') && (isset($_SESSION['user_id']))){
168 //setting user location
169 $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']."'";
170 $db->executequery($q);
173 $whole_time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
174 $smarty->assign('whole_time',$whole_time);
177 if ($template_id=='download' OR $template_id=='download.jpg') {
178 if ($permissions['r']) {
179 $linkname = SYSTEM_ROOT."/files/".$node['node_id'];
180 $filename= readlink($linkname);
181 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
183 $ext = substr( $filename,-3 );
184 if( $filename == "" ) {
185 echo "ERROR: Empty file to download. ";
187 } elseif ( ! file_exists( $filename ) ) {
190 switch( strtolower($ext) ){
191 case "pdf": $ctype="application/pdf"; break;
192 case "exe": $ctype="application/octet-stream"; break;
193 case "zip": $ctype="application/zip"; break;
194 case "doc": $ctype="application/msword"; break;
195 case "xls": $ctype="application/vnd.ms-excel"; break;
196 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
197 case "gif": $ctype="image/gif"; break;
198 case "png": $ctype="image/png"; break;
199 case "jpg": $ctype="image/jpg"; break;
200 default: $ctype="application/force-download";
202 $file=str_replace(" ","_",$node['node_name']).".$ext";
203 header("Pragma: public");
204 header("Expires: 0");
205 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
206 header("Content-Type: $ctype");
207 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
208 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
209 (strpos($user_agent, "win")))) {
210 header( "Content-Disposition: filename=$file;" );
212 header( "Content-Disposition: attachment;
215 header("Content-Transfer-Encoding: binary");
216 header("Content-Length: ".filesize($filename));
217 readfile("$filename");
220 else { echo "you don't have permissions for downloading this data"; die(); }
223 if ($node['template_id']=='2019721'){
224 Header("Cache-control: max-age=3600");
226 Header("Cache-control: no-cache");
227 Header("Expires:".gmdate("D, d M Y H:i:s")." GMT");
228 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
232 //for cases like search & preview
233 $smarty->assign('post_vars',$_POST);
234 if (!empty($_POST['template_event'])) {
235 $smarty->assign('template_event',$_POST['template_event']);
239 //setting listing parameters
240 $children_count=$node['node_children_count'];
241 $descendant_count=$node['node_descendant_count'];
243 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
244 $listing_amount=mysql_real_escape_string($_POST['listing_amount']);
245 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
246 else $listing_amount=DEFAULT_LISTING_AMOUNT;
247 $smarty->assign('listing_amount',$listing_amount);
249 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
250 $listing_order=mysql_real_escape_string($_POST['listing_order']);
251 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
252 else $listing_order=DEFAULT_LISTING_ORDER;
253 $smarty->assign('listing_order',$listing_order);
255 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
256 $offset=$_POST['get_children_offset'];
257 } else { $offset=0; }
260 //movement forward and backward
261 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
263 if ($_POST['get_children_move']=='<') {
264 $offset=$offset-$listing_amount;
265 if ($offset<0) $offset=0;
267 elseif ($_POST['get_children_move']=='>') {
268 $offset=$offset+$listing_amount;
270 elseif ($_POST['get_children_move']=='>>') {
271 $offset=$descendant_count-$listing_amount;
274 elseif ($_POST['get_children_move']=='<<') {
277 if ($offset<0) $offset=0;
278 $_POST['offset']=$offset;
279 $smarty->assign('offset',$offset);
282 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
283 header("Content-Type: image/svg+xml");
287 elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
288 $smarty->assign('header_id',$_SESSION['header_id']);
289 $smarty->template_dir=OWN_TEMPLATE_DIR;
290 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
291 $smarty->template_dir = TEMPLATE_DIR.TEMPLATE_SET;
292 //not registered user
293 if ($_SESSION['header_id']==2091520) {
300 $smarty->template_dir=OWN_TEMPLATE_DIR;
302 if (is_numeric($template_id)) {
303 $content.=$smarty->fetch($template_id.".tpl");
307 $template_id=$node['template_id'];
308 $content.=$smarty->fetch($node['template_id'].".tpl");
311 if ($template_id=='2019721'){
312 $content=$smarty->fetch($template_id.".tpl");
315 $time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
317 // echo "<center>page generation took: $time second</center>";