We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36693
    • 66 Posts
    Some interesting results!

    I inserted the following code as a VB plugin (VB does this with eval, I believe) and got some mixed output:

    The wayfinder snippets did not execute, but the chunk was called successfully. We’ve seen this behaviour before, but what I didn’t notice last time was that a nested "UltimateParent" snippet DID execute.

    I changed the calls so that they were cached, and they executed, but not the UP one although this time it looked like a parsing error. So, just randomly, I changed that to uncacheable and the whole thing worked. Amazing.

    Here’s the problem. The main ModX hosted site went blank, completely blank. No returned html or anything. The code also messed around with some database calls that followed in VB and a gallery that runs there too, on the same page.

    So, very good progress, thank you all, but some niggles which make this unusable at the moment. It looks as if ModX is being upset by foreign calls (the forums and site are on different subdomains... does this affect things?), and from what I can tell, bad encapsulation of database usage is causing them all to mess around with each other.

    <?php
    // I had to make this direct, as they are on different subdomains
    define('MODX_BASE_PATH', '/home/xxx/subdomains/pages/');
    
    define("IN_PARSER_MODE", "true");
    define("IN_MANAGER_MODE", "false");
    
    if (!defined('MODX_API_MODE')) {
        define('MODX_API_MODE', true);
    }
    
    // initialize the variables prior to grabbing the config file
    $GLOBALS['database_type'] = 'mysql';
    $GLOBALS['database_server'] = 'localhost';
    $GLOBALS['database_user'] = 'username';
    $GLOBALS['database_password'] = 'password';
    $GLOBALS['dbase'] = 'database';
    $GLOBALS['table_prefix'] = 'modx_';
    $GLOBALS['base_url'] = 'http://pages.bfenthusiasts.com/';
    $GLOBALS['base_path'] = '/home/xxx/subdomains/pages/';
    define('MODX_BASE_URL', $GLOBALS['base_url']);
    define('MODX_SITE_URL', $GLOBALS['base_url']);
    
    $ipath = ini_get('include_path');
    ini_set('include_path', $ipath . ':' . $GLOBALS['base_path']);
    
    // initiate a new document parser
    include_once($GLOBALS['base_path'].'manager/includes/document.parser.class.inc.php');
    $GLOBALS['modx'] = new DocumentParser;
    $modx =& $GLOBALS['modx'];
    $etomite = &$GLOBALS['modx']; // for backward compatibility
    
    // set some parser options
    $modx->minParserPasses = 1; // min number of parser recursive loops or passes
    $modx->maxParserPasses = 10; // max number of parser recursive loops or passes
    $modx->dumpSQL = false;
    $modx->dumpSnippets = false;
    $modx->tstart = $tstart; // feed the parser the execution start time
    
    $modx->getSettings();
    $modx->documentMethod = 'id';
    $modx->documentIdentifier = 71;
    
    // header
    $modx_navcanvas = $modx->rewriteUrls($modx->parseDocumentSource('{{NavigationCanvas}}'));  
      • 36693
      • 66 Posts
      I’ll look into saving the db setup, running my plugin, and then restoring the db variables to see if that helps with ahem enhacksulation. As for the blank page... ideas?
        • 20413
        • 2,877 Posts
        I haven’t had time to test this! Maybe post this problem inside that other thread to see if
        netProphET can give you some clues! smiley
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 36693
          • 66 Posts
          I’ve posted something there. All but one problem has been resolved:

          1. I tidy up ModX at the end of the plugin so that its resources do not affect the forum
          2. I define DISABLE_HOOKS in the ModX index, which includes vb, so that vb does not run any plugins, which include another instantiation of ModX obviously.

          However. The remaining problem. Outer uncached snippets do not fire within a chunk.

          My code so far for reference (perhaps useful to some)
          <?php
          /**
           * vBulletin plugin for collecting template data from ModX
           */
          
          global $vbulletin;
          
          // define the true pages location
          define('MODX_BASE_PATH', '/home/xxx/subdomains/pages/');
          
          define("IN_PARSER_MODE", "true");
          define("IN_MANAGER_MODE", "false");
          
          
          if (!defined('MODX_API_MODE')) {
              define('MODX_API_MODE', true);
          }
          
          
          // initialize the variables prior to grabbing the config file
          $GLOBALS['database_type'] = 'mysql';
          $GLOBALS['database_server'] = 'localhost';
          $GLOBALS['database_user'] = 'xxx';
          $GLOBALS['database_password'] = 'xxx';
          $GLOBALS['dbase'] = 'xxx';
          $GLOBALS['table_prefix'] = 'modx_';
          $GLOBALS['base_url'] = 'http://pages.bfenthusiasts.com/';
          $GLOBALS['base_path'] = '/home/xxx/subdomains/pages/';
          define('MODX_BASE_URL', $GLOBALS['base_url']);
          define('MODX_SITE_URL', $GLOBALS['base_url']);
          
          $ipath = ini_get('include_path');
          ini_set('include_path', $ipath . ':' . $GLOBALS['base_path']);
          
          // initiate a new document parser
          include_once($GLOBALS['base_path'].'manager/includes/document.parser.class.inc.php');
          $GLOBALS['modx'] = new DocumentParser;
          $modx =& $GLOBALS['modx'];
          $etomite = &$GLOBALS['modx']; // for backward compatibility
          
          // set some parser options
          $modx->minParserPasses = 1; // min number of parser recursive loops or passes
          $modx->maxParserPasses = 10; // max number of parser recursive loops or passes
          $modx->dumpSQL = false;
          $modx->dumpSnippets = false;
          $modx->tstart = $tstart; // feed the parser the execution start time
          
          $modx->getSettings();
          $modx->documentMethod = 'id';
          $modx->documentIdentifier = 71; //the location of the forums menu item, so it is "active" in the menu
          
          // header
          $modx_navcanvas = $modx->rewriteUrls($modx->parseDocumentSource('{{NavigationCanvas}}'));
          
          /* And put things back as we found them*/
          
          // reselect the forum database
          mysql_select_db('xxx');
          
          // unset all our new variables
          unset($etomite);
          unset($modx);
          unset($GLOBALS['modx']);
          unset($GLOBALS['database_type']);
          unset($GLOBALS['database_server']);
          unset($GLOBALS['database_user']);
          unset($GLOBALS['database_password']);
          unset($GLOBALS['dbase']);
          unset($GLOBALS['table_prefix']);
          unset($GLOBALS['base_url']);
          unset($GLOBALS['base_path']);
          
          define('MODX_BASE_URL', NULL);
          define('MODX_SITE_URL', NULL);
          define('MODX_BASE_PATH', NULL);
          define("IN_PARSER_MODE", NULL);
          define("IN_MANAGER_MODE", NULL);
          define('MODX_API_MODE', NULL);
          
          //and put the path back as we found it.
          ini_set('include_path', $ipath);
          
            • 20413
            • 2,877 Posts
            Outer uncached snippets do not fire within a chunk.

            But you say cached snippet does?
            http://modxcms.com/forums/index.php/topic,36619.msg221169.html#msg221169
              @hawproductions | http://mrhaw.com/

              Infograph: MODX Advanced Install in 7 steps:
              http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

              Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
              http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
              • 36693
              • 66 Posts
              I gave that a go (it’s a low traffic site really lol), and cleared all the cache and nothing changed. Is there more to it?
                • 36693
                • 66 Posts
                I had no success with the uncached calls, so I’ve played around a bit with the API, and do the following, instead of using parseDocumentSource:

                <?php
                // header 
                $bfe_ultimateparent = $modx->runSnippet("UltimateParent", array("topLevel" => "0")); 
                $modx_navcanvas = $modx->runSnippet("WayFinder", array( 
                    "startId" => "0", "config" => "dropline2")); 
                $modx_navcanvas = $modx_navcanvas . $modx->runSnippet("WayFinder", array( 
                    "startId" => $bfe_ultimateparent, "config" => "dropline2sub")); 
                $modx_navcanvas = "<div id=\"nav\">" . $modx->rewriteUrls($modx_navcanvas) . "</div>"; 
                


                It’s not ideal as it means updating the plugin every time the chunk changes, but it works!
                  • 20413
                  • 2,877 Posts
                  Nice
                    @hawproductions | http://mrhaw.com/

                    Infograph: MODX Advanced Install in 7 steps:
                    http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                    Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                    http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower