/** * * * @param Model_Page_Front $page * @param boolean $set_page_data Установка данных страницы * @return KodiCMS_Meta */ public function set_page(Model_Page_Front $page, $set_page_data = FALSE) { $this->_page = $page; if ($set_page_data !== FALSE) { $this->title(HTML::chars($this->_page->meta_title()))->add(array('name' => 'keywords', 'content' => HTML::chars($this->_page->meta_keywords())))->add(array('name' => 'description', 'content' => HTML::chars($this->_page->meta_description())))->add(array('name' => 'robots', 'content' => HTML::chars($this->_page->robots)))->add(array('charset' => 'utf-8'), 'meta::charset'); } return $this; }
/** * * @param Model_Page_Front $page * @param string $part * @param boolean $inherit * @return boolean */ public static function exists(Model_Page_Front $page, $part, $inherit = FALSE) { self::_load_parts($page->id()); if (isset(self::$_cache[$page->id()][$part])) { return TRUE; } else { if ($inherit !== FALSE and $page->parent() instanceof Model_Page_Front) { return self::exists($this->parent(), $part, TRUE); } } return FALSE; }
public function find_by_uri($uri, $fields = array()) { $fields = $this->prepare_param($fields); $page = Model_Page_Front::find($uri); if (!$page) { throw new HTTP_Exception_404('Page :uri not found', array(':uri' => $uri)); } // If page needs login, redirect to login if ($page->needs_login() == Model_Page::LOGIN_REQUIRED) { throw new HTTP_Exception_401('You don`t have access to view page :uri. Please login', array(':uri' => $uri)); } $fields = array_merge(array('id', 'title', 'url'), $fields); $allowed_fields = array('id', 'title', 'url', 'breadcrumb', 'author', 'author_id', 'updator', 'updator_id', 'slug', 'keywords', 'description', 'level', 'tags', 'is_active', 'date', 'breadcrumbs', 'layout', 'content'); foreach ($fields as $field) { if (strpos($field, 'part::') === 0) { $allowed_fields[] = $field; } } $fields = array_intersect($allowed_fields, $fields); $array = array(); foreach ($fields as $field) { if ($field == 'content') { $array['content'] = (string) $page->render_layout(); continue; } elseif (strpos($field, 'part::') === 0) { list($part, $name) = explode('::', $field); $array[$part][$name] = $page->content($name); } else { if (method_exists($page, $field)) { $array[$field] = $page->{$field}(); } } } return array('page' => $array); }
public function action_index() { $code = $this->request->param('code'); if ($code === NULL) { Model_Page_Front::not_found(); } $reflink_model = ORM::factory('user_reflink', $code); if (!$reflink_model->loaded()) { Messages::errors(__('Reflink not found')); $this->go_home(); } $next_url = Arr::get($reflink_model->data, 'next_url'); try { Database::instance()->begin(); Reflink::factory($reflink_model)->confirm(); $reflink_model->delete(); Database::instance()->commit(); } catch (Kohana_Exception $e) { Database::instance()->rollback(); Messages::errors($e->getMessage()); } if (Valid::url($next_url)) { $this->go($next_url); } $this->go_home(); }
/** * * @param string $part * @param boolean $inherit * @param integer $cache_lifetime */ public function content($part = 'body', $inherit = FALSE, $cache_lifetime = NULL, array $tags = array()) { $method = 'content_' . URL::title($part, '_'); if (method_exists($this, $method)) { return $this->{$method}($cache_lifetime, $tags); } return parent::content($part, $inherit, $cache_lifetime, $tags); }
/** * Generate a Response for the 401 Exception. * * The user should be redirect to a login page. * * @return Response */ public function get_response() { Flash::set('protected_page', Context::instance()->get_page()); if (($page = Model_Page_Front::findByField('behavior_id', 'protected_page')) !== FALSE) { return Request::factory($page->url)->execute(); } throw new HTTP_Exception_401($this->message); }
public function execute() { $page_id = $this->__get_item_page_id(); if (empty($page_id) or $this->router()->matched_route() === NULL) { return FALSE; } $this->_page = Model_Page_Front::findById($page_id); }
public function execute() { $slug = $this->router()->param('username'); $inner_page = Model_Page_Front::findBySlug($slug, $this->page()); // Если не найдена внутрення страница по SLUG if ($inner_page) { $this->_page = $inner_page; return; } }
public function action_index() { $path = Download::decode_path($this->request->param('path')); if (!file_exists($path)) { if (IS_BACKEND) { throw new HTTP_Exception_404('File :file not found', array(':file' => $path)); } else { Model_Page_Front::not_found('File :file not found', array(':file' => $path)); } } $this->responses->send_file($path); }
public function get_page() { $page = NULL; if ($this->page_id >= 1) { $page = Model_Page_Front::findById($this->page_id); } else { if (empty($this->page_id)) { $page = $this->_ctx->get_page(); } } return $page; }
/** * * @param type Model_Page_Front */ private function _render(Model_Page_Front $page) { View::set_global('page_object', $page); View::set_global('page', $page); $this->_ctx->set_page($page); // If page needs login, redirect to login if ($page->needs_login() == Model_Page::LOGIN_REQUIRED) { Observer::notify('frontpage_login_required', $page); if (!Auth::is_logged_in()) { Flash::set('redirect', $page->url()); $this->redirect(Route::get('user')->uri(array('action' => 'login'))); } } Observer::notify('frontpage_found', $page); $this->_ctx->set_crumbs($page); $this->_ctx->build_crumbs(); // Если установлен статус 404, то выводим страницу 404 // Страницу 404 могут выкидывать также Виджеты if (Request::current()->is_initial() and $this->response->status() == 404) { $message = $this->_ctx->get('throw_message'); $this->_ctx = NULL; if (!$message) { $message = 'Page not found'; } Model_Page_Front::not_found($message); } $html = (string) $page->render_layout(); // Если пользователь Администраторо или девелопер, в конец шаблона // добавляем View 'system/blocks/toolbar', в котором можно добавлять // собственный HTML, например панель администратора if (Auth::is_logged_in() and Auth::has_permissions(array('administrator', 'developer'))) { $inject_html = (string) View::factory('system/blocks/toolbar'); // Insert system HTML before closed tag body $matches = preg_split('/(<\\/body>)/i', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); if (count($matches) > 1) { /* assemble the HTML output back with the iframe code in it */ $html = $matches[0] . $inject_html . $matches[1] . $matches[2]; } } // Если в наcтройках выключен режим отладки, то выключить etag кеширование if (Config::get('site', 'debug') == Config::NO) { $this->check_cache(sha1($html)); $this->response->headers('last-modified', date('r', strtotime($page->updated_on))); } $this->response->headers('Content-Type', $page->mime()); if (Config::get('global', 'x_powered_header') == Config::YES) { $this->response->headers('X-Powered-CMS', CMS_NAME . '/' . CMS_VERSION); } $this->response->body($html); }
public function get_response() { $ext = pathinfo(Request::current()->url(), PATHINFO_EXTENSION); $mimetype = FALSE; if ($ext and !($mimetype = File::mime_by_ext($ext))) { $mimetype = 'application/octet-stream'; } if ($mimetype and $mimetype !== 'text/html') { return Response::factory()->headers('content-type', $mimetype)->status(404); } if (($page = Model_Page_Front::findByField('behavior_id', 'page_not_found')) !== FALSE) { return Request::factory($page->url)->query('message', $this->message)->execute()->status(404); } throw new HTTP_Exception_404('Something went wrong'); }
/** * * @param Model_Page_Front $page * @param string $key * @param boolean $inherit * @return boolean */ public static function exists(Model_Page_Front $page, $key, $inherit = FALSE) { if (Arr::get(self::$_fields, $page->id()) === NULL) { self::$_fields[$page->id()] = ORM::factory('Page_Field')->get_by_page_id($page->id())->as_array('key', 'value'); } if (isset(self::$_fields[$page->id()][$key])) { return TRUE; } else { if ($inherit !== FALSE and $page->parent() instanceof Model_Page_Front) { return self::exists($page->parent(), $key, $inherit); } } return FALSE; }
public function execute() { $slug = $this->router()->param('item'); if (empty($slug)) { return; } $item_page_id = $this->settings()->item_page_id; // Если не найдена внутрення страница по SLUG if (($this->_page = Model_Page_Front::find($slug, FALSE, $this->page())) === FALSE) { // Производим поиск страницы которая укзана в настройках типа страницы if (!empty($item_page_id)) { $this->_page = Model_Page_Front::findById($item_page_id); return; } Model_Page_Front::not_found(); } }
/** * * @return array [$pages] */ public function fetch_data() { $page = $this->get_page(); if (!$page instanceof Model_Page_Behavior_Archive) { Model_Page_Front::not_found(); } $params = $page->behavior()->router()->params(); $date = implode('-', $params); $clause = array('where' => array(array('page.published_on', 'like', $date . '%')), 'order_by' => array(array('page.published_on', 'desc'))); if ($this->list_offset > 0) { $clause['offset'] = (int) $this->list_offset; } if ($this->list_size > 0) { $clause['limit'] = (int) $this->list_size; } $pages = $page->parent()->children($clause); return array('pages' => $pages); }
/** * * @return array [$total_found, $results, $keyword] */ public function fetch_data() { $keyword = $this->keyword(); $return = array('total_found' => 0, 'results' => array(), 'keyword' => $keyword); if (empty($keyword)) { return $return; } $ids = Search::instance()->find_by_keyword($keyword, FALSE, 'pages', $this->list_size, $this->list_offset); if (empty($ids['pages'])) { return $return; } $pages = array(); foreach ($ids['pages'] as $item) { if (($page = Model_Page_Front::findById($item['id'])) === FALSE) { $this->_total--; continue; } $pages[$item['id']] = $page; } $return['total_found'] = $this->_total; $return['results'] = $pages; return $return; }
/** * * @param Model_Page_Front $page * @return \Context */ public function set_crumbs(Model_Page_Front $page) { $this->_crumbs = $page->breadcrumbs(); return $this; }
public function get_parse_meta() { $page_id = $this->param('page_id', NULL, TRUE); $fields = (array) $this->param('fields', array(), TRUE); $response = array(); $page = Model_Page_Front::findById($page_id); if ($page instanceof Model_Page_Front) { foreach ($fields as $field => $value) { $response[$field] = $page->parse_meta($field, $value); } } $this->response($response); }
}); // Сохранение контента частей страниц Observer::observe('page_edit_after_save', function ($page) { $parts = Arr::get(Request::initial()->post(), 'part_content', array()); $indexable_content = ''; foreach ($parts as $id => $content) { $part = ORM::factory('page_part', (int) $id); if ((bool) $part->is_indexable) { $indexable_content .= ' ' . $part->content; } if ($content == $part->content) { continue; } $part->values(array('content' => $content))->save(); } if (in_array($page->status_id, Model_Page_Front::get_statuses())) { Search::instance()->add_to_index('pages', $page->id, $page->title, $indexable_content, '', array('uri' => $page->get_uri())); } else { Search::instance()->remove_from_index('pages', $page->id); } }); Observer::observe('update_search_index', function () { $pages = ORM::factory('page')->find_all(); foreach ($pages as $page) { $indexable_content = ''; $parts = ORM::factory('page_part')->where('page_id', '=', $page->id)->where('is_indexable', '=', 1)->find_all(); foreach ($parts as $part) { $indexable_content .= ' ' . $part->content; } Search::instance()->add_to_index('pages', $page->id, $page->title, $indexable_content, '', array('uri' => $page->get_uri())); }
/** * * @return Model_Page_Front */ public function get_current_page() { if (!$this->current_page) { $this->current_page = Model_Page_Front::findById($this->get_page_id()); } return $this->current_page; }
<?php defined('SYSPATH') or die('No direct script access.'); if ($plugin->get('maintenance_mode') == Config::YES and !Auth::is_logged_in()) { Observer::observe('frontpage_requested', function () { $page = DB::select()->from('pages')->where('behavior_id', '=', 'maintenance_mode')->limit(1)->as_object()->execute()->current(); if ($page) { $page = Model_Page_Front::find($page->slug); // if we fund it, display it! if (is_object($page)) { echo Response::factory()->status(403)->body($page->render_layout()); exit; } } else { throw new HTTP_Exception_403('Maintenance mode'); exit; } }); }