/** * * */ 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; }