protected function WordPressItemMigration::replaceCaptions in WordPress Migrate 7
Same name and namespace in other branches
- 7.2 wordpress_item.inc \WordPressItemMigration::replaceCaptions()
Rewrite [caption] tags into HTML representing a caption. [caption] itself ($matches[1]) will become an opening <div>, the content within the tag ($matches[2]) will be passed through unchanged, and the closing [/caption] ($matches[3]) will become a <p> containing the caption followed by a closing </div>.
Parameters
array $matches:
File
- ./
wordpress_item.inc, line 382 - Support for migrating posts and pages from a WordPress blog into Drupal.
Class
- WordPressItemMigration
- Intermediate Migration class, implementing behavior common across different types (post_type) of items.
Code
protected function replaceCaptions(array $matches) {
$caption_open = $matches[1];
$content = $matches[2];
$caption_close = $matches[3];
preg_match('|width="(.*?)"|i', $caption_open, $matches);
$width = (int) $matches[1] + 10;
$style = "width: {$width}px;";
preg_match('|align="(.*?)"|i', $caption_open, $matches);
$align = $matches[1];
switch ($align) {
case 'aligncenter':
$style .= "display:block;margin:0 auto;";
break;
case 'alignleft':
$style .= "float:left;";
break;
case 'alignright':
$style .= "float:right;";
break;
default:
break;
}
preg_match('|caption="(.*?)"|i', $caption_open, $matches);
$caption = $matches[1];
$result = '<div style="' . $style . '">';
$result .= $content;
$result .= "<p>{$caption}</p></div>";
return $result;
}