Ejemplo n.º 1
0
 /**
  * 
  * 
  */
 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();
 }
Ejemplo n.º 2
0
 /**
  * Navigation tag definition
  * @usage	
  *
  */
 public static function tag_navigation(FTL_Binding $tag)
 {
     $cache = $tag->getAttribute('cache', TRUE);
     // Tag cache
     if ($cache == TRUE && ($str = self::get_cache($tag)) !== FALSE) {
         return $str;
     }
     // Final string to print out.
     $str = '';
     // Helper / No helper ?
     $helper = $tag->getAttribute('helper');
     // Get the asked lang if any
     $lang = $tag->getAttribute('lang');
     // 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'];
         }
     }
     // Navigation level. FALSE if not defined
     $asked_level = $tag->getAttribute('level', FALSE);
     // Display hidden navigation elements ?
     $display_hidden = $tag->getAttribute('display_hidden', FALSE);
     // Current page
     $current_page = self::registry('page');
     // Attribute : active CSS class
     $active_class = $tag->getAttribute('active_class', 'active');
     if (strpos($active_class, 'class') !== FALSE) {
         $active_class = str_replace('\'', '"', $active_class);
     }
     // Pages : Current lang OR asked lang code pages.
     $global_pages = !is_null($lang) && Settings::get_lang() != $lang ? Pages::get_pages($lang) : self::registry('pages');
     // Add the active class key
     $id_current_page = !empty($current_page['id_page']) ? $current_page['id_page'] : FALSE;
     $active_pages = Structure::get_active_pages($global_pages, $id_current_page);
     foreach ($global_pages as &$page) {
         $page['title'] = $page['nav_title'] != '' ? $page['nav_title'] : $page['title'];
         // Add the active_class key
         $page['active_class'] = in_array($page['id_page'], $active_pages) ? $active_class : '';
         $page['is_active'] = in_array($page['id_page'], $active_pages);
         $page['id_navigation'] = $page['id_page'];
     }
     // Filter by menu and asked level : We only need the asked level pages !
     // $pages = array_filter($global_pages, create_function('$row','return ($row["level"] == "'. $asked_level .'" && $row["id_menu"] == "'. $id_menu .'") ;'));
     $pages = array();
     $parent_page = array();
     // Only conserve the menu asked pages
     foreach ($global_pages as $key => $p) {
         if ($p['id_menu'] != $id_menu) {
             unset($global_pages[$key]);
         }
     }
     // Asked Level exists
     if ($asked_level !== FALSE) {
         foreach ($global_pages as $p) {
             if ($p['level'] == $asked_level && $p['id_menu'] == $id_menu) {
                 $pages[] = $p;
             }
         }
     } else {
         foreach ($global_pages as $p) {
             // Child pages of id_subnav
             if ($p['id_parent'] == $current_page['id_subnav']) {
                 $pages[] = $p;
             }
             // Parent page is the id_subnav page
             if ($p['id_page'] == $current_page['id_subnav']) {
                 $parent_page = $p;
             }
         }
     }
     // Filter on 'appears'=>'1'
     if ($display_hidden == FALSE) {
         $pages = array_values(array_filter($pages, array('TagManager_Page', '_filter_appearing_pages')));
     }
     // Get the parent page from one level upper
     if ($asked_level > 0) {
         $parent_pages = array();
         foreach ($global_pages as $p) {
             if ($p['level'] == $asked_level - 1) {
                 $parent_pages[] = $p;
             }
         }
         foreach ($parent_pages as $p) {
             if ($p['active_class'] != '') {
                 $parent_page = $p;
             }
         }
     }
     // Filter the current level pages on the link with parent page
     if (!empty($parent_page)) {
         $o_pages = $pages;
         $pages = array();
         foreach ($o_pages as $p) {
             if ($p['id_parent'] == $parent_page['id_page']) {
                 $pages[] = $p;
             }
         }
     } else {
         if ($asked_level > 0) {
             $pages = array();
         }
     }
     if ($helper) {
         // Get helper method
         $helper_function = substr(strrchr($helper, ':'), 1) ? substr(strrchr($helper, ':'), 1) : 'get_navigation';
         $helper = strpos($helper, ':') !== FALSE ? substr($helper, 0, strpos($helper, ':')) : 'navigation';
         // load the helper
         self::$ci->load->helper($helper);
         // Return the helper function result
         if (function_exists($helper_function)) {
             // Set the helper
             $tag->setAttribute('helper', $helper . ':' . $helper_function);
             // Process the helper
             $value = self::helper_process($tag, $pages, $helper . ':' . $helper_function);
             $output = self::wrap($tag, $value);
             // Tag cache
             self::set_cache($tag, $output);
             return $output;
         }
         $error_message = 'Helper ' . $helper . ':' . $helper_function . '() not found';
     } else {
         foreach ($pages as $index => $p) {
             $tag->set('navigation', $p);
             $tag->set('page', $p);
             $tag->set('is_active', $p['is_active']);
             $tag->set('index', $index);
             $str .= $tag->expand();
         }
         $output = self::wrap($tag, $str);
         // Tag cache
         self::set_cache($tag, $output);
         return $output;
     }
     return self::show_tag_error($tag, $error_message);
 }
Ejemplo n.º 3
0
 /**
  * 
  * 
  */
 public static function init()
 {
     // parent::init('Page');
     self::$ci =& get_instance();
     // Article model
     self::$ci->load->model('article_model');
     self::$ci->load->model('page_model');
     // Helpers
     self::$ci->load->helper('text');
     $uri = preg_replace("|/*(.+?)/*\$|", "\\1", self::$ci->uri->uri_string);
     self::$uri_segments = explode('/', $uri);
     // Get pages and add them to the context
     self::$context->globals->pages = Pages::get_pages();
     // Pagination URI
     //		$uri_config = self::$ci->config->item('special_uri');
     //		$uri_config = array_flip($uri_config);
     //		self::pagination_uri = $uri_config['pagination'];
     // Set self::$context->globals->page
     self::add_globals();
     // Current page
     $page = self::$context->globals->page;
     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::$context->globals->pages, $page['link_id'], 'id_page')) {
                     redirect($page['absolute_url']);
                 }
             }
             // Article
             if ($page['link_type'] == 'article') {
                 if (count(self::$uri_segments) == 1) {
                     redirect($page['absolute_url']);
                 }
                 /*				
                 					$rel = explode('.', $page['link_id']);
                 
                 					if ($article_page = array_get(self::$context->globals->pages, $rel[0], 'id_page'))
                 					{
                 						$articles =  self::$ci->article_model->get_lang_list
                 						(
                 							array('id_article' => $rel[1]), 
                 							Settings::get_lang()
                 						);
                 						
                 						self::init_articles_urls($articles);
                 						$article = array_shift($articles);
                 
                 						if ($article['url'] != current_url())
                 						{
                 							redirect($article['url']);
                 						}
                 					}
                 */
             }
         }
     }
     // Can we get one article from the URL ?
     $article = self::get_article_from_url();
     if (!empty($article)) {
         self::$_article = $article;
         $page['view'] = $page['view_single'] != false ? $page['view_single'] : $page['view'];
     }
     self::$view = $page['view'] != false ? $page['view'] : Theme::get_default_view('page');
     self::render();
 }
Ejemplo n.º 4
0
 /**
  * Navigation tag definition
  * @usage	
  *
  */
 public static function tag_navigation($tag)
 {
     $cache = isset($tag->attr['cache']) && $tag->attr['cache'] == 'off' ? FALSE : TRUE;
     $error_message = '';
     // Tag cache
     if ($cache == TRUE && ($str = self::get_cache($tag)) !== FALSE) {
         return $str;
     }
     // Final string to print out.
     $str = '';
     // Helper / No helper ?
     // $tag->attr['no_helper'] : Will disapear in next versions... replaced by $tag->attr['helper']
     $no_helper = isset($tag->attr['no_helper']) ? TRUE : FALSE;
     $helper = isset($tag->attr['helper']) ? $tag->attr['helper'] : 'navigation';
     // Get the asked lang if any
     $lang = isset($tag->attr['lang']) ? $tag->attr['lang'] : FALSE;
     if ($helper == 'false' or $no_helper == TRUE) {
         $helper = FALSE;
     }
     // Menu : Main menu by default
     $menu_name = isset($tag->attr['menu']) ? $tag->attr['menu'] : 'main';
     $id_menu = 1;
     foreach ($tag->globals->menus as $menu) {
         if ($menu_name == $menu['name']) {
             $id_menu = $menu['id_menu'];
         }
     }
     // Navigation level. FALSE if not defined
     $asked_level = isset($tag->attr['level']) ? $tag->attr['level'] : FALSE;
     // Display hidden navigation elements ?
     $display_hidden = isset($tag->attr['display_hidden']) ? TRUE : FALSE;
     // Current page
     $current_page =& $tag->locals->page;
     // Attribute : active CSS class
     $active_class = isset($tag->attr['active_class']) ? $tag->attr['active_class'] : 'active';
     if (strpos($active_class, 'class') !== FALSE) {
         $active_class = str_replace('\'', '"', $active_class);
     }
     /*
      * Getting menu data
      *
      */
     // Pages : Current lang OR asked lang code pages.
     $global_pages = $lang !== FALSE && Settings::get_lang() != $lang ? Pages::get_pages($lang) : $tag->globals->pages;
     // Add the active class key
     $id_current_page = !empty($current_page['id_page']) ? $current_page['id_page'] : FALSE;
     $active_pages = Structure::get_active_pages($global_pages, $id_current_page);
     foreach ($global_pages as &$page) {
         // Add the active_class key
         $page['active_class'] = in_array($page['id_page'], $active_pages) ? $active_class : '';
     }
     // Filter by menu and asked level : We only need the asked level pages !
     // $pages = array_filter($global_pages, create_function('$row','return ($row["level"] == "'. $asked_level .'" && $row["id_menu"] == "'. $id_menu .'") ;'));
     $pages = array();
     $parent_page = array();
     // Asked Level exists
     if ($asked_level !== FALSE) {
         foreach ($global_pages as $p) {
             if ($p['level'] == $asked_level && $p['id_menu'] == $id_menu) {
                 $pages[] = $p;
             }
         }
     } else {
         foreach ($global_pages as $p) {
             // Child pages of id_subnav
             if ($p['id_parent'] == $tag->locals->page['id_subnav']) {
                 $pages[] = $p;
             }
             // Parent page is the id_subnav page
             if ($p['id_page'] == $tag->locals->page['id_subnav']) {
                 $parent_page = $p;
             }
         }
     }
     // Filter on 'appears'=>'1'
     if ($display_hidden == FALSE) {
         $pages = array_values(array_filter($pages, array('TagManager_Page', '_filter_appearing_pages')));
     }
     // Get the parent page from one level upper
     if ($asked_level > 0) {
         // $parent_pages = array_filter($global_pages, create_function('$row','return $row["level"] == "'. ($asked_level-1) .'";'));
         $parent_pages = array();
         foreach ($global_pages as $p) {
             if ($p['level'] == $asked_level - 1) {
                 $parent_pages[] = $p;
             }
         }
         // $parent_page = array_values(array_filter($parent_pages, create_function('$row','return $row["active_class"] != "";')));
         // $parent_page = ( ! empty($parent_page)) ? $parent_page[0] : FALSE;
         foreach ($parent_pages as $p) {
             if ($p['active_class'] != '') {
                 $parent_page = $p;
             }
         }
     }
     // Filter the current level pages on the link with parent page
     if (!empty($parent_page)) {
         // $pages = array_filter($pages, create_function('$row','return $row["id_parent"] == "'. $parent_page['id_page'] .'";'));
         $o_pages = $pages;
         $pages = array();
         foreach ($o_pages as $p) {
             if ($p['id_parent'] == $parent_page['id_page']) {
                 $pages[] = $p;
             }
         }
     } else {
         if ($asked_level > 0) {
             $pages = array();
         }
     }
     if ($helper !== FALSE) {
         // Get helper method
         $helper_function = substr(strrchr($helper, ':'), 1) ? substr(strrchr($helper, ':'), 1) : 'get_navigation';
         $helper = strpos($helper, ':') !== FALSE ? substr($helper, 0, strpos($helper, ':')) : $helper;
         // load the helper
         self::$ci->load->helper($helper);
         // Return the helper function result
         if (function_exists($helper_function)) {
             //$nav = call_user_func($helper_function, $pages);
             $tag->attr['helper'] = $helper . ':' . $helper_function;
             $output = self::wrap($tag, $pages);
             // Tag cache
             self::set_cache($tag, $output);
             return $output;
         }
         $error_message = 'Helper ' . $helper . ':' . $helper_function . '() not found';
     } else {
         foreach ($pages as $index => $p) {
             $tag->locals->page = $p;
             $tag->locals->index = $index;
             $str .= $tag->expand();
         }
         $output = self::wrap($tag, $str);
         // Tag cache
         self::set_cache($tag, $output);
         return $output;
     }
     return self::show_tag_error($tag->name, $error_message);
 }