path fixing (SYSTEM_ROOT.'inc/a' -> INCLUDE_DIR.'a')
[mirrors/Kyberia-bloodline.git] / wwwroot / nodes.php
1 <?php
2 // output buffering forcing (mx)
3 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_start();
4
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 :)";
7 //exit;
8 error_reporting(1);
9 //exit;
10
11 //starting timer for benchmarking purposes
12 $timer_start=Time()+SubStr(MicroTime(),0,8);
13
14 //setting PHPSESSID cookie and starting user session
15 session_start();
16
17
18 if ($_SESSION['debugging']) {
19
20 error_reporting(E_ALL);
21 echo "GET VARIABLES::<br/>";
22 print_r($_GET);
23 echo "POST VARIABLES::<br/>";
24 print_r($_POST);
25 echo "<b>SESSION VARIABLES::</b><br/>";
26 print_r($_SESSION);
27 }
28
29 //requiring main config file with path/database etc. constants
30 require('config/config.inc');
31 require(INCLUDE_DIR.'senate.inc');
32
33 preg_match("/id\/(.*)\//",$_SERVER['HTTP_REFERER'],$ref_match);
34 $referer_id=$ref_match[1];
35
36 //connecting to database and creating universal $db object
37 require(INCLUDE_DIR.'log.inc');
38 require(INCLUDE_DIR.'ubik.inc');
39 require(INCLUDE_DIR.'nodes.inc');
40 require(INCLUDE_DIR.'error_messages.inc');
41 require(INCLUDE_DIR.'database.inc');
42
43 $db=new CLASS_DATABASE();
44
45 if (!empty($_GET['template_id'])) {
46 $template_id=$_GET['template_id'];
47 }
48 else $template_id=false;
49
50 //initializing node methods
51 if (!empty($_GET['node_name'])) {
52 $node = nodes::redirByName($_GET['node_name']);
53 }
54 elseif (!empty($_GET['node_id'])) {
55 $node = nodes::getNodeById($_GET['node_id'],$_SESSION['user_id']);
56 }
57
58 //loading smarty template engine and setting main parameters
59 require(SMARTY_DIR.'Smarty.class.php');
60 $smarty = new Smarty;
61
62 $smarty->template_dir = TEMPLATE_DIR.TEMPLATE_SET;
63 //echo TEMPLATE_DIR.TEMPLATE_SET;
64 //echo $smarty->template_dir;
65 $smarty->compile_dir = SYSTEM_ROOT."data/templates_c/".TEMPLATE_SET;
66 $smarty->config_dir = SMARTY_DIR.'configs/';
67 $smarty->cache_dir = SMARTY_DIR.'cache/';
68 $smarty->plugins_dir = SMARTY_PLUGIN_DIR ;
69 if ($_SESSION['debugging']) $smarty->debugging=true;
70
71 //initializing variables
72 if (empty($_POST['event'])) $event=false;
73 else $event=$_POST['event'];
74
75
76 if ($_SESSION['debugging']) {
77 echo "<pre><b>NODE::";
78 print_r($node);
79 echo "</pre>";
80 }
81
82 if ($node['node_creator']==$_SESSION['user_id']) $node['node_permission']='owner';
83
84 if ($_SESSION['cube_vector']) {
85 if (strpos($node['node_vector'],$_SESSION['cube_vector'])===false) {
86 echo "node::".$node['node_vector'];
87 echo "cube_Vector::".$_SESSION['cube_vector'];
88 echo "you are out of allowed cwbe. access forbidden";
89 die();
90 }
91 }
92
93 //if not existent node show our own 404
94 if (empty($node)) {
95 $nodes= nodes::getNodesByName($_GET['node_name']);
96 if ($nodes) {
97 $smarty->assign('nodes',$nodes);
98 $content=$smarty->display("404.tpl");
99 die();
100 }
101 elseif ($_SESSION['user_id']) {
102 $smarty->assign('node_name',$_GET['node_name']);
103 $content=$smarty->display("modules/addnode.tpl");
104 }
105 }
106
107 //modifying node glass pearl
108 if (is_array($children_types[$node['node_type']])) $smarty->assign('children_types',$children_types[$node['node_type']]);
109 $smarty->assign('types',$types);
110
111
112 //$node['node_type']=$types[$node['node_type']];
113 $node['node_content']=StripSlashes($node['node_content']);
114 $node['node_name']=StripSlashes($node['node_name']);
115
116 //checking permissions
117 function _checkPermissions()
118 {
119 global $permissions, $node;
120
121 require(INCLUDE_DIR.'permissions.inc');
122 $permissions=permissions::checkPermissions($node);
123 $permissions['h']=permissions::isHierarch($node);
124 }
125
126 // mail rss
127 if ($template_id=='rss')
128 {
129 $_feedType = "RSS0.91";
130 if (!is_numeric($_SESSION['user_id']))
131 {
132 if (!isset($_SERVER['PHP_AUTH_USER'])) {
133 header('WWW-Authenticate: Basic realm="Kyberia"');
134 header('HTTP/1.0 401 Unauthorized');
135 echo 'Cancel button';
136 exit;
137 }
138 else
139 {
140 require_once(EVENT_DIR.'/login.inc');
141 $_POST['login'] = $_SERVER['PHP_AUTH_USER'];
142 $_POST['password'] = $_SERVER['PHP_AUTH_PW'];
143 $_POST['login_type'] = "name";
144 if (!login())
145 {
146 echo "Zle meno/heslo.";
147 exit();
148 }
149 }
150 }
151
152 _checkPermissions();
153
154 // Mail
155 if ($_GET['node_id']==='24' && $permissions['r'])
156 {
157 require_once(INCLUDE_DIR.'/feedcreator.class.php');
158
159 $rss =& new UniversalFeedCreator();
160 $rss->title = "Kyberia mail";
161 $rss->description = "";
162 $rss->link = "https://kyberia.sk/id/24";
163
164 $query = "select date_format(mail.mail_timestamp,\"%e.%c. %k:%i:%s\") as cas,
165 userfrom.user_action as locationfrom_action,
166 userfrom.user_action_id as locationfrom_action_id,
167 userto.user_action as locationto_action,
168 userto.user_action_id as locationto_action_id,
169 userto.login as mail_to_name, userfrom.login as mail_from_name,
170 mail.* from mail left join users as userfrom on
171 mail_from=userfrom.user_id left join users as userto on mail_to=userto.user_id
172 where mail_user='$_SESSION[user_id]' and mail_to='$_SESSION[user_id]' order by mail_id desc limit 0,10";
173
174 $set = $db->query($query);
175
176 while($set->next()) {
177 $m = $set->getRecord();
178 if ($m['mail_to'] != $_SESSION['user_id'])
179 continue;
180 $item =& new FeedItem();
181 $item->title = $m['mail_from_name'];
182 $item->link = "https://kyberia.sk/id/24";
183 $item->description = $m['mail_text'];
184 $rss->addItem($item);
185 }
186 }
187 // bookmarks
188 elseif ($_GET['node_id']=='19' && $permissions['r'])
189 {
190 require_once(INCLUDE_DIR.'/feedcreator.class.php');
191
192 $rss =& new UniversalFeedCreator();
193 $rss->title = "Kyberia bookmarks";
194 $rss->link = "http://kyberia.sk/id/19";
195
196 require_once(SMARTY_PLUGIN_DIR.'/function.get_bookmarks.php');
197 smarty_function_get_bookmarks(array(), $smarty);
198 $_items = $smarty->get_template_vars('get_bookmarks');
199 foreach ($_items as $_item)
200 {
201 if (is_array($_item['children']))
202 foreach ($_item['children'] as $_b)
203 {
204 $item =& new FeedItem();
205 $item->title = $_b['node_name'];
206 $item->link = "http://kyberia.sk/id/".$_b['node_id']."/rss";
207 $rss->addItem($item);
208 }
209 }
210 $_feedType = 'OPML';
211 }
212 elseif ($permissions['r'])
213 {
214 require_once(INCLUDE_DIR.'/feedcreator.class.php');
215
216 $rss =& new UniversalFeedCreator();
217 $rss->title = $node['node_name'];
218 $rss->description = "";
219 $rss->link = "http://kyberia.sk/id/".$node['node_id'];
220
221 // K list
222 if ($_GET['node_id']=='15')
223 {
224 require_once(SMARTY_PLUGIN_DIR.'/function.get_k.php');
225 smarty_function_get_k(array(), $smarty);
226 $_items = $smarty->get_template_vars('get_k');
227 }
228 else
229 {
230 require_once(SMARTY_PLUGIN_DIR.'/function.get_children.php');
231 smarty_function_get_children(
232 array('orderby' => 'desc', 'orderby_type' => 'time'), $smarty);
233 $_items = $smarty->get_template_vars('get_children');
234 }
235
236 foreach ($_items as $_item)
237 {
238 $item =& new FeedItem();
239 $item->title = $_item['node_name'];
240 $item->link = "http://kyberia.sk/id/".$_item['node_id'];
241 $item->description = $_item['node_content'];
242 $rss->addItem($item);
243 }
244 }
245
246 if ($permissions['r']) $rss->showFeed($_feedType);
247 exit();
248 }
249
250 _checkPermissions();
251
252 //entering the node
253
254 //sventest
255 if (($permissions['r']) || ($event != 'register')) {
256
257 //performing node_events (based on update/insert/delete db queries)
258 if ($event) {
259 require(INCLUDE_DIR.'eventz.inc');
260 }
261
262 elseif ($transaction) {
263 require(INCLUDE_DIR.'transaction.inc');
264 }
265 //end of performing node events
266
267 //sventest
268 }
269
270
271 if ($permissions['r']) {
272
273 //these 4 lines are not the source of kyberia lagging problems. leave them. started on the 10.4. data gained will be used for scientific purposes
274 if ($_SESSION['user_id']) {
275 $q="insert delayed into levenshtein set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."'";
276 $db->update($q);
277 }
278
279 //if node is css
280 if ($node['template_id']!='2019721'){
281
282 log::log('enter',$node['node_id'],'ok',$node['node_user_subchild_count']);
283 if (!empty($_SESSION['user_id']) && is_numeric($node['node_id'])) {
284 $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']."'";
285 // echo $q;
286 $result=$db->update($q);
287
288 if (!$result) {
289 $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()";
290 $db->query($q);
291 }
292 }//end of if node os css
293 }
294
295
296 }
297 // DO NOT MESS WITH THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
298 //creating neural network
299 $db->update("update nodes set node_views=node_views+1 where node_id='".$node['node_id']."'");
300 if (is_numeric($referer_id)) {
301 $q="update neurons set synapse=synapse+1 where dst='".$node['node_id']."' and src='$referer_id'";
302 $result=$db->update($q);
303 if (!$result) {
304 $q="insert into neurons set synapse_creator='".$_SESSION['user_id']."',dst='".$node['node_id']."',src='$referer_id',synapse=1";
305 $db->query($q);
306 }
307 }
308
309
310 elseif (!$permissions['r'] && $_GET['magic_word']) {
311 $magic_word_big=$_GET['magic_word'];
312
313 if ( preg_match("/(\d+)-(.+)/",$_GET['magic_word'],$mu)) {
314 $magic_uid=$mu['1'];
315 $magic_word=addslashes($mu['2']);
316 $q="select login from users where user_id='$magic_uid' and magic_word='$magic_word'";
317 $set=$db->query($q);
318 if ($set->getNumRows()) {
319 $permissions['r']=true;
320 }
321 }
322 }
323
324
325
326
327
328 else {
329 log::log('enter',$node['node_id'],'failed');
330 }
331
332
333
334 //assigning user data to smarty if user logged in
335 if ($user_id=$_SESSION['user_id']) {
336 $smarty->assign('_POST',$_POST);
337 $smarty->assign('bookmarks',$_SESSION['bookmarks']);
338 $smarty->assign('ignore',$_SESSION['ignore']);
339 $smarty->assign('bookstyl',$_SESSION['bookstyl']);
340 $smarty->assign('fook',$_SESSION['fook']);
341 $smarty->assign('user_id',$_SESSION['user_id']);
342 if (!empty($_SESSION['cube_vector'])) $smarty->assign('cube_vector',$_SESSION['cube_vector']);
343 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
344 $smarty->assign('user_quota',$_SESSION['user_quota']);
345 $newmailset=$db->query("select user_mail,user_mail_name,user_k,k_wallet from users where user_id='$user_id'");
346 $newmailset->next();
347 $new_mail=$newmailset->getString('user_mail');
348 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
349 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
350 $newmailset2->next();
351 $smarty->assign('new_mail',$new_mail);
352 $smarty->assign('new_mail_name',$newmailset->getString('user_mail_name'));
353 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
354 $user_k=$newmailset->getString('user_k');
355 $smarty->assign('user_k',$user_k);
356 $k_wallet=$newmailset->getString('k_wallet');
357 $smarty->assign('k_wallet',$k_wallet);
358 $user_id=$_SESSION['user_id'];
359
360 //mail node
361 if ($node['node_name']=='mail') {
362
363 //clear new mail message
364 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
365
366 //set messages as delivered to recipient
367 $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'");
368 while($set->next()) {
369 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
370 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
371
372 $new_messages[$set->getString('mail_id')]=true;
373 }
374 /*
375 if (count($new_messages)) {
376 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
377 $smarty->assign('new_messages',$new_messages);
378
379 }
380 */
381 }
382 }
383
384
385
386 if ($node['node_system_access']=='crypto') {
387 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
388 }
389
390 //hlaska
391 //$error .= "ocakavajte planovany vypadok okolo 6 hodiny <br>
392 //s pozdravom br .)";
393 //$error .= "dnes od 22:00 zurka v subclube! ucast povinna!";
394
395 $smarty->assign('error',$error);
396 $smarty->assign('permissions',$permissions);
397 $smarty->assign('current_vector',$node['node_vector']);
398 if ($permissions['r']) $smarty->assign('node',$node);
399 else {
400
401 $smarty->assign('node',$node);
402 //new templates by Dark matter
403 $smarty->template_dir=OWN_TEMPLATE_DIR;
404
405 $smarty->display('1549864.tpl');
406 $smarty->display('1549885.tpl');
407 $smarty->display('630526.tpl');
408 die();
409
410 //redirect to mainpage
411 // looks like poeple totaly hate this redirect!
412 // header("Location: /id/1");
413 }
414
415
416 if ($node['template_id']!='2019721'){
417 //setting user location
418 $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']."'";
419 $db->executequery($q);
420 }
421
422 $whole_time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
423 $smarty->assign('whole_time',$whole_time);
424
425
426 if ($template_id=='download' OR $template_id=='download.jpg') {
427 if ($permissions['r']) {
428 $linkname = SYSTEM_ROOT."/files/".$node['node_id'];
429 $filename= readlink($linkname);
430 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
431
432 $ext = substr( $filename,-3 );
433 if( $filename == "" ) {
434 echo "ERROR: Empty file to download. ";
435 exit;
436 } elseif ( ! file_exists( $filename ) ) {
437 exit;
438 };
439 switch( strtolower($ext) ){
440 case "pdf": $ctype="application/pdf"; break;
441 case "exe": $ctype="application/octet-stream"; break;
442 case "zip": $ctype="application/zip"; break;
443 case "doc": $ctype="application/msword"; break;
444 case "xls": $ctype="application/vnd.ms-excel"; break;
445 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
446 case "gif": $ctype="image/gif"; break;
447 case "png": $ctype="image/png"; break;
448 case "jpg": $ctype="image/jpg"; break;
449 default: $ctype="application/force-download";
450 }
451 $file=str_replace(" ","_",$node['node_name']).".$ext";
452 header("Pragma: public");
453 header("Expires: 0");
454 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
455 header("Content-Type: $ctype");
456 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
457 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
458 (strpos($user_agent, "win")))) {
459 header( "Content-Disposition: filename=$file;" );
460 } else {
461 header( "Content-Disposition: attachment;
462 filename=$file;" );
463 }
464 header("Content-Transfer-Encoding: binary");
465 header("Content-Length: ".filesize($filename));
466 readfile("$filename");
467 exit();
468 }
469 else { echo "you don't have permissions for downloading this data"; die(); }
470 }
471
472 if ($node['template_id']=='2019721'){
473 Header("Cache-control: max-age=3600");
474 }else{
475 Header("Cache-control: no-cache");
476 Header("Expires:".gmdate("D, d M Y H:i:s")." GMT");
477 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
478 }
479
480
481 //for cases like search & preview
482 $smarty->assign('post_vars',$_POST);
483 if (!empty($_POST['template_event'])) {
484 $smarty->assign('template_event',$_POST['template_event']);
485
486 }
487
488 //setting listing parameters
489 $children_count=$node['node_children_count'];
490 $descendant_count=$node['node_descendant_count'];
491
492 if (is_numeric($_POST['listing_amount'])) $listing_amount=$_POST['listing_amount'];
493 elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
494 else $listing_amount=DEFAULT_LISTING_AMOUNT;
495 $smarty->assign('listing_amount',$listing_amount);
496
497 if ($_POST['listing_order']) $listing_order=$_POST['listing_order'];
498 elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
499 else $listing_order=DEFAULT_LISTING_ORDER;
500 $smarty->assign('listing_order',$listing_order);
501
502 if (is_numeric($_POST['get_children_offset'])) $offset=$_POST['get_children_offset'];
503 else $offset=0;
504
505
506 //movement forward and backward
507 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
508
509 if ($_POST['get_children_move']=='<') {
510 $offset=$offset-$listing_amount;
511 if ($offset<0) $offset=0;
512 }
513 elseif ($_POST['get_children_move']=='>') {
514 $offset=$offset+$listing_amount;
515 }
516 elseif ($_POST['get_children_move']=='>>') {
517 $offset=$descendant_count-$listing_amount;
518 }
519
520 elseif ($_POST['get_children_move']=='<<') {
521 $offset=0;
522 }
523 if ($offset<0) $offset=0;
524 $_POST['offset']=$offset;
525 $smarty->assign('offset',$offset);
526
527
528 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
529 header("Content-Type: image/svg+xml");
530 }
531
532 //show own header
533 elseif ($_SESSION['header_id']==true) {
534 $smarty->assign('header_id',$_SESSION['header_id']);
535 $smarty->template_dir=OWN_TEMPLATE_DIR;
536 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
537 $smarty->template_dir = TEMPLATE_DIR.TEMPLATE_SET;
538 //not registered user
539 if ($_SESSION['header_id']==2091520) {
540 echo $content;
541 session_destroy();
542 die();
543 }
544 }
545
546 $smarty->template_dir=OWN_TEMPLATE_DIR;
547
548 if (is_numeric($template_id)) {
549 $content.=$smarty->fetch($template_id.".tpl");
550 }
551
552 else {
553 $template_id=$node['template_id'];
554 $content.=$smarty->fetch($node['template_id'].".tpl");
555 }
556
557 if ($template_id=='2019721'){
558 $content=$smarty->fetch($template_id.".tpl");
559 echo $content;
560 }else{
561 $time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
562 echo $content;
563 // echo "<center>page generation took: $time second</center>";
564 }
565 //end of displaying
566
567 // output buffering forcing (mx)
568 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_end_flush();
569
570 ?>
This page took 0.719973 seconds and 5 git commands to generate.