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/>";
31 //Base36 http://en.wikipedia.org/wiki/Base_36 (Initial support only :-)
32 if(isset($_GET['node_kid'])) $_GET['node_id'] = base_convert($_GET['node_kid'], 36, 10);
33 if(isset($_GET['template_kid'])) $_GET['template_id'] = base_convert($_GET['template_kid'], 36, 10);
35 //requiring main config file with path/database etc. constants
36 require('config/config.inc');
37 require(INCLUDE_DIR
.'senate.inc');
39 if (isset($_SERVER['HTTP_REFERER'])) {
40 preg_match("/id\/([0-9]*)\//",$_SERVER['HTTP_REFERER'],$ref_match);
41 $referer_id=$ref_match[1];
44 //connecting to database and creating universal $db object
45 require(INCLUDE_DIR
.'log.inc');
46 require(INCLUDE_DIR
.'ubik.inc');
47 require(INCLUDE_DIR
.'nodes.inc');
48 require(INCLUDE_DIR
.'error_messages.inc');
49 require(INCLUDE_DIR
.'database.inc');
51 $db = new CLASS_DATABASE();
53 if (!empty($_GET['template_id'])) {
54 $template_id=$_GET['template_id'];
59 //initializing node methods
60 if (!empty($_GET['node_name'])) {
61 $node = nodes
::redirByName($_GET['node_name']);
62 } elseif (!empty($_GET['node_id'])) {
63 $node = nodes
::getNodeById($_GET['node_id'],
64 (isset($_SESSION['user_id']))?
$_SESSION['user_id']:'');
67 //XXX Paths are wrong (!)
68 //loading smarty template engine and setting main parameters
69 require(SMARTY_DIR
.'Smarty.class.php');
72 //$smarty->php_handling = SMARTY_PHP_REMOVE; //XXX
73 $smarty->template_dir
= TEMPLATE_DIR
;
74 //echo TEMPLATE_DIR.TEMPLATE_SET;
75 //echo $smarty->template_dir;
76 $smarty->compile_dir
= SYSTEM_DATA
."templates_c/";
77 $smarty->config_dir
= SMARTY_DIR
.'configs/'; //XXX neexistuje
78 $smarty->cache_dir
= SMARTY_DIR
.'cache/';
79 $smarty->plugins_dir
= SMARTY_PLUGIN_DIR
;
80 if ($_SESSION['debugging']) $smarty->debugging
=true;
82 // initializing variables
83 // preg_replace prevents LFI
84 if (empty($_POST['event'])) $event=false;
85 else $event= preg_replace( "![^a-zA-Z0-9_]+!", "", $_POST['event']);
88 if ($_SESSION['debugging']) {
89 echo "<pre><b>NODE::";
94 if ((isset($_SESSION['user_id']) && ($node['node_creator']==$_SESSION['user_id']))) {
95 $node['node_permission']='owner';
98 if (isset($_SESSION['cube_vector']) && ($_SESSION['cube_vector'])) {
99 if (strpos($node['node_vector'],$_SESSION['cube_vector'])===false) {
100 echo "node::".$node['node_vector'];
101 echo "cube_Vector::".$_SESSION['cube_vector'];
102 echo "you are out of allowed cwbe. access forbidden";
107 //if not existent node show our own 404
109 $nodes= nodes
::getNodesByName($_GET['node_name']);
111 $smarty->assign('nodes',$nodes);
112 $content=$smarty->display("404.tpl");
115 elseif ($_SESSION['user_id']) {
116 $smarty->assign('node_name',$_GET['node_name']);
117 $content=$smarty->display("modules/addnode.tpl");
121 //modifying node glass pearl //XXX WTF
122 if (is_array($children_types[$node['node_type']])) {
123 $smarty->assign('children_types',$children_types[$node['node_type']]);
125 $smarty->assign('types',$types);
128 //$node['node_type']=$types[$node['node_type']];
129 $node['node_content']= StripSlashes($node['node_content']);
130 $node['node_name']= StripSlashes($node['node_name']);
132 //checking permissions
133 function _checkPermissions()
135 global $permissions, $node;
137 require(INCLUDE_DIR
.'permissions.inc');
138 $permissions=permissions
::checkPermissions($node);
139 $permissions['h']=permissions
::isHierarch($node);
143 if ($template_id=='rss') //XXX WHAT?
145 $_feedType = "RSS0.91";
146 if (!is_numeric($_SESSION['user_id']))
148 if (!isset($_SERVER['PHP_AUTH_USER'])) {
149 header('WWW-Authenticate: Basic realm="Kyberia"');
150 header('HTTP/1.0 401 Unauthorized');
151 echo 'Cancel button';
156 require_once(EVENT_DIR
.'/login.inc');
157 $_POST['login'] = $_SERVER['PHP_AUTH_USER'];
158 $_POST['password'] = $_SERVER['PHP_AUTH_PW'];
159 $_POST['login_type'] = "name";
162 echo "Zle meno/heslo.";
171 if ($_GET['node_id']==='24' && $permissions['r'])
173 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
175 $rss = new UniversalFeedCreator();
176 $rss->title
= "Kyberia mail";
177 $rss->description
= "";
178 $rss->link
= "https://". SYSTEM_URL
. "/id/24";
181 $query = "select date_format(mail.mail_timestamp,\"%e.%c. %k:%i:%s\") as cas,
182 userfrom.user_action as locationfrom_action,
183 userfrom.user_action_id as locationfrom_action_id,
184 userto.user_action as locationto_action,
185 userto.user_action_id as locationto_action_id,
186 userto.login as mail_to_name, userfrom.login as mail_from_name,
187 mail.* from mail left join users as userfrom on
188 mail_from=userfrom.user_id left join users as userto on mail_to=userto.user_id
189 where mail_user='$_SESSION[user_id]' and mail_to='$_SESSION[user_id]' order by mail_id desc limit 0,10";
191 $set = $db->query($query);
193 while($set->next()) {
194 $m = $set->getRecord();
195 if ($m['mail_to'] != $_SESSION['user_id'])
197 $item = new FeedItem();
198 $item->title
= $m['mail_from_name'];
199 $item->link
= "https://".SYSTEM_URL
."/id/24";
200 $item->description
= $m['mail_text'];
201 $rss->addItem($item);
205 elseif ($_GET['node_id']=='19' && $permissions['r'])
207 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
209 $rss = new UniversalFeedCreator();
210 $rss->title
= "Kyberia bookmarks";
211 $rss->link
= "http://".SYSTEM_URL
."/id/19"; //XXX https ?
213 require_once(SMARTY_PLUGIN_DIR
.'/function.get_bookmarks.php');
214 smarty_function_get_bookmarks(array(), $smarty);
215 $_items = $smarty->get_template_vars('get_bookmarks');
216 foreach ($_items as $_item)
218 if (is_array($_item['children']))
219 foreach ($_item['children'] as $_b)
221 $item = new FeedItem();
222 $item->title
= $_b['node_name'];
223 $item->link
= "http://".SYSTEM_URL
."/id/".$_b['node_id']."/rss";
224 $rss->addItem($item);
229 elseif ($permissions['r'])
231 require_once(INCLUDE_DIR
.'/feedcreator.class.php');
233 $rss = new UniversalFeedCreator();
234 $rss->title
= $node['node_name'];
235 $rss->description
= "";
236 $rss->link
= "http://".SYSTEM_URL
."/id/".$node['node_id'];
239 if ($_GET['node_id']=='15')
241 require_once(SMARTY_PLUGIN_DIR
.'/function.get_k.php');
242 smarty_function_get_k(array(), $smarty);
243 $_items = $smarty->get_template_vars('get_k');
247 require_once(SMARTY_PLUGIN_DIR
.'/function.get_children.php');
248 smarty_function_get_children(
249 array('orderby' => 'desc', 'orderby_type' => 'time'), $smarty);
250 $_items = $smarty->get_template_vars('get_children');
253 foreach ($_items as $_item)
255 $item = new FeedItem();
256 $item->title
= $_item['node_name'];
257 $item->link
= "http://".SYSTEM_URL
."/id/".$_item['node_id'];
258 $item->description
= $_item['node_content'];
259 $rss->addItem($item);
263 if ($permissions['r']) $rss->showFeed($_feedType);
272 if (($permissions['r']) ||
($event != 'register')) {
274 //performing node_events (based on update/insert/delete db queries)
276 require(INCLUDE_DIR
.'eventz.inc');
279 elseif ($transaction) {
280 require(INCLUDE_DIR
.'transaction.inc');
282 //end of performing node events
288 if ($permissions['r']) {
290 // these 4 lines are not the source of kyberia lagging problems.
291 // leave them. started on the 10.4.
292 // data gained will be used for scientific purposes
294 // if (isset($_SESSION['user_id']) {
295 // log_levenshtein($_SESSION['user_id'],$node['node_id']);
298 if ((isset($_SESSION['user_id'])) && ($_SESSION['user_id'])) {
299 $q="insert delayed into levenshtein set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."'";
305 if ($node['template_id']!='2019721'){
307 logger
::log('enter',$node['node_id'],'ok',$node['node_user_subchild_count']);
308 if (!empty($_SESSION['user_id']) && is_numeric($node['node_id'])) {
309 $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']."'";
311 $result=$db->update($q);
314 $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()";
317 }//end of if node os css
323 // if (isset($_SESSION['user_id']) {
324 // if (isset($referer_id)) {
325 // update_nodes($_SESSION['user_id'],$node['node_id'],$referer_id);
327 // update_nodes($_SESSION['user_id'],$node['node_id'],0);
331 // DO NOT MESS WITH THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
332 //creating neural network
333 $db->update("update nodes set node_views=node_views+1 where node_id='".$node['node_id']."'");
334 if (isset($referer_id) && is_numeric($referer_id)) {
335 $q="update neurons set synapse=synapse+1 where dst='".$node['node_id']."' and src='$referer_id'";
336 $result=$db->update($q);
338 $q="insert into neurons set synapse_creator='".$_SESSION['user_id']."',dst='".$node['node_id']."',src='$referer_id',synapse=1";
344 elseif (!$permissions['r'] && $_GET['magic_word']) {
345 $magic_word_big=$_GET['magic_word'];
347 if ( preg_match("/(\d+)-(.+)/",$_GET['magic_word'],$mu)) {
349 $magic_word=addslashes($mu['2']);
350 // XXX WTF column magic_word does not exists
351 $q="select login from users where user_id='$magic_uid' and magic_word='$magic_word'";
353 if ($set->getNumRows()) {
354 $permissions['r']=true;
364 logger
::log('enter',$node['node_id'],'failed');
369 //assigning user data to smarty if user logged in
370 if (isset($_SESSION['user_id'])&&($user_id=$_SESSION['user_id'])) {
371 $smarty->assign('_POST',$_POST);
372 $smarty->assign('bookmarks',$_SESSION['bookmarks']);
373 $smarty->assign('ignore',$_SESSION['ignore']);
374 $smarty->assign('bookstyl',$_SESSION['bookstyl']);
375 $smarty->assign('fook',$_SESSION['fook']);
376 $smarty->assign('user_id',$_SESSION['user_id']);
377 if (!empty($_SESSION['cube_vector']))
378 $smarty->assign('cube_vector',$_SESSION['cube_vector']);
379 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
380 $smarty->assign('user_quota',$_SESSION['user_quota']);
383 $newmail_q = sprintf('select u.user_mail_id
387 , ms.user_id as mail_sender_id
388 , ms.login as mail_sender
390 left join users ms on ms.user_id = u.user_mail_id
391 where u.user_id = %d',
393 $newmailset = $db->query($newmail_q);
397 $new_mail=$newmailset->getString('user_mail');
399 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
400 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
401 $newmailset2->next();
402 $smarty->assign('new_mail',$new_mail);
403 $smarty->assign('new_mail_name',$newmailset->getString('mail_sender'));
404 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
405 $user_k=$newmailset->getString('user_k');
406 $smarty->assign('user_k',$user_k);
407 $k_wallet=$newmailset->getString('k_wallet');
408 $smarty->assign('k_wallet',$k_wallet);
409 $user_id=$_SESSION['user_id'];
412 if ($node['node_name']=='mail') {
414 //clear new mail message
416 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
418 //set messages as delivered to recipient
419 $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'");
420 while($set->next()) {
421 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
422 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
424 $new_messages[$set->getString('mail_id')]=true;
427 if (count($new_messages)) {
428 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
429 $smarty->assign('new_messages',$new_messages);
438 if ($node['node_system_access']=='crypto') {
439 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
442 $smarty->assign('error',$error);
443 $smarty->assign('permissions',$permissions);
444 $smarty->assign('current_vector',$node['node_vector']);
445 if ($permissions['r']) $smarty->assign('node',$node);
448 $smarty->assign('node',$node);
449 //new templates by Dark matter
450 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
452 $smarty->display('1549864.tpl');
453 $smarty->display('1549885.tpl');
454 $smarty->display('630526.tpl');
457 //redirect to mainpage
458 // looks like poeple totaly hate this redirect!
459 // header("Location: /id/1");
464 if (($node['template_id']!='2019721') && (isset($_SESSION['user_id']))){
465 //setting user location
466 $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']."'";
467 $db->executequery($q);
470 $whole_time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
471 $smarty->assign('whole_time',$whole_time);
474 if ($template_id=='download' OR $template_id=='download.jpg') {
475 if ($permissions['r']) {
476 $linkname = SYSTEM_ROOT
."/files/".$node['node_id'];
477 $filename= readlink($linkname);
478 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
480 $ext = substr( $filename,-3 );
481 if( $filename == "" ) {
482 echo "ERROR: Empty file to download. ";
484 } elseif ( ! file_exists( $filename ) ) {
487 switch( strtolower($ext) ){
488 case "pdf": $ctype="application/pdf"; break;
489 case "exe": $ctype="application/octet-stream"; break;
490 case "zip": $ctype="application/zip"; break;
491 case "doc": $ctype="application/msword"; break;
492 case "xls": $ctype="application/vnd.ms-excel"; break;
493 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
494 case "gif": $ctype="image/gif"; break;
495 case "png": $ctype="image/png"; break;
496 case "jpg": $ctype="image/jpg"; break;
497 default: $ctype="application/force-download";
499 $file=str_replace(" ","_",$node['node_name']).".$ext";
500 header("Pragma: public");
501 header("Expires: 0");
502 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
503 header("Content-Type: $ctype");
504 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
505 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
506 (strpos($user_agent, "win")))) {
507 header( "Content-Disposition: filename=$file;" );
509 header( "Content-Disposition: attachment;
512 header("Content-Transfer-Encoding: binary");
513 header("Content-Length: ".filesize($filename));
514 readfile("$filename");
517 else { echo "you don't have permissions for downloading this data"; die(); }
520 if ($node['template_id']=='2019721'){
521 Header("Cache-control: max-age=3600");
523 Header("Cache-control: no-cache");
524 Header("Expires:".gmdate("D, d M Y H:i:s")." GMT");
525 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
529 //for cases like search & preview
530 $smarty->assign('post_vars',$_POST);
531 if (!empty($_POST['template_event'])) {
532 $smarty->assign('template_event',$_POST['template_event']);
536 //setting listing parameters
537 $children_count=$node['node_children_count'];
538 $descendant_count=$node['node_descendant_count'];
540 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
541 $listing_amount=mysql_real_escape_string($_POST['listing_amount']);
542 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
543 else $listing_amount=DEFAULT_LISTING_AMOUNT
;
544 $smarty->assign('listing_amount',$listing_amount);
546 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
547 $listing_order=mysql_real_escape_string($_POST['listing_order']);
548 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
549 else $listing_order=DEFAULT_LISTING_ORDER
;
550 $smarty->assign('listing_order',$listing_order);
552 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
553 $offset=$_POST['get_children_offset'];
554 } else { $offset=0; }
557 //movement forward and backward
558 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
560 if ($_POST['get_children_move']=='<') {
561 $offset=$offset-$listing_amount;
562 if ($offset<0) $offset=0;
564 elseif ($_POST['get_children_move']=='>') {
565 $offset=$offset+
$listing_amount;
567 elseif ($_POST['get_children_move']=='>>') {
568 $offset=$descendant_count-$listing_amount;
571 elseif ($_POST['get_children_move']=='<<') {
574 if ($offset<0) $offset=0;
575 $_POST['offset']=$offset;
576 $smarty->assign('offset',$offset);
579 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
580 header("Content-Type: image/svg+xml");
584 elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
585 $smarty->assign('header_id',$_SESSION['header_id']);
586 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
587 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
588 $smarty->template_dir
= TEMPLATE_DIR
.TEMPLATE_SET
;
589 //not registered user
590 if ($_SESSION['header_id']==2091520) {
597 $smarty->template_dir
=OWN_TEMPLATE_DIR
;
599 if (is_numeric($template_id)) {
600 $content.=$smarty->fetch($template_id.".tpl");
604 $template_id=$node['template_id'];
605 $content.=$smarty->fetch($node['template_id'].".tpl");
608 if ($template_id=='2019721'){
609 $content=$smarty->fetch($template_id.".tpl");
612 $time=SubStr((Time()+
SubStr(MicroTime(),0,8)-$timer_start),0,7);
614 // echo "<center>page generation took: $time second</center>";
618 // output buffering forcing (mx)
619 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_end_flush();
This page took 0.810548 seconds and 5 git commands to generate.