public function compile() { $urlset = parent::createElement('urlset'); $urlset->attr('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); foreach ($this->m_urls as $u) { $l = $u->getLoc(); if (empty($l)) { continue; } $url = parent::create('url'); $url->append(parent::createElement('loc', $l)); $l = $u->getLastmod(); if ($l) { $url->append(parent::createElement('lastmod', $l)); } $l = $u->getChangefreq(); if ($l) { $url->append(parent::createElement('changefreq', $l)); } $l = $u->getPriority(); if ($l) { $url->append(parent::createElement('priority', $l)); } $urlset->append($url); } parent::append($urlset); return parent::compile(); }
public function compile() { $index = parent::createElement('sitemapindex'); $index->attr('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); foreach ($this->m_maps as $m) { $l = $m->getLoc(); if (empty($l)) { continue; } $map = parent::create('sitemap'); $map->append(parent::createElement('loc', $l)); $l = $m->getLastmod(); if (!empty($l)) { $map->append(parent::createElement('lastmod', $l)); } $index->append($map); } parent::append($index); return parent::compile(); }
public function compile() { $rss = parent::create('rss'); $rss->attr("xmlns:atom", "http://www.w3.org/2005/Atom"); $rss->attr('version', $this->getVersion()); $c = $this->getChannel(); $channel = parent::create('channel'); $self = $this->getSelf(); if (!empty($self)) { $selflink = parent::create('atom:link'); $selflink->attr('href', (string) $self); $selflink->attr('rel', 'self'); $selflink->attr('type', "application/rss+xml"); $channel->append($selflink); } $title = parent::create('title'); $title->text($c->getTitle()); $channel->append($title); $desc = parent::create('description'); $desc->text($c->getDescription()); $channel->append($desc); $link = parent::create('link'); $link->text($c->getLink()); $channel->append($link); $language = $c->getLanguage(); if (!empty($language)) { $node = parent::createElement('language', $language); $channel->append($node); } $copyright = $c->getCopyright(); if (!empty($language)) { $node = parent::createElement('copyright', $copyright); $channel->append($node); } $managingEditor = $c->getManagingEditor(); if (!empty($language)) { $node = parent::createElement('managingEditor', $managingEditor->toString()); $channel->append($node); } $webMaster = $c->getWebMaster(); if (!empty($language)) { $node = parent::createElement('webMaster', $webMaster->toString()); $channel->append($node); } $pubDate = $c->getPubDate(); if (!empty($language)) { $node = parent::createElement('pubDate', gmdate("D, d M Y H:i:s", strtotime($pubDate)) . ' +0000'); $channel->append($node); } $lastBuildDate = $c->getLastBuildDate(); if (!empty($lastBuildDate)) { $node = parent::createElement('lastBuildDate', gmdate("D, d M Y H:i:s", strtotime($lastBuildDate)) . ' +0000'); $channel->append($node); } $category = $c->getCategory(); if (count($category)) { foreach ($category as $cat) { $node = parent::createElement('category', $cat->getTitle()); $domain = $cat->getDomain(); if (!empty($domain)) { $node->attr('domain', $domain); } $channel->append($node); } } $generator = $c->getGenerator(); if (!empty($generator)) { $node = parent::createElement('generator', $generator); $channel->append($node); } $docs = $c->getDocs(); if (!empty($docs)) { $node = parent::createElement('docs', $docs); $channel->append($node); } $ttl = $c->getTtl(); if (!empty($ttl)) { $node = parent::createElement('ttl', $ttl); $channel->append($node); } $image = $c->getImage(); $img_url = $image->getUrl(); if (!empty($img_url)) { $imgnode = parent::create('image'); $image_title = $image->getTitle(); $node = parent::createElement('title', empty($image_title) ? $c->getTitle() : $image_title); $imgnode->append($node); $image_link = $image->getLink(); $node = parent::createElement('link', empty($image_link) ? $c->getLink() : $image_link); $imgnode->append($node); $node = parent::createElement('url', $img_url); $imgnode->append($node); $img_description = $image->getDescription(); if (!empty($img_description)) { $node = parent::createElement('description', $img_description); $imgnode->append($node); } $channel->append($imgnode); } $items = $c->getItems(); foreach ($items as $item) { $itemnode = parent::create('item'); $item_title = parent::createElement('title', $item->getTitle()); $itemnode->append($item_title); $item_desc = parent::createElement('description', $item->getDescription()); $itemnode->append($item_desc); $item_link = parent::createElement('link', $item->getLink()); $itemnode->append($item_link); $item_pubDate = $item->getPubDate(); if (!empty($item_pubDate)) { $inode = parent::createElement('pubDate', gmdate("D, d M Y H:i:s", strtotime($item_pubDate)) . ' +0000'); $itemnode->append($inode); } $item_guid = $item->getGuid(); if (empty($item_guid)) { $item_guid = $item_link; } $inode = parent::createElement('guid', $item->getGuid()); $itemnode->append($inode); $item_author = $item->getAuthor()->toString(); if (!empty($item_author)) { $inode = parent::createElement('author', $item_author); $itemnode->append($inode); } $item_coments = $item->getComments(); if (!empty($item_coments)) { $inode = parent::createElement('comments', $item_coments); $itemnode->append($inode); } $item_source = $item->getSource(); if (!empty($item_source)) { $inode = parent::createElement('source', $c->getTitle()); $inode->attr($c->getUrl()); $itemnode->append($inode); } foreach ($item->getCategory() as $cat) { $cat_title = $cat->getTitle(); if (empty($cat_title)) { continue; } $catnode = parent::createElement('category', $cat_title); $domain = $cat->getDomain(); if (!empty($domain)) { $catnode->attr('domain', $domain); } $itemnode->append($catnode); } foreach ($item->getEnclosure() as $enc) { $encnode = parent::create('enclosure'); $encnode->attr('url', $enc->getUrl()); $encnode->attr('length', $enc->getLength()); $encnode->attr('type', $enc->getType()); $itemnode->append($encnode); } $channel->append($itemnode); } $rss->append($channel); parent::append($rss); return parent::compile(); }
public function compile() { /* $doc_impl = new DOMImplementation; $implType = $doc_impl->createDocumentType($this->m_doctype[0], $this->m_doctype[1], $this->m_doctype[2]); $doc = null; if( $implType ) $doc = $doc_impl->createDocument(null, $this->m_doctype[0], $implType); else return; */ //$e = parent::getCharset(); //parent::setDocument($doc); //parent::setCharset($e); $html = parent::getRoot(); if ($this->getDocument()->doctype->name == 'xhtml') { $html->attr('xmlns', 'http://www.w3.org/1999/xhtml'); $html->attr('xml:lang', 'en'); } $head = parent::create('head'); $body = parent::create('body'); $title = parent::create('title'); $title->text($this->m_title); $head->append($title); if ($this->m_base) { $base = parent::create('base'); $base->attr('href', $this->m_base); $head->append($base); } $doc = ''; //$this->metaAddHttp( 'Content-Type', 'text/html; charset=' . $this->getEncoding() ); if ($this->m_keywords) { $this->metaAddName('keywords', $this->m_keywords); } if ($this->m_description) { $this->metaAddName('description', $this->m_description); } foreach ($this->m_meta as $m) { if (!is_array($m) || count($m) < 0) { continue; } $mnode = parent::create('meta'); foreach ($m as $key => $val) { $mnode->attr($key, $val); } $head->append($mnode); } foreach ($this->m_styles['inline'] as $s) { $style = parent::create('style'); $style->attr('type', 'text/css'); $style->text($s); $head->append($style); } foreach ($this->m_link as $link) { if (!is_array($link) || count($link) < 0) { continue; } $l = parent::create('link'); foreach ($link as $key => $val) { $l->attr($key, $val); } $head->append($l); } foreach ($this->m_scripts['header'] as $s) { $script = parent::create('script'); $script->attr('type', 'text/javascript'); $script->text($s); $head->append($script); } foreach ($this->m_styles['url'] as $s) { $style = parent::create('link'); $style->attr('rel', 'stylesheet'); $style->attr('type', 'text/css'); $style->attr('media', $s[1]); $style->attr('href', $s[0]); $head->append($style); } foreach ($this->m_styles['include'] as $s) { $style = parent::create('link'); $style->attr('rel', 'stylesheet'); $style->attr('type', 'text/css'); $style->attr('media', $s[1]); $style->attr('href', $s[0]); $head->append($style); } foreach ($this->m_scripts['url'] as $s) { $script = parent::create('script'); $script->attr('type', 'text/javascript'); $script->attr('src', $s); $script->text(''); $head->append($script); } $placeholder = '[-----REPLACE-HERE-' . md5(time()) . '-----]'; $body->text($placeholder); foreach ($this->m_scripts['include'] as $s) { $script = parent::create('script'); $script->attr('type', 'text/javascript'); $script->attr('src', $s); $script->text(''); $body->append($script); } foreach ($this->m_scripts['inline'] as $s) { $script = parent::create('script'); $script->attr('type', 'text/javascript'); $script->text($s); $body->append($script); } $d = $this->getDocument(); $d->preserveWhiteSpace = true; $d->recover = false; $d->formatOutput = true; $html->append($head); $html->append($body); parent::append($html); $d->normalizeDocument(); $content = str_replace($placeholder, $this->body(), $d->saveHtml()); return $content; }