We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20349 ☆ A M B ☆
    • 453 Posts
    I have a problem...

    When I post some news on my site, in the url.com/sitemap.xml displays
    <url>
    <loc>http://url.com/arhiva/article-1180706927</loc>
    <lastmod>1969-12-31</lastmod>

    When I edit the document (news) through Manager, it displays the <lastmod> correctly.
    What’s the deal? I want to display the date correctly when I publih the news...

    huh
      BASE - Web Design Studio
      MODX Ambassador

      Website
      • 13246
      • 42 Posts
      hello,

      when I have installed this snippet as I can read on the wiki. I get this error:

      faultCode0faultStringFatal error:Cannot redeclare gettv() (previously declared in /home/vol2/nexethosting.com/nexet_1097593/steunpunt.nexethosting.com/htdocs/manager/includes/document.parser.class.inc.php(766) : eval()’d code:194) in /home/vol2/nexethosting.com/nexet_1097593/steunpunt.nexethosting.com/htdocs/manager/includes/document.parser.class.inc.php(766) : eval()’d code on line 217

      I use modx version 0.9.6 and simple url’s with the .htacces

      What can I do to fix this?

      Ivar
        • 7554
        • 1 Posts
        Hi,

        when i use this snippet without xsl, everything works fine. Sitemap looks great, google accepts.

        But: With xsl the sitemap seems to be empty... (although the source contains the data, it is not rendered, and: "Number of sitemaps in this Google sitemap index: 0")

        i use modx 0.9.6; the newest sitemap-snippet-version, my calls are:
        sitemap.xml:
        [!SiteMap? &format=`sp` &startid=`0` &xsl=``!]

        sitemap_.xml:
        [!SiteMap? &format=`sp` &startid=`0` &xsl=`sitemap.xsl`!]
        

        document sitemap.xsl contains the downloaded stylesheet.

        You can access them: http://burg-kl.de/sitemap.xml resp. /sitemap_.xml

        Any ideas? Thanks!
          • 13246
          • 42 Posts
          My problem is solved.
            • 5727
            • 160 Posts
            Quote from: dj at Oct 24, 2007, 04:56 AM

            Hi,

            when i use this snippet without xsl, everything works fine. Sitemap looks great, google accepts.

            But: With xsl the sitemap seems to be empty... (although the source contains the data, it is not rendered, and: "Number of sitemaps in this Google sitemap index: 0")

            i use modx 0.9.6; the newest sitemap-snippet-version, my calls are:
            sitemap.xml:
            [!SiteMap? &format=`sp` &startid=`0` &xsl=``!]

            sitemap_.xml:
            [!SiteMap? &format=`sp` &startid=`0` &xsl=`sitemap.xsl`!]
            

            document sitemap.xsl contains the downloaded stylesheet.

            You can access them: http://burg-kl.de/sitemap.xml resp. /sitemap_.xml

            Any ideas? Thanks!


            The XSL has not been updated since 2005 and still only supports the old Google format. You will have to use version 1.0.2 of the snippet or design a new XSL.
              Olivier Deland
              Montreal, Canada - Web Developer
              • 7111
              • 30 Posts
              Quote from: grad at Jan 24, 2007, 08:11 AM

              Quote from: ricardosanX at Jan 24, 2007, 05:42 AM

              Is there any way to get this Snippet to display pages that are nested within Unpublished folders. My blog pages are accessed via the Ditto Snippet, so are inside an Unpublished folder.

              Try this:

              <?php
              # @line 119
              if (!$doc[$excludeTV]) // remove
              if (!$doc[$excludeTV] && $doc['published'] && $doc['template']!=0) // add
              
              # @line 198
              $docs = $modx->getActiveChildren($startid,'menuindex','asc','id,editedon,template'); //remove
              $docs = $modx->getAllChildren($startid,'menuindex','asc','id,editedon,template,published'); // add
              
              # @line 206
              if ($modx->getActiveChildren($id)) // remove
              if ($modx->getAllChildren($id)) // add
              ?>


              The change includes also filtering out documents with no template inteded for weblinks.

              Is there a way to also include documents in the sitemap that are flagged as private?
                • 3177
                • 137 Posts
                Hello,

                I took the liberty to create a version 1.0.4 of this snippet.
                What I added was a display option called ’ulli’. This creates the
                sitemap as an Unordered list (<ul><li> structure) containing
                links to the document and the pagename as the text of the link.
                Next step, but not yet implemented, is the option to sort the
                docs on ’menu index’ and display the ul-li tree in multilevel
                according to the document tree. (Will be version 1.0.4-2 wink )

                Since I don’t know how to officially upgrade a snippet, and I
                don’t want to since I am not the owner of the snippet, I have
                posted the code below.

                Regards,

                Bert Catsburg

                <?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.4 (By Bert Catsburg, [email protected])
                - Added display option 'ulli'. 
                  An <ul><li> list of all published documents.
                # 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)
                {
                	// Next case added in version 1.0.4
                	case 'ulli': // UL List
                		$output .= "<ul class=\"sitemap\">\n";
                		// TODO: Sort the array on Menu Index
                		// TODO: Make a nested ul-li based on the levels in the document tree.
                		foreach ($docs as $doc)
                		{
                			$s  = "  <li class=\"sitemap\">";
                			$s .= "<a href=\"[(site_url)][~" . $doc['id'] . "~]\" class=\"sitemap\">" . $doc['pagetitle'] . "</a>";
                			//$s .= "id = [~" . $doc['id'] . "~]<br>";
                			//$s .= "editedon = " . $doc['editedon'] . "<br>";
                			//$s .= "template = " . $doc['template'] . "<br>";
                			//$s .= "published = " . $doc['published'] . "<br>";
                			//$s .= "pagetitle = " . $doc['pagetitle'] . "<br>";
                			$s .= "</li>\n";
                			$output .= $s;
                		} // end foreach
                		$output .= "</ul>\n";
                		break;
                		
                	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,pagetitle'); 
                	// 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;
                }
                ?>
                

                  • 25663 MODX Staff
                  • 12,272 Posts
                  Thanks for updating the code. One of the reasons we made the repository updateable by anyone is in the event the original author moves on or is otherwise unavailable. There’s a button in the repository on each add on that allows you to upload a new version.
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 17340
                    • 70 Posts
                    I installed SiteMap in a pre-production MODx-test-site located in a sub-directory and promptly get the error report:

                    (by doing your-domain/sitemap.xml and ending up nicely at the MODx-correct document)

                    XML-parse error: XML-declaration is not at the beginning of external entity..

                    OK, I understand that, but then it states:

                    Line 112, colomn 1:

                    <?xml version="1.0" encoding="UTF-8"?>
                    ^

                    is that for the same reason ? (the file not located in the root?)

                    and is it possible to simulate the SiteMap temporarely in a subdirectory for test reasons ?

                    such that when we decide to change it into a production site we have it up and running including the SiteMap in no time ?

                    thanks
                    lmv
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      I really have only the vaguest idea of what I’m talking about here, but might this work if the document in question has no template? It may be that the template’s head code is being inserted by the MODx parser, then the XML stuff, which of course the XML reader at Google won’t like at all.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org