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

    I need to be able to export the header of a website im working to be able to place that header in a forum which is running outside modx.

    The site is multilingual and implements PMS’s YAMS Module which is quite awesome smiley

    So basically i need to be able to run the header snippet CACHEDfrom outside modx in a separate php file and then include that file in the top of the forum page.

    Iv looked into the modx api plugin which creats an instance of $modx in any php page you want, even outside the cms and then use the modx runSnippet() function to call the header.

    However this calls it uncached ie runs it. The fact that it runs uncached causes problems with the YAMS part of the header.

    Can anyone point me in the right direction on how to run snippets cached from pages outside modx? or a way around this.

    Thanks
      • 4310
      • 2,310 Posts
      To use a MODx menu on a Wordpress site I just had Wayfinder output on a document with a blank template then included that document into the Wordpress theme where the menu should be.
        • 1570
        • 38 Posts
        Could be a way:

        how diod you accomplish this exactly, im doing the following:

        $_REQUEST['id'] = 81;
        include('../index.php');


        yet i always get the homepage ie index.php?id=1

        Friendly URLs are active
          • 4310
          • 2,310 Posts
          This is the custom function defined in a Wordpress file that is included automatically within Wordpress :
          <?php
          function get_modx_content($url) {
          	$base_url = 'http://www.your-domain.com/';
          	$full_url = $base_url.$url;
          	$ch = curl_init();
          	curl_setopt ($ch, CURLOPT_URL, $full_url);
          	curl_setopt ($ch, CURLOPT_HEADER, 0);		
          	ob_start();
          	curl_exec ($ch);
          	curl_close ($ch);
          	$string = ob_get_contents();
          	ob_end_clean();  
          	echo $string; 
          }
          ?>  
          

          In the Wordpress theme I used :
          <?php get_modx_content('index.php?id=933'); ?>

          Document 933 is the MODx page that has the Wayfinder call.
          It may not do exactly what you want, but might help wink
            • 1570
            • 38 Posts
            Hi your script works perfect smiley also it seems to be secure as i turned off remote includes and remote fopen on the server and it worked fine.

            One minor issue tho, when i include the page in this way in what context does it run?

            The page im including calls some modx sessions and outputs either login/registration options or else logout.

            This page works fine when its called in the browser, however if i use the include method it never catches the session :/
              • 4310
              • 2,310 Posts
              Sorry, should have read your post more carefully.
              My method won’t take into account MODx sessions.
              It’s really only useful for grabbing dynamic html content.
                • 1570
                • 38 Posts
                No, actually im very gratefull for your code smiley

                I narrowed down the problem, its kinda strange.

                Basically i the page im calling using your script i have a function that reads a cookie
                if(!empty($_COOKIE[$cookie_name]))
                	{
                }


                so when i access the page directly via its url ie www.domain.com/index.php?id=999 it will work fine, however when the same exact page is included with a full url ie http://www.domain.com/index.php?id=999 be it via your code, an include or require statement or file_get_contents() the if statement will return false and not execute the code inside that collects the cookie and logs the user in.

                Strange, your code rocks cause its secure against cross site scripting but this issue is strange :/

                  • 1570
                  • 38 Posts
                    • 2777 ☆ A M B ☆
                    • 5 Posts
                    Hey AndrewBrg, i have kinda same problem, i’m running a snippet which sends an email retreiving data from item with other snippets, the problem is that if just print that data on the web page evrithing is fine, but in the email i just get the snippet call instead of the data, so what’s the name of that plugin you mention? maybe that could fix my problem. rolleyes