forked from sauruscms/Saurus-CMS-Community-Edition
/
index.php
921 lines (741 loc) · 29.3 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
<?php
/**
* This source file is is part of Saurus CMS content management software.
* It is licensed under MPL 1.1 (http://www.opensource.org/licenses/mozilla1.1.php).
* Copyright (C) 2000-2010 Saurused Ltd (http://www.saurus.info/).
* Redistribution of this file must retain the above copyright notice.
*
* Please note that the original authors never thought this would turn out
* such a great piece of software when the work started using Perl in year 2000.
* Due to organic growth, you may find parts of the software being
* a bit (well maybe more than a bit) old fashioned and here's where you can help.
* Good luck and keep your open source minds open!
*
* @package SaurusCMS
* @copyright 2000-2010 Saurused Ltd (http://www.saurus.info/)
* @license Mozilla Public License 1.1 (http://www.opensource.org/licenses/mozilla1.1.php)
*
*/
##############################
# Main page
# : is independent script, not for including, new Site is generated
##############################
error_reporting(7);
global $site;
global $class_path;
global $CMS_SETTINGS;
global $forceRedirect;
preg_match('/\/(admin|editor)\//i', $_SERVER["REQUEST_URI"], $matches);
if ($matches[1]=="editor"){
$class_path = "../classes/";
$CMS_SETTINGS['cache_enabled'] = 0; # Cache: deny cache using for editor-area
} else {
$class_path = "./classes/";
$CMS_SETTINGS['cache_enabled'] = 1; # Cache: allow using cache for user-area
$CMS_SETTINGS['switch_lang_enabled'] = 1;
//ini_set('session.cache_limiter', 'private'); // cant be done, messes up reg users view and log in ifno is not available
}
#################################################
# Debug cookies
if ($_GET['debug'] == 'on')
{
setcookie ('debug', '1');
$_COOKIE['debug'] = 1;
}
else if ($_GET['debug'] == 'off')
{
setcookie ('debug', '0', time()-100000);
$_COOKIE['debug'] = 0;
}
$debug = $_COOKIE["debug"] ? 1:0;
################################
# Cache: URL parameter "speed_debug=on" displayes cache and speed info
if ($_GET["speed_debug"]=="on") {
setcookie ("speed_debug", "1");
$_COOKIE["speed_debug"] = 1;
} else if ($_GET["speed_debug"]=="off") {
setcookie ("speed_debug", "0", time()-100000);
$_COOKIE["speed_debug"] = 0;
}
$speed_debug = $_COOKIE["speed_debug"] ? 1:0;
####################################################################################
# BEGIN: Cache related stuff, PART 1
function mygetmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$startaeg = mygetmicrotime();
if ($CMS_SETTINGS['cache_enabled']) { # if we are using cache => go on
########################
# FUNCTION get_active_lang
# get active lang from session or from db; returns extension string; used for homepage
# $keel_ext = get_active_lang();
function get_active_lang(){
Global $CMS_SETTINGS, $DB, $site;
# a) at first search keel from session
if(isset($_SESSION['keel'])) {
#echo "FOUND SESSION KEEL:".$_SESSION['keel']['keel_id'];
$sql = $DB->prepare("SELECT extension FROM keel WHERE keel_id=?",$_SESSION['keel']['keel_id']);
$sth = new SQL($sql);
$keel_ext = $sth->fetchsingle();
}
# b) if not extension found at this point (either no session set or faulty value set)
# then get default keel
if(!$keel_ext){
$sql = $DB->prepare("SELECT extension FROM keel WHERE on_default=1");
$sth = new SQL($sql);
$keel_ext = $sth->fetchsingle();
}
return $keel_ext;
}
########################
# FUNCTION save_to_cache
# cache saving is done at the end of the page:
# save_to_cache(Array(
# 'data' => $cache_data,
# 'objekt_id' => $_GET['id'], # oldstyle
# 'url' => $site->fullself
# ));
function save_to_cache(){
Global $CMS_SETTINGS, $DB, $site;
$args = func_get_arg(0);
$url = $args['url'];
$nocache_ids = Array();
$nocache_ids = split(',', preg_replace("/\s+/","",$CMS_SETTINGS['dont_cache_objects']));
$CMS_SETTINGS['cache_inserted']=1; # inserted or not, mark as inserted anyway
########## SAVE if:
# - setting 'cache_not_found' is true (khm, what's that?)
# - parameter "data" found (is smth to save)
# - if POST values doesn't exist
if ($CMS_SETTINGS['cache_not_found'] && strlen($args['data'])>0 && !count($_POST)){
### 1. if parameter "objekt_id" (== URL parameter "id") found =>
# check if it's not in conf array 'dont_cache_objects'.
if( is_numeric($_GET['id']) && in_array($_GET['id'], $nocache_ids) ) {
# If found, dont save cache and exit function
return;
}
### 2. if NO URL PARAMETERS found OR URL parameter "id" not found => then we have page where we dont know language info,
# do some extra logic: add parameter "lang" automatically to the end of URL
if(!count($_GET) || !is_numeric($_GET['id']) && !isset($_GET['lang']) ) {
$keel_ext = get_active_lang(); # get keel from session or from db
## homepage
if(!count($_GET)) {
$url .= "?lang=".$keel_ext; # assign new URL
// don't cache homepage (ID:0)
if(in_array(0, $nocache_ids))
{
return;
}
}
## parameters found in URL
else {
$url .= "&lang=".$keel_ext; # assign new URL
}
}
// don't cache homepage (ID:0)
if(count($_GET) == 1 && $_GET['lang'] && in_array(0, $nocache_ids))
{
return;
}
$sql = $DB->prepare("INSERT INTO cache (aeg, sisu, objekt_id, url, site_id) VALUES (NOW(),?,?,?,".(is_numeric($args['site_id']) ? (int)$args['site_id'] : 'NULL').")", $args['data'], $args['objekt_id'], $url);
$sth = new SQL($sql);
$CMS_SETTINGS['cache_inserted']=2; # put '2', if actually inserted (for debug)
} # save cache to table
}
# / FUNCTION save_to_cache
########################
#####################
# Classes include, only some necessary classes:
include_once($class_path."timer.class.php");
if ($debug) {
include_once($class_path."debug.inc.php");
} else {
include_once($class_path."nodebug.inc.php");
}
include_once($class_path."config.class.php");
#####################
# Read config-file:
######## get absolute path of website root
$absolute_path = getcwd().'/';
# strip /admin|editor|classes/ from the end
if (preg_match("/(.*)\/(admin|editor|classes|temp|test)\/$/", $absolute_path, $matches) || preg_match("/(.*)\\\(admin|editor|classes|temp|test)\/$/", $absolute_path, $matches)) {
$absolute_path = $matches[1];
}
# add slash to the end
if (!preg_match("/\/$/",$absolute_path)) {$absolute_path .= "/"; }
####### read config.php
$file = $absolute_path."config.php";
# check if file config.php exists at all
if(!file_exists($file)) {
print "<font color=red>Error: file \"$file\" not found!</font>";
exit;
}
$fp = fopen($file, "r");
$config = new CONFIG(fread($fp, 1024*1024));
fclose($fp);
$dbconf = $config->CONF;
#############################################
# include database independent API functions:
include_once($class_path.$dbconf["dbtype"].".inc.php");
$DB = new DB(array(
host => $dbconf["dbhost"],
port => $dbconf["dbport"],
dbname => $dbconf["db"],
user => $dbconf["user"],
pass => $dbconf["passwd"],
'mysql_set_names' => $dbconf["mysql_set_names"],
));
if ($DB->error) { # Bug #2468
print "<font face=\"arial, verdana\" color=red>Error! Can't connect to database!</font>";
exit;
}
$sql = "SELECT nimi, sisu FROM config WHERE nimi IN ('cache_expired','dont_cache_objects','kasuta_ip_filter','display_errors_ip','save_error_log','hostname','wwwroot')";
$sth = new SQL($sql);
while ($tmpconf = $sth->fetch()){
$CMS_SETTINGS[$tmpconf['nimi']] = $tmpconf['sisu'];
}
define('DISPLAY_ERRORS_IP', $CMS_SETTINGS['display_errors_ip']);
define('SAVE_ERROR_LOG', $CMS_SETTINGS['save_error_log']);
session_start();
####################################
# USE CACHE, if:
# if allowed in config
# AND if no POST values found
# Cached page is saved into variable "$cache_data"
if (!count($_POST) && $CMS_SETTINGS['cache_expired']){
############ DISABLE CACHE, if:
# - we are in the after-login page (cookie "logged")
# - in the debug mode
# - if IP filter is used for users (1) or for both admin and users (3)
# - if no referer found (khm, why?) removed: " || !$_SERVER['HTTP_REFERER']"
# - if user is logged in (#2676)
if ($_COOKIE["logged"]==1 || $debug || ($CMS_SETTINGS['kasuta_ip_filter']==1 || $CMS_SETTINGS['kasuta_ip_filter']==3) || $_SESSION['user_id']) {
$CMS_SETTINGS['cache_enabled'] = 0;
}
if ($CMS_SETTINGS['cache_enabled']){ # we are actually using cache
#echo "<br><b>trying to use the cache</b><br>";
$url = $_SERVER["REQUEST_URI"];
### if NO URL PARAMETERS found OR URL parameter "id" not found => then we have page where we dont know language info,
# do some extra logic: add parameter "lang" automatically to the end of URL
if(!count($_GET) || !is_numeric($_GET['id']) && !isset($_GET['lang']) ) {
$keel_ext = get_active_lang(); # get keel from session or from db
## homepage
if(!count($_GET)) {
$url .= "?lang=".$keel_ext; # assign new URL
}
## parameters found in URL
else {
$url .= "&lang=".$keel_ext; # assign new URL
}
}
elseif (isset($_GET['lang']))
{
$sql = $DB->prepare("SELECT keel_id, encoding, extension, locale, glossary_id FROM keel WHERE extension=? LIMIT 1", $_GET['lang']);
$sth = new SQL($sql);
$_SESSION['keel'] = $sth->fetch();
}
# Bug #2407: Cache moodulis saab teha SQL injectionit
$sql = "SELECT aeg, sisu FROM cache WHERE url='".mysql_escape_string($url)."';";
$sth = new SQL($sql);
$cache = $sth->fetch();
$cache_data = $cache['sisu'];
if (1 && $sth->rows){
$CMS_SETTINGS['cache_found'] = 1;
} else {
$CMS_SETTINGS['cache_not_found'] = 1;
};
} # we are actually using cache
} # we try to use cache
} // if ($CMS_SETTINGS['cache_enabled'])
# Check (at the start of cms-engine) language of the given object and send it forward into $fdat[keel]
# -if cached data not found
# -if parameter "lang" or "keel" not found
# -if parameter "id" or "pg" found (GRR FIX IT - IT's BUG! 'pg' is in configuration and changable)
if ($CMS_SETTINGS['switch_lang_enabled'] && !$cache_data && !$_GET['lang'] && !$_GET['keel'] && (is_numeric($_GET['id']) || is_numeric($_GET['pg']))){
$myid = $_GET['id'] ? $_GET['id'] : $_GET['pg'];
$sql = "SELECT keel.extension FROM objekt LEFT JOIN keel ON keel.keel_id=objekt.keel WHERE objekt_id='".$myid."'";
$sth = new SQL($sql);
$mykeel = $sth->fetchsingle();
if ($mykeel){
# merle kommenteeris v�lja bug #2398:
# $_GET['keel'] = $mykeel;
}
}
##########################
# SHOW cached page or START SAVING cache info
######### 1. SHOW CACHED HTML
# If Cache was found, return screen-data from cache:
if ($CMS_SETTINGS['cache_found']){
echo $cache_data;
$cache_msg = " <b>Cache used!</b>";
} else {
if (!$CMS_SETTINGS['cache_inserted'] && $CMS_SETTINGS['cache_expired']){
ob_start();
}
# / END: Cache related stuff, PART 1
####################################################################################
#####################################
# Here will be content of site:
include_once($class_path."port.inc.php");
#################################################
# error_reporting
error_reporting(7);
#################################################
# create site and page
$site = new Site(array(
on_debug=>($debug ? 1 : 0),
));
######### PHP memory limit
# sets the maximum amount of memory in CONF["php_memory_limit"] Mbytes
# that a script is allowed to allocate
# if general value is smaller
if ( intval(ini_get('memory_limit')) < intval($site->CONF["php_memory_limit"]) ) {
ini_set ( "memory_limit", $site->CONF["php_memory_limit"]."M" );
}
# Kui keegi sisestas mitte numbriline id:
if ($site->fdat['id'] && !is_numeric($site->fdat['id'])){$site->fdat['id']=$site->alias("404error");}
if ( $site->fdat[rep_id]>0 ) {
$sql = $site->db->prepare("
SELECT objekt_id FROM objekt WHERE related_objekt_id = ?",
$site->fdat[rep_id]
);
$sth = new SQL($sql);
$site->debug->msg($sth->debug->get_msgs());
$site->fdat[id] = $sth->rows ? $sth->fetchsingle() : $site->alias("404error");
}
# if not admin tries to query system section (using URL or smth)
# show 404 error page instead
# WHY was it commented out before??
if ($site->fdat[id] == $site->alias("system") && !$site->in_editor) {
$site->fdat[id] = $site->alias("404error");
}
# create page
$leht = new Leht(array(
id => $site->fdat[id] ? $site->fdat[id] : $site->alias($site->sys_alias ? $site->sys_alias : 'rub_home_id'),
));
# / create site and page
#################################################
#################################################
# redirect to alias
if ($leht->objekt && $site->CONF['use_aliases'] && $site->CONF['redirect_to_alias'] && ($_SERVER['PHP_SELF'] != $site->wwwroot . '/map.php' || $forceRedirect) && !$site->in_editor) {
$variable = array();
foreach ($_GET as $k=>$v) {
if ($k != 'mod_rewrite' && $k != 'cmd') {
if (!($k == 'id' && is_numeric($v)) && !($k == 'lang' && $v != '')) {
$variable[] = $k . '=' . $v;
}
}
}
if (is_array($variable) && sizeof($variable) > 0) {
$qs = '?' . implode('&', $variable);
}
$sql1 = $site->db->prepare('SELECT site_url FROM keel WHERE keel_id = ?', $leht->objekt->all['keel']);
$sth1 = new SQL($sql1);
if (!($site_url = $sth1->fetchsingle())) {
$site_url = $site->CONF['hostname'];
}
$cmdArray = explode('/', $_GET['cmd']);
while (end($cmdArray) == '' && count($cmdArray) > 0) {
array_pop($cmdArray);
}
$aliasArray = explode('/', $leht->objekt->get_object_href());
while (end($aliasArray) == '' && count($aliasArray) > 0) {
array_pop($aliasArray);
}
// compare alias and redirect cmd. do not redirect if they are the same to prevent endless redirecting
if ((end($cmdArray) != end($aliasArray) || !is_numeric(end($cmdArray))) && !(count($cmdArray) == 0 && !$_GET['id'])) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $site_url . $leht->objekt->get_object_href() . $qs);
}
}
#
#################################################
#################################################
# find all parents
# m��ratakse kas objekt on avaldatud v�i mitte parentite p�hjal
if (!$leht->parents) {exit;}
$leht->level = 0;
$i = -1;
$myobj = $leht->parents->get($i++);
// get permssions
$perm = get_obj_permission(array(
"objekt_id" => $leht->id,
));
if (is_object($myobj)) {
while ( $myobj->objekt_id > 0 && $i<100 ){
# if trying to open existing, but not published object JA kui useril POLE �igust n�ha avaldamata objekte, then show 404 error page
if ($myobj->on_avaldatud == 0 && !$site->in_editor) {
$site->fdat['id'] = $site->alias("404error");
# If sys_artikkel 404error puudub, siis viskame esilehele (varem naitas tyhi ekraan):
if (!$site->fdat['id']){
header("Refresh: 0;url=".$site->CONF['wwwroot']."/?404"); // param ?404 - ainult infoks
exit;
}
$leht = new Leht(array(
id => $site->alias("404error"),
));
$site->debug->msg("Attempt to open existing, but not published object (ID ".$myobj->objekt_id.") => show 404 error page");
}
if (is_object($leht->parents)){
$myobj = $leht->parents->get($i++);
} else {
$i=101;
$site->fdat['id'] = $site->alias("404error");
# If sys_artikkel 404error puudub, siis viskame esilehele (varem naitas tyhi ekraan):
if (!$site->fdat['id']){
header("Refresh: 0;url=".$site->CONF['wwwroot']."/?404"); // param ?404 - ainult infoks
exit;
}
$leht = new Leht(array(
id => $site->alias("404error"),
));
}
# level-i leidmisel arvestakse ainult rubriikidega
if($myobj->all[klass] == "rubriik"){
$leht->level++;
}
}
$leht->level -= 1;
}
// kui on olemasolev objekt permissionid aga ei ole avaldatud bug #2740
elseif($perm['R'] && !$perm['is_visible'])
{
// 404
$site->fdat['id'] = $site->alias("404error");
# If sys_artikkel 404error puudub, siis viskame esilehele (varem naitas tyhi ekraan):
if (!$site->fdat['id']){
header("Refresh: 0;url=".$site->CONF['wwwroot']."/?404"); // param ?404 - ainult infoks
exit;
}
$leht = new Leht(array(
id => $site->alias("404error"),
));
$site->debug->msg("Attempt to open existing, but not published object (ID ".$myobj->objekt_id.") => show 404 error page");
}
# / find parents
#################################################
#################################################
# for error page send correct 404 header
if( $leht->objekt->on_404 ) {
if (isset($_ENV['REDIRECT_STATUS'])) { // compatible with php CGI-mode
header ("Status: 404 Not found");
} else {
header ("HTTP/1.1 404 Not found");
}
}
# for error page send correct 404 header
#################################################
#################################################
# Save Bookmark
if($site->fdat['op'] == "bookmark" && is_numeric($site->fdat['id'])) {
$site->user->toggle_favorite(array(
objekt_id => $site->fdat['id']
));
$site->user->load_favorites(true);
}
#################################################
# put to cookie "current_section"
if ($leht->objekt->all["klass"] == "rubriik") {
# current section
$myparent = $leht->parents->get(0);
# $leht->site->sess_save(array(current_section => $myparent->objekt_id));
}
else {
# parent section
$myparent = $leht->parents->get(1);
# $leht->site->sess_save(array(current_section => $myparent->objekt_id));
}
# POOLELI - bossu arvestamine v�ga madalas objektipuus
#print "minu boss on: ".$myparent->all[pealkiri]." (".$myparent->objekt_id.")";
if($myparent->all['klass'] == 'rubriik'){ # set cookie only if we have section
if (setcookie("current_section", $myparent->objekt_id, time()+1800, $site->CONF['wwwroot'] . "/")) {
$site->debug->msg("Put to cookies current_section: ".$myparent->objekt_id);
} else {
$site->debug->msg("CAN'T put to cookies current_section: ".$myparent->objekt_id."; possible reason - headers already have been sent");
}
#print "current section is:".$myparent->objekt_id. ' (class:'.$myparent->all['klass'].')';
}
# / put to cookie "current_section"
#################################################
#################################################
# syswords changing mode
if ( $site->fdat[mode]=="editsysword" ) {
if (setcookie ("mode", "editsysword","","/")){
#echo "<B>Panen cookie!</B>";
} else {
#echo "<FONT COLOR=red>headers already sent!</FONT>";
}
} else if ( $site->fdat[mode]=="noeditsysword" ) {
if (setcookie ("mode", "editsysword",time()-100000,"/")){
#echo "<B>Panen cookie!</B>";
} else {
#echo "<FONT COLOR=red>headers already sent!</FONT>";
}
}
# / syswords changing mode
#################################################
#################################################
# Gallup_id=1 cookie-sse:
if ($site->fdat[op]=="vote" && preg_match("/^\d+$/",$site->fdat[vastus]) && preg_match("/^\d+$/",$site->fdat[gallup_id]) && $site->CONF[gallup_ip_check]==2){
if (setcookie ("gallup[".$site->fdat[gallup_id]."]", "1", time()+15768000)){
#echo "<B>Panen cookie!</B>";
} else {
#echo "<FONT COLOR=red>headers already sent!</FONT>";
}
}
# / Gallup_id=1 cookie-sse:
#################################################
#### kontrolli kas install.php on kustutatud:
if ($site->in_editor || $site->in_admin) {
$site->security_check();
}
$site->debug->print_hash($site->fdat,0,"FDAT");
$REMOTE_ADDR = $_SERVER["REMOTE_ADDR"];
# featuur! Kui kasutaja klikib otsele m�nele keelatud lingile,
# mis n�uab sisselogimist, siis n�idata
# sisselogimise akent. Kui kasutaja on sisselogitud ja
# kui objekt on peidetud ja piiratud kasutajale
# siis n�idata 404 error page
##############################################################
####### check permissions
$perm = get_obj_permission(array(
"objekt_id" => $leht->id,
));
# kas useril on �igus objekti n�ha? 1/0
if (!$perm['R'] && !$leht->site->in_editor) {
if ($leht->site->user) {
# POOLELI in ver 4
# header("Location: ".$site->CONF['protocol'].$site->CONF['hostname'].$site->CONF['wwwroot']."?id=".$site->alias("404error"));
} else {
$leht->site->fdat[op] = "";
include_once($class_path."login_html.inc.php");
admin_login_form(array("site" => $site, "auth_error" => 0));
}
}
#$leht->parents->debug->print_msg();
#$leht->topmeny->debug->print_msg();
#$site->debug->print_hash($site->fdat,1,"FDAT");
#$leht->debug->print_msg();
##############################
# create template
$template = new Template($leht);
###########################
# 1. CONTENT TEMPLATE, kui master template on SAPI template
# tr�kkida: admin-header & page-html (kas parenti oma v�i master) & content-html
if(!$template->on_page_templ && $site->master_tpl['ttyyp_id']) {
#######################
# hoiame meeles sisumalli - see kutsutakse hiljem v�lja smarty tag-iga {print_content}
$content_template = $template;
$leht->content_template = &$content_template;
#######################
# 1. kui sisumall on m�tteliselt rubriigiga seotud
# (op = <empty>/ arhiiv) AND (op=<empty> AND otsi<>'') - v�listada otsingutulemuste mall
# siis kasutada �mbritsevaks malliks esimese parent-rubriigi malli
if(($site->fdat[op] == '' || $site->fdat[op] == 'arhiiv')
&& !$site->fdat[otsi]) {
#######################
# hakka otsima �mbritsevat page malli:
# k�igepealt vaadata, kas aktiivsel rubriigil endal on m��ratud page-mall
# kui on, siis v�tta see page-malliks
# kui rubriik, vaata ise-ennast
if($leht->objekt->all['klass'] == 'rubriik') {
$i = 0;
}
# kui muu objekt, otsi parent rubriik
else {
$i = 1;
}
$par = $leht->parents->get($i);
$page_ttyyp_id = $par->all[page_ttyyp_id];
#### kui parent on artikkel (e vaadatakse alamartiklit),
# siis leia �lem-artikli parent RUBRIIK ja v�tta selle mall (bug #966)
if ($par->all[tyyp_id] == 2){
$par = $leht->parents->get(2);
$page_ttyyp_id = $par->all[page_ttyyp_id];
# kui endiselt on parent artikkel => j�tka
if ($par->all[tyyp_id] == 2){
$par = $leht->parents->get(3);
$page_ttyyp_id = $par->all[page_ttyyp_id];
}
}
# Evgeny: et n�idata ekraanil s�steem-artiklid, otsime esialgu s�steemrubriigi mall,
# ja kui see defineeritud, siis kasutame seda:
if ($leht->objekt->all['klass']=='artikkel' && $leht->objekt->all['parent_id']==$site->alias("system")){
# leia s�steemirubriigi objekt
$system_obj = new Objekt(array(
objekt_id => $site->alias("system")
));
# kui s�steemirubriigil on mall m��ratud, siis kasuta seda �mbritsevaks malliks
if ($system_obj->all['page_ttyyp_id']){
$page_ttyyp_id = $system_obj->all['page_ttyyp_id'];
$template->debug->msg("Page mall: S�steemi artikkel on fookuses. S�steemi rubriigil on defineeritud mall ja me kasutame seda: ID=".$page_ttyyp_id);
}
};
# kui ei objektile endal ei olenud page-malli m��ratud,
# siis kasutada saidi p�himalli
if(!$page_ttyyp_id) {
$page_ttyyp_id = $site->master_tpl['ttyyp_id'];
$template->debug->msg("Page mall: Objekti enda page-mall oli t�hi, kasutan saidi p�himalli: ID=".$page_ttyyp_id);
}
else {
$template->debug->msg("Page mall: Kasutan objekti enda page-malli: ID=".$page_ttyyp_id. ", Parent ID=".$par->objekt_id);
}
# erijuht: kui objekt on teema v�i kommentaar (foorum)
# JA mall on ette antud URL-il (&tpl=..),
# siis mitte panna page-malliks �sjaleitud malli, sest mall antakse ette malli html-is
if ($leht->objekt->all[klass] == "teema" && $site->fdat[tpl]) {
$template->debug->msg("Page mall: Kuna tegu teemaga ja kasutatud URL-il 'tpl' parameetrit, ignoreerin leitud page-malli");
}
# tavajuht:
else {
##########################
# CONTENT mall debug
# enne page malli tegemist printida content malli debug v�lja
$template->debug->print_msg();
###########################
# TEE PAGE mall
# POOLELI: igaks juhuks kontrollida, et �mbritsev mall poleks tegelikult content tyypi //
# kui mall on d�naamiline (id >= 1000), siis j�tka ja tee mall ID p�hjal
if ($page_ttyyp_id >= 1000 ) {
$template = new Template($leht, '', $page_ttyyp_id);
}
# kui mall on mingil p�hjusel fix mall,
# siis ignoreerida fix-malli ja kasutada �mbriseks home d�n.malli
else {
$template = new Template($leht, '', $site->master_tpl['ttyyp_id']);
$template->debug->msg("Page mall: Kuna parenti mall oli fix-sisumall (ID=".$page_ttyyp_id."), ignoreerisin seda ja kasutasin saidi p�himalli: ".$template->fail);
}
# / TEE PAGE mall
###########################
} # if objekti t��p on teema v�i mingi muu
}
#######################
# 2. kui sisumall on �ldine eritemplate
# op = tappisotsing/ kaart/ error/ register/ gallup-arhiiv
# siis kasutada �mbritsevaks malliks master malli
else if ( $site->fdat["op"] != 'print'){
#####################
# erijuht: aga kui URLi peal on mall ette antud (&tpl=<malli ID>),
# siis miks mitte kasutada seda lehemallina :)
if($site->fdat[tpl] != '' && is_numeric($site->fdat[tpl])) {
$page_ttyyp_id = $site->fdat[tpl];
$template->debug->msg("Page mall: Kuna mall on URL-is antud, siis kasutan seda malli: ID=".$page_ttyyp_id);
}
####################
# tavajuht: kasuta erimallide jaoks p�himalli
else {
$page_ttyyp_id = $site->master_tpl['ttyyp_id'];
$template->debug->msg("Page mall: Kuna sisumall on erimall, kasutan saidi p�himalli: ID=".$page_ttyyp_id);
}
##########################
# CONTENT mall debug
# enne uue malli tegemist printida vana malli debug v�lja
$template->debug->print_msg();
###########################
# TEE PAGE mall
# tee mall ID p�hjal
$template = new Template($leht, '', $page_ttyyp_id);
# / TEE PAGE mall
###########################
}
#######################
# 3. kui sisumall on print template
# op = print
# siis tr�kkida default html-head, sest stiile on ju vaja
else {
?>
<html>
<head>
<title><?=$leht->meta[title] ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$site->encoding ?>">
<meta http-equiv="Cache-Control" content="no-cache">
<meta name="Author" content="SAURUS - www.saurus.info">
<meta name="keywords" content="<?=$leht->meta[keywords] ?>">
<meta name="description" content="<?=$leht->meta[description] ?>">
<link rel="stylesheet" href="<?=$leht->site->CONF[wwwroot] ?>/styles.php">
<?
}
# / kui sisumall on ..
#######################
# =========================
# template
# =========================
$template->print_text();
}
# / 1. CONTENT TEMPLATE, kui master template on SAPI template
###########################
###########################
# 2. PAGE TEMPLATE (html)
# page mall, siis tr�kkida: # admin-header & html
else {
# =========================
# template
# =========================
$template->print_text();
}
# / 2. PAGE TEMPLATE (html)
###################
###########################
# debug info
$site->debug->msg("SQL p�ringute arv = ".$site->db->sql_count."; aeg = ".$site->db->sql_aeg);
$site->debug->msg("T��AEG = ".$site->timer->get_aeg());
if(is_object($template)){
$template->debug->print_msg();
}
if($content_template){
$content_template->debug->print_msg();
}
# user debug:
if($site->user) { $site->user->debug->print_msg(); }
# guest debug:
if($site->guest) { $site->guest->debug->print_msg(); }
$site->debug->print_msg();
#$menyy->debug->print_msg();
$leht->parents->debug->print_msg();
#$leht->debug->print_msg();
$site->db->debug->print_msg();
# / debug info
###########################
# / Here will be content of site
#####################################
####################################################################################
# BEGIN: Cache related stuff, PART 2
# Hidden feature: remove object from cache, if 'nocache' parameter found in URL
if ($site->fdat['nocache'] && is_numeric($site->fdat['id'])){
$sql = $site->db->prepare("DELETE FROM cache WHERE objekt_id=?", $site->fdat['id']);
$sth = new SQL($sql);
$site->debug->msg($sth->debug->get_msgs());
}
##############################################
# If vead on nahtav, siis ei salvesta cache!
if (!$CMS_SETTINGS['cache_inserted'] && $CMS_SETTINGS['cache_expired'] && $CMS_SETTINGS['cache_enabled'] /*&& is_numeric($_GET['id'])*/){
$cache_data = ob_get_contents();
ob_end_clean();
if ($cache_data){ # if found smth to save
save_to_cache(Array(
'data' => $cache_data,
'objekt_id' => $_GET['id'], # oldstyle, optional
'url' => $site->fullself,
'site_id' => $leht->objekt->all['keel'],
));
}
}
############## PRINT CACHE to screen:
echo $cache_data;
} # / 2. OR START saving page info
# / SHOW cached page or START SAVING cache info
##########################
##########################
# SHOW "speed_debug" message
if ($speed_debug){
$loppaeg = mygetmicrotime();
$itog = $loppaeg-$startaeg;
$sth = new SQL("SELECT count(*) FROM cache");
$total_in_cache = $sth->fetchsingle();
echo "<hr size=1> <center><font face=Verdana size=2 color=black>Page was generated in ".number_format($itog, 5, ".", " ")." seconds. ".$cache_msg.($CMS_SETTINGS['cache_inserted']==2 ? "<b>Saved to cache!</b>":"");
echo (( ($CMS_SETTINGS['kasuta_ip_filter']==1 || $CMS_SETTINGS['kasuta_ip_filter']==3) && $CMS_SETTINGS['cache_expired']) ? "<br><b>IP Filter for users enabled. Cache skipped!</b>":"");
echo "<br>Total cached objects: ".$total_in_cache."; Queries: ".($site->db->sql_count-1)."</font></center>"; // (sql_count-1), because 1 query used for speed_debug
flush();
}
# / END: Cache related stuff, PART 2
####################################################################################