We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22851
    • 805 Posts
    Does anyone know between which two events in the system event cycle the [(site_start)], [(site_url)], etc. placeholders are parsed? I’d like to have the opportunity to alter the document output before MODx parses them.

    (Normally when I ask obscure technical questions like this Sottwell magically appears from somewhere and provides a clear answer. Hoping to see the puff of smoke...)

    Thanks.
      YAMS: Yet Another Multilingual Solution for MODx
      YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
      Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      http://www.sottwell.com/system-events.html

      These aren’t "parsed" as such, nor in any way connected to any document; they are taken from the siteCache.idx.php file’s arrays as one of the first actions of the parser when a page is requested, immediately after connecting to the database.

          function executeParser() {
              //error_reporting(0);
              if (version_compare(phpversion(), "5.0.0", ">="))
                  set_error_handler(array (
                      & $this,
                      "phpError"
                  ), E_ALL);
              else
                  set_error_handler(array (
                      & $this,
                      "phpError"
                  ));
      
              $this->db->connect();
      
              // get the settings
              if (empty ($this->config)) {
                  $this->getSettings();
              }
      
        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
        • 22851
        • 805 Posts
        I told you. Sottwell the forum genie.

        So, it looks like those placeholders are replaced before even the OnLoadWebDocument event occurs. Actually, that’s fine. I know how to achieve what I wanted now. Thanks.

        By the way, I have already used your system events page extensively. I wouldn’t have been able to develop YAMS without it. So, yet another reason to thank you!

        Cheers.
          YAMS: Yet Another Multilingual Solution for MODx
          YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
          Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Sorry, I misunderstood the question! At that point the template hasn’t even been loaded yet. But you mean when in the document being parsed are these tags being replaced, that’s a different matter altogether!

          Immediately after the onParseDocument event trigger, the document and template variables are processed, then the settings variables are processed:
          // combine template and document variables
          $source= $this->mergeDocumentContent($source);
          // replace settings referenced in document
          $source= $this->mergeSettingsContent($source);
          // replace HTMLSnippets in document
          $source= $this->mergeChunkContent($source);
          // insert META tags & keywords
          $source= $this->mergeDocumentMETATags($source);
          // find and merge snippets
          $source= $this->evalSnippets($source);
          // find and replace Placeholders (must be parsed last) - Added by Raymond
          $source= $this->mergePlaceholderContent($source);
          
            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
            • 22851
            • 805 Posts
            Yes. That is what I meant. That’s the point at which I guessed MODx would be replacing those placeholders... so I’m not sure why my initial attempt at replacing [(site_url)][~something~] with (yams_docr:something) during the onParseDocument event didn’t work. I suspect that there was a bug in my regexp.

            Currently YAMS deals with document variables transparently, so [*pagetitle*] will display the pagetitle in the correct language at all times - but all URLs have to be updated manually using a special YAMS placeholder, which is a pain. I’m hoping to get it so that YAMS will recognise MODx URLs and deal with them automatically too. That way you can just write (almost) pure MODx templates and it will transparently appear in the correct language.
              YAMS: Yet Another Multilingual Solution for MODx
              YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
              Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              So your plugin would need to deal with $modx->config[’site_url’] or other config array values in your plugin somewhere between OnWebPageInit and OnParseDocument if the document is not cached. If it’s cached, you’d have to catch it a lot earlier, before OnLoadWebPageCache.
                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
                • 22851
                • 805 Posts
                Got it working! Just before I parse my YAMS placeholders, I do the following:

                      // Do automatic conversion of quoted URLs
                      $content
                        = preg_replace(
                          '/"('
                            . '\[\(site_url\)\]'
                            . '|\[\(base_url\)\]'
                            . '|' . preg_quote( $this->itsMODx->config['site_url'], '/' )
                            . '|' . preg_quote( $this->itsMODx->config['base_url'], '/' )
                            . '|'
                            . ')'
                            . '\[~(.*)~\]"/U'
                            . $this->itsEncodingModifier
                          , '"(yams_docr:\2)"'
                          , $content
                          , -1
                        );
                


                Now whether or not the MODx placholders are in a state of having been replaced by MODx, this still transforms URLs of the form [~something~] preceded by [(site_url)], [(base_url)] or nothing to an equivalent YAMS placeholder.

                Now multilingual URLs are handled transparently too. Great! Not bad for what is effectively one line of PHP code.
                  YAMS: Yet Another Multilingual Solution for MODx
                  YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                  Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.