2009-08-05 19:53:47 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* e107 website system
|
|
|
|
*
|
2009-11-18 01:06:08 +00:00
|
|
|
* Copyright (C) 2008-2009 e107 Inc (e107.org)
|
2009-08-05 19:53:47 +00:00
|
|
|
* Released under the terms and conditions of the
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
|
|
|
*
|
|
|
|
* e107 Core functions
|
|
|
|
*
|
|
|
|
* $Source: /cvs_backup/e107_0.8/e107_handlers/core_functions.php,v $
|
2010-02-10 18:18:01 +00:00
|
|
|
* $Revision$
|
|
|
|
* $Date$
|
|
|
|
* $Author$
|
2009-08-05 19:53:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
2009-08-28 00:22:08 +00:00
|
|
|
|
2009-08-05 19:53:47 +00:00
|
|
|
//
|
2009-08-28 00:22:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2009-08-05 19:53:47 +00:00
|
|
|
function varset(&$val, $default='')
|
|
|
|
{
|
|
|
|
if (isset($val)) { return $val; }
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
2009-08-28 00:22:08 +00:00
|
|
|
/**
|
|
|
|
* Check if the given string is defined (constant)
|
|
|
|
*
|
|
|
|
* @param string $str
|
|
|
|
* @param mixed $default [optional]
|
2009-12-13 21:52:32 +00:00
|
|
|
* @return mixed
|
2009-08-28 00:22:08 +00:00
|
|
|
*/
|
2009-08-05 19:53:47 +00:00
|
|
|
function defset($str, $default='')
|
|
|
|
{
|
2017-04-14 11:00:29 -07:00
|
|
|
if(is_array($str))
|
2017-04-04 09:53:48 -07:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-05 19:53:47 +00:00
|
|
|
if (defined($str)) { return constant($str); }
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
2009-08-28 00:22:08 +00:00
|
|
|
/**
|
|
|
|
* Variant of {@link varset()}, but only return the value if both set AND 'true'
|
2013-06-08 16:06:52 -07:00
|
|
|
* @deprecated - use vartrue();
|
2009-08-28 00:22:08 +00:00
|
|
|
* @param mixed $val
|
|
|
|
* @param mixed $default [optional]
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2009-08-05 19:53:47 +00:00
|
|
|
function varsettrue(&$val, $default='')
|
|
|
|
{
|
2020-12-21 10:00:28 -08:00
|
|
|
trigger_error('<b>varsettrue() is deprecated.</b> Use vartrue() instead.', E_USER_DEPRECATED); // NO LAN
|
2015-02-14 23:34:15 -08:00
|
|
|
return vartrue($val, $default);
|
2009-08-05 19:53:47 +00:00
|
|
|
}
|
|
|
|
|
2009-08-28 00:22:08 +00:00
|
|
|
/**
|
|
|
|
* Alias of {@link varsettrue()}
|
|
|
|
*
|
|
|
|
* @param mixed $val
|
|
|
|
* @param mixed $default [optional]
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function vartrue(&$val, $default='')
|
|
|
|
{
|
2015-02-14 23:34:15 -08:00
|
|
|
|
|
|
|
if (isset($val) && $val) { return $val; }
|
|
|
|
return $default;
|
2009-08-28 00:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Variant of {@link defset()}, but only return the value if both defined AND 'true'
|
2013-06-08 16:06:52 -07:00
|
|
|
* @deprecated - use deftrue()
|
2009-08-28 00:22:08 +00:00
|
|
|
* @param string $str
|
|
|
|
* @param mixed $default [optional]
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function defsettrue($str, $default='')
|
|
|
|
{
|
2020-12-21 10:00:28 -08:00
|
|
|
trigger_error('<b>defsettrue() is deprecated.</b> Use deftrue() instead.', E_USER_DEPRECATED); // NO LAN
|
2009-08-28 00:22:08 +00:00
|
|
|
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='')
|
2009-08-05 19:53:47 +00:00
|
|
|
{
|
2009-08-28 00:22:08 +00:00
|
|
|
if (defined($str) && constant($str)) { return constant($str); }
|
2009-08-05 19:53:47 +00:00
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:54:24 -07:00
|
|
|
/**
|
|
|
|
* @param $fname
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2009-08-05 19:53:47 +00:00
|
|
|
function e107_include($fname)
|
|
|
|
{
|
2020-04-26 13:32:18 -07:00
|
|
|
global $_E107;
|
|
|
|
$ret = (isset($_E107['debug']) || deftrue('e_DEBUG')) ? include($fname) : @include($fname);
|
2009-08-05 19:53:47 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:54:24 -07:00
|
|
|
/**
|
|
|
|
* @param $fname
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
2009-08-05 19:53:47 +00:00
|
|
|
function e107_include_once($fname)
|
|
|
|
{
|
2020-04-26 13:32:18 -07:00
|
|
|
global $_E107;
|
2009-08-05 19:53:47 +00:00
|
|
|
if(is_readable($fname))
|
|
|
|
{
|
2020-04-26 13:32:18 -07:00
|
|
|
$ret = (isset($_E107['debug']) || deftrue('e_DEBUG')) ? include_once($fname) : @include_once($fname);
|
2009-08-05 19:53:47 +00:00
|
|
|
}
|
|
|
|
return (isset($ret)) ? $ret : '';
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:54:24 -07:00
|
|
|
/**
|
|
|
|
* @param $fname
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2009-08-05 19:53:47 +00:00
|
|
|
function e107_require_once($fname)
|
|
|
|
{
|
2020-04-26 13:32:18 -07:00
|
|
|
global $_E107;
|
2009-12-27 13:56:15 +00:00
|
|
|
|
2020-04-26 13:32:18 -07:00
|
|
|
$ret = ((isset($_E107['debug']) || deftrue('e_DEBUG')) ? require_once($fname) : @require_once($fname));
|
2009-12-27 13:56:15 +00:00
|
|
|
|
2009-08-05 19:53:47 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:54:24 -07:00
|
|
|
/**
|
|
|
|
* @param $fname
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2009-08-05 19:53:47 +00:00
|
|
|
function e107_require($fname)
|
|
|
|
{
|
2020-04-26 13:32:18 -07:00
|
|
|
global $_E107;
|
|
|
|
$ret = ((isset($_E107['debug']) || deftrue('e_DEBUG')) ? require($fname) : @require($fname));
|
2009-08-05 19:53:47 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-04 10:54:24 -07:00
|
|
|
/**
|
|
|
|
* @param $var
|
|
|
|
* @param $return
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
2009-08-05 19:53:47 +00:00
|
|
|
function print_a($var, $return = FALSE)
|
|
|
|
{
|
|
|
|
if( ! $return)
|
|
|
|
{
|
|
|
|
echo '<pre>'.htmlspecialchars(print_r($var, TRUE), ENT_QUOTES, 'utf-8').'</pre>';
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-12-14 16:21:48 -08:00
|
|
|
|
|
|
|
return '<pre>'.htmlspecialchars(print_r($var, true), ENT_QUOTES, 'utf-8').'</pre>';
|
|
|
|
|
2009-08-05 19:53:47 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 10:54:24 -07:00
|
|
|
/**
|
|
|
|
* @param $expr
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-10-26 07:41:20 +00:00
|
|
|
function e_print($expr = null)
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
if(!$args) return;
|
|
|
|
foreach ($args as $arg)
|
|
|
|
{
|
|
|
|
print_a($arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:54:24 -07:00
|
|
|
/**
|
|
|
|
* @param $expr
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-10-26 07:41:20 +00:00
|
|
|
function e_dump($expr = null)
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
if(!$args) return;
|
|
|
|
|
|
|
|
echo '<pre>';
|
|
|
|
call_user_func_array('var_dump', $args);
|
|
|
|
echo '</pre>';
|
|
|
|
}
|
|
|
|
|
2009-08-05 19:53:47 +00:00
|
|
|
/**
|
|
|
|
* Strips slashes from a var if magic_quotes_gqc is enabled
|
2020-12-21 17:46:32 -08:00
|
|
|
* @deprecated
|
2009-08-05 19:53:47 +00:00
|
|
|
* @param mixed $data
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function strip_if_magic($data)
|
|
|
|
{
|
2020-12-14 16:21:48 -08:00
|
|
|
if (MAGIC_QUOTES_GPC === true)
|
2009-08-05 19:53:47 +00:00
|
|
|
{
|
|
|
|
return array_stripslashes($data);
|
|
|
|
}
|
2020-12-14 16:21:48 -08:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
2009-08-05 19:53:47 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 07:36:54 -08:00
|
|
|
/**
|
|
|
|
* Return an array with changes between 2 arrays.
|
|
|
|
*/
|
|
|
|
function array_diff_recursive($array1, $array2)
|
|
|
|
{
|
|
|
|
$ret = array();
|
|
|
|
|
|
|
|
foreach($array1 as $key => $val)
|
|
|
|
{
|
2020-01-17 19:21:06 +01:00
|
|
|
if(is_array($array2) && array_key_exists($key, $array2))
|
2014-01-10 07:36:54 -08:00
|
|
|
{
|
|
|
|
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;
|
2022-04-04 10:54:24 -07:00
|
|
|
}
|
2014-01-10 07:36:54 -08:00
|
|
|
|
|
|
|
|
2009-08-05 19:53:47 +00:00
|
|
|
/**
|
|
|
|
* Strips slashes from a string or an array
|
|
|
|
*
|
2022-04-04 10:54:24 -07:00
|
|
|
* @param $data
|
2021-12-03 14:58:33 -08:00
|
|
|
* @return array|string
|
2009-08-05 19:53:47 +00:00
|
|
|
*/
|
|
|
|
function array_stripslashes($data)
|
|
|
|
{
|
|
|
|
return is_array($data) ? array_map('array_stripslashes', $data) : stripslashes($data);
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:54:24 -07:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-08-05 19:53:47 +00:00
|
|
|
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)
|
|
|
|
{
|
2020-12-14 16:21:48 -08:00
|
|
|
$contents = ob_get_clean();
|
|
|
|
header('Content-Encoding: '.$encoding);
|
2009-08-05 19:53:47 +00:00
|
|
|
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
|
|
|
|
$size = strlen($contents);
|
|
|
|
$contents = gzcompress($contents, 9);
|
|
|
|
$contents = substr($contents, 0, $size);
|
|
|
|
print($contents);
|
|
|
|
exit();
|
|
|
|
}
|
2020-12-14 16:21:48 -08:00
|
|
|
|
|
|
|
ob_end_flush();
|
|
|
|
exit();
|
|
|
|
|
2009-08-05 19:53:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-25 14:57:53 -08:00
|
|
|
/**
|
|
|
|
* @deprecated but necessary. BC Fix.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getip()
|
|
|
|
{
|
|
|
|
trigger_error('<b>getip() is deprecated.</b> 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('<b>loadLanFiles() is deprecated.</b> 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('<b>e107_ini_set() is deprecated.</b> 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('<b>plugInstalled() is deprecated.</b> Use <e107::isInstalled() instead.', E_USER_DEPRECATED); // NO LAN
|
|
|
|
|
|
|
|
return e107::isInstalled($plugname);
|
|
|
|
/*global $pref;
|
|
|
|
// Could add more checks here later if appropriate
|
|
|
|
return isset($pref['plug_installed'][$plugname]);*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
function table_exists($check)
|
|
|
|
{
|
|
|
|
if (!$GLOBALS['mySQLtablelist'])
|
|
|
|
{
|
|
|
|
$tablist=mysql_list_tables($GLOBALS['mySQLdefaultdb']);
|
|
|
|
while (list($temp) = mysql_fetch_array($tablist))
|
|
|
|
{
|
|
|
|
$GLOBALS['mySQLtablelist'][] = $temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$mltable=MPREFIX.strtolower($check);
|
|
|
|
|
|
|
|
foreach ($GLOBALS['mySQLtablelist'] as $lang)
|
|
|
|
{
|
|
|
|
if (strpos($lang, $mltable) !== false)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-26 17:17:31 -08:00
|
|
|
|
|
|
|
// 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'))
|
|
|
|
{
|
2022-04-04 10:54:24 -07:00
|
|
|
/**
|
|
|
|
* @param $array
|
|
|
|
* @param $key
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function asortbyindex($array, $key)
|
2013-02-26 17:17:31 -08:00
|
|
|
{
|
|
|
|
foreach ($array as $i => $k)
|
|
|
|
{
|
2021-12-03 14:58:33 -08:00
|
|
|
$sort_values[$i] = $k[$key];
|
2013-02-26 17:17:31 -08:00
|
|
|
}
|
|
|
|
asort ($sort_values);
|
|
|
|
reset ($sort_values);
|
2019-05-27 10:45:35 -07:00
|
|
|
|
2021-01-14 17:26:15 -08:00
|
|
|
$sorted_arr = array();
|
|
|
|
|
2019-05-27 10:45:35 -07:00
|
|
|
foreach($sort_values as $arr_key =>$arr_val)
|
2013-02-26 17:17:31 -08:00
|
|
|
{
|
|
|
|
$sorted_arr[] = $array[$arr_key];
|
|
|
|
}
|
2019-05-27 10:45:35 -07:00
|
|
|
|
2013-02-26 17:17:31 -08:00
|
|
|
return $sorted_arr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-20 17:10:38 -07:00
|
|
|
if (!function_exists('r_emote'))
|
|
|
|
{
|
|
|
|
/**
|
2016-01-30 18:39:01 -08:00
|
|
|
* Still in use.
|
2013-05-20 17:10:38 -07:00
|
|
|
*/
|
|
|
|
function r_emote()
|
|
|
|
{
|
2021-01-14 17:26:15 -08:00
|
|
|
|
|
|
|
$pack = e107::getPref('emotepack');
|
|
|
|
|
|
|
|
$list = e107::getEmote()->getList();
|
|
|
|
|
2013-05-20 17:10:38 -07:00
|
|
|
$str = '';
|
2021-01-14 17:26:15 -08:00
|
|
|
foreach($list as $key => $value) // filename => text code
|
2013-05-20 17:10:38 -07:00
|
|
|
{
|
|
|
|
$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
|
2021-01-14 17:26:15 -08:00
|
|
|
$key = e_IMAGE_ABS."emotes/" . $pack . "/" .$key; // Add in the file path
|
2013-05-20 17:10:38 -07:00
|
|
|
|
|
|
|
$value2 = substr($value, 0, strpos($value, " "));
|
|
|
|
$value = ($value2 ? $value2 : $value);
|
2020-12-14 16:21:48 -08:00
|
|
|
$value = ($value === '&|') ? ':((' : $value;
|
2013-05-20 17:10:38 -07:00
|
|
|
$value = " ".$value." ";
|
2016-01-30 18:39:01 -08:00
|
|
|
|
|
|
|
// $str .= "\n<a class='addEmote' data-emote=\"".$value."\" href=\"javascript:addtext('$value',true)\"><img src='$key' alt='' /></a> ";
|
|
|
|
$str .= "\n<a class='addEmote' data-emote=\"".$value."\" href=\"#\"><img src='$key' alt='' /></a> ";
|
2013-05-20 17:10:38 -07:00
|
|
|
}
|
2016-01-30 18:39:01 -08:00
|
|
|
|
|
|
|
$JS = "
|
|
|
|
|
|
|
|
$('.addEmote').click(function(){
|
|
|
|
|
|
|
|
val = $(this).attr('data-emote')
|
|
|
|
addtext(val,true);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
";
|
|
|
|
|
|
|
|
e107::js('footer-inline',$JS);
|
|
|
|
|
|
|
|
|
2013-05-20 17:10:38 -07:00
|
|
|
return "<div class='spacer'>".$str."</div>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-06 14:52:35 -08:00
|
|
|
if (!function_exists('multiarray_sort'))
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort a Multi-Dimensional array
|
|
|
|
* @param $array
|
|
|
|
* @param $key
|
|
|
|
* @param $order
|
|
|
|
* @param $natsort
|
|
|
|
* @param $case
|
2018-11-22 13:43:02 -08:00
|
|
|
* @return array sorted array.
|
2013-03-06 14:52:35 -08:00
|
|
|
*/
|
2013-02-26 17:17:31 -08:00
|
|
|
function multiarray_sort(&$array, $key, $order = 'asc', $natsort = true, $case = true)
|
|
|
|
{
|
|
|
|
if(!is_array($array)) return $array;
|
|
|
|
|
|
|
|
$order = strtolower($order);
|
|
|
|
foreach ($array as $i => $arr)
|
|
|
|
{
|
2013-03-16 14:30:53 -07:00
|
|
|
$sort_values[$i] = varset($arr[$key]);
|
2013-02-26 17:17:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!$natsort)
|
|
|
|
{
|
2020-12-14 16:21:48 -08:00
|
|
|
($order==='asc')? asort($sort_values) : arsort($sort_values);
|
2013-02-26 17:17:31 -08:00
|
|
|
}
|
|
|
|
elseif(isset($sort_values))
|
|
|
|
{
|
|
|
|
$case ? natsort($sort_values) : natcasesort($sort_values);
|
2020-12-14 16:21:48 -08:00
|
|
|
if($order !== 'asc') $sort_values = array_reverse($sort_values, true);
|
2013-02-26 17:17:31 -08:00
|
|
|
}
|
|
|
|
|
2013-03-06 14:52:35 -08:00
|
|
|
|
2013-02-26 17:17:31 -08:00
|
|
|
if(!isset($sort_values))
|
|
|
|
{
|
2018-11-22 13:43:02 -08:00
|
|
|
return $array;
|
2013-02-26 17:17:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
reset ($sort_values);
|
2018-11-22 13:43:02 -08:00
|
|
|
/*
|
2013-02-26 17:17:31 -08:00
|
|
|
while (list ($arr_key, $arr_val) = each ($sort_values))
|
|
|
|
{
|
2013-03-06 14:52:35 -08:00
|
|
|
$key = is_numeric($arr_key) ? "" : $arr_key; // retain assoc-array keys.
|
|
|
|
$sorted_arr[$key] = $array[$arr_key];
|
2018-11-22 13:43:02 -08:00
|
|
|
}*/
|
2021-01-14 17:26:15 -08:00
|
|
|
$sorted_arr = array();
|
2018-11-22 13:43:02 -08:00
|
|
|
|
|
|
|
foreach($sort_values as $arr_key=>$arr_val)
|
|
|
|
{
|
2019-01-26 09:01:04 -08:00
|
|
|
$key = is_numeric($arr_key) ? "" : $arr_key; // retain assoc-array keys.
|
|
|
|
$sorted_arr[$key] = $array[$arr_key];
|
2013-02-26 17:17:31 -08:00
|
|
|
}
|
|
|
|
return $sorted_arr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:12:17 -08:00
|
|
|
/**
|
|
|
|
* Array Storage Class.
|
|
|
|
*/
|
|
|
|
class e_array {
|
|
|
|
|
|
|
|
/**
|
2016-11-18 14:40:53 -08:00
|
|
|
* Returns an array from stored array data in php serialized, e107 var_export and json-encoded data.
|
2013-02-26 19:12:17 -08:00
|
|
|
*
|
2019-05-13 12:29:24 -07:00
|
|
|
* @param string $sourceArrayData
|
2018-07-22 10:39:01 -07:00
|
|
|
* @return array|bool stored data
|
2013-02-26 19:12:17 -08:00
|
|
|
*/
|
2019-05-13 12:29:24 -07:00
|
|
|
public function unserialize($sourceArrayData)
|
2013-02-26 19:12:17 -08:00
|
|
|
{
|
2019-05-13 12:29:24 -07:00
|
|
|
$ArrayData = $sourceArrayData;
|
|
|
|
|
|
|
|
|
2020-12-12 11:32:23 -08:00
|
|
|
if (empty($ArrayData))
|
2019-05-22 13:57:26 -07:00
|
|
|
{
|
2013-02-26 19:12:17 -08:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-08 13:54:44 -08:00
|
|
|
|
|
|
|
if(is_array($ArrayData))
|
|
|
|
{
|
2021-02-08 08:44:44 -08:00
|
|
|
return $ArrayData;
|
2016-02-08 13:54:44 -08:00
|
|
|
}
|
2013-02-26 19:12:17 -08:00
|
|
|
|
2020-12-14 16:21:48 -08:00
|
|
|
// Saftety mechanism for 0.7 -> 0.8 transition.
|
|
|
|
$first2Chars = substr($ArrayData,0,2);
|
|
|
|
if($first2Chars === 'a:' || $first2Chars === 's:') // php serialize.
|
2013-02-26 19:12:17 -08:00
|
|
|
{
|
2020-12-21 10:09:03 -08:00
|
|
|
if(PHP_MAJOR_VERSION > 5)
|
|
|
|
{
|
|
|
|
$dat = unserialize($ArrayData, ['allowed_classes' => false]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$dat = unserialize($ArrayData);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ArrayData = $this->serialize($dat,FALSE);
|
2013-02-26 19:12:17 -08:00
|
|
|
}
|
2019-05-22 13:57:26 -07:00
|
|
|
elseif(strpos($ArrayData,'{') === 0 || strpos($ArrayData,'[') === 0) // json
|
2016-11-18 14:40:53 -08:00
|
|
|
{
|
|
|
|
$dat = json_decode($ArrayData, true);
|
|
|
|
|
|
|
|
// e107::getDebug()->log("Json data found");
|
|
|
|
|
2020-12-22 14:48:28 -08:00
|
|
|
if(deftrue('e_DEBUG') && json_last_error() != JSON_ERROR_NONE && !e107::isCli())
|
2016-11-18 14:40:53 -08:00
|
|
|
{
|
2020-12-19 11:46:58 -08:00
|
|
|
e107::getDebug()->log("e107::unserialize() Parser Error (json)");
|
|
|
|
|
|
|
|
$dbg = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 9);
|
|
|
|
|
|
|
|
$fileName = e_LOG.'unserializeError_'.time().'.log';
|
|
|
|
|
|
|
|
file_put_contents($fileName, "input:". $sourceArrayData."\nbacktrace:\n".print_r($dbg,true));
|
|
|
|
|
|
|
|
return null;
|
2016-11-18 14:40:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $dat;
|
|
|
|
}
|
|
|
|
|
|
|
|
// below is var_export() format using eval();
|
|
|
|
|
2016-02-08 13:54:44 -08:00
|
|
|
$ArrayData = trim($ArrayData);
|
|
|
|
|
2018-07-22 10:39:01 -07:00
|
|
|
if(strpos($ArrayData, "\$data = ") === 0) // Fix for buggy old value.
|
|
|
|
{
|
2019-05-13 12:29:24 -07:00
|
|
|
$ArrayData = (string) substr($ArrayData,8);
|
2018-07-22 10:39:01 -07:00
|
|
|
}
|
|
|
|
|
2021-01-24 17:00:02 -08:00
|
|
|
if(stripos($ArrayData, 'array') !== 0)
|
2016-02-08 13:54:44 -08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-21 19:15:20 -07:00
|
|
|
|
2020-12-14 16:21:48 -08:00
|
|
|
if(strpos($ArrayData,"0 => \'")!==false)
|
2016-03-21 19:15:20 -07:00
|
|
|
{
|
|
|
|
$ArrayData = stripslashes($ArrayData);
|
|
|
|
}
|
2019-06-01 15:51:05 -07:00
|
|
|
elseif(strpos($ArrayData,'array') === 0 && strpos($ArrayData,"\' => \'") !== false && strpos($ArrayData,"' => 'array") === false) // FIX for old corrupted link-words preference.
|
2019-05-22 13:57:26 -07:00
|
|
|
{
|
|
|
|
$ArrayData = stripslashes($ArrayData);
|
|
|
|
}
|
2016-03-21 19:15:20 -07:00
|
|
|
|
2016-03-22 21:11:47 -07:00
|
|
|
$ArrayData = str_replace('=>','=>',$ArrayData); //FIX for PDO encoding of strings. .
|
|
|
|
|
|
|
|
|
2020-12-14 16:21:48 -08:00
|
|
|
if(trim($ArrayData) === 'Array') // Something went wrong with storage.
|
2016-03-25 11:24:07 -07:00
|
|
|
{
|
|
|
|
$debug = debug_backtrace(false);
|
|
|
|
e107::getMessage()->addDebug("Bad Array Storage found: ". print_a($debug,true));
|
|
|
|
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:12:17 -08:00
|
|
|
$data = "";
|
2016-02-08 13:54:44 -08:00
|
|
|
$ArrayData = '$data = '.$ArrayData.';';
|
2016-03-22 21:11:47 -07:00
|
|
|
|
2016-11-18 14:40:53 -08:00
|
|
|
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 "<div class='alert alert-danger'><h4>e107::unserialize() Parser Error</h4>". $message. "</div>";
|
|
|
|
echo "<pre>";
|
2018-08-10 14:24:32 -07:00
|
|
|
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
|
2016-11-18 14:40:53 -08:00
|
|
|
echo "</pre>";
|
2019-05-22 13:57:26 -07:00
|
|
|
file_put_contents(e_LOG.'unserializeError_'.time().'.log', $sourceArrayData);
|
2016-11-18 14:40:53 -08:00
|
|
|
}
|
|
|
|
|
2019-05-22 13:57:26 -07:00
|
|
|
// e107::getAdminLog()->addError($sourceArrayData)->toFile('unserializeError_'.time().'.log','e107::unserialize',false);
|
|
|
|
|
2019-05-13 12:29:24 -07:00
|
|
|
|
2016-11-18 14:40:53 -08:00
|
|
|
return array();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
@eval($ArrayData);
|
|
|
|
if (!isset($data) || !is_array($data))
|
|
|
|
{
|
2019-05-22 13:57:26 -07:00
|
|
|
if(e_DEBUG === true)
|
|
|
|
{
|
|
|
|
file_put_contents(e_LOG.'unserializeError_'.time().'.log', $sourceArrayData);
|
|
|
|
}
|
|
|
|
|
2020-04-26 13:32:18 -07:00
|
|
|
trigger_error("Bad stored array data - <br /><br />".htmlentities($ArrayData), E_USER_ERROR);
|
|
|
|
|
2016-11-18 14:40:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-22 21:11:47 -07:00
|
|
|
|
2013-02-26 19:12:17 -08:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a string containg exported array data.
|
|
|
|
*
|
|
|
|
* @param array $ArrayData array to be stored
|
2016-11-18 14:40:53 -08:00
|
|
|
* @param bool|string $mode true = var_export with addedslashes, false = var_export (default), 'json' = json encoded
|
2018-11-15 14:20:08 -08:00
|
|
|
* @return null|string
|
2013-02-26 19:12:17 -08:00
|
|
|
*/
|
2016-11-18 14:40:53 -08:00
|
|
|
public function serialize($ArrayData, $mode = false)
|
2013-02-26 19:12:17 -08:00
|
|
|
{
|
2016-11-18 14:40:53 -08:00
|
|
|
if (!is_array($ArrayData) || empty($ArrayData))
|
|
|
|
{
|
2018-11-15 14:20:08 -08:00
|
|
|
return null;
|
2013-02-26 19:12:17 -08:00
|
|
|
}
|
2016-03-26 10:14:57 -07:00
|
|
|
|
2016-11-18 14:40:53 -08:00
|
|
|
if($mode === 'json')
|
|
|
|
{
|
2020-03-24 13:57:05 -07:00
|
|
|
//todo discuss - move to e_parse::toJSON() ?
|
|
|
|
$encoded = json_encode($ArrayData, JSON_PRETTY_PRINT);
|
|
|
|
if(json_last_error() === JSON_ERROR_UTF8)
|
|
|
|
{
|
|
|
|
$ArrayData = e107::getParser()->toUTF8($ArrayData);
|
|
|
|
$encoded = json_encode($ArrayData, JSON_PRETTY_PRINT);
|
|
|
|
//todo log
|
|
|
|
}
|
|
|
|
|
|
|
|
return $encoded;
|
2016-11-18 14:40:53 -08:00
|
|
|
}
|
|
|
|
|
2013-02-26 19:12:17 -08:00
|
|
|
$Array = var_export($ArrayData, true);
|
2016-03-26 10:14:57 -07:00
|
|
|
|
2020-12-14 16:21:48 -08:00
|
|
|
if ($mode === true)
|
2016-03-26 10:14:57 -07:00
|
|
|
{
|
2013-02-26 19:12:17 -08:00
|
|
|
$Array = addslashes($Array);
|
|
|
|
}
|
2016-03-26 10:14:57 -07:00
|
|
|
|
2013-02-26 19:12:17 -08:00
|
|
|
return $Array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-24 13:57:05 -07:00
|
|
|
|
|
|
|
|
2013-02-26 19:12:17 -08:00
|
|
|
/**
|
2020-12-21 10:00:28 -08:00
|
|
|
* @deprecated - Backwards Compatible. Use e107::serialize() instead;
|
2013-02-26 19:12:17 -08:00
|
|
|
* @param array $ArrayData array to be stored
|
|
|
|
* @param bool $AddSlashes default true, add slashes for db storage, else false
|
2013-05-28 15:41:05 +03:00
|
|
|
* @return string a string containg exported array data.
|
2013-02-26 19:12:17 -08:00
|
|
|
*/
|
2020-12-21 10:00:28 -08:00
|
|
|
function WriteArray($ArrayData, $AddSlashes = true)
|
|
|
|
{
|
|
|
|
trigger_error('<b>'.__METHOD__.' is deprecated.</b> Use e107::serialize() instead.', E_USER_DEPRECATED); // no LAN
|
2013-03-31 05:55:08 -07:00
|
|
|
return $this->serialize($ArrayData, $AddSlashes);
|
|
|
|
|
|
|
|
}
|
2022-04-04 10:54:24 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $ArrayData
|
|
|
|
* @param $AddSlashes
|
|
|
|
* @return string|null
|
|
|
|
*/
|
2020-12-21 10:00:28 -08:00
|
|
|
function write($ArrayData, $AddSlashes = true)
|
|
|
|
{
|
2020-12-22 14:48:28 -08:00
|
|
|
return $this->serialize($ArrayData, $AddSlashes);
|
2013-02-26 19:12:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:00:28 -08:00
|
|
|
* @deprecated: Use e107::unserialize(); instead.
|
2013-02-26 19:12:17 -08:00
|
|
|
* Returns an array from stored array data.
|
2015-02-14 23:34:15 -08:00
|
|
|
* @deprecated
|
2013-02-26 19:12:17 -08:00
|
|
|
* @param string $ArrayData
|
|
|
|
* @return array stored data
|
|
|
|
*/
|
|
|
|
function ReadArray($ArrayData)
|
|
|
|
{
|
2020-12-21 10:00:28 -08:00
|
|
|
trigger_error('<b>'.__METHOD__.' is deprecated.</b> Use e107::unserialize() instead.', E_USER_DEPRECATED); // NO LAN
|
2013-03-31 05:55:08 -07:00
|
|
|
return $this->unserialize($ArrayData);
|
|
|
|
}
|
2022-04-04 10:54:24 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $ArrayData
|
|
|
|
* @return array|bool|string|null
|
|
|
|
*/
|
|
|
|
function read($ArrayData)
|
2013-03-31 05:55:08 -07:00
|
|
|
{
|
|
|
|
return $this->unserialize($ArrayData);
|
2013-02-26 19:12:17 -08:00
|
|
|
}
|
2013-05-28 15:41:05 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load and unserialize stored data from a local file inside SYSTEM folder
|
|
|
|
* @example e107::getArrayStorage()->load('import/somefile'); // -> e_SYSTEM/import/somefile.php
|
|
|
|
* @example e107::getArrayStorage()->load('somefile', 'weird'); // -> e_SYSTEM/somefile.weird
|
|
|
|
*
|
|
|
|
* @param string $systemLocationFile relative to e_SYSTEM file path (without the extension)
|
|
|
|
* @param string $extension [optional] file extension, default is 'php'
|
2020-03-24 13:57:05 -07:00
|
|
|
* @return array|false false when file not found (or on error)
|
2013-05-28 15:41:05 +03:00
|
|
|
*/
|
|
|
|
public function load($systemLocationFile, $extension = 'php')
|
|
|
|
{
|
|
|
|
if($extension) $extension = '.'.$extension;
|
|
|
|
$_f = e_SYSTEM.preg_replace('#[^\w/]#', '', trim($systemLocationFile, '/')).$extension;
|
|
|
|
if(!file_exists($_f))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$content = file_get_contents($_f);
|
2013-02-26 19:12:17 -08:00
|
|
|
|
2013-05-28 15:41:05 +03:00
|
|
|
return $this->read($content);
|
|
|
|
}
|
2020-04-26 13:32:18 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Serialize and store data to a local file inside SYSTEM folder
|
|
|
|
* @example e107::getArrayStorage()->store($arrayData, 'import/somefile'); // -> e_SYSTEM/import/somefile.php
|
|
|
|
* @example e107::getArrayStorage()->store($arrayData, 'somefile', 'weird'); // -> e_SYSTEM/somefile.weird
|
|
|
|
*
|
|
|
|
* @param array $array
|
|
|
|
* @param string $systemLocationFile relative to e_SYSTEM file path (without the extension)
|
|
|
|
* @param string $extension [optional] file extension, default is 'php'
|
2021-12-03 14:58:33 -08:00
|
|
|
* @return bool when file not found (or on error)
|
2020-04-26 13:32:18 -07:00
|
|
|
*/
|
2013-05-28 15:41:05 +03:00
|
|
|
public function store($array, $systemLocationFile, $extension = 'php')
|
|
|
|
{
|
|
|
|
if($extension) $extension = '.'.$extension;
|
|
|
|
$_f = e_SYSTEM.preg_replace('#[^\w/]#', '', trim($systemLocationFile, '/')).$extension;
|
|
|
|
|
|
|
|
$content = $this->write($array, false);
|
|
|
|
|
|
|
|
if(false !== $content)
|
|
|
|
{
|
|
|
|
return file_put_contents($_f, $content) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-02-26 17:17:31 -08:00
|
|
|
|