Commented-out whole transaction.inc stuff
[mirrors/Kyberia-bloodline.git] / wwwroot / nodes.php
CommitLineData
51ff3226 1<?php
2bfe7a1f
H
2require_once('config/config.inc'); //requiring main config file with path/database etc. constants
3if(isset($realm) && isset($users)) require_once(INCLUDE_DIR.'http_auth.php'); //Ask for auth if enabled...
a81e2af2 4//echo($_SERVER['PATH_INFO']."\n<pre>"); var_dump(preg_split('/\//', $_SERVER['PATH_INFO'])); die(); //PATH_INFO Debug (usefull when messing with mod_rewrite)
51ff3226 5// output buffering forcing (mx)
6if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_start();
7
51ff3226 8//header("Location: http://web.archive.org/web/20020925021139/http://kyberia.sk");
51ff3226 9//echo "je to uz uplne v pici. vsetky data su stratene, prajem pekny den :)";
10//exit;
ab8ec5e5 11
51ff3226 12//starting timer for benchmarking purposes
13$timer_start=Time()+SubStr(MicroTime(),0,8);
51ff3226 14//setting PHPSESSID cookie and starting user session
15session_start();
16
45a1b870 17error_reporting(1);
cb4300b2 18//$_SESSION['debugging']=1;
88698052 19//unset($_SESSION['debugging']); //Well... we should make some event or JavaScript page to turning this on/off...
45a1b870 20//exit;
21
51ff3226 22
23if ($_SESSION['debugging']) {
24
25 error_reporting(E_ALL);
a81e2af2 26 echo 'GET VARIABLES::<br/>';
51ff3226 27 print_r($_GET);
a81e2af2 28 echo 'POST VARIABLES::<br/>';
51ff3226 29 print_r($_POST);
a81e2af2 30 echo '<b>SESSION VARIABLES::</b><br/>';
51ff3226 31 print_r($_SESSION);
32}
33
5c9aff9f
H
34@ini_set('magic_quotes_gpc' , 'off');
35if(get_magic_quotes_gpc()) die("Error: magic_quotes_gpc needs to be disabled! F00K!\n");
36
4dd26acd 37//Smarty from DB
00be2b5c
H
38$smarty_resource = 'kyberia';
39//$smarty_resource = ''; //same as 'file' (fallback)
40/* I have moved old templates to DB using following lame script:
41 * for i in *.tpl; do j=$(echo "$i" | cut -d . -f 1); echo UPDATE nodes SET node_content = "'$(php -r "echo mysql_escape_string(file_get_contents('$i'));")'" WHERE node_id = "'$j'" COLLATE utf8_bin LIMIT '1;'; done | mysql --user=kyberia --password=PASSSSSSS kyberia
42 * In future we should have some mechanism for distributing templates because they are very important part of kyberia source...
43 */
822594dc 44
a81e2af2 45//Path info (Experimental - this replaced most of mod_rewrites...)
822594dc
H
46@$PATH_INFO=trim($_SERVER[PATH_INFO]);
47if($PATH_INFO != '') {
a81e2af2 48 $PATH_CHUNKS = preg_split('/\//', $PATH_INFO);
20b73641 49 if(isset($PATH_CHUNKS[1])) switch($PATH_CHUNKS[1]) {
822594dc
H
50 case 'k':
51 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_kid'] = $PATH_CHUNKS[2];
52 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_kid'] = $PATH_CHUNKS[3];
53 break;
54 case 'id':
55 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_id'] = $PATH_CHUNKS[2];
56 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_id'] = $PATH_CHUNKS[3];
692f2b82
H
57
58 //Base36 fascism redirect
93748c08 59 if($_GET['template_id'] == 'download') break; //Fix ugly download hack...
692f2b82
H
60 if(!count($_POST)) {
61 header('Location: /k/'.base_convert($_GET['node_id'], 10, 36).
62 (isset($_GET['template_id'])?'/'.base_convert($_GET['template_id'], 10, 36):'')
63 );
64 die("Base36 fascism...\n"); //If you want to be a fascist you have to die imediatelly...
65 }
66
822594dc 67 break;
20b73641
H
68 default:
69 if($PATH_CHUNKS[1] != '') $_GET['node_name'] = $PATH_CHUNKS[1];
70 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['template_kid'] = $PATH_CHUNKS[2];
71 break;
822594dc
H
72 }
73}
15de3e32
H
74if(
75 (!isset($_GET['node_kid']) || trim($_GET['node_kid']) == '') &&
76 (!isset($_GET['node_id']) || trim($_GET['node_id']) == '')
77) $_GET['node_kid'] = 1;
822594dc 78
96a2b554
H
79//Base36 http://en.wikipedia.org/wiki/Base_36 (Initial support only :-)
80if(isset($_GET['node_kid'])) $_GET['node_id'] = base_convert($_GET['node_kid'], 36, 10);
81if(isset($_GET['template_kid'])) $_GET['template_id'] = base_convert($_GET['template_kid'], 36, 10);
82
1dbcd100 83require_once(INCLUDE_DIR.'senate.inc');
51ff3226 84
2bcd35a6 85if (isset($_SERVER['HTTP_REFERER'])) {
a81e2af2 86 preg_match('/(k|id)\/([0-9]*)\//',$_SERVER['HTTP_REFERER'],$ref_match);
2bcd35a6 87 $referer_id=$ref_match[1];
88}
51ff3226 89
90//connecting to database and creating universal $db object
cb5cd120
H
91require_once(INCLUDE_DIR.'log.inc');
92require_once(INCLUDE_DIR.'ubik.inc');
93require_once(INCLUDE_DIR.'nodes.inc');
94require_once(INCLUDE_DIR.'error_messages.inc');
95require_once(INCLUDE_DIR.'database.inc');
96require_once(INCLUDE_DIR.'transports.inc');
51ff3226 97
e23557a6 98$db = new CLASS_DATABASE();
51ff3226 99
100if (!empty($_GET['template_id'])) {
101 $template_id=$_GET['template_id'];
5b9c0808 102} else {
103 $template_id=false;
51ff3226 104}
51ff3226 105
106//initializing node methods
107if (!empty($_GET['node_name'])) {
51ff3226 108 $node = nodes::redirByName($_GET['node_name']);
5b9c0808 109} elseif (!empty($_GET['node_id'])) {
110 $node = nodes::getNodeById($_GET['node_id'],
111 (isset($_SESSION['user_id']))?$_SESSION['user_id']:'');
51ff3226 112}
113
065440d5 114//XXX Paths are wrong (!)
51ff3226 115//loading smarty template engine and setting main parameters
116require(SMARTY_DIR.'Smarty.class.php');
117$smarty = new Smarty;
6a967e24 118require(INCLUDE_DIR.'smarty/resource.kyberia.php');
00be2b5c 119$smarty->default_resource_type=$smarty_resource;
51ff3226 120
065440d5 121//$smarty->php_handling = SMARTY_PHP_REMOVE; //XXX
39244cfc 122$smarty->template_dir = TEMPLATE_DIR;
51ff3226 123//echo TEMPLATE_DIR.TEMPLATE_SET;
124//echo $smarty->template_dir;
a81e2af2 125$smarty->compile_dir = SYSTEM_DATA.'templates_c/';
175043f4 126$smarty->config_dir = SMARTY_DIR.'configs/'; //XXX neexistuje
51ff3226 127$smarty->cache_dir = SMARTY_DIR.'cache/';
128$smarty->plugins_dir = SMARTY_PLUGIN_DIR ;
129if ($_SESSION['debugging']) $smarty->debugging=true;
130
9850bdc4 131// initializing variables
132// preg_replace prevents LFI
51ff3226 133if (empty($_POST['event'])) $event=false;
9850bdc4 134else $event= preg_replace( "![^a-zA-Z0-9_]+!", "", $_POST['event']);
51ff3226 135
136
137if ($_SESSION['debugging']) {
138 echo "<pre><b>NODE::";
139 print_r($node);
140 echo "</pre>";
141}
142
12425f11 143if ((isset($_SESSION['user_id']) && ($node['node_creator']==$_SESSION['user_id']))) {
006bd683 144 $node['node_permission']='owner';
145}
51ff3226 146
006bd683 147if (isset($_SESSION['cube_vector']) && ($_SESSION['cube_vector'])) {
51ff3226 148 if (strpos($node['node_vector'],$_SESSION['cube_vector'])===false) {
149 echo "node::".$node['node_vector'];
150 echo "cube_Vector::".$_SESSION['cube_vector'];
151 echo "you are out of allowed cwbe. access forbidden";
152 die();
153 }
154}
155
156//if not existent node show our own 404
157if (empty($node)) {
158 $nodes= nodes::getNodesByName($_GET['node_name']);
159 if ($nodes) {
160 $smarty->assign('nodes',$nodes);
00be2b5c 161 $content=$smarty->display('404.tpl');
51ff3226 162 die();
163 }
164 elseif ($_SESSION['user_id']) {
165 $smarty->assign('node_name',$_GET['node_name']);
166 $content=$smarty->display("modules/addnode.tpl");
167 }
168}
169
006bd683 170//modifying node glass pearl //XXX WTF
09f0f2fa 171//if (is_array($children_types[$node['node_type']])) {
172// $smarty->assign('children_types',$children_types[$node['node_type']]);
173//}
174
ac6dff25 175//smarty->assign('types',$types);
51ff3226 176
177
178//$node['node_type']=$types[$node['node_type']];
5c9aff9f 179/* This should NOT BE HANDLED HERE! This breaks things...
006bd683 180$node['node_content']= StripSlashes($node['node_content']);
181$node['node_name']= StripSlashes($node['node_name']);
5c9aff9f 182*/
51ff3226 183
184//checking permissions
185function _checkPermissions()
186{
187 global $permissions, $node;
188
e909f81b 189 require(INCLUDE_DIR.'permissions.inc');
51ff3226 190 $permissions=permissions::checkPermissions($node);
191 $permissions['h']=permissions::isHierarch($node);
192}
193
194// mail rss
5b9c0808 195if ($template_id=='rss') //XXX WHAT?
51ff3226 196{
197 $_feedType = "RSS0.91";
198 if (!is_numeric($_SESSION['user_id']))
199 {
200 if (!isset($_SERVER['PHP_AUTH_USER'])) {
201 header('WWW-Authenticate: Basic realm="Kyberia"');
202 header('HTTP/1.0 401 Unauthorized');
203 echo 'Cancel button';
204 exit;
205 }
206 else
207 {
208 require_once(EVENT_DIR.'/login.inc');
209 $_POST['login'] = $_SERVER['PHP_AUTH_USER'];
210 $_POST['password'] = $_SERVER['PHP_AUTH_PW'];
211 $_POST['login_type'] = "name";
212 if (!login())
213 {
214 echo "Zle meno/heslo.";
215 exit();
216 }
217 }
218 }
219
220 _checkPermissions();
221
222 // Mail
223 if ($_GET['node_id']==='24' && $permissions['r'])
224 {
225 require_once(INCLUDE_DIR.'/feedcreator.class.php');
226
82765da6 227 $rss = new UniversalFeedCreator();
51ff3226 228 $rss->title = "Kyberia mail";
229 $rss->description = "";
b6e35197 230 $rss->link = "https://". SYSTEM_URL . "/id/24";
51ff3226 231
5b9c0808 232 //XXX into function
51ff3226 233 $query = "select date_format(mail.mail_timestamp,\"%e.%c. %k:%i:%s\") as cas,
234 userfrom.user_action as locationfrom_action,
235 userfrom.user_action_id as locationfrom_action_id,
236 userto.user_action as locationto_action,
237 userto.user_action_id as locationto_action_id,
238 userto.login as mail_to_name, userfrom.login as mail_from_name,
239 mail.* from mail left join users as userfrom on
240 mail_from=userfrom.user_id left join users as userto on mail_to=userto.user_id
241 where mail_user='$_SESSION[user_id]' and mail_to='$_SESSION[user_id]' order by mail_id desc limit 0,10";
242
243 $set = $db->query($query);
244
245 while($set->next()) {
246 $m = $set->getRecord();
247 if ($m['mail_to'] != $_SESSION['user_id'])
248 continue;
82765da6 249 $item = new FeedItem();
51ff3226 250 $item->title = $m['mail_from_name'];
b6e35197 251 $item->link = "https://".SYSTEM_URL."/id/24";
51ff3226 252 $item->description = $m['mail_text'];
253 $rss->addItem($item);
254 }
255 }
256 // bookmarks
257 elseif ($_GET['node_id']=='19' && $permissions['r'])
258 {
259 require_once(INCLUDE_DIR.'/feedcreator.class.php');
260
82765da6 261 $rss = new UniversalFeedCreator();
51ff3226 262 $rss->title = "Kyberia bookmarks";
5b9c0808 263 $rss->link = "http://".SYSTEM_URL."/id/19"; //XXX https ?
51ff3226 264
265 require_once(SMARTY_PLUGIN_DIR.'/function.get_bookmarks.php');
266 smarty_function_get_bookmarks(array(), $smarty);
267 $_items = $smarty->get_template_vars('get_bookmarks');
268 foreach ($_items as $_item)
269 {
270 if (is_array($_item['children']))
271 foreach ($_item['children'] as $_b)
272 {
82765da6 273 $item = new FeedItem();
51ff3226 274 $item->title = $_b['node_name'];
b6e35197 275 $item->link = "http://".SYSTEM_URL."/id/".$_b['node_id']."/rss";
51ff3226 276 $rss->addItem($item);
277 }
278 }
279 $_feedType = 'OPML';
280 }
281 elseif ($permissions['r'])
282 {
283 require_once(INCLUDE_DIR.'/feedcreator.class.php');
284
82765da6 285 $rss = new UniversalFeedCreator();
51ff3226 286 $rss->title = $node['node_name'];
287 $rss->description = "";
b6e35197 288 $rss->link = "http://".SYSTEM_URL."/id/".$node['node_id'];
51ff3226 289
290 // K list
291 if ($_GET['node_id']=='15')
292 {
293 require_once(SMARTY_PLUGIN_DIR.'/function.get_k.php');
294 smarty_function_get_k(array(), $smarty);
295 $_items = $smarty->get_template_vars('get_k');
296 }
297 else
298 {
299 require_once(SMARTY_PLUGIN_DIR.'/function.get_children.php');
300 smarty_function_get_children(
301 array('orderby' => 'desc', 'orderby_type' => 'time'), $smarty);
302 $_items = $smarty->get_template_vars('get_children');
303 }
304
305 foreach ($_items as $_item)
306 {
82765da6 307 $item = new FeedItem();
51ff3226 308 $item->title = $_item['node_name'];
b6e35197 309 $item->link = "http://".SYSTEM_URL."/id/".$_item['node_id'];
51ff3226 310 $item->description = $_item['node_content'];
311 $rss->addItem($item);
312 }
313 }
314
315 if ($permissions['r']) $rss->showFeed($_feedType);
316 exit();
317}
318
319_checkPermissions();
320
321//entering the node
322
323//sventest
324if (($permissions['r']) || ($event != 'register')) {
325
5b9c0808 326 //performing node_events (based on update/insert/delete db queries)
327 if ($event) {
328 require(INCLUDE_DIR.'eventz.inc');
329 }
51ff3226 330
5e60ef4b 331 /* broken
5b9c0808 332 elseif ($transaction) {
333 require(INCLUDE_DIR.'transaction.inc');
334 }
5e60ef4b 335 */
5b9c0808 336 //end of performing node events
51ff3226 337
5b9c0808 338 //sventest
51ff3226 339}
340
341
342if ($permissions['r']) {
343
5b9c0808 344// these 4 lines are not the source of kyberia lagging problems.
345// leave them. started on the 10.4.
346// data gained will be used for scientific purposes
347
348// if (isset($_SESSION['user_id']) {
349// log_levenshtein($_SESSION['user_id'],$node['node_id']);
350// }
351
d9464c68 352if ((isset($_SESSION['user_id'])) && ($_SESSION['user_id'])) {
51ff3226 353 $q="insert delayed into levenshtein set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."'";
354 $db->update($q);
355}
356
357//if node is css
5b9c0808 358//XXX into function
51ff3226 359if ($node['template_id']!='2019721'){
360
fd15ea3a 361 logger::log('enter',$node['node_id'],'ok',$node['node_user_subchild_count']);
51ff3226 362 if (!empty($_SESSION['user_id']) && is_numeric($node['node_id'])) {
363 $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']."'";
364// echo $q;
365 $result=$db->update($q);
366
367 if (!$result) {
368 $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()";
369 $db->query($q);
5b9c0808 370 }
371 }//end of if node os css
51ff3226 372}
373
5b9c0808 374}
375
376//XXX into function
377// if (isset($_SESSION['user_id']) {
378// if (isset($referer_id)) {
379// update_nodes($_SESSION['user_id'],$node['node_id'],$referer_id);
380// } else {
381// update_nodes($_SESSION['user_id'],$node['node_id'],0);
382// }
383// }
51ff3226 384
51ff3226 385// DO NOT MESS WITH THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
386//creating neural network
387$db->update("update nodes set node_views=node_views+1 where node_id='".$node['node_id']."'");
202718bc 388if (isset($referer_id) && is_numeric($referer_id)) {
51ff3226 389 $q="update neurons set synapse=synapse+1 where dst='".$node['node_id']."' and src='$referer_id'";
390 $result=$db->update($q);
391 if (!$result) {
392 $q="insert into neurons set synapse_creator='".$_SESSION['user_id']."',dst='".$node['node_id']."',src='$referer_id',synapse=1";
393 $db->query($q);
394 }
395}
396
397
398elseif (!$permissions['r'] && $_GET['magic_word']) {
399 $magic_word_big=$_GET['magic_word'];
400
401 if ( preg_match("/(\d+)-(.+)/",$_GET['magic_word'],$mu)) {
402 $magic_uid=$mu['1'];
403 $magic_word=addslashes($mu['2']);
5b9c0808 404 // XXX WTF column magic_word does not exists
51ff3226 405 $q="select login from users where user_id='$magic_uid' and magic_word='$magic_word'";
406 $set=$db->query($q);
407 if ($set->getNumRows()) {
408 $permissions['r']=true;
409 }
410 }
411}
412
413
414
415
416
417else {
fd15ea3a 418 logger::log('enter',$node['node_id'],'failed');
51ff3226 419}
420
421
422
423//assigning user data to smarty if user logged in
58a9d5d7 424if (isset($_SESSION['user_id'])&&($user_id=$_SESSION['user_id'])) {
51ff3226 425 $smarty->assign('_POST',$_POST);
426 $smarty->assign('bookmarks',$_SESSION['bookmarks']);
427 $smarty->assign('ignore',$_SESSION['ignore']);
428 $smarty->assign('bookstyl',$_SESSION['bookstyl']);
429 $smarty->assign('fook',$_SESSION['fook']);
430 $smarty->assign('user_id',$_SESSION['user_id']);
7fb8c265 431 $smarty->assign('user_name',$_SESSION['user_name']);
9a7d7230 432 if (!empty($_SESSION['cube_vector']))
433 $smarty->assign('cube_vector',$_SESSION['cube_vector']);
51ff3226 434 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
435 $smarty->assign('user_quota',$_SESSION['user_quota']);
9a7d7230 436
5b9c0808 437 // XXX into function
9a7d7230 438 $newmail_q = sprintf('select u.user_mail_id
439 , u.user_k
440 , u.k_wallet
441 , u.user_mail
442 , ms.user_id as mail_sender_id
443 , ms.login as mail_sender
444 from users u
445 left join users ms on ms.user_id = u.user_mail_id
446 where u.user_id = %d',
447 $user_id);
448 $newmailset = $db->query($newmail_q);
449
9a7d7230 450
51ff3226 451 $newmailset->next();
452 $new_mail=$newmailset->getString('user_mail');
5b9c0808 453 // XXX into function
51ff3226 454 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
455 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
456 $newmailset2->next();
457 $smarty->assign('new_mail',$new_mail);
9a7d7230 458 $smarty->assign('new_mail_name',$newmailset->getString('mail_sender'));
51ff3226 459 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
460 $user_k=$newmailset->getString('user_k');
461 $smarty->assign('user_k',$user_k);
462 $k_wallet=$newmailset->getString('k_wallet');
463 $smarty->assign('k_wallet',$k_wallet);
464 $user_id=$_SESSION['user_id'];
465
466 //mail node
467 if ($node['node_name']=='mail') {
468
469 //clear new mail message
5b9c0808 470
51ff3226 471 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
472
473 //set messages as delivered to recipient
474 $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'");
475 while($set->next()) {
476 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
477 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
478
479 $new_messages[$set->getString('mail_id')]=true;
480 }
481/*
482 if (count($new_messages)) {
483 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
484 $smarty->assign('new_messages',$new_messages);
485
486 }
487*/
488 }
489}
490
491
492
493if ($node['node_system_access']=='crypto') {
494 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
495}
496
51ff3226 497$smarty->assign('error',$error);
498$smarty->assign('permissions',$permissions);
499$smarty->assign('current_vector',$node['node_vector']);
d4ac6b36
H
500if ($permissions['r']) {
501 $smarty->assign('node',$node);
502 $smarty->assign('node_json',json_encode($node));
503}
51ff3226 504else {
505
506 $smarty->assign('node',$node);
507 //new templates by Dark matter
508 $smarty->template_dir=OWN_TEMPLATE_DIR;
509
00be2b5c
H
510 $smarty->display('1549864.tpl');
511 $smarty->display('1549885.tpl');
512 $smarty->display('630526.tpl');
51ff3226 513 die();
514
515 //redirect to mainpage
516// looks like poeple totaly hate this redirect!
517// header("Location: /id/1");
518}
519
520
5b9c0808 521// XXX into function
58a9d5d7 522if (($node['template_id']!='2019721') && (isset($_SESSION['user_id']))){
51ff3226 523//setting user location
524$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']."'";
525$db->executequery($q);
526}
527
528$whole_time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
529$smarty->assign('whole_time',$whole_time);
530
531
532if ($template_id=='download' OR $template_id=='download.jpg') {
533 if ($permissions['r']) {
534 $linkname = SYSTEM_ROOT."/files/".$node['node_id'];
535 $filename= readlink($linkname);
536 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
537
538 $ext = substr( $filename,-3 );
539 if( $filename == "" ) {
540 echo "ERROR: Empty file to download. ";
541 exit;
542 } elseif ( ! file_exists( $filename ) ) {
543 exit;
544 };
545 switch( strtolower($ext) ){
546 case "pdf": $ctype="application/pdf"; break;
547 case "exe": $ctype="application/octet-stream"; break;
548 case "zip": $ctype="application/zip"; break;
549 case "doc": $ctype="application/msword"; break;
550 case "xls": $ctype="application/vnd.ms-excel"; break;
551 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
552 case "gif": $ctype="image/gif"; break;
553 case "png": $ctype="image/png"; break;
554 case "jpg": $ctype="image/jpg"; break;
555 default: $ctype="application/force-download";
556 }
557 $file=str_replace(" ","_",$node['node_name']).".$ext";
558 header("Pragma: public");
559 header("Expires: 0");
560 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
561 header("Content-Type: $ctype");
562 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
563 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
564 (strpos($user_agent, "win")))) {
565 header( "Content-Disposition: filename=$file;" );
566 } else {
567 header( "Content-Disposition: attachment;
568 filename=$file;" );
569 }
570 header("Content-Transfer-Encoding: binary");
571 header("Content-Length: ".filesize($filename));
572 readfile("$filename");
573 exit();
574 }
575 else { echo "you don't have permissions for downloading this data"; die(); }
576}
577
578if ($node['template_id']=='2019721'){
579Header("Cache-control: max-age=3600");
580}else{
581Header("Cache-control: no-cache");
582Header("Expires:".gmdate("D, d M Y H:i:s")." GMT");
583header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
584}
585
586
587//for cases like search & preview
588 $smarty->assign('post_vars',$_POST);
589if (!empty($_POST['template_event'])) {
590 $smarty->assign('template_event',$_POST['template_event']);
591
592}
593
594//setting listing parameters
595 $children_count=$node['node_children_count'];
596 $descendant_count=$node['node_descendant_count'];
597
202718bc 598 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
599 $listing_amount=mysql_real_escape_string($_POST['listing_amount']);
600 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
51ff3226 601 else $listing_amount=DEFAULT_LISTING_AMOUNT;
602 $smarty->assign('listing_amount',$listing_amount);
603
202718bc 604 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
605 $listing_order=mysql_real_escape_string($_POST['listing_order']);
606 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
51ff3226 607 else $listing_order=DEFAULT_LISTING_ORDER;
608 $smarty->assign('listing_order',$listing_order);
609
202718bc 610 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
611 $offset=$_POST['get_children_offset'];
612 } else { $offset=0; }
51ff3226 613
614
615 //movement forward and backward
616// if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
617
618 if ($_POST['get_children_move']=='<') {
619 $offset=$offset-$listing_amount;
620 if ($offset<0) $offset=0;
621 }
622 elseif ($_POST['get_children_move']=='>') {
623 $offset=$offset+$listing_amount;
624 }
625 elseif ($_POST['get_children_move']=='>>') {
626 $offset=$descendant_count-$listing_amount;
627 }
628
629 elseif ($_POST['get_children_move']=='<<') {
630 $offset=0;
631 }
632 if ($offset<0) $offset=0;
633 $_POST['offset']=$offset;
634 $smarty->assign('offset',$offset);
635
636
637if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
638 header("Content-Type: image/svg+xml");
639}
640
641//show own header
58a9d5d7 642elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
51ff3226 643 $smarty->assign('header_id',$_SESSION['header_id']);
644 $smarty->template_dir=OWN_TEMPLATE_DIR;
00be2b5c 645 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
51ff3226 646 $smarty->template_dir = TEMPLATE_DIR.TEMPLATE_SET;
647 //not registered user
648 if ($_SESSION['header_id']==2091520) {
649 echo $content;
650 session_destroy();
651 die();
652 }
653}
654
655$smarty->template_dir=OWN_TEMPLATE_DIR;
656
657if (is_numeric($template_id)) {
00be2b5c 658 $content.=$smarty->fetch($template_id.".tpl");
51ff3226 659}
660
661else {
662 $template_id=$node['template_id'];
00be2b5c 663 $content.=$smarty->fetch($node['template_id'].".tpl");
51ff3226 664}
665
666if ($template_id=='2019721'){
00be2b5c 667 $content=$smarty->fetch($template_id.".tpl");
51ff3226 668 echo $content;
669}else{
670 $time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
671 echo $content;
672// echo "<center>page generation took: $time second</center>";
673}
674//end of displaying
675
676// output buffering forcing (mx)
677if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_end_flush();
678
679?>
This page took 0.703663 seconds and 4 git commands to generate.