mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 17:21:39 +09:00
Fix conversion of paths relative to the Rhymix install directory
This commit is contained in:
parent
5899845b1d
commit
f2fabab239
1 changed files with 44 additions and 31 deletions
|
|
@ -824,7 +824,7 @@ class TemplateParser_v2
|
|||
if (preg_match('#^([a-z0-9_-]+):(.+)$#', $filter, $m))
|
||||
{
|
||||
$filter = $m[1];
|
||||
$filter_option = $m[2];
|
||||
$filter_option = strtr($m[2], ['\|' => '|']);
|
||||
if (!preg_match('#^\$#', $filter_option) && !preg_match('#^([\'"]).*\1$#', $filter_option))
|
||||
{
|
||||
$filter_option = "'" . escape_sqstr($filter_option) . "'";
|
||||
|
|
@ -838,7 +838,6 @@ class TemplateParser_v2
|
|||
// Apply each filter.
|
||||
switch ($filter)
|
||||
{
|
||||
case 'autocontext':
|
||||
case 'autoescape':
|
||||
case 'autolang':
|
||||
case 'escape':
|
||||
|
|
@ -938,34 +937,6 @@ class TemplateParser_v2
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert variable scope.
|
||||
*
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
protected function _convertVariableScope(string $content): string
|
||||
{
|
||||
// Replace variables that need to be enclosed in curly braces, using temporary entities to prevent double-replacement.
|
||||
$content = preg_replace_callback('#(?<!\$__Context)->\$([a-zA-Z_][a-zA-Z0-9_]*)#', function($match) {
|
||||
return '->' . self::_escapeCurly('{') . '$__Context->' . $match[1] . self::_escapeCurly('}');
|
||||
}, $content);
|
||||
|
||||
// Replace all other variables with Context attributes.
|
||||
$content = preg_replace_callback('#(?<!::|\\\\|\$__Context->|\')\$([a-zA-Z_][a-zA-Z0-9_]*)#', function($match) {
|
||||
if (preg_match('/^(?:GLOBALS|_SERVER|_COOKIE|_ENV|_GET|_POST|_REQUEST|_SESSION|__Context|this)$/', $match[1]))
|
||||
{
|
||||
return '$' . $match[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return '$__Context->' . $match[1];
|
||||
}
|
||||
}, $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Postprocessing.
|
||||
*
|
||||
|
|
@ -1026,7 +997,21 @@ class TemplateParser_v2
|
|||
*/
|
||||
protected static function _convertRelativePath(string $path, string $basepath): string
|
||||
{
|
||||
$path = preg_replace('#/\./#', '/', $basepath . $path);
|
||||
// Path relative to the Rhymix installation directory?
|
||||
if (preg_match('#^\^/?(\w.+)$#s', $path, $match))
|
||||
{
|
||||
$path = \RX_BASEURL . $match[1];
|
||||
}
|
||||
|
||||
// Other paths will be relative to the given basepath.
|
||||
else
|
||||
{
|
||||
$path = preg_replace('#/\./#', '/', $basepath . $path);
|
||||
}
|
||||
|
||||
// Remove extra slashes and parent directory references.
|
||||
$path = preg_replace('#\\\\#', '/', $path);
|
||||
$path = preg_replace('#//#', '/', $path);
|
||||
while (($tmp = preg_replace('#/[^/]+/\.\./#', '/', $path)) !== $path)
|
||||
{
|
||||
$path = $tmp;
|
||||
|
|
@ -1034,6 +1019,34 @@ class TemplateParser_v2
|
|||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert variable scope.
|
||||
*
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
protected function _convertVariableScope(string $content): string
|
||||
{
|
||||
// Replace variables that need to be enclosed in curly braces, using temporary entities to prevent double-replacement.
|
||||
$content = preg_replace_callback('#(?<!\$__Context)->\$([a-zA-Z_][a-zA-Z0-9_]*)#', function($match) {
|
||||
return '->' . self::_escapeCurly('{') . '$__Context->' . $match[1] . self::_escapeCurly('}');
|
||||
}, $content);
|
||||
|
||||
// Replace all other variables with Context attributes.
|
||||
$content = preg_replace_callback('#(?<!::|\\\\|\$__Context->|\')\$([a-zA-Z_][a-zA-Z0-9_]*)#', function($match) {
|
||||
if (preg_match('/^(?:GLOBALS|_SERVER|_COOKIE|_ENV|_GET|_POST|_REQUEST|_SESSION|__Context|this)$/', $match[1]))
|
||||
{
|
||||
return '$' . $match[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return '$__Context->' . $match[1];
|
||||
}
|
||||
}, $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attributes of an HTML tag as an associative array.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue