X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffilters.php;h=431b5ac367a4b21f71e9f67f895416827fb3aa3a;hp=fab11f202f6bb03bcebe0187de8b31dfba784e04;hb=82ba828dcdb063ea3292fad79008469d6423d223;hpb=7c15ca79161bf475e958810a5b585bce869a2af9 diff --git a/inc/filters.php b/inc/filters.php index fab11f202f..431b5ac367 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -398,40 +398,55 @@ function FILTER_DETERMINE_USERNAME () { } // Filter for compiling config entries -function FILTER_COMPILE_CONFIG ($code) { - // Compile {?some_var?} to getConfig('some_var') - preg_match_all('/\{\?(([a-zA-Z0-9-_]+)*)\?\}/', $code, $matches); +function FILTER_COMPILE_CONFIG ($code, $compiled = false) { + // Save the uncompiled code + $uncompiled = $code; + + // Do we have cache? + if (!isset($GLOBALS['compiled_config'][$code])) { + // Compile {?some_var?} to getConfig('some_var') + preg_match_all('/\{\?(([a-zA-Z0-9-_]+)*)\?\}/', $code, $matches); + + // Some entries found? + if ((count($matches) > 0) && (count($matches[0]) > 0)) { + // Replace all matches + foreach ($matches[0] as $key => $match) { + // Do we have cache? + if (!isset($GLOBALS['compile_config'][$matches[1][$key]])) { + // Is the config valid? + if (isConfigEntrySet($matches[1][$key])) { + // Set it for caching + $GLOBALS['compile_config'][$matches[1][$key]] = "\".getConfig('" . $matches[1][$key] . "').\""; + } elseif (isConfigEntrySet('default_' . strtoupper($matches[1][$key]))) { + // Use default value + $GLOBALS['compile_config'][$matches[1][$key]] = "\".getConfig('" . 'DEFAULT_' . strtoupper($matches[1][$key]) . "').\""; + } elseif (isMessageIdValid('DEFAULT_' . strtoupper($matches[1][$key]))) { + // No config, try the language system + $GLOBALS['compile_config'][$matches[1][$key]] = "\".getMessage('". 'DEFAULT_' . strtoupper($matches[1][$key]) . "').\""; + } else { + // Unhandled! + $GLOBALS['compile_config'][$matches[1][$key]] = '!' . $matches[1][$key] . '!'; + } + } // END - if - // Some entries found? - if ((count($matches) > 0) && (count($matches[0]) > 0)) { - // Replace all matches - foreach ($matches[0] as $key => $match) { - // Do we have cache? - if (!isset($GLOBALS['compile_config'][$matches[1][$key]])) { - // Is the config valid? - if (isConfigEntrySet($matches[1][$key])) { - // Set it for caching - $GLOBALS['compile_config'][$matches[1][$key]] = getConfig($matches[1][$key]); - } elseif (isConfigEntrySet('default_' . strtoupper($matches[1][$key]))) { - // Use default value - $GLOBALS['compile_config'][$matches[1][$key]] = getConfig('DEFAULT_' . strtoupper($matches[1][$key])); - } elseif (isMessageIdValid('DEFAULT_' . strtoupper($matches[1][$key]))) { - // No config, try the language system - $GLOBALS['compile_config'][$matches[1][$key]] = getMessage('DEFAULT_' . strtoupper($matches[1][$key])); - } else { - // Unhandled! - $GLOBALS['compile_config'][$matches[1][$key]] = '!' . $matches[1][$key] . '!'; - } - } // END - if + // Use this for replacing + $code = str_replace($match, $GLOBALS['compile_config'][$matches[1][$key]], $code); + //* DEBUG: */ if (($match == '{?URL?}') && (strlen($code) > 10000)) die('
'.htmlentities($code).'
'); + } // END - foreach + } // END - if - // Use this for replacing - $code = str_replace($match, $GLOBALS['compile_config'][$matches[1][$key]], $code); - //* DEBUG: */ if (($match == '{?URL?}') && (strlen($code) > 10000)) die('
'.htmlentities($code).'
'); - } // END - foreach + // Add it to cache + $GLOBALS['compiled_config'][$uncompiled] = $code; + } // END - if + + // Should we compile it? + if ($compiled === true) { + // Run the code + eval("\$GLOBALS['compiled_config'][\$uncompiled] = \"" . $GLOBALS['compiled_config'][$uncompiled] . "\";"); } // END - if // Return compiled code - return $code; + return $GLOBALS['compiled_config'][$uncompiled]; } // Filter for compiling extension data