Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-03-07 23:13:57

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

[SOLVED] Plugin stops working when production status switched to live

I’ve just updated a site to the most recent txp and have made all emails bot safe using my jcr_email_enkode plugin.

Everything works fine in testing: the plugin inserts a bit of ‘impenetrable’ javascript that is executed in the browser to become a regular mailto link. When I switch to “Live”, however, the javascript that is output is somehow borked causing the “you need javascript” message to appear – or to be more precise, because the javascript isn’t inserted properly, it no longer removes the message.

The javascript block inserts looks like this with the $name specific to the respective instance on the page. In debugging and testing production statuses, it is inserted and executed just fine, only in live does it stop working.

The plugin uses a standalone PHP library that is included in the data.txp part of the plugin. I added dmp(…) statements to the data.txp file in the /textpattern/plugins/… folder and in live mode I can successfully dump the output string that the code is supposed to insert. It’s just not inserted how it should be. I wondered if it might be because it contains an eval(…) statement (the javascript version) but why would it then work in testing/debugging mode?


TXP Builders – finely-crafted code, design and txp

Offline

#2 2021-03-08 20:28:33

etc
Developer
Registered: 2010-11-11
Posts: 5,235
Website GitHub

Re: [SOLVED] Plugin stops working when production status switched to live

The plugin seems to work fine for me, whatever prod status. Are you sure it’s not a theme/cache issue?

Offline

#3 2021-03-08 20:42:43

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

Re: [SOLVED] Plugin stops working when production status switched to live

etc wrote #329154:

The plugin seems to work fine for me, whatever prod status. Are you sure it’s not a theme/cache issue?

Thank you for looking. I’ve just tested it myself on a completely clean installation too, also with several instances of the tag and it does work correctly. So I compared my two installations … and discovered the answer:

The site where it doesn’t work is because pat_speeder is activated when switching to production status = live and that strips out code in comments … causing the inserted javascript to be removed. If I disable the regex for comments stripping in pat_speeder, it works again.

But maybe instead I can stop jcr_email_enkode inserting the comment instead? It currently inserts the js like this:

<script id="script_enkoder_0_348870068" type="text/javascript">
    /* <!-- */
    function hivelogic_enkoder_0_348870068() {
    … 
    }
    hivelogic_enkoder_0_348870068();
    /* --> */
</script>

Wasn’t the reason for this to do with old browsers displaying the javascript? Is it still needed for modern browers? And might there be a better non-comment way of achieving the same, e.g. CDATA or something?


TXP Builders – finely-crafted code, design and txp

Offline

#4 2021-03-08 20:51:25

etc
Developer
Registered: 2010-11-11
Posts: 5,235
Website GitHub

Re: [SOLVED] Plugin stops working when production status switched to live

jakob wrote #329155:

Is it still needed for modern browers? And might there be a better non-comment way of achieving the same, e.g. CDATA or something?

AFAIK, that’s useless nowadays. You could replace it with

//<![CDATA[
...
//]]>

though, if XHTML output is likely (source).

Offline

#5 2021-03-08 21:02:13

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

Re: [SOLVED] Plugin stops working when production status switched to live

Thanks. As you mention, it seems CDATA was only needed for XHTML doctypes.

So it seems to be legacy code in the standalone enkoder library I used. I tested it without comments and it was fine, so I’ll update the plugin to remove that clash with pat_speeder and perhaps put in an issue on the legacy library repo.

Thanks for thinking this through with me!


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB