Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
Use a pre-BBCode parser to fix rendering of blockquote: use the dedic…
Browse files Browse the repository at this point in the history
…ated blockquote tag instead of e107's div-based blockquote.
  • Loading branch information
kdeldycke committed Mar 28, 2011
1 parent 66d5314 commit 73f1c4b
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions e107-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ function ip_hex2dec($hex_ip) {
}


// An utility method to replace a bunch of matching regexps by constant strings
// Mainly used in content parsing and markup clean-up
function massRegexpReplace($string, $rules) {
foreach ($rules as $regexp => $replacement)
if (preg_match_all($regexp, $string, $matches, PREG_SET_ORDER))
foreach ($matches as $tag)
$string = str_replace($tag, $replacement, $string);
return $string;
}


// A method to simplify a string by removing spaces, returns and tags fo easy comparison
function simplifyString($s) {
// Remove BBCode tags
Expand Down Expand Up @@ -1201,10 +1212,12 @@ function parseAndUpdate($content_ids, $content_type, $property, $parser) {
$new_content = $this->e107_parser->toHTML($content, $parseBB = True);
break;
case 'clean_markup':
// Some advanced cleaning needs to parse BBCode
$new_content = $this->preCleanUpMarkup($content);
// Transform BBCode to HTML using original e107 parser
$new_content = $this->e107_parser->toHTML($content, $parseBB = True);
$new_content = $this->e107_parser->toHTML($new_content, $parseBB = True);
// Clean-up markup produced by e107's BBCode parser
$new_content = $this->cleanUpMarkup($new_content);
$new_content = $this->postCleanUpMarkup($new_content);
break;
case 'upload_local_images':
$domain_list = $this->get_local_domains();
Expand Down Expand Up @@ -1241,8 +1254,23 @@ function parseAndUpdate($content_ids, $content_type, $property, $parser) {
}


// Clean-up markup produced by e107's BBCode parser
function cleanUpMarkup($content) {
// Clean-up BBCode before feeding it to the e107's parser
function preCleanUpMarkup($content) {
$new_content = $content;

$content_transforms = array(
// Replace "[blockquote]...[/blockquote]" with "<blockquote>...</blockquote>"
'/\[\s*blockquote\s*\]/i' => '<blockquote>'
, '/\[\/\s*blockquote\s*\]/i' => '</blockquote>'
);
$new_content = $this->massRegexpReplace($new_content, $content_transforms);

return $new_content;
}


// Clean-up HTML markup produced by e107's BBCode parser
function postCleanUpMarkup($content) {
$new_content = $content;

// Filter bad HTML
Expand Down Expand Up @@ -1300,14 +1328,7 @@ function cleanUpMarkup($content) {
// Translate back each <br> and <br/> to natural '\n' line-breaking
, '/<\s*br\s*\/?>/i' => "\n"
);

foreach ($content_transforms as $regexp => $replacement) {
if (preg_match_all($regexp, $new_content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $tag) {
$new_content = str_replace($tag, $replacement, $new_content);
}
}
}
$new_content = $this->massRegexpReplace($new_content, $content_transforms);

// Normalize \n line-breaks
$new_content = normalize_whitespace($new_content);
Expand Down

0 comments on commit 73f1c4b

Please sign in to comment.