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)
*
*
* @param mixed $val
* @param mixed $default [optional]
* @return mixed
*/
function varset(&$val, $default='')
{
if (isset($val)) { return $val; }
return $default;
}
/**
* Check if the given string is defined (constant)
*
* @param string $str
* @param mixed $default [optional]
* @return mixed
*/
function defset($str, $default='')
{
if(is_array($str))
{
return false;
}
if (defined($str)) { return constant($str); }
return $default;
}
/**
* Variant of {@link varset()}, but only return the value if both set AND 'true'
* @deprecated - use vartrue();
* @param mixed $val
* @param mixed $default [optional]
* @return mixed
*/
function varsettrue(&$val, $default='')
{
trigger_error('varsettrue() is deprecated. Use vartrue() instead.', E_USER_DEPRECATED); // NO LAN
return vartrue($val, $default);
}
/**
* Alias of {@link varsettrue()}
*
* @param mixed $val
* @param mixed $default [optional]
* @return mixed
*/
function vartrue(&$val, $default='')
{
if (isset($val) && $val) { return $val; }
return $default;
}
/**
* Variant of {@link defset()}, but only return the value if both defined AND 'true'
* @deprecated - use deftrue()
* @param string $str
* @param mixed $default [optional]
* @return mixed
*/
function defsettrue($str, $default='')
{
trigger_error('defsettrue() is deprecated. Use deftrue() instead.', E_USER_DEPRECATED); // NO LAN
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;
}
/**
* @param $fname
* @return mixed
*/
function e107_include($fname)
{
global $_E107;
$ret = (isset($_E107['debug']) || deftrue('e_DEBUG')) ? include($fname) : @include($fname);
return $ret;
}
/**
* @param $fname
* @return mixed|string
*/
function e107_include_once($fname)
{
global $_E107;
if(is_readable($fname))
{
$ret = (isset($_E107['debug']) || deftrue('e_DEBUG')) ? include_once($fname) : @include_once($fname);
}
return (isset($ret)) ? $ret : '';
}
/**
* @param $fname
* @return mixed
*/
function e107_require_once($fname)
{
global $_E107;
$ret = ((isset($_E107['debug']) || deftrue('e_DEBUG')) ? require_once($fname) : @require_once($fname));
return $ret;
}
/**
* @param $fname
* @return mixed
*/
function e107_require($fname)
{
global $_E107;
$ret = ((isset($_E107['debug']) || deftrue('e_DEBUG')) ? require($fname) : @require($fname));
return $ret;
}
/**
* @param $var
* @param $return
* @return bool|string
*/
function print_a($var, $return = FALSE)
{
if( ! $return)
{
echo '
'.htmlspecialchars(print_r($var, TRUE), ENT_QUOTES, 'utf-8').''; return TRUE; } return '
'.htmlspecialchars(print_r($var, true), ENT_QUOTES, 'utf-8').''; } /** * @param $expr * @return void */ function e_print($expr = null) { $args = func_get_args(); if(!$args) return; foreach ($args as $arg) { print_a($arg); } } /** * @param $expr * @return void */ function e_dump($expr = null) { $args = func_get_args(); if(!$args) return; echo '
'; call_user_func_array('var_dump', $args); echo ''; } /** * Strips slashes from a var if magic_quotes_gqc is enabled * @deprecated * @param mixed $data * @return mixed */ function strip_if_magic($data) { if (MAGIC_QUOTES_GPC === true) { return array_stripslashes($data); } return $data; } /** * Return an array with changes between 2 arrays. */ function array_diff_recursive($array1, $array2) { $ret = array(); foreach($array1 as $key => $val) { if(is_array($array2) && array_key_exists($key, $array2)) { if(is_array($val)) { $diff = array_diff_recursive($val, $array2[$key]); if(count($diff)) { $ret[$key] = $diff; } } else { if($val != $array2[$key]) { $ret[$key] = $val; } } } else { $ret[$key] = $val; } } return $ret; } /** * Strips slashes from a string or an array * * @param $data * @return array|string */ function array_stripslashes($data) { return is_array($data) ? array_map('array_stripslashes', $data) : stripslashes($data); } /** * @return void */ function echo_gzipped_page() { if(headers_sent()) { $encoding = false; } elseif( strpos($_SERVER["HTTP_ACCEPT_ENCODING"], 'x-gzip') !== false ) { $encoding = 'x-gzip'; } elseif( strpos($_SERVER["HTTP_ACCEPT_ENCODING"],'gzip') !== false ) { $encoding = 'gzip'; } else { $encoding = false; } if($encoding) { $contents = ob_get_clean(); header('Content-Encoding: '.$encoding); print("\x1f\x8b\x08\x00\x00\x00\x00\x00"); $size = strlen($contents); $contents = gzcompress($contents, 9); $contents = substr($contents, 0, $size); print($contents); exit(); } ob_end_flush(); exit(); } /** * @deprecated but necessary. BC Fix. * @return string */ function getip() { trigger_error('getip() is deprecated. Use e107::getIPHandler()->ipDecode(USERIP) instead.', E_USER_DEPRECATED); // NO LAN return e107::getIPHandler()->ipDecode(USERIP); } /** * @deprecated - use e107::loadLanFiles(); * @param $unitName * @param string $type * @return bool|string * Routine looks in standard paths for language files associated with a plugin or theme - primarily for core routines, which won't know * for sure where the author has put them. * $unitName is the name (directory path) of the plugin or theme * $type determines what is to be loaded: * 'runtime' - the standard runtime language file for a plugin * 'admin' - the standard admin language file for a plugin * 'theme' - the standard language file for a plugin (these are usually pretty small, so one is enough) * Otherwise, $type is treated as part of a filename within the plugin's language directory, prefixed with the current language * Returns false on failure (not found). * Returns the include_once error return if there is one * Otherwise returns an empty string. * * Note - if the code knows precisely where the language file is located, use include_lan() * * $pref['noLanguageSubs'] can be set true to prevent searching for the English files if the files for the current site language don't exist. */ function loadLanFiles($unitName, $type='runtime') { trigger_error('loadLanFiles() is deprecated. Use e107::loadLanFiles() instead.', E_USER_DEPRECATED); // NO LAN $info = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,2); e107::getMessage()->addDebug("Using deprecated function loanLanFiles(). Replace with e107::loadLanFiles().".print_a($info,true)); return e107::loadLanFiles($unitName, $type); } /** * @deprecated Use ini_set() directly. * @param $var * @param $value * @return false|string */ function e107_ini_set($var, $value) { trigger_error('e107_ini_set() is deprecated. Use ini_set() instead.', E_USER_DEPRECATED); // NO LAN if (function_exists('ini_set')) { return ini_set($var, $value); } return false; } /** * @deprecated - use e107::isInstalled(); * @param $plugname * @return bool */ function plugInstalled($plugname) { trigger_error('plugInstalled() is deprecated. Use
"; debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); echo ""; file_put_contents(e_LOG.'unserializeError_'.time().'.log', $sourceArrayData); } // e107::getAdminLog()->addError($sourceArrayData)->toFile('unserializeError_'.time().'.log','e107::unserialize',false); return array(); } } else { @eval($ArrayData); if (!isset($data) || !is_array($data)) { if(e_DEBUG === true) { file_put_contents(e_LOG.'unserializeError_'.time().'.log', $sourceArrayData); } trigger_error("Bad stored array data -