protected function build($text)
{
preg_match('/src="([^"]*?)"/im', $text, $matches);
$url = esc_url_raw(apply_filters('apple_news_build_image_src', $matches[1], $text));
$filename = preg_replace('/\\?.*/', '', \Apple_News::get_filename($url));
$this->json = array('role' => 'photo', 'URL' => $this->maybe_bundle_source($url, $filename));
// IMAGE ALIGNMENT is defined as follows:
// 1. If there is a left or right alignment specified, respect it.
// 2. If there is a center alignment specified:
// 2.a If the image is big enough, use a full-width image
// 2.b Otherwise auto-align
// 3. Otherwise, if there is no alignment specified or set to "none", auto-align.
if (preg_match('#align="left"#', $text) || preg_match('#class=".*?(?:alignleft).*?"#', $text)) {
$this->set_anchor_position(Component::ANCHOR_LEFT);
} else {
if (preg_match('#align="right"#', $text) || preg_match('#class=".*?(?:alignright).*?"#', $text)) {
$this->set_anchor_position(Component::ANCHOR_RIGHT);
} else {
if (preg_match('#align="center"#', $text) || preg_match('#class=".*?(?:aligncenter).*?"#', $text)) {
list($width, $height) = getimagesize($url);
if ($width < $this->get_setting('layout_width')) {
$this->set_anchor_position(Component::ANCHOR_AUTO);
} else {
$this->set_anchor_position(Component::ANCHOR_NONE);
}
} else {
$this->set_anchor_position(Component::ANCHOR_AUTO);
}
}
}
// Full width images have top margin
if (Component::ANCHOR_NONE == $this->get_anchor_position()) {
$this->register_non_anchor_layout();
} else {
$this->register_anchor_layout();
}
// Check for caption
if (preg_match('#<figcaption.*?>(.*?)</figcaption>#m', $text, $matches)) {
$caption = trim($matches[1]);
$this->json['caption'] = $caption;
$this->group_component($caption);
}
}