[TYPO3-core] RFC: #4155 / userFunc in conditions / t3lib_div::callUserFunction
Wolfgang Klinger
wolfgang at stufenlos.net
Mon Sep 11 15:14:49 CEST 2006
*hiya!*
On Wed, 06 Sep 2006, Wolfgang Klinger wrote the following:
> http://bugs.typo3.org/view.php?id=4155
>
> The attached patch uses t3lib_div::callUserFunction instead of
> reinventing the wheel here.
clean patch attached
(one +1 missing)
Documentation:
( http://typo3.org/documentation/document-library/references/doc_core_tsref/current/view/4/1/ )
---
userFunc:
Syntax:
[userFunc = user_match(checkLocalIP)]
Comparison:
This call the function user_match with the first parameter checkLocalIP. You write that function. You decide what it checks. Function result is evaluated as true/false.
Example:
Put this function in your localconf.php file:
function user_match($cmd){
switch($cmd){
case "checkLocalIP":
if (strstr(getenv("REMOTE_ADDR"),"192.168")){
return true;
}
break;
case "checkSomethingElse":
// ....
break;
}
}
This condition will return true if the remote address contains 192.168 - which is what your function finds out.
[userFunc = user_match(checkLocalIP)]
---
Michael, you may add the following:
---
you may call the user function by a complete reference too,
for example:
[userFunc = EXT:user_mylib/mylib.php:user_mylib->test(param)]
while this won't work (because of technical limitations):
includeLibs.mylib = EXT:user_mylib/mylib.php
[userFunc = user_mylib->test(param)]
# do something
[global]
And you may pass more than one parameter.
If you pass more than one parameter the parameters are given as
a single array, if not you'll get a single string as parameter.
Example:
[userFunc = user_mylib->test(hello,goodbye)]
function test($params) {
// $params is an array
list($param_a, $param_b) = $params;
if ($param_a == 'hello' &&
$param_b == 'goodbye') {
return true;
}
return false;
}
[userFunc = user_mylib->test(hello)]
function test($param) {
// $param is a string
if ($param == 'hello') {
return true;
}
return false;
}
---
bye
Wolfgang
-------------- next part --------------
Index: t3lib/class.t3lib_matchcondition.php
===================================================================
--- t3lib/class.t3lib_matchcondition.php (revision 1731)
+++ t3lib/class.t3lib_matchcondition.php (working copy)
@@ -355,18 +355,14 @@
{ return t3lib_div::compat_version($value); }
break;
case 'userFunc':
- $values = split('\(|\)',$value);
- $funcName=trim($values[0]);
- $funcValue = t3lib_div::trimExplode(',',$values[1]);
- $pre = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix'];
- if ($pre &&
- !t3lib_div::isFirstPartOfStr(trim($funcName),$pre) &&
- !t3lib_div::isFirstPartOfStr(trim($funcName),'tx_')
- ) {
- if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('Match condition: Function "'.$funcName.'" was not prepended with "'.$pre.'"',3);
- return false;
+ $values = split('\(|\)', $value);
+ $funcName = trim($values[0]);
+ $funcValues = t3lib_div::trimExplode(',', $values[1]);
+ // backwards compatible
+ if (count($funcValues) == 1) {
+ list($funcValues) = $funcValues;
}
- if (function_exists($funcName) && call_user_func($funcName, $funcValue[0])) {
+ if (t3lib_div::callUserFunction($funcName, $funcValues, $this, $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix'])) {
return true;
}
break;
More information about the TYPO3-team-core
mailing list