Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * Converts a serialized array back into a SitemapTree object
  */
 public function unserialize($importArray = array())
 {
     foreach ($importArray as $nodeArray) {
         if (isset($nodeArray['name']) && isset($nodeArray['href'])) {
             $node = new SitemapTree($nodeArray['name']);
             $node->setHref($nodeArray['href']);
             if (isset($nodeArray['nodes']) && is_array($nodeArray['nodes'])) {
                 $node->unserialize($nodeArray['nodes']);
             }
             $this->addNode($node);
         }
     }
 }