Project

General

Profile

Bug #14988 » class.t3lib_parsehtml.diff

Administrator Admin, 2006-12-06 13:03

View differences:

/var/www/html/TYPO3trunk/t3lib/class.t3lib_parsehtml.php 2006-12-06 12:48:02.000000000 +0100
* @return string Processed HTML content
*/
function HTMLcleaner($content, $tags=array(),$keepAll=0,$hSC=0,$addConfig=array()) {
$bScriptFound = false;
$bCdataFound = false;
$bCdataInserted = false;
$newContent = array();
$tokArr = explode('<',$content);
$newContent[] = $this->processContent(current($tokArr),$hSC,$addConfig);
......
$c = 1;
$tagRegister = array();
$tagStack = array();
while(list(,$tok)=each($tokArr)) {
$scriptStringArr = array(0 => 'script', 1 => '/script', 2 => '![CDATA[*/');
$scriptLengthArr = array();
foreach ($scriptStringArr as $k => $value) {
$scriptLengthArr [$k] = strlen($scriptStringArr[$k]);
}
while(list(,$tok)=each($tokArr)) {
$bIsTag = false;
$firstChar = substr($tok,0,1);
# if (strcmp(trim($firstChar),'')) { // It is a tag...
if (preg_match('/[[:alnum:]\/]/',$firstChar)==1) { // It is a tag... (first char is a-z0-9 or /) (fixed 19/01 2004). This also avoids triggering on <?xml..> and <!DOCTYPE..>
if ($bScriptFound) {
// inserting CDATA markers if necessary
if (strncmp($tok, $scriptStringArr[1], $scriptLengthArr[1]) == 0) {
if (!$bCdataFound) {
$actc = $c-1;
$tmp = $newContent[$actc];
$newContent[$actc] = '/*<![CDATA[*/';
$newContent[$c++] = $tmp;
$newContent[$c++] = '/*]]>*/';
$bCdataInserted = true;
}
$bScriptFound = false;
$bCdataFound = false;
$bCdataInserted = false;
} else if ($bCdataFound) {
$cdataEnd = (strrpos($tok,'/*]]>*/') !== FALSE); // this could be used for some check
} if (strncmp($tok, $scriptStringArr[2], $scriptLengthArr[2]) == 0) { // '![CDATA[*/'
$bCdataFound = true;
}
} else {
$compareString = substr($tok,0,$scriptLengthArr[0]);
if ($compareString == $scriptStringArr[0]) {
$bScriptFound = true;
$bIsTag = true;
} else {
$bIsTag = preg_match('/[[:alnum:]\/]/',$firstChar)==1; // It is a tag... (first char is a-z0-9 or /) (fixed 19/01 2004). This also avoids triggering on <?xml..> and <!DOCTYPE..>
}
}
if ($bIsTag) {
$tagEnd = strpos($tok,'>');
if ($tagEnd) { // If there is and end-bracket... tagEnd can't be 0 as the first character can't be a >
$endTag = $firstChar=='/' ? 1 : 0;
......
}
}
return implode('',$newContent);
$rc = implode('',$newContent);
return $rc;
}
/**
(2-2/3)