a3ddbc614b757ef6f539b13ec0af2f892fd4e53a
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);
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 $smarty_resource = 'kyberia:';
33 //$smarty_resource = ''; //same as 'file:' (fallback)
35 //Path info (Experimental - this replaced most of mod_rewrites...)
36 @$PATH_INFO=trim($_SERVER[PATH_INFO
]);
37 if($PATH_INFO != '') {
38 $PATH_CHUNKS = preg_split('/\//', $PATH_INFO);
39 if(isset($PATH_CHUNKS[1])) switch($PATH_CHUNKS[1]) {
41 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_kid'] = $PATH_CHUNKS[2];
42 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_kid'] = $PATH_CHUNKS[3];
45 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_id'] = $PATH_CHUNKS[2];
46 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_id'] = $PATH_CHUNKS[3];
49 if($PATH_CHUNKS[1] != '') $_GET['node_name'] = $PATH_CHUNKS[1];
50 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['template_kid'] = $PATH_CHUNKS[2];
55 (!isset($_GET['node_kid']) ||
trim($_GET['node_kid']) == '') &&
56 (!isset($_GET['node_id']) ||
trim($_GET['node_id']) == '')
57 ) $_GET['node_kid'] = 1;
59 //Base36 http://en.wikipedia.org/wiki/Base_36 (Initial support only :-)
60 if(isset($_GET['node_kid'])) $_GET['node_id'] = base_convert($_GET['node_kid'], 36, 10);
61 if(isset($_GET['template_kid'])) $_GET['template_id'] = base_convert($_GET['template_kid'], 36, 10);
63 //requiring main config file with path/database etc. constants
64 require('config/config.inc');
65 require(INCLUDE_DIR
.'senate.inc');
67 if (isset($_SERVER['HTTP_REFERER'])) {
68 preg_match('/(k|id)\/([0-9]*)\//',$_SERVER['HTTP_REFERER'],$ref_match);
69 $referer_id=$ref_match[1];
72 //connecting to database and creating universal $db object
73 require(INCLUDE_DIR
.'log.inc');
74 require(INCLUDE_DIR
.'ubik.inc');
75 require(INCLUDE_DIR
.'nodes.inc');
76 require(INCLUDE_DIR
.'error_messages.inc');
77 require(INCLUDE_DIR
.'database.inc');
79 $db = new CLASS_DATABASE();
81 if (!empty($_GET['template_id'])) {
82 $template_id=$_GET['template_id'];
87 //initializing node methods
88 if (!empty($_GET['node_name'])) {
89 $node = nodes
::redirByName($_GET['node_name']);
90 } elseif (!empty($_GET['node_id'])) {
91 $node = nodes
::getNodeById($_GET['node_id'],
92 (isset($_SESSION['user_id']))?
$_SESSION['user_id']:'');
95 //XXX Paths are wrong (!)
96 //loading smarty template engine and setting main parameters
97 require(SMARTY_DIR
.'Smarty.class.php');
99 require(INCLUDE_DIR
.'smarty/resource.kyberia.php');
101 //$smarty->php_handling = SMARTY_PHP_REMOVE; //XXX
102 $smarty->template_dir
= TEMPLATE_DIR
;
103 //echo TEMPLATE_DIR.TEMPLATE_SET;
104 //echo $smarty->template_dir;
105 $smarty->compile_dir
= SYSTEM_DATA
.'templates_c/';
106 $smarty->config_dir
= SMARTY_DIR
.'configs/'; //XXX neexistuje
107 $smarty->cache_dir
= SMARTY_DIR
.'cache/';
108 $smarty->plugins_dir
= SMARTY_PLUGIN_DIR
;
109 if ($_SESSION['debugging']) $smarty->debugging
=true;
111 // initializing variables
112 // preg_replace prevents LFI
113 if (empty($_POST['event'])) $event=false;
114 else $event= preg_replace( "![^a-zA-Z0-9_]+!", "", $_POST['event']);
117 if ($_SESSION['debugging']) {
118 echo "<pre><b>NODE::";
123 if ((isset($_SESSION['user_id']) && ($node['node_creator']==$_SESSION['user_id']))) {
124 $node['node_permission']='owner';
127 if (isset($_SESSION['cube_vector']) && ($_SESSION['cube_vector'])) {
128 if (strpos($node['node_vector'],$_SESSION['cube_vector'])===false) {
129 echo "node::".$node['node_vector'];
130 echo "cube_Vector::".$_SESSION['cube_vector'];
131 echo "you are out of allowed cwbe. access forbidden";
136 //if not existent node show our own 404
138 $nodes= nodes
::getNodesByName($_GET['node_name']);
140 $smarty->assign('nodes',$nodes);
141 $content=$smarty->display($smarty_resource.'404.tpl');
144 elseif ($_SESSION['user_id']) {
145 $smarty->assign('node_name',$_GET['node_name']);
146 $content=$smarty->display("modules/addnode.tpl");
150 //modifying node glass pearl //XXX WTF
151 if (is_array($children_types[$node['node_type']])) {
152 $smarty->assign('children_types',$children_types[$node['node_type']]);
154 $smarty->assign('types',$types);
157 //$node['node_type']=$types[$node['node_type']];
158 $node['node_content']= StripSlashes($node['node_content']);
159 $node['node_name']= StripSlashes($node['node_name']);
161 //checking permissions
162 function _checkPermissions()
164 global $permissions, $node;
166 require(INCLUDE_DIR
.'permissions.inc');
167 $permissions=permissions
::checkPermissions($node);
168 $permissions['h']=permissions
::isHierarch($node);
172 if ($template_id=='rss') //XXX WHAT?
174 $_feedType = "RSS0.91";
175 if (!is_numeric($_SESSION['user_id']))
177 if (!isset($_SERVER['PHP_AUTH_USER'])) {
178 header('WWW-Authenticate: Basic realm="Kyberia"');
179 header('HTTP/1.0 401 Unauthorized');
180 echo 'Cancel button';
185 require_once(EVENT_DIR
.'/login.inc');
186 $_POST['login'] = $_SERVER['PHP_AUTH_USER'];
187 $_POST['password'] = $_SERVER['PHP_AUTH_PW'];
188 $_POST['login_type'] = "name";
191 echo "Zle meno/heslo.";
200 if ($_GET['node_id']==='24' && $permissions['r'])
202 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
204 $rss = new UniversalFeedCreator();
205 $rss->title
= "Kyberia mail";
206 $rss->description
= "";
207 $rss->link
= "https://". SYSTEM_URL
. "/id/24";
210 $query = "select date_format(mail.mail_timestamp,\"%e.%c. %k:%i:%s\") as cas,
211 userfrom.user_action as locationfrom_action,
212 userfrom.user_action_id as locationfrom_action_id,
213 userto.user_action as locationto_action,
214 userto.user_action_id as locationto_action_id,
215 userto.login as mail_to_name, userfrom.login as mail_from_name,
216 mail.* from mail left join users as userfrom on
217 mail_from=userfrom.user_id left join users as userto on mail_to=userto.user_id
218 where mail_user='$_SESSION[user_id]' and mail_to='$_SESSION[user_id]' order by mail_id desc limit 0,10";
220 $set = $db->query($query);
222 while($set->next()) {
223 $m = $set->getRecord();
224 if ($m['mail_to'] != $_SESSION['user_id'])
226 $item = new FeedItem();
227 $item->title
= $m['mail_from_name'];
228 $item->link
= "https://".SYSTEM_URL
."/id/24";
229 $item->description
= $m['mail_text'];
230 $rss->addItem($item);
234 elseif ($_GET['node_id']=='19' && $permissions['r'])
236 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
238 $rss = new UniversalFeedCreator();
239 $rss->title
= "Kyberia bookmarks";
240 $rss->link
= "http://".SYSTEM_URL
."/id/19"; //XXX https ?
242 require_once(SMARTY_PLUGIN_DIR
.'/function.get_bookmarks.php');
243 smarty_function_get_bookmarks(array(), $smarty);
244 $_items = $smarty->get_template_vars('get_bookmarks');
245 foreach ($_items as $_item)
247 if (is_array($_item['children']))
248 foreach ($_item['children'] as $_b)
250 $item = new FeedItem();
251 $item->title
= $_b['node_name'];
252 $item->link
= "http://".SYSTEM_URL
."/id/".$_b['node_id']."/rss";
253 $rss->addItem($item);
258 elseif ($permissions['r'])
260 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
262 $rss = new UniversalFeedCreator();
263 $rss->title
= $node['node_name'];
264 $rss->description
= "";
265 $rss->link
= "http://".SYSTEM_URL
."/id/".$node['node_id'];
268 if ($_GET['node_id']=='15')
270 require_once(SMARTY_PLUGIN_DIR
.'/function.get_k.php');
271 smarty_function_get_k(array(), $smarty);
272 $_items = $smarty->get_template_vars('get_k');
276 require_once(SMARTY_PLUGIN_DIR
.'/function.get_children.php');
277 smarty_function_get_children(
278 array('orderby' => 'desc', 'orderby_type' => 'time'), $smarty);
279 $_items = $smarty->get_template_vars('get_children');
282 foreach ($_items as $_item)
284 $item = new FeedItem();
285 $item->title
= $_item['node_name'];
286 $item->link
= "http://".SYSTEM_URL
."/id/".$_item['node_id'];
287 $item->description
= $_item['node_content'];
288 $rss->addItem($item);
292 if ($permissions['r']) $rss->showFeed($_feedType);
301 if (($permissions['r']) ||
($event != 'register')) {
303 //performing node_events (based on update/insert/delete db queries)
305 require(INCLUDE_DIR
.'eventz.inc');
308 elseif ($transaction) {
309 require(INCLUDE_DIR
.'transaction.inc');
311 //end of performing node events
317 if ($permissions['r']) {
319 // these 4 lines are not the source of kyberia lagging problems.
320 // leave them. started on the 10.4.
321 // data gained will be used for scientific purposes
323 // if (isset($_SESSION['user_id']) {
324 // log_levenshtein($_SESSION['user_id'],$node['node_id']);
327 if ((isset($_SESSION['user_id'])) && ($_SESSION['user_id'])) {
328 $q="insert delayed into levenshtein set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."'";
334 if ($node['template_id']!='2019721'){
336 logger
::log('enter',$node['node_id'],'ok',$node['node_user_subchild_count']);
337 if (!empty($_SESSION['user_id']) && is_numeric($node['node_id'])) {
338 $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']."'";
340 $result=$db->update($q);
343 $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()";
346 }//end of if node os css
352 // if (isset($_SESSION['user_id']) {
353 // if (isset($referer_id)) {
354 // update_nodes($_SESSION['user_id'],$node['node_id'],$referer_id);
356 // update_nodes($_SESSION['user_id'],$node['node_id'],0);
360 // DO NOT MESS WITH THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
361 //creating neural network
362 $db->update("update nodes set node_views=node_views+1 where node_id='".$node['node_id']."'");
363 if (isset($referer_id) && is_numeric($referer_id)) {
364 $q="update neurons set synapse=synapse+1 where dst='".$node['node_id']."' and src='$referer_id'";
365 $result=$db->update($q);
367 $q="insert into neurons set synapse_creator='".$_SESSION['user_id']."',dst='".$node['node_id']."',src='$referer_id',synapse=1";
373 elseif (!$permissions['r'] && $_GET['magic_word']) {
374 $magic_word_big=$_GET['magic_word'];
376 if ( preg_match("/(\d+)-(.+)/",$_GET['magic_word'],$mu)) {
378 $magic_word=addslashes($mu['2']);
379 // XXX WTF column magic_word does not exists
380 $q="select login from users where user_id='$magic_uid' and magic_word='$magic_word'";
382 if ($set->getNumRows()) {
383 $permissions['r']=true;
393 logger
::log('enter',$node['node_id'],'failed');
398 //assigning user data to smarty if user logged in
399 if (isset($_SESSION['user_id'])&&($user_id=$_SESSION['user_id'])) {
400 $smarty->assign('_POST',$_POST);
401 $smarty->assign('bookmarks',$_SESSION['bookmarks']);
402 $smarty->assign('ignore',$_SESSION['ignore']);
403 $smarty->assign('bookstyl',$_SESSION['bookstyl']);
404 $smarty->assign('fook',$_SESSION['fook']);
405 $smarty->assign('user_id',$_SESSION['user_id']);
406 if (!empty($_SESSION['cube_vector']))
407 $smarty->assign('cube_vector',$_SESSION['cube_vector']);
408 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
409 $smarty->assign('user_quota',$_SESSION['user_quota']);
412 $newmail_q = sprintf('select u.user_mail_id
416 , ms.user_id as mail_sender_id
417 , ms.login as mail_sender
419 left join users ms on ms.user_id = u.user_mail_id
420 where u.user_id = %d',
422 $newmailset = $db->query($newmail_q);
426 $new_mail=$newmailset->getString('user_mail');
428 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
429 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
430 $newmailset2->next();
431 $smarty->assign('new_mail',$new_mail);
432 $smarty->assign('new_mail_name',$newmailset->getString('mail_sender'));
433 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
434 $user_k=$newmailset->getString('user_k');
435 $smarty->assign('user_k',$user_k);
436 $k_wallet=$newmailset->getString('k_wallet');
437 $smarty->assign('k_wallet',$k_wallet);
438 $user_id=$_SESSION['user_id'];
441 if ($node['node_name']=='mail') {
443 //clear new mail message
445 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
447 //set messages as delivered to recipient
448 $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'");
449 while($set->next()) {
450 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
451 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
453 $new_messages[$set->getString('mail_id')]=true;
456 if (count($new_messages)) {
457 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
458 $smarty->assign('new_messages',$new_messages);
467 if ($node['node_system_access']=='crypto') {
468 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
471 $smarty->assign('error',$error);
472 $smarty->assign('permissions',$permissions);
473 $smarty->assign('current_vector',$node['node_vector']);
474 if ($permissions['r']) $smarty->assign('node',$node);
477 $smarty->assign('node',$node);
478 //new templates by Dark matter
479 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
481 $smarty->display($smarty_resource.'1549864.tpl');
482 $smarty->display($smarty_resource.'1549885.tpl');
483 $smarty->display($smarty_resource.'630526.tpl');
486 //redirect to mainpage
487 // looks like poeple totaly hate this redirect!
488 // header("Location: /id/1");
493 if (($node['template_id']!='2019721') && (isset($_SESSION['user_id']))){
494 //setting user location
495 $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']."'";
496 $db->executequery($q);
499 $whole_time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
500 $smarty->assign('whole_time',$whole_time);
503 if ($template_id=='download' OR $template_id=='download.jpg') {
504 if ($permissions['r']) {
505 $linkname = SYSTEM_ROOT
."/files/".$node['node_id'];
506 $filename= readlink($linkname);
507 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
509 $ext = substr( $filename,-3 );
510 if( $filename == "" ) {
511 echo "ERROR: Empty file to download. ";
513 } elseif ( ! file_exists( $filename ) ) {
516 switch( strtolower($ext) ){
517 case "pdf": $ctype="application/pdf"; break;
518 case "exe": $ctype="application/octet-stream"; break;
519 case "zip": $ctype="application/zip"; break;
520 case "doc": $ctype="application/msword"; break;
521 case "xls": $ctype="application/vnd.ms-excel"; break;
522 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
523 case "gif": $ctype="image/gif"; break;
524 case "png": $ctype="image/png"; break;
525 case "jpg": $ctype="image/jpg"; break;
526 default: $ctype="application/force-download";
528 $file=str_replace(" ","_",$node['node_name']).".$ext";
529 header("Pragma: public");
530 header("Expires: 0");
531 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
532 header("Content-Type: $ctype");
533 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
534 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
535 (strpos($user_agent, "win")))) {
536 header( "Content-Disposition: filename=$file;" );
538 header( "Content-Disposition: attachment;
541 header("Content-Transfer-Encoding: binary");
542 header("Content-Length: ".filesize($filename));
543 readfile("$filename");
546 else { echo "you don't have permissions for downloading this data"; die(); }
549 if ($node['template_id']=='2019721'){
550 Header("Cache-control: max-age=3600");
552 Header("Cache-control: no-cache");
553 Header("Expires:".gmdate("D, d M Y H:i:s")." GMT");
554 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
558 //for cases like search & preview
559 $smarty->assign('post_vars',$_POST);
560 if (!empty($_POST['template_event'])) {
561 $smarty->assign('template_event',$_POST['template_event']);
565 //setting listing parameters
566 $children_count=$node['node_children_count'];
567 $descendant_count=$node['node_descendant_count'];
569 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
570 $listing_amount=mysql_real_escape_string($_POST['listing_amount']);
571 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
572 else $listing_amount=DEFAULT_LISTING_AMOUNT
;
573 $smarty->assign('listing_amount',$listing_amount);
575 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
576 $listing_order=mysql_real_escape_string($_POST['listing_order']);
577 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
578 else $listing_order=DEFAULT_LISTING_ORDER
;
579 $smarty->assign('listing_order',$listing_order);
581 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
582 $offset=$_POST['get_children_offset'];
583 } else { $offset=0; }
586 //movement forward and backward
587 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
589 if ($_POST['get_children_move']=='<') {
590 $offset=$offset-$listing_amount;
591 if ($offset<0) $offset=0;
593 elseif ($_POST['get_children_move']=='>') {
594 $offset=$offset+
$listing_amount;
596 elseif ($_POST['get_children_move']=='>>') {
597 $offset=$descendant_count-$listing_amount;
600 elseif ($_POST['get_children_move']=='<<') {
603 if ($offset<0) $offset=0;
604 $_POST['offset']=$offset;
605 $smarty->assign('offset',$offset);
608 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
609 header("Content-Type: image/svg+xml");
613 elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
614 $smarty->assign('header_id',$_SESSION['header_id']);
615 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
616 $content=$smarty->fetch($smarty_resource.$_SESSION['header_id'].".tpl");
617 $smarty->template_dir
= TEMPLATE_DIR
.TEMPLATE_SET
;
618 //not registered user
619 if ($_SESSION['header_id']==2091520) {
626 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
628 if (is_numeric($template_id)) {
629 $content.=$smarty->fetch($smarty_resource.$template_id.".tpl");
633 $template_id=$node['template_id'];
634 $content.=$smarty->fetch($smarty_resource.$node['template_id'].".tpl");
637 if ($template_id=='2019721'){
638 $content=$smarty->fetch($smarty_resource.$template_id.".tpl");
641 $time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
643 // echo "<center>page generation took: $time second</center>";
647 // output buffering forcing (mx)
648 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_end_flush();
This page took 0.784823 seconds and 3 git commands to generate.