2 //echo($_SERVER['PATH_INFO']."\n<pre>"); var_dump(preg_split('/\//', $_SERVER['PATH_INFO'])); die(); //PATH_INFO Debug (usefull when messing with mod_rewrite)
3 // output buffering forcing (mx)
4 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_start();
6 //header("Location: http://web.archive.org/web/20020925021139/http://kyberia.sk");
7 //echo "je to uz uplne v pici. vsetky data su stratene, prajem pekny den :)";
10 //starting timer for benchmarking purposes
11 $timer_start=Time()+
SubStr(MicroTime(),0,8);
13 //setting PHPSESSID cookie and starting user session
17 //$_SESSION['debugging']=1;
21 if ($_SESSION['debugging']) {
23 error_reporting(E_ALL
);
24 echo 'GET VARIABLES::<br/>';
26 echo 'POST VARIABLES::<br/>';
28 echo '<b>SESSION VARIABLES::</b><br/>';
33 //Path info (Experimental - this replaced most of mod_rewrites...)
34 @$PATH_INFO=trim($_SERVER[PATH_INFO
]);
35 if($PATH_INFO != '') {
36 $PATH_CHUNKS = preg_split('/\//', $PATH_INFO);
37 if(isset($PATH_CHUNKS[1])) switch($PATH_CHUNKS[1]) {
39 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_kid'] = $PATH_CHUNKS[2];
40 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_kid'] = $PATH_CHUNKS[3];
43 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_id'] = $PATH_CHUNKS[2];
44 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_id'] = $PATH_CHUNKS[3];
47 if($PATH_CHUNKS[1] != '') $_GET['node_name'] = $PATH_CHUNKS[1];
48 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['template_kid'] = $PATH_CHUNKS[2];
53 (!isset($_GET['node_kid']) ||
trim($_GET['node_kid']) == '') &&
54 (!isset($_GET['node_id']) ||
trim($_GET['node_id']) == '')
55 ) $_GET['node_kid'] = 1;
57 //Base36 http://en.wikipedia.org/wiki/Base_36 (Initial support only :-)
58 if(isset($_GET['node_kid'])) $_GET['node_id'] = base_convert($_GET['node_kid'], 36, 10);
59 if(isset($_GET['template_kid'])) $_GET['template_id'] = base_convert($_GET['template_kid'], 36, 10);
61 //requiring main config file with path/database etc. constants
62 require('config/config.inc');
63 require(INCLUDE_DIR
.'senate.inc');
65 if (isset($_SERVER['HTTP_REFERER'])) {
66 preg_match('/(k|id)\/([0-9]*)\//',$_SERVER['HTTP_REFERER'],$ref_match);
67 $referer_id=$ref_match[1];
70 //connecting to database and creating universal $db object
71 require(INCLUDE_DIR
.'log.inc');
72 require(INCLUDE_DIR
.'ubik.inc');
73 require(INCLUDE_DIR
.'nodes.inc');
74 require(INCLUDE_DIR
.'error_messages.inc');
75 require(INCLUDE_DIR
.'database.inc');
77 $db = new CLASS_DATABASE();
79 if (!empty($_GET['template_id'])) {
80 $template_id=$_GET['template_id'];
85 //initializing node methods
86 if (!empty($_GET['node_name'])) {
87 $node = nodes
::redirByName($_GET['node_name']);
88 } elseif (!empty($_GET['node_id'])) {
89 $node = nodes
::getNodeById($_GET['node_id'],
90 (isset($_SESSION['user_id']))?
$_SESSION['user_id']:'');
93 //XXX Paths are wrong (!)
94 //loading smarty template engine and setting main parameters
95 require(SMARTY_DIR
.'Smarty.class.php');
97 require(INCLUDE_DIR
.'smarty/resource.kyberia.php');
99 //$smarty->php_handling = SMARTY_PHP_REMOVE; //XXX
100 $smarty->template_dir
= TEMPLATE_DIR
;
101 //echo TEMPLATE_DIR.TEMPLATE_SET;
102 //echo $smarty->template_dir;
103 $smarty->compile_dir
= SYSTEM_DATA
.'templates_c/';
104 $smarty->config_dir
= SMARTY_DIR
.'configs/'; //XXX neexistuje
105 $smarty->cache_dir
= SMARTY_DIR
.'cache/';
106 $smarty->plugins_dir
= SMARTY_PLUGIN_DIR
;
107 if ($_SESSION['debugging']) $smarty->debugging
=true;
109 // initializing variables
110 // preg_replace prevents LFI
111 if (empty($_POST['event'])) $event=false;
112 else $event= preg_replace( "![^a-zA-Z0-9_]+!", "", $_POST['event']);
115 if ($_SESSION['debugging']) {
116 echo "<pre><b>NODE::";
121 if ((isset($_SESSION['user_id']) && ($node['node_creator']==$_SESSION['user_id']))) {
122 $node['node_permission']='owner';
125 if (isset($_SESSION['cube_vector']) && ($_SESSION['cube_vector'])) {
126 if (strpos($node['node_vector'],$_SESSION['cube_vector'])===false) {
127 echo "node::".$node['node_vector'];
128 echo "cube_Vector::".$_SESSION['cube_vector'];
129 echo "you are out of allowed cwbe. access forbidden";
134 //if not existent node show our own 404
136 $nodes= nodes
::getNodesByName($_GET['node_name']);
138 $smarty->assign('nodes',$nodes);
139 $content=$smarty->display("404.tpl");
142 elseif ($_SESSION['user_id']) {
143 $smarty->assign('node_name',$_GET['node_name']);
144 $content=$smarty->display("modules/addnode.tpl");
148 //modifying node glass pearl //XXX WTF
149 if (is_array($children_types[$node['node_type']])) {
150 $smarty->assign('children_types',$children_types[$node['node_type']]);
152 $smarty->assign('types',$types);
155 //$node['node_type']=$types[$node['node_type']];
156 $node['node_content']= StripSlashes($node['node_content']);
157 $node['node_name']= StripSlashes($node['node_name']);
159 //checking permissions
160 function _checkPermissions()
162 global $permissions, $node;
164 require(INCLUDE_DIR
.'permissions.inc');
165 $permissions=permissions
::checkPermissions($node);
166 $permissions['h']=permissions
::isHierarch($node);
170 if ($template_id=='rss') //XXX WHAT?
172 $_feedType = "RSS0.91";
173 if (!is_numeric($_SESSION['user_id']))
175 if (!isset($_SERVER['PHP_AUTH_USER'])) {
176 header('WWW-Authenticate: Basic realm="Kyberia"');
177 header('HTTP/1.0 401 Unauthorized');
178 echo 'Cancel button';
183 require_once(EVENT_DIR
.'/login.inc');
184 $_POST['login'] = $_SERVER['PHP_AUTH_USER'];
185 $_POST['password'] = $_SERVER['PHP_AUTH_PW'];
186 $_POST['login_type'] = "name";
189 echo "Zle meno/heslo.";
198 if ($_GET['node_id']==='24' && $permissions['r'])
200 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
202 $rss = new UniversalFeedCreator();
203 $rss->title
= "Kyberia mail";
204 $rss->description
= "";
205 $rss->link
= "https://". SYSTEM_URL
. "/id/24";
208 $query = "select date_format(mail.mail_timestamp,\"%e.%c. %k:%i:%s\") as cas,
209 userfrom.user_action as locationfrom_action,
210 userfrom.user_action_id as locationfrom_action_id,
211 userto.user_action as locationto_action,
212 userto.user_action_id as locationto_action_id,
213 userto.login as mail_to_name, userfrom.login as mail_from_name,
214 mail.* from mail left join users as userfrom on
215 mail_from=userfrom.user_id left join users as userto on mail_to=userto.user_id
216 where mail_user='$_SESSION[user_id]' and mail_to='$_SESSION[user_id]' order by mail_id desc limit 0,10";
218 $set = $db->query($query);
220 while($set->next()) {
221 $m = $set->getRecord();
222 if ($m['mail_to'] != $_SESSION['user_id'])
224 $item = new FeedItem();
225 $item->title
= $m['mail_from_name'];
226 $item->link
= "https://".SYSTEM_URL
."/id/24";
227 $item->description
= $m['mail_text'];
228 $rss->addItem($item);
232 elseif ($_GET['node_id']=='19' && $permissions['r'])
234 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
236 $rss = new UniversalFeedCreator();
237 $rss->title
= "Kyberia bookmarks";
238 $rss->link
= "http://".SYSTEM_URL
."/id/19"; //XXX https ?
240 require_once(SMARTY_PLUGIN_DIR
.'/function.get_bookmarks.php');
241 smarty_function_get_bookmarks(array(), $smarty);
242 $_items = $smarty->get_template_vars('get_bookmarks');
243 foreach ($_items as $_item)
245 if (is_array($_item['children']))
246 foreach ($_item['children'] as $_b)
248 $item = new FeedItem();
249 $item->title
= $_b['node_name'];
250 $item->link
= "http://".SYSTEM_URL
."/id/".$_b['node_id']."/rss";
251 $rss->addItem($item);
256 elseif ($permissions['r'])
258 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
260 $rss = new UniversalFeedCreator();
261 $rss->title
= $node['node_name'];
262 $rss->description
= "";
263 $rss->link
= "http://".SYSTEM_URL
."/id/".$node['node_id'];
266 if ($_GET['node_id']=='15')
268 require_once(SMARTY_PLUGIN_DIR
.'/function.get_k.php');
269 smarty_function_get_k(array(), $smarty);
270 $_items = $smarty->get_template_vars('get_k');
274 require_once(SMARTY_PLUGIN_DIR
.'/function.get_children.php');
275 smarty_function_get_children(
276 array('orderby' => 'desc', 'orderby_type' => 'time'), $smarty);
277 $_items = $smarty->get_template_vars('get_children');
280 foreach ($_items as $_item)
282 $item = new FeedItem();
283 $item->title
= $_item['node_name'];
284 $item->link
= "http://".SYSTEM_URL
."/id/".$_item['node_id'];
285 $item->description
= $_item['node_content'];
286 $rss->addItem($item);
290 if ($permissions['r']) $rss->showFeed($_feedType);
299 if (($permissions['r']) ||
($event != 'register')) {
301 //performing node_events (based on update/insert/delete db queries)
303 require(INCLUDE_DIR
.'eventz.inc');
306 elseif ($transaction) {
307 require(INCLUDE_DIR
.'transaction.inc');
309 //end of performing node events
315 if ($permissions['r']) {
317 // these 4 lines are not the source of kyberia lagging problems.
318 // leave them. started on the 10.4.
319 // data gained will be used for scientific purposes
321 // if (isset($_SESSION['user_id']) {
322 // log_levenshtein($_SESSION['user_id'],$node['node_id']);
325 if ((isset($_SESSION['user_id'])) && ($_SESSION['user_id'])) {
326 $q="insert delayed into levenshtein set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."'";
332 if ($node['template_id']!='2019721'){
334 logger
::log('enter',$node['node_id'],'ok',$node['node_user_subchild_count']);
335 if (!empty($_SESSION['user_id']) && is_numeric($node['node_id'])) {
336 $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']."'";
338 $result=$db->update($q);
341 $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()";
344 }//end of if node os css
350 // if (isset($_SESSION['user_id']) {
351 // if (isset($referer_id)) {
352 // update_nodes($_SESSION['user_id'],$node['node_id'],$referer_id);
354 // update_nodes($_SESSION['user_id'],$node['node_id'],0);
358 // DO NOT MESS WITH THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
359 //creating neural network
360 $db->update("update nodes set node_views=node_views+1 where node_id='".$node['node_id']."'");
361 if (isset($referer_id) && is_numeric($referer_id)) {
362 $q="update neurons set synapse=synapse+1 where dst='".$node['node_id']."' and src='$referer_id'";
363 $result=$db->update($q);
365 $q="insert into neurons set synapse_creator='".$_SESSION['user_id']."',dst='".$node['node_id']."',src='$referer_id',synapse=1";
371 elseif (!$permissions['r'] && $_GET['magic_word']) {
372 $magic_word_big=$_GET['magic_word'];
374 if ( preg_match("/(\d+)-(.+)/",$_GET['magic_word'],$mu)) {
376 $magic_word=addslashes($mu['2']);
377 // XXX WTF column magic_word does not exists
378 $q="select login from users where user_id='$magic_uid' and magic_word='$magic_word'";
380 if ($set->getNumRows()) {
381 $permissions['r']=true;
391 logger
::log('enter',$node['node_id'],'failed');
396 //assigning user data to smarty if user logged in
397 if (isset($_SESSION['user_id'])&&($user_id=$_SESSION['user_id'])) {
398 $smarty->assign('_POST',$_POST);
399 $smarty->assign('bookmarks',$_SESSION['bookmarks']);
400 $smarty->assign('ignore',$_SESSION['ignore']);
401 $smarty->assign('bookstyl',$_SESSION['bookstyl']);
402 $smarty->assign('fook',$_SESSION['fook']);
403 $smarty->assign('user_id',$_SESSION['user_id']);
404 if (!empty($_SESSION['cube_vector']))
405 $smarty->assign('cube_vector',$_SESSION['cube_vector']);
406 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
407 $smarty->assign('user_quota',$_SESSION['user_quota']);
410 $newmail_q = sprintf('select u.user_mail_id
414 , ms.user_id as mail_sender_id
415 , ms.login as mail_sender
417 left join users ms on ms.user_id = u.user_mail_id
418 where u.user_id = %d',
420 $newmailset = $db->query($newmail_q);
424 $new_mail=$newmailset->getString('user_mail');
426 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
427 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
428 $newmailset2->next();
429 $smarty->assign('new_mail',$new_mail);
430 $smarty->assign('new_mail_name',$newmailset->getString('mail_sender'));
431 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
432 $user_k=$newmailset->getString('user_k');
433 $smarty->assign('user_k',$user_k);
434 $k_wallet=$newmailset->getString('k_wallet');
435 $smarty->assign('k_wallet',$k_wallet);
436 $user_id=$_SESSION['user_id'];
439 if ($node['node_name']=='mail') {
441 //clear new mail message
443 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
445 //set messages as delivered to recipient
446 $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'");
447 while($set->next()) {
448 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
449 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
451 $new_messages[$set->getString('mail_id')]=true;
454 if (count($new_messages)) {
455 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
456 $smarty->assign('new_messages',$new_messages);
465 if ($node['node_system_access']=='crypto') {
466 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
469 $smarty->assign('error',$error);
470 $smarty->assign('permissions',$permissions);
471 $smarty->assign('current_vector',$node['node_vector']);
472 if ($permissions['r']) $smarty->assign('node',$node);
475 $smarty->assign('node',$node);
476 //new templates by Dark matter
477 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
479 $smarty->display('1549864.tpl');
480 $smarty->display('1549885.tpl');
481 $smarty->display('630526.tpl');
484 //redirect to mainpage
485 // looks like poeple totaly hate this redirect!
486 // header("Location: /id/1");
491 if (($node['template_id']!='2019721') && (isset($_SESSION['user_id']))){
492 //setting user location
493 $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']."'";
494 $db->executequery($q);
497 $whole_time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
498 $smarty->assign('whole_time',$whole_time);
501 if ($template_id=='download' OR $template_id=='download.jpg') {
502 if ($permissions['r']) {
503 $linkname = SYSTEM_ROOT
."/files/".$node['node_id'];
504 $filename= readlink($linkname);
505 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
507 $ext = substr( $filename,-3 );
508 if( $filename == "" ) {
509 echo "ERROR: Empty file to download. ";
511 } elseif ( ! file_exists( $filename ) ) {
514 switch( strtolower($ext) ){
515 case "pdf": $ctype="application/pdf"; break;
516 case "exe": $ctype="application/octet-stream"; break;
517 case "zip": $ctype="application/zip"; break;
518 case "doc": $ctype="application/msword"; break;
519 case "xls": $ctype="application/vnd.ms-excel"; break;
520 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
521 case "gif": $ctype="image/gif"; break;
522 case "png": $ctype="image/png"; break;
523 case "jpg": $ctype="image/jpg"; break;
524 default: $ctype="application/force-download";
526 $file=str_replace(" ","_",$node['node_name']).".$ext";
527 header("Pragma: public");
528 header("Expires: 0");
529 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
530 header("Content-Type: $ctype");
531 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
532 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
533 (strpos($user_agent, "win")))) {
534 header( "Content-Disposition: filename=$file;" );
536 header( "Content-Disposition: attachment;
539 header("Content-Transfer-Encoding: binary");
540 header("Content-Length: ".filesize($filename));
541 readfile("$filename");
544 else { echo "you don't have permissions for downloading this data"; die(); }
547 if ($node['template_id']=='2019721'){
548 Header("Cache-control: max-age=3600");
550 Header("Cache-control: no-cache");
551 Header("Expires:".gmdate("D, d M Y H:i:s")." GMT");
552 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
556 //for cases like search & preview
557 $smarty->assign('post_vars',$_POST);
558 if (!empty($_POST['template_event'])) {
559 $smarty->assign('template_event',$_POST['template_event']);
563 //setting listing parameters
564 $children_count=$node['node_children_count'];
565 $descendant_count=$node['node_descendant_count'];
567 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
568 $listing_amount=mysql_real_escape_string($_POST['listing_amount']);
569 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
570 else $listing_amount=DEFAULT_LISTING_AMOUNT
;
571 $smarty->assign('listing_amount',$listing_amount);
573 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
574 $listing_order=mysql_real_escape_string($_POST['listing_order']);
575 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
576 else $listing_order=DEFAULT_LISTING_ORDER
;
577 $smarty->assign('listing_order',$listing_order);
579 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
580 $offset=$_POST['get_children_offset'];
581 } else { $offset=0; }
584 //movement forward and backward
585 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
587 if ($_POST['get_children_move']=='<') {
588 $offset=$offset-$listing_amount;
589 if ($offset<0) $offset=0;
591 elseif ($_POST['get_children_move']=='>') {
592 $offset=$offset+
$listing_amount;
594 elseif ($_POST['get_children_move']=='>>') {
595 $offset=$descendant_count-$listing_amount;
598 elseif ($_POST['get_children_move']=='<<') {
601 if ($offset<0) $offset=0;
602 $_POST['offset']=$offset;
603 $smarty->assign('offset',$offset);
606 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
607 header("Content-Type: image/svg+xml");
611 elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
612 $smarty->assign('header_id',$_SESSION['header_id']);
613 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
614 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
615 $smarty->template_dir
= TEMPLATE_DIR
.TEMPLATE_SET
;
616 //not registered user
617 if ($_SESSION['header_id']==2091520) {
624 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
626 if (is_numeric($template_id)) {
627 $content.=$smarty->fetch($template_id.".tpl");
631 $template_id=$node['template_id'];
632 $content.=$smarty->fetch($node['template_id'].".tpl");
635 if ($template_id=='2019721'){
636 $content=$smarty->fetch($template_id.".tpl");
639 $time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
641 // echo "<center>page generation took: $time second</center>";
645 // output buffering forcing (mx)
646 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_end_flush();
This page took 1.026178 seconds and 5 git commands to generate.