Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

CadPHP is not compatible with Grav 1.7

Solved by Vladimir Novak View solution

Started by Vladimir Novak 5 years ago · 3 replies · 545 views
5 years ago

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.

last edited 01/22/21 by Vladimir Novak
5 years ago

@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':
    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
    TXT
    cadphp:p1:test
    
  • Content of '/user/plugins/cadphp/php/test.php'
    PHP
    <?php
    return "Hello the World";
    
  • Output: Hello the World
  • Generated HTML: <p>Hello the World</p>

What am I doing wrong?

5 years ago Solution

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:
<h1 class="gdlr-blog-title">{{ page.header.title }}</h1>
{{ page.content }}
<br />
<div class="clear"></div>

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

HTML
     <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.

YAML
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:

https://learn.getgrav.org/17/advanced/grav-development/grav-16-upgrade-guide#twig

Please, close the thread.

last edited 01/25/21 by Vladimir Novak
5 years ago

@vlad73, This means you did not have CadPhp issue, but a template issue... ;-)

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

YAML
twig:
  autoescape: true
strict_mode:
  twig_compat: true

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 75 1 week ago
Plugins · by Xavier, 4 weeks ago
2 81 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1208 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 74 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 99 2 months ago