• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.
  • Chevereto Support CLST

    Support response

    Support checklist

XML Sitemap

SMP

💖 Chevereto Fan
This is basically improved version of this one

Changes:

1) Includes all public images
2) Added "caption" element
3) Excluded images of private profiles
4) Added albums sitemap (only public ones which are not password protected or from private profiles)
5) Added users sitemap (only public profiles)

Info:

This generates a sitemap-index.xml in root and images1.xml, images2.xml, etc... , albums1.xml, etc... , users1.xml, etc... in "xml-sitemaps" folder

Optional edits:

Line 4 to change sitemaps folder to something other then "xml-sitemaps"
Line 5 to change maximum number of urls to be included in each sitemap

Files

Route (upload/add to app/routes/route.xml-sitemap.php)

PHP:
<?php
$route = function($handler) {
try {
  $sitemapsFolder = "xml-sitemaps/"; //Child sitemaps folder(Optional change)
  $max_url_limit = 10000; // 50k is maximum  https://support.google.com/webmasters/answer/183668?hl=en

  //DO NOT CHANGE
  //////////////////////////////////////////////////////////
  $absSitemapsFolder = getcwd()."/".$sitemapsFolder;
  $handler::$vars['sitemapsFolder'] = $sitemapsFolder;

  // Basic things
  if( !file_exists($absSitemapsFolder)){
  if(!mkdir($absSitemapsFolder))
  throw new Exception("Can not create ".$sitemapsFolder);

  if(!is_readable($absSitemapsFolder) or !is_writeable($absSitemapsFolder))
  throw new Exception("Can not read/write to ".$sitemapsFolder. ". Check permissions.");
  }
  // lastmod
  $objDateTime  =  new DateTime('NOW');
  $dateTime  = $objDateTime->format(DATE_W3C);

  // Get paths
  $site_upload_image_route = CHV\getSetting('upload_image_path');
  $site_album_route = CHV\getSetting('route_album');
  $site_image_route = CHV\getSetting('route_image');
  $site_user_route = CHV\getSetting('user_routing');

  // To get no of child sitemaps in each one
  /////////////////////////////////////////////////////////////////////////////////////////////////

  // Count no of images and then round off to higher number.
  $count_images = CHV\DB::queryFetchSingle("SELECT COUNT(*) as total FROM " . CHV\DB::getTable('images'). "")['total'];
  if ($count_images > 0) {
  $image_sitemap_count = ceil($count_images/$max_url_limit);
  for ($i=1; $i<= $image_sitemap_count; $i++) {
  $lists[] = array("list_id" => images, "list_name" => "Images ".$i, "list_slug" => "images".$i);
  }
  }

  // Count no of albums and then round off to higher number.
  $count_albums = CHV\DB::queryFetchSingle("SELECT COUNT(*) as total FROM " . CHV\DB::getTable('albums'). " WHERE album_privacy = 'public' AND album_password IS NULL AND NOT album_image_count = 0")['total'];
  if ($count_albums > 0) {
  $album_sitemap_count = ceil($count_albums/$max_url_limit);
  for ($j=1; $j<= $album_sitemap_count; $j++) {
  $lists[] = array("list_id" => albums, "list_name" => "Albums ".$j, "list_slug" => "albums".$j);
  }
  }

  // Count no of users and then round off to higher number.
  $count_users = CHV\DB::queryFetchSingle("SELECT COUNT(*) as total FROM " . CHV\DB::getTable('users'). " WHERE user_is_private = '0'")['total'];
  if ($count_users > 0) {
  $user_sitemap_count = ceil($count_users/$max_url_limit);
  for ($k=1; $k<= $user_sitemap_count; $k++) {
  $lists[] = array("list_id" => users, "list_name" => "Users ".$k, "list_slug" => "users".$k);
  }
  }

  $handler::$vars['lists'] = $lists;
  
  //Strip away the unwanted chars
  function utf8_for_xml($string)
  {
  return preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string);
  }
  

  // Create index sitemap on root dir
  //////////////////////////////////////////////////////////////////////////////////////
  $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" />');


  foreach($lists as $list) {
  $c = $xml->addChild("sitemap");

  $xml_url  = $handler->base_url.$sitemapsFolder.$list["list_slug"].".xml";
  $xml_local  = $sitemapsFolder.$list["list_slug"].".xml";

  $c->addChild("loc", $xml_url);
  $c->addChild("lastmod", $dateTime );


  // Lets create a sitemaps
  /////////////////////////////////////////////////////////////////////////////////
  $xml2 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" />');

  $DB = CHV\DB::getInstance();

  if($list["list_id"] == "images" and $count_images > 0) {

  for ($l=1; $l<= $image_sitemap_count; $l++) {

  $iurl_offset = $max_url_limit*($l-1);
  if($list["list_slug"] == "images".$l) {
  $q = $DB->query("SELECT image_id, image_title, image_description, DATE_FORMAT(image_date, '%Y') as year, DATE_FORMAT(image_date, '%m') as month, DATE_FORMAT(image_date, '%d') as day, image_storage_mode, image_storage_id, image_date, image_name, image_extension, storage_url FROM " . CHV\DB::getTable('images'). "
  LEFT JOIN " . CHV\DB::getTable('storages'). " on storage_id = image_storage_id
  LEFT JOIN " . CHV\DB::getTable('users'). " on user_id = image_user_id
  WHERE user_is_private = '0' AND image_user_id IS NOT NULL
  UNION
  SELECT image_id, image_title, image_description, DATE_FORMAT(image_date, '%Y') as year, DATE_FORMAT(image_date, '%m') as month, DATE_FORMAT(image_date, '%d') as day, image_storage_mode, image_storage_id, image_date, image_name, image_extension, storage_url FROM " . CHV\DB::getTable('images'). "
  LEFT JOIN " . CHV\DB::getTable('storages'). " on storage_id = image_storage_id
  WHERE image_user_id IS NULL
  ORDER BY image_date DESC LIMIT ".$max_url_limit." OFFSET ".$iurl_offset."");
  }
  }

  }
  
  if($list["list_id"] == "albums" and $count_albums > 0) {

  for ($m=1; $m<= $album_sitemap_count; $m++) {

  $aurl_offset = $max_url_limit*($m-1);
  if($list["list_slug"] == "albums".$m) {  
  $q = $DB->query("SELECT album_id FROM " . CHV\DB::getTable('albums'). " LEFT JOIN " . CHV\DB::getTable('users'). " on user_id = album_user_id WHERE album_privacy = 'public' AND album_password IS NULL AND NOT album_image_count = 0 AND user_is_private = '0' ORDER BY album_id DESC LIMIT ".$max_url_limit." OFFSET ".$aurl_offset."");
  }
  }  

  }
  if($list["list_id"] == "users" and $count_users > 0) {

  for ($n=1; $n<= $user_sitemap_count; $n++) {
  $uurl_offset = $max_url_limit*($n-1);
  if($list["list_slug"] == "users".$n) {  
  $q = $DB->query("SELECT user_username FROM " . CHV\DB::getTable('users'). " WHERE user_is_private = '0' ORDER BY user_id DESC LIMIT ".$max_url_limit." OFFSET ".$uurl_offset."");
  }
  }
  }

  $images = $DB->fetchAll();
  //Inner xml elements
  /////////////////////////////////////////////////////////////
  foreach($images as $image) {

  if($list["list_id"] == "albums" and $count_albums > 0) {

  // Every album gets its own URL
  $cc = $xml2->addChild("url");
  $cc->addChild("loc", $handler->base_url.$site_album_route."/".CHV\encodeID($image["album_id"], "encode") );  

  }
  
  if($list["list_id"] == "users" and $count_users > 0) {

  if ($site_user_route == "1") {
  $user_base_url = $handler->base_url;
  } else {
  $user_base_url = $handler->base_url.'user/';
  }
  
  // Every user gets their own URL
  $cc = $xml2->addChild("url");
  $cc->addChild("loc", $user_base_url.$image["user_username"]);  

  }
  
  if($list["list_id"] == "images" and $count_images > 0) {  

  $folder = "";

  switch ($image["image_storage_mode"]){
  case "datefolder":
  $folder = $image["year"]."/".$image["month"]."/".$image["day"]."/";
  break;

  default:
  $folder = "";
  break;
  }
  
  // Every image gets its own URL
  $cc = $xml2->addChild("url");
  $cc->addChild("loc", $handler->base_url.$site_image_route."/".CHV\encodeID($image["image_id"], "encode") );
  
  if ($image["image_storage_id"] == NULL) {
  $image_base_url = $handler->base_url.$site_upload_image_route.'/';
  } else {
  $image_base_url = $image["storage_url"];
  }  

  $cc_image = $cc->addChild("xmlns:image:image");
  $cc_image->addChild("xmlns:image:loc", $image_base_url.$folder.$image["image_name"].".".$image["image_extension"]);
  $cc_image->addChild("xmlns:image:title", utf8_for_xml($image["image_title"]));
  if (strlen($image["image_description"]) > 3) {
  $cc_image->addChild("xmlns:image:caption", utf8_for_xml($image["image_description"]));
  }
  }

  }

  $dom = new DomDocument();
  $dom->loadXML($xml2->asXML());
  $dom->formatOutput = true;

  file_put_contents( $xml_local, $dom->saveXML(), LOCK_EX);
  }

  $dom = new DomDocument();
  $dom->loadXML($xml->asXML());
  $dom->formatOutput = true;

  if(file_put_contents("sitemap-index.xml", $dom->saveXML(), LOCK_EX) === false){
  die("Could not write sitemap-index.xml");
  }

  $handler::setVar('pre_doctitle', _s('XML Sitemaps'));

} catch(Exception $e) {
  G\exception_to_error($e);
}
};

?>

Template
(upload/add to app/themes/YOUR_THERE_NAME/views/xml-sitemap.php)
Using default one? then (upload/add to app/themes/Peafowl/views/xml-sitemap.php)

PHP:
<?php if(!defined('access') or !access) die('This file cannot be directly accessed.'); ?>
<?php G\Render\include_theme_header(); ?>

<div class="content-width">
  <div class="page-not-found">
  <h1>XML Sitemaps</h1>
  <h4><a href="<?php echo G\get_base_url()."/sitemap-index.xml";?>">Index</a></h4>
  <br />

  <h5>Child Sitemaps</h5>
  <br />

  <div>
  <ul>
  <?php
  $cat = get_lists();
  foreach($cat as $key){
  echo "<li><a href=\"".G\get_base_url()."/".get_sitemapsFolder().$key["list_slug"].".xml"."\">".$key["list_name"]."</a></li>";
  }
  ?>
  </ul>
  </div>
  </div>
</div>

<?php G\Render\include_theme_footer(); ?>

<?php if(isset($_REQUEST["deleted"])) { ?>
<script>PF.fn.growl.call("<?php echo (G\get_route_name() == 'user' ? _s('The user has been deleted') : _s('The content has been deleted.')); ?>"); </script>
<?php } ?>

Add cron job
(The below one runs two times a day at 6th and 18th hr)
Code:
0 6,18 * * *   wget -O /dev/null -o /dev/null http://www.domain.tld/xml-sitemap

(Do not forget to submit (or change) sitemap in webmaster section)

Thats it
 
Last edited:
And if you don't (want to) use the Google Webmastertools create an file and name it "runme.php" in your root folder:

PHP:
function myCurl($url) {
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_exec($ch);
  $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);
  return $httpCode;
}

$sitemapUrl = "https://www.your-domain.tld/sitemap-index.xml"; // or 'http://' if you don't use SSL

$urlG = "http://www.google.com/webmasters/sitemaps/ping?sitemap=".$sitemapUrl;
$urlB = "http://www.bing.com/webmaster/ping.aspx?siteMap=".$sitemapUrl;
myCurl($urlG);
myCurl($urlB);

and create an cron for this file to execute it once a day.

This will ping your sitemap to Google and Bing.

You must have cURL activated on your server!
 
Thank U 4 the script!

But now, if you have consent screen enabled - there is a problem with the cron and wget (it doesn't work), remember it ...
Some time i used something like this in my cron (yep, it isn't great option - but it works)

Code:
elinks -auto-submit https://your-domain.tld/xml-sitemap

but now I just disable consent screen, so ...
 
About 1M pics and 700 users on the site.
32 core (16 real + hyper threading).
Usually I have something about 20 LA (+- 2).

After last chevereto update sitemap script (from this topic) add 10LA (up to 100% load) every start of the cron :(
Couple of days I've tried to understand WTF but rm -f is the command which is the best solution at the moment.
No sitemap = No problem :)

Screen:

Woiqdg6.png


p.s. Sorry 4 my English, it is not my native.
 
Thank
This is basically improved version of this one

Changes:

1) Includes all public images
2) Added "caption" element
3) Excluded images of private profiles
4) Added albums sitemap (only public ones which are not password protected or from private profiles)
5) Added users sitemap (only public profiles)

Info:

This generates a sitemap-index.xml in root and images1.xml, images2.xml, etc... , albums1.xml, etc... , users1.xml, etc... in "xml-sitemaps" folder

Optional edits:

Line 4 to change sitemaps folder to something other then "xml-sitemaps"
Line 5 to change maximum number of urls to be included in each sitemap

Files

Route (upload/add to app/routes/route.xml-sitemap.php)

PHP:
<?php
$route = function($handler) {
try {
  $sitemapsFolder = "xml-sitemaps/"; //Child sitemaps folder(Optional change)
  $max_url_limit = 10000; // 50k is maximum  https://support.google.com/webmasters/answer/183668?hl=en

  //DO NOT CHANGE
  //////////////////////////////////////////////////////////
  $absSitemapsFolder = getcwd()."/".$sitemapsFolder;
  $handler::$vars['sitemapsFolder'] = $sitemapsFolder;

  // Basic things
  if( !file_exists($absSitemapsFolder)){
  if(!mkdir($absSitemapsFolder))
  throw new Exception("Can not create ".$sitemapsFolder);

  if(!is_readable($absSitemapsFolder) or !is_writeable($absSitemapsFolder))
  throw new Exception("Can not read/write to ".$sitemapsFolder. ". Check permissions.");
  }
  // lastmod
  $objDateTime  =  new DateTime('NOW');
  $dateTime  = $objDateTime->format(DATE_W3C);

  // Get paths
  $site_upload_image_route = CHV\getSetting('upload_image_path');
  $site_album_route = CHV\getSetting('route_album');
  $site_image_route = CHV\getSetting('route_image');
  $site_user_route = CHV\getSetting('user_routing');

  // To get no of child sitemaps in each one
  /////////////////////////////////////////////////////////////////////////////////////////////////

  // Count no of images and then round off to higher number.
  $count_images = CHV\DB::queryFetchSingle("SELECT COUNT(*) as total FROM " . CHV\DB::getTable('images'). "")['total'];
  if ($count_images > 0) {
  $image_sitemap_count = ceil($count_images/$max_url_limit);
  for ($i=1; $i<= $image_sitemap_count; $i++) {
  $lists[] = array("list_id" => images, "list_name" => "Images ".$i, "list_slug" => "images".$i);
  }
  }

  // Count no of albums and then round off to higher number.
  $count_albums = CHV\DB::queryFetchSingle("SELECT COUNT(*) as total FROM " . CHV\DB::getTable('albums'). " WHERE album_privacy = 'public' AND album_password IS NULL AND NOT album_image_count = 0")['total'];
  if ($count_albums > 0) {
  $album_sitemap_count = ceil($count_albums/$max_url_limit);
  for ($j=1; $j<= $album_sitemap_count; $j++) {
  $lists[] = array("list_id" => albums, "list_name" => "Albums ".$j, "list_slug" => "albums".$j);
  }
  }

  // Count no of users and then round off to higher number.
  $count_users = CHV\DB::queryFetchSingle("SELECT COUNT(*) as total FROM " . CHV\DB::getTable('users'). " WHERE user_is_private = '0'")['total'];
  if ($count_users > 0) {
  $user_sitemap_count = ceil($count_users/$max_url_limit);
  for ($k=1; $k<= $user_sitemap_count; $k++) {
  $lists[] = array("list_id" => users, "list_name" => "Users ".$k, "list_slug" => "users".$k);
  }
  }

  $handler::$vars['lists'] = $lists;
 
  //Strip away the unwanted chars
  function utf8_for_xml($string)
  {
  return preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string);
  }
 

  // Create index sitemap on root dir
  //////////////////////////////////////////////////////////////////////////////////////
  $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" />');


  foreach($lists as $list) {
  $c = $xml->addChild("sitemap");

  $xml_url  = $handler->base_url.$sitemapsFolder.$list["list_slug"].".xml";
  $xml_local  = $sitemapsFolder.$list["list_slug"].".xml";

  $c->addChild("loc", $xml_url);
  $c->addChild("lastmod", $dateTime );


  // Lets create a sitemaps
  /////////////////////////////////////////////////////////////////////////////////
  $xml2 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" />');

  $DB = CHV\DB::getInstance();

  if($list["list_id"] == "images" and $count_images > 0) {

  for ($l=1; $l<= $image_sitemap_count; $l++) {

  $iurl_offset = $max_url_limit*($l-1);
  if($list["list_slug"] == "images".$l) {
  $q = $DB->query("SELECT image_id, image_title, image_description, DATE_FORMAT(image_date, '%Y') as year, DATE_FORMAT(image_date, '%m') as month, DATE_FORMAT(image_date, '%d') as day, image_storage_mode, image_storage_id, image_date, image_name, image_extension, storage_url FROM " . CHV\DB::getTable('images'). "
  LEFT JOIN " . CHV\DB::getTable('storages'). " on storage_id = image_storage_id
  LEFT JOIN " . CHV\DB::getTable('users'). " on user_id = image_user_id
  WHERE user_is_private = '0' AND image_user_id IS NOT NULL
  UNION
  SELECT image_id, image_title, image_description, DATE_FORMAT(image_date, '%Y') as year, DATE_FORMAT(image_date, '%m') as month, DATE_FORMAT(image_date, '%d') as day, image_storage_mode, image_storage_id, image_date, image_name, image_extension, storage_url FROM " . CHV\DB::getTable('images'). "
  LEFT JOIN " . CHV\DB::getTable('storages'). " on storage_id = image_storage_id
  WHERE image_user_id IS NULL
  ORDER BY image_date DESC LIMIT ".$max_url_limit." OFFSET ".$iurl_offset."");
  }
  }

  }
 
  if($list["list_id"] == "albums" and $count_albums > 0) {

  for ($m=1; $m<= $album_sitemap_count; $m++) {

  $aurl_offset = $max_url_limit*($m-1);
  if($list["list_slug"] == "albums".$m) { 
  $q = $DB->query("SELECT album_id FROM " . CHV\DB::getTable('albums'). " LEFT JOIN " . CHV\DB::getTable('users'). " on user_id = album_user_id WHERE album_privacy = 'public' AND album_password IS NULL AND NOT album_image_count = 0 AND user_is_private = '0' ORDER BY album_id DESC LIMIT ".$max_url_limit." OFFSET ".$aurl_offset."");
  }
  } 

  }
  if($list["list_id"] == "users" and $count_users > 0) {

  for ($n=1; $n<= $user_sitemap_count; $n++) {
  $uurl_offset = $max_url_limit*($n-1);
  if($list["list_slug"] == "users".$n) { 
  $q = $DB->query("SELECT user_username FROM " . CHV\DB::getTable('users'). " WHERE user_is_private = '0' ORDER BY user_id DESC LIMIT ".$max_url_limit." OFFSET ".$uurl_offset."");
  }
  }
  }

  $images = $DB->fetchAll();
  //Inner xml elements
  /////////////////////////////////////////////////////////////
  foreach($images as $image) {

  if($list["list_id"] == "albums" and $count_albums > 0) {

  // Every album gets its own URL
  $cc = $xml2->addChild("url");
  $cc->addChild("loc", $handler->base_url.$site_album_route."/".CHV\encodeID($image["album_id"], "encode") ); 

  }
 
  if($list["list_id"] == "users" and $count_users > 0) {

  if ($site_user_route == "1") {
  $user_base_url = $handler->base_url;
  } else {
  $user_base_url = $handler->base_url.'user/';
  }
 
  // Every user gets their own URL
  $cc = $xml2->addChild("url");
  $cc->addChild("loc", $user_base_url.$image["user_username"]); 

  }
 
  if($list["list_id"] == "images" and $count_images > 0) { 

  $folder = "";

  switch ($image["image_storage_mode"]){
  case "datefolder":
  $folder = $image["year"]."/".$image["month"]."/".$image["day"]."/";
  break;

  default:
  $folder = "";
  break;
  }
 
  // Every image gets its own URL
  $cc = $xml2->addChild("url");
  $cc->addChild("loc", $handler->base_url.$site_image_route."/".CHV\encodeID($image["image_id"], "encode") );
 
  if ($image["image_storage_id"] == NULL) {
  $image_base_url = $handler->base_url.$site_upload_image_route.'/';
  } else {
  $image_base_url = $image["storage_url"];
  } 

  $cc_image = $cc->addChild("xmlns:image:image");
  $cc_image->addChild("xmlns:image:loc", $image_base_url.$folder.$image["image_name"].".".$image["image_extension"]);
  $cc_image->addChild("xmlns:image:title", utf8_for_xml($image["image_title"]));
  if (strlen($image["image_description"]) > 3) {
  $cc_image->addChild("xmlns:image:caption", utf8_for_xml($image["image_description"]));
  }
  }

  }

  $dom = new DomDocument();
  $dom->loadXML($xml2->asXML());
  $dom->formatOutput = true;

  file_put_contents( $xml_local, $dom->saveXML(), LOCK_EX);
  }

  $dom = new DomDocument();
  $dom->loadXML($xml->asXML());
  $dom->formatOutput = true;

  if(file_put_contents("sitemap-index.xml", $dom->saveXML(), LOCK_EX) === false){
  die("Could not write sitemap-index.xml");
  }

  $handler::setVar('pre_doctitle', _s('XML Sitemaps'));

} catch(Exception $e) {
  G\exception_to_error($e);
}
};

?>

Template
(upload/add to app/themes/YOUR_THERE_NAME/views/xml-sitemap.php)
Using default one? then (upload/add to app/themes/Peafowl/views/xml-sitemap.php)

PHP:
<?php if(!defined('access') or !access) die('This file cannot be directly accessed.'); ?>
<?php G\Render\include_theme_header(); ?>

<div class="content-width">
  <div class="page-not-found">
  <h1>XML Sitemaps</h1>
  <h4><a href="<?php echo G\get_base_url()."/sitemap-index.xml";?>">Index</a></h4>
  <br />

  <h5>Child Sitemaps</h5>
  <br />

  <div>
  <ul>
  <?php
  $cat = get_lists();
  foreach($cat as $key){
  echo "<li><a href=\"".G\get_base_url()."/".get_sitemapsFolder().$key["list_slug"].".xml"."\">".$key["list_name"]."</a></li>";
  }
  ?>
  </ul>
  </div>
  </div>
</div>

<?php G\Render\include_theme_footer(); ?>

<?php if(isset($_REQUEST["deleted"])) { ?>
<script>PF.fn.growl.call("<?php echo (G\get_route_name() == 'user' ? _s('The user has been deleted') : _s('The content has been deleted.')); ?>"); </script>
<?php } ?>

Add cron job
(The below one runs two times a day at 6th and 18th hr)
Code:
0 6,18 * * *   wget -O /dev/null -o /dev/null http://www.domain.tld/xml-sitemap

(Do not forget to submit (or change) sitemap in webmaster section)

Thats it
Thanks a lot. Do you have codes for RSS too?
 
There seems to be bug in below code. So had to comment out for this to work.

Code:
 if (strlen($image["image_description"]) > 3) {
  $cc_image->addChild("xmlns:image:caption", utf8_for_xml($image["image_description"]));
  }
 
This script is giving 500 internal server error now on newer chevereto version.

Could some 1 post a fix to make it work on newer versions?
 
This script is giving 500 internal server error now on newer chevereto version.

Could some 1 post a fix to make it work on newer versions?
true, i just realised I too get error 500. Maybe time to implement sitemapping feature as a feature?
 
This sitemap method not working anymore in v 3.20


Code:
** errorId #af6c42d2f9b1e630 **

>> ErrorException [0]: Use of undefined constant images - assumed 'images' (this will throw an Error in a future version of PHP)

At /app/routes/route.xml-sitemap.php:38



Stack trace:

#0 /app/routes/route.xml-sitemap.php(38): G\errorsAsExceptions()

#1 /lib/G/classes/class.handler.php(230): G\Handler->{closure}()

#2 /lib/G/classes/class.handler.php(130): G\Handler->processRequest()

#3 /app/web.php(411): G\Handler->__construct()

#4 /app/loader.php(230): require_once('/app/web.php')

#5 /index.php(20): include_once('/app/loader.php')

How to resolve this thanks
 
This sitemap method not working anymore in v 3.20


Code:
** errorId #af6c42d2f9b1e630 **

>> ErrorException [0]: Use of undefined constant images - assumed 'images' (this will throw an Error in a future version of PHP)

At /app/routes/route.xml-sitemap.php:38



Stack trace:

#0 /app/routes/route.xml-sitemap.php(38): G\errorsAsExceptions()

#1 /lib/G/classes/class.handler.php(230): G\Handler->{closure}()

#2 /lib/G/classes/class.handler.php(130): G\Handler->processRequest()

#3 /app/web.php(411): G\Handler->__construct()

#4 /app/loader.php(230): require_once('/app/web.php')

#5 /index.php(20): include_once('/app/loader.php')

How to resolve this thanks

You need to add
to
images - line 38
albums - line 48
users - line 57

i.e
$lists[] = array("list_id" => 'images', "list_name" => "Images ".$i, "list_slug" => "images".$i);
$lists[] = array("list_id" => 'albums', "list_name" => "Albums ".$j, "list_slug" => "albums".$j);
$lists[] = array("list_id" => 'users', "list_name" => "Users ".$k, "list_slug" => "users".$k);

But then another bug popped up and the images don't count anyway

Got error 'PHP message: \n
Aw, snap! Internal Server Error [debug @ error_log] - https://v3-docs.chevereto.com/setup/troubleshoot/debug.html\n\n
** errorId #bba3059cd76e2bed **\n>>

ErrorException [0]: SimpleXMLElement::addChild(): unterminated entity reference Associates is a full-service debt collection agency with proprietary techniques that serves clients worldwide.\nWith years of experience and extensive knowledge in the collection industry, BCA is the choice to make when considering a company to help you with your delinquent accounts on a contingency basis. Call us for more information at 844-733-4770 or email us at signup@benjaminchaise.com.\n

At /app/routes/route.xml-sitemap.php:186\n\nStack trace:\n
#0 unknown file(unknown line): G\\errorsAsExceptions()\n
#1 /app/routes/route.xml-sitemap.php(186): SimpleXMLElement->addChild()\n
#2 /lib/G/classes/class.handler.php(230): G\\Handler->{closure}()\n
#3 /lib/G/classes/class.handler.php(130): G\\Handler->processRequest()\n
#4 /app/web.php(411): G\\Handler->__construct()\n#5 /app/lo...'
 
You need to add

to


i.e




But then another bug popped up and the images don't count anyway
I try that and still not resolve issue


Code:
** errorId #9963b5d4d7d64040 **
>> ErrorException [0]: SimpleXMLElement::addChild(): unterminated entity reference Packaging Agency | walnutfolks
At /app/routes/route.xml-sitemap.php:185

Stack trace:
#0 unknown file(unknown line): G\errorsAsExceptions()
#1 /app/routes/route.xml-sitemap.php(185): SimpleXMLElement->addChild()
#2 /lib/G/classes/class.handler.php(230): G\Handler->{closure}()
#3 /lib/G/classes/class.handler.php(130): G\Handler->processRequest()
#4 /app/web.php(411): G\Handler->__construct()
#5 /app/loader.php(230): require_once('/app/web.php')
#6 /index.php(20): include_once('/app/loader.php')
 
Update:
app/routes/route.xml-sitemap.php

It is updated to version 3.20+ :cool:

PHP:
<?php
$route = function($handler) {
try {
  $sitemapsFolder = 'xml-sitemaps/'; //Child sitemaps folder(Optional change)
  $max_url_limit = 5000; // 50k is maximum  https://support.google.com/webmasters/answer/183668?hl=en

  //DO NOT CHANGE
  //////////////////////////////////////////////////////////
  $absSitemapsFolder = getcwd().'/'.$sitemapsFolder;
  $handler::$vars['sitemapsFolder'] = $sitemapsFolder;

  // Basic things
  if( !file_exists($absSitemapsFolder)){
  if(!mkdir($absSitemapsFolder))
  throw new Exception('Can not create '.$sitemapsFolder);

  if(!is_readable($absSitemapsFolder) or !is_writeable($absSitemapsFolder))
  throw new Exception('Can not read/write to '.$sitemapsFolder. '. Check permissions.');
  }
  // lastmod
  $objDateTime  =  new DateTime('NOW');
  $dateTime  = $objDateTime->format(DATE_W3C);

  // Get paths
  $site_upload_image_route = CHV\getSetting('upload_image_path');
  $site_album_route = CHV\getSetting('route_album');
  $site_image_route = CHV\getSetting('route_image');
  $site_user_route = CHV\getSetting('user_routing');

  // To get no of child sitemaps in each one
  /////////////////////////////////////////////////////////////////////////////////////////////////

  // Count no of images and then round off to higher number.
  $count_images = CHV\DB::queryFetchSingle('SELECT COUNT(*) as total FROM ' . CHV\DB::getTable('images'). '')['total'];
  if ($count_images > 0) {
  $image_sitemap_count = ceil($count_images/$max_url_limit);
  for ($i=1; $i<= $image_sitemap_count; $i++) {
  $lists[] = array('list_id' => 'images', 'list_name' => 'Images '.$i, 'list_slug' => 'images'.$i);
  }
  }

  // Count no of albums and then round off to higher number.
  $count_albums = CHV\DB::queryFetchSingle('SELECT COUNT(*) as total FROM ' . CHV\DB::getTable('albums'). ' WHERE album_privacy = "public" AND album_password IS NULL AND NOT album_image_count = "0"')['total'];
  if ($count_albums > 0) {
  $album_sitemap_count = ceil($count_albums/$max_url_limit);
  for ($j=1; $j<= $album_sitemap_count; $j++) {
  $lists[] = array('list_id' => 'albums', 'list_name' => 'Albums '.$j, 'list_slug' => 'albums'.$j);
  }
  }

  // Count no of users and then round off to higher number.
  $count_users = CHV\DB::queryFetchSingle('SELECT COUNT(*) as total FROM ' . CHV\DB::getTable('users'). ' WHERE user_is_private = "0"')['total'];
  if ($count_users > 0) {
  $user_sitemap_count = ceil($count_users/$max_url_limit);
  for ($k=1; $k<= $user_sitemap_count; $k++) {
  $lists[] = array('list_id' => 'users', 'list_name' => 'Users '.$k, 'list_slug' => 'users'.$k);
  }
  }

  $handler::$vars['lists'] = $lists;
 
  //Strip away the unwanted chars
  function utf8_for_xml($string)
  {
  return preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string);
  }
 

  // Create index sitemap on root dir
  //////////////////////////////////////////////////////////////////////////////////////
  $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" />');


  foreach($lists as $list) {
  $c = $xml->addChild('sitemap');

  $xml_url  = $handler->base_url.$sitemapsFolder.$list['list_slug'].'.xml';
  $xml_local  = $sitemapsFolder.$list['list_slug'].'.xml';

  $c->addChild('loc', $xml_url);
  $c->addChild('lastmod', $dateTime );


  // Lets create a sitemaps
  /////////////////////////////////////////////////////////////////////////////////
  $xml2 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" />');

  $DB = CHV\DB::getInstance();

  if($list['list_id'] == 'images' and $count_images > 0) {

  for ($l=1; $l<= $image_sitemap_count; $l++) {

  $iurl_offset = $max_url_limit*($l-1);
  if($list['list_slug'] == 'images'.$l) {
  $q = $DB->query('SELECT image_id, image_title, image_description, DATE_FORMAT(image_date, "%Y") as year, DATE_FORMAT(image_date, "%m") as month, DATE_FORMAT(image_date, "%d") as day, image_storage_mode, image_storage_id, image_date, image_name, image_extension, storage_url FROM ' . CHV\DB::getTable('images'). '
  LEFT JOIN ' . CHV\DB::getTable('storages'). ' on storage_id = image_storage_id
  LEFT JOIN ' . CHV\DB::getTable('users'). ' on user_id = image_user_id
  WHERE user_is_private = 0 AND image_user_id IS NOT NULL
  UNION
  SELECT image_id, image_title, image_description, DATE_FORMAT(image_date, "%Y") as year, DATE_FORMAT(image_date, "%m") as month, DATE_FORMAT(image_date, "%d") as day, image_storage_mode, image_storage_id, image_date, image_name, image_extension, storage_url FROM ' . CHV\DB::getTable('images'). '
  LEFT JOIN ' . CHV\DB::getTable('storages'). ' on storage_id = image_storage_id
  WHERE image_user_id IS NULL
  ORDER BY image_date DESC LIMIT '.$max_url_limit.' OFFSET '.$iurl_offset.'');
  }
  }

  }
 
  if($list['list_id'] == 'albums' and $count_albums > 0) {

  for ($m=1; $m<= $album_sitemap_count; $m++) {

  $aurl_offset = $max_url_limit*($m-1);
  if($list['list_slug'] == 'albums'.$m) { 
  $q = $DB->query('SELECT album_id FROM ' . CHV\DB::getTable('albums'). ' LEFT JOIN ' . CHV\DB::getTable('users'). ' on user_id = album_user_id WHERE album_privacy = "public" AND album_password IS NULL AND NOT album_image_count = "0" AND user_is_private = "0" ORDER BY album_id DESC LIMIT '.$max_url_limit.' OFFSET '.$aurl_offset.'');
  }
  } 

  }
  if($list['list_id'] == 'users' and $count_users > 0) {

  for ($n=1; $n<= $user_sitemap_count; $n++) {
  $uurl_offset = $max_url_limit*($n-1);
  if($list['list_slug'] == 'users'.$n) { 
  $q = $DB->query('SELECT user_username FROM ' . CHV\DB::getTable('users'). ' WHERE user_is_private = "0" ORDER BY user_id DESC LIMIT '.$max_url_limit.' OFFSET '.$uurl_offset.'');
  }
  }
  }

  $images = $DB->fetchAll();
  //Inner xml elements
  /////////////////////////////////////////////////////////////
  foreach($images as $image) {

  if($list['list_id'] == 'albums' and $count_albums > 0) {

  // Every album gets its own URL
  $cc = $xml2->addChild('url');
  $cc->addChild('loc', $handler->base_url.$site_album_route.'/'.CHV\encodeID($image['album_id'], 'encode') ); 

  }
 
  if($list['list_id'] == 'users' and $count_users > 0) {

  if ($site_user_route == '1') {
  $user_base_url = $handler->base_url;
  } else {
  $user_base_url = $handler->base_url.'user/';
  }
 
  // Every user gets their own URL
  $cc = $xml2->addChild('url');
  $cc->addChild('loc', $user_base_url.$image['user_username']); 

  }
 
  if($list['list_id'] == 'images' and $count_images > 0) { 

  $folder = '';

  switch ($image['image_storage_mode']){
  case 'datefolder':
  $folder = $image['year'].'/'.$image['month'].'/'.$image['day'].'/';
  break;

  default:
  $folder = '';
  break;
  }
 
  // Every image gets its own URL
  $cc = $xml2->addChild('url');
  $cc->addChild('loc', $handler->base_url.$site_image_route.'/'.CHV\encodeID($image['image_id'], 'encode') );
 
  if ($image['image_storage_id'] == NULL) {
  $image_base_url = $handler->base_url.$site_upload_image_route.'/';
  } else {
  $image_base_url = $image['storage_url'];
  } 

  $cc_image = $cc->addChild('xmlns:image:image');
  $cc_image->addChild('xmlns:image:loc', $image_base_url.$folder.$image['image_name'].'.'.$image['image_extension']);
  $cc_image->addChild("xmlns:image:title", htmlspecialchars($image["image_title"]));
  //if (strlen($image['image_description']) > 3) {
  //$cc_image->addChild('xmlns:image:caption', utf8_for_xml($image['image_description']));
  //}
  }

  }

  $dom = new DomDocument();
  $dom->loadXML($xml2->asXML());
  $dom->formatOutput = true;

  file_put_contents( $xml_local, $dom->saveXML(), LOCK_EX);
  }

  $dom = new DomDocument();
  $dom->loadXML($xml->asXML());
  $dom->formatOutput = true;

  if(file_put_contents('sitemap-index.xml', $dom->saveXML(), LOCK_EX) === false){
  die('Could not write sitemap-index.xml');
  }

  $handler::setVar('pre_doctitle', _s('XML Sitemaps'));

} catch(Exception $e) {
  G\exception_to_error($e);
}
};

?>
 
permiso!


You need to attach one more file :cool:

Template:
add to app/themes/Peafowl/views/xml-sitemap.php

PHP:
<?php if(!defined('access') or !access) die('This file cannot be directly accessed.'); ?>
<?php G\Render\include_theme_header(); ?>

<div class="content-width">
  <div class="page-not-found">
  <h1>NF Host XML Sitemaps</h1>
  <h4><a href="<?php echo G\get_base_url()."/sitemap-index.xml";?>">Index</a></h4>
  <br />

  <h5>Child Sitemaps</h5>
  <br />

  <div>
  <ul>
  <?php
  $cat = get_lists();
  foreach($cat as $key){
  echo "<li><a href=\"".G\get_base_url()."/".get_sitemapsFolder().$key["list_slug"].".xml"."\">".$key["list_name"]."</a></li>";
  }
  ?>
  </ul>
  </div>
  </div>
</div>

<?php G\Render\include_theme_footer(); ?>

<?php if(isset($_REQUEST["deleted"])) { ?>
<script>PF.fn.growl.call("<?php echo (G\get_route_name() == 'user' ? _s('The user has been deleted') : _s('The content has been deleted.')); ?>"); </script>
<?php } ?>
 
Back
Top