/** * nav() walker function * @param array $sitemap * @param array $args * @param string $parent */ function nav_walker($sitemap, $args, $parent = '') { $output = ''; foreach ($sitemap as $slug => $page) { if ($slug == 'home') { $slug = ''; } // Prep for page_meta $page['slug'] = $slug; if (!Xysti::meta('hidden', $page)) { // Format the URI $uri = $parent . $slug; $current_depth = Xysti::uri_count($uri); // If this page has children and we haven't reached the max depth if (isset($page['/']) && is_array($page['/']) && $current_depth < $args['depth']) { $dropdown = TRUE; } else { $dropdown = FALSE; } // Is this the active page if (URI::segment($current_depth) == $uri) { $is_active = TRUE; } else { $is_active = FALSE; } // Now the output $output .= '<li class="'; if ($dropdown) { $output .= 'dropdown'; } if ($is_active) { $output .= ' active'; } //$output .= ' data-depth="' . $current_depth . '"'; if (isset($page['href'])) { $output .= '"><a href="' . Xysti::meta('href', $page) . '"'; } else { $output .= '"><a href="' . $uri . '"'; } if ($dropdown) { $output .= ' class="dropdown-toggle" data-toggle="dropdown"'; } $output .= '>' . Xysti::meta('title', $page); if ($dropdown) { $output .= ' <b class="caret"></b>'; } $output .= '</a>'; if ($dropdown) { $output .= PHP_EOL . '<ul class="dropdown-menu">' . PHP_EOL; // Lets go deeper.. $output .= nav_walker($page['/'], $args, $uri . '/'); $output .= '</ul>' . PHP_EOL; } $output .= '</li>' . PHP_EOL; } } return $output; }
function sitemap_xml_walk($sitemap, $parent = '') { $output = ''; foreach ($sitemap as $slug => $page) { $uri = $parent . $slug; // If hidden if (!Xysti::meta('disabled', $page) && !Xysti::meta('auth', $page)) { $output .= '<url>' . PHP_EOL; $output .= '<loc>' . URL::base() . '/' . $uri . '</loc>' . PHP_EOL; foreach (array('lastmod', 'changefreq', 'priority') as $attr) { if (isset($page['sitemap'][$attr])) { $output .= '<' . $attr . '>' . $page['sitemap'][$attr] . '</' . $attr . '>' . PHP_EOL; } } $output .= '</url>' . PHP_EOL; } // If children if (isset($page['/']) && is_array($page['/'])) { $output .= sitemap_xml_walk($page['/'], $uri . '/'); } } return $output; }
/** * Page variable * * Checks wether a page variable is set in the sitemap and returns it * @param string $request The variable key to return * @param mixed $uri Optional segment # or URI * @return mixed */ public static function page($request, $uri = NULL) { // Use current page if no second argument if (is_null($uri)) { // Check for a cached page if (is_null(Xysti::$page)) { Xysti::$page = Xysti::sitemap_page_walk(Xysti::uri_array()); } // Take the page from the cache $page = Xysti::$page; // Segment number specified } elseif (is_int($uri)) { $page = Xysti::sitemap_page_walk(Xysti::uri_array(), $uri); // Segment string specified } elseif (is_string($uri)) { $page = Xysti::sitemap_page_walk(Xysti::uri_array($uri), Xysti::uri_count($uri)); // Segment array specified } elseif (is_string($uri)) { $page = Xysti::sitemap_page_walk(Xysti::uri_array($uri), Xysti::uri_count($uri)); } else { //Log::write('error', 'Unexpected Xysti::page(' . $request . ',' . $uri . ') call at ' . URI::current() . '.'); return Xysti::error(500, 'Unexpected Xysti::page(' . $request . ',' . $uri . ') call at ' . URI::current() . '.'); } // Fetch the meta regardless of whether a sitemap entry has been found return Xysti::meta($request, $page); // Page was found // @todo Remove this if statement on confirmation of working if ($page) { return Xysti::meta($request, $page); } else { //Log::write('error', 'Xysti::page(' . $request . ',' . $uri . ') could not be found at ' . URI::current() . '.'); return FALSE; } }