Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Trivial
-
Resolution: Unresolved
-
Affects Version/s: 1.5.3, 1.8.10, 1.9.6, 2.0
-
Fix Version/s: STABLE backlog
-
Labels:
-
Environment:Linux
-
Database:Any
-
Affected Branches:MOODLE_15_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE, MOODLE_20_STABLE
Description
When displaying a list of forums (mod/forum/index.php...),
If a forum contains an HTML table and the forum is truncated by the parser before the </table> tag is reached, subsequent forums are displayed in a nested table format.
I've run against this many times because we use the forum as a "site news" thing...and we put pictures in it and we always want to be able to use tables.
I've been working on a project that ran into this same problem....this is how I fixed it. I ran this function after I truncated the posts. It might not be perfect, but it is definately better than the entire page being screwed up because of open table tags.
function closetags($html)
{
$selfclosing = ',img,input,br,hr,';
//put all opened tags into an array
preg_match_all("#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU", $html, $result);
$openedtags=$result[1];
//put all closed tags into an array
preg_match_all("#</([a-z]+)>#iU",$html,$result);
$closedtags=$result[1];
$len_opened = count($openedtags);
//all tags are closed
{ return $html; }if(count($closedtags) == $len_opened)
$openedtags = array_reverse($openedtags);
//close tags
{ $html .= '</'.$openedtags[$i].'>'; }for($i=0;$i < $len_opened;$i++)
{
$temp = $openedtags[$i];
switch ($openedtags[$i])
{
case strstr($selfclosing,",$temp,"):
break;
default:
if (!in_array($openedtags[$i],$closedtags))
else
{ unset($closedtags[array_search($openedtags[$i],$closedtags)]); }}
}
return $html;
}