/** * * */ public static function init() { self::$ci =& get_instance(); // Models self::$ci->load->model(array('article_model', 'page_model', 'url_model'), '', TRUE); // Helpers self::$ci->load->helper('text'); // Pages, Page self::register('pages', Pages::get_pages()); self::register('page', self::get_current_page()); // Current page $page = self::registry('page'); // Last option : Even the 404 wasn't found... if (empty($page['id_page'])) { echo 'Not found'; die; } if (!empty($page['link'])) { // External redirect if ($page['link_type'] == 'external') { redirect($page['link']); die; } else { self::$ci->load->helper('array_helper'); // Page if ($page['link_type'] == 'page') { if ($page = array_get(self::registry('pages'), $page['link_id'], 'id_page')) { redirect($page['absolute_url']); } } // Article if ($page['link_type'] == 'article') { if (count(self::get_uri_segments()) == 1) { redirect($page['absolute_url']); } } } } // Can we get one article from the URL ? $entity = self::get_entity(); if ($entity['type'] == 'article') { $article = self::$ci->article_model->get_by_id($entity['id_entity'], Settings::get_lang()); $articles = array($article); TagManager_Article::init_articles_urls($articles); $article = $articles[0]; } if (!empty($article)) { self::register('article', $article); } // Event : On before render $event_data = array('entity' => $entity, 'article' => self::registry('article')); Event::fire('Page.render.before', $event_data); self::$view = self::_get_page_view($page); self::render(); }
/** * Search results tag * Parent tag for results * * @param FTL_Binding * @return string * @usage <ion:search:results> * */ public static function tag_search_results(FTL_Binding $tag) { $str = ''; // POST realm $realm = $tag->get('realm'); $tag->set('count', 0); if ($realm !== FALSE && $realm != '') { // Get the results if (is_null(self::$_articles)) { // Loads the serach module model self::$ci->load->model('search_model', '', TRUE); $articles = self::$ci->search_model->get_articles($realm); if (!empty($articles)) { // arrays of keys, for multisorting $knum = $kdate = array(); $unique = array(); foreach ($articles as $key => &$article) { // remove duplicates if (!in_array($article['id_article'], $unique)) { $unique[] = $article['id_article']; // set number of found words preg_match_all('#' . $realm . '#i', $article['title'] . ' ' . $article['content'], $match); $num = count($match[0]); $article['nb_words'] = $knum[$key] = $num; $kdate[$key] = strtotime($article['date']); } else { unset($articles[$key]); } } // Sort the results by realm occurences DESC first, by date DESC second. array_multisort($knum, SORT_DESC, SORT_NUMERIC, $kdate, SORT_DESC, SORT_NUMERIC, $articles); } // Init the articles URLs TagManager_Article::init_articles_urls($articles); // Adds the page URL to each article self::init_pages_urls($articles); self::$_articles = $articles; } // Add the number of result to the tag data $count = count(self::$_articles); $tag->set('count', $count); $tag->set('results', self::$_articles); foreach (self::$_articles as $key => $_article) { // The tag should at least do 1 expand to get the child "loop" attribute if ($tag->getAttribute('loop') === FALSE) { return $tag->expand(); } else { $tag->set('result', $_article); $tag->set('count', $count); $tag->set('index', $key); $str .= $tag->expand(); } } } // Expand the tag if no articles : Allows the children tags to be processed even not results were found // Must not be done if articles or this add one unwanted expand. if (empty(self::$_articles)) { $str .= $tag->expand(); } return $str; }
/** * Return a tree navigation based on the given helper. * One helper is needed to use this tag. * The default helper is /application/helpers/navigation_helper->get_tree_navigation() * If you wish to change the * * @param FTL_Binding object * * @return string * * @usage <ion:tree_navigation [helper="navigation::your_helper_method"] /> * */ public static function tag_tree_navigation(FTL_Binding $tag) { // Page : Asked one through the page tag $page = $tag->get('page'); // Current page if (is_null($page)) { $page = self::registry('page'); } // If 404 : Put empty vars, so the menu will prints out without errors /* if ( !isset($page['id_page'])) { $page = array( 'id_page' => '', 'id_parent' => '' ); } */ // Menu : Main menu by default $menu_name = $tag->getAttribute('menu', 'main'); $id_menu = 1; foreach (self::registry('menus') as $menu) { if ($menu_name == $menu['name']) { $id_menu = $menu['id_menu']; break; } } // Attribute level, else parent page level + 1 $from_level = $tag->getAttribute('level', 0); // Depth $depth = $tag->getAttribute('depth', -1); // Attribute : active class, first_class, last_class $active_class = $tag->getAttribute('active_class', 'active'); $first_class = $tag->getAttribute('first_class', ''); $last_class = $tag->getAttribute('last_class', ''); // Display hidden navigation elements ? $display_hidden = $tag->getAttribute('display_hidden', FALSE); // Includes articles as menu elements $with_articles = $tag->getAttribute('articles', FALSE); // Attribute : HTML Tree container ID & class attribute $id = $tag->getAttribute('id'); if (strpos($id, 'id') !== FALSE) { $id = str_replace('\'', '"', $id); } $class = $tag->getAttribute('class'); if (strpos($active_class, 'class') !== FALSE) { $active_class = str_replace('\'', '"', $active_class); } // Attribute : Helper to use to print out the tree navigation $helper = $tag->getAttribute('helper', 'navigation'); // Get helper method $helper_function = substr(strrchr($helper, ':'), 1) ? substr(strrchr($helper, ':'), 1) : 'get_tree_navigation'; $helper = strpos($helper, ':') !== FALSE ? substr($helper, 0, strpos($helper, ':')) : $helper; // load the helper self::$ci->load->helper($helper); // Page from locals : By ref because of active_class definition // $pages = $tag->locals->_pages; $pages = self::registry('pages'); /* Get the reference parent page ID * Note : this is depending on the whished level. * If the curent page level > asked level, we need to find recursively the parent page which has the good level. * This is done to avoid tree cut when navigation to a child page * * e.g : * * On the "services" page and each subpage, we want the tree navigation composed by the sub-pages of "services" * We are in the page "offer" * We have to find out that the level 1 parent is "services" * * Page structure Level * * home 0 * |_ about 1 * |_ services 1 <- We want all the nested nav starting at level 1 from this parent page * |_ development 2 * |_ design 2 * |_ offer 3 <- We are here. * |_ portfolio 3 */ $page_level = isset($page['level']) ? $page['level'] : 0; // Asked Level exists $parent_page = array('id_page' => $from_level > 0 ? $page['id_page'] : 0, 'id_parent' => isset($page['id_parent']) ? $page['id_parent'] : 0); if ($from_level !== FALSE) { $parent_page = array('id_page' => $from_level > 0 ? $page['id_page'] : 0, 'id_parent' => isset($page['id_parent']) ? $page['id_parent'] : 0); } else { foreach ($pages as $p) { // Parent page is the id_subnav page if ($p['id_page'] == $page['id_subnav']) { $parent_page = $p; } } } // Find out the wished parent page while ($page_level >= $from_level && $from_level > 0) { $potential_parent_page = array(); foreach ($pages as $p) { if ($p['id_page'] == $parent_page['id_parent']) { $potential_parent_page = $p; break; } } if (!empty($potential_parent_page)) { $parent_page = $potential_parent_page; $page_level = $parent_page['level']; } else { $page_level--; } } // Active pages array. Array of ID $active_pages = Structure::get_active_pages($pages, $page['id_page']); foreach ($pages as $key => $p) { $pages[$key]['active_class'] = in_array($p['id_page'], $active_pages) ? $active_class : ''; } // Filter on 'appears'=>'1' $nav_pages = $pages; if ($display_hidden === FALSE) { $nav_pages = array_values(array_filter($pages, array('TagManager_Page', '_filter_appearing_pages'))); } $final_nav_pages = $nav_pages_list = array(); foreach ($nav_pages as $k => $np) { if ($np['id_menu'] == $id_menu) { $final_nav_pages[] = $np; $nav_pages_list[] = $np['id_page']; } } // Should we include articles ? $articles = FALSE; if ($with_articles == TRUE) { $entity = self::get_entity(); $id_active_article = $entity['type'] == 'article' ? $entity['id_entity'] : NULL; foreach ($final_nav_pages as $key => $p) { // TODO : Change for future "Articles" lib call $tag->set('page', $p); $articles = TagManager_Article::get_articles($tag); // Set active article if (!is_null($id_active_article)) { foreach ($articles as $akey => $a) { if ($a['id_article'] == $id_active_article) { $articles[$akey]['active_class'] = $active_class; $articles[$akey]['is_active'] = TRUE; } } } $final_nav_pages[$key]['articles'] = $articles; } } // Get the tree navigation array $tree = Structure::get_tree_navigation($final_nav_pages, $parent_page['id_page'], $from_level, $depth, $articles); // Return the helper function if (function_exists($helper_function)) { return call_user_func($helper_function, $tree, $id, $class, $first_class, $last_class); } }
/** * * @param FTL_Binding $tag * @return string * */ public static function tag_article_deny(FTL_Binding $tag) { // Set this tag as "process tag" $tag->setAsProcessTag(); // 1. Try to get from tag's data array $value = $tag->getValue('deny_code', 'article'); $resource = 'frontend/article/' . $tag->getValue('id_article', 'article'); if (Authority::cannot('access', $resource, NULL, TRUE)) { return self::output_value($tag, $value); } else { if ($tag->getAttribute('is') == '') { self::$trigger_else = 0; return self::wrap($tag, $tag->expand()); } } return ''; }