| 1 |
989
|
aldus
|
<?php
|
| 2 |
991
|
Ruebenwurz
|
|
| 3 |
|
|
// $Id$
|
| 4 |
|
|
|
| 5 |
989
|
aldus
|
/*
|
| 6 |
|
|
* @version 1.0
|
| 7 |
|
|
* @author Ruud Eisinga (Ruud) John (PCWacht)
|
| 8 |
|
|
* @date June 2009
|
| 9 |
|
|
*
|
| 10 |
|
|
* droplets are small codeblocks that are called from anywhere in the template.
|
| 11 |
|
|
* To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value¶meter2=value]]
|
| 12 |
|
|
*/
|
| 13 |
|
|
|
| 14 |
|
|
function evalDroplets ($wb_page_data) {
|
| 15 |
|
|
global $database;
|
| 16 |
|
|
$parameter = array();
|
| 17 |
|
|
preg_match_all('~\[\[(.*?)\]\]~', $wb_page_data, $matches);
|
| 18 |
|
|
foreach ($matches[1] as $match) {
|
| 19 |
|
|
if (strpos($match,"?")) {
|
| 20 |
|
|
list ($droplet,$params) = explode("?",$match);
|
| 21 |
|
|
if(!empty($params)) {
|
| 22 |
1028
|
ruud
|
$params = html_entity_decode($params,ENT_COMPAT,DEFAULT_CHARSET); // make sure we can parse the parameters correctly
|
| 23 |
989
|
aldus
|
$paramarray = explode("&",$params); //create array of parms as parm=value
|
| 24 |
|
|
foreach ($paramarray as $paramelement) {
|
| 25 |
|
|
$parameterTemp = explode("=", $paramelement,2);
|
| 26 |
|
|
if (count($parameterTemp) == 2)
|
| 27 |
1028
|
ruud
|
$parameter[$parameterTemp[0]] = htmlentities($parameterTemp[1],ENT_COMPAT,DEFAULT_CHARSET); //re-encode the parameter values
|
| 28 |
989
|
aldus
|
else
|
| 29 |
1028
|
ruud
|
$parameter['parm'] = htmlentities($parameterTemp[0],ENT_COMPAT,DEFAULT_CHARSET);
|
| 30 |
989
|
aldus
|
}
|
| 31 |
|
|
}
|
| 32 |
|
|
} else {
|
| 33 |
|
|
$droplet = $match;
|
| 34 |
|
|
$parameter = "";
|
| 35 |
|
|
}
|
| 36 |
|
|
$query_content = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets WHERE name = '$droplet' AND active = 1 ");
|
| 37 |
|
|
if ($query_content && $query_content->numRows() > 0){
|
| 38 |
|
|
$fetch_content = $query_content->fetchRow();
|
| 39 |
|
|
$codedata = ($fetch_content['code']);
|
| 40 |
|
|
if(is_array($parameter)) extract($parameter, EXTR_SKIP);
|
| 41 |
|
|
$newvalue = eval($codedata);
|
| 42 |
|
|
if ($newvalue == "" && !$newvalue === true)
|
| 43 |
|
|
$newvalue = "<font color=\"red\">Error in: $match, no correct returnvalue.</font>";
|
| 44 |
|
|
if ($newvalue === true)
|
| 45 |
|
|
$newvalue = "";
|
| 46 |
|
|
$wb_page_data = str_replace("[[".$match."]]", $newvalue, $wb_page_data);
|
| 47 |
|
|
}
|
| 48 |
|
|
}
|
| 49 |
|
|
return $wb_page_data;
|
| 50 |
|
|
}
|
| 51 |
|
|
?>
|