Project

General

Profile

1 989 aldus
<?php
2 991 Ruebenwurz
3
// $Id$
4
5 989 aldus
/*
6 1289 kweitzel
*	@version	1.0.2
7 989 aldus
*	@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 1289 kweitzel
* 	To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value&parameter2=value]]\
12
*
13
*   1.0.2, bugfix. Reused the evalDroplet function so the extracted parameters will be only available within the scope of the eval and cleared when ready.
14 989 aldus
*/
15
16
function evalDroplets ($wb_page_data) {
17
	global $database;
18
	$parameter = array();
19
	preg_match_all('~\[\[(.*?)\]\]~', $wb_page_data, $matches);
20
	foreach ($matches[1] as $match) {
21
		if (strpos($match,"?")) {
22
			list ($droplet,$params) = explode("?",$match);
23
			if(!empty($params)) {
24 1028 ruud
				$params = html_entity_decode($params,ENT_COMPAT,DEFAULT_CHARSET); // make sure we can parse the parameters correctly
25 989 aldus
				$paramarray = explode("&",$params); //create array of parms as parm=value
26
				foreach ($paramarray as $paramelement) {
27
					$parameterTemp = explode("=", $paramelement,2);
28
					if (count($parameterTemp) == 2)
29 1028 ruud
						$parameter[$parameterTemp[0]] = htmlentities($parameterTemp[1],ENT_COMPAT,DEFAULT_CHARSET); //re-encode the parameter values
30 989 aldus
					else
31 1028 ruud
						$parameter['parm'] = htmlentities($parameterTemp[0],ENT_COMPAT,DEFAULT_CHARSET);
32 989 aldus
				}
33
			}
34
		} else {
35
			$droplet = $match;
36
			$parameter = "";
37
		}
38
		$query_content = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets WHERE name = '$droplet' AND active = 1 ");
39
		if ($query_content && $query_content->numRows() > 0){
40
			$fetch_content = $query_content->fetchRow();
41
			$codedata = ($fetch_content['code']);
42 1289 kweitzel
			$newvalue = evalDroplet($codedata, $parameter, $wb_page_data);
43 989 aldus
			if ($newvalue == "" && !$newvalue === true)
44
				$newvalue = "<font color=\"red\">Error in: $match, no correct returnvalue.</font>";
45
			if ($newvalue === true)
46
				$newvalue = "";
47
			$wb_page_data = str_replace("[[".$match."]]", $newvalue, $wb_page_data);
48
		}
49
	}
50
	return $wb_page_data;
51
}
52 1289 kweitzel
53
function evalDroplet($droplet, $params, &$wb_page_data) {
54
    if(is_array($params)) extract($params, EXTR_SKIP);
55
	return eval($droplet);
56
}
57 989 aldus
?>