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='')
{
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='')
{
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'))
{
/**
* Still in use.
*/
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_ABS."emotes/" . $pref['emotepack'] . "/" .$key; // Add in the file path
$value2 = substr($value, 0, strpos($value, " "));
$value = ($value2 ? $value2 : $value);
$value = ($value == '&|') ? ':((' : $value;
$value = " ".$value." ";
// $str .= "\n"; debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); echo ""; } return $dat; } // below is var_export() format using eval(); $ArrayData = trim($ArrayData); if(strpos($ArrayData, "\$data = ") === 0) // Fix for buggy old value. { $ArrayData = substr($ArrayData,8); } if(strtolower(substr($ArrayData,0,5)) != 'array') { return false; } if(strpos($ArrayData,"0 => \'")!=false) { $ArrayData = stripslashes($ArrayData); } $ArrayData = str_replace('=>','=>',$ArrayData); //FIX for PDO encoding of strings. . if(trim($ArrayData) == 'Array') // Something went wrong with storage. { $debug = debug_backtrace(false); e107::getMessage()->addDebug("Bad Array Storage found: ". print_a($debug,true)); return array(); } $data = ""; $ArrayData = '$data = '.$ArrayData.';'; if(PHP_MAJOR_VERSION > 6) // catch parser error. { try { @eval($ArrayData); } catch (ParseError $e) { if(e_DEBUG === true) { $message = $e->getMessage(); $message .= print_a($ArrayData,true); echo "
"; debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); echo ""; } return array(); } } else { @eval($ArrayData); if (!isset($data) || !is_array($data)) { trigger_error("Bad stored array data -