fixate/pw-mvc-boilerplate

View on GitHub
controllers/traits/video_embed.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

require_once TEMPLATE_DIR.'/lib/VideoEmbedder.php';

trait VideoEmbed
{
    public static function __vidembedInitialize($obj)
    {
        $obj->helper('video_embed');
    }
    /**
     * Embed code for videos.
     * Supports:
     *  - Youtube: converts video links to embed links.
     */
    public function video_embed($url, $options = array())
    {
        if (!$url) {
            return '';
        }

        $options = array_merge(array(
            'width' => 560,
            'height' => 315,
            'allowfullscreen' => true,
        ), $options);

        $embedder = Embedder::factory($url);
        if ($embedder == null) {
            return $url;
        }

        return $embedder->code($options);
    }
}