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');
98 //$smarty->php_handling = SMARTY_PHP_REMOVE; //XXX
99 $smarty->template_dir
= TEMPLATE_DIR
;
100 //echo TEMPLATE_DIR.TEMPLATE_SET;
101 //echo $smarty->template_dir;
102 $smarty->compile_dir
= SYSTEM_DATA
.'templates_c/';
103 $smarty->config_dir
= SMARTY_DIR
.'configs/'; //XXX neexistuje
104 $smarty->cache_dir
= SMARTY_DIR
.'cache/';
105 $smarty->plugins_dir
= SMARTY_PLUGIN_DIR
;
106 if ($_SESSION['debugging']) $smarty->debugging
=true;
108 // initializing variables
109 // preg_replace prevents LFI
110 if (empty($_POST['event'])) $event=false;
111 else $event= preg_replace( "![^a-zA-Z0-9_]+!", "", $_POST['event']);
114 if ($_SESSION['debugging']) {
115 echo "<pre><b>NODE::";
120 if ((isset($_SESSION['user_id']) && ($node['node_creator']==$_SESSION['user_id']))) {
121 $node['node_permission']='owner';
124 if (isset($_SESSION['cube_vector']) && ($_SESSION['cube_vector'])) {
125 if (strpos($node['node_vector'],$_SESSION['cube_vector'])===false) {
126 echo "node::".$node['node_vector'];
127 echo "cube_Vector::".$_SESSION['cube_vector'];
128 echo "you are out of allowed cwbe. access forbidden";
133 //if not existent node show our own 404
135 $nodes= nodes
::getNodesByName($_GET['node_name']);
137 $smarty->assign('nodes',$nodes);
138 $content=$smarty->display("404.tpl");
141 elseif ($_SESSION['user_id']) {
142 $smarty->assign('node_name',$_GET['node_name']);
143 $content=$smarty->display("modules/addnode.tpl");
147 //modifying node glass pearl //XXX WTF
148 if (is_array($children_types[$node['node_type']])) {
149 $smarty->assign('children_types',$children_types[$node['node_type']]);
151 $smarty->assign('types',$types);
154 //$node['node_type']=$types[$node['node_type']];
155 $node['node_content']= StripSlashes($node['node_content']);
156 $node['node_name']= StripSlashes($node['node_name']);
158 //checking permissions
159 function _checkPermissions()
161 global $permissions, $node;
163 require(INCLUDE_DIR
.'permissions.inc');
164 $permissions=permissions
::checkPermissions($node);
165 $permissions['h']=permissions
::isHierarch($node);
169 if ($template_id=='rss') //XXX WHAT?
171 $_feedType = "RSS0.91";
172 if (!is_numeric($_SESSION['user_id']))
174 if (!isset($_SERVER['PHP_AUTH_USER'])) {
175 header('WWW-Authenticate: Basic realm="Kyberia"');
176 header('HTTP/1.0 401 Unauthorized');
177 echo 'Cancel button';
182 require_once(EVENT_DIR
.'/login.inc');
183 $_POST['login'] = $_SERVER['PHP_AUTH_USER'];
184 $_POST['password'] = $_SERVER['PHP_AUTH_PW'];
185 $_POST['login_type'] = "name";
188 echo "Zle meno/heslo.";
197 if ($_GET['node_id']==='24' && $permissions['r'])
199 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
201 $rss = new UniversalFeedCreator();
202 $rss->title
= "Kyberia mail";
203 $rss->description
= "";
204 $rss->link
= "https://". SYSTEM_URL
. "/id/24";
207 $query = "select date_format(mail.mail_timestamp,\"%e.%c. %k:%i:%s\") as cas,
208 userfrom.user_action as locationfrom_action,
209 userfrom.user_action_id as locationfrom_action_id,
210 userto.user_action as locationto_action,
211 userto.user_action_id as locationto_action_id,
212 userto.login as mail_to_name, userfrom.login as mail_from_name,
213 mail.* from mail left join users as userfrom on
214 mail_from=userfrom.user_id left join users as userto on mail_to=userto.user_id
215 where mail_user='$_SESSION[user_id]' and mail_to='$_SESSION[user_id]' order by mail_id desc limit 0,10";
217 $set = $db->query($query);
219 while($set->next()) {
220 $m = $set->getRecord();
221 if ($m['mail_to'] != $_SESSION['user_id'])
223 $item = new FeedItem();
224 $item->title
= $m['mail_from_name'];
225 $item->link
= "https://".SYSTEM_URL
."/id/24";
226 $item->description
= $m['mail_text'];
227 $rss->addItem($item);
231 elseif ($_GET['node_id']=='19' && $permissions['r'])
233 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
235 $rss = new UniversalFeedCreator();
236 $rss->title
= "Kyberia bookmarks";
237 $rss->link
= "http://".SYSTEM_URL
."/id/19"; //XXX https ?
239 require_once(SMARTY_PLUGIN_DIR
.'/function.get_bookmarks.php');
240 smarty_function_get_bookmarks(array(), $smarty);
241 $_items = $smarty->get_template_vars('get_bookmarks');
242 foreach ($_items as $_item)
244 if (is_array($_item['children']))
245 foreach ($_item['children'] as $_b)
247 $item = new FeedItem();
248 $item->title
= $_b['node_name'];
249 $item->link
= "http://".SYSTEM_URL
."/id/".$_b['node_id']."/rss";
250 $rss->addItem($item);
255 elseif ($permissions['r'])
257 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
259 $rss = new UniversalFeedCreator();
260 $rss->title
= $node['node_name'];
261 $rss->description
= "";
262 $rss->link
= "http://".SYSTEM_URL
."/id/".$node['node_id'];
265 if ($_GET['node_id']=='15')
267 require_once(SMARTY_PLUGIN_DIR
.'/function.get_k.php');
268 smarty_function_get_k(array(), $smarty);
269 $_items = $smarty->get_template_vars('get_k');
273 require_once(SMARTY_PLUGIN_DIR
.'/function.get_children.php');
274 smarty_function_get_children(
275 array('orderby' => 'desc', 'orderby_type' => 'time'), $smarty);
276 $_items = $smarty->get_template_vars('get_children');
279 foreach ($_items as $_item)
281 $item = new FeedItem();
282 $item->title
= $_item['node_name'];
283 $item->link
= "http://".SYSTEM_URL
."/id/".$_item['node_id'];
284 $item->description
= $_item['node_content'];
285 $rss->addItem($item);
289 if ($permissions['r']) $rss->showFeed($_feedType);
298 if (($permissions['r']) ||
($event != 'register')) {
300 //performing node_events (based on update/insert/delete db queries)
302 require(INCLUDE_DIR
.'eventz.inc');
305 elseif ($transaction) {
306 require(INCLUDE_DIR
.'transaction.inc');
308 //end of performing node events
314 if ($permissions['r']) {
316 // these 4 lines are not the source of kyberia lagging problems.
317 // leave them. started on the 10.4.
318 // data gained will be used for scientific purposes
320 // if (isset($_SESSION['user_id']) {
321 // log_levenshtein($_SESSION['user_id'],$node['node_id']);
324 if ((isset($_SESSION['user_id'])) && ($_SESSION['user_id'])) {
325 $q="insert delayed into levenshtein set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."'";
331 if ($node['template_id']!='2019721'){
333 logger
::log('enter',$node['node_id'],'ok',$node['node_user_subchild_count']);
334 if (!empty($_SESSION['user_id']) && is_numeric($node['node_id'])) {
335 $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']."'";
337 $result=$db->update($q);
340 $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()";
343 }//end of if node os css
349 // if (isset($_SESSION['user_id']) {
350 // if (isset($referer_id)) {
351 // update_nodes($_SESSION['user_id'],$node['node_id'],$referer_id);
353 // update_nodes($_SESSION['user_id'],$node['node_id'],0);
357 // DO NOT MESS WITH THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
358 //creating neural network
359 $db->update("update nodes set node_views=node_views+1 where node_id='".$node['node_id']."'");
360 if (isset($referer_id) && is_numeric($referer_id)) {
361 $q="update neurons set synapse=synapse+1 where dst='".$node['node_id']."' and src='$referer_id'";
362 $result=$db->update($q);
364 $q="insert into neurons set synapse_creator='".$_SESSION['user_id']."',dst='".$node['node_id']."',src='$referer_id',synapse=1";
370 elseif (!$permissions['r'] && $_GET['magic_word']) {
371 $magic_word_big=$_GET['magic_word'];
373 if ( preg_match("/(\d+)-(.+)/",$_GET['magic_word'],$mu)) {
375 $magic_word=addslashes($mu['2']);
376 // XXX WTF column magic_word does not exists
377 $q="select login from users where user_id='$magic_uid' and magic_word='$magic_word'";
379 if ($set->getNumRows()) {
380 $permissions['r']=true;
390 logger
::log('enter',$node['node_id'],'failed');
395 //assigning user data to smarty if user logged in
396 if (isset($_SESSION['user_id'])&&($user_id=$_SESSION['user_id'])) {
397 $smarty->assign('_POST',$_POST);
398 $smarty->assign('bookmarks',$_SESSION['bookmarks']);
399 $smarty->assign('ignore',$_SESSION['ignore']);
400 $smarty->assign('bookstyl',$_SESSION['bookstyl']);
401 $smarty->assign('fook',$_SESSION['fook']);
402 $smarty->assign('user_id',$_SESSION['user_id']);
403 if (!empty($_SESSION['cube_vector']))
404 $smarty->assign('cube_vector',$_SESSION['cube_vector']);
405 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
406 $smarty->assign('user_quota',$_SESSION['user_quota']);
409 $newmail_q = sprintf('select u.user_mail_id
413 , ms.user_id as mail_sender_id
414 , ms.login as mail_sender
416 left join users ms on ms.user_id = u.user_mail_id
417 where u.user_id = %d',
419 $newmailset = $db->query($newmail_q);
423 $new_mail=$newmailset->getString('user_mail');
425 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
426 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
427 $newmailset2->next();
428 $smarty->assign('new_mail',$new_mail);
429 $smarty->assign('new_mail_name',$newmailset->getString('mail_sender'));
430 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
431 $user_k=$newmailset->getString('user_k');
432 $smarty->assign('user_k',$user_k);
433 $k_wallet=$newmailset->getString('k_wallet');
434 $smarty->assign('k_wallet',$k_wallet);
435 $user_id=$_SESSION['user_id'];
438 if ($node['node_name']=='mail') {
440 //clear new mail message
442 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
444 //set messages as delivered to recipient
445 $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'");
446 while($set->next()) {
447 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
448 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
450 $new_messages[$set->getString('mail_id')]=true;
453 if (count($new_messages)) {
454 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
455 $smarty->assign('new_messages',$new_messages);
464 if ($node['node_system_access']=='crypto') {
465 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
468 $smarty->assign('error',$error);
469 $smarty->assign('permissions',$permissions);
470 $smarty->assign('current_vector',$node['node_vector']);
471 if ($permissions['r']) $smarty->assign('node',$node);
474 $smarty->assign('node',$node);
475 //new templates by Dark matter
476 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
478 $smarty->display('1549864.tpl');
479 $smarty->display('1549885.tpl');
480 $smarty->display('630526.tpl');
483 //redirect to mainpage
484 // looks like poeple totaly hate this redirect!
485 // header("Location: /id/1");
490 if (($node['template_id']!='2019721') && (isset($_SESSION['user_id']))){
491 //setting user location
492 $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']."'";
493 $db->executequery($q);
496 $whole_time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
497 $smarty->assign('whole_time',$whole_time);
500 if ($template_id=='download' OR $template_id=='download.jpg') {
501 if ($permissions['r']) {
502 $linkname = SYSTEM_ROOT
."/files/".$node['node_id'];
503 $filename= readlink($linkname);
504 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
506 $ext = substr( $filename,-3 );
507 if( $filename == "" ) {
508 echo "ERROR: Empty file to download. ";
510 } elseif ( ! file_exists( $filename ) ) {
513 switch( strtolower($ext) ){
514 case "pdf": $ctype="application/pdf"; break;
515 case "exe": $ctype="application/octet-stream"; break;
516 case "zip": $ctype="application/zip"; break;
517 case "doc": $ctype="application/msword"; break;
518 case "xls": $ctype="application/vnd.ms-excel"; break;
519 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
520 case "gif": $ctype="image/gif"; break;
521 case "png": $ctype="image/png"; break;
522 case "jpg": $ctype="image/jpg"; break;
523 default: $ctype="application/force-download";
525 $file=str_replace(" ","_",$node['node_name']).".$ext";
526 header("Pragma: public");
527 header("Expires: 0");
528 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
529 header("Content-Type: $ctype");
530 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
531 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
532 (strpos($user_agent, "win")))) {
533 header( "Content-Disposition: filename=$file;" );
535 header( "Content-Disposition: attachment;
538 header("Content-Transfer-Encoding: binary");
539 header("Content-Length: ".filesize($filename));
540 readfile("$filename");
543 else { echo "you don't have permissions for downloading this data"; die(); }
546 if ($node['template_id']=='2019721'){
547 Header("Cache-control: max-age=3600");
549 Header("Cache-control: no-cache");
550 Header("Expires:".gmdate("D, d M Y H:i:s")." GMT");
551 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
555 //for cases like search & preview
556 $smarty->assign('post_vars',$_POST);
557 if (!empty($_POST['template_event'])) {
558 $smarty->assign('template_event',$_POST['template_event']);
562 //setting listing parameters
563 $children_count=$node['node_children_count'];
564 $descendant_count=$node['node_descendant_count'];
566 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
567 $listing_amount=mysql_real_escape_string($_POST['listing_amount']);
568 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
569 else $listing_amount=DEFAULT_LISTING_AMOUNT
;
570 $smarty->assign('listing_amount',$listing_amount);
572 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
573 $listing_order=mysql_real_escape_string($_POST['listing_order']);
574 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
575 else $listing_order=DEFAULT_LISTING_ORDER
;
576 $smarty->assign('listing_order',$listing_order);
578 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
579 $offset=$_POST['get_children_offset'];
580 } else { $offset=0; }
583 //movement forward and backward
584 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
586 if ($_POST['get_children_move']=='<') {
587 $offset=$offset-$listing_amount;
588 if ($offset<0) $offset=0;
590 elseif ($_POST['get_children_move']=='>') {
591 $offset=$offset+
$listing_amount;
593 elseif ($_POST['get_children_move']=='>>') {
594 $offset=$descendant_count-$listing_amount;
597 elseif ($_POST['get_children_move']=='<<') {
600 if ($offset<0) $offset=0;
601 $_POST['offset']=$offset;
602 $smarty->assign('offset',$offset);
605 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
606 header("Content-Type: image/svg+xml");
610 elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
611 $smarty->assign('header_id',$_SESSION['header_id']);
612 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
613 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
614 $smarty->template_dir
= TEMPLATE_DIR
.TEMPLATE_SET
;
615 //not registered user
616 if ($_SESSION['header_id']==2091520) {
623 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
625 if (is_numeric($template_id)) {
626 $content.=$smarty->fetch($template_id.".tpl");
630 $template_id=$node['template_id'];
631 $content.=$smarty->fetch($node['template_id'].".tpl");
634 if ($template_id=='2019721'){
635 $content=$smarty->fetch($template_id.".tpl");
638 $time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
640 // echo "<center>page generation took: $time second</center>";
644 // output buffering forcing (mx)
645 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_end_flush();
This page took 0.758921 seconds and 4 git commands to generate.