Skip to content

Commit

Permalink
Merge pull request #4074 from Deltik/errors-galore
Browse files Browse the repository at this point in the history
Pass through PHP notices, warnings, and errors to test harness and fix resulting failures
  • Loading branch information
CaMer0n authored Jan 19, 2020
2 parents 34047a2 + f2a7590 commit 2487f58
Show file tree
Hide file tree
Showing 58 changed files with 5,399 additions and 6,214 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ jobs:
- name: Install PHP pdo_mysql extension
run: docker-php-ext-install pdo_mysql

- name: Install PHP mysqli extension
run: docker-php-ext-install mysqli

- uses: actions/checkout@v2

- name: Install Composer
Expand Down
19 changes: 8 additions & 11 deletions class2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* e107 website system
*
* Copyright (C) 2008-2010 e107 Inc (e107.org)
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
Expand Down Expand Up @@ -143,8 +143,8 @@
// D: Setup PHP error handling
// (Now we can see PHP errors) -- but note that DEBUG is not yet enabled!
//
global $error_handler;
$error_handler = new error_handler();
set_error_handler(array(&$error_handler, 'handle_error'));

//
// E: Setup other essential PHP parameters
Expand Down Expand Up @@ -391,7 +391,7 @@
// e107_require_once(e_HANDLER.'mysql_class.php');

//DEPRECATED, BC, $e107->sql caught by __get()
/** @var e_db_mysql $sql */
/** @var e_db $sql */
$sql = e107::getDb(); //TODO - find & replace $sql, $e107->sql
$sql->db_SetErrorReporting(false);

Expand Down Expand Up @@ -1418,12 +1418,6 @@ function systemTimeZoneIsValid($zone = '')
// ----------------------------------------------------------------------------
$sql->db_Mark_Time('Find/Load Theme');

if(e_ADMIN_AREA) // Load admin phrases ASAP
{
e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_admin.php');
}


if(!defined('THEME'))
{

Expand Down Expand Up @@ -2033,6 +2027,7 @@ function init_session()
define('USERNAME', 'e107-cli');
define('USERTHEME', false);
define('ADMIN', true);
define('ADMINPERMS', false);
define('GUEST', false);
define('USERCLASS', '');
define('USEREMAIL', '');
Expand Down Expand Up @@ -2418,8 +2413,8 @@ function force_userupdate($currentUser)
class error_handler
{

var $errors;
var $debug = false;
public $errors = [];
public $debug = false;
protected $xdebug = false;
protected $docroot = '';
protected $label = array();
Expand Down Expand Up @@ -2462,6 +2457,8 @@ function __construct()
{
error_reporting(E_ERROR | E_PARSE);
}

set_error_handler(array(&$this, 'handle_error'));
}

/**
Expand Down
8 changes: 0 additions & 8 deletions e107_admin/lancheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
require_once("../class2.php");
}

/*
if (!getperms("L"))
{
e107::redirect('admin');
exit;
}
*/

e107::coreLan('lancheck', true);

$e_sub_cat = 'language';
Expand Down
2 changes: 1 addition & 1 deletion e107_core/bbcodes/link.bb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ global $pref;
$parm .= ']';
}

list($link,$extras) = explode(" ",$parm);
list($link,$extras) = array_pad(explode(" ",$parm), 2, null);
if(!$parm) $link = $code_text;
Expand Down
21 changes: 11 additions & 10 deletions e107_core/shortcodes/single/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@ function navigation_shortcode($parm=null)
'alt6' => 6,
);


if(is_array($parm) && !empty($parm))
$category = 1;
$tmpl = 'main';
if (!is_array($parm))
{
$category = isset($types[$parm]) ? $types[$parm] : 1;
$tmpl = $parm ?: 'main';
}
elseif (!empty($parm))
{
$category = 1;
$tmpl = 'main';

if(!empty($parm['type']))
if (!empty($parm['type']))
{
$cat = $parm['type'];
$category = varset($types[$cat], 1);
}

if(!empty($parm['layout']))
if (!empty($parm['layout']))
{
$tmpl= $parm['layout'];
$tmpl = $parm['layout'];
}
}
else
{
$category = varset($types[$parm], 1);
$tmpl = vartrue($parm, 'main');
}

$nav = e107::getNav();

Expand Down
1 change: 1 addition & 0 deletions e107_handlers/bbcode_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ function imgToBBcode($html, $fromDB = false)
print_a($arr);
}

$arr['img'] = isset($arr['img']) && is_array($arr['img']) ? $arr['img'] : [];
foreach($arr['img'] as $img)
{
if(/*substr($img['src'],0,4) == 'http' ||*/ strpos($img['src'], e_IMAGE_ABS.'emotes/')!==false) // dont resize external images or emoticons.
Expand Down
4 changes: 2 additions & 2 deletions e107_handlers/core_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function array_diff_recursive($array1, $array2)

foreach($array1 as $key => $val)
{
if(array_key_exists($key, $array2))
if(is_array($array2) && array_key_exists($key, $array2))
{
if(is_array($val))
{
Expand Down Expand Up @@ -457,7 +457,7 @@ public function unserialize($sourceArrayData)

// e107::getDebug()->log("Json data found");

if(json_last_error() != JSON_ERROR_NONE && (e_DEBUG === true))
if(json_last_error() != JSON_ERROR_NONE && e_DEBUG === true && !e107::isCli())
{
echo "<div class='alert alert-danger'><h4>e107::unserialize() Parser Error (json)</h4></div>";
echo "<pre>";
Expand Down
2 changes: 1 addition & 1 deletion e107_handlers/date_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ function computeLapse($older_date, $newer_date = FALSE, $mode = FALSE, $show_sec
*/
public function strptime($str, $format)
{
if(STRPTIME_COMPAT !== TRUE && function_exists('strptime')) // Unix Only.
if(function_exists('strptime')) // Unix Only.
{
$vals = strptime($str,$format); // PHP5 is more accurate than below.
$vals['tm_amon'] = strftime('%b', mktime(0,0,0, $vals['tm_mon'] +1) );
Expand Down
6 changes: 4 additions & 2 deletions e107_handlers/db_verify_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ private function load()
*/
private function diffStructurePermissive($expected, $actual)
{
$expected['default'] = isset($expected['default']) ? $expected['default'] : '';
$actual['default'] = isset($actual['default']) ? $actual['default'] : '';

if($expected['type'] === 'JSON') // Fix for JSON alias MySQL 5.7+
{
$expected['type'] = 'LONGTEXT';
}


// Permit actual text types that default to null even when
// expected does not explicitly default to null
if(0 === strcasecmp($expected['type'], $actual['type']) &&
Expand Down Expand Up @@ -410,7 +412,7 @@ public function prepareResults($tbl, $selection, $sqlData, $fileData)
{
$this->{$results}[$tbl][$key]['_status'] = 'ok';

if(!is_array($sqlData[$type][$key]))
if(!isset($sqlData[$type][$key]) || !is_array($sqlData[$type][$key]))
{
$this->errors[$tbl]['_status'] = 'error'; // table status
$this->{$results}[$tbl][$key]['_status'] = "missing_$type"; // type status
Expand Down
2 changes: 1 addition & 1 deletion e107_handlers/debug_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
define('E107_DEBUG_LEVEL', $e107_debug_level);
}
}
else
elseif (!defined('E107_DEBUG_LEVEL'))
{
define('E107_DEBUG_LEVEL', 0);
}
Expand Down
49 changes: 38 additions & 11 deletions e107_handlers/e107_class.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,12 @@ protected function _init($e107_paths, $e107_root_path, $e107_config_mysql_info,

if(!is_dir(e_SYSTEM))
{
mkdir(e_SYSTEM, 0755);
mkdir(e_SYSTEM, 0755, true);
}

if(!is_dir(e_CACHE_IMAGE))
{
mkdir(e_CACHE_IMAGE, 0755);
mkdir(e_CACHE_IMAGE, 0755, true);
}

// Prepare essential directories.
Expand Down Expand Up @@ -2821,7 +2821,7 @@ public static function getCoreTemplate($id, $key = null, $override = true, $merg
*/
public static function getTemplate($plug_name, $id = null, $key = null, $override = true, $merge = false, $info = false)
{
if(null === $plug_name)
if(!$plug_name)
{
return self::getCoreTemplate($id, $key, $override, $merge, $info);
}
Expand All @@ -2837,6 +2837,15 @@ public static function getTemplate($plug_name, $id = null, $key = null, $overrid
self::getMessage()->addDebug( "Attempting to load Template File: ".$path );
}

/**
* "front" and "global" LANs might not be loaded come self::_getTemplate(),
* so the following calls to self::plugLan() fix that.
*/
self::plugLan($plug_name, null, true);
self::plugLan($plug_name, null, false);
self::plugLan($plug_name, 'global', true);
self::plugLan($plug_name, 'global', false);

$id = str_replace('/', '_', $id);
$ret = self::_getTemplate($id, $key, $reg_path, $path, $info);

Expand Down Expand Up @@ -3145,6 +3154,11 @@ public static function includeLan($path, $force = false)
*/
public static function coreLan($fname, $admin = false)
{
if ($admin)
{
e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_admin.php');
}

$cstring = 'corelan/'.e_LANGUAGE.'_'.$fname.($admin ? '_admin' : '_front');
if(self::getRegistry($cstring)) return;

Expand Down Expand Up @@ -3545,7 +3559,7 @@ public static function url($plugin = '', $key = null, $row = array(), $options =

// Avoid duplicate query keys. eg. URL has ?id=x and $options['query']['id'] exists.
// @see forum/e_url.php - topic/redirect and forum/view_shortcodes.php sc_post_url()
list($legacyUrl, $tmp) = explode("?", $legacyUrl);
list($legacyUrl, $tmp) = array_pad(explode("?", $legacyUrl), 2, null);

if (!empty($tmp))
{
Expand Down Expand Up @@ -3852,7 +3866,12 @@ public function prepare_request($checkS = true)
if(isset($GLOBALS['_E107']) && is_array($GLOBALS['_E107'])) $this->_E107 = & $GLOBALS['_E107'];

// remove ajax_used=1 from query string to avoid SELF problems, ajax should always be detected via e_AJAX_REQUEST constant
$_SERVER['QUERY_STRING'] = trim(str_replace(array('ajax_used=1', '&&'), array('', '&'), $_SERVER['QUERY_STRING']), '&');
$_SERVER['QUERY_STRING'] = trim(
str_replace(
array('ajax_used=1', '&&'),
array('', '&'),
(isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '')
), '&');

/* PathInfo doesn't break anything, URLs should be always absolute. Disabling the below forever.
// e107 uses relative url's, which are broken by "pretty" URL's. So for now we don't support / after .php
Expand Down Expand Up @@ -4100,13 +4119,16 @@ public function set_constants()
$subdomain = false;

// Define the domain name and subdomain name.
if(is_numeric(str_replace(".","",$_SERVER['HTTP_HOST'])))
if (is_numeric(str_replace(".", "",
(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')
)))
{
$domain = false;
$subdomain = false;
}
else
{
$_SERVER['SERVER_NAME'] = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
$host = !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$domain = preg_replace('/^www\.|:\d*$/', '', $host); // remove www. and port numbers.

Expand Down Expand Up @@ -4182,9 +4204,12 @@ public function set_paths()
{
// ssl_enabled pref not needed anymore, scheme is auto-detected
$this->HTTP_SCHEME = 'http';
if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443)
if (
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ||
(!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)
)
{
$this->HTTP_SCHEME = 'https';
$this->HTTP_SCHEME = 'https';
}

$path = ""; $i = 0;
Expand Down Expand Up @@ -4232,6 +4257,7 @@ public function set_paths()


$this->relative_base_path = (!self::isCli()) ? $path : e_ROOT;
$_SERVER['HTTP_HOST'] = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
$this->http_path = filter_var("http://{$_SERVER['HTTP_HOST']}{$this->server_path}", FILTER_SANITIZE_URL);
$this->https_path = filter_var("https://{$_SERVER['HTTP_HOST']}{$this->server_path}", FILTER_SANITIZE_URL);

Expand Down Expand Up @@ -4259,11 +4285,11 @@ public function set_paths()
}

//BC temporary fixes
if (!isset($this->e107_dirs['UPLOADS_SERVER']) && $this->e107_dirs['UPLOADS_DIRECTORY']{0} == "/")
if (!isset($this->e107_dirs['UPLOADS_SERVER']) && $this->e107_dirs['UPLOADS_DIRECTORY'][0] == "/")
{
$this->e107_dirs['UPLOADS_SERVER'] = $this->e107_dirs['UPLOADS_DIRECTORY'];
}
if (!isset($this->e107_dirs['DOWNLOADS_SERVER']) && $this->e107_dirs['DOWNLOADS_DIRECTORY']{0} == "/")
if (!isset($this->e107_dirs['DOWNLOADS_SERVER']) && $this->e107_dirs['DOWNLOADS_DIRECTORY'][0] == "/")
{
$this->e107_dirs['DOWNLOADS_SERVER'] = $this->e107_dirs['DOWNLOADS_DIRECTORY'];
}
Expand Down Expand Up @@ -4518,6 +4544,7 @@ public function set_urls($no_cbrace = true)
$isPluginDir = strpos($_self,'/'.$PLUGINS_DIRECTORY) !== FALSE; // True if we're in a plugin
$e107Path = str_replace($this->base_path, '', $_self); // Knock off the initial bits
$curPage = basename($_SERVER['SCRIPT_FILENAME']);
$_SERVER['REQUEST_URI'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';

if (
(!$isPluginDir && strpos($e107Path, $ADMIN_DIRECTORY) === 0 ) // Core admin directory
Expand Down Expand Up @@ -5088,7 +5115,7 @@ public function __get($name)
break;
}

$this->{$name} = $ret;
$this->$name = $ret;
return $ret;
}

Expand Down
Loading

0 comments on commit 2487f58

Please sign in to comment.