mirror of
https://github.com/e107inc/e107.git
synced 2025-08-06 06:38:00 +02:00
Linkwords: Ignore commented HTML code during processing.
This commit is contained in:
@@ -233,6 +233,7 @@ class linkwords_parse
|
|||||||
// Split up by HTML tags and process the odd bits here
|
// Split up by HTML tags and process the odd bits here
|
||||||
$ptext = "";
|
$ptext = "";
|
||||||
$lflag = FALSE;
|
$lflag = FALSE;
|
||||||
|
$cflag = false; // commented code prsent.
|
||||||
|
|
||||||
// Shouldn't need utf-8 on next line - just looking for HTML tags
|
// Shouldn't need utf-8 on next line - just looking for HTML tags
|
||||||
$content = preg_split('#(<.*?>)#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
$content = preg_split('#(<.*?>)#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
||||||
@@ -241,12 +242,19 @@ class linkwords_parse
|
|||||||
|
|
||||||
foreach($content as $cont)
|
foreach($content as $cont)
|
||||||
{
|
{
|
||||||
|
if(strpos($cont, '-->') !== false)
|
||||||
|
{
|
||||||
|
$cflag = false; // end of commented code
|
||||||
|
$ptext .= $cont;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($cont[0] === "<") // Its some HTML
|
if ($cont[0] === "<") // Its some HTML
|
||||||
{
|
{
|
||||||
$ptext .= $cont;
|
$ptext .= $cont;
|
||||||
if (strpos($cont, "<a") === 0) $lflag = true;
|
if (strpos($cont, "<!--") === 0) $cflag = true; // start of commented code.
|
||||||
if (strpos($cont, "</a") === 0) $lflag = false;
|
if (strpos($cont, "<a") === 0) $lflag = true; // start of link
|
||||||
|
if (strpos($cont, "</a") === 0) $lflag = false; // end of link.
|
||||||
|
|
||||||
if($area === 'BODY' && !isset($this->area_opts['TITLE'])) // disable linking on header tag content unless enabled in prefs.
|
if($area === 'BODY' && !isset($this->area_opts['TITLE'])) // disable linking on header tag content unless enabled in prefs.
|
||||||
{
|
{
|
||||||
@@ -263,7 +271,7 @@ class linkwords_parse
|
|||||||
}
|
}
|
||||||
else // Its the text in between
|
else // Its the text in between
|
||||||
{
|
{
|
||||||
if ($lflag) // Its probably within a link - leave unchanged
|
if ($lflag || $cflag) // Its probably within a link - leave unchanged
|
||||||
{
|
{
|
||||||
$ptext .= $cont;
|
$ptext .= $cont;
|
||||||
}
|
}
|
||||||
|
@@ -81,13 +81,22 @@
|
|||||||
'text' => "<h3>Body only title</h3><p>body only text</p>",
|
'text' => "<h3>Body only title</h3><p>body only text</p>",
|
||||||
'expected' => "<h3>Body only title</h3><p><a class=\"lw-link lw-1\" href=\"/body-link\" >body only</a> text</p>",
|
'expected' => "<h3>Body only title</h3><p><a class=\"lw-link lw-1\" href=\"/body-link\" >body only</a> text</p>",
|
||||||
),
|
),
|
||||||
|
// Ignore commented code.
|
||||||
|
6 => array(
|
||||||
|
'text' => "<!-- <div>Body only title</div> --> <p>body only text</p>",
|
||||||
|
'expected' => "<!-- <div>Body only title</div> --> <p><a class=\"lw-link lw-2\" href=\"/body-link\" >body only</a> text</p>",
|
||||||
|
),
|
||||||
|
7 => array(
|
||||||
|
'text' => "contact us link <p>body only text</p>",
|
||||||
|
'expected' => '<a class="lw-tip lw-link lw-2" href="/contact.php" title="Contact Us Now" >contact us</a> <a class="lw-link lw-2" href="/page-link" >link</a> <p><a class="lw-link lw-3" href="/body-link" >body only</a> text</p>',
|
||||||
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($tests as $val)
|
foreach($tests as $index => $val)
|
||||||
{
|
{
|
||||||
$result = $this->lw->toHTML($val['text'], 'BODY');
|
$result = $this->lw->toHTML($val['text'], 'BODY');
|
||||||
$this->assertEquals($val['expected'],$result);
|
$this->assertEquals($val['expected'],$result, 'Test #'.$index.' failed. ');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user