_items = $items; } // add a new sitemap item function addItem($url, $lastmod = '', $changefreq = '', $priority = '', $additional_fields = array()) { $this->_items[] = array_merge(array('loc' => $url, 'lastmod' => $lastmod, 'changefreq' => $changefreq, 'priority' => $priority), $additional_fields); } // get Google sitemap function getGoogle() { ob_start(); header('Content-type: text/xml'); echo ''; echo ''; foreach ($this->_items as $i) { echo ''; foreach ($i as $index => $_i) { if (!$_i) continue; echo "<$index>" . $this->_escapeXML($_i) . ""; } echo ''; } echo ''; return ob_get_clean(); } // get Yahoo sitemap function getYahoo() { ob_start(); header('Content-type: text/plain'); foreach ($this->_items as $i) { echo $i['loc'] . "\n"; } return ob_get_clean(); } // escape string characters for inclusion in XML structure function _escapeXML($str) { $translation = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES); foreach ($translation as $key => $value) { $translation[$key] = '&#' . ord($key) . ';'; } $translation[chr(38)] = '&'; return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($str, $translation)); } } ?>