select('[slug="'.$requested_page.'" and locale="'.Pages::$locale.'"]', null); if(count($page) == 0) { $page = Pages::$pages->select('[slug="'.$requested_page.'" and locale="'.Site::getDefaultSiteLocale().'"]', null); } } else { $page = Pages::$pages->select('[slug="'.$requested_page.'" and locale="'.Pages::$locale.'"]', null); } return $page; } /** * Load current page * * @global string $defpage default page * @param array $data uri * @return string */ public static function lowLoader($data) { $defpage = Option::get('defaultpage'); if (Arr::keyExists(Site::getLocales(), $data[0])) { $locale = $data[0]; if ($locale == Site::getDefaultSiteLocale()) { if ((isset($data[2])) && ($data[2] != '')) { Request::redirect(Site::url().'/'.$data[1].'/'.$data[2], 301); } else { Request::redirect(Site::url().'/'.(isset($data[1]) ? $data[1] : '') , 301); } } $data[0] = isset($data[1]) ? $data[1] : ''; $data[1] = isset($data[2]) ? $data[2] : ''; if ($data[0] == '') unset($data[0]); if ($data[1] == '') unset($data[1]); } else { $locale = Site::getDefaultSiteLocale(); } Pages::$locale = $locale; Cookie::set('site_locale', $locale); // If data count 2 then it has Parent/Child if (count($data) >= 2) { // If exists parent file if (count(Pages::$pages->select('[slug="'.$data[0].'" and locale="'.$locale.'"]')) !== 0) { // Get child file and get parent page name $child_page = Pages::$pages->select('[slug="'.$data[1].'" and locale="'.$locale.'"]', null); // If child page parent is not empty then get his parent if (count($child_page) == 0) { $c_p = ''; } else { if ($child_page['parent'] != '') { $c_p = $child_page['parent']; } else { $c_p = ''; } } // Hack For old Monstra $child_page['access'] = (isset($child_page['access'])) ? $child_page['access'] : 'public' ; // Check is child_parent -> request parent if ($c_p == $data[0]) { if (count($data) < 3) { // Checking only for the parent and one child, the remaining issue 404 if ((($child_page['status'] == 'published') or (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) and ($child_page['access'] == 'public')) { $id = $data[1]; } elseif (($child_page['access'] == 'registered') and (Session::exists('user_id')) and ($child_page['status'] == 'published')) { $id = $data[1]; } else { $id = 'error404'; Response::status(404); } } else { $id = 'error404'; Response::status(404); } } else { $id = 'error404'; Response::status(404); } } else { $id = 'error404'; Response::status(404); } } else { // Only parent page come if (empty($data[0])) { $id = $defpage; } else { // Get current page $current_page = Pages::$pages->select('[slug="'.$data[0].'" and locale="'.$locale.'"]', null); // Hack For old Monstra $current_page['access'] = (isset($current_page['access'])) ? $current_page['access'] : 'public' ; if (count($current_page) != 0) { if ( ! empty($current_page['parent'])) { $c_p = $current_page['parent']; } else { $c_p = ''; } } else { $c_p = ''; } // Check if this page has parent if ($c_p !== '') { if ($c_p == $data[0]) { if (count(Pages::$pages->select('[slug="'.$data[0].'"] and locale="'.$locale.'"]', null)) != 0) { if ((($current_page['status'] == 'published') or (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) and ($current_page['access'] == 'public')) { $id = $data[0]; } elseif (($current_page['access'] == 'registered') and (Session::exists('user_id')) and ($current_page['status'] == 'published')) { $id = $data[0]; } else { $id = 'error404'; Response::status(404); } } else { $id = 'error404'; Response::status(404); } } else { $id = 'error404'; Response::status(404); } } else { if (count(Pages::$pages->select('[slug="'.$data[0].'" and locale="'.$locale.'"]', null)) != 0) { if ((($current_page['status'] == 'published') or (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) and ($current_page['access'] == 'public')) { $id = $data[0]; } elseif (($current_page['access'] == 'registered') and (Session::exists('user_id')) and ($current_page['status'] == 'published')) { $id = $data[0]; } else { $id = 'error404'; Response::status(404); } } else { $id = 'error404'; Response::status(404); } } } } // Return page name/id to load return $id; } /** * Get pages template * * @return string */ public static function template() { if (Pages::$page['template'] == '') return 'index'; else return Pages::$page['template']; } /** * Get pages contents * * @return string */ public static function content($slug = '', $locale = '') { if ( ! empty($slug)) { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; $page = Table::factory('pages')->select('[slug="'.$slug.'" and locale="'.$locale.'"]', null); if ( ! empty($page)) { $content = Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt')); $content = Filter::apply('content', $content); return $content; } else { return ''; } } else { return Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . Pages::$page['id'] . '.page.txt')); } } /** * Get pages title * * * echo Page::title(); * * * @return string */ public static function title() { return !empty(Pages::$page['meta_title']) ? Pages::$page['meta_title'] : Pages::$page['title']; } /** * Get pages Description * * * echo Page::description(); * * * @return string */ public static function description() { return Pages::$page['description']; } /** * Get pages Keywords * * * echo Page::keywords(); * * * @return string */ public static function keywords() { return Pages::$page['keywords']; } /** * Get pages */ public static function getPages($locale = '') { // Init vars $pages_array = array(); $count = 0; $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; // Get pages table $pages = new Table('pages'); // Get Pages List $pages_list = $pages->select('[slug!="error404" and status="published" and locale="'.$locale.'"]'); foreach ($pages_list as $page) { $pages_array[$count]['title'] = Html::toText($page['title']); $pages_array[$count]['meta_title'] = !empty($page['meta_title']) ? Html::toText($page['meta_title']) : $page['title']; $pages_array[$count]['parent'] = $page['parent']; $pages_array[$count]['date'] = $page['date']; $pages_array[$count]['author'] = $page['author']; $pages_array[$count]['locale'] = $page['locale']; $pages_array[$count]['slug'] = ($page['slug'] == Option::get('defaultpage')) ? '' : $page['slug'] ; if (isset($page['parent'])) { $c_p = $page['parent']; } else { $c_p = ''; } if ($c_p != '') { $_page = $pages->select('[slug="'.$page['parent'].'" and locale="'.$locale.'"]', null); if (isset($_page['title'])) { $_title = $_page['title']; } else { $_title = ''; } $pages_array[$count]['sort'] = $_title . ' ' . $page['title']; } else { $pages_array[$count]['sort'] = $page['title']; } $_title = ''; $count++; } // Sort pages $_pages_list = Arr::subvalSort($pages_array, 'sort'); // return return $_pages_list; } } /** * Page class */ class Page extends Pages { /** * Get date of current page * * * echo Page::date(); * * * @param string $format Date format * @return string */ public static function date($format = 'Y-m-d') { return Date::format(Pages::$page['date'], $format); } /** * Get author of current page * * * echo Page::author(); * * * @return string */ public static function author() { return Pages::$page['author']; } /** * Get children pages for a specific parent page * * * $pages = Page::children('page'); * * * @param string $parent Parent page * @return array */ public static function children($parent, $locale = '') { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; return Pages::$pages->select('[parent="'.(string) $parent.'" and locale="'.$locale.'"]', 'all'); } /** * Get the available children pages for requested page. * * * echo Page::available(); * * */ public static function available($locale = '') { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; $pages = Pages::$pages->select('[parent="'.Pages::$requested_page.'" and locale="'.$locale.'"]', 'all'); // Display view View::factory('box/pages/views/frontend/available_pages') ->assign('pages', $pages) ->display(); } /** * Get page breadcrumbs * * * echo Page::breadcrumbs(); * * */ public static function breadcrumbs($locale = '') { if (Uri::command() == 'pages') { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; $current_page = Pages::$requested_page; $parent_page = ''; if ($current_page !== 'error404') { $page = Pages::$pages->select('[slug="'.$current_page.'" and locale="'.$locale.'"]', null); if (trim($page['parent']) !== '') { $parent = true; $parent_page = Pages::$pages->select('[slug="'.$page['parent'].'" and locale="'.$locale.'"]', null); } else { $parent = false; } // Display view View::factory('box/pages/views/frontend/breadcrumbs') ->assign('current_page', $current_page) ->assign('page', $page) ->assign('parent', $parent) ->assign('parent_page', $parent_page) ->display(); } } } /** * Get page url * * * echo Page::url(); * * */ public static function url() { return Option::get('siteurl').'/'.Pages::$page['slug']; } /** * Get page slug * * * echo Page::slug(); * * */ public static function slug() { return Pages::$page['slug']; } /** * Get page meta robots * * * echo Page::robots(); * * */ public static function robots() { if (Pages::$page !== null) { $_index = (isset(Pages::$page['robots_index'])) ? Pages::$page['robots_index'] : ''; $_follow = (isset(Pages::$page['robots_follow'])) ? Pages::$page['robots_follow'] : ''; $robots = ( ! empty($_index) && ! empty($_follow)) ? $_index.', '.$_follow : ''; } else { $robots = ''; } return $robots; } public static function _date($attributes) { return Page::date((isset($attributes['format'])) ? $attributes['format'] : 'Y-m-d'); } public static function _content($attributes) { return Pages::content((isset($attributes['name']) ? $attributes['name'] : '')); } } /** * Add new shortcodes {page_author} {page_slug} {page_url} {page_date} {page_content} */ Shortcode::add('page_author', 'Page::author'); Shortcode::add('page_slug', 'Page::slug'); Shortcode::add('page_url', 'Page::url'); Shortcode::add('page_content', 'Page::_content'); Shortcode::add('page_date', 'Page::_date');