/** * Reads the child node along with the settings specified in the index the adds it to the tree. * * @param \DOMNode $node * @param WebPage $parentPage */ private function readInChildNode(\DOMNode $node, WebPage $parentPage = null) { $webPage = $parentPage; $settings = new WebPageSettings(); if (strcmp($node->nodeName, 'document') == 0) { $attributes = $node->attributes; $title = null; $src = null; $tag = array(); $order = null; $category = array(); if (isset($attributes)) { for ($i = 0; $i < $attributes->length; $i++) { $attribute = $attributes->item($i)->nodeName; switch ($attribute) { case 'title': $title = $attributes->item($i)->nodeValue; break; case 'src': $src = $attributes->item($i)->nodeValue; if ($src[0] != '/') { $src = basename($this->retriever->getFullFilePath($src)); } break; case 'category': // if category is set in XML, then overrides the web settings // TODO: should have a setting for if to use xml or web settings $category = explode(',', $attributes->item($i)->nodeValue); break; // case 'tag': // $tag = explode( ',', $attributes->item( $i )->nodeValue ); // break; // case 'tag': // $tag = explode( ',', $attributes->item( $i )->nodeValue ); // break; case 'order': $order = $attributes->item($i)->nodeValue; break; // /* future cases // case 'overwrite-existing': // break; // */ // /* future cases // case 'overwrite-existing': // break; // */ default: break; } } } if (!is_null($category) && is_array($category)) { foreach ($category as $index => $cat) { $cat_id = wp_create_category(trim($cat)); $settings->addCategory(intval($cat_id)); } } /* if ( !is_null( $tag ) && is_array( $tag ) ) { foreach ( $tag as $t ) { //TODO: support tags } }*/ $webPage = new WebPage($this->retriever, $title, $src, null, $settings); $webPage->setOrderPosition($order); if (is_null($parentPage)) { $this->trees[] = $webPage; } else { $parentPage->addChild($webPage); } } $children = $node->childNodes; if (isset($children)) { for ($i = 0; $i < $children->length; $i++) { $this->readInChildNode($children->item($i), $webPage); } } }