mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 22:27:34 +02:00
toHTML modifiers extracted to new method.
This commit is contained in:
@@ -332,8 +332,7 @@ class e_parse
|
|||||||
*/
|
*/
|
||||||
public function setMultibyte($bool)
|
public function setMultibyte($bool)
|
||||||
{
|
{
|
||||||
// var_dump(e_LAN);
|
|
||||||
// var_dump(e_LANGUAGE);
|
|
||||||
if($bool === false)
|
if($bool === false)
|
||||||
{
|
{
|
||||||
$this->multibyte = false;
|
$this->multibyte = false;
|
||||||
@@ -1072,7 +1071,6 @@ class e_parse
|
|||||||
* @param string $ending It will be used as Ending and appended to the trimmed string.
|
* @param string $ending It will be used as Ending and appended to the trimmed string.
|
||||||
* @param boolean $exact If false, $text will not be cut mid-word
|
* @param boolean $exact If false, $text will not be cut mid-word
|
||||||
* @return string Trimmed string.
|
* @return string Trimmed string.
|
||||||
* @todo find a modern replacement
|
|
||||||
*/
|
*/
|
||||||
public function html_truncate($text, $length = 100, $ending = '...', $exact = true)
|
public function html_truncate($text, $length = 100, $ending = '...', $exact = true)
|
||||||
{
|
{
|
||||||
@@ -1355,42 +1353,7 @@ class e_parse
|
|||||||
global $fromadmin;
|
global $fromadmin;
|
||||||
|
|
||||||
// Set default modifiers to start
|
// Set default modifiers to start
|
||||||
$opts = $this->e_optDefault;
|
$opts = $this->getModifiers($modifiers);
|
||||||
|
|
||||||
|
|
||||||
// Now process any modifiers that are specified
|
|
||||||
if($modifiers)
|
|
||||||
{
|
|
||||||
$aMods = explode(',', $modifiers);
|
|
||||||
|
|
||||||
// If there's a supermodifier, it must be first, and in uppercase
|
|
||||||
$psm = trim($aMods[0]);
|
|
||||||
if(isset($this->e_SuperMods[$psm]))
|
|
||||||
{
|
|
||||||
// Supermodifier found - override default values where necessary
|
|
||||||
$opts = array_merge($opts, $this->e_SuperMods[$psm]);
|
|
||||||
$opts['context'] = $psm;
|
|
||||||
unset($aMods[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now find any regular modifiers; use them to modify the context
|
|
||||||
// (there should only be one or two out of the list of possibles)
|
|
||||||
foreach($aMods as $mod)
|
|
||||||
{
|
|
||||||
// Slight concession to varying coding styles - stripping spaces is a waste of CPU cycles!
|
|
||||||
$mod = trim($mod);
|
|
||||||
if(isset($this->e_Modifiers[$mod]))
|
|
||||||
{
|
|
||||||
// This is probably quicker than array_merge
|
|
||||||
// - especially as usually only one or two loops
|
|
||||||
foreach($this->e_Modifiers[$mod] as $k => $v)
|
|
||||||
{
|
|
||||||
// Update our context-specific options
|
|
||||||
$opts[$k] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Turn off a few things if not enabled in options
|
// Turn off a few things if not enabled in options
|
||||||
if(empty($pref['smiley_activate']))
|
if(empty($pref['smiley_activate']))
|
||||||
@@ -1434,12 +1397,12 @@ class e_parse
|
|||||||
{
|
{
|
||||||
$text = strip_tags($text);
|
$text = strip_tags($text);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if(MAGIC_QUOTES_GPC === true) // precaution for badly saved data.
|
if(MAGIC_QUOTES_GPC === true) // precaution for badly saved data.
|
||||||
{
|
{
|
||||||
$text = stripslashes($text);
|
$text = stripslashes($text);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Make sure we have a valid count for word wrapping
|
// Make sure we have a valid count for word wrapping
|
||||||
if(!$wrap && !empty($pref['main_wordwrap']))
|
if(!$wrap && !empty($pref['main_wordwrap']))
|
||||||
@@ -1484,6 +1447,7 @@ class e_parse
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Set the options for this pass
|
// Set the options for this pass
|
||||||
|
|
||||||
$opts = $saveOpts;
|
$opts = $saveOpts;
|
||||||
|
|
||||||
// Have to have a good test in case a 'non-key' bbcode starts the block
|
// Have to have a good test in case a 'non-key' bbcode starts the block
|
||||||
@@ -1501,34 +1465,21 @@ class e_parse
|
|||||||
// $matches[5] - closing tag
|
// $matches[5] - closing tag
|
||||||
// In case we decide to load a file
|
// In case we decide to load a file
|
||||||
|
|
||||||
$bbPath = e_CORE . 'bbcodes/';
|
// $bbPath = e_CORE . 'bbcodes/';
|
||||||
$bbFile = strtolower(str_replace('_', '', $matches[2]));
|
// $bbFile = strtolower(str_replace('_', '', $matches[2]));
|
||||||
$bbcode = '';
|
// $bbcode = '';
|
||||||
$className = '';
|
// $className = '';
|
||||||
$full_text = '';
|
$full_text = '';
|
||||||
$code_text = $matches[4];
|
$code_text = $matches[4];
|
||||||
$parm = $matches[3] ? substr($matches[3], 1) : '';
|
// $parm = $matches[3] ? substr($matches[3], 1) : '';
|
||||||
$last_bbcode = $matches[2];
|
$last_bbcode = $matches[2];
|
||||||
|
|
||||||
switch($matches[2])
|
switch($matches[2])
|
||||||
{
|
{
|
||||||
case 'php' :
|
case 'php' :
|
||||||
// Probably run the output through the normal processing functions - but put here so the PHP code can disable if desired
|
|
||||||
$proc_funcs = true;
|
|
||||||
|
|
||||||
// This is just the contents of the php.bb file pulled in - its short, so will be quicker
|
$proc_funcs = false;
|
||||||
// $search = array(""", "'", "$", '<br />', E_NL, "->", "<br />");
|
$code_text = '';
|
||||||
// $replace = array('"', "'", "$", "\n", "\n", "->", "<br />");
|
|
||||||
// Shouldn't have any parameter on this bbcode
|
|
||||||
// Not sure whether checks are necessary now we've reorganised
|
|
||||||
// if (!$matches[3]) $bbcode = str_replace($search, $replace, $matches[4]);
|
|
||||||
// Because we're bypassing most of the initial parser processing, we should be able to just reverse the effects of toDB() and execute the code
|
|
||||||
// [SecretR] - avoid php code injections, missing php.bb will completely disable user posted php blocks
|
|
||||||
$bbcode = file_get_contents($bbPath . $bbFile . '.bb');
|
|
||||||
if(!$matches[3])
|
|
||||||
{
|
|
||||||
$code_text = html_entity_decode($matches[4], ENT_QUOTES, 'UTF-8');
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'html' : // This overrides and deprecates html.bb
|
case 'html' : // This overrides and deprecates html.bb
|
||||||
@@ -1560,40 +1511,13 @@ class e_parse
|
|||||||
case 'hide' :
|
case 'hide' :
|
||||||
$proc_funcs = true;
|
$proc_funcs = true;
|
||||||
|
|
||||||
default : // Most bbcodes will just execute their normal file
|
case 'scode':
|
||||||
// @todo should we cache these bbcodes? require_once should make class-related codes quite efficient
|
case 'code' :
|
||||||
if(file_exists($bbPath . 'bb_' . $bbFile . '.php'))
|
$parseBB = false;
|
||||||
{ // Its a bbcode class file
|
$full_text = $this->parseBBcodes('['.$last_bbcode.']'.$code_text.'[/'.$last_bbcode.']', $postID);
|
||||||
require_once($bbPath . 'bb_' . $bbFile . '.php');
|
break;
|
||||||
$className = 'bb_' . $last_bbcode;
|
|
||||||
|
|
||||||
$this->bbList[$last_bbcode] = new $className();
|
|
||||||
}
|
|
||||||
elseif(file_exists($bbPath . $bbFile . '.bb'))
|
|
||||||
{
|
|
||||||
$bbcode = file_get_contents($bbPath . $bbFile . '.bb');
|
|
||||||
}
|
|
||||||
} // end - switch ($matches[2])
|
|
||||||
|
|
||||||
if($className)
|
|
||||||
{
|
|
||||||
/** @var e_bb_base $tempCode */
|
|
||||||
$tempCode = new $className();
|
|
||||||
|
|
||||||
$full_text = $tempCode->bbPreDisplay($matches[4], $parm);
|
|
||||||
}
|
|
||||||
elseif($bbcode)
|
|
||||||
{ // Execute the file
|
|
||||||
$full_text = eval($bbcode); // Require output of bbcode to be returned
|
|
||||||
// added to remove possibility of nested bbcode exploits ...
|
|
||||||
// (same as in bbcode_handler - is it right that it just operates on $bbcode_return and not on $bbcode_output? - QUERY XXX-02
|
|
||||||
}
|
|
||||||
if(strpos($full_text, '[') !== false)
|
|
||||||
{
|
|
||||||
$exp_search = array('eval', 'expression');
|
|
||||||
$exp_replace = array('ev<b></b>al', 'expres<b></b>sion');
|
|
||||||
$bbcode_return = str_replace($exp_search, $exp_replace, $full_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5384,6 +5308,53 @@ class e_parse
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $modifiers
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getModifiers($modifiers)
|
||||||
|
{
|
||||||
|
$opts = $this->e_optDefault;
|
||||||
|
|
||||||
|
if(empty($modifiers))
|
||||||
|
{
|
||||||
|
return $opts;
|
||||||
|
}
|
||||||
|
// Now process any modifiers that are specified
|
||||||
|
$aMods = explode(',', $modifiers);
|
||||||
|
|
||||||
|
// If there's a supermodifier, it must be first, and in uppercase
|
||||||
|
$psm = trim($aMods[0]);
|
||||||
|
if(isset($this->e_SuperMods[$psm]))
|
||||||
|
{
|
||||||
|
// Supermodifier found - override default values where necessary
|
||||||
|
$opts = array_merge($opts, $this->e_SuperMods[$psm]);
|
||||||
|
$opts['context'] = $psm;
|
||||||
|
unset($aMods[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now find any regular modifiers; use them to modify the context
|
||||||
|
// (there should only be one or two out of the list of possibles)
|
||||||
|
foreach($aMods as $mod)
|
||||||
|
{
|
||||||
|
// Slight concession to varying coding styles - stripping spaces is a waste of CPU cycles!
|
||||||
|
$mod = trim($mod);
|
||||||
|
if(isset($this->e_Modifiers[$mod]))
|
||||||
|
{
|
||||||
|
// This is probably quicker than array_merge
|
||||||
|
// - especially as usually only one or two loops
|
||||||
|
foreach($this->e_Modifiers[$mod] as $k => $v)
|
||||||
|
{
|
||||||
|
// Update our context-specific options
|
||||||
|
$opts[$k] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $opts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -89,8 +89,8 @@
|
|||||||
'block' =>
|
'block' =>
|
||||||
array (
|
array (
|
||||||
),
|
),
|
||||||
'code' =>
|
'code' => array (
|
||||||
array (
|
|
||||||
),
|
),
|
||||||
'glyph' =>
|
'glyph' =>
|
||||||
array (
|
array (
|
||||||
@@ -217,6 +217,7 @@
|
|||||||
{
|
{
|
||||||
$input = '['.$bbcode.']http://mysite.com[/'.$bbcode.']';
|
$input = '['.$bbcode.']http://mysite.com[/'.$bbcode.']';
|
||||||
$result = $this->bb->parseBBCodes($input, true); // parsing to check for PHP errors.
|
$result = $this->bb->parseBBCodes($input, true); // parsing to check for PHP errors.
|
||||||
|
// $this->assertNotEmpty($result, $input." was empty.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -135,6 +135,43 @@ while($row = $sql->fetch())
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function testToHTMLWithBBcode()
|
||||||
|
{
|
||||||
|
$tests = array(
|
||||||
|
0 => array(
|
||||||
|
'text' => '[code]$something = "something";[/code]',
|
||||||
|
'expected' => "<pre class='prettyprint linenums code_highlight code-box bbcode-code' style='unicode-bidi: embed; direction: ltr'>\$something = "something";</pre>",
|
||||||
|
),
|
||||||
|
1 => array(
|
||||||
|
'text' => '[b]Title[/b][code]$something = "something"; [b]Not parsed[/b][/code]',
|
||||||
|
'expected' => "<strong class='bbcode bold bbcode-b'>Title</strong><pre class='prettyprint linenums code_highlight code-box bbcode-code' style='unicode-bidi: embed; direction: ltr'>\$something = "something"; [b]Not parsed[/b]</pre>",
|
||||||
|
),
|
||||||
|
2 => array(
|
||||||
|
'text' => '[php]<?php $something = "something";[/php]', // legacy usage, now deprecated.
|
||||||
|
'expected' => "",
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($tests as $var)
|
||||||
|
{
|
||||||
|
$result = $this->tp->toHTML($var['text'], true);
|
||||||
|
|
||||||
|
if(!isset($var['expected']))
|
||||||
|
{
|
||||||
|
echo $result."\n\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($var['expected'], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testParseTemplateWithEnabledCoreShortcodes()
|
public function testParseTemplateWithEnabledCoreShortcodes()
|
||||||
{
|
{
|
||||||
@@ -295,7 +332,7 @@ while($row = $sql->fetch())
|
|||||||
//$this->assertSame();
|
//$this->assertSame();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public function testMultibyte()
|
public function testMultibyteOn()
|
||||||
{
|
{
|
||||||
|
|
||||||
// enable multibyte mode.
|
// enable multibyte mode.
|
||||||
@@ -331,6 +368,46 @@ while($row = $sql->fetch())
|
|||||||
$result = $this->tp->ustrrpos($input, 'с');
|
$result = $this->tp->ustrrpos($input, 'с');
|
||||||
$this->assertEquals(3, $result);
|
$this->assertEquals(3, $result);
|
||||||
|
|
||||||
|
$this->tp->setMultibyte(false); // disable after test.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMultibyteOff()
|
||||||
|
{
|
||||||
|
|
||||||
|
// enable multibyte mode.
|
||||||
|
$this->tp->setMultibyte(false);
|
||||||
|
|
||||||
|
$input = "an example of text";
|
||||||
|
|
||||||
|
// strtoupper
|
||||||
|
$result = $this->tp->ustrtoupper($input);
|
||||||
|
$this->assertEquals('AN EXAMPLE OF TEXT', $result);
|
||||||
|
|
||||||
|
// strlen
|
||||||
|
$result = $this->tp->ustrlen($input);
|
||||||
|
$this->assertEquals(18, $result);
|
||||||
|
|
||||||
|
// strtolower
|
||||||
|
$result = $this->tp->ustrtolower('AN EXAMPLE OF TEXT');
|
||||||
|
$this->assertEquals($input, $result);
|
||||||
|
|
||||||
|
// strpos
|
||||||
|
$result = $this->tp->ustrpos($input, 't');
|
||||||
|
$this->assertEquals(14, $result);
|
||||||
|
|
||||||
|
// substr
|
||||||
|
$result = $this->tp->usubstr($input, 0, 5);
|
||||||
|
$this->assertEquals('an ex', $result);
|
||||||
|
|
||||||
|
// stristr
|
||||||
|
$result = $this->tp->ustristr($input, 'of', true);
|
||||||
|
$this->assertEquals('an example ', $result);
|
||||||
|
|
||||||
|
// strrpos (last occurance of a string)
|
||||||
|
$result = $this->tp->ustrrpos($input, 'e');
|
||||||
|
$this->assertEquals(15, $result);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -733,6 +810,12 @@ while($row = $sql->fetch())
|
|||||||
'options' => array('w'=>300, 'h'=>200, 'type'=>'webp'),
|
'options' => array('w'=>300, 'h'=>200, 'type'=>'webp'),
|
||||||
'expected' =>'/thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=300&h=200&type=webp'
|
'expected' =>'/thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=300&h=200&type=webp'
|
||||||
),
|
),
|
||||||
|
3 => array(
|
||||||
|
'path' => '{e_PLUGIN}gallery/images/butterfly.jpg',
|
||||||
|
'options' => array('w'=>300, 'h'=>200, 'scale'=>'2x'),
|
||||||
|
'expected' =>'/thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=600&h=400'
|
||||||
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($urls as $val)
|
foreach($urls as $val)
|
||||||
@@ -1833,6 +1916,7 @@ while($row = $sql->fetch())
|
|||||||
array("before http://something.com after", 'before <a class="e-url" href="http://something.com" >http://something.com</a> after'),
|
array("before http://something.com after", 'before <a class="e-url" href="http://something.com" >http://something.com</a> after'),
|
||||||
array("before https://someplace.com after", 'before <a class="e-url" href="https://someplace.com" >https://someplace.com</a> after'),
|
array("before https://someplace.com after", 'before <a class="e-url" href="https://someplace.com" >https://someplace.com</a> after'),
|
||||||
array("before (www.something.com) after", 'before (<a class="e-url" href="http://www.something.com" >www.something.com</a>) after'),
|
array("before (www.something.com) after", 'before (<a class="e-url" href="http://www.something.com" >www.something.com</a>) after'),
|
||||||
|
array('', ''),
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($tests as $row)
|
foreach($tests as $row)
|
||||||
|
Reference in New Issue
Block a user