DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:safely_include_php_code

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
tips:safely_include_php_code [2016-09-24 10:05] – Match <php> case-insentible to cover <PHP> as well 92.75.129.61tips:safely_include_php_code [2019-10-06 09:21] (current) – New php function clso
Line 143: Line 143:
  --- //[[codronm@gmail.com|Mat]] 2007-27-05 00:30//  --- //[[codronm@gmail.com|Mat]] 2007-27-05 00:30//
  
 +
 +----
 +
 +==== The New function php ====
 +I fixed some wrong and stale code,\\
 +It's works great on DokuWiki "Greebo"(2018).
 +
 +[[https://clso.fun/]]\\
 + --- [[user>clso|clso]] //2019-10-06 09:11//
 +
 +<code php>
 +function php($text) {
 +    global $conf;
 +    global $INFO;
 +
 +    $editor = $INFO['editor'];
 +
 +    /* @var Doku_Plugin_Controller $plugin_controller */
 +    global $plugin_controller;
 +    /* @var DokuWiki_Auth_Plugin $users */
 +    $users = null;
 +    foreach ($plugin_controller->getList('auth') as $plugin) {
 +        if ($conf['authtype'] === $plugin) {
 +            $users = $plugin_controller->load('auth', $plugin);
 +            break;
 +        }
 +    }
 +    $is_admin = false;
 +    if(!empty($users)){
 +        $user = $users->getUserData($editor);
 +        $is_admin = auth_isMember($conf['superuser'], $editor, $user['grps']);
 +    }
 +
 +    // disable revisions is not good idea
 +    // if ($conf['phpok'] and $is_admin and !$INFO['rev'])
 +    if ($conf['phpok'] and $is_admin) {
 +        ob_start();
 +        eval($text);
 +        $this->doc .= ob_get_contents();
 +        ob_end_clean();
 +    }else{
 +        $this->file("This dynamic content cannot be displayed");
 +    }
 +}
 +</code>
tips/safely_include_php_code.txt · Last modified: 2019-10-06 09:21 by clso

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki