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 (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='')
{
if (isset($val) && $val) { return $val; }
return $default;
}
/**
* Alias of {@link varsettrue()}
*
* @param mixed $val
* @param mixed $default [optional]
* @return mixed
*/
function vartrue(&$val, $default='')
{
return varsettrue($val, $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='')
{
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;
}
function e107_include($fname)
{
global $e107_debug, $_E107;
$ret = (($e107_debug || isset($_E107['debug']) || deftrue('e_DEBUG')) ? include($fname) : @include($fname));
return $ret;
}
function e107_include_once($fname)
{
global $e107_debug, $_E107;
if(is_readable($fname))
{
$ret = ($e107_debug || isset($_E107['debug']) || deftrue('e_DEBUG')) ? include_once($fname) : @include_once($fname);
}
return (isset($ret)) ? $ret : '';
}
function e107_require_once($fname)
{
global $e107_debug, $_E107;
$ret = (($e107_debug || isset($_E107['debug']) || deftrue('e_DEBUG')) ? require_once($fname) : @require_once($fname));
return $ret;
}
function e107_require($fname)
{
global $e107_debug, $_E107;
$ret = (($e107_debug || isset($_E107['debug']) || deftrue('e_DEBUG')) ? require($fname) : @require($fname));
return $ret;
}
function print_a($var, $return = FALSE)
{
if( ! $return)
{
echo '
'.htmlspecialchars(print_r($var, TRUE), ENT_QUOTES, 'utf-8').''; return TRUE; } else { return '
'.htmlspecialchars(print_r($var, true), ENT_QUOTES, 'utf-8').''; } } function e_print($expr = null) { $args = func_get_args(); if(!$args) return; foreach ($args as $arg) { print_a($arg); } } 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 * * @param mixed $data * @return mixed */ function strip_if_magic($data) { if (MAGIC_QUOTES_GPC == true) { return array_stripslashes($data); } else { return $data; } } /** * Return an array with changes between 2 arrays. */ function array_diff_recursive($array1, $array2) { $ret = array(); foreach($array1 as $key => $val) { if(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 mixed $value * @return mixed */ function array_stripslashes($data) { return is_array($data) ? array_map('array_stripslashes', $data) : stripslashes($data); } 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_contents(); ob_end_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(); } else { ob_end_flush(); exit(); } } // Better Array-sort by key function by acecream (22-Apr-2003 11:02) http://php.net/manual/en/function.asort.php if (!function_exists('asortbyindex')) { function asortbyindex($array, $key) { foreach ($array as $i => $k) { $sort_values[$i] = $array[$i][$key]; } asort ($sort_values); reset ($sort_values); while (list ($arr_key, $arr_val) = each ($sort_values)) { $sorted_arr[] = $array[$arr_key]; } return $sorted_arr; } } if (!function_exists('r_emote')) { /** * @DEPRECATED */ function r_emote() { global $sysprefs, $pref; $tp = e107::getParser(); if (!is_object($tp->e_emote)) { // require_once(e_HANDLER.'emote_filter.php'); $tp->e_emote = new e_emoteFilter; } $str = ''; foreach($tp->e_emote->emotes as $key => $value) // filename => text code { $key = str_replace("!", ".", $key); // Usually '.' was replaced by '!' when saving $key = preg_replace("#_(\w{3})$#", ".\\1", $key); // '_' followed by exactly 3 chars is file extension $key = e_IMAGE."emotes/" . $pref['emotepack'] . "/" .$key; // Add in the file path $value2 = substr($value, 0, strpos($value, " ")); $value = ($value2 ? $value2 : $value); $value = ($value == '&|') ? ':((' : $value; $value = " ".$value." "; //TODO CSS class $str .= "\n "; } return "