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

    I am trying to intergrate external php file in Modx, the code does Dynamic Text Replacement with my own font, http://www.joaomak.net/util/dtr/.

    To use this script on a normal php page, I just need to Include the script in the top of the page.

    In Modx I have included the file in a snippet, and call this snippet on top of the template, but it’s not working.

    Does anyone can help.
      • 26903
      • 1,336 Posts
      Are you getting any errors in your webserver error log? The snippet should be something like this :-
      <?php
      include(’path to php file’);
      ?>
      and called like this :-
      [[snippet]] or [!snippet!] for uncached calls.


        Use MODx, or the cat gets it!
        • 24160
        • 15 Posts
        Yes, that’s what I did.

        Can not get the code working.

        Does anyone did text replacement before in MODX, I don’t want to use sIRF .

        Hope someone can have a look this text replacement, if we could make a plugin based on this that would be great.

          • 16034
          • 107 Posts
          I just scanned the code quickly, it seems like it is using the output buffer (ob_end_flush) in the example. It is also being used by snippet-handling in MODx. So I think that’s where you should start your debug.

          After a bit more research I found this in the readme-file:

          * If you are using this script in a CMS that doesn't allow you to use output 
            buffering functions, simply comment the line with `ob_start('PCDTR_init');` in 
            the class.php file and, in your code, execute $content=PCDTR_init($content); 
            with your generated content string.


          I think the right place to put this in MODx is in a plugin, after the content has been rendered.
            MODx snippet-glossary 101:
            Ditto = Content Lister -- Wayfinder == Menu Builder -- Jot = Comment Control
            • 24160
            • 15 Posts
            Yes, I got it working in the plugin, but the text does not change dynamicly

            I comment the line with `ob_start(’PCDTR_init’);` in the class.php file and created an OnWebPagePrerender plugin with the following code

            include (’pcdtr/php/class.php’);
            $o = &$modx->documentOutput;
            $o=PCDTR_init($o);

            I got it working with the test code, but after i change the text, the out put text is still old text it doesn’t change, after a bit search I got gtext snippet working in similar way, but still want to find out why problem happened in the PCDTR text replacement.



              • 36805
              • 354 Posts
              Your plugin approach is a good one, thanks for sharing!

              If finally figured out how to achieve pcdtr integration! The problem that remained was the $_SESSION variables set in class.php which could not be retrieved by external png.php and css.php. The class.php itself is included into MODx context (index.php) and stores its data in that session, the other 2 can’t do that.

              Text, path and css parameters are shared between scripts through $_SESSION variables. This is the reason you kept seeing your old example text, new values set in a different context have no effect.

              In order to gain access to those variables you need to call startCMSSession() in the beginning of those external php files, read here for more info.

              PS: This is untested since I took a different approach before. Currently I use pcdtr working by similating png.php and css.php files through friendly urls and MODx documents. This approach has many problems, most importantly with path settings. Use the startCMSSession approach instead and all your trouble should go away.