示例#1
0
 /**
  * Converts the shorthand sitemap config array into a tree structure.
  *
  * @param array          $children    The items to add as child nodes to the given $parent
  * @param TreeSitemap    $parent      The parent tree object
  * @param string         $path        The root-relative base url
  *
  * @return boolean true if ok, otherwise false
  */
 protected function expandChildNodes(SitemapTree $parent, array $children, $path = '/')
 {
     foreach ($children as $key => $value) {
         if (is_numeric($key) && is_string($value)) {
             $nodeValue = $value;
         } elseif (is_string($key) && is_array($value)) {
             $nodeValue = $key;
         } else {
             $nodeValue = $key;
             if ($value != '~') {
                 # assume a hardcoded url: 'Google' => 'google.com'
                 $url = $value;
             }
         }
         $node = $parent->addNode($nodeValue);
         $slug = $this->slugify($nodeValue);
         $node->setSlug($slug);
         $href = isset($url) ? $url : $path . $slug;
         $node->setHref($href);
         # recurse
         if (is_array($value)) {
             $this->expandChildNodes($node, $value, $path . $slug . '/');
         }
     }
     return $parent;
 }