Example #1
0
 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);
 }
Example #2
0
 public function page_by_slug()
 {
     if (!$this->router()->param('slug')) {
         return FALSE;
     }
     if (($page = Model_Page_Front::find($slug, FALSE, $this->page())) === FALSE) {
         return $this->execute();
     }
     $this->_page = $page;
 }
Example #3
0
 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();
     }
 }
Example #4
0
 public function action_index()
 {
     Observer::notify('frontpage_requested', $this->request->uri());
     $page = Model_Page_Front::find($this->request->uri());
     if ($page instanceof Model_Page_Front) {
         if ($page->use_redirect and !empty($page->redirect_url)) {
             HTTP::redirect($page->redirect_url, 301);
         }
         return $this->_render($page);
     } else {
         // Если включен поиск похожей страницы и она найдена, производим
         // редирект на найденую страницу
         if (Config::get('site', 'find_similar') == Config::YES) {
             if (($uri = Model_Page_Front::find_similar($this->request->uri())) !== FALSE) {
                 HTTP::redirect(URL::frontend($uri), 301);
             }
         }
         Model_Page_Front::not_found();
     }
 }
Example #5
0
<?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;
        }
    });
}