public function before() { parent::before(); View::bind_global('preview', $this->preview); if ($this->request->action() === 'index') { $this->page = Model_Page::find_by_slug($this->request->param('catcher')); } else { if (!Can::show()) { throw new Kohana_Exception("Permission Denied."); } $this->preview = TRUE; if ($this->request->query('preview') !== NULL) { $this->preview = (bool) $this->request->query('preview'); } if ($this->request->query('id_page') !== NULL) { $id_page = (bool) $this->request->query('id_page'); $this->page = Model_Page::factory('Page')->where('id_page', '=', $id_page)->order_by('id', 'DESC')->find(); dd($this->page); } else { $page_id = (int) $this->request->param('id'); $this->page = Model_Page::factory('Page', $page_id); } } View::bind_global('page', $this->page); $this->content = $this->page->render_blocks(); }
public function action_save() { $block = new stdClass(); $block->data = $this->request->post(); $block->page_id = $this->request->query('page_id'); $block->page_block_template_id = $this->request->query('page_block_template_id'); View::set_global('preview', TRUE); $page = Model_Page::factory('Page', $block->page_id); View::bind_global('page', $page); $result = Model_Page::instance()->render_block($block); $this->response->body($result); }
public function a($data, $name, $default = NULL, $attrs = array(), $force = FALSE) { $default_attrs = array('property' => $name); if (!$force) { $attrs = Arr::merge($default_attrs, $attrs); } $name_link = $name . '_link'; $name_link_internal = $name . '_link_internal'; $title = $force ? $default : $this->get($data, $name, $default); $href = $this->get($data, $name_link); $href = $href ? $href : Model_Page::factory('Page')->published()->where('id_page', '=', $this->get($data, $name_link_internal))->find()->link(); return HTML::anchor($href, $title, $attrs) . $this->hidden($data, $name_link) . $this->pages($data, $name_link_internal); }
public static function find_by_slug($slug) { // @TODO Aumentar quantidade de níveis $exploded = explode('/', $slug, 2); $model = Model_Page::factory('Page'); if (count($exploded) === 2) { $model->join('page_categories'); $model->on('page_categories.id', '=', 'page.page_category_id'); $model->where('page_categories.slug', '=', $exploded[0]); $slug = $exploded[1]; } if (count($exploded) === 1 and $exploded[0] === '') { $model->where_open(); $model->or_where('page.slug', 'IS', NULL); $model->or_where('page.slug', '=', ''); $model->where_close(); } else { $model->where('page.slug', '=', $slug); } $model->where('page.published', '=', TRUE); $model->where('page.actived', '=', TRUE); $model->order_by('page.updated_at', 'DESC'); return $model->find(); }
public function action_sort($type = false) { if (!$type) { return false; } $items = \Input::post('sort'); if (is_array($items)) { foreach ($items as $item) { list($item, $old_item) = explode('_', $item); if (is_numeric($item)) { $sort[] = $item; } if (is_numeric($old_item)) { $old_sort[] = $old_item; } } if (is_array($sort)) { // Get starting point for sort $start = min($old_sort); $start = $start > 0 ? --$start : $start; $model = Model_Page::factory(ucfirst($type)); foreach ($sort as $key => $id) { $item = $model::find_one_by_id($id); $item->set(array('cover' => $key == 0 ? 1 : 0, 'sort' => ++$start)); $item->save(); } \Messages::success('Items successfully reordered.'); echo \Messages::display('left', false); } } }
public function action_preview() { $page = Model_Page::factory('Page', $this->request->param('id')); $page = $page->find_last_composite(); View::bind_global('page', $page); }