Project

General

Profile

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