mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 11:50:30 +02:00
added vartrue(), alias of varsettrue(); added deftrue(), alias of defsettrue()
This commit is contained in:
@@ -9,46 +9,99 @@
|
|||||||
* e107 Core functions
|
* e107 Core functions
|
||||||
*
|
*
|
||||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/core_functions.php,v $
|
* $Source: /cvs_backup/e107_0.8/e107_handlers/core_functions.php,v $
|
||||||
* $Revision: 1.1 $
|
* $Revision: 1.2 $
|
||||||
* $Date: 2009-08-05 19:53:47 $
|
* $Date: 2009-08-28 00:22:08 $
|
||||||
* $Author: secretr $
|
* $Author: secretr $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//
|
//
|
||||||
// Use these to combine isset() and use of the set value. or defined and use of a constant
|
|
||||||
// i.e. to fix if($pref['foo']) ==> if ( varset($pref['foo']) ) will use the pref, or ''.
|
|
||||||
// Can set 2nd param to any other default value you like (e.g. false, 0, or whatever)
|
|
||||||
// $testvalue adds additional test of the value (not just isset())
|
|
||||||
// Examples:
|
|
||||||
// $something = pref; // Bug if pref not set ==> $something = varset(pref);
|
|
||||||
// $something = isset(pref) ? pref : ""; ==> $something = varset(pref);
|
|
||||||
// $something = isset(pref) ? pref : default; ==> $something = varset(pref,default);
|
|
||||||
// $something = isset(pref) && pref ? pref : default; ==> use varsettrue(pref,default)
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use these to combine isset() and use of the set value. or defined and use of a constant
|
||||||
|
* i.e. to fix if($pref['foo']) ==> if ( varset($pref['foo']) ) will use the pref, or ''.
|
||||||
|
* Can set 2nd param to any other default value you like (e.g. false, 0, or whatever)
|
||||||
|
* $testvalue adds additional test of the value (not just isset())
|
||||||
|
* Examples:
|
||||||
|
* <code>
|
||||||
|
* $something = pref; Bug if pref not set ==> $something = varset(pref);
|
||||||
|
* $something = isset(pref) ? pref : ""; ==> $something = varset(pref);
|
||||||
|
* $something = isset(pref) ? pref : default; ==> $something = varset(pref,default);
|
||||||
|
* $something = isset(pref) && pref ? pref : default; ==> use varsettrue(pref,default)
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @param mixed $val
|
||||||
|
* @param mixed $default [optional]
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
function varset(&$val, $default='')
|
function varset(&$val, $default='')
|
||||||
{
|
{
|
||||||
if (isset($val)) { return $val; }
|
if (isset($val)) { return $val; }
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the given string is defined (constant)
|
||||||
|
*
|
||||||
|
* @param string $str
|
||||||
|
* @param mixed $default [optional]
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
function defset($str, $default='')
|
function defset($str, $default='')
|
||||||
{
|
{
|
||||||
if (defined($str)) { return constant($str); }
|
if (defined($str)) { return constant($str); }
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// These variants are like the above, but only return the value if both set AND 'true'
|
* Variant of {@link varset()}, but only return the value if both set AND 'true'
|
||||||
//
|
*
|
||||||
|
* @param mixed $val
|
||||||
|
* @param mixed $default [optional]
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
function varsettrue(&$val, $default='')
|
function varsettrue(&$val, $default='')
|
||||||
{
|
{
|
||||||
if (isset($val) && $val) { return $val; }
|
if (isset($val) && $val) { return $val; }
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
function defsettrue($str,$default='')
|
/**
|
||||||
|
* Alias of {@link varsettrue()}
|
||||||
|
*
|
||||||
|
* @param mixed $val
|
||||||
|
* @param mixed $default [optional]
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function vartrue(&$val, $default='')
|
||||||
{
|
{
|
||||||
if (defined($str) && constant($str)) {return constant($str); }
|
return varsettrue($val, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variant of {@link defset()}, but only return the value if both defined AND 'true'
|
||||||
|
*
|
||||||
|
* @param string $str
|
||||||
|
* @param mixed $default [optional]
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function defsettrue($str, $default='')
|
||||||
|
{
|
||||||
|
if (defined($str) && constant($str)) { return constant($str); }
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias of {@link defsettrue()}
|
||||||
|
*
|
||||||
|
* @param string $str
|
||||||
|
* @param mixed $default [optional]
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function deftrue($str, $default='')
|
||||||
|
{
|
||||||
|
if (defined($str) && constant($str)) { return constant($str); }
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user