/
node.php
317 lines (219 loc) · 8.73 KB
/
node.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
<?php
/**
* Copyright (c) 2005-2014 Laposa Ltd (http://laposa.co.uk)
* Licensed under the New BSD License. See the file LICENSE.txt for details.
*
*/
class Onxshop_Controller_Node extends Onxshop_Controller {
/**
* main action
*/
public function mainAction() {
if ($this->processNode()) return true;
else return false;
}
/**
* process node
*/
public function processNode() {
/**
* check node id value
*/
if (!is_numeric($this->GET['id'])) {
msg("Node.processNode(): id is not numeric", 'error');
return false;
} else {
$node_id = $this->GET['id'];
}
/**
* initialize
*/
require_once('models/common/common_node.php');
$this->Node = new common_node();
$node_data = $this->Node->nodeDetail($node_id);
if (!is_array($node_data)) {
msg("Node ID {$node_id} does not exists", 'error');
return false;
}
$source = $node_data;
$this->temp['node_group'] = $node_data['node_group'];
/**
* Initialise node configuration overwrites
*/
$global_conf_node_overwrites = $this->initGlobalNodeConfigurationOverwrites($node_id );
/**
* merge
*/
$GLOBALS['onxshop_conf'] = $this->array_replace_recursive($GLOBALS['onxshop_conf'], $global_conf_node_overwrites);
/**
* check if page is published, but keep it available in edit mode
*/
if ($node_data['publish'] == 0 && $node_data['node_group'] == 'page' && !Onxshop_Bo_Authentication::getInstance()->isAuthenticated()) {
// display 404 page
$_Onxshop_Request = new Onxshop_Request('node~id=' . $this->Node->conf['id_map-404'].'~');
$node_data['content'] = $_Onxshop_Request->getContent();
$this->tpl->assign('NODE', $node_data);
return true;
}
/**
* force login
*/
if ($node_data['require_login'] == 1 && $_SESSION['client']['customer']['id'] == 0) {
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
if ($parsed_url['query']) $_SESSION['to'] = "page/{$node_id}?{$parsed_url['query']}";
else $_SESSION['to'] = "page/{$node_id}";
onxshopGoTo("page/" . $this->Node->conf['id_map-login']);//will exit immediatelly
}
/**
* force SSL
*/
if ($node_data['require_ssl'] == 1) {
if (!($_SERVER['SSL_PROTOCOL'] || $_SERVER['HTTPS']) && ONXSHOP_CUSTOMER_USE_SSL) {
//don't exit in this case, just say "next time use SSL"
header("Location: https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}");
}
}
/**
* check if template file exists in ONXSHOP_DIR or in ONXSHOP_PROJECT_DIR
*/
$template_path = "node/{$node_data['node_group']}/{$node_data['node_controller']}";
$template_file_path = "templates/{$template_path}.html";
if (file_exists(ONXSHOP_DIR . $template_file_path) || file_exists(ONXSHOP_PROJECT_DIR . $template_file_path)) {
$template = $template_path;
} else {
msg("missing $template_file_path", 'error', 1);
//fallback to default
$template = "node/{$node_data['node_group']}/default";
}
/**
* check if controller exits
*/
$controller_path = $template_path; //try the same filename as for the template
$controller_file_path = "controllers/{$controller_path}.php";
if (file_exists(ONXSHOP_DIR . $controller_file_path) || file_exists(ONXSHOP_PROJECT_DIR . $controller_file_path)) {
$controller = $controller_path;
} else {
//fallback to default
$controller = "node/{$node_data['node_group']}/default";
}
/**
* check if we need to use default_controller@specic_template
*/
if ($template == $controller) $controller_request = $template;
else $controller_request = "{$controller}@{$template}";
/**
* process controller referred from this node
*/
msg("Node process: $controller", 'ok', 2);
$_Onxshop_Request = new Onxshop_Request("$controller_request&id={$node_data['id']}&parent_id={$node_data['parent']}");
$node_data['content'] = $_Onxshop_Request->getContent();
/**
* add extra_css_class
*/
$node_data['extra_css_class'] = '';
if (trim($node_data['css_class']) != '') {
$css_classes = explode(" ", $node_data['css_class']);
foreach ($css_classes as $css_class_item) {
$node_data['extra_css_class'] .= "node-$css_class_item ";
}
}
/**
* check visibility and than display
*/
if ($node_visibility = $this->checkVisibility($node_data)) {
if ($this->_checkPermissionForExtraCSS($node_data)) {
//TODO: add and icon with status
// we cannot add this css_class to normal node.css_class, because of inheritance
if ($node_data['display_permission'] == 1) $node_data['extra_css_class'] = $node_data['extra_css_class'] . ' show_at_normal_login';
else if ($node_data['display_permission'] == 2) $node_data['extra_css_class'] = $node_data['extra_css_class'] . ' hide_at_normal_login';
else if ($node_data['display_permission'] == 3) $node_data['extra_css_class'] = $node_data['extra_css_class'] . ' show_at_trade_login';
else if ($node_data['display_permission'] == 4) $node_data['extra_css_class'] = $node_data['extra_css_class'] . ' hide_at_trade_login';
if (is_array($node_data['display_permission_group_acl'])) $node_data['extra_css_class'] = $node_data['extra_css_class'] . ' acl_in_use';
if ($node_data['publish'] == 0) $node_data['extra_css_class'] = $node_data['extra_css_class'] . ' not_public';
}
$this->tpl->assign("NODE", $node_data);
}
/**
* front-end node edit and node move (sort) icons
* node add are inserted in controller/node/default
*/
// don't show edit icons when shared parameter is 1 (passed from shared content)
// and not authenticated for the backend
if ($this->GET['shared'] == 0 && Onxshop_Bo_Authentication::getInstance()->isAuthenticated()) {
if ($node_data['node_group'] == 'content' && $_SESSION['fe_edit_mode'] == 'edit') {
if ($node_data['node_controller'] == 'shared') {
$this->tpl->assign("SOURCE", $source);
$this->tpl->parse('content.wrapper.fe_edit.edit_source');
}
$this->tpl->parse('content.wrapper.fe_edit');
} else if ($node_data['node_group'] == 'layout' && $_SESSION['fe_edit_mode'] == 'edit') {
if ($node_data['node_controller'] == 'shared') {
$this->tpl->parse('content.wrapper.fe_layout_property.edit_shared');
}
$this->tpl->parse('content.wrapper.fe_layout_property');
//$this->tpl->parse('content.wrapper.layout_add');
} else if ($node_data['node_group'] == 'page' && $_SESSION['fe_edit_mode'] == 'edit') {
$this->tpl->parse('content.wrapper.fe_page_properties');
}
}
if ($node_visibility) $this->tpl->parse('content.wrapper');
return true;
}
/**
* checkVisibility
*/
public function checkVisibility($node_data) {
$visibility = false;
//force visibility for admin, only when in edit or preview mode
if ($_SESSION['fe_edit_mode'] == 'edit' || $_SESSION['fe_edit_mode'] == 'move') $force_admin_visibility = true;
else $force_admin_visibility = false;
/**
* CONDITIONAL DISPLAY OPTION BY display_permission
*/
if ($this->Node->checkDisplayPermission($node_data, $force_admin_visibility)) {
//don't display hidden node in preview mode
if ($node_data['publish'] == 0 && Onxshop_Bo_Authentication::getInstance()->isAuthenticated() && $_SESSION['fe_edit_mode'] == 'preview' ) $visibility1 = false;
else $visibility1 = true;
}
/**
* check permission from group_acl
*/
if ($this->Node->checkDisplayPermissionGroupAcl($node_data, $force_admin_visibility)) {
$visibility2 = true;
} else {
$visibility2 = false;
}
if ($visibility1 && $visibility2) return true;
else return false;
}
/**
* check if add CSS highlight
*/
public function _checkPermissionForExtraCSS($node_data) {
//add css class when when logged in and using edit or move mode
if (Onxshop_Bo_Authentication::getInstance()->isAuthenticated() && ($_SESSION['fe_edit_mode'] == 'edit' || $_SESSION['fe_edit_mode'] == 'move')) return true;
else return false;
}
/**
* Initialise configuration overwrites from database
*/
function initGlobalNodeConfigurationOverwrites($node_id) {
if (!is_numeric($node_id)) return false;
$conf = array();
require_once ('models/common/common_configuration.php');
$Configuration = new common_configuration();
$conf = $Configuration->getConfiguration($node_id);
return $conf;
}
/**
* merge array with overwrites (for local configuration overwrites)
* TEMP: native array_replace_recursive function available in PHP 5.3
*/
function array_replace_recursive($Arr1, $Arr2) {
foreach($Arr2 as $key => $Value) {
if(array_key_exists($key, $Arr1) && is_array($Value)) $Arr1[$key] = $this->array_replace_recursive($Arr1[$key], $Arr2[$key]);
else $Arr1[$key] = $Value;
}
return $Arr1;
}
}