Fix random content being replaced for widget output if skin path does not exist

This commit is contained in:
Kijin Sung 2021-04-12 22:48:05 +09:00
parent 06f23f3b3b
commit 827499bee3
2 changed files with 27 additions and 6 deletions

View file

@ -63,6 +63,24 @@ class TemplateHandler
return $oTemplate; return $oTemplate;
} }
/**
* Reset all instance properties to the default state.
*
* @return void
*/
protected function resetState()
{
$this->path = null;
$this->web_path = null;
$this->filename = null;
$this->file = null;
$this->compiled_file = null;
$this->config = new stdClass;
$this->skipTags = null;
$this->compiled_file = null;
self::$rootTpl = null;
}
/** /**
* set variables for template compile * set variables for template compile
* @param string $tpl_path * @param string $tpl_path
@ -76,6 +94,7 @@ class TemplateHandler
$tpl_path = trim(preg_replace('@^' . preg_quote(\RX_BASEDIR, '@') . '|\./@', '', str_replace('\\', '/', $tpl_path)), '/') . '/'; $tpl_path = trim(preg_replace('@^' . preg_quote(\RX_BASEDIR, '@') . '|\./@', '', str_replace('\\', '/', $tpl_path)), '/') . '/';
if($tpl_path === '/' || !is_dir($tpl_path)) if($tpl_path === '/' || !is_dir($tpl_path))
{ {
$this->resetState();
return; return;
} }
if(!file_exists(\RX_BASEDIR . $tpl_path . $tpl_filename) && file_exists(\RX_BASEDIR . $tpl_path . $tpl_filename . '.html')) if(!file_exists(\RX_BASEDIR . $tpl_path . $tpl_filename) && file_exists(\RX_BASEDIR . $tpl_path . $tpl_filename . '.html'))
@ -122,8 +141,8 @@ class TemplateHandler
// if target file does not exist exit // if target file does not exist exit
if(!$this->file || !file_exists($this->file)) if(!$this->file || !file_exists($this->file))
{ {
$tpl_path = str_replace('\\', '/', $tpl_path); $tpl_path = rtrim(str_replace('\\', '/', $tpl_path), '/') . '/';
$error_message = "Template not found: ${tpl_path}${tpl_filename}" . ($tpl_file ? " (${tpl_file})" : ''); $error_message = "Template not found: ${tpl_path}${tpl_filename}.html" . ($tpl_file ? " (${tpl_file})" : '');
trigger_error($error_message, \E_USER_WARNING); trigger_error($error_message, \E_USER_WARNING);
return escape($error_message); return escape($error_message);
} }
@ -145,7 +164,9 @@ class TemplateHandler
$tmpfilename = tempnam(sys_get_temp_dir(), 'rx-compiled'); $tmpfilename = tempnam(sys_get_temp_dir(), 'rx-compiled');
if($tmpfilename === false || Rhymix\Framework\Storage::write($tmpfilename, $buff) === false) if($tmpfilename === false || Rhymix\Framework\Storage::write($tmpfilename, $buff) === false)
{ {
return 'Fatal Error : Cannot create temporary file. Please check permissions.'; $error_message = 'Template compile failed: Cannot create temporary file. Please check permissions.';
trigger_error($error_message, \E_USER_WARNING);
return escape($error_message);
} }
$this->compiled_file = $tmpfilename; $this->compiled_file = $tmpfilename;
@ -189,8 +210,8 @@ class TemplateHandler
// if target file does not exist exit // if target file does not exist exit
if(!$this->file || !file_exists($this->file)) if(!$this->file || !file_exists($this->file))
{ {
$tpl_path = str_replace('\\', '/', $tpl_path); $tpl_path = rtrim(str_replace('\\', '/', $tpl_path), '/') . '/';
$error_message = "Template not found: ${tpl_path}${tpl_filename}"; $error_message = "Template not found: ${tpl_path}${tpl_filename}.html";
trigger_error($error_message, \E_USER_WARNING); trigger_error($error_message, \E_USER_WARNING);
return escape($error_message); return escape($error_message);
} }

View file

@ -736,7 +736,7 @@ class content extends WidgetHandler
function _compile($args,$content_items) function _compile($args,$content_items)
{ {
$oTemplate = &TemplateHandler::getInstance(); $oTemplate = TemplateHandler::getInstance();
// Set variables for widget // Set variables for widget
$widget_info = new stdClass(); $widget_info = new stdClass();
$widget_info->modules_info = $args->modules_info; $widget_info->modules_info = $args->modules_info;