-
Notifications
You must be signed in to change notification settings - Fork 6
/
extension.driver.php
338 lines (254 loc) · 9.28 KB
/
extension.driver.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
<?php
require_once(EXTENSIONS.'/sections_event/lib/class.se_perman.php');
Final Class Extension_Sections_Event extends Extension
{
private $valid_dependencies = null;
public function __construct(){
$this->validateDependencies();
}
/*------------------------------------------------------------------------------------------------*/
/* Installation */
/*------------------------------------------------------------------------------------------------*/
public function install(){
$this->dropPermissionTables();
return $this->createPermissionTables();
}
public function uninstall(){
return $this->dropPermissionTables();
}
public function update($previous_version){
if( version_compare( $previous_version, '2.0', '<' ) ){
$this->dropPermissionTables();
$this->createPermissionTables();
}
}
private function createPermissionTables(){
return Symphony::Database()->import( "
CREATE TABLE `tbl_se_section_permissions` (
`id` INT unsigned NOT NULL AUTO_INCREMENT,
`role_id` INT unsigned NOT NULL,
`section_id` INT unsigned NOT NULL,
`view` TINYINT unsigned NOT NULL DEFAULT '0',
`create` TINYINT unsigned NOT NULL DEFAULT '0',
`edit` TINYINT unsigned NOT NULL DEFAULT '0',
`delete` TINYINT unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `tbl_se_field_permissions` (
`id` INT unsigned NOT NULL AUTO_INCREMENT,
`role_id` INT unsigned NOT NULL,
`field_id` INT unsigned NOT NULL,
`view` TINYINT unsigned NOT NULL DEFAULT '0',
`edit` TINYINT unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
" );
}
private function dropPermissionTables(){
return Symphony::Database()->import( "
DROP TABLE IF EXISTS `tbl_se_section_permissions`;
DROP TABLE IF EXISTS `tbl_se_field_permissions`;
" );
}
/*------------------------------------------------------------------------------------------------*/
/* Setters & Getters */
/*------------------------------------------------------------------------------------------------*/
private function setValidDependencies($status){
$this->valid_dependencies = $status;
}
private function getValidDependencies(){
return $this->valid_dependencies;
}
/*------------------------------------------------------------------------------------------------*/
/* Navigation */
/*------------------------------------------------------------------------------------------------*/
public function fetchNavigation(){
if( !$this->getValidDependencies() ){
return null;
}
return array(
array(
'location' => __( 'System' ),
'name' => __( 'Section permissions' ),
'link' => '/permissions/'
)
);
}
/*------------------------------------------------------------------------------------------------*/
/* Delegates */
/*------------------------------------------------------------------------------------------------*/
public function getSubscribedDelegates(){
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'dInitialiseAdminPageHead'
),
array(
'page' => '*',
'delegate' => 'SE_PrepareFilter',
'callback' => 'dSE_PrepareFilter'
),
array(
'page' => '*',
'delegate' => 'SE_CommitFilter',
'callback' => 'dSE_CommitFilter'
),
array(
'page' => '/frontend/',
'delegate' => 'ManageEXSLFunctions',
'callback' => 'dManageEXSLFunctions'
),
);
}
public function dInitialiseAdminPageHead(){
if( !$this->getValidDependencies() ){
$message = __( 'Sections Event depends on Members and EXSL Function Manager extensions. Make sure they are installed.' );
Administration::instance()->Page->pageAlert( $message, Alert::NOTICE );
}
}
public function dSE_PrepareFilter($context){
// simulate XSS filter
$this->triggerXSS( $context );
}
public function dSE_CommitFilter($context){
// simulate ETM
$this->triggerETM( $context );
// simulate Multilingual Reflection
// $this->triggerMultilingualReflection( $context );
// simulate Reflection
$this->triggerReflection( $context );
// simulate Multilingual Entry URL
$this->triggerMultilingualEntryUrl( $context );
}
public function dManageEXSLFunctions($context){
$context['manager']->addFunction(
'SE_PerMan::control_check',
'http://xanderadvertising.com/functions',
'controlCheck'
);
$context['manager']->addFunction(
'SE_PerMan::control_getLevel',
'http://xanderadvertising.com/functions',
'controlGetLevel'
);
}
/*------------------------------------------------------------------------------------------------*/
/* Utilities */
/*------------------------------------------------------------------------------------------------*/
public static function baseURL(){
return SYMPHONY_URL.'/extension/sections_event/';
}
/*------------------------------------------------------------------------------------------------*/
/* Internal */
/*------------------------------------------------------------------------------------------------*/
private function triggerETM($context){
// make sure extension is enabled
$etm_ext_status = ExtensionManager::fetchStatus( array('handle' => 'email_template_manager') );
if( $etm_ext_status[0] !== EXTENSION_ENABLED ){
return;
}
/** @var $etm Extension_Email_Template_Manager */
$etm = ExtensionManager::getInstance( 'email_template_manager' );
require_once(EXTENSIONS.'/sections_event/lib/class.etmsectionsevent.php');
// simulate ETM context
$event = new ETMSectionsEvent();
$event->eParamFILTERS = $context['filters'];
$errors = array();
$etm_context = array(
'entry' => $context['entry'],
'fields' => $context['fields'],
'event' => $event,
'errors' => &$errors
);
$etm->eventFinalSaveFilter( $etm_context );
$context['filter_results'] = $errors;
}
private function triggerMultilingualReflection($context){
$reflection_ext_status = ExtensionManager::fetchStatus( array('handle' => 'multilingual_reflection') );
if( $reflection_ext_status[0] !== EXTENSION_ENABLED ){
return;
}
/** @var $multilingual_reflection Extension_Multilingual_Reflection */
$multilingual_reflection = ExtensionManager::getInstance( 'multilingual_reflection' );
$multilingual_reflection_context = array(
'entry' => $context['entry']
);
$multilingual_reflection->compileFields( $multilingual_reflection_context );
}
private function triggerReflection($context){
$reflection_ext_status = ExtensionManager::fetchStatus( array('handle' => 'reflectionfield') );
if( $reflection_ext_status[0] !== EXTENSION_ENABLED ){
return;
}
/** @var $reflection Extension_ReflectionField */
$reflection = ExtensionManager::getInstance( 'reflectionfield' );
$reflection_context = array(
'entry' => $context['entry']
);
$reflection->compileFrontendFields( $reflection_context );
}
private function triggerMultilingualEntryUrl($context){
$meu_ext_status = ExtensionManager::fetchStatus( array('handle' => 'multilingual_entry_url') );
if( $meu_ext_status[0] !== EXTENSION_ENABLED ){
return;
}
/** @var $reflection Extension_ReflectionField */
$reflection = ExtensionManager::getInstance( 'multilingual_entry_url' );
$meu_context = array(
'entry' => $context['entry']
);
$reflection->compileFrontendFields( $meu_context );
}
/**
* Triggers XSS filter functionality
*
* @param $context
*/
private function triggerXSS($context){
// make sure extension is enabled
$xss_ext_status = ExtensionManager::fetchStatus( array('handle' => 'xssfilter') );
if( $xss_ext_status[0] !== EXTENSION_ENABLED ){
return;
}
// check for filter presence
if( !in_array( 'xss-fail', $context['filters'] ) && !in_array( 'xss-remove', $context['filters'] ) ){
return;
}
/** @var $xss_filter Extension_XssFilter */
$xss_filter = ExtensionManager::getInstance( 'xssfilter' );
$contains_xss = false;
// Loop over the fields to check for XSS, this loop will
// break as soon as XSS is detected
foreach($context['original_fields'] as $value){
if( is_array( $value ) ){
if( $xss_filter::detectXSSInArray( $value ) ){
$contains_xss = true;
break;
}
}
else{
if( $xss_filter::detectXSS( $value ) ){
$contains_xss = true;
break;
}
}
}
// "fail" filter
if( in_array( 'xss-fail', $context['filters'] ) && $contains_xss === true ){
$context['filter_results'][] = array(
'xss', false, __( "Possible XSS attack detected in submitted data" )
);
}
}
private function validateDependencies(){
$result = true;
// members installed
$members = ExtensionManager::fetchStatus( array('handle' => 'members') );
$result = $result && ($members[0] === EXTENSION_ENABLED);
// exsl function manager installed
$efm = ExtensionManager::fetchStatus( array('handle' => 'exsl_function_manager') );
$result = $result && ($efm[0] === EXTENSION_ENABLED);
$this->setValidDependencies( $result );
}
}