__('Video embed for YouTube/Vimeo', __FILE__), 'version' => 109, 'summary' => __('Enter a full YouTube or Vimeo URL by itself in any paragraph (example: http://www.youtube.com/watch?v=Wl4XiYadV_k) and this will automatically convert it to an embedded video. This formatter is intended to be run on trusted input. Recommended for use with TinyMCE textarea fields.', __FILE__), 'author' => 'Ryan Cramer', 'href' => 'http://modules.processwire.com/modules/textformatter-video-embed/' ); } const dbTableName = 'textformatter_video_embed'; protected static $configDefaults = array( 'maxWidth' => 640, 'maxHeight' => 480, 'responsive' => 0, ); /** * Data as used by the get/set functions * */ protected $data = array(); /** * Either http or https, depending on $config->https * */ protected $http = ''; /** * Set our configuration defaults * */ public function __construct() { foreach(self::$configDefaults as $key => $value) { $this->set($key, $value); } $this->http = $this->config->https ? 'https' : 'http'; } /** * Given a service oembed URL and video ID, return the corresponding embed code. * * A cached version of the embed code will be used if possible. When not possible, * it will be retrieved from the service's oembed URL, and then cached. * */ protected function getEmbedCode($oembedURL, $videoID) { $db = wire('db'); $videoID = $db->escape_string($videoID); $result = $db->query("SELECT embed_code FROM " . self::dbTableName . " WHERE video_id='$videoID'"); if($result->num_rows) { list($embedCode) = $result->fetch_row(); } else { $data = file_get_contents($oembedURL); if($data) $data = json_decode($data, true); if(is_array($data) && isset($data['html'])) { $embedCode = $data['html']; $sql = "INSERT INTO " . self::dbTableName . " SET " . "video_id='$videoID', " . "embed_code='" . $db->escape_string($embedCode) . "', " . "created=NOW() "; $db->query($sql); } $result->free(); } // account for possibility that stored embed code contains http version while requested on https if($this->http == 'https') $embedCode = str_replace('http://', 'https://', $embedCode); return $embedCode; } /** * Make an iframe-based embed code responsive * */ protected function makeResponsive($out) { $out = str_ireplace('