We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27889
    • 415 Posts
    This problem is related to the chunkie class, but I don’t find a dedicated forum, so I post here.

    I’m trying to pass a (big) template ina string to create a new chunkie class:
    $tpl = new CChunkie($_lang[’links_template’]);
    the problem is in file chunkie.class.inc.php, in function getTemplate() arround line 44: My template contains tons of bizarre chars for the is_file test and php raise a warning (normal)
    so I have change :
    } else if(is_file($tpl)) { with } else if(@is_file($tpl)) {
    EDIT doesn’t work now ?!??§!!,§!
    } else if(is_file($tpl)) { with } else if( file_exists($tpl)) {
      MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
      MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
      • 7923
      • 4,213 Posts
      I would suggest to replace the function with this:

      <?php
      	function getTemplate($tpl){
      		// by Mark Kaplan
      		global $modx;
      		$template = "";
      		if ($modx->getChunk($tpl) != "") {
      			$template = $modx->getChunk($tpl);
      		} else if(substr($tpl, 0, 6) == "@FILE:") {
      			$template = $this->get_file_contents($modx->config['base_path'].substr($tpl, 6));
      		} else if(substr($tpl, 0, 6) == "@CODE:") {
      			$template = substr($tpl, 6);
      		} else {
      			$template = FALSE;
      		}
      		return $template;
      	}
      
      	function get_file_contents($filename) {
      		// Function written at http://www.nutt.net/2006/07/08/file_get_contents-function-for-php-4/#more-210
      		// Returns the contents of file name passed
      		if (!function_exists('file_get_contents')) {
      			$fhandle = fopen($filename, "r");
      			$fcontents = fread($fhandle, filesize($filename));
      			fclose($fhandle);
      		} else	{
      			$fcontents = file_get_contents($filename);
      		}
      		return $fcontents;
      	}
      ?>
      


      Then use @FILE:path/to/file.html if you are defining a template from file


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 27889
        • 415 Posts
        That’all the difference between a good programmer and me smiley , thank you.
          MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
          MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
          • 18174
          • 116 Posts
          There’s a problem in conjunction with JOT Comments on the same page.
          If I call JOT ahead of FDM, the cchunkie class already exists, because JOT already included a version. Your modifications mentioned above have no effect. The "@CODE:" Template Error appears...
          If I call JOT after the FDM call JOT doesn’t operate because it cannot handle your modified cchunkie class, I suppose.
          I don’t know whats the cchunkie class is exactly for. But if both snippets use the same class, shoutdn’t it be at a common place and when not, use different class names?
          BTW the same effect could happen with phx.parser.class.php. Both JOT and FDM have their own version...

          Regards
          manu