We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40045
    • 534 Posts
    Just playing around with the idea to autogenerate a sitemapindex file, for that I'd like to use (partly) the existing GoogleSiteMap snippet. I call it like this:

    $sitemaps = $modx->runSnippet('GoogleSiteMap', array('showHidden' => true, 'searchable' => false, 'where' => array('alias' => 'sitemap'), 'context' => 'contextde'));
    
    // i also tried with a JSON string because as you can see in the code below, this seems to be possible (fromJSON)
    
    $sitemaps = $modx->runSnippet('GoogleSiteMap', array('showHidden' => true, 'searchable' => false, 'where' => '{"alias":"sitemap"}', 'context' => 'contextde'));
    


    in the code of the googlesitemap.class.php there is at line 199 the following section of code:

            /* where filtering */
            if (!empty($this->config['where'])) {
                $where = is_array($this->config['where']) ? $this->config['where'] : $this->modx->fromJSON($this->config['where']);
                $this->modx->log(modX::LOG_LEVEL_ERROR, 'where conditions: ' . print_r($where)); // I added this...for debugging...
                $c->where($where);
            }
    


    in the RTFM for the extra there is nothing mentioned about that where filtering but it seems to implement that and it would be exactly what I need =)...

    Basically it seems to be an xPDO where query right? http://rtfm.modx.com/display/xPDO20/xPDOQuery.where

    There it says: Equals -> Operator "none" results in
    $query->where(array('width' => 15));

    looks quite similar to what would be sent to the DB from that snippet call above...

    what I want is to select all the resources (across different contexts -> multilingual site) with the alias "sitemap", ie domain.tld/de/sitemap.xml, domain.tld/en/sitemap.xml and so on...these resources are hidden from menus and not searchable). As can be seen above, I tried if the parameter $where is passed when calling the snippet, this is the case but it doesn't have any effect or the effect that nothing is in the output (but I have a resource with an alias of "sitemap" in the specified context (will add more when it works for one...).

    so my question is, should that work what I'm trying here, or am I missing something completely?

    thanks in advance for tipps! [ed. note: exside last edited this post 13 years, 9 months ago.]
      • 40045
      • 534 Posts
      Really nobody has a clue about this? I would like to use this (and it doesn't seem to be such a big thing, because the code seems already there) and also add it to the documentation (where it's missing). But as long as cannot figure out what the heck I'm doing wrong, I cannot do this^^...
        • 38169
        • 7 Posts
        You can use Wayfinder to create the sitemapindex file. If you want to do it yourself (althought wayfinder code is perfect) you can querry and get the modx resources using xPDOCriteria to create the criteria for the get and then get them with getCollection etch...
          • 40045
          • 534 Posts
          @cktdesign: Finally I'll have to try your suggestions =), so thank you very much for those!

          I usually don't have problems with xpdo->where() queries (although they are kind of tricky sometimes) but what really made me hairpulling is that I could not get it to work with that snippet GoogleSiteMap, even when that functionality seems implemented (but not documented) and the $where param is passed in correctly, transformed into an array but it doesn't return anything^^...

          so maybe I get some insights into my problem if @splittingred aka. the author had a quick look over what I tried above and maybe the where functionality is plain and simple not ready to use and thus not documented...I don't know =)
            • 38169
            • 7 Posts
            It is strange that you get empty output, your examples seem valid. Also after a quick look at the sitemap class i am pretty sure there are no errors or problems in where filtering functionality.
              • 40045
              • 534 Posts
              =), at least you also see that like me...and indeed it works with everything else I tried, I could filter for example all resources that are published (there the resources in containers [see explanation below code] are shown!!) or searchable or have a specific pagetitle or even use the :LIKE filter, so my where conditions looked like:

              // published -> works
              $where = array('published' => 1);
              
              // searchable -> works
              $where = array('searchable' => 1);
              
              // pagetitle -> works
              $where = array('pagetitle:LIKE' => 'What');
              
              // LIKE filtering -> works
              $where = array('alias:LIKE' => 'w%');
              
              // and I can even do -> works...
              $where = array('alias' => 'what');
              


              I somehow narrowed it down:

              It is not specific to WHAT kind of criteria you're filtering (also 'id' => 22, which would be that document, doesn't work) but where that document is in the document tree...

              that sitemap resource lies in a continer "outsites" like so (around the rest of the structure, more simple is almost not possible, the names are the aliases of the resources):

              what            // (container) -> can be accessed with where
                  links        // (container) -> CANNOT BE ACCESSED with where
              we               // (normal resource) -> can be accessed with where
              do               //(normal resource) -> can be accessed with where
              outsites       // (hidden from menu, container) -> can be accessed with where
                  sitemap   //(normal resource, xml content type, but doesn't matter if html, xml or whatever) -> CANNOT BE ACCESSED with where
              


              nothing special, but somehow I cannot get ANY resources with the where filter inside a container, also not other sites that are children of another resource. If I move that "sitemap" resource up one level (siteroot/contextroot) then the where filter gets it without problems...so this seems really something buggy that the core devs should have a look at I think or then I miss something completely^^ (I also tried to set the &maxDepth param explicitly to 0, but that's default...and didn't help) =), any ideas?

              EDIT: Something really even more strange -> When I do array('published' => 1); as where condition then it show all the resources, also the ones in containers (ie the ones with alias = sitemap too), so they don't seem to be really hidden from the snippet^^ but as soon as I add something else like array('published' => 1, 'id' => 22); then everything breaks and I don't get anything back. I also played around with different events, from OnInitCulture to OnWebPageComplete. I also "outsourced" the plugin in a snippet "sitemapIndex" and called it in a resource, also didn't help...

              what I tried is also to track down if something is not passed anywhere, for this I added added to googlesitemap.class.php:

              /* where filtering */
                      if (!empty($this->config['where'])) {
                          $where = is_array($this->config['where']) ? $this->config['where'] : $this->modx->fromJSON($this->config['where']);
                          $c->where($where);
                          $this->modx->log(modX::LOG_LEVEL_ERROR, 'where query: ' . $this->config['where'] . ' becomes ' . print_r($where, true)); // added
                      }
              
              // which gives me
              [2012-12-14 11:32:40] (ERROR @ /path/to/index.php) where query: {"alias":"sitemap"} becomes Array
              (
                  [alias] => sitemap
              )
              


              in my opinion that looks fine =) [ed. note: exside last edited this post 13 years, 9 months ago.]
                • 40045
                • 534 Posts
                Tried the same with getResources, and this returns the (debug) array (because no tpl is specified) from the desired resource^^...I really don't get it, is that a bug in xpdo, in GoogleSitemap or where (cannot see anything wrong in both, because getResources is probably also using the xpdo->where() query, like GoogleSitemap, and when it works in getResources, there does not seem to be a bug, and it also works in GoogleSitemap, just not for sites in a container^^)?

                $sitemaps = $modx->runSnippet('getResources', array('parents' => 16, 'showHidden' => 1, 'includeTVs' => 0, 'context' => 'contextname', 'where' => '{"alias":"sitemap"}'));


                The reason I'm still trying to do this with GoogleSitemap is the automatic calculating of the priority parameter...don't like to have a TV for that (like proposed in the getResources Sitemap example), and it would probably be the same with Wayfinder...and it's also nagging on me that I cannot get this to work with GoogleSitemap while everything needed seems to be there =D
                [ed. note: exside last edited this post 13 years, 9 months ago.]
                  • 28107
                  • 230 Posts
                  maybe you can have a look at sitemapfriend for reference ?
                    CONIN Werbeagentur . Köln
                    http://www.conin.de
                    • 40045
                    • 534 Posts
                    @spackko: Thanks for the suggestion, I just checked the rtfm/code of sitemapFriend but unfortunately there is no custom expression "where" feature implemented (nor mentioned in the docs, which was also the case in GoogleSiteMap, but that's fixed now)...so looks like I have to wait until @splittingred can shed a light on what's happening (or not happening) under the hood there =)