2 // output buffering forcing (mx)
3 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_start();
5 //header("Location: http://web.archive.org/web/20020925021139/http://kyberia.sk");
6 //echo "je to uz uplne v pici. vsetky data su stratene, prajem pekny den :)";
9 //starting timer for benchmarking purposes
10 $timer_start=Time()+
SubStr(MicroTime(),0,8);
12 //setting PHPSESSID cookie and starting user session
16 //$_SESSION['debugging']=1;
20 if ($_SESSION['debugging']) {
22 error_reporting(E_ALL
);
23 echo "GET VARIABLES::<br/>";
25 echo "POST VARIABLES::<br/>";
27 echo "<b>SESSION VARIABLES::</b><br/>";
32 //Path info (Experimental - thish should replace most of mod_rewrites in future...)
33 @$PATH_INFO=trim($_SERVER[PATH_INFO
]);
34 if($PATH_INFO != '') {
35 $PATH_CHUNKS = preg_split("/\//", $PATH_INFO);
36 if(isset($PATH_CHUNKS[1])) switch($PATH_CHUNKS[1]) {
38 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_kid'] = $PATH_CHUNKS[2];
39 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_kid'] = $PATH_CHUNKS[3];
42 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_id'] = $PATH_CHUNKS[2];
43 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_id'] = $PATH_CHUNKS[3];
46 if($PATH_CHUNKS[1] != '') $_GET['node_name'] = $PATH_CHUNKS[1];
47 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['template_kid'] = $PATH_CHUNKS[2];
52 //Base36 http://en.wikipedia.org/wiki/Base_36 (Initial support only :-)
53 if(isset($_GET['node_kid'])) $_GET['node_id'] = base_convert($_GET['node_kid'], 36, 10);
54 if(isset($_GET['template_kid'])) $_GET['template_id'] = base_convert($_GET['template_kid'], 36, 10);
56 //requiring main config file with path/database etc. constants
57 require('config/config.inc');
58 require(INCLUDE_DIR
.'senate.inc');
60 if (isset($_SERVER['HTTP_REFERER'])) {
61 preg_match("/id\/([0-9]*)\//",$_SERVER['HTTP_REFERER'],$ref_match);
62 $referer_id=$ref_match[1];
65 //connecting to database and creating universal $db object
66 require(INCLUDE_DIR
.'log.inc');
67 require(INCLUDE_DIR
.'ubik.inc');
68 require(INCLUDE_DIR
.'nodes.inc');
69 require(INCLUDE_DIR
.'error_messages.inc');
70 require(INCLUDE_DIR
.'database.inc');
72 $db = new CLASS_DATABASE();
74 if (!empty($_GET['template_id'])) {
75 $template_id=$_GET['template_id'];
80 //initializing node methods
81 if (!empty($_GET['node_name'])) {
82 $node = nodes
::redirByName($_GET['node_name']);
83 } elseif (!empty($_GET['node_id'])) {
84 $node = nodes
::getNodeById($_GET['node_id'],
85 (isset($_SESSION['user_id']))?
$_SESSION['user_id']:'');
88 //XXX Paths are wrong (!)
89 //loading smarty template engine and setting main parameters
90 require(SMARTY_DIR
.'Smarty.class.php');
93 //$smarty->php_handling = SMARTY_PHP_REMOVE; //XXX
94 $smarty->template_dir
= TEMPLATE_DIR
;
95 //echo TEMPLATE_DIR.TEMPLATE_SET;
96 //echo $smarty->template_dir;
97 $smarty->compile_dir
= SYSTEM_DATA
."templates_c/";
98 $smarty->config_dir
= SMARTY_DIR
.'configs/'; //XXX neexistuje
99 $smarty->cache_dir
= SMARTY_DIR
.'cache/';
100 $smarty->plugins_dir
= SMARTY_PLUGIN_DIR
;
101 if ($_SESSION['debugging']) $smarty->debugging
=true;
103 // initializing variables
104 // preg_replace prevents LFI
105 if (empty($_POST['event'])) $event=false;
106 else $event= preg_replace( "![^a-zA-Z0-9_]+!", "", $_POST['event']);
109 if ($_SESSION['debugging']) {
110 echo "<pre><b>NODE::";
115 if ((isset($_SESSION['user_id']) && ($node['node_creator']==$_SESSION['user_id']))) {
116 $node['node_permission']='owner';
119 if (isset($_SESSION['cube_vector']) && ($_SESSION['cube_vector'])) {
120 if (strpos($node['node_vector'],$_SESSION['cube_vector'])===false) {
121 echo "node::".$node['node_vector'];
122 echo "cube_Vector::".$_SESSION['cube_vector'];
123 echo "you are out of allowed cwbe. access forbidden";
128 //if not existent node show our own 404
130 $nodes= nodes
::getNodesByName($_GET['node_name']);
132 $smarty->assign('nodes',$nodes);
133 $content=$smarty->display("404.tpl");
136 elseif ($_SESSION['user_id']) {
137 $smarty->assign('node_name',$_GET['node_name']);
138 $content=$smarty->display("modules/addnode.tpl");
142 //modifying node glass pearl //XXX WTF
143 if (is_array($children_types[$node['node_type']])) {
144 $smarty->assign('children_types',$children_types[$node['node_type']]);
146 $smarty->assign('types',$types);
149 //$node['node_type']=$types[$node['node_type']];
150 $node['node_content']= StripSlashes($node['node_content']);
151 $node['node_name']= StripSlashes($node['node_name']);
153 //checking permissions
154 function _checkPermissions()
156 global $permissions, $node;
158 require(INCLUDE_DIR
.'permissions.inc');
159 $permissions=permissions
::checkPermissions($node);
160 $permissions['h']=permissions
::isHierarch($node);
164 if ($template_id=='rss') //XXX WHAT?
166 $_feedType = "RSS0.91";
167 if (!is_numeric($_SESSION['user_id']))
169 if (!isset($_SERVER['PHP_AUTH_USER'])) {
170 header('WWW-Authenticate: Basic realm="Kyberia"');
171 header('HTTP/1.0 401 Unauthorized');
172 echo 'Cancel button';
177 require_once(EVENT_DIR
.'/login.inc');
178 $_POST['login'] = $_SERVER['PHP_AUTH_USER'];
179 $_POST['password'] = $_SERVER['PHP_AUTH_PW'];
180 $_POST['login_type'] = "name";
183 echo "Zle meno/heslo.";
192 if ($_GET['node_id']==='24' && $permissions['r'])
194 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
196 $rss = new UniversalFeedCreator();
197 $rss->title
= "Kyberia mail";
198 $rss->description
= "";
199 $rss->link
= "https://". SYSTEM_URL
. "/id/24";
202 $query = "select date_format(mail.mail_timestamp,\"%e.%c. %k:%i:%s\") as cas,
203 userfrom.user_action as locationfrom_action,
204 userfrom.user_action_id as locationfrom_action_id,
205 userto.user_action as locationto_action,
206 userto.user_action_id as locationto_action_id,
207 userto.login as mail_to_name, userfrom.login as mail_from_name,
208 mail.* from mail left join users as userfrom on
209 mail_from=userfrom.user_id left join users as userto on mail_to=userto.user_id
210 where mail_user='$_SESSION[user_id]' and mail_to='$_SESSION[user_id]' order by mail_id desc limit 0,10";
212 $set = $db->query($query);
214 while($set->next()) {
215 $m = $set->getRecord();
216 if ($m['mail_to'] != $_SESSION['user_id'])
218 $item = new FeedItem();
219 $item->title
= $m['mail_from_name'];
220 $item->link
= "https://".SYSTEM_URL
."/id/24";
221 $item->description
= $m['mail_text'];
222 $rss->addItem($item);
226 elseif ($_GET['node_id']=='19' && $permissions['r'])
228 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
230 $rss = new UniversalFeedCreator();
231 $rss->title
= "Kyberia bookmarks";
232 $rss->link
= "http://".SYSTEM_URL
."/id/19"; //XXX https ?
234 require_once(SMARTY_PLUGIN_DIR
.'/function.get_bookmarks.php');
235 smarty_function_get_bookmarks(array(), $smarty);
236 $_items = $smarty->get_template_vars('get_bookmarks');
237 foreach ($_items as $_item)
239 if (is_array($_item['children']))
240 foreach ($_item['children'] as $_b)
242 $item = new FeedItem();
243 $item->title
= $_b['node_name'];
244 $item->link
= "http://".SYSTEM_URL
."/id/".$_b['node_id']."/rss";
245 $rss->addItem($item);
250 elseif ($permissions['r'])
252 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
254 $rss = new UniversalFeedCreator();
255 $rss->title
= $node['node_name'];
256 $rss->description
= "";
257 $rss->link
= "http://".SYSTEM_URL
."/id/".$node['node_id'];
260 if ($_GET['node_id']=='15')
262 require_once(SMARTY_PLUGIN_DIR
.'/function.get_k.php');
263 smarty_function_get_k(array(), $smarty);
264 $_items = $smarty->get_template_vars('get_k');
268 require_once(SMARTY_PLUGIN_DIR
.'/function.get_children.php');
269 smarty_function_get_children(
270 array('orderby' => 'desc', 'orderby_type' => 'time'), $smarty);
271 $_items = $smarty->get_template_vars('get_children');
274 foreach ($_items as $_item)
276 $item = new FeedItem();
277 $item->title
= $_item['node_name'];
278 $item->link
= "http://".SYSTEM_URL
."/id/".$_item['node_id'];
279 $item->description
= $_item['node_content'];
280 $rss->addItem($item);
284 if ($permissions['r']) $rss->showFeed($_feedType);
293 if (($permissions['r']) ||
($event != 'register')) {
295 //performing node_events (based on update/insert/delete db queries)
297 require(INCLUDE_DIR
.'eventz.inc');
300 elseif ($transaction) {
301 require(INCLUDE_DIR
.'transaction.inc');
303 //end of performing node events
309 if ($permissions['r']) {
311 // these 4 lines are not the source of kyberia lagging problems.
312 // leave them. started on the 10.4.
313 // data gained will be used for scientific purposes
315 // if (isset($_SESSION['user_id']) {
316 // log_levenshtein($_SESSION['user_id'],$node['node_id']);
319 if ((isset($_SESSION['user_id'])) && ($_SESSION['user_id'])) {
320 $q="insert delayed into levenshtein set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."'";
326 if ($node['template_id']!='2019721'){
328 logger
::log('enter',$node['node_id'],'ok',$node['node_user_subchild_count']);
329 if (!empty($_SESSION['user_id']) && is_numeric($node['node_id'])) {
330 $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']."'";
332 $result=$db->update($q);
335 $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()";
338 }//end of if node os css
344 // if (isset($_SESSION['user_id']) {
345 // if (isset($referer_id)) {
346 // update_nodes($_SESSION['user_id'],$node['node_id'],$referer_id);
348 // update_nodes($_SESSION['user_id'],$node['node_id'],0);
352 // DO NOT MESS WITH THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
353 //creating neural network
354 $db->update("update nodes set node_views=node_views+1 where node_id='".$node['node_id']."'");
355 if (isset($referer_id) && is_numeric($referer_id)) {
356 $q="update neurons set synapse=synapse+1 where dst='".$node['node_id']."' and src='$referer_id'";
357 $result=$db->update($q);
359 $q="insert into neurons set synapse_creator='".$_SESSION['user_id']."',dst='".$node['node_id']."',src='$referer_id',synapse=1";
365 elseif (!$permissions['r'] && $_GET['magic_word']) {
366 $magic_word_big=$_GET['magic_word'];
368 if ( preg_match("/(\d+)-(.+)/",$_GET['magic_word'],$mu)) {
370 $magic_word=addslashes($mu['2']);
371 // XXX WTF column magic_word does not exists
372 $q="select login from users where user_id='$magic_uid' and magic_word='$magic_word'";
374 if ($set->getNumRows()) {
375 $permissions['r']=true;
385 logger
::log('enter',$node['node_id'],'failed');
390 //assigning user data to smarty if user logged in
391 if (isset($_SESSION['user_id'])&&($user_id=$_SESSION['user_id'])) {
392 $smarty->assign('_POST',$_POST);
393 $smarty->assign('bookmarks',$_SESSION['bookmarks']);
394 $smarty->assign('ignore',$_SESSION['ignore']);
395 $smarty->assign('bookstyl',$_SESSION['bookstyl']);
396 $smarty->assign('fook',$_SESSION['fook']);
397 $smarty->assign('user_id',$_SESSION['user_id']);
398 if (!empty($_SESSION['cube_vector']))
399 $smarty->assign('cube_vector',$_SESSION['cube_vector']);
400 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
401 $smarty->assign('user_quota',$_SESSION['user_quota']);
404 $newmail_q = sprintf('select u.user_mail_id
408 , ms.user_id as mail_sender_id
409 , ms.login as mail_sender
411 left join users ms on ms.user_id = u.user_mail_id
412 where u.user_id = %d',
414 $newmailset = $db->query($newmail_q);
418 $new_mail=$newmailset->getString('user_mail');
420 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
421 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
422 $newmailset2->next();
423 $smarty->assign('new_mail',$new_mail);
424 $smarty->assign('new_mail_name',$newmailset->getString('mail_sender'));
425 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
426 $user_k=$newmailset->getString('user_k');
427 $smarty->assign('user_k',$user_k);
428 $k_wallet=$newmailset->getString('k_wallet');
429 $smarty->assign('k_wallet',$k_wallet);
430 $user_id=$_SESSION['user_id'];
433 if ($node['node_name']=='mail') {
435 //clear new mail message
437 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
439 //set messages as delivered to recipient
440 $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'");
441 while($set->next()) {
442 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
443 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
445 $new_messages[$set->getString('mail_id')]=true;
448 if (count($new_messages)) {
449 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
450 $smarty->assign('new_messages',$new_messages);
459 if ($node['node_system_access']=='crypto') {
460 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
463 $smarty->assign('error',$error);
464 $smarty->assign('permissions',$permissions);
465 $smarty->assign('current_vector',$node['node_vector']);
466 if ($permissions['r']) $smarty->assign('node',$node);
469 $smarty->assign('node',$node);
470 //new templates by Dark matter
471 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
473 $smarty->display('1549864.tpl');
474 $smarty->display('1549885.tpl');
475 $smarty->display('630526.tpl');
478 //redirect to mainpage
479 // looks like poeple totaly hate this redirect!
480 // header("Location: /id/1");
485 if (($node['template_id']!='2019721') && (isset($_SESSION['user_id']))){
486 //setting user location
487 $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']."'";
488 $db->executequery($q);
491 $whole_time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
492 $smarty->assign('whole_time',$whole_time);
495 if ($template_id=='download' OR $template_id=='download.jpg') {
496 if ($permissions['r']) {
497 $linkname = SYSTEM_ROOT
."/files/".$node['node_id'];
498 $filename= readlink($linkname);
499 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
501 $ext = substr( $filename,-3 );
502 if( $filename == "" ) {
503 echo "ERROR: Empty file to download. ";
505 } elseif ( ! file_exists( $filename ) ) {
508 switch( strtolower($ext) ){
509 case "pdf": $ctype="application/pdf"; break;
510 case "exe": $ctype="application/octet-stream"; break;
511 case "zip": $ctype="application/zip"; break;
512 case "doc": $ctype="application/msword"; break;
513 case "xls": $ctype="application/vnd.ms-excel"; break;
514 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
515 case "gif": $ctype="image/gif"; break;
516 case "png": $ctype="image/png"; break;
517 case "jpg": $ctype="image/jpg"; break;
518 default: $ctype="application/force-download";
520 $file=str_replace(" ","_",$node['node_name']).".$ext";
521 header("Pragma: public");
522 header("Expires: 0");
523 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
524 header("Content-Type: $ctype");
525 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
526 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
527 (strpos($user_agent, "win")))) {
528 header( "Content-Disposition: filename=$file;" );
530 header( "Content-Disposition: attachment;
533 header("Content-Transfer-Encoding: binary");
534 header("Content-Length: ".filesize($filename));
535 readfile("$filename");
538 else { echo "you don't have permissions for downloading this data"; die(); }
541 if ($node['template_id']=='2019721'){
542 Header("Cache-control: max-age=3600");
544 Header("Cache-control: no-cache");
545 Header("Expires:".gmdate("D, d M Y H:i:s")." GMT");
546 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
550 //for cases like search & preview
551 $smarty->assign('post_vars',$_POST);
552 if (!empty($_POST['template_event'])) {
553 $smarty->assign('template_event',$_POST['template_event']);
557 //setting listing parameters
558 $children_count=$node['node_children_count'];
559 $descendant_count=$node['node_descendant_count'];
561 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
562 $listing_amount=mysql_real_escape_string($_POST['listing_amount']);
563 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
564 else $listing_amount=DEFAULT_LISTING_AMOUNT
;
565 $smarty->assign('listing_amount',$listing_amount);
567 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
568 $listing_order=mysql_real_escape_string($_POST['listing_order']);
569 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
570 else $listing_order=DEFAULT_LISTING_ORDER
;
571 $smarty->assign('listing_order',$listing_order);
573 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
574 $offset=$_POST['get_children_offset'];
575 } else { $offset=0; }
578 //movement forward and backward
579 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
581 if ($_POST['get_children_move']=='<') {
582 $offset=$offset-$listing_amount;
583 if ($offset<0) $offset=0;
585 elseif ($_POST['get_children_move']=='>') {
586 $offset=$offset+
$listing_amount;
588 elseif ($_POST['get_children_move']=='>>') {
589 $offset=$descendant_count-$listing_amount;
592 elseif ($_POST['get_children_move']=='<<') {
595 if ($offset<0) $offset=0;
596 $_POST['offset']=$offset;
597 $smarty->assign('offset',$offset);
600 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
601 header("Content-Type: image/svg+xml");
605 elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
606 $smarty->assign('header_id',$_SESSION['header_id']);
607 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
608 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
609 $smarty->template_dir
= TEMPLATE_DIR
.TEMPLATE_SET
;
610 //not registered user
611 if ($_SESSION['header_id']==2091520) {
618 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
620 if (is_numeric($template_id)) {
621 $content.=$smarty->fetch($template_id.".tpl");
625 $template_id=$node['template_id'];
626 $content.=$smarty->fetch($node['template_id'].".tpl");
629 if ($template_id=='2019721'){
630 $content=$smarty->fetch($template_id.".tpl");
633 $time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
635 // echo "<center>page generation took: $time second</center>";
639 // output buffering forcing (mx)
640 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_end_flush();
This page took 0.780328 seconds and 5 git commands to generate.