We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1764
    • 680 Posts
    It apears that regClientStartupScript is not working in 0.9.1. Here’s the fix:

    if (!empty($src) && array_key_exists($src, $this->loadedjscripts)) {
    


    if (!empty($src) && !array_key_exists($src, $this->loadedjscripts)) {
    


    in manager/includes/document.parser.class.inc.php.

    This fix has already been commited to SVN and will be fixed in the next release.
      • 32241
      • 1,495 Posts
      Ok, I found the problem. It’s from the MODx API. This is not a real solution to fix the API, but at least I know how to generate the same problem.

      Check this code (this is the fixed version, with some problem as well.
      <?php
      01	# Registers Client-side CSS scripts - these scripts are loaded at inside the <head> tag
      02	function regClientCSS($src){
      03		if ($this->loadedjscripts[$src]) return '';
      04		$this->loadedjscripts[$src] = true;
      05		if (strpos(strtolower($src),"<style")!==false||strpos(strtolower($src),"<link")!==false) {
      06			$this->sjscripts[count($this->sjscripts)] = $src;
      07		}
      08		else {
      09			$this->sjscripts[count($this->sjscripts)] = "<style type='text/css'>@import:url($src)</style>";
      10		}
      11	}
      12
      13	# Registers Startup Client-side JavaScript - these scripts are loaded at inside the <head> tag
      14	function regClientStartupScript($src, $plaintext=false){
      15		if (!empty($src) && !array_key_exists($src, $this->loadedjscripts)) {
      16			if ($this->loadedjscripts[$src]) 
      17				return '';
      18	
      19			$this->loadedjscripts[$src] = true;
      20			if ($plaintext==true) $this->sjscripts[count($this->sjscripts)] = $src;
      21			elseif (strpos(strtolower($src),"<script")!==false) $this->sjscripts[count($this->sjscripts)] = $src;
      22			else $this->sjscripts[count($this->sjscripts)] = "<script type='text/javascript' language='JavaScript' src='$src'></script>";
      23		}
      24	}
      25
      26	# Registers Client-side JavaScript 	- these scripts are loaded at the end of the page
      27	function regClientScript($src, $plaintext=false){
      28		if ($this->loadedjscripts[$src]) return '';
      29		$this->loadedjscripts[$src] = true;
      30		if ($plaintext==true) $this->jscripts[count($this->jscripts)] = $src;
      31		elseif (strpos(strtolower($src),"<script")!==false) $this->jscripts[count($this->jscripts)] = $src;
      32		else $this->jscripts[count($this->jscripts)] = "<script type='text/javascript' language='JavaScript' src='$src'></script>";
      33	}
      ?>
      


      The fix that needs to be done:
      1. Line 06: Change "$sjscripts" to "$this->sjscripts"
      2. Line 15: Change "!empty($src) && array_key_exists($src, $this->loadedjscripts)" to "!empty($src) && !array_key_exists($src, $this->loadedjscripts)"

      Now, with this fix, the problem still persist, the client side script won’t be attached to the output if you set the page uncached. So you need to make the page cached. After setting the page cached, the first time you access the page, it’s still gonna looks ugly, because this system won’t work when the page is still fetching from database. Now when you refresh the page, then the client scripts will be added. So for now, this is going to be a quick fix to the API. Maybe we need to fix this API, so that it will load the script, even the page is uncached/fetch from database.
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 32241
        • 1,495 Posts
        To answer the previous problem for register client script and etc, I just found out the real culprit behind this. So cabiscally if the snippet is set to uncached, then this will cause this problem, while if the snippet is being set to cached, then this problem won’t occured, due to the processing timing inside the parser. Anyway to make the story short, here is the fix.

        <?php
        01	function outputContent($noEvent=false) {
        02
        03		$this->documentOutput = $this->documentContent;
        04
        05		// check for non-cached snippet output
        06		if(strpos($this->documentOutput, '[!')>-1) {
        07			$this->documentOutput = str_replace('[!', '[[', $this->documentOutput);
        08			$this->documentOutput = str_replace('!]', ']]', $this->documentOutput);
        09
        10			// Parse document source
        11			$this->documentOutput = $this->parseDocumentSource($this->documentOutput);
        12			
        13			// Insert Startup jscripts & CSS scripts into template - template must have a <head> tag
        14			if ($js = $this->getRegisteredClientStartupScripts()){
        15				// change to just before closing </head>
        16				// $this->documentContent = preg_replace("/(<head[^>]*>)/i", "\\1\n".$js, $this->documentContent);
        17				$this->documentOutput = preg_replace("/(<\/head>)/i", $js."\n\\1", $this->documentOutput);
        18			}
        19            
        20			// Insert jscripts & html block into template - template must have a </body> tag
        21			if ($js = $this->getRegisteredClientScripts()){
        22				$this->documentOutput = preg_replace("/(<\/body>)/i", $js."\n\\1", $this->documentOutput);
        23			}
        24		}
        ?>
        


        Notice that the $this->documentOutput, before that it was setup as $this->documentContent. It’s located on line 17 & 22 on this code above. So to make registering the client script to work, please follow the fix on this post and the previous post.

        Thanks to Adam for pointing this out.

        This relates to bugs
        http://modxcms.com/bugs/task/124
        http://modxcms.com/bugs/task/220

        Note: I already fix this bugs, but I spent another 30 min to figure out the same problem. lol I think I need to have a better memory. embarrassed
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          All these fixes are starting to confuse me. Is there any chance somebody can attach a fully patched version of document.parser.class.inc.php that we can just swap out for the original?
            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
            • 32241
            • 1,495 Posts
            Quote from: sottwell at Feb 03, 2006, 02:26 AM

            All these fixes are starting to confuse me. Is there any chance somebody can attach a fully patched version of document.parser.class.inc.php that we can just swap out for the original?

            Sorry if this makes you confuse. All you need to do is search for a similar code inside the "/manager/includes/document.parser.class.php" and replace it with the code in my previous post. That’s all. Don’t forget to remove the line numbering as well. wink
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 15914
              • 145 Posts

              I have also included a little fix of my own. I removed

              [/list]
              language='JavaScript' 


              found in two places. On line 1962 and line 1972. This is to conform to the XHTML Strict 1.0 standard as this attribute was deprecated. (Should I log this in the bugtracker?)

              Another bug I found is that on line 1949:

              $this->sjscripts[count($this->sjscripts)] = "<style type='text/css'>@import:url($src)</style>";


              did not seem to be behave when @importing CSS. So I removed the colon (:) between @import and url, and it seems to work fine.

              I also changed the single quotes into double quotes. Not neccessary, just me being picky. I use double quotes in attributes throughout my HTML, that’s all.

              You need to place the document.parser.class.inc.php file in the /manager/includes/ folder.

              The other file, FileComparisonReport.html is a HTML report outlining the direct differences between the original file that shipped with MODx 0.9.1 (on the right), and my altered version including all the fixes above (on the left).

              For some reason however, I’m getting these two lines in my HTML source before the $modx->regClientStartupScript I’ve inserted:

              <script type="text/javascript">var MODX_MEDIA_PATH = "media";</script>
              <script type="text/javascript">var MODX_MEDIA_PATH = "media";</script>


              Any ideas?
                Kunal Kapoor
                Technical Director
                Limesharp Internet Limited - Effective, Functional, Standards Compliant

                IRC Nick: KingKoopa
                Skype ID: KingKoopa16
                • 25663 MODX Staff
                • 12,272 Posts
                I’ve seen the double media path as well. I’m not sure what’s causing it, but it’d be good to find out. Thanks for the great work on regClient...
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 15914
                  • 145 Posts
                  Quote from: rthrash at Feb 17, 2006, 09:02 AM

                  I’ve seen the double media path as well. I’m not sure what’s causing it, but it’d be good to find out.

                  I have found 6 instances of var MODX_MEDIA_PATH:

                  <script type="text/javascript">var MODX_MEDIA_PATH = "<?php echo IN_MANAGER_MODE ? "media":"manager/media"; ?>";</script>

                  <script type="text/javascript">var MODX_MEDIA_PATH = "<?php echo IN_MANAGER_MODE ? "media":"manager/media"; ?>";</script>

                  <script type="text/javascript">var MODX_MEDIA_PATH = "<?php echo IN_MANAGER_MODE ? "media":"manager/media"; ?>";</script>

                  var MODX_MEDIA_PATH = "media"; // set media path

                  <script type="text/javascript">var MODX_MEDIA_PATH = "<?php echo IN_MANAGER_MODE ? "media":"manager/media"; ?>";</script>

                  $modx->regClientStartupScript('<script type="text/javascript">var MODX_MEDIA_PATH = "'.(IN_MANAGER_MODE ? 'media':'manager/media').'";</script>');


                  If you comment out the last instance, it seems to work fine and both those MODX_MEDIA_PATHs disappear. Are there any consequences to this?
                    Kunal Kapoor
                    Technical Director
                    Limesharp Internet Limited - Effective, Functional, Standards Compliant

                    IRC Nick: KingKoopa
                    Skype ID: KingKoopa16
                    • 25663 MODX Staff
                    • 12,272 Posts
                    LOL... only 6, why when I was a childe we had TWELVE copies of the code in MODx... and we LIKED IT!

                    (seriously, that’s crazy!)
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 15914
                      • 145 Posts
                      Only the last one seems to matter though. Commenting that out seems to resolve the issue. The comment attached to it is:
                      // set media path for js scripts

                      So I’m not entirely sure if commenting it out was completely safe at all.
                        Kunal Kapoor
                        Technical Director
                        Limesharp Internet Limited - Effective, Functional, Standards Compliant

                        IRC Nick: KingKoopa
                        Skype ID: KingKoopa16