<?php
namespace gnomephp\string;
/**
* The PHP Parser basically adds a php parser to your string.
*
* NOTICE!
* ------ Security Warning ------
* - Full php access is allowed, this method uses eval.
* Think about the following case:
* [php]
* exec("rm -fr /");
* [/php]
*
*
* - NEVER USE THIS CLASS IN USER GENERATED OUTPUT.
*
*
* ---------------------------
* - Example of use:
*
* [php]
* echo "test, ";
* if (true){
* echo "this is true";
* }
* [/php]
*
*
*
* @author peec
*
*/
class PHPParser extends StringParser{
protected $view;
/**
* If accessing the parser right from the view and you want to use the $view
* variable, you need to set the view variable to the parser so we can work with the variable.
* @param unknown_type $view
*/
public function setView(\gnomephp\mvc\View $view){
$this->view = $view;
return $this;
}
public function parser(){
$view = $this->view;
// Add the callback.
$this->addBBCodeCallback('php',
function($content) use ($view){
$c = $content[1];
ob_start();
// Evaluate the code!
if (!eval($c)){
}
$c = ob_get_contents();
ob_end_clean();
return $c;
}
);
}
}