| 1 | <?php |
| 2 | function display() { |
| 3 | global $node,$db,$error,$referer_id,$smarty,$permissions; |
| 4 | if (!$referer_id) $referer_id=1; |
| 5 | |
| 6 | $node_id=$node['node_id']; |
| 7 | $user_id=$_SESSION['user_id']; |
| 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 | } else { |
| 63 | logger::log('enter',$node['node_id'],'failed'); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |
| 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']); |
| 81 | |
| 82 | // XXX into function |
| 83 | $newmail_q = sprintf('select u.user_mail_id |
| 84 | , u.user_k |
| 85 | , u.k_wallet |
| 86 | , u.user_mail |
| 87 | , ms.user_id as mail_sender_id |
| 88 | , ms.login as mail_sender |
| 89 | from users u |
| 90 | left join users ms on ms.user_id = u.user_mail_id |
| 91 | where u.user_id = %d', |
| 92 | $user_id); |
| 93 | $newmailset = $db->query($newmail_q); |
| 94 | |
| 95 | |
| 96 | $newmailset->next(); |
| 97 | $new_mail=$newmailset->getString('user_mail'); |
| 98 | // XXX into function |
| 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']; |
| 110 | |
| 111 | //mail node |
| 112 | if ($node['node_name']=='mail') { |
| 113 | |
| 114 | //clear new mail message |
| 115 | |
| 116 | if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'"); |
| 117 | |
| 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')."'"); |
| 123 | |
| 124 | $new_messages[$set->getString('mail_id')]=true; |
| 125 | } |
| 126 | /* |
| 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); |
| 130 | |
| 131 | } |
| 132 | */ |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | |
| 137 | |
| 138 | if ($node['node_system_access']=='crypto') { |
| 139 | $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]); |
| 140 | } |
| 141 | |
| 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)); |
| 148 | } |
| 149 | else { |
| 150 | |
| 151 | $smarty->assign('node',$node); |
| 152 | //new templates by Dark matter |
| 153 | $smarty->template_dir=OWN_TEMPLATE_DIR; |
| 154 | |
| 155 | $smarty->display('1549864.tpl'); |
| 156 | $smarty->display('1549885.tpl'); |
| 157 | $smarty->display('630526.tpl'); |
| 158 | die(); |
| 159 | |
| 160 | //redirect to mainpage |
| 161 | // looks like poeple totaly hate this redirect! |
| 162 | // header("Location: /id/1"); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | // XXX into function |
| 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); |
| 171 | } |
| 172 | |
| 173 | $whole_time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7); |
| 174 | $smarty->assign('whole_time',$whole_time); |
| 175 | |
| 176 | |
| 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); |
| 182 | |
| 183 | $ext = substr( $filename,-3 ); |
| 184 | if( $filename == "" ) { |
| 185 | echo "ERROR: Empty file to download. "; |
| 186 | exit; |
| 187 | } elseif ( ! file_exists( $filename ) ) { |
| 188 | exit; |
| 189 | }; |
| 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"; |
| 201 | } |
| 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;" ); |
| 211 | } else { |
| 212 | header( "Content-Disposition: attachment; |
| 213 | filename=$file;" ); |
| 214 | } |
| 215 | header("Content-Transfer-Encoding: binary"); |
| 216 | header("Content-Length: ".filesize($filename)); |
| 217 | readfile("$filename"); |
| 218 | exit(); |
| 219 | } |
| 220 | else { echo "you don't have permissions for downloading this data"; die(); } |
| 221 | } |
| 222 | |
| 223 | if ($node['template_id']=='2019721'){ |
| 224 | Header("Cache-control: max-age=3600"); |
| 225 | }else{ |
| 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"); |
| 229 | } |
| 230 | |
| 231 | |
| 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']); |
| 236 | |
| 237 | } |
| 238 | |
| 239 | //setting listing parameters |
| 240 | $children_count=$node['node_children_count']; |
| 241 | $descendant_count=$node['node_descendant_count']; |
| 242 | |
| 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); |
| 248 | |
| 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); |
| 254 | |
| 255 | if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) { |
| 256 | $offset=$_POST['get_children_offset']; |
| 257 | } else { $offset=0; } |
| 258 | |
| 259 | |
| 260 | //movement forward and backward |
| 261 | // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount; |
| 262 | |
| 263 | if ($_POST['get_children_move']=='<') { |
| 264 | $offset=$offset-$listing_amount; |
| 265 | if ($offset<0) $offset=0; |
| 266 | } |
| 267 | elseif ($_POST['get_children_move']=='>') { |
| 268 | $offset=$offset+$listing_amount; |
| 269 | } |
| 270 | elseif ($_POST['get_children_move']=='>>') { |
| 271 | $offset=$descendant_count-$listing_amount; |
| 272 | } |
| 273 | |
| 274 | elseif ($_POST['get_children_move']=='<<') { |
| 275 | $offset=0; |
| 276 | } |
| 277 | if ($offset<0) $offset=0; |
| 278 | $_POST['offset']=$offset; |
| 279 | $smarty->assign('offset',$offset); |
| 280 | |
| 281 | |
| 282 | if ($node['external_link']=='header://svg' && !is_numeric($template_id)) { |
| 283 | header("Content-Type: image/svg+xml"); |
| 284 | } |
| 285 | |
| 286 | //show own header |
| 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) { |
| 294 | echo $content; |
| 295 | session_destroy(); |
| 296 | die(); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | $smarty->template_dir=OWN_TEMPLATE_DIR; |
| 301 | |
| 302 | if (is_numeric($template_id)) { |
| 303 | $content.=$smarty->fetch($template_id.".tpl"); |
| 304 | } |
| 305 | |
| 306 | else { |
| 307 | $template_id=$node['template_id']; |
| 308 | $content.=$smarty->fetch($node['template_id'].".tpl"); |
| 309 | } |
| 310 | |
| 311 | if ($template_id=='2019721'){ |
| 312 | $content=$smarty->fetch($template_id.".tpl"); |
| 313 | echo $content; |
| 314 | }else{ |
| 315 | $time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7); |
| 316 | echo $content; |
| 317 | // echo "<center>page generation took: $time second</center>"; |
| 318 | } |
| 319 | //end of displaying |
| 320 | |
| 321 | return false; |
| 322 | } |