2015-07-01, 23:04:14
This
The xml had to be changed to our SimpleXMLExtended to include the cdata function.
note that the i18n nav plugin uses its own function!
This will probably not work correctly though since the urls are already encoded, you probably have to entitydecode them in the cdata now.
generate_sitemap()
will do what you want for the <loc> field.The xml had to be changed to our SimpleXMLExtended to include the cdata function.
note that the i18n nav plugin uses its own function!
This will probably not work correctly though since the urls are already encoded, you probably have to entitydecode them in the cdata now.
PHP Code:
/**
* Creates Sitemap
*
* Creates sitemap.xml in the site's root.
*/
function generate_sitemap() {
if(getDef('GSNOSITEMAP',true)) return;
// Variable settings
global $SITEURL;
$path = GSDATAPAGESPATH;
global $pagesArray;
getPagesXmlValues(false);
$pagesSorted = subval_sort($pagesArray,'menuStatus');
if (count($pagesSorted) != 0)
{
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>');
$xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
$xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
foreach ($pagesSorted as $page)
{
if ($page['url'] != '404')
{
if ($page['private'] != 'Y')
{
// set <loc>
$pageLoc = find_url($page['url'], $page['parent']);
// set <lastmod>
$tmpDate = date("Y-m-d H:i:s", strtotime($page['pubDate']));
$pageLastMod = makeIso8601TimeStamp($tmpDate);
// set <changefreq>
$pageChangeFreq = 'weekly';
// set <priority>
if ($page['menuStatus'] == 'Y') {
$pagePriority = '1.0';
} else {
$pagePriority = '0.5';
}
//add to sitemap
$url_item = $xml->addChild('url');
$item = $url_item->addChild('loc');
$item->addCData($pageLoc);
$url_item->addChild('lastmod', $pageLastMod);
$url_item->addChild('changefreq', $pageChangeFreq);
$url_item->addChild('priority', $pagePriority);
}
}
}
//create xml file
$file = GSROOTPATH .'sitemap.xml';
$xml = exec_filter('sitemap',$xml);
XMLsave($xml, $file);
exec_action('sitemap-aftersave');
}
if (!defined('GSDONOTPING')) {
if (file_exists(GSROOTPATH .'sitemap.xml')){
if( 200 === ($status=pingGoogleSitemaps($SITEURL.'sitemap.xml'))) {
#sitemap successfully created & pinged
return true;
} else {
error_log(i18n_r('SITEMAP_ERRORPING'));
return i18n_r('SITEMAP_ERRORPING');
}
} else {
error_log(i18n_r('SITEMAP_ERROR'));
return i18n_r('SITEMAP_ERROR');
}
} else {
#sitemap successfully created - did not ping
return true;
}
}