1
|
<?php
|
2
|
|
3
|
// $Id: droplets.php 1028 2009-07-03 12:00:42Z ruud $
|
4
|
|
5
|
/*
|
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
|
$params = html_entity_decode($params,ENT_COMPAT,DEFAULT_CHARSET); // make sure we can parse the parameters correctly
|
23
|
$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
|
$parameter[$parameterTemp[0]] = htmlentities($parameterTemp[1],ENT_COMPAT,DEFAULT_CHARSET); //re-encode the parameter values
|
28
|
else
|
29
|
$parameter['parm'] = htmlentities($parameterTemp[0],ENT_COMPAT,DEFAULT_CHARSET);
|
30
|
}
|
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
|
?>
|