11<?php
22/******************************************************************************/
33// //
4- // InstantMedia 2017 //
4+ // InstantMedia //
55// http://instantmedia.ru/, support@instantmedia.ru //
66// written by Fuze //
77// //
@@ -105,7 +105,7 @@ public function run($method_name = null){
105105
106106 // проверяем сначала экшен
107107 // Важно! Болокируйте экшен от прямого выполнения свойством lock_explicit_call
108- // http ://docs.instantcms.ru/dev/controllers/actions#действия-во-внешних-файлах
108+ // https ://docs.instantcms.ru/dev/controllers/actions#действия-во-внешних-файлах
109109
110110 $ api_dir_action_file = $ this ->root_path .'api_actions/ ' .$ this ->method_controller ->current_action .'.php ' ;
111111 $ action_file = $ this ->method_controller ->root_path .'actions/ ' .$ this ->method_controller ->current_action .'.php ' ;
@@ -117,6 +117,10 @@ public function run($method_name = null){
117117
118118 include_once $ action_file ;
119119
120+ if (!class_exists ($ class_name , false )){
121+ cmsCore::error (sprintf (ERR_CLASS_NOT_DEFINED , str_replace (PATH , '' , $ action_file ), $ class_name ));
122+ }
123+
120124 $ this ->method_action = new $ class_name ($ this ->method_controller );
121125
122126 } else {
@@ -128,10 +132,14 @@ public function run($method_name = null){
128132
129133 if (is_readable ($ hook_file )){
130134
131- if (!class_exists ($ class_name )){
135+ if (!class_exists ($ class_name, false )){
132136 include_once $ hook_file ;
133137 }
134138
139+ if (!class_exists ($ class_name , false )){
140+ cmsCore::error (sprintf (ERR_CLASS_NOT_DEFINED , str_replace (PATH , '' , $ hook_file ), $ class_name ));
141+ }
142+
135143 $ this ->method_action = new $ class_name ($ this ->method_controller );
136144
137145 }
@@ -162,7 +170,10 @@ public function run($method_name = null){
162170 return $ this ->error (777 );
163171 }
164172
165- cmsUser::setIp ($ ip );
173+ // совместимость
174+ if (method_exists ('cmsUser ' , 'setIp ' )){
175+ cmsUser::setIp ($ ip );
176+ }
166177
167178 }
168179
@@ -180,6 +191,18 @@ public function run($method_name = null){
180191 }
181192 }
182193
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+
183206 // ставим ключ API в свойство
184207 $ this ->method_action ->key = $ this ->key ;
185208 $ this ->method_action ->method_name = $ this ->method_name ;
@@ -289,29 +312,37 @@ private function validateMethodParams() {
289312 $ this ->request ->set ($ param_name , $ value );
290313
291314 } elseif (!is_null ($ value ) && isset ($ rules ['default ' ])){
315+
292316 $ value = $ this ->request ->get ($ param_name , $ rules ['default ' ]);
317+
318+ // для применения типизации переменной
319+ $ this ->request ->set ($ param_name , $ value );
320+
293321 }
294322
295- foreach ($ rules ['rules ' ] as $ rule ) {
323+ if (!empty ($ rules ['rules ' ])){
324+ foreach ($ rules ['rules ' ] as $ rule ) {
296325
297- if (!$ rule ) { continue ; }
326+ if (!$ rule ) { continue ; }
298327
299- $ validate_function = "validate_ {$ rule [0 ]}" ;
328+ $ validate_function = "validate_ {$ rule [0 ]}" ;
300329
301- $ rule [] = $ value ;
330+ $ rule [] = $ value ;
302331
303- unset($ rule [0 ]);
332+ unset($ rule [0 ]);
304333
305- $ result = call_user_func_array (array ($ this , $ validate_function ), $ rule );
334+ $ result = call_user_func_array (array ($ this , $ validate_function ), $ rule );
306335
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+ }
313342
343+ }
314344 }
345+
315346 }
316347
317348 if (!sizeof ($ errors )) { return false ; }
@@ -343,8 +374,8 @@ public function checkRequest() {
343374 return $ this ->error (23 );
344375 }
345376
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 ' ]);
348379
349380 // проверяем доступ к методу
350381 if (!$ is_view || $ is_hide ) {
0 commit comments