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