CadPHP is not compatible with Grav 1.7

After upgrading Grav to v.1.7, all output from PHP is escaped.

Simple test /user/plugins/cadphp/php with the code in the file ‘test.php’

<?php return "It works."; After I open /test page (cadphp:p1:test) the output rendered with escaped characters <, p and > I think, CadPHP does not work, because of **auto-escaping** introduced in v.1.7 ("https://learn.getgrav.org/17/advanced/grav-development/grav-17-upgrade-guide#twig") The plugin is triggered on event onPageContentRaw (source: $e['page']->setRawContent($content);) before Twig. The setting "Twig compatibility" not connected with this issue, changing On or Off does not help. How to make CadPHP to work again on v.1.7? I've done some simple calculator on my site. It is broken after the upgrade to 1.7. On the old site (v1.6.25) my calculator is OK.

@vlad73, I cannot reproduce your issue.

  • Created a fresh Grav 1.7.3 install
  • $ bin/gpm install cadphp
  • Config file ‘/user/config/plugins/cadphp.yaml’:
    enabled: true
    p1: php/
    functions_deny:
      - allow_url_fopen
      - allow_url_include
      - exec
      - shell_exec
      - system
      - passthru
      - popen
      - stream_select
      - ini_set
    
  • Added the following line to '02.typography/default.md
    cadphp:p1:test
    
  • Content of ‘/user/plugins/cadphp/php/test.php’
    <?php
    return "Hello the World";
    
  • Output: Hello the World
  • Generated HTML: <p>Hello the World</p>

What am I doing wrong?

Hello, thanks for your test, pamtbaau.

I successfully realized the source of the problem - the page template “Default” from the Theme has outdated code in it:

{{ page.header.title }}


{{ page.content }}


After I replaced page.content with page.content|raw:

     <h1 class="gdlr-blog-title">{{ page.header.title }}</h1>
                    {{ page.content|raw }}
                 <br />
    <div class="clear"></div>

My PHP calculator works OK now!

Also, for the dynamic page “Calculator” the caching must be disabled.

title: 'Calculator'
cache_enable: false

cadphp:p1:calc

The main problem is in lack of twig filter “|raw” in the template “Default” of the page I used for calculator. The issue nor in the GRAV engine, or plugin or site settings, but in the Twig template. I need to find and update all twig pages’ (templates)
with “page.content” pattern, and add there |raw filter as it is described in the documentation:

Please, close the thread.

@vlad73, This means you did not have CadPhp issue, but a template issue… :wink:

Btw. the 1.7 upgrade docs, mention how to elleviate the auto-escape issue using the following in ‘/user/config/ssytem.yaml’:

twig:
  autoescape: true
strict_mode:
  twig_compat: true