FixedPre mystery

This has been baffling me.

The FixedPre plugin just entifies MODX and HTML tags inside <fixedpre></fixedpre> tags.

In MODX 3, a resource with just this line:

<fixedpre><fixedpre></fixedpre>

displays

<fixedpre>

as it should. In MODX 2, it displays nothing, but both these lines work as they should:

<p><fixedpre><fixedpre></fixedpre></p>
<pre>
   <fixedpre><fixedpre></fixedpre>
</pre>

This also works fine:

<p></p>
<fixedpre><fixedpre></fixedpre>

As does this:

<h3></h3>
<fixedpre><fixedpre></fixedpre>

The FixedPre plugin is attached only to OnParseDocument. It’s really simple. Here’s the entire plugin:

if (! function_exists('quote_meta') ) {
    function quote_meta($a) {
        $lhs = array("<", ">", "[", "]", "!", "{", "}", "`", "*", "~");
        $rhs = array("&lt;", "&gt;", "&#091;", "&#093;", "&#033;", "&#123;", "&#125;", "&#96;", "&#42;", "&#126;");
        $b = str_replace("&", "\255", $a[2]);  //save "&"
        $lhs_preg = array('|<!(!*)fixedpre>|',  '|<!(!*)/fixedpre>|');
        $rhs_preg = array('<$1fixedpre>',  '<$1/fixedpre>');
        $b = preg_replace($lhs_preg, $rhs_preg, $b);
        $b = str_replace($lhs, $rhs, $b);

        /* restore '&' as '&amp;' and wrap in span tag */
        //return '<span class="fxp">' . str_replace("\255", "&amp;", $b) . '</span>';
        return str_replace("\255", "&amp;", $b);
    }
}
/** @var $modx modX */
$output =& $modx->documentOutput;
$output = preg_replace_callback("#(<fixedpre>)(.*?)(</fixedpre>)#s",
    "quote_meta", $output);

return '';

So in MODX 2 (but not MODX 3), the plugin has to encounter an HTML tag before processing the FixedPre section correctly. HTML in the template that displays the pagetitle doesn’t make it work. The HTML has to be in the page content. Both sites are using the default template from the installation. It also fails with a minimal template in MODX 2.

It’s not a serious problem, because it’s pretty much guaranteed that there will be some HTML tag ahead of the FixedPre section, but it’s bothering me that I can’t figure it out.

I can’t reproduce this.

I did a test in MODX in 2.8.5-pl with an (empty) template and the content <fixedpre><fixedpre></fixedpre> and got the output = &lt;fixedpre&gt;.


Are you maybe using an old/different version of PHP for your MODX 2 installation?

Interesting. Did you try with a minimal template (w/ html, head, and body tags)?

The PHP version is the same for both my test cases. Maybe there is something about the site that’s doing it, but with a minimal template and all other plugins disables, it still fails.