/** * Return an adjacent page * Internal use * * @param FTL_Binding object * @param String Mode. 'prev' or 'next' * * @return Mixed Page array or FALSE if no page was found. * */ private static function get_adjacent_page(FTL_Binding $tag, $mode = 'prev') { $mode = $mode == 'prev' ? -1 : 1; $menu_name = $tag->getAttribute('menu'); $menu_name = is_null($menu_name) ? 'main' : $menu_name; $id_menu = 1; // $current_page = self::$context->registry('page'); // Get the current page: Fall down to registry if no one found in tag $current_page = $tag->get('page'); foreach (self::registry('menus') as $menu) { if ($menu_name == $menu['name']) { $id_menu = $menu['id_menu']; } } $level = is_null($tag->getAttribute('level')) ? 0 : $tag->getAttribute('level'); // Order the pages, because the are not. if (is_null(self::$ordered_pages)) { self::$ordered_pages = array(); self::order_pages(self::registry('pages'), self::$ordered_pages); } // Filter by menu and asked level : We only need the asked level pages ! $pages = array(); foreach (self::$ordered_pages as $p) { if ($p['level'] == $level && $p['id_menu'] == $id_menu) { $pages[] = $p; } } // Filter on 'appears'=>'1' $pages = array_values(array_filter($pages, array(__CLASS__, '_filter_appearing_pages'))); foreach ($pages as $idx => $page) { if ($page['id_page'] == $current_page['id_page']) { if (!empty($pages[$idx + $mode])) { return $pages[$idx + $mode]; } } } return FALSE; }
public function index() { // Init the Page TagManager TagManager_Page::init(); }
/** * Categories tag * Get the categories list from within the current page or globally * * */ public static function tag_categories($tag) { // Tag cache if (($str = self::get_cache($tag)) !== FALSE) { return $str; } // Store of all categories if (self::$categories === FALSE) { self::$categories = self::get_categories($tag, self::get_asked_page($tag)); } // Tag expand $str = ''; foreach (self::$categories as $category) { $tag->locals->category = $category; $str .= $tag->expand(); } $output = self::wrap($tag, $str); // Tag cache self::set_cache($tag, $output); return $output; }
/** * Return a tree navigation based on the given helper. * * @param FTL_Binding object * */ public static function tag_tree_navigation($tag) { // Current page $page = $tag->locals->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 = 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']; } } // If set, attribute level, else parent page level + 1 $from_level = isset($tag->attr['level']) ? $tag->attr['level'] : 0; // $from_level = (isset($tag->attr['level']) ) ? $tag->attr['level'] : FALSE ; // If set, depth $depth = isset($tag->attr['depth']) ? $tag->attr['depth'] : -1; // Attribute : active class, first_class, last_class $active_class = isset($tag->attr['active_class']) ? $tag->attr['active_class'] : 'active'; $first_class = isset($tag->attr['first_class']) ? $tag->attr['first_class'] : ''; $last_class = isset($tag->attr['last_class']) ? $tag->attr['last_class'] : ''; // Display hidden navigation elements ? $display_hidden = isset($tag->attr['display_hidden']) ? TRUE : FALSE; // Includes articles as menu elements $with_articles = isset($tag->attr['articles']) ? TRUE : FALSE; // Attribute : HTML Tree container ID & class attribute $id = isset($tag->attr['id']) ? $tag->attr['id'] : NULL; if (strpos($id, 'id') !== FALSE) { $id = str_replace('\'', '"', $id); } $class = isset($tag->attr['class']) ? $tag->attr['class'] : NULL; if (strpos($active_class, 'class') !== FALSE) { $active_class = str_replace('\'', '"', $active_class); } // Attribute : Use lang_url or url ? // $lang_url = (isset($tag->attr['lang']) && $tag->attr['lang'] === 'TRUE') ? TRUE : FALSE ; // if ($lang_url == FALSE) // $lang_url = (isset($tag->attr['lang_url']) && $tag->attr['lang_url'] === 'TRUE') ? TRUE : FALSE ; // Attribute : Helper to use to print out the tree navigation $helper = isset($tag->attr['helper']) && $tag->attr['helper'] != '' ? $tag->attr['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; /* 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; $parent_page = array(); // 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_values(array_filter($pages, create_function('$row','return $row["id_page"] == "'. $parent_page['id_parent'] .'";'))); $potential_parent_page = array(); foreach ($pages as $p) { if ($p['id_page'] == $parent_page['id_parent']) { $potential_parent_page = $p; break; } } // if (isset($potential_parent_page[0])) 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'))); } // $nav_pages = array_filter($nav_pages, create_function('$row','return ($row["id_menu"] == "'. $id_menu .'") ;')); $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) { $uri = preg_replace("|/*(.+?)/*\$|", "\\1", self::$ci->uri->uri_string); $uri_segments = explode('/', $uri); $current_article_uri = array_pop($uri_segments); $tag->attr['scope'] = 'global'; $articles = TagManager_Page::get_articles($tag); foreach ($articles as &$article) { if (array_pop(explode('/', $article['url'])) == $current_article_uri) { $article['active_class'] = $active_class; } } } // 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); } }