We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7923
    • 4,213 Posts
    Quote from: Djamoer at Apr 07, 2006, 04:57 AM

    Ehmm... I think the one that I provided in the previous post and on bug tracker works just fine though.
    Anyway, it works on me, but it doesn’t me that it’s the best way to go.
    Btw, it needs the fix from Adam’s as well.

    Take care.
    Wendy,

    With your and adam’s fixes, If I call the snipped in an uncached document with [[mySnippet]], I get the regClientCSS and regClientStartupScript twice in the <head> section, and at the second time, it doesn’t parse modx tags in the scripts like [*id*] for example.

    If I call the snippet in an uncached document with [!mySnippet!], I only get the regClientCSS and regClientStartupScript once at the <head>, but it doesn’t parse the modx tags that are in the scripts.

    By commenting lines 380 through 390 (in the Kunal’s attatched document.parser.class) that have all your fixes, It works if the snippet is called with [[mySnippet]], but when calling uncached like [!mySnippet!] nothing comes to the <head>.

    So the fixes you have pointed out are definently an improve, but not a fix to the problem. rolleyes There’s still something fishy going on in outputContent function.


      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
      • 20813
      • 1 Posts
      I couldn’t find it in my searches but is anyone else having issues untarring this file?

      This is what I get on CentOS 3.6

      root@server]# tar -xzvf MODx-0.9.1.tar.gz
      tar: This does not look like a tar archive
      tar: Skipping to next header
      tar: Archive contains obsolescent base-64 headers
      tar: Error exit delayed from previous errors

      Thank you.
        • 32241
        • 1,495 Posts
        Thanks for clarifying that doze.
        I never actually try that combination that you pointed out before. It does make some sense to me now.

        I think Jason will have a better solution. Btw, if I found something to fix it, I’ll post it up in this thread.

        Sincerely,
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media
          • 32241
          • 1,495 Posts
          Ok guys, here is the fix that I did, so far it works on mine.

          * Fixed loading an uncached snippet client script when using the given API
          * Fixed double loading client script on uncached document and using cached snippet tag
          * Fixed MODx tag parsing on uncached snippet

          Replace outputContent function on document.parser.class.inc.php with the one provided below.
          	function outputContent($noEvent=false) {
          
          		$this->documentOutput = $this->documentContent;
          
          		// check for non-cached snippet output
          		if(strpos($this->documentOutput, '[!')>-1) {
          			$this->documentOutput = str_replace('[!', '[[', $this->documentOutput);
          			$this->documentOutput = str_replace('!]', ']]', $this->documentOutput);
          
          			// Clean up client script array
          			$this->jscripts = array();
          			$this->sjscripts = array();
          
          			// Parse document source
          			$this->documentOutput = $this->parseDocumentSource($this->documentOutput);
          			
          			// Insert Startup jscripts & CSS scripts into template - template must have a <head> tag
          			if ($js = $this->getRegisteredClientStartupScripts()){
          				// change to just before closing </head>
          				$this->documentOutput = preg_replace("/(<\/head>)/i", $js."\n\\1", $this->documentOutput);
          			}
          			// Insert jscripts & html block into template - template must have a </body> tag
          			if ($js = $this->getRegisteredClientScripts()){
          				$this->documentOutput = preg_replace("/(<\/body>)/i", $js."\n\\1", $this->documentOutput);
          			}
          			
          			// Parse document source
          			$this->documentOutput = $this->parseDocumentSource($this->documentOutput);
          		}
          
          		// Parse document source
          			$this->documentOutput = $this->parseDocumentSource($this->documentOutput);
          
          		// remove all unused placeholders
          		if(strpos($this->documentOutput, '[+')>-1) {
          			$matches= array();
          			preg_match_all('~\[\+(.*?)\+\]~', $this->documentOutput, $matches);
          			if($matches[0]) $this->documentOutput = str_replace($matches[0],'',$this->documentOutput);
          		}
          
          		$this->documentOutput = $this->rewriteUrls($this->documentOutput);
          		
          		$totalTime = ($this->getMicroTime() - $this->tstart);
          		$queryTime = $this->queryTime;
          		$phpTime = $totalTime-$queryTime;
          
          		$queryTime = sprintf("%2.4f s", $queryTime);
          		$totalTime = sprintf("%2.4f s", $totalTime);
          		$phpTime = sprintf("%2.4f s", $phpTime);
          		$source = $this->documentGenerated==1 ? "database" : "cache";
          		$queries = isset($this->executedQueries) ? $this->executedQueries : 0 ;
          
          		// send out content-type and content-disposition headers
          		if(IN_PARSER_MODE=="true") {
          			$type = !empty($this->contentTypes[$this->documentIdentifier]) ? $this->contentTypes[$this->documentIdentifier] : "text/html";
          			$header = 'Content-Type: '.$type.'; charset='.$this->config['etomite_charset'];
          			header($header);
          			if(!$this->checkPreview() && $this->documentObject['content_dispo']==1) {
          				if($this->documentObject['alias']) $name = $this->documentObject['alias'];
          				else {
          					// strip title of special characters
          					$name = $this->documentObject['pagetitle'];
          					$name = strip_tags($name);
          					$name = strtolower($name);
          					$name = preg_replace('/&.+?;/', '', $name); // kill entities
          					$name = preg_replace('/[^\.%a-z0-9 _-]/', '', $name);
          					$name = preg_replace('/\s+/', '-', $name);
          					$name = preg_replace('|-+|', '-', $name);
          					$name = trim($name, '-');					
          				}
          				$header = 'Content-Disposition: attachment; filename='.$name;
          				header($header);
          			}
          		}
          
          		$out = $this->addNotice($this->documentOutput, $type);
          		if($this->dumpSQL) {
          			$out .= $this->queryCode;
          		}
          		$out = str_replace("[^q^]", $queries, $out);
          		$out = str_replace("[^qt^]", $queryTime, $out);
          		$out = str_replace("[^p^]", $phpTime, $out);
          		$out = str_replace("[^t^]", $totalTime, $out);
          		$out = str_replace("[^s^]", $source, $out);
          		$this->documentOutput = $out;
          
          		// invoke OnWebPagePrerender event
          		if(!$noEvent) {
          			$this->invokeEvent("OnWebPagePrerender");
          		}
          	
          		echo $this->documentOutput;
           		ob_end_flush();
          	}
          


          Replace all these 3 function called regClientCSS, regClientStartupScript, and regClientScript function located on document.parser.class.inc.php file as well with the one provided below. It contains improvement from Kunal to have a valid javascript and stylsheet output.
          	# Registers Client-side CSS scripts - these scripts are loaded at inside the <head> tag
          	function regClientCSS($src){
          		if ($this->loadedjscripts[$src]) return '';
          		$this->loadedjscripts[$src] = true;
          		if (strpos(strtolower($src),"<style")!==false||strpos(strtolower($src),"<link")!==false)
          			$this->sjscripts[count($this->sjscripts)] = $src;
          		else $this->sjscripts[count($this->sjscripts)] = "<style type='text/css'>@import url($src)</style>";
          	}
          
          	# Registers Startup Client-side JavaScript - these scripts are loaded at inside the <head> tag
          	function regClientStartupScript($src, $plaintext=false){
          		if (!empty($src) && !array_key_exists($src, $this->loadedjscripts)) {
          			if ($this->loadedjscripts[$src]) return '';
          			$this->loadedjscripts[$src] = true;
          			if ($plaintext==true) $this->sjscripts[count($this->sjscripts)] = $src;
          			elseif (strpos(strtolower($src),"<script")!==false) $this->sjscripts[count($this->sjscripts)] = $src;
          			else $this->sjscripts[count($this->sjscripts)] = "<script type='text/javascript' src='$src'></script>";
          		}
          	}
          
          	# Registers Client-side JavaScript 	- these scripts are loaded at the end of the page
          	function regClientScript($src, $plaintext=false){
          		if ($this->loadedjscripts[$src]) return '';
          		$this->loadedjscripts[$src] = true;
          		if ($plaintext==true) $this->jscripts[count($this->jscripts)] = $src;
          		elseif (strpos(strtolower($src),"<script")!==false) $this->jscripts[count($this->jscripts)] = $src;
          		else $this->jscripts[count($this->jscripts)] = "<script type='text/javascript' src='$src'></script>";
          	}
          


          That’s all the fix that you need to get the API works correctly. I tried this on brand new installation from MODx0.9.1 without applying any other fixes given on this thread, and so far everything works fine.
          Try it and report back to us. If it works fine, I believe this will be included in the next release 0.9.2

          Regards,
            Wendy Novianto
            [font=Verdana]PT DJAMOER Technology Media
            [font=Verdana]Xituz Media
            • 7923
            • 4,213 Posts
            Quote from: Djamoer at Apr 12, 2006, 04:45 PM

            Ok guys, here is the fix that I did, so far it works on mine.

            * Fixed loading an uncached snippet client script when using the given API
            * Fixed double loading client script on uncached document and using cached snippet tag
            * Fixed MODx tag parsing on uncached snippet
            I tested this and everything seems to be working great with these fixes, Good work Wendy!


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."