We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19090
    • 35 Posts
    Hi everybody
    I’m not a contributor to Modx project but recently I had to modifiy document.parser.class.inc.php to generate valid BOM carrying XML UTF-8 files for a project.
    Perhaps it’s worth to add this lines of code to the core parse function so everybody can enjoy this added feature...
    Basically you have to insert the following lines in the above mentioned file at aprox line 473:

    if ($type == "text/xml" && $this->config['modx_charset'] == "UTF-8"){ 
    	echo pack ( "C3" , 0xef, 0xbb, 0xbf ); 
    }
    


    Regards and hope it’s useful to someone

      • 22303 MODX Staff
      • 10,725 Posts
      This can be accomplished without modifying the core code by creating a plugin for the OnWebPagePrerender event with code like:
      <?php
      if (array_key_exists($modx->documentIdentifier, $modx->contentTypes)) {
          $type = $modx->contentTypes[$modx->documentIdentifier];
          if ($modx->config['modx_charset'] == 'UTF-8' && $type == 'text/xml') {
              $modx->documentOutput = pack("C3", 0xef, 0xbb, 0xbf) . $modx->documentOutput;
          }
      }
      ?>
        • 19090
        • 35 Posts
        Hey thanks for the alternative method!
          • 13428 ☆ A M B ☆
          • 1,031 Posts
          FYI: $modx->contentTypes [$modx->documentIdentifier] seems not to work in 1.0.2 anymore (maybe later but not in OnParseDocument).

          Had to use $modx->documentObject [contentType] there.
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: Jako at Feb 19, 2010, 06:00 AM

            FYI: $modx->contentTypes [$modx->documentIdentifier] seems not to work in 1.0.2 anymore (maybe later but not in OnParseDocument).

            Had to use $modx->documentObject [contentType] there.
            This is intended for OnWebPagePrerender, as I described in a previous post here.
              • 13428 ☆ A M B ☆
              • 1,031 Posts
              Quote from: OpenGeek at Feb 19, 2010, 08:56 AM

              This is intended for OnWebPagePrerender, as I described in a previous post here.
              Ok, but $modx->contentTypes [$modx->documentIdentifier] worked in 0.9.6.3 in OnParseDocument too. In 1.0.2 it doesn’t.

              Sorry but I don’t know whether I had the code example out of this thread or found it elsewhere, but it was the first ’google hit’ with modx->contentTypes [$modx->documentIdentifier]. Posted it on this thread if someone else searches for problems with this. Should i had started a new thread?