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