-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
172 lines (134 loc) · 4.33 KB
/
index.php
File metadata and controls
172 lines (134 loc) · 4.33 KB
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
<?php
include '_include.php';
// initialize CMS
TznCms::init(0, true); //public page, autoload modules
// site under maintenance
if ($GLOBALS['objCms']->settings->get('maintenance') && (!$GLOBALS['objUser']->hasAccess(3))) {
$objCms->errorPage('maintenance');
}
// load requested page
$GLOBALS['objPage'] = new TznPage();
/*
echo '<pre>';
print_r($_GET);
echo '</pre>';
// exit;
*/
if ($_GET['content']) {
$objContent = new CmsObjectPage();
$shortcut = TznUtils::sanitize(TZN_SANITIZE_SIMPLE, $_REQUEST['content']);
if ($objContent->loadByKey('shortcut',$shortcut)) {
$objPage = $objContent->page;
$objPage->_loaded = true;
$_REQUEST['item'] = $objContent->id;
}
} else if ($_GET['title']) {
$shortcut = TznUtils::sanitize(TZN_SANITIZE_SIMPLE, $_GET['title']);
$objPage->loadByKey('shortcut',$shortcut);
} else if ($id = intval($_REQUEST['page'])) {
$objPage->loadByKey('id',$id);
} else {
$req = trim($_SERVER['REQUEST_URI'],'/');
if ($req) {
if ($pos = strrpos($_SERVER['REQUEST_URI'],'.html')) {
$req = substr($req, 0, $pos-1);
} else if ($pos = strrpos($_SERVER['REQUEST_URI'],'?')) {
$req = substr($req, 0, $pos-1);
}
$GLOBALS['arrReqPrm'] = explode('/',$req);
if ($GLOBALS['arrReqPrm'][1]) {
$objContent = new CmsObjectPage();
if ($objContent->loadByKey('shortcut',$GLOBALS['arrReqPrm'][1])) {
$objPage = $objContent->page;
$objPage->_loaded = true;
$_REQUEST['item'] = $objContent->id;
}
}
if (!$objPage->isLoaded()) {
$objPage->loadByKey('shortcut',$GLOBALS['arrReqPrm'][0]);
}
} else {
$objPage->loadFirstPage();
}
}
// requested page not found
if (!$objPage->isLoaded()) {
$objCms->errorPage('404');
}
// page is section -> load sub page
if (!$objPage->module) {
$objPageParent = $objPage->clone4();
$objPage = $objPageParent->loadChildWithModule();
}
// --- Module check --------------------
if (!$objPage || !$objPage->isLoaded()) {
// page not found
$objCms->errorPage('404');
}
if (!$objPage->module) {
// still no module page or no children defined
$objCms->errorPage('404');
}
// --- Private pages: check access ----
if (!$objPage->canAccess()) {
// visitor does not have access, show error message
$objCms->errorPage('403');
}
// --- Page not published (and no access) ---
if (!$objPage->display) {
if ($GLOBALS['objUser']->hasAccess(3)) {
TznUtils::addMessage('Attention: cette page n\'est pas publiée!');
} else {
$objCms->errorPage('unpublished');
}
}
// -- Everything's fine, let's show the page ------------
// --- Define Template --------------------------------------------------
if (!$objPage->template) {
$objPage->template = $objCms->settings->get('default_template');
}
define ('CMS_TEMPLATE',$objPage->template);
// Referrer
TznUtils::setReferrer();
if (@constant('CMS_ADMIN')) {
$GLOBALS['objHeaders']->add('jsScript', array('mootools-1.2.4.js','common.js'));
} else if (CMS_MOOTOOLS) {
$GLOBALS['objHeaders']->add('jsScript', 'mootools-1.2.4.js');
}
// --- template initialization --------
if (file_exists(CMS_TEMPLATE_PATH.$objPage->template.'/init.php')) {
include CMS_TEMPLATE_PATH.$objPage->template.'/init.php';
}
// --- module initialization ----------
if ($objPage->module) {
$objModule = $GLOBALS['objCms']->getModuleObject($objPage->module);
if (!$objModule) {
TznCms::errorFatal('module '.$objPage->module.' does not exist or is not enabled'); //-TODO- translate
}
// call module init method
$notyet = true;
if ($_REQUEST['action']) {
$method = 'public'.ucFirst($_REQUEST['action']);
if (preg_match('/^[a-z0-9_\-]*$/i', $method) && method_exists($objModule, $method)) {
$objModule->$method();
$notyet = false;
}
}
if ($notyet && method_exists($objModule, 'publicDefault')) {
$objModule->publicDefault();
}
}
// --- more template stuff ------------
if (file_exists(CMS_TEMPLATE_PATH.$objPage->template.'/core.php')) {
include CMS_TEMPLATE_PATH.$objPage->template.'/core.php';
}
// --- HTML Header --------------------
TznCms::getHeader();
// --- template body ------------------
if (file_exists(CMS_TEMPLATE_PATH.$objPage->template.'/body.php')) {
include CMS_TEMPLATE_PATH.$objPage->template.'/body.php';
} else if (file_exists(CMS_MODULE_PATH.$objPage->module.'/'.$objCms->pageToInclude)) {
include CMS_MODULE_PATH.$objPage->module.'/'.$objCms->pageToInclude;
}
// --- page footer --------------------
TznCms::getFooter();