Skip to content

cadjou/grav-plugin-cadphp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grav-plugin-cadphp

Include PHP simply inside Grav CMS

In English

Installation

By Grav Package Manager (GPM)

Easy way to install with GPM.

$ bin/gpm install cadphp

Manualy

Upload the plugin : https://github.com/cadjou/grav-plugin-cadphp/archive/master.zip

Copy the Pack in the folder Site-Grav/user/plugins/

And rename the plugin folder grav-plugin-cadphp-master to cadphp

After installation

Save the parameters in the plugin interface if you have admin interface or copy the file cadphp.yaml in /user/config/plugins/cadphp.yml with this minimum :

enabled: true
p1: php/

Use

To run a PHP file, you have to place the Keyword cadphp: at the beginning of the line in the content of a Grav page.

Next, indicate the path parameterized pX where X is between 1 and 99
More information in the Setup part

To finish, you have to set the relative path to the predefined path pX without the extension .php

By default, p1 is set to point to the folder /user/plugins/cadphp/php/

cadphp:p1:test // Run /user/plugins/cadphp/php/test.php
cadphp:p2:path_dir_php_files
cadphp:p3:path_dir_php_files
cadphp:p4:path_dir_php_files
cadphp:p5:path_dir_php_files

PHP Limitation

The file must start with <?php and it must be unique.
The ?> closure is not mandatory but it must be unique and at the end of the file.

The file must return a string as in this example: /cadphp/php/test.php

<?php
return "Hello the World";

Setup

In the administration interface, several options are possible.

Configuration of PHP file localizations

From the web interface, it is possible to define 5 configurable paths.
The first by default is the folder /user/plugins/cadphp/php/ and the second is the folder /user/plugins/page/

If the path begins with a / then it represents Document Root otherwise it is the path of the plugin cadPHP /user/plugins/cadphp/

A total of 99 configurable paths can be created.

Advanced Settings

To secure the executed code, some PHP functions are prohibited by default.
The prohibited are functions :

  • allow_url_fopen
  • allow_url_include
  • exec
  • shell_exec
  • system
  • passthru
  • popen
  • stream_select
  • ini_set

At your own risk to change this parts ;) .

Errors

In case of error in the PHP code, it will not be executed and the error is logged in /logs/grav.log

In Development

  • Add a predefined path via the web interface
  • Put more information in the error message

En francais

Installation

Via Grav Package Manager (GPM)

Commande pour installer CadPHP avec GPM.

$ bin/gpm install cadphp

Manuellement

Télécharger le plugin : https://github.com/cadjou/grav-plugin-cadphp/archive/master.zip

Copier le Pack dans le dossier Site-Grav/user/plugins/

Et renommer le plugin grav-plugin-cadphp-master en cadphp

Après l'installation

Enregistrez les paramètres dans l’interface du plugin si vous avez une interface admin ou copiez le fichier cadphp.yaml dans /user/config/plugins/cadphp.yml avec au minimum :

enabled: true
p1: php/

Utilisation

Pour exécuter un fichier PHP, il faut placer le mot-clé cadphp: en début de ligne dans le contenu d'une page Grav.

Ensuite, il faut indiquer le chemin pré-paramétré pXX est compris entre 1 et 99. Plus d'informations dans la partie paramétrage.

Pour terminer, il faut mettre le chemin relatif par rapport au chemin prédéfini pX sans l'extension .php

Par défaut, p1 est défini pour pointer vers le dossier /user/plugins/cadphp/php/

cadphp:p1:test // Execute /user/plugins/cadphp/php/test.php
cadphp:p2:chemin_du_fichier
cadphp:p3:chemin_du_fichier
cadphp:p4:chemin_du_fichier
cadphp:p5:chemin_du_fichier

Limitation du PHP

Le fichier doit commencer par <?php et il doit être unique.
La fermeture ?> n'est pas obligatoire mais il doit être unique et en fin du fichier.

Le fichier doit retourne une chaine de caractères comme dans cette exemple :
/cadphp/php/test.php

<?php
return "Hello the World";

Paramétrage

Dans l'interface d'administration, plusieurs options sont possibles.

Configuration des localisations des fichiers PHP

Depuis l'interface web, il est possible de définir 5 chemins paramétrables. Le 1er par défaut est le dossier /user/plugins/cadphp/php/ et le 2ème est le dossier est /user/plugins/page/

Si le chemin commence par un / alors cela repésente Document Root sinon c'est le chemin du plugin cadPHP /user/plugins/cadphp/

Il est possible de créer 99 chemins paramétrables en tout.

Configuration avancée

Pour sécuriser le code executé, certaines fonctions PHP sont interdites.
Par défaut, les fonctions interdites :

  • allow_url_fopen
  • allow_url_include
  • exec
  • shell_exec
  • system
  • passthru
  • popen
  • stream_select
  • ini_set

A vos risques et périls si vous en envelez certaines ;) .

Erreurs

En cas d'erreur dans le code PHP, il ne sera pas executé et l'erreur est loggé dans /logs/grav.log

En cours de développement

  • Ajouter un chemin prédéfinit via l'interface web
  • Mettre plus d'informations dans le Erreur