| 1 | <?php
 | 
  
    | 2 | 
 | 
  
    | 3 | // $Id: droplets.php 1289 2010-02-10 15:13:21Z kweitzel $
 | 
  
    | 4 | 
 | 
  
    | 5 | /*
 | 
  
    | 6 | *	@version	1.0.2
 | 
  
    | 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 | *   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 | */
 | 
  
    | 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 | 				$params = html_entity_decode($params,ENT_COMPAT,DEFAULT_CHARSET); // make sure we can parse the parameters correctly
 | 
  
    | 25 | 				$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 | 						$parameter[$parameterTemp[0]] = htmlentities($parameterTemp[1],ENT_COMPAT,DEFAULT_CHARSET); //re-encode the parameter values
 | 
  
    | 30 | 					else
 | 
  
    | 31 | 						$parameter['parm'] = htmlentities($parameterTemp[0],ENT_COMPAT,DEFAULT_CHARSET);
 | 
  
    | 32 | 				}
 | 
  
    | 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 | 			$newvalue = evalDroplet($codedata, $parameter, $wb_page_data);
 | 
  
    | 43 | 			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 | 
 | 
  
    | 53 | function evalDroplet($droplet, $params, &$wb_page_data) {
 | 
  
    | 54 |     if(is_array($params)) extract($params, EXTR_SKIP);
 | 
  
    | 55 | 	return eval($droplet);
 | 
  
    | 56 | }
 | 
  
    | 57 | ?>
 |