We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17673
    • 194 Posts

    I Checked the 2 docs again, they are both set to blank template, text/xml.

    I’m seeing the error outside the manager preview, but if I also logout from the manager I get a 404 error when opening http://mysite.com/sitemap.xml.

    Other random trials...
    If I remove the &startid=25 from the call it works again (but only lists 8 top level docs);
    changing the id to some other docid or moving sitemap.xml & sitemap.xls inside the folder where docid is both have no effect.

      ----------------------------------------------------------
      http://www.linkedin.com/in/lucapost/
      http://www.twitter.com/lukwe/
      ----------------------------------------------------------
      • 36541
      • 222 Posts
      Quote from: lukwe at Mar 28, 2007, 09:42 AM

      I Checked the 2 docs again, they are both set to blank template, text/xml.

      Are you using an empty template or the stock [tt](blank)[/tt] template? You should use a custom, empty template with no content. The [tt](blank)[/tt] template in fact is not a template.
        This is the web: the only thing you know about who will come is that you don't know who will come.
        • 17673
        • 194 Posts
        I thought your last suggestion would fix this when I first read it; but it does not .
        Nothing changed.
        I also tried using &\#187; for the parameters in the sitemap call, nothing.

        can it be something about Character encoding? I have it set to ’unicode UTF-8’ in the general MODx configuration.

        mistery.... Thanks anyhow !!
          ----------------------------------------------------------
          http://www.linkedin.com/in/lucapost/
          http://www.twitter.com/lukwe/
          ----------------------------------------------------------
          • 14050
          • 788 Posts
          I don’t know if this is redundant or not. But the template I use just contains [*content*], and it works fine.

          Here is the call I use:

          [!Sitemap? &format=`sp` &excludeTemplates=`blank, empty, hidden, sitemap`!]

          Hope that might help.
            Jesse R.
            Consider trying something new and extraordinary.
            Illinois Wine

            Have you considered donating to MODx lately?
            Donate now. Every contribution helps.
            • 36541
            • 222 Posts
            Quote from: lukwe at Mar 28, 2007, 12:24 PM

            I thought your last suggestion would fix this when I first read it; but it does not .
            (...) can it be something about Character encoding? I have it set to ’unicode UTF-8’ in the general MODx configuration.

            Then I have no idea why it doesn’t work. Sorry. It has nothing to do with content encoding. Besides, utf-8 is the default one for XML.

            The last try. Rename or remove `sitemap.xsl` and check if you can see the source of `sitemap.xml`. I mean display it in your browser and preview its source code. Don’t be scared by errors about missing `sitemap.xsl` - web crawlers don’t use them.

            Is your site available to the public? If it is, drop me its URL by PM or email. I’m curious what’s going on there.
              This is the web: the only thing you know about who will come is that you don't know who will come.
              • 17673
              • 194 Posts

              I tried putting [*content*] in template, renaming/deleting & re-downloading the .xsl, disactivating friendly urls, inserted the ’AddType application/xml .xsl’ in the .htaccess -NOTHING!

              I believe it has to do with the apache addressing for the site: to make the MODx content be the default one, instead of moving ’manager’, ’assets’ to the root level, the sys admin simply inserted a [tt]<VirtualHost *:80>DocumentRoot "/usr/local/apache2/htdocs/modx" (...)[/tt] directive in httpd.conf and left the modx directory untouched.

                ----------------------------------------------------------
                http://www.linkedin.com/in/lucapost/
                http://www.twitter.com/lukwe/
                ----------------------------------------------------------
                • 17673
                • 194 Posts

                After a few days of actually getting something done today I wasted time with the sitemap thing again; I tried to implement it with Ditto2 (see http://webbake.com/tutorials/modx-cms/google-sitemap-with-ditto) and got exactly the same errors as with the [[Sitemap]] snippet ; confirming that it has to be something at the server level which is not resolving xml content correctly.

                The only progress was discovering that switching the content-type to text/html returns an error:

                [tt]MODx Parse Error »
                MODx encountered the following error while attempting to parse the requested resource:
                « PHP Parse Error »
                PHP error debug
                Error: explode() [function.explode]: Empty delimiter.
                Error type/ Nr.: Warning - 2
                File: /user0/htdocs/modx/manager/includes/document.parser.class.inc.php(724) : eval()’d code
                Line: 195 [/tt]
                  ----------------------------------------------------------
                  http://www.linkedin.com/in/lucapost/
                  http://www.twitter.com/lukwe/
                  ----------------------------------------------------------
                  • 21056
                  • 327 Posts
                  Quote from: raum at Mar 21, 2007, 03:15 AM

                  Quote from: rthrash at Mar 20, 2007, 02:53 PM

                  Thanks raun. Maybe you could add it to the release in the repository as a new version. smiley

                  I think my contribution to this snippet is too small to release it under my name ;-) And I think, somebody should release a version which includes grad´s modifications or picachu´s modification too ... these work fine, at least for me ...

                  I have made a version of the Sitemap script which incorporates all these changes and some of my own (which makes attaching an XSL stylesheet optional, and allows you to specify it via a parameter as either an alias or an ID).

                  What is the etiquette of submitting improvements to the repository? If grad is about he’s welcome to do it -- maybe if there is no reply, in a few days I will post it. Code is here:

                  <?php
                  /*
                  ==================================================
                  	sitemap
                  ==================================================
                  
                  Outputs a machine readable site map for search
                  engines and robots. Supports the following
                  formats:
                  
                  - Sitemap Protocol used by Google Sitemaps
                    (http://www.google.com/webmasters/sitemaps/)
                  
                  - URL list in text format
                    (e.g. Yahoo! submission)
                  
                  Author: Grzegorz Adamiak [grad]
                  Version: 1.0.3 @ 2007-04-25
                  License: LGPL
                  MODx: 0.9.2.1
                  
                  History:
                  # 1.0.3
                  - NC added ability to specify the XSL URL - you don't always need one and it 
                    seems to create a lot of support confusion!
                    It is now a parameter (&xsl=``) which can take either an alias or a doc ID
                  - Modifications suggested by forum users Grad and Picachu incorporated
                    (http://modxcms.com/forums/index.php/topic,5754.60.html)
                  # 1.0.2
                  - Reworked fetching of template variable value to
                    get INHERITED value.
                  # 1.0.1
                  - Reworked fetching of template variable value,
                    now it gets computed value instead of nominal;
                    however, still not the inherited value.
                  # 1.0
                  - First public release.
                  
                  TODO:
                  - provide output for ROR
                  --------------------------------------------------
                  */
                  
                  /* Parameters
                  ----------------------------------------------- */
                  
                  # $startid [ int ]
                  # Id of the 'root' document from which the sitemap
                  # starts.
                  # Default: 0
                  
                  $startid = (isset($startid)) ? $startid : 0;
                  
                  # $format [ sp | txt | ror ]
                  # Which format of sitemap to use:
                  # - sp <- Sitemap Protocol used by Google
                  # - txt <- text file with list of URLs
                  # TODO - ror <- Resource Of Resources
                  # Default: sp
                  
                  $format = (isset($format) && ($format != 'ror')) ? $format : 'sp';
                  
                  # $priority [ str ]
                  # Name of TV which sets the relative priority of
                  # the document. If there is no such TV, this
                  # parameter will not be used.
                  # Default: sitemap_priority
                  
                  $priority = (isset($priority)) ? $priority : 'sitemap_priority';
                  
                  # $changefreq [ str ]
                  # Name of TV which sets the change frequency. If
                  # there is no such TV this parameter will not be
                  # used.
                  # Default: sitemap_changefreq
                  
                  $changefreq = (isset($changefreq)) ? $changefreq : 'sitemap_changefreq';
                  
                  # $excludeTemplates [ str ]
                  # Documents based on which templates should not be
                  # included in the sitemap. Comma separated list
                  # with names of templates.
                  # Default: empty
                  
                  $excludeTemplates = (isset($excludeTemplates)) ? $excludeTemplates : array();
                  
                  # $excludeTV [ str ]
                  # Name of TV (boolean type) which sets document
                  # exclusion form sitemap. If there is no such TV
                  # this parameter will not be used.
                  # Default: 'sitemap_exclude'
                  
                  $excludeTV = (isset($excludeTV)) ? $excludeTV : 'sitemap_exclude';
                  
                  # $xsl [ str ] 
                  # URL to the XSL style sheet
                  # or
                  # $xsl [ int ]
                  # doc ID of the XSL style sheet
                  
                  $xsl = (isset($xsl)) ? $xsl : '';
                  if (is_numeric($xsl)) { $xsl = $modx->makeUrl($xsl); }
                  
                  
                  /* End parameters
                  ----------------------------------------------- */
                  
                  # get list of documents
                  # ---------------------------------------------
                  $docs = getDocs($modx,$startid,$priority,$changefreq,$excludeTV);
                  
                  # filter out documents by template or TV
                  # ---------------------------------------------
                  // get all templates
                  $select = $modx->db->select("id, templatename", $modx->getFullTableName('site_templates'));
                  while ($query = $modx->db->getRow($select))
                  {
                  	$allTemplates[$query['id']] = $query['templatename'];
                  }
                  
                  // get templates to exclude
                  if (!empty ($excludeTemplates))
                  {
                  	$excludeTemplates = explode(",", $excludeTemplates);
                  	// trim template names and remove empty ones (just in case)
                  	foreach ($excludeTemplates as $template)
                  	{
                  		if (trim($template))
                  			$excludeTemplates[] = trim($template);
                  	} // end foreach
                  }
                  
                  // filter out documents
                  foreach ($docs as $doc)
                  {
                  	if (!in_array($doc['template'], array_flip(array_intersect($allTemplates, $excludeTemplates))))
                  		if (!$doc[$excludeTV] && $doc['published'] && $doc['template']!=0 )
                  			$output[] = $doc;
                  }
                  $docs = $output;
                  unset ($output, $allTemplates, $excludeTemplates);
                  
                  # build sitemap in specified format
                  # ---------------------------------------------
                  
                  switch ($format)
                  {
                  	case 'txt': // plain text list of URLs
                  
                  		foreach ($docs as $doc)
                  		{
                  			$url = '[(site_url)][~'.$doc['id'].'~]';
                  
                  			$output .= $url."\n";
                  		} // end foreach
                  		break;
                  
                  	case 'ror': // TODO
                  	default: // Sitemap Protocol
                  
                  		// Modified by NC
                  		$output = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
                  		if ($xsl != '') {
                  			$output .='<?xml-stylesheet type="text/xsl" href="'.$xsl.'"?>'."\n";
                  		}
                  		$output .='<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
                  		// End modified by NC
                  		
                  		foreach ($docs as $doc)
                  		{
                  			$url = '[(site_url)][~'.$doc['id'].'~]';
                  			$date = $doc['editedon'];
                  			$date = date("Y-m-d", $date);
                  			$docPriority = ($doc[$priority]) ? $doc[$priority] : 0; // false if TV doesn't exist
                  			$docChangefreq = ($doc[$changefreq]) ? $doc[$changefreq] : 0; // false if TV doesn't exist
                  
                  			$output .= "\t".'<url>'."\n";
                  			$output .= "\t\t".'<loc>'.$url.'</loc>'."\n";
                  			$output .= "\t\t".'<lastmod>'.$date.'</lastmod>'."\n";
                  			$output .= ($docPriority) ? ("\t\t".'<priority>'.$docPriority.'</priority>'."\n") : ''; // don't output anything if TV doesn't exist
                  			$output .= ($docChangefreq) ? ("\t\t".'<changefreq>'.$docChangefreq.'</changefreq>'."\n") : ''; // don't output anything if TV doesn't exist
                  			$output .= "\t".'</url>'."\n";
                  		} // end foreach
                  		$output .= '</urlset>';
                  
                  } // end switch
                  
                  return $output;
                  
                  # functions
                  # ---------------------------------------------
                  
                  # gets (inherited) value of template variable
                  function getTV($modx,$docid,$doctv)
                  {
                  /* apparently in 0.9.2.1 the getTemplateVarOutput function doesn't work as expected and doesn't return INHERITED value; this is probably to be fixed for next release; see http://modxcms.com/bugs/task/464
                  	$output = $modx->getTemplateVarOutput($tv,$docid);
                  	return $output[$tv];
                  */
                  	
                  	while ($pid = $modx->getDocument($docid,'parent'))
                  	{
                  		$tv = $modx->getTemplateVar($doctv,'*',$docid);
                  		if (($tv['value'] && substr($tv['value'],0,8) != '@INHERIT') or !$tv['value']) // tv default value is overriden (including empty)
                  		{
                  			$output = $tv['value'];
                  			break;
                  		}
                  		else // there is no parent with default value overriden 
                  		{
                  			$output = trim(substr($tv['value'],8));
                  		}
                  		$docid = $pid['parent']; // move up one document in document tree
                  	} // end while
                  	
                  	return $output;
                  }
                  
                  # gets list of published documents with properties
                  function getDocs($modx,$startid,$priority,$changefreq,$excludeTV)
                  {
                  	// get children documents
                  	$docs = $modx->getAllChildren($startid,'menuindex','asc','id,editedon,template,published'); 
                  	// add sub-children to the list
                  	foreach ($docs as $key => $doc)
                  	{
                  		$id = $doc['id'];
                  		$docs[$key][$priority] = getTV($modx,$id,$priority); // add priority property
                  		$docs[$key][$changefreq] = getTV($modx,$id,$changefreq); // add changefreq property
                  		$docs[$key][$excludeTV] = getTV($modx,$id,$excludeTV); // add excludeTV property
                  		if ($modx->getActiveChildren($id))
                  			$docs = array_merge($docs, getDocs($modx,$id,$priority,$changefreq,$excludeTV));
                  	} // end foreach
                  	return $docs;
                  }
                  ?>
                    Author: ManagerManager plugin - customise your ModX manager interface

                    Rckt - web development, Sheffield, UK
                    • 13667
                    • 3 Posts
                    Thanks to Grad and all who contributed to this helpful snippet!
                    I use it along with MetaTagsExtra (http://modxcms.com/MetaTagsExtra-930.html) for SEO.
                    MetaTagsExtra has a useful feature, which in it’s documentation is described and reasoned as follows:
                    When you mark a page as "NOT searchable" - a Robots meta tag
                    with "noindex, nofollow" is inserted to keep web search engines
                    from indexing that document. After all, there’s little value in
                    making your MODx document unsearchable to MODx, when
                    Google still knows where it is!
                    I’ve made two little modifications to the Sitemap snippet, which adopt this behavior, by excluding documents with unchecked searchable-option in manager, from sitemaps output.
                    In v1.0.3 on line 137 add "&& $doc[’searchable’]" to the condition, that it reads:
                    		if ( !$doc[$excludeTV] && $doc['published'] && $doc['template']!=0 && $doc['searchable'])

                    and on line 223 add ",searchable" to the argument string:
                    	$docs = $modx->getAllChildren($startid,'menuindex','asc','id,editedon,template,published,searchable'); 


                    Greetz
                    JayBee
                      • 21056
                      • 327 Posts
                      Quote from: ncrossland at Apr 25, 2007, 08:08 AM


                      I have made a version of the Sitemap script which incorporates all these changes and some of my own (which makes attaching an XSL stylesheet optional, and allows you to specify it via a parameter as either an alias or an ID).

                      What is the etiquette of submitting improvements to the repository? If grad is about he’s welcome to do it -- maybe if there is no reply, in a few days I will post it. Code is here:


                      This is now posted in the repository.
                        Author: ManagerManager plugin - customise your ModX manager interface

                        Rckt - web development, Sheffield, UK