Fixed mail: column mail_name does not exists in sql
[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']))
347 $smarty->assign('cube_vector',$_SESSION['cube_vector']);
348 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
349 $smarty->assign('user_quota',$_SESSION['user_quota']);
350
351 $newmail_q = sprintf('select u.user_mail_id
352 , u.user_k
353 , u.k_wallet
354 , u.user_mail
355 , ms.user_id as mail_sender_id
356 , ms.login as mail_sender
357 from users u
358 left join users ms on ms.user_id = u.user_mail_id
359 where u.user_id = %d',
360 $user_id);
361 $newmailset = $db->query($newmail_q);
362
363 # $newmailset=$db->query("select user_mail,user_mail_name,user_k,k_wallet from users where user_id='$user_id'");
364
365 $newmailset->next();
366 $new_mail=$newmailset->getString('user_mail');
367 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
368 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
369 $newmailset2->next();
370 $smarty->assign('new_mail',$new_mail);
371 $smarty->assign('new_mail_name',$newmailset->getString('mail_sender'));
372 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
373 $user_k=$newmailset->getString('user_k');
374 $smarty->assign('user_k',$user_k);
375 $k_wallet=$newmailset->getString('k_wallet');
376 $smarty->assign('k_wallet',$k_wallet);
377 $user_id=$_SESSION['user_id'];
378
379 //mail node
380 if ($node['node_name']=='mail') {
381
382 //clear new mail message
383 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
384
385 //set messages as delivered to recipient
386 $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'");
387 while($set->next()) {
388 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
389 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
390
391 $new_messages[$set->getString('mail_id')]=true;
392 }
393 /*
394 if (count($new_messages)) {
395 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
396 $smarty->assign('new_messages',$new_messages);
397
398 }
399 */
400 }
401 }
402
403
404
405 if ($node['node_system_access']=='crypto') {
406 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
407 }
408
409 $smarty->assign('error',$error);
410 $smarty->assign('permissions',$permissions);
411 $smarty->assign('current_vector',$node['node_vector']);
412 if ($permissions['r']) $smarty->assign('node',$node);
413 else {
414
415 $smarty->assign('node',$node);
416 //new templates by Dark matter
417 $smarty->template_dir=OWN_TEMPLATE_DIR;
418
419 $smarty->display('1549864.tpl');
420 $smarty->display('1549885.tpl');
421 $smarty->display('630526.tpl');
422 die();
423
424 //redirect to mainpage
425 // looks like poeple totaly hate this redirect!
426 // header("Location: /id/1");
427 }
428
429
430 if ($node['template_id']!='2019721'){
431 //setting user location
432 $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']."'";
433 $db->executequery($q);
434 }
435
436 $whole_time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
437 $smarty->assign('whole_time',$whole_time);
438
439
440 if ($template_id=='download' OR $template_id=='download.jpg') {
441 if ($permissions['r']) {
442 $linkname = SYSTEM_ROOT."/files/".$node['node_id'];
443 $filename= readlink($linkname);
444 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
445
446 $ext = substr( $filename,-3 );
447 if( $filename == "" ) {
448 echo "ERROR: Empty file to download. ";
449 exit;
450 } elseif ( ! file_exists( $filename ) ) {
451 exit;
452 };
453 switch( strtolower($ext) ){
454 case "pdf": $ctype="application/pdf"; break;
455 case "exe": $ctype="application/octet-stream"; break;
456 case "zip": $ctype="application/zip"; break;
457 case "doc": $ctype="application/msword"; break;
458 case "xls": $ctype="application/vnd.ms-excel"; break;
459 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
460 case "gif": $ctype="image/gif"; break;
461 case "png": $ctype="image/png"; break;
462 case "jpg": $ctype="image/jpg"; break;
463 default: $ctype="application/force-download";
464 }
465 $file=str_replace(" ","_",$node['node_name']).".$ext";
466 header("Pragma: public");
467 header("Expires: 0");
468 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
469 header("Content-Type: $ctype");
470 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
471 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
472 (strpos($user_agent, "win")))) {
473 header( "Content-Disposition: filename=$file;" );
474 } else {
475 header( "Content-Disposition: attachment;
476 filename=$file;" );
477 }
478 header("Content-Transfer-Encoding: binary");
479 header("Content-Length: ".filesize($filename));
480 readfile("$filename");
481 exit();
482 }
483 else { echo "you don't have permissions for downloading this data"; die(); }
484 }
485
486 if ($node['template_id']=='2019721'){
487 Header("Cache-control: max-age=3600");
488 }else{
489 Header("Cache-control: no-cache");
490 Header("Expires:".gmdate("D, d M Y H:i:s")." GMT");
491 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
492 }
493
494
495 //for cases like search & preview
496 $smarty->assign('post_vars',$_POST);
497 if (!empty($_POST['template_event'])) {
498 $smarty->assign('template_event',$_POST['template_event']);
499
500 }
501
502 //setting listing parameters
503 $children_count=$node['node_children_count'];
504 $descendant_count=$node['node_descendant_count'];
505
506 if (is_numeric($_POST['listing_amount'])) $listing_amount=$_POST['listing_amount'];
507 elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
508 else $listing_amount=DEFAULT_LISTING_AMOUNT;
509 $smarty->assign('listing_amount',$listing_amount);
510
511 if ($_POST['listing_order']) $listing_order=$_POST['listing_order'];
512 elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
513 else $listing_order=DEFAULT_LISTING_ORDER;
514 $smarty->assign('listing_order',$listing_order);
515
516 if (is_numeric($_POST['get_children_offset'])) $offset=$_POST['get_children_offset'];
517 else $offset=0;
518
519
520 //movement forward and backward
521 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
522
523 if ($_POST['get_children_move']=='<') {
524 $offset=$offset-$listing_amount;
525 if ($offset<0) $offset=0;
526 }
527 elseif ($_POST['get_children_move']=='>') {
528 $offset=$offset+$listing_amount;
529 }
530 elseif ($_POST['get_children_move']=='>>') {
531 $offset=$descendant_count-$listing_amount;
532 }
533
534 elseif ($_POST['get_children_move']=='<<') {
535 $offset=0;
536 }
537 if ($offset<0) $offset=0;
538 $_POST['offset']=$offset;
539 $smarty->assign('offset',$offset);
540
541
542 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
543 header("Content-Type: image/svg+xml");
544 }
545
546 //show own header
547 elseif ($_SESSION['header_id']==true) {
548 $smarty->assign('header_id',$_SESSION['header_id']);
549 $smarty->template_dir=OWN_TEMPLATE_DIR;
550 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
551 $smarty->template_dir = TEMPLATE_DIR.TEMPLATE_SET;
552 //not registered user
553 if ($_SESSION['header_id']==2091520) {
554 echo $content;
555 session_destroy();
556 die();
557 }
558 }
559
560 $smarty->template_dir=OWN_TEMPLATE_DIR;
561
562 if (is_numeric($template_id)) {
563 $content.=$smarty->fetch($template_id.".tpl");
564 }
565
566 else {
567 $template_id=$node['template_id'];
568 $content.=$smarty->fetch($node['template_id'].".tpl");
569 }
570
571 if ($template_id=='2019721'){
572 $content=$smarty->fetch($template_id.".tpl");
573 echo $content;
574 }else{
575 $time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
576 echo $content;
577 // echo "<center>page generation took: $time second</center>";
578 }
579 //end of displaying
580
581 // output buffering forcing (mx)
582 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_end_flush();
583
584 ?>
This page took 0.670234 seconds and 5 git commands to generate.