Revision 1420
Added by Luisehahne almost 15 years ago
| droplets.php | ||
|---|---|---|
| 1 |
<?php |
|
| 2 |
/** |
|
| 3 |
* |
|
| 4 |
* @category module |
|
| 5 |
* @package droplets |
|
| 6 |
* @author Ruud Eisinga (Ruud) John (PCWacht) |
|
| 7 |
* @author WebsiteBaker Project |
|
| 8 |
* @copyright 2004-2009, Ryan Djurovich |
|
| 9 |
* @copyright 2009-2011, 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 5.2.2 and higher |
|
| 14 |
* @version $Id$ |
|
| 15 |
* @filesource $HeadURL$ |
|
| 16 |
* @lastmodified $Date$ |
|
| 17 |
* |
|
| 18 |
* droplets are small codeblocks that are called from anywhere in the template. |
|
| 19 |
* To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value¶meter2=value]]\ |
|
| 20 |
* |
|
| 21 |
* 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. |
|
| 22 |
* 1.0.3, optimize, reduce memory consumption, increase speed, remove CSS, enable nested droplets |
|
| 23 |
* |
|
| 24 |
*/ |
|
| 25 |
|
|
| 26 |
function do_eval($_x_codedata, $_x_varlist, &$wb_page_data) |
|
| 27 |
{
|
|
| 28 |
extract($_x_varlist, EXTR_SKIP); |
|
| 29 |
return(eval($_x_codedata)); |
|
| 30 |
} |
|
| 31 |
|
|
| 32 |
function processDroplets( &$wb_page_data ) {
|
|
| 33 |
// collect all droplets from document |
|
| 34 |
$droplet_tags = array(); |
|
| 35 |
$droplet_replacements = array(); |
|
| 36 |
if( preg_match_all( '/\[\[(.*?)\]\]/', $wb_page_data, $found_droplets ) ) |
|
| 37 |
{
|
|
| 38 |
foreach( $found_droplets[1] as $droplet ) |
|
| 39 |
{
|
|
| 40 |
if(array_key_exists( '[['.$droplet.']]', $droplet_tags) == false) |
|
| 41 |
{
|
|
| 42 |
// go in if same droplet with same arguments is not processed already |
|
| 43 |
$varlist = array(); |
|
| 44 |
// split each droplet command into droplet_name and request_string |
|
| 45 |
$tmp = preg_split('/\?/', $droplet, 2);
|
|
| 46 |
$droplet_name = $tmp[0]; |
|
| 47 |
$request_string = (isset($tmp[1]) ? $tmp[1] : ''); |
|
| 48 |
if( $request_string != '' ) |
|
| 49 |
{
|
|
| 50 |
// make sure we can parse the arguments correctly |
|
| 51 |
$request_string = html_entity_decode($request_string, ENT_COMPAT,DEFAULT_CHARSET); |
|
| 52 |
// create array of arguments from query_string |
|
| 53 |
$argv = preg_split( '/&(?!amp;)/', $request_string ); |
|
| 54 |
foreach ($argv as $argument) |
|
| 55 |
{
|
|
| 56 |
// split argument in pair of varname, value |
|
| 57 |
list( $variable, $value ) = explode('=', $argument,2);
|
|
| 58 |
if( !empty($value) ) |
|
| 59 |
{
|
|
| 60 |
// re-encode the value and push the var into varlist |
|
| 61 |
$varlist[$variable] = htmlentities($value, ENT_COMPAT,DEFAULT_CHARSET); |
|
| 62 |
} |
|
| 63 |
} |
|
| 64 |
} |
|
| 65 |
else |
|
| 66 |
{
|
|
| 67 |
// no arguments given, so |
|
| 68 |
$droplet_name = $droplet; |
|
| 69 |
} |
|
| 70 |
// request the droplet code from database |
|
| 71 |
$sql = 'SELECT `code` FROM `'.TABLE_PREFIX.'mod_droplets` WHERE `name` LIKE "'.$droplet_name.'" AND `active` = 1'; |
|
| 72 |
$codedata = $GLOBALS['database']->get_one($sql); |
|
| 73 |
if (!is_null($codedata)) |
|
| 74 |
{
|
|
| 75 |
$newvalue = do_eval($codedata, $varlist, $wb_page_data); |
|
| 76 |
// check returnvalue (must be a string of 1 char at least or (bool)true |
|
| 77 |
if ($newvalue == '' && $newvalue !== true) |
|
| 78 |
{
|
|
| 79 |
if(DEBUG === true) |
|
| 80 |
{
|
|
| 81 |
$newvalue = '<span class="mod_droplets_err">Error in: '.$droplet.', no valid returnvalue.</span>'; |
|
| 82 |
} |
|
| 83 |
else |
|
| 84 |
{
|
|
| 85 |
$newvalue = true; |
|
| 86 |
} |
|
| 87 |
} |
|
| 88 |
if ($newvalue === true) { $newvalue = ""; }
|
|
| 89 |
// remove any defined CSS section from code. For valid XHTML a CSS-section is allowed inside <head>...</head> only! |
|
| 90 |
$newvalue = preg_replace('/<style.*>.*<\/style>/siU', '', $newvalue);
|
|
| 91 |
// push droplet-tag and it's replacement into Search/Replace array after executing only |
|
| 92 |
$droplet_tags[] = '[['.$droplet.']]'; |
|
| 93 |
$droplet_replacements[] = $newvalue; |
|
| 94 |
} |
|
| 95 |
} |
|
| 96 |
} // End foreach( $found_droplets[1] as $droplet ) |
|
| 97 |
// replace each Droplet-Tag with coresponding $newvalue |
|
| 98 |
$wb_page_data = str_replace($droplet_tags, $droplet_replacements, $wb_page_data); |
|
| 99 |
} |
|
| 100 |
// returns TRUE if droplets found in content, FALSE if not |
|
| 101 |
return( count($droplet_tags)!=0 ); |
|
| 102 |
} |
|
| 103 |
|
|
| 104 |
function evalDroplets( &$wb_page_data, $max_loops = 3 ) {
|
|
| 105 |
$max_loops = ((int)$max_loops = 0 ? 3 : (int)$max_loops); |
|
| 106 |
while( (processDroplets($wb_page_data) == true) && ($max_loops > 0)) |
|
| 107 |
{
|
|
| 108 |
$max_loops--; |
|
| 109 |
} |
|
| 110 |
return $wb_page_data; |
|
| 111 |
} |
|
| 112 |
|
|
| 1 |
<?php |
|
| 2 |
/** |
|
| 3 |
* |
|
| 4 |
* @category module |
|
| 5 |
* @package droplets |
|
| 6 |
* @author Ruud Eisinga (Ruud) John (PCWacht) |
|
| 7 |
* @author WebsiteBaker Project |
|
| 8 |
* @copyright 2004-2009, Ryan Djurovich |
|
| 9 |
* @copyright 2009-2011, 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 5.2.2 and higher |
|
| 14 |
* @version $Id$ |
|
| 15 |
* @filesource $HeadURL$ |
|
| 16 |
* @lastmodified $Date$ |
|
| 17 |
* |
|
| 18 |
* droplets are small codeblocks that are called from anywhere in the template. |
|
| 19 |
* To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value¶meter2=value]]\ |
|
| 20 |
* |
|
| 21 |
* 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. |
|
| 22 |
* 1.0.3, optimize, reduce memory consumption, increase speed, remove CSS, enable nested droplets |
|
| 23 |
* |
|
| 24 |
*/ |
|
| 25 |
|
|
| 26 |
// Must include code to stop this file being access directly |
|
| 27 |
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
|
|
| 28 |
|
|
| 29 |
function do_eval($_x_codedata, $_x_varlist, &$wb_page_data) |
|
| 30 |
{
|
|
| 31 |
extract($_x_varlist, EXTR_SKIP); |
|
| 32 |
return(eval($_x_codedata)); |
|
| 33 |
} |
|
| 34 |
|
|
| 35 |
function processDroplets( &$wb_page_data ) {
|
|
| 36 |
// collect all droplets from document |
|
| 37 |
$droplet_tags = array(); |
|
| 38 |
$droplet_replacements = array(); |
|
| 39 |
if( preg_match_all( '/\[\[(.*?)\]\]/', $wb_page_data, $found_droplets ) ) |
|
| 40 |
{
|
|
| 41 |
foreach( $found_droplets[1] as $droplet ) |
|
| 42 |
{
|
|
| 43 |
if(array_key_exists( '[['.$droplet.']]', $droplet_tags) == false) |
|
| 44 |
{
|
|
| 45 |
// go in if same droplet with same arguments is not processed already |
|
| 46 |
$varlist = array(); |
|
| 47 |
// split each droplet command into droplet_name and request_string |
|
| 48 |
$tmp = preg_split('/\?/', $droplet, 2);
|
|
| 49 |
$droplet_name = $tmp[0]; |
|
| 50 |
$request_string = (isset($tmp[1]) ? $tmp[1] : ''); |
|
| 51 |
if( $request_string != '' ) |
|
| 52 |
{
|
|
| 53 |
// make sure we can parse the arguments correctly |
|
| 54 |
$request_string = html_entity_decode($request_string, ENT_COMPAT,DEFAULT_CHARSET); |
|
| 55 |
// create array of arguments from query_string |
|
| 56 |
$argv = preg_split( '/&(?!amp;)/', $request_string ); |
|
| 57 |
foreach ($argv as $argument) |
|
| 58 |
{
|
|
| 59 |
// split argument in pair of varname, value |
|
| 60 |
list( $variable, $value ) = explode('=', $argument,2);
|
|
| 61 |
if( !empty($value) ) |
|
| 62 |
{
|
|
| 63 |
// re-encode the value and push the var into varlist |
|
| 64 |
$varlist[$variable] = htmlentities($value, ENT_COMPAT,DEFAULT_CHARSET); |
|
| 65 |
} |
|
| 66 |
} |
|
| 67 |
} |
|
| 68 |
else |
|
| 69 |
{
|
|
| 70 |
// no arguments given, so |
|
| 71 |
$droplet_name = $droplet; |
|
| 72 |
} |
|
| 73 |
// request the droplet code from database |
|
| 74 |
$sql = 'SELECT `code` FROM `'.TABLE_PREFIX.'mod_droplets` WHERE `name` LIKE "'.$droplet_name.'" AND `active` = 1'; |
|
| 75 |
$codedata = $GLOBALS['database']->get_one($sql); |
|
| 76 |
if (!is_null($codedata)) |
|
| 77 |
{
|
|
| 78 |
$newvalue = do_eval($codedata, $varlist, $wb_page_data); |
|
| 79 |
// check returnvalue (must be a string of 1 char at least or (bool)true |
|
| 80 |
if ($newvalue == '' && $newvalue !== true) |
|
| 81 |
{
|
|
| 82 |
if(DEBUG === true) |
|
| 83 |
{
|
|
| 84 |
$newvalue = '<span class="mod_droplets_err">Error in: '.$droplet.', no valid returnvalue.</span>'; |
|
| 85 |
} |
|
| 86 |
else |
|
| 87 |
{
|
|
| 88 |
$newvalue = true; |
|
| 89 |
} |
|
| 90 |
} |
|
| 91 |
if ($newvalue === true) { $newvalue = ""; }
|
|
| 92 |
// remove any defined CSS section from code. For valid XHTML a CSS-section is allowed inside <head>...</head> only! |
|
| 93 |
$newvalue = preg_replace('/<style.*>.*<\/style>/siU', '', $newvalue);
|
|
| 94 |
// push droplet-tag and it's replacement into Search/Replace array after executing only |
|
| 95 |
$droplet_tags[] = '[['.$droplet.']]'; |
|
| 96 |
$droplet_replacements[] = $newvalue; |
|
| 97 |
} |
|
| 98 |
} |
|
| 99 |
} // End foreach( $found_droplets[1] as $droplet ) |
|
| 100 |
// replace each Droplet-Tag with coresponding $newvalue |
|
| 101 |
$wb_page_data = str_replace($droplet_tags, $droplet_replacements, $wb_page_data); |
|
| 102 |
} |
|
| 103 |
// returns TRUE if droplets found in content, FALSE if not |
|
| 104 |
return( count($droplet_tags)!=0 ); |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
function evalDroplets( &$wb_page_data, $max_loops = 3 ) {
|
|
| 108 |
$max_loops = ((int)$max_loops = 0 ? 3 : (int)$max_loops); |
|
| 109 |
while( (processDroplets($wb_page_data) == true) && ($max_loops > 0)) |
|
| 110 |
{
|
|
| 111 |
$max_loops--; |
|
| 112 |
} |
|
| 113 |
return $wb_page_data; |
|
| 114 |
} |
|
| 115 |
|
|
| 113 | 116 |
?> |
Also available in: Unified diff
YGN Ethical Hacker Group (2.8.2 / 2.9.0)