Various fixes to remove warnings in PHP 8.0

This commit is contained in:
Kijin Sung 2020-12-15 00:18:42 +09:00
parent 9a0bf6d907
commit 49923844b2
36 changed files with 271 additions and 176 deletions

View file

@ -123,7 +123,7 @@ class HTMLDisplayHandler
// get the layout information currently requested
$oLayoutModel = getModel('layout');
$layout_info = Context::get('layout_info');
$layout_srl = $layout_info->layout_srl;
$layout_srl = $layout_info->layout_srl ?? 0;
// compile if connected to the layout
if($layout_srl > 0)
@ -403,7 +403,7 @@ class HTMLDisplayHandler
{
return '';
}
if($matches[3])
if($matches[3] ?? false)
{
$vars = Context::get(str_replace('?$__Context->', '', $matches[3]));
Context::loadFile(array($matches[2], null, null, null, $vars));

View file

@ -168,22 +168,22 @@ class FrontEndFileHandler extends Handler
$file = new stdClass();
$file->fileName = $pathInfo['basename'];
$file->filePath = $this->_getAbsFileUrl($pathInfo['dirname']);
$file->fileRealPath = FileHandler::getRealPath($pathInfo['dirname']);
$file->fileFullPath = $file->fileRealPath . '/' . $pathInfo['basename'];
$file->fileExtension = strtolower($pathInfo['extension']);
$file->filePath = $this->_getAbsFileUrl($pathInfo['dirname'] ?? '');
$file->fileRealPath = FileHandler::getRealPath($pathInfo['dirname'] ?? '');
$file->fileFullPath = $file->fileRealPath . '/' . ($pathInfo['basename'] ?? '');
$file->fileExtension = strtolower($pathInfo['extension'] ?? '');
if (($pos = strpos($file->fileExtension, '?')) !== false)
{
$file->fileExtension = substr($file->fileExtension, 0, $pos);
}
if (preg_match('/^(.+)\.min$/', $pathInfo['filename'], $matches))
if (preg_match('/^(.+)\.min$/', $pathInfo['filename'] ?? '', $matches))
{
$file->fileNameNoExt = $matches[1];
$file->isMinified = true;
}
else
{
$file->fileNameNoExt = $pathInfo['filename'];
$file->fileNameNoExt = $pathInfo['filename'] ?? '';
$file->isMinified = false;
}
$file->isExternalURL = preg_match('@^(https?:)?//@i', $file->filePath) ? true : false;
@ -194,7 +194,7 @@ class FrontEndFileHandler extends Handler
$file->isCachedScript = !$file->isExternalURL && strpos($file->filePath, 'files/cache/') !== false;
$file->isCommon = $isCommon;
$file->keyName = $file->fileNameNoExt . '.' . $file->fileExtension;
$file->cdnPath = $this->_normalizeFilePath($pathInfo['dirname']);
$file->cdnPath = $this->_normalizeFilePath($pathInfo['dirname'] ?? '');
$file->vars = (array)$vars;
// Fix incorrectly minified URL
@ -625,7 +625,8 @@ class FrontEndFileHandler extends Handler
*/
protected function _normalizeFilePath($path)
{
if(strpos($path, '://') === FALSE && $path[0] != '/' && $path[0] != '.')
$path = strval($path);
if(!preg_match('!://!', $path) && !preg_match('!^[/.]!', $path))
{
$path = './' . $path;
}
@ -635,7 +636,6 @@ class FrontEndFileHandler extends Handler
}
$path = preg_replace('@/\./|(?<!:)\/\/@', '/', $path);
while(strpos($path, '/../'))
{
$path = preg_replace('/\/([^\/]+)\/\.\.\//s', '/', $path, 1);

View file

@ -335,9 +335,9 @@ class ModuleHandler extends Handler
}
// get type, kind
$type = $xml_info->action->{$this->act}->type;
$ruleset = $xml_info->action->{$this->act}->ruleset;
$meta_noindex = $xml_info->action->{$this->act}->meta_noindex;
$type = $xml_info->action->{$this->act}->type ?? null;
$ruleset = $xml_info->action->{$this->act}->ruleset ?? null;
$meta_noindex = $xml_info->action->{$this->act}->meta_noindex ?? null;
$kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : '';
if ($meta_noindex === 'true')
{
@ -995,16 +995,16 @@ class ModuleHandler extends Handler
$viewType = $this->is_mobile ? 'M' : 'P';
if($viewType === 'M')
{
$layout_srl = $oModule->module_info->mlayout_srl;
$layout_srl = $oModule->module_info->mlayout_srl ?? 0;
if($layout_srl == -2)
{
$layout_srl = $oModule->module_info->layout_srl;
$layout_srl = $oModule->module_info->layout_srl ?? 0;
$viewType = 'P';
}
}
else
{
$layout_srl = $oModule->module_info->layout_srl;
$layout_srl = $oModule->module_info->layout_srl ?? 0;
}
// if layout_srl is rollback by module, set default layout

View file

@ -63,7 +63,7 @@ class Security
}
elseif($varName0)
{
$var = $is_object ? $this->_targetVar->{$varName0} : $this->_targetVar[$varName0];
$var = $is_object ? ($this->_targetVar->{$varName0} ?? null) : ($this->_targetVar[$varName0] ?? null);
}
else
{
@ -131,7 +131,7 @@ class Security
if(strlen($name0))
{
$target = $is_object ? $var->{$name0} : $var[$name0];
$target = $is_object ? ($var->{$name0} ?? null) : ($var[$name0] ?? null);
$target = $this->_encodeHTML($target, $name);
if($target === false)

View file

@ -267,7 +267,7 @@ class TemplateHandler
* preg_replace_callback handler
* 1. remove ruleset from form tag
* 2. add hidden tag with ruleset value
* 3. if empty default hidden tag, generate hidden tag (ex:mid, vid, act...)
* 3. if empty default hidden tag, generate hidden tag (ex:mid, act...)
* 4. generate return url, return url use in server side validator
* @param array $matches
* @return string
@ -278,7 +278,7 @@ class TemplateHandler
if($matches[1])
{
preg_match('/ruleset="([^"]*?)"/is', $matches[1], $m);
if($m[0])
if(isset($m[0]) && $m[0])
{
$matches[1] = preg_replace('/' . addcslashes($m[0], '?$') . '/i', '', $matches[1]);
@ -286,6 +286,7 @@ class TemplateHandler
{
$path = str_replace('@', '', $m[1]);
$path = './files/ruleset/' . $path . '.xml';
$autoPath = '';
}
else if(strpos($m[1], '#') !== FALSE)
{
@ -304,6 +305,7 @@ class TemplateHandler
{
$module_path = $mm[1];
$path = $module_path . '/ruleset/' . $m[1] . '.xml';
$autoPath = '';
}
$matches[2] = '<input type="hidden" name="ruleset" value="' . $m[1] . '" />' . $matches[2];
@ -313,15 +315,15 @@ class TemplateHandler
}
// if not exists default hidden tag, generate hidden tag
preg_match_all('/<input[^>]* name="(act|mid|vid)"/is', $matches[2], $m2);
$checkVar = array('act', 'mid', 'vid');
preg_match_all('/<input[^>]* name="(act|mid)"/is', $matches[2], $m2);
$checkVar = array('act', 'mid');
$resultArray = array_diff($checkVar, $m2[1]);
if(is_array($resultArray))
{
$generatedHidden = '';
foreach($resultArray AS $key => $value)
{
$generatedHidden .= '<input type="hidden" name="' . $value . '" value="<?php echo $__Context->' . $value . ' ?>" />';
$generatedHidden .= '<input type="hidden" name="' . $value . '" value="<?php echo $__Context->' . $value . ' ?? \'\'; ?>" />';
}
$matches[2] = $generatedHidden . $matches[2];
}
@ -330,7 +332,7 @@ class TemplateHandler
if(!preg_match('/no-error-return-url="true"/i', $matches[1]))
{
preg_match('/<input[^>]*name="error_return_url"[^>]*>/is', $matches[2], $m3);
if(!$m3[0])
if(!isset($m3[0]) || !$m3[0])
$matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo escape(getRequestUriByServerEnviroment(), false); ?>" />' . $matches[2];
}
else
@ -466,17 +468,17 @@ class TemplateHandler
{
$expr_m[1] = trim($expr_m[1]);
$expr_m[2] = trim($expr_m[2]);
if($expr_m[3])
if(isset($expr_m[3]) && $expr_m[3])
{
$expr_m[2] .= '=>' . trim($expr_m[3]);
}
$nodes[$idx - 1] .= sprintf('<?php if(%1$s)foreach(%1$s as %2$s){ ?>', $expr_m[1], $expr_m[2]);
}
elseif($expr_m[4])
elseif(isset($expr_m[4]) && $expr_m[4])
{
$nodes[$idx - 1] .= "<?php for({$expr_m[4]}){ ?>";
}
elseif($expr_m[5])
elseif(isset($expr_m[5]) && $expr_m[5])
{
$nodes[$idx - 1] .= "<?php while({$expr_m[5]}={$expr_m[6]}){ ?>";
}
@ -759,6 +761,7 @@ class TemplateHandler
case 'load':
case 'unload':
$metafile = '';
$metavars = '';
$replacements = HTMLDisplayHandler::$replacements;
$attr['target'] = preg_replace(array_keys($replacements), array_values($replacements), $attr['target']);
$pathinfo = pathinfo($attr['target']);
@ -807,8 +810,10 @@ class TemplateHandler
}
else
{
$metafile = $attr['target'];
$result = "\$__tmp=array('{$attr['target']}','{$attr['type']}','{$attr['targetie']}','{$attr['index']}');Context::loadFile(\$__tmp);unset(\$__tmp);";
$metafile = isset($attr['target']) ? $attr['target'] : '';
$result = vsprintf("Context::loadFile(['%s', '%s', '%s', '%s']);", [
$attr['target'] ?? '', $attr['type'] ?? '', $attr['targetie'] ?? '', $attr['index'] ?? '',
]);
}
break;
case 'css':