Skip to content

Commit

Permalink
MoveCSStoHead was running into an endless loop on some occasions.
Browse files Browse the repository at this point in the history
Calling phpinfo() from a code section for example.

This is the fix from the last public svn of WB.
Thx to Kant
  • Loading branch information
NorHei committed Oct 26, 2015
1 parent 7f1344a commit 9004e66
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions wbce/modules/output_filter/filters/filterCssToHead.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
* @param string $content
* @return string
*/
function doFilterCssToHead($content) {
// move css definitions into head section
$pattern1 = '/(?:<body.*?)(<link[^>]*?\"text\/css\".*?\/>)/si';
$pattern2 = '/(?:<body.*?)(<style[^>]*?\"text\/css\"[^>]*?>.*?<\/style>)/si';
while(preg_match($pattern1, $content, $matches)==1) {
// loop through all linked CSS
$insert = $matches[1];
$content = str_replace($insert, '', $content);
$insert = "\n".$insert."\n</head>\n<body";
$content = preg_replace('/<\/head>.*?<body/si', $insert, $content);
}
while(preg_match($pattern2, $content, $matches)==1) {
// loop through all inline CSS
$insert = $matches[1];
$content = str_replace($insert, '', $content);
$insert = "\n".$insert."\n</head>\n<body";
$content = preg_replace('/<\/head>.*?<body/si', $insert, $content);
}
return $content;
function doFilterCssToHead($sContent) {
// move css definitions into head section
$sPattern1 = '/(?:<body.*?)(<link[^>]*?\"text\/css\".*?\/>)/si';
$sPattern2 = '/(?:<body.*?)(<style[^>]*?\"text\/css\"[^>]*?>.*?<\/style>)/si';
$aInsert = array();
while(preg_match($sPattern1, $sContent, $aMatches)) {
$aInsert[] = $aMatches[1];
$sContent = str_replace($aMatches[1], '', $sContent);
}
while(preg_match($sPattern2, $sContent, $aMatches)) {
$aInsert[] = $aMatches[1];
$sContent = str_replace($aMatches[1], '', $sContent);
}
$aInsert = array_unique($aInsert);
if(sizeof($aInsert) > 0) {
$sInsert = "\n".implode("\n", $aInsert)."\n</head>\n<body";
$sContent = preg_replace('/<\/head>.*?<body/si', $sInsert, $sContent, 1);
}
return $sContent;
}

0 comments on commit 9004e66

Please sign in to comment.