protected function init() { $module_config = Helper_Module::load_config('blog'); $helper_acl = new Helper_ACL($this->acl); $helper_acl->inject(Arr::get($module_config, 'a2')); $this->blog_group = Arr::get($this->params, 'group'); }
protected function init() { $request = $this->request->current(); $this->config = Kohana::$config->load($this->config)->as_array(); $this->acl_init(); $this->site_init(); $helper_acl = new Helper_ACL($this->acl); $a2_config = Kohana::$config->load('admin/a2/base')->as_array(); $helper_acl->inject($a2_config); if (Route::name($request->route()) == 'modules') { $this->module_page_id = (int) $request->query('page'); $this->module_config = empty($this->module_config) ? Helper_Module::code_by_controller($request->controller()) : $this->module_config; $_pages = $this->get_module_pages($this->module_config); if ($_pages->count() > 0) { if ($this->module_page_id == 0) { $this->module_page_id = $_pages->rewind()->current()->id; } foreach ($_pages as $_item) { $_link = URL::base() . Page_Route::dynamic_base_uri($_item->id); $this->module_pages[$_item->id] = $_item->title . " [ {$_link} ]"; } } $this->module_config = Helper_Module::load_config($this->module_config); if (!Kohana::$is_cli) { $config = Arr::get($this->module_config, 'a2'); $helper_acl->inject($config); } if (!$this->acl->is_allowed($this->user, $request->controller() . '_controller', 'access')) { throw new HTTP_Exception_404(); } } $injectors = array(); foreach ($this->injectors as $_key => $_array) { $params = Arr::get($_array, 1); if (class_exists($_array[0])) { $object = new $_array[0]($request, $this->user, $this->acl, $params); $injectors[$_key] = $object; } } $this->injectors = $injectors; unset($injectors); $this->is_cancel = $request->post('cancel') == 'cancel'; $this->back_url = $request->query('back_url'); $this->post_check_empty_files(); $this->post_check_deleted_fields(); }
/** * Return module list declared in _modules config * If module type is Single and it co */ public static function modules() { if (self::$_modules === NULL) { self::$_modules = array(); $_modules = Kohana::$config->load(self::$_modules_config); foreach ($_modules as $code => $config) { if ($config['type'] == self::MODULE_HIDDEN) { continue; } if ($config['type'] != self::MODULE_STANDALONE) { if (!self::check_module($config['alias'])) { continue; } } self::$_modules[$code] = $config; } } return self::$_modules; }
public function action_index() { $modules = array(); $_modules = Kohana::$config->load('_modules'); foreach ($_modules as $code => $config) { if (empty($config['alias']) or !Helper_Module::check_module($config['alias'])) { continue; } $module_config = Kohana::$config->load('admin/modules/' . $code); $helper_acl = new Helper_ACL($this->acl); $helper_acl->inject($module_config->get('a2')); $_controller = empty($config['controller']) ? $code : $config['controller']; if ($this->acl->is_allowed($this->user, $_controller . '_controller', 'access')) { $modules[$code] = array('code' => $code, 'name' => __($config['name']), 'url' => Route::url('modules', array('controller' => $_controller))); } } $this->template->set_filename('modules/list')->set('modules', $modules); $this->title = __('Modules'); }
public function action_edit() { $request = $this->request->current(); $id = (int) $request->param('id'); $helper_orm = ORM_Helper::factory('page'); $orm = $helper_orm->orm(); if ((bool) $id) { $orm->and_where('id', '=', $id)->find(); if (!$this->acl->is_allowed($this->user, $orm, 'edit')) { throw new HTTP_Exception_404(); } $this->title = __('Edit page'); } else { $this->title = __('Add page'); } if (empty($this->back_url)) { $this->back_url = Route::url('admin', array('controller' => 'pages')); } if ($this->is_cancel) { $request->redirect($this->back_url); } $pages_db = ORM::factory('page')->order_by('level', 'asc')->order_by('parent_id', 'asc')->order_by('position', 'asc')->find_all(); $pages = $pages_db->as_array('id'); $errors = array(); $submit = $request->post('submit'); if ($submit) { try { if ((bool) $id) { $orm->updater_id = $this->user->id; $orm->updated = date('Y-m-d H:i:s'); } else { $orm->site_id = SITE_ID; $orm->creator_id = $this->user->id; } $parent_id = (int) $request->post('parent_id'); if ($parent_id > 0 and isset($pages[$parent_id])) { $orm->level = $pages[$parent_id]->level + 1; } else { $orm->level = Model_Page::LEVEL_START; } $values = $this->meta_seo_reset($this->request->current()->post(), 'meta_tags'); if (empty($values['uri'])) { $values['uri'] = transliterate_unique($values['title'], $orm, 'uri', array(array('and', 'parent_id', '=', $parent_id))); } if (!IS_MASTER_SITE) { $values['for_all'] = 0; } if (!IS_MASTER_SITE) { $values['can_hiding'] = 0; } $helper_orm->save($values + $_FILES); Helper_Page::clear_cache(); } catch (ORM_Validation_Exception $e) { $errors = $this->errors_extract($e); } } if (!empty($errors) or $submit != 'save_and_exit') { $relations = $pages_db->as_array('id', 'parent_id'); $modules = array(); $linked_modules = Helper_Module::linked_modules(); $leave_module_types = array(Helper_Module::MODULE_SINGLE, Helper_Module::MODULE_STANDALONE); $this_page = $helper_orm->orm()->as_array(); foreach (Helper_Module::modules() as $key => $value) { $_own_module = ($this_page['type'] == 'module' and $this_page['data'] == $key); if (in_array($key, $linked_modules) and in_array($value['type'], $leave_module_types) and !$_own_module) { continue; } $modules[$key] = __($value['name']); } if ((bool) $id) { $page_list = array_diff_key(Helper_Page::parse_to_list($pages), array_flip($this->_get_childrens($id, $relations))); } else { $page_list = Helper_Page::parse_to_list($pages); } $properties = $helper_orm->property_list(); $this->template->set_filename('pages/edit')->set('errors', $errors)->set('helper_orm', $helper_orm)->set('pages', $page_list)->set('base_uri_list', Helper_Page::parse_to_base_uri($pages))->set('modules', $modules)->set('properties', $properties); } else { $request->redirect($this->back_url); } }
public function action_edit() { $blog_orm = ORM::factory('blog')->where('group', '=', $this->group_key)->and_where('id', '=', $this->blog_id)->find(); if (!$blog_orm->loaded()) { throw new HTTP_Exception_404(); } $request = $this->request->current(); $id = (int) $this->request->current()->param('id'); $helper_orm = ORM_Helper::factory('blog_Post'); $orm = $helper_orm->orm(); if ((bool) $id) { $orm->where('id', '=', $id)->find(); if (!$orm->loaded() or !$this->acl->is_allowed($this->user, $orm, 'edit')) { throw new HTTP_Exception_404(); } $this->title = __('Edit post'); } else { $this->title = __('Add post'); } if (empty($this->back_url)) { $query_array = array('group' => $this->group_key, 'blog' => $this->blog_id); $query_array = Paginator::query($request, $query_array); $this->back_url = Route::url('modules', array('controller' => $this->controller_name['element'], 'query' => Helper_Page::make_query_string($query_array))); } if ($this->is_cancel) { $request->redirect($this->back_url); } $errors = array(); $submit = $request->post('submit'); if ($submit) { try { if ((bool) $id) { $orm->updater_id = $this->user->id; $orm->updated = date('Y-m-d H:i:s'); $reload = FALSE; } else { $orm->site_id = SITE_ID; $orm->creator_id = $this->user->id; $orm->blog_id = $this->blog_id; $reload = TRUE; } $values = $this->meta_seo_reset($this->request->current()->post(), 'meta_tags'); $values['public_date'] = $this->value_multiple_date($values, 'public_date'); if (empty($values['uri'])) { $values['uri'] = transliterate_unique($values['title'], $orm, 'uri'); } $helper_orm->save($values + $_FILES); if ($reload) { if ($submit != 'save_and_exit') { $this->back_url = Route::url('modules', array('controller' => $request->controller(), 'action' => $request->action(), 'id' => $orm->id, 'query' => Helper_Page::make_query_string($request->query()))); } $request->redirect($this->back_url); } } catch (ORM_Validation_Exception $e) { $errors = $this->errors_extract($e); } } // If add action then $submit = NULL if (!empty($errors) or $submit != 'save_and_exit') { $this->left_menu_blog_add($blog_orm); $this->left_menu_element_list(); $this->left_menu_element_add(); $blogs_list = ORM::factory('blog')->order_by('position', 'asc')->find_all()->as_array('id', 'title'); if (!$orm->loaded()) { $orm->blog_id = $this->blog_id; } $properties = $helper_orm->property_list(); $this->template->set_filename('modules/blog/element/edit')->set('helper_orm', $helper_orm)->set('blogs_list', $blogs_list)->set('properties', $properties); if (Helper_Module::check_module('kubikrubik-photo')) { $injector = $this->injectors['photo']; if ($orm->loaded()) { try { $this->hook_list_content[] = $injector->get_hook($orm); $this->menu_left_add($injector->menu_list($orm->photo_album)); $this->menu_left_add($injector->menu_add($orm->photo_album)); $this->menu_left_add($injector->menu_fix($orm->photo_album)); } catch (ORM_Validation_Exception $e) { $errors = array_merge($errors, $this->errors_extract($e)); } } } $this->template->set('errors', $errors); } else { $request->redirect($this->back_url); } }
public static function factory($uri = TRUE, HTTP_Cache $cache = NULL, $injected_routes = array()) { $request = parent::factory($uri, $cache, $injected_routes); // for admin routes $exluded_routes = array('admin', 'admin_error', 'modules'); if ($request->route() !== NULL and in_array($request->route()->route_name, $exluded_routes)) { return $request; } // for public routes $request->define_site(); ORM_Base::$filter_mode = ORM_Base::FILTER_FRONTEND; ORM_Base::$site_id = $request->site_id; ORM_Base::$site_id_master = $request->site_id_master; if ($request->route() !== NULL) { return $request; } $request_uri = $request->uri(); $request->page = $page = Page_Route::page($request->uri()); if ($page !== NULL) { $routes = array(); if ($page['type'] == 'module' and !Helper_Module::is_stanalone($page['data'])) { $routes_config = Kohana::$config->load('routes/' . $page['data'])->as_array(); $request->set_module_routes($routes_config, $page['uri_full'], $page['id'], $cache); } elseif (Helper_Module::is_stanalone($page['data'])) { /* * For controllers which no need admin side (only public contoller) * and have one action (by default is 'index') * Can have route file or default controller (controller name equal 'data' field value) */ $routes_config = Kohana::$config->load('routes/' . $page['data'])->as_array(); if (empty($routes_config)) { $name = $page['id'] . '<->standalone_page'; $uri_callback = $page['uri_full']; $defaults = array('directory' => 'standalone', 'controller' => $page['data']); $route = new Route($uri_callback); $route->defaults($defaults); $routes[$name] = $route; Route::set($name, $uri_callback)->defaults($defaults); $processed_uri = Request::process_uri($request_uri, $routes); if ($processed_uri !== NULL) { $request->set_dinamic_route($processed_uri, $cache); } } else { $request->set_module_routes($routes_config, $page['uri_full'], $page['id'], $cache); } } else { /* * For simple static pages */ $name = $page['id'] . '<->std_page'; $uri_callback = $page['uri_full']; $defaults = array('controller' => 'page', 'action' => $page['type']); $route = new Route($uri_callback); $route->defaults($defaults); $routes[$name] = $route; Route::set($name, $uri_callback)->defaults($defaults); $processed_uri = Request::process_uri($request_uri, $routes); if ($processed_uri !== NULL) { $request->set_dinamic_route($processed_uri, $cache); } } } else { Kohana::$log->add(Log::ERROR, 'Page for :uri not found. [:file][:line] ', array(':file' => Debug::path(__FILE__), ':line' => __LINE__, ':uri' => $request->uri())); throw new HTTP_Exception_404(); } return $request; }