Skip to content

Commit

Permalink
Issue #5120 Use static methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Dec 18, 2023
1 parent ab5f0fb commit 63d3c07
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 86 deletions.
46 changes: 5 additions & 41 deletions class2.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,6 @@

//
// C: Find out if register globals is enabled and destroy them if so
// (DO NOT use the value of any variables before this point! They could have been set by the user)
//

// Can't be moved to e107, required here for e107_config vars security
/*$register_globals = true;
if(function_exists('ini_get'))
{
$register_globals = ini_get('register_globals');
}*/

// Destroy! (if we need to)
/*
if($register_globals === true)
{
if(isset($_REQUEST['_E107'])) { unset($_E107); }
foreach($GLOBALS as $global=>$var)
{
if (!preg_match('/^(_POST|_GET|_COOKIE|_SERVER|_FILES|_SESSION|GLOBALS|HTTP.*|_REQUEST|_E107|retrieve_prefs|eplug_admin|eTimingStart.*|oblev_.*)$/', $global))
{
unset($$global);
}
}
unset($global);
}*/


// Set Absolute file-path of directory containing class2.php
Expand Down Expand Up @@ -159,7 +135,7 @@
unset($retrieve_prefs);
}

$config = include(e_ROOT.'e107_config.php');
include(e_ROOT.'e107_config.php');

if(!defined('e_POWEREDBY_DISABLE'))
{
Expand All @@ -183,7 +159,7 @@

//define("MPREFIX", $mySQLprefix); moved to $e107->set_constants()

if(empty($mySQLdefaultdb) && empty($config))
if(empty($mySQLdefaultdb) && !class_exists('e107_config'))
{
// e107_config.php is either empty, not valid or doesn't exist so redirect to installer..
header('Location: install.php');
Expand Down Expand Up @@ -235,9 +211,9 @@
}
else // New e107_config.php format. v2.4+
{
$e107_paths = $config->paths();
$sql_info = $config->database();
$E107_CONFIG = $config->other() ?? [];
$e107_paths = e107_config::paths();
$sql_info = e107_config::database();
$E107_CONFIG = e107_config::other() ?? [];
}


Expand Down Expand Up @@ -297,15 +273,6 @@
$dbg->logTime('Init ErrHandler');
}

//
// I: Sanity check on e107_config.php
// e107_config.php upgrade check
// obsolete check, rewrite it
// if (!$ADMIN_DIRECTORY && !$DOWNLOADS_DIRECTORY)
// {
// message_handler('CRITICAL_ERROR', 8, ': generic, ', 'e107_config.php');
// exit;
// }

//
// J: MYSQL INITIALIZATION
Expand Down Expand Up @@ -433,9 +400,6 @@
$sysprefs = new prefs;
//DEPRECATED, BC, call e107::getPref/findPref() instead

//this could be part of e107->init() method now, prefs will be auto-initialized
//when proper called (e107::getPref())
// $e107->set_base_path(); moved to init().

//DEPRECATED, BC, call e107::getConfig('menu')->get('pref_name') only when needed
if(!isset($_E107['no_menus']))
Expand Down
2 changes: 1 addition & 1 deletion e107_handlers/e_db_pdo_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function __construct()
$this->mySQLlanguage = e107::getLanguage()->e_language;
}

if (E107_DEBUG_LEVEL > 0)
if (defset('E107_DEBUG_LEVEL') > 0)
{
$this->debugMode = true;
}
Expand Down
7 changes: 3 additions & 4 deletions e107_tests/tests/_data/e107_config.php.sample
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const e_MOD_REWRITE = true;

class e107_config
{
public function database()
public static function database()
{
return [
'server' => '{{ mySQLserver }}',
Expand All @@ -52,7 +52,7 @@ class e107_config
];
}

public function paths()
public static function paths()
{
return [
'admin' => 'e107_admin/',
Expand All @@ -68,12 +68,11 @@ class e107_config
];
}

public function other()
public static function other()
{
return [
'site_path' => '000000test'
];
}
}

return new e107_config;
73 changes: 33 additions & 40 deletions thumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ function thumbExceptionHandler(Throwable $exception)
{
http_response_code(500);
echo "Fatal Thumbnail Error\n";
echo $exception->getMessage();

error_log($exception->getMessage());
}

function thumbErrorHandler($errno, $errstr, $errfile, $errline)
Expand Down Expand Up @@ -73,7 +72,7 @@ class e_thumbpage
function __construct()
{

$self = realpath(__DIR__);
$self = realpath(__DIR__);

$e_ROOT = $self."/";

Expand Down Expand Up @@ -109,51 +108,45 @@ function __construct()
$tmp = $self.DIRECTORY_SEPARATOR.$HANDLERS_DIRECTORY;

//Core functions - now API independent
@require($tmp.DIRECTORY_SEPARATOR.'core_functions.php');
require($tmp.DIRECTORY_SEPARATOR.'core_functions.php');
//e107 class
@require($tmp.DIRECTORY_SEPARATOR.'e107_class.php');

$e107_paths = compact(
'ADMIN_DIRECTORY',
'FILES_DIRECTORY',
'IMAGES_DIRECTORY',
'THEMES_DIRECTORY',
'PLUGINS_DIRECTORY',
'HANDLERS_DIRECTORY',
'LANGUAGES_DIRECTORY',
'HELP_DIRECTORY',
'DOWNLOADS_DIRECTORY',
'UPLOADS_DIRECTORY',
'MEDIA_DIRECTORY',
'CACHE_DIRECTORY',
'LOGS_DIRECTORY',
'WEB_DIRECTORY',
'SYSTEM_DIRECTORY',
'CORE_DIRECTORY'
);

$e107 = e107::getInstance();

$e107->site_path = substr(md5($mySQLdefaultdb.".".$mySQLprefix),0,10);

$e107->prepare_request();
$e107->setDirs($e107_paths, varset($E107_CONFIG, array()));
$e107->set_constants();
$e107->set_paths();
$e107->file_path = $e107->fix_windows_paths($self)."/";
$e107->set_base_path();
$e107->set_request(false);

unset($tmp, $self);
$e107->set_urls(false);
require($tmp.DIRECTORY_SEPARATOR.'e107_class.php');

if(!class_exists('e107_config')) // old e107_config.php format.
{
$dirNames = ['ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'DOWNLOADS_DIRECTORY','UPLOADS_DIRECTORY','SYSTEM_DIRECTORY', 'MEDIA_DIRECTORY','CACHE_DIRECTORY','LOGS_DIRECTORY', 'CORE_DIRECTORY', 'WEB_DIRECTORY'];

$e107_paths = [];
foreach ($dirNames as $name)
{
if (isset($$name))
{
$e107_paths[$name] = $$name;
}
}

$sql_info = array_combine(array_map(function($k) {
return str_replace('mySQL', '', $k);
}, array_keys($legacy_sql_info)),
$legacy_sql_info
);
}
else // New e107_config.php format. v2.4+
{
$e107_paths = e107_config::paths();
$sql_info = e107_config::database();
$E107_CONFIG = e107_config::other() ?? [];
}

$e107 = e107::getInstance()->initCore($e107_paths, e_ROOT, $sql_info, varset($E107_CONFIG, array()));
// basic Admin area detection - required for proper path parsing
define('ADMIN', strpos(e_SELF, (e107::getFolder('admin')) != false || strpos(e_PAGE, 'admin') !== false));

// Next function call maintains behavior identical to before; might not be needed
// See https://github.com/e107inc/e107/issues/3033
$e107->set_urls_deferred();

$pref = $e107->getPref();
$pref = e107::getPref();


require_once(e_HANDLER."e_thumbnail_class.php");
Expand Down

0 comments on commit 63d3c07

Please sign in to comment.