Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         droplet
6
 * @author          Ruud Eisinga (Ruud) John (PCWacht)
7
 * @author          WebsiteBaker Project
8
 * @copyright       2004-2009, Ryan Djurovich
9
 * @copyright       2009-2010, Website Baker Org. e.V.
10
 * @link			http://www.websitebaker2.org/
11
 * @license         http://www.gnu.org/licenses/gpl.html
12
 * @platform        WebsiteBaker 2.8.x
13
 * @requirements    PHP 4.4.9 and higher
14
 * @version         $Id: droplets.php 1296 2010-02-19 11:02:17Z Luisehahne $
15
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/droplets.php $
16
 * @lastmodified    $Date: 2010-02-19 12:02:17 +0100 (Fri, 19 Feb 2010) $
17
 *
18
 */
19

    
20
/*
21
 *	@version	1.0.2
22
 *	@date		June 2009
23
 *
24
 *	droplets are small codeblocks that are called from anywhere in the template.
25
 * 	To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value&parameter2=value]]\
26
 *
27
 *  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.
28
 */
29

    
30
function evalDroplets ($wb_page_data) {
31
	global $database;
32
	$parameter = array();
33
	preg_match_all('~\[\[(.*?)\]\]~', $wb_page_data, $matches);
34
	foreach ($matches[1] as $match) {
35
		if (strpos($match,"?")) {
36
			list ($droplet,$params) = explode("?",$match);
37
			if(!empty($params)) {
38
				$params = html_entity_decode($params,ENT_COMPAT,DEFAULT_CHARSET); // make sure we can parse the parameters correctly
39
				$paramarray = explode("&",$params); //create array of parms as parm=value
40
				foreach ($paramarray as $paramelement) {
41
					$parameterTemp = explode("=", $paramelement,2);
42
					if (count($parameterTemp) == 2)
43
						$parameter[$parameterTemp[0]] = htmlentities($parameterTemp[1],ENT_COMPAT,DEFAULT_CHARSET); //re-encode the parameter values
44
					else
45
						$parameter['parm'] = htmlentities($parameterTemp[0],ENT_COMPAT,DEFAULT_CHARSET);
46
				}
47
			}
48
		} else {
49
			$droplet = $match;
50
			$parameter = "";
51
		}
52
		$query_content = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets WHERE name = '$droplet' AND active = 1 ");
53
		if ($query_content && $query_content->numRows() > 0){
54
			$fetch_content = $query_content->fetchRow();
55
			$codedata = ($fetch_content['code']);
56
			$newvalue = evalDroplet($codedata, $parameter, $wb_page_data);
57
			if ($newvalue == "" && !$newvalue === true) 
58
				$newvalue = "<font color=\"red\">Error in: $match, no correct returnvalue.</font>";
59
			if ($newvalue === true) 
60
				$newvalue = "";
61
			$wb_page_data = str_replace("[[".$match."]]", $newvalue, $wb_page_data);
62
		}
63
	}
64
	return $wb_page_data;
65
}
66

    
67
function evalDroplet($droplet, $params, &$wb_page_data) {
68
    if(is_array($params)) extract($params, EXTR_SKIP);
69
	return eval($droplet);
70
}
71
?>
(5-5/13)