1
1
<?php
2
2
/******************************************************************************/
3
3
// //
4
- // InstantMedia 2017 //
4
+ // InstantMedia //
5
5
// http://instantmedia.ru/, support@instantmedia.ru //
6
6
// written by Fuze //
7
7
// //
@@ -105,7 +105,7 @@ public function run($method_name = null){
105
105
106
106
// проверяем сначала экшен
107
107
// Важно! Болокируйте экшен от прямого выполнения свойством lock_explicit_call
108
- // http ://docs.instantcms.ru/dev/controllers/actions#действия-во-внешних-файлах
108
+ // https ://docs.instantcms.ru/dev/controllers/actions#действия-во-внешних-файлах
109
109
110
110
$ api_dir_action_file = $ this ->root_path .'api_actions/ ' .$ this ->method_controller ->current_action .'.php ' ;
111
111
$ action_file = $ this ->method_controller ->root_path .'actions/ ' .$ this ->method_controller ->current_action .'.php ' ;
@@ -117,6 +117,10 @@ public function run($method_name = null){
117
117
118
118
include_once $ action_file ;
119
119
120
+ if (!class_exists ($ class_name , false )){
121
+ cmsCore::error (sprintf (ERR_CLASS_NOT_DEFINED , str_replace (PATH , '' , $ action_file ), $ class_name ));
122
+ }
123
+
120
124
$ this ->method_action = new $ class_name ($ this ->method_controller );
121
125
122
126
} else {
@@ -128,10 +132,14 @@ public function run($method_name = null){
128
132
129
133
if (is_readable ($ hook_file )){
130
134
131
- if (!class_exists ($ class_name )){
135
+ if (!class_exists ($ class_name, false )){
132
136
include_once $ hook_file ;
133
137
}
134
138
139
+ if (!class_exists ($ class_name , false )){
140
+ cmsCore::error (sprintf (ERR_CLASS_NOT_DEFINED , str_replace (PATH , '' , $ hook_file ), $ class_name ));
141
+ }
142
+
135
143
$ this ->method_action = new $ class_name ($ this ->method_controller );
136
144
137
145
}
@@ -162,7 +170,10 @@ public function run($method_name = null){
162
170
return $ this ->error (777 );
163
171
}
164
172
165
- cmsUser::setIp ($ ip );
173
+ // совместимость
174
+ if (method_exists ('cmsUser ' , 'setIp ' )){
175
+ cmsUser::setIp ($ ip );
176
+ }
166
177
167
178
}
168
179
@@ -180,6 +191,18 @@ public function run($method_name = null){
180
191
}
181
192
}
182
193
194
+ // проверяем админ доступ, если метод этого требует
195
+ if (!empty ($ this ->method_action ->admin_required )){
196
+ if (!$ this ->cms_user ->is_logged ){
197
+ return $ this ->error (71 );
198
+ }
199
+ if (!$ this ->cms_user ->is_admin ){
200
+ return $ this ->error (710 );
201
+ }
202
+ // грузим язык админки
203
+ cmsCore::loadControllerLanguage ('admin ' );
204
+ }
205
+
183
206
// ставим ключ API в свойство
184
207
$ this ->method_action ->key = $ this ->key ;
185
208
$ this ->method_action ->method_name = $ this ->method_name ;
@@ -289,29 +312,37 @@ private function validateMethodParams() {
289
312
$ this ->request ->set ($ param_name , $ value );
290
313
291
314
} elseif (!is_null ($ value ) && isset ($ rules ['default ' ])){
315
+
292
316
$ value = $ this ->request ->get ($ param_name , $ rules ['default ' ]);
317
+
318
+ // для применения типизации переменной
319
+ $ this ->request ->set ($ param_name , $ value );
320
+
293
321
}
294
322
295
- foreach ($ rules ['rules ' ] as $ rule ) {
323
+ if (!empty ($ rules ['rules ' ])){
324
+ foreach ($ rules ['rules ' ] as $ rule ) {
296
325
297
- if (!$ rule ) { continue ; }
326
+ if (!$ rule ) { continue ; }
298
327
299
- $ validate_function = "validate_ {$ rule [0 ]}" ;
328
+ $ validate_function = "validate_ {$ rule [0 ]}" ;
300
329
301
- $ rule [] = $ value ;
330
+ $ rule [] = $ value ;
302
331
303
- unset($ rule [0 ]);
332
+ unset($ rule [0 ]);
304
333
305
- $ result = call_user_func_array (array ($ this , $ validate_function ), $ rule );
334
+ $ result = call_user_func_array (array ($ this , $ validate_function ), $ rule );
306
335
307
- // если получилось false, то дальше не проверяем, т.к.
308
- // ошибка уже найдена
309
- if ($ result !== true ) {
310
- $ errors [$ param_name ] = $ result ;
311
- break ;
312
- }
336
+ // если получилось false, то дальше не проверяем, т.к.
337
+ // ошибка уже найдена
338
+ if ($ result !== true ) {
339
+ $ errors [$ param_name ] = $ result ;
340
+ break ;
341
+ }
313
342
343
+ }
314
344
}
345
+
315
346
}
316
347
317
348
if (!sizeof ($ errors )) { return false ; }
@@ -343,8 +374,8 @@ public function checkRequest() {
343
374
return $ this ->error (23 );
344
375
}
345
376
346
- $ is_view = !$ this ->key ['methods_access ' ]['allow ' ] || in_array ($ this ->method_name , $ this ->key ['methods_access ' ]['allow ' ]);
347
- $ is_hide = $ this ->key ['methods_access ' ]['disallow ' ] && in_array ($ this ->method_name , $ this ->key ['methods_access ' ]['disallow ' ]);
377
+ $ is_view = !$ this ->key ['key_methods ' ]['allow ' ] || in_array ($ this ->method_name , $ this ->key ['key_methods ' ]['allow ' ]);
378
+ $ is_hide = $ this ->key ['key_methods ' ]['disallow ' ] && in_array ($ this ->method_name , $ this ->key ['key_methods ' ]['disallow ' ]);
348
379
349
380
// проверяем доступ к методу
350
381
if (!$ is_view || $ is_hide ) {
0 commit comments