Apple_Exporter\Components\Embed_Web_Video::build PHP Method

build() protected method

Build the component.
protected build ( string $text )
$text string
    protected function build($text)
    {
        $aspect_ratio = 1.777;
        $src = $url = null;
        // If a paragraph was matched, it's because it contains a EWV URL.
        // The URL could be linked if it was generated by the [embed] shortcode.
        //
        // If it's an iframe, just get the src attribute.
        if (preg_match('#<p(.*?)>(<a(.*?)>)?(.*?)(</a>)?</p>#', $text, $matches)) {
            $url = trim($matches[4]);
        } else {
            if (preg_match('#<iframe(.*?)src="(.*?)"(.*?)>#', $text, $matches)) {
                $url = trim($matches[2]);
            }
        }
        if (!empty($url)) {
            if (preg_match(self::YOUTUBE_MATCH, $url, $matches)) {
                $src = 'https://www.youtube.com/embed/' . end($matches);
            } else {
                preg_match(self::VIMEO_MATCH, $url, $matches);
                $src = 'https://player.vimeo.com/video/' . end($matches);
            }
        }
        $this->json = array('role' => 'embedwebvideo', 'aspectRatio' => round(floatval($aspect_ratio), 3), 'URL' => $src);
    }