1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 03:40:37 +02:00

toHTML modifiers test added.

This commit is contained in:
Cameron
2021-01-15 12:47:26 -08:00
parent 497e7279b6
commit 136093b4de
2 changed files with 279 additions and 33 deletions

View File

@@ -32,6 +32,8 @@ class e_parse
*/
private $multibyte = false; // previously $utfAction
private $pref; // core prefs used in toHTML.
// Profanity filter
private $e_pf;
@@ -102,8 +104,8 @@ class e_parse
'link_replace' => true,
// Parse shortcodes - TRUE enables parsing
'parse_sc' => false,
// remove HTML tags.
'no_tags' => false,
@@ -182,6 +184,11 @@ class e_parse
'RAWTEXT' =>
array(
'nobreak' => true, 'retain_nl' => true, 'link_click' => false, 'emotes' => false, 'hook' => false, 'no_tags' => true
),
'NODEFAULT' =>
array ('context' => false, 'fromadmin' => false, 'emotes' => false, 'defs' => false, 'constants' => false, 'hook' => false,
'scripts' => false, 'link_click' => false, 'link_replace' => false, 'parse_sc' => false, 'no_tags' => false, 'value' => false,
'nobreak' => false, 'retain_nl' => false
)
);
@@ -316,9 +323,14 @@ class e_parse
}
public function getModifierList()
public function getModifierList($type = '')
{
return $this->e_SuperMods;
if($type === 'super')
{
return $this->e_SuperMods;
}
return $this->e_Modifiers;
}
@@ -1348,29 +1360,24 @@ class e_parse
return $text;
}
$pref = e107::getPref();
if(empty($this->pref)) // cache the prefs.
{
$prefsUsed = array('smiley_activate', 'make_clickable', 'link_replace', 'main_wordwrap', 'link_text',
'email_text', 'links_new_window', 'profanity_filter', 'tohtml_hook', 'e_tohtml_list', 'e_parse_list'
);
$cfg = e107::getConfig();
foreach($prefsUsed as $v)
{
$this->pref[$v] = $cfg->get($v);
}
}
global $fromadmin;
// Set default modifiers to start
$opts = $this->getModifiers($modifiers);
// Turn off a few things if not enabled in options
if(empty($pref['smiley_activate']))
{
$opts['emotes'] = false;
}
if(empty($pref['make_clickable']))
{
$opts['link_click'] = false;
}
if(empty($pref['link_replace']))
{
$opts['link_replace'] = false;
}
if($this->isHtml($text)) //BC FIx for when HTML is saved without [html][/html]
{
$opts['nobreak'] = true;
@@ -1405,9 +1412,9 @@ class e_parse
*/
// Make sure we have a valid count for word wrapping
if(!$wrap && !empty($pref['main_wordwrap']))
if(!$wrap && !empty($this->pref['main_wordwrap']))
{
$wrap = $pref['main_wordwrap'];
$wrap = $this->pref['main_wordwrap'];
}
// $text = " ".$text;
@@ -1570,10 +1577,10 @@ class e_parse
if($opts['link_replace'] && defset('ADMIN_AREA') !== true)
{
$link_text = $pref['link_text'];
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : LAN_EMAIL_SUBS;
$link_text = $this->pref['link_text'];
$email_text = ($this->pref['email_text']) ? $this->replaceConstants($this->pref['email_text']) : LAN_EMAIL_SUBS;
$sub_blk = $this->makeClickable($sub_blk, 'url', array('sub' => $link_text, 'ext' => $pref['links_new_window']));
$sub_blk = $this->makeClickable($sub_blk, 'url', array('sub' => $link_text, 'ext' => $this->pref['links_new_window']));
$sub_blk = $this->makeClickable($sub_blk, 'email', array('sub' => $email_text));
}
else
@@ -1661,7 +1668,7 @@ class e_parse
// profanity filter
if(!empty($pref['profanity_filter']))
if($this->pref['profanity_filter'])
{
if(!is_object($this->e_pf))
{
@@ -1686,12 +1693,12 @@ class e_parse
if($opts['hook']) //Run any hooked in parsers
{
if(!empty($pref['tohtml_hook']))
if(!empty($this->pref['tohtml_hook']))
{
// trigger_error('<b>tohtml_hook is deprecated.</b> Use e_parse.php instead.', E_USER_DEPRECATED); // NO LAN
//Process the older tohtml_hook pref (deprecated)
foreach(explode(',', $pref['tohtml_hook']) as $hook)
foreach(explode(',', $this->pref['tohtml_hook']) as $hook)
{
if(!is_object($this->e_hook[$hook]) && is_readable(e_PLUGIN . $hook . '/' . $hook . '.php'))
{
@@ -1710,10 +1717,10 @@ class e_parse
/**
* / @deprecated
*/
if(isset($pref['e_tohtml_list']) && is_array($pref['e_tohtml_list']))
if(isset($this->pref['e_tohtml_list']) && is_array($this->pref['e_tohtml_list']))
{
foreach($pref['e_tohtml_list'] as $hook)
foreach($this->pref['e_tohtml_list'] as $hook)
{
if(empty($hook))
{
@@ -1741,9 +1748,9 @@ class e_parse
/**
* / Preferred 'hook'
*/
if(!empty($pref['e_parse_list']))
if(!empty($this->pref['e_parse_list']))
{
foreach($pref['e_parse_list'] as $plugin)
foreach($this->pref['e_parse_list'] as $plugin)
{
$hookObj = e107::getAddon($plugin, 'e_parse');
if($tmp = e107::callMethod($hookObj, 'toHTML', $sub_blk, $opts['context']))
@@ -5320,6 +5327,11 @@ class e_parse
{
return $opts;
}
if(strpos($modifiers,'defaults_off') !== false)
{
$opts = $this->e_SuperMods['NODEFAULT'];
}
// Now process any modifiers that are specified
$aMods = explode(',', $modifiers);
@@ -5351,6 +5363,21 @@ class e_parse
}
}
// Turn off a few things if not enabled in options
if(empty($this->pref['smiley_activate']))
{
$opts['emotes'] = false;
}
if(empty($this->pref['make_clickable']))
{
$opts['link_click'] = false;
}
if(empty($this->pref['link_replace']))
{
$opts['link_replace'] = false;
}
return $opts;
}

View File

@@ -135,6 +135,209 @@ while(&#036;row = &#036;sql-&gt;fetch())
}
*/
function testToHTMLModifiers()
{
e107::getConfig()->set('make_clickable', 0)->save(false, true);
$list = $this->tp->getModifierList();
$tests = array (
'emotes_off' =>
array(
'input' => ":-)",
'expected' => ':-)',
),
'emotes_on' =>
array(
'input' => ":-)",
'expected' => '<img class=\'e-emoticon\' src=\'https://localhost/e107/e107_images/emotes/default/smile.png\' alt="smile" />',
),
'no_hook' =>
array(
'input' => "",
'expected' => '',
),
'do_hook' =>
array(
'input' => "",
'expected' => '',
),
'scripts_off' =>
array(
'input' => "",
'expected' => '',
),
'scripts_on' =>
array(
'input' => "",
'expected' => '',
),
'no_make_clickable' =>
array(
'input' => "www.somewhere.com mailto:myemail@somewhere.com",
'expected' => 'www.somewhere.com mailto:myemail@somewhere.com',
),
'make_clickable' =>
array(
'input' => "www.somewhere.com mailto:myemail@somewhere.com",
'expected' => '', // random obfiscation
),
'no_replace' =>
array(
'input' => "www.somewhere.com",
'expected' => '',
),
'replace' =>
array(
'input' => "www.somewhere.com",
'expected' => '',
),
'consts_off' =>
array(
'input' => "{e_PLUGIN}",
'expected' => '{e_PLUGIN}',
),
'consts_rel' =>
array(
'input' => "{e_PLUGIN}",
'expected' => 'e107_plugins/',
),
'consts_abs' =>
array(
'input' => "{e_PLUGIN}",
'expected' => '/e107_plugins/',
),
'consts_full' =>
array(
'input' => "{e_PLUGIN}",
'expected' => 'https://localhost/e107/e107_plugins/',
),
'scparse_off' =>
array(
'input' => "{SITENAME}",
'expected' => '{SITENAME}',
),
'scparse_on' =>
array(
'input' => "{SITENAME}",
'expected' => 'e107',
),
'no_tags' =>
array(
'input' => "<b>bold</b>",
'expected' => 'bold',
),
'do_tags' =>
array(
'input' => "<b>bold</b>",
'expected' => '<b>bold</b>',
),
'fromadmin' =>
array(
'input' => "My Text {SITENAME} {e_PLUGIN} www.somewhere.com \nNew line :-)",
'expected' => '',
),
'notadmin' =>
array(
'input' => "My Text {SITENAME} {e_PLUGIN} www.somewhere.com \nNew line :-)",
'expected' => '',
),
'er_off' =>
array(
'input' => "My Text {SITENAME} {e_PLUGIN} www.somewhere.com \nNew line :-)",
'expected' => '',
),
'er_on' =>
array(
'input' => "My Text {SITENAME} {e_PLUGIN} www.somewhere.com \nNew line :-)",
'expected' => '',
),
'defs_off' =>
array(
'input' => "LAN_THANK_YOU",
'expected' => 'LAN_THANK_YOU',
),
'defs_on' =>
array(
'input' => "LAN_THANK_YOU",
'expected' => 'Thank you',
),
'dobreak' =>
array(
'input' => "Line 1\nLine 2\nLine 3",
'expected' => 'Line 1<br />Line 2<br />Line 3',
),
'nobreak' =>
array(
'input' => "Line 1\nLine 2\nLine 3",
'expected' => "Line 1\nLine 2\nLine 3",
),
'lb_nl' =>
array(
'input' => "Line 1\nLine 2\nLine 3",
'expected' => "Line 1\nLine 2\nLine 3",
),
'lb_br' =>
array(
'input' => "Line 1\nLine 2\nLine 3",
'expected' => 'Line 1<br />Line 2<br />Line 3',
),
'retain_nl' =>
array(
'input' => "Line 1\nLine 2\nLine 3",
'expected' => "Line 1\nLine 2\nLine 3",
),
'defs' =>
array(
'input' => "LAN_THANK_YOU",
'expected' => 'Thank you',
),
'parse_sc' =>
array(
'input' => "{SITENAME}",
'expected' => 'e107',
),
'constants' =>
array(
'input' => "{e_PLUGIN}",
'expected' => 'e107_plugins/',
),
'value' =>
array(
'input' => "",
'expected' => '',
),
'wysiwyg' =>
array(
'input' => "",
'expected' => '',
),
);
$ret = [];
foreach($list as $mod => $val)
{
if(empty($tests[$mod]['expected']))
{
continue;
}
$result = $this->tp->toHTML($tests[$mod]['input'], false, 'defaults_off,'.$mod);
$this->assertSame($tests[$mod]['expected'], $result, $mod." didn't match the expected result.");
// $ret[$mod] = $result;
}
// e107::getConfig()->set('make_clickable', 0)->save(false, true);
// var_export($ret);
}
function testToHTMLWithBBcode()
{
$tests = array(
@@ -1161,9 +1364,25 @@ while(&#036;row = &#036;sql-&gt;fetch())
'nobreak' => true,
'retain_nl' => true,
),
'NODEFAULT' => array(
'context' => 'NODEFAULT',
'fromadmin' => false,
'emotes' => false,
'defs' => false,
'constants' => false,
'hook' => false,
'scripts' => false,
'link_click' => false,
'link_replace' => false,
'parse_sc' => false,
'no_tags' => false,
'value' => false,
'nobreak' => false,
'retain_nl' => false,
)
);
$list = $this->tp->getModifierList();
$list = $this->tp->getModifierList('super');
$this->assertSame($expected, $list);