コード例 #1
0
ファイル: menu.php プロジェクト: volodymyr-volynets/backend
 public function process($data, $options = [])
 {
     $temp = [];
     // we need to precess items that are controller and suboptions at the same time
     $subgroups = [];
     foreach ($data as $k => $v) {
         // determine acl
         if (!empty($v['sm_menuitm_acl_controller_id']) && !helper_acl::can_see_this_controller($v['sm_menuitm_acl_controller_id'], $v['sm_menuitm_acl_action_id'])) {
             unset($data[$k]);
             continue;
         }
         // go though each group
         for ($i = 1; $i <= 4; $i++) {
             if (!empty($v["g{$i}_code"])) {
                 $subgroups[$v["g{$i}_code"]] = true;
             }
         }
     }
     $subgroup_items = [];
     foreach ($data as $k => $v) {
         if (isset($subgroups[$v['sm_menuitm_code']])) {
             $subgroup_items[$v['sm_menuitm_code']] = $v;
             unset($data[$k]);
         }
     }
     // loop though data
     foreach ($data as $k => $v) {
         // loop though groups and add them to menu
         $key = [];
         for ($i = 1; $i <= 4; $i++) {
             if (!empty($v['g' . $i . '_code'])) {
                 $key[] = $v['g' . $i . '_code'];
                 // we need to set all groups
                 $temp2 = array_key_get($temp, $key);
                 if (is_null($temp2)) {
                     // if we have a controller that acts as submenu
                     if (!empty($subgroup_items[$v['g' . $i . '_code']])) {
                         $v9 = $subgroup_items[$v['g' . $i . '_code']];
                         array_key_set($temp, $key, ['code' => $v9['sm_menuitm_code'], 'name' => $v9['sm_menuitm_name'], 'name_extension' => null, 'icon' => $v9['sm_menuitm_icon'], 'url' => $v9['sm_menuitm_url'], 'order' => $v9['sm_menuitm_order'], 'options' => []]);
                     } else {
                         // if we do not have url we assume visitor wants to see extended menu
                         if (empty($v['g' . $i . '_url'])) {
                             $params = [];
                             for ($j = 1; $j <= $i; $j++) {
                                 $params['group' . $j . '_code'] = $v['g' . $j . '_code'];
                             }
                             $v['g' . $i . '_url'] = '/numbers/backend/system/menu/controller/menu?' . http_build_query2($params);
                         }
                         array_key_set($temp, $key, ['code' => $v['g' . $i . '_code'], 'name' => $v['g' . $i . '_name'], 'icon' => $v['g' . $i . '_icon'], 'order' => $v['g' . $i . '_order'], 'url' => $v['g' . $i . '_url'], 'options' => []]);
                     }
                 }
                 $key[] = 'options';
             }
         }
         // some replaces
         $name_extension = null;
         if ($v['sm_menuitm_code'] == 'entites.authorization.__entity_name') {
             $name_extension = '<b>' . session::get(['numbers', 'entity', 'em_entity_name']) . '</b>';
         }
         // finally we need to add menu item to the array
         $key[] = $v['sm_menuitm_code'];
         array_key_set($temp, $key, ['code' => $v['sm_menuitm_code'], 'name' => $v['sm_menuitm_name'], 'name_extension' => $name_extension, 'icon' => $v['sm_menuitm_icon'], 'url' => $v['sm_menuitm_url'], 'order' => $v['sm_menuitm_order'], 'options' => []]);
         // options generator
         if (!empty($v['sm_menuitm_options_generator'])) {
             $temp3 = explode('::', $v['sm_menuitm_options_generator']);
             $temp_data = factory::model($temp3[0])->{$temp3[1]}();
             $temp_key = $key;
             $temp_key[] = 'options';
             foreach ($temp_data as $k2 => $v2) {
                 $temp_key2 = $temp_key;
                 $temp_key2[] = $k2;
                 array_key_set($temp, $temp_key2, $v2);
             }
         }
     }
     // sorting
     foreach ($temp as $k => $v) {
         if (!empty($v['options'])) {
             foreach ($v['options'] as $k2 => $v2) {
                 if (!empty($v2['options'])) {
                     foreach ($v2['options'] as $k3 => $v3) {
                         if (!empty($v3['options'])) {
                             foreach ($v3['options'] as $k4 => $v4) {
                                 if (!empty($v4['options'])) {
                                     array_key_sort($temp[$k]['options'][$k2]['options'][$k3]['options'][$k4]['options'], ['order' => SORT_ASC], ['order' => SORT_NUMERIC]);
                                 }
                             }
                             array_key_sort($temp[$k]['options'][$k2]['options'][$k3]['options'], ['order' => SORT_ASC], ['order' => SORT_NUMERIC]);
                         }
                     }
                     array_key_sort($temp[$k]['options'][$k2]['options'], ['order' => SORT_ASC], ['order' => SORT_NUMERIC]);
                 }
             }
             array_key_sort($temp[$k]['options'], ['order' => SORT_ASC], ['order' => SORT_NUMERIC]);
         }
     }
     // sort root
     array_key_sort($temp, ['order' => SORT_ASC], ['order' => SORT_NUMERIC]);
     return $temp;
 }
コード例 #2
0
 public static function process($options = [])
 {
     // start buffering
     helper_ob::start(true);
     $controller_class = self::$settings['mvc']['controller_class'];
     // if we are handling error message and controller class has not been loaded
     if ($controller_class == 'controller_error' && error_base::$flag_error_already && !class_exists('controller_error')) {
         require './controller/error.php';
     }
     $controller = new $controller_class();
     // processing options
     if (!empty($options)) {
         foreach ($options as $k => $v) {
             $controller->{$k} = $v;
         }
     }
     // put action into controller
     $controller->action = ['code' => self::$settings['mvc']['controller_action_code'], 'full' => self::$settings['mvc']['controller_action']];
     // check ACL
     if ($controller_class != 'controller_error') {
         helper_acl::merge_data_with_db($controller, self::$settings['mvc']['controller_class']);
         if (helper_acl::can_be_executed($controller, true) == false) {
             throw new Exception('Permission denied!', -1);
         }
     } else {
         // important to unset controller data
         application::set('controller', null);
     }
     // auto populating input property in controller
     if (!empty(self::$settings['application']['controller']['input'])) {
         $controller->input = request::input(null, true, true);
     }
     // init method
     if (method_exists($controller, 'init')) {
         call_user_func(array($controller, 'init'));
     }
     // check if action exists
     if (!method_exists($controller, $controller->action['full'])) {
         throw new Exception('Action does not exists!');
     }
     // calling action
     echo call_user_func(array($controller, $controller->action['full']));
     // auto rendering view only if view exists, processing extension order as specified in .ini file
     $temp_reflection_obj = new ReflectionClass($controller);
     $controller_dir = pathinfo($temp_reflection_obj->getFileName(), PATHINFO_DIRNAME) . '/';
     $controller_file = end(self::$settings['mvc']['controllers']);
     $view = self::$settings['mvc']['controller_view'];
     $flag_view_found = false;
     if (!empty($view)) {
         $extensions = explode(',', isset(self::$settings['application']['view']['extension']) ? self::$settings['application']['view']['extension'] : 'html');
         foreach ($extensions as $extension) {
             $file = $controller_dir . $controller_file . '.' . $view . '.' . $extension;
             if (file_exists($file)) {
                 $controller = new view($controller, $file, $extension);
                 $flag_view_found = true;
                 break;
             }
         }
         // if views are mandatory
         if (!empty(self::$settings['application']['view']['mandatory']) && !$flag_view_found) {
             throw new Exception('View ' . $view . ' does not exists!');
         }
     }
     // autoloading media files
     layout::include_media($controller_dir, $controller_file, $view, $controller_class);
     // appending view after controllers output
     $controller->view = ($controller->view ?? '') . helper_ob::clean();
     // if we have to render debug toolbar
     if (debug::$toolbar) {
         helper_ob::start();
     }
     // call pre rendering method in bootstrap
     bootstrap::pre_render();
     // rendering layout
     $__skip_layout = application::get('flag.global.__skip_layout');
     if (!empty(self::$settings['mvc']['controller_layout']) && empty($__skip_layout)) {
         helper_ob::start();
         if (file_exists(self::$settings['mvc']['controller_layout_file'])) {
             $controller = new layout($controller, self::$settings['mvc']['controller_layout_file'], self::$settings['mvc']['controller_layout_extension']);
         }
         // session expiry dialog before replaces
         session::expiry_dialog();
         // buffer output and handling javascript files, chicken and egg problem
         $from = ['<!-- [numbers: messages] -->', '<!-- [numbers: title] -->', '<!-- [numbers: document title] -->', '<!-- [numbers: actions] -->', '<!-- [numbers: breadcrumbs] -->', '<!-- [numbers: javascript links] -->', '<!-- [numbers: javascript data] -->', '<!-- [numbers: css links] -->', '<!-- [numbers: layout onload] -->', '<!-- [numbers: layout onhtml] -->'];
         $to = [layout::render_messages(), layout::render_title(), layout::render_document_title(), layout::render_actions(), layout::render_breadcrumbs(), layout::render_js(), layout::render_js_data(), layout::render_css(), layout::render_onload(), layout::$onhtml];
         echo str_replace($from, $to, helper_ob::clean());
     } else {
         echo $controller->view;
     }
     // ajax calls that has not been processed by application
     if (application::get('flag.global.__ajax')) {
         layout::render_as(['success' => false, 'error' => [i18n(null, 'Could not process ajax call!')]], 'application/json');
     }
 }
コード例 #3
0
ファイル: acl.php プロジェクト: volodymyr-volynets/framework
 /**
  * Check if user can see this controller, used in menu
  *
  * @param int $controller_id
  * @param int $action_id
  * @return boolean
  */
 public static function can_see_this_controller($controller_id, $action_id)
 {
     $authorized = session::get(['numbers', 'authorized']);
     if (self::$controllers == null) {
         self::$controllers = application::get(['storage', 'controllers']);
     }
     if (self::$permissions == null) {
         self::handle_permissions();
     }
     if (!empty($controller_id)) {
         if (!isset(self::$controllers[$controller_id])) {
             return false;
         }
         // authorized
         if ($authorized) {
             if (empty(self::$controllers[$controller_id]['sm_controller_acl_authorized'])) {
                 return false;
             }
             // check permission
             if (!empty(self::$controllers[$controller_id]['sm_controller_acl_permission'])) {
                 // admin account can see everything
                 if (self::$flag_admin) {
                     return true;
                 }
                 // if we have permission to see the controller
                 if (empty(self::$permissions[$controller_id])) {
                     return false;
                 }
                 // if we have action
                 if (!empty($action_id)) {
                     if (empty(self::$permissions[$controller_id][$action_id])) {
                         return false;
                     }
                 }
             }
         } else {
             if (empty(self::$controllers[$controller_id]['sm_controller_acl_public'])) {
                 return false;
             }
         }
         // if we got here means we are ok
         return true;
     }
 }