We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29988
    • 89 Posts
    This is an auto-generated support/comment thread for GoogleSiteMap_XML.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Renders Google Sitemaps XML output.
      • 32982
      • 674 Posts
      thanks for this usefoul code, i retouch a bit for show only public areas of the website
      think id usefoul
      hi
      /* GoogleSiteMap_XML Snippet for MODx
      Michal Till
      `->Based on Ryan Nutt’s Google Sitemap snippet for Etomite
      `->Based on the ListSiteMap snippet by JaredDC

      USAGE
      =====
      Use &allowedtemplates to specify templates, that would be included in the sitemap listing. SEPARATE BY COMMA. Don’t forget to switch mime type to text/xml. NOTE: &allowed templates may be case sensitive!

      ALERT: Change the website root url in the code! (will be solved in future versions)

      EXAMPLE
      =======
      [[GoogleSiteMap_XML? &allowedtemplates=`Site,Article,Homepage`]]

      */

      // Overcome single use limitation on functions
      global $MakeMapDefined;

      if(!function_exists(datediff))
      {
      function datediff($interval, $datefrom, $dateto, $using_timestamps = false) {
      /*
      $interval can be:
      yyyy - Number of full years
      q - Number of full quarters
      m - Number of full months
      y - Difference between day numbers
      (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
      d - Number of full days
      w - Number of full weekdays
      ww - Number of full weeks
      h - Number of full hours
      n - Number of full minutes
      s - Number of full seconds (default)
      */

      if (!$using_timestamps) {
      $datefrom = strtotime($datefrom, 0);
      $dateto = strtotime($dateto, 0);
      }
      $difference = $dateto - $datefrom; // Difference in seconds

      switch($interval) {

      case ’yyyy’: // Number of full years

      $years_difference = floor($difference / 31536000);
      if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) {
      $years_difference--;
      }
      if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) {
      $years_difference++;
      }
      $datediff = $years_difference;
      break;

      case "q": // Number of full quarters

      $quarters_difference = floor($difference / 8035200);
      while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
      $months_difference++;
      }
      $quarters_difference--;
      $datediff = $quarters_difference;
      break;

      case "m": // Number of full months

      $months_difference = floor($difference / 2678400);
      while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
      $months_difference++;
      }
      $months_difference--;
      $datediff = $months_difference;
      break;

      case ’y’: // Difference between day numbers

      $datediff = date("z", $dateto) - date("z", $datefrom);
      break;

      case "d": // Number of full days

      $datediff = floor($difference / 86400);
      break;

      case "w": // Number of full weekdays

      $days_difference = floor($difference / 86400);
      $weeks_difference = floor($days_difference / 7); // Complete weeks
      $first_day = date("w", $datefrom);
      $days_remainder = floor($days_difference % 7);
      $odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
      if ($odd_days > 7) { // Sunday
      $days_remainder--;
      }
      if ($odd_days > 6) { // Saturday
      $days_remainder--;
      }
      $datediff = ($weeks_difference * 5) + $days_remainder;
      break;

      case "ww": // Number of full weeks

      $datediff = floor($difference / 604800);
      break;

      case "h": // Number of full hours

      $datediff = floor($difference / 3600);
      break;

      case "n": // Number of full minutes

      $datediff = floor($difference / 60);
      break;

      default: // Number of full seconds (default)

      $datediff = $difference;
      break;
      }

      return $datediff;
      }
      }
      if(!isset($MakeMapDefined))
      {
      function MakeMap_snippet($funcEtomite, $listParent,$selfid=-1,$settings)
      {

      $children = $funcEtomite->getActiveChildren($listParent, "menuindex", "ASC", "id, editedon, template, privateweb ,alias");
      foreach($children as $child)
      {
      $id = $child[’id’];
      if ($selfid!=$id) {
      $url = "http://www.YOURWEBSITE.com/[~".$id."~]";
      $date = $child[’editedon’];
      $date = date("Y-m-d", $date);

      // Get the date difference
      $datediff = datediff("d", $date, date("Y-m-d"));
      if ($datediff <=1)
      {
      $priority = "1.0";
      $update = "daily";
      }
      elseif (($datediff >1) && ($datediff<=7))
      {
      $priority = "0.75";
      $update = "weekly";
      }
      elseif (($datediff >7) && ($datediff<=30))
      {
      $priority = "0.50";
      $update = "weekly";
      }
      else
      {
      $priority = "0.25";
      $update = "monthly";
      }
      if (@$settings["allowedtemplates"][$child["template"]]&&$child["privateweb"]==0) {
      $output .= "<url>\n";
      $output .= "<loc>$url</loc>\n";
      $output .= "<lastmod>$date</lastmod>\n";
      $output .= "<changefreq>$update</changefreq>\n";
      $output .= "<priority>$priority</priority>\n";
      $output .= "</url>\n";
      }
      if ($funcEtomite->getActiveChildren($child[’id’]))
      {
      $output .= MakeMap_snippet($funcEtomite, $child[’id’],$selfid,$settings);
      }
      }
      }
      return $output;
      }
      $MakeMapDefined = true;
      }


      $templatesok=array();
      @$allowedtemplates.="";
      $allowedtemplates=",".$allowedtemplates.",";
      $allowedtemplates=preg_replace("/ *, */",",",$allowedtemplates);
      $allowedtemplates=str_replace("’","",$allowedtemplates);
      $sql="select * from ".$this->getFullTableName(’site_templates’)." where POSITION(CONCAT(’,’,templatename,’,’) IN ’".$allowedtemplates."’)>0";
      $templates=$modx->db->query($sql);
      echo $query;
      while ($template=$modx->db->getRow($templates)) {
      $templatesok[$template["id"]]=true;
      }
      $settings["allowedtemplates"]=$templatesok;
      $out .= "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">\n";
      $out .= MakeMap_snippet($etomite, 0,$selfid,$settings);
      $out .= "</urlset>";
      return $out;
        Jabiertxof (formerly XYZVISUAL)
        My bussines: http://marker.es
        https://www.youtube.com/user/jabiertxof/videos
        • 25663 MODX Staff
        • 12,272 Posts
        That’s a great addition xyzvisual. Why not add it to the repository?
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 32982
          • 674 Posts
          i think is a good thing add to repository... tillda could update it hi
            Jabiertxof (formerly XYZVISUAL)
            My bussines: http://marker.es
            https://www.youtube.com/user/jabiertxof/videos
            • 33337
            • 3,975 Posts
            Quote from: xyzvisual at Jul 05, 2006, 01:42 PM

            i think is a good thing add to repository... tillda could update it hi

            You can add it as an "Extra", so main snippet and your modifications will remain stored side by side smiley
              Zaigham R - MODX Professional | Skype | Email | Twitter

              Digging the interwebs for #MODX gems and bringing it to you. modx.link
              • 28021
              • 13 Posts
              How to install this snippet and make it work? I get this error:

              XML-parsefout: geen element gevonden
              Locatie: http://www.allthingsroyal.net/googlesitemap.php
              Regelnummer 2, kolom 1:

              I created a new snippet with the code, and altered my URL in the code. Then I made a template (empty), and a new page with the code to call the snippet, [[GoogleSiteMap]] and set the page to XML content.
                • 29988
                • 89 Posts
                I’ve added the update to the repository.
                  • 29988
                  • 89 Posts
                  Quote from: sophietje at Jul 08, 2006, 05:35 AM

                  XML-parsefout: geen element gevonden
                  Locatie: http://www.allthingsroyal.net/googlesitemap.php
                  Regelnummer 2, kolom 1:

                  Well, if it’s a browser’s reply, there is probably something bad in the XML. This is nothing new, I’m constantlycrossing problems with
                  -bad encoding
                  -html entities

                  I don’t understand your language, so I can’t tell more.
                    • 28021
                    • 13 Posts
                    The error tells this: XML-parse error: no element found
                    Location : http://www.allthingsroyal.net/googlesitemap.php
                    Line 2, column 1

                    But did I install the snippet correctly? (see my previous post) That could be also the problem smiley
                      • 16879
                      • 87 Posts
                      I’m getting a very similiar output... any clues? Anybody? Help!