Exemple #1
0
 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');
 }
Exemple #2
0
 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);
     }
 }