mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 13:17:24 +02:00
Performance: Reduced e107::getFolder() usage from 2500+ to less than 30.
This commit is contained in:
@@ -66,6 +66,9 @@ class e_parse extends e_parser
|
|||||||
|
|
||||||
protected $staticUrl = null;
|
protected $staticUrl = null;
|
||||||
|
|
||||||
|
/** @var array Stored relative paths - used by replaceConstants() */
|
||||||
|
private $relativePaths = array();
|
||||||
|
|
||||||
|
|
||||||
// BBcode that contain preformatted code.
|
// BBcode that contain preformatted code.
|
||||||
private $preformatted = array('html', 'markdown');
|
private $preformatted = array('html', 'markdown');
|
||||||
@@ -3296,11 +3299,15 @@ class e_parse extends e_parser
|
|||||||
return $new;
|
return $new;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($mode != '')
|
|
||||||
|
if(!empty($mode))
|
||||||
{
|
{
|
||||||
$e107 = e107::getInstance();
|
$e107 = e107::getInstance();
|
||||||
|
|
||||||
$replace_relative = array(
|
if(empty($this->relativePaths)) // prevent multiple lookups.
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->relativePaths = array(
|
||||||
$e107::getFolder('media_files'),
|
$e107::getFolder('media_files'),
|
||||||
$e107::getFolder('media_video'),
|
$e107::getFolder('media_video'),
|
||||||
$e107::getFolder('media_image'),
|
$e107::getFolder('media_image'),
|
||||||
@@ -3327,6 +3334,9 @@ class e_parse extends e_parser
|
|||||||
$e107::getFolder('core'),
|
$e107::getFolder('core'),
|
||||||
$e107::getFolder('system'),
|
$e107::getFolder('system'),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$replace_relative = $this->relativePaths;
|
||||||
|
|
||||||
switch ($mode)
|
switch ($mode)
|
||||||
{
|
{
|
||||||
@@ -3815,8 +3825,8 @@ class e_parse extends e_parser
|
|||||||
* Cameron's DOM-based parser.
|
* Cameron's DOM-based parser.
|
||||||
*
|
*
|
||||||
* @method replaceConstants($text, $mode = '', $all = false)
|
* @method replaceConstants($text, $mode = '', $all = false)
|
||||||
* @method toAttribute($title)
|
* @method toAttribute($text)
|
||||||
* @method thumbUrl($icon)
|
* @method thumbUrl($url)
|
||||||
* @method thumbDimensions()
|
* @method thumbDimensions()
|
||||||
*/
|
*/
|
||||||
class e_parser
|
class e_parser
|
||||||
|
@@ -505,10 +505,30 @@ while($row = $sql->fetch())
|
|||||||
*/
|
*/
|
||||||
public function testReplaceConstants()
|
public function testReplaceConstants()
|
||||||
{
|
{
|
||||||
$actual = $this->tp->replaceConstants('{e_BASE}news','abs');
|
$tests = array(
|
||||||
|
0 => array(
|
||||||
|
'path' => '{e_BASE}news',
|
||||||
|
'type' => 'abs',
|
||||||
|
'match' => e_HTTP,
|
||||||
|
),
|
||||||
|
1 => array(
|
||||||
|
'path' => '{e_BASE}news.php',
|
||||||
|
'type' => 'full',
|
||||||
|
'match' => 'https://localhost/e107/news.php',
|
||||||
|
),
|
||||||
|
2 => array(
|
||||||
|
'path' => '{e_PLUGIN}news/index.php',
|
||||||
|
'type' => null,
|
||||||
|
'match' => 'e107_plugins/news/index.php',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertStringContainsString(e_HTTP,$actual);
|
|
||||||
|
|
||||||
|
foreach($tests as $var)
|
||||||
|
{
|
||||||
|
$actual = $this->tp->replaceConstants($var['path'],$var['type']);
|
||||||
|
$this->assertStringContainsString($var['match'], $actual);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user