video_filter.codecs.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <?php
  2. /**
  3. * @file
  4. * This file contains all codecs provided by Video Filter.
  5. */
  6. /**
  7. * Implements hook_codec_info().
  8. */
  9. function video_filter_codec_info() {
  10. $codecs = array();
  11. $codecs['archive'] = array(
  12. 'name' => t('Archive.org'),
  13. 'sample_url' => 'http://www.archive.org/details/DrupalconBoston2008-TheStateOfDrupal',
  14. 'callback' => 'video_filter_archive',
  15. 'html5_callback' => 'video_filter_archive',
  16. 'regexp' => '/archive\.org\/details\/([\w-_]+)/i',
  17. 'ratio' => 4 / 3,
  18. );
  19. $codecs['bliptv'] = array(
  20. 'name' => t('Blip.tv'),
  21. 'sample_url' => 'http://blip.tv/file/123456',
  22. 'callback' => 'video_filter_bliptv',
  23. 'regexp' => array(
  24. '@blip\.tv/rss/flash/([^"\&\?/]+)@i',
  25. '@blip\.tv/file/view/([^"\&\?/]+)@i',
  26. '@blip\.tv/file/([^"\&\?/]+)@i',
  27. '@blip\.tv/play/([^"\&\?/]+)@i',
  28. ),
  29. 'ratio' => 16 / 9,
  30. 'control_bar_height' => 30,
  31. );
  32. $codecs['capped'] = array(
  33. 'name' => t('Capped'),
  34. 'sample_url' => 'http://capped.tv/playeralt.php?vid=some-title',
  35. 'callback' => 'video_filter_capped',
  36. 'regexp' => '/capped\.tv\/([a-zA-Z0-9\-_]+)/',
  37. 'ratio' => 425 / 355,
  38. );
  39. $codecs['collegehumor'] = array(
  40. 'name' => t('College Humor'),
  41. 'sample_url' => 'http://www.collegehumor.com/video:1234567890',
  42. 'callback' => 'video_filter_collegehumor',
  43. 'regexp' => '/collegehumor\.com\/video\:([0-9]+)/',
  44. 'ratio' => 16 / 9,
  45. 'control_bar_height' => 0,
  46. );
  47. $codecs['dailymotion'] = array(
  48. 'name' => t('DailyMotion'),
  49. 'sample_url' => 'http://www.dailymotion.com/video/some_video_title',
  50. 'callback' => 'video_filter_dailymotion',
  51. 'regexp' => '/dailymotion\.com\/video\/([a-z0-9\-_]+)/i',
  52. 'ratio' => 4 / 3,
  53. 'control_bar_height' => 20,
  54. );
  55. $codecs['flickr_slideshows'] = array(
  56. 'name' => t('Flickr Slideshows'),
  57. 'sample_url' => 'http://www.flickr.com/photos/username/sets/1234567890/show/',
  58. 'callback' => 'video_filter_flickr_slideshows',
  59. 'regexp' => '/flickr\.com\/photos\/([a-zA-Z0-9@_\-]+)\/sets\/([0-9]+)\/?[show]?\/?/i',
  60. 'ratio' => 4 / 3,
  61. 'control_bar_height' => 0,
  62. );
  63. $codecs['flickr_video'] = array(
  64. 'name' => t('Flickr Video'),
  65. 'sample_url' => 'http://www.flickr.com/photos/hansnilsson/1234567890/',
  66. 'callback' => 'video_filter_flickr_video',
  67. 'regexp' => '/flickr\.com\/photos\/([a-zA-Z0-9@_\-]+)\/([0-9]+)/',
  68. 'ratio' => 4 / 3,
  69. 'control_bar_height' => 0,
  70. );
  71. $codecs['gametrailers'] = array(
  72. 'name' => t('Game Trailers'),
  73. 'sample_url' => 'http://www.gametrailers.com/video/some-title/12345',
  74. 'callback' => 'video_filter_gametrailers',
  75. 'regexp' => array(
  76. '/gametrailers\.com\/player\/([0-9]+)/',
  77. '/gametrailers\.com\/video\/([a-z0-9\-_]+)\/([0-9]+)/',
  78. ),
  79. 'ratio' => 16 / 9,
  80. );
  81. $codecs['gamevideos'] = array(
  82. 'name' => t('Game Videos'),
  83. 'sample_url' => 'http://gamevideos.1up.com/video/id/12345',
  84. 'callback' => 'video_filter_gamevideos',
  85. 'regexp' => '/gamevideos\.1up\.com\/video\/id\/([0-9]+)/',
  86. 'ratio' => 500 / 319,
  87. );
  88. $codecs['godtube'] = array(
  89. 'name' => t('GodTube'),
  90. 'sample_url' => 'http://www.godtube.com/watch/?v=123abc',
  91. 'callback' => 'video_filter_godtube',
  92. 'regexp' => '/godtube\.com\/watch\/\?v=([a-z0-9\-_]+)/i',
  93. 'ratio' => 400 / 283,
  94. 'control_bar_height' => 40,
  95. );
  96. $codecs['google'] = array(
  97. 'name' => t('Google Video'),
  98. 'sample_url' => 'http://video.google.com/videoplay?docid=-uN1qUeId',
  99. 'callback' => 'video_filter_google',
  100. 'regexp' => '/video\.google\.[a-z]+\.?[a-z]+?\/videoplay\?docid=(\-?[0-9]+)/',
  101. 'ratio' => 400 / 326,
  102. );
  103. $codecs['metacafe'] = array(
  104. 'name' => t('Meta Cafe'),
  105. 'sample_url' => 'http://www.metacafe.com/watch/1234567890/some_title/',
  106. 'callback' => 'video_filter_metacafe',
  107. 'regexp' => '/metacafe\.com\/watch\/([a-z0-9\-_]+)\/([a-z0-9\-_]+)/i',
  108. 'ratio' => 400 / 313,
  109. 'control_bar_height' => 32,
  110. );
  111. $codecs['myspace'] = array(
  112. 'name' => t('MySpace'),
  113. 'sample_url' => 'http://myspace.com/video/vid/1234567890',
  114. 'callback' => 'video_filter_myspace',
  115. 'regexp' => array(
  116. '/vids\.myspace\.com\/.*VideoID=([0-9]+)/i',
  117. '/myspace\.com\/video\/([a-z])+\/([0-9]+)/i',
  118. '/myspace\.com\/video\/([a-z0-9\-_]+)\/([a-z0-9\-_]+)\/([a-z0-9]+)/i',
  119. '/myspace\.com\/([a-z0-9\-_]+)\/videos\/([a-z0-9\-_]+)\/([a-z0-9]+)/i',
  120. ),
  121. 'ratio' => 620 / 400,
  122. 'control_bar_height' => 40,
  123. );
  124. $codecs['picasa_slideshows'] = array(
  125. 'name' => t('Picasa Slideshows'),
  126. 'sample_url' => 'http://picasaweb.google.com/data/feed/base/user/USER_NAME/albumid/5568104935784209834?alt=rss&amp;kind=photo&amp;hl=en_US',
  127. 'callback' => 'video_filter_picasa_slideshows',
  128. 'instructions' => t('You must use the URL of the RSS feed for the Picasa album:') .
  129. '<ol>' .
  130. '<li>' . t('View the album in Picasa (you should see thumbnails, not a slideshow).') . '</li>' .
  131. '<li>' . t('Find the "RSS" link and click it.') . '</li>' .
  132. '<li>' . t('Copy the resulting URL from the browser address bar. Example:') . '<br />' .
  133. '<code>[video: http://picasaweb.google.com/data/feed/base/user/USER_NAME/albumid/5568104935784209834?alt=rss&amp;kind=photo&amp;hl=en_US]</code>' .
  134. '</li>' .
  135. '</ol>',
  136. 'regexp' => '/picasaweb\.google\.com\/data\/feed\/base\/user\/([a-zA-Z0-9@_\-\.]+)\/albumid\/([a-z0-9]+)/i',
  137. 'ratio' => 800 / 600,
  138. );
  139. $codecs['slideshare'] = array(
  140. 'name' => t('Slideshare'),
  141. 'sample_url' => 'http://slideshare.net/1759622',
  142. 'callback' => 'video_filter_slideshare',
  143. 'instructions' => t('You need to construct your own URL, using the "Wordpress Embed" code from Slideshare, extract the "id", and form the URL like this: slideshare.net/1759622'),
  144. 'regexp' => array(
  145. '/slideshare\.net\/\?id=([a-z0-9]+)/',
  146. '/slideshare\.net\/([a-z0-9]+)/',
  147. ),
  148. 'ratio' => 425 / 355,
  149. );
  150. $codecs['streamhoster'] = array(
  151. 'name' => t('Streamhoster'),
  152. 'sample_url' => 'http://web26.streamhoster.com/username/filename.flv',
  153. 'callback' => 'video_filter_streamhoster',
  154. 'regexp' => '/([a-z0-9]+)\:\/\/([a-z0-9\-_]+)\.streamhoster\.com\/([a-z0-9\-_]+)\/([a-z0-9\-_\.]+)/i',
  155. 'ratio' => 480 / 360,
  156. );
  157. $codecs['teachertube'] = array(
  158. 'name' => t('Teachertube'),
  159. 'sample_url' => 'http://www.teachertube.com/viewVideo.php?video_id=VIDEOID',
  160. 'callback' => 'video_filter_teachertube',
  161. 'regexp' => '/teachertube\.com\/viewVideo.php\?video_id\=([0-9]+)/i',
  162. 'ratio' => 16 / 9,
  163. );
  164. $codecs['vimeo'] = array(
  165. 'name' => t('Vimeo'),
  166. 'sample_url' => 'http://www.vimeo.com/123456',
  167. 'callback' => 'video_filter_vimeo',
  168. 'html5_callback' => 'video_filter_vimeo_html5',
  169. 'regexp' => '/vimeo\.com\/([0-9]+)/',
  170. 'ratio' => 16 / 9,
  171. 'control_bar_height' => 0,
  172. );
  173. $codecs['wistia'] = array(
  174. 'name' => t('Wistia'),
  175. 'sample_url' => 'http://wistia.com/medias/9pj9n6ftlk',
  176. 'callback' => 'video_filter_wistia_html5',
  177. 'html5_callback' => 'video_filter_wistia_html5',
  178. 'regexp' => '@https?://(.+\.)?(wistia\.com|wi\.st)/((m|medias|projects)|embed/(iframe|playlists))/([a-zA-Z0-9]+)@',
  179. );
  180. $codecs['youtube'] = array(
  181. 'name' => t('YouTube'),
  182. 'sample_url' => 'http://www.youtube.com/watch?v=uN1qUeId',
  183. 'callback' => 'video_filter_youtube',
  184. 'html5_callback' => 'video_filter_youtube_html5',
  185. 'regexp' => array(
  186. '/youtube\.com\/watch\?v=([a-z0-9\-_]+)/i',
  187. '/youtu.be\/([a-z0-9\-_]+)/i',
  188. '/youtube\.com\/v\/([a-z0-9\-_]+)/i',
  189. ),
  190. 'ratio' => 16 / 9,
  191. 'control_bar_height' => 25,
  192. );
  193. $codecs['youtube_playlist'] = array(
  194. 'name' => t('YouTube (Playlist)'),
  195. 'sample_url' => 'http://www.youtube.com/playlist?list=uN1qUeId',
  196. 'callback' => 'video_filter_youtube_playlist_html5',
  197. 'regexp' => array(
  198. '/youtube\.com\/playlist\?list=([a-z0-9\-_]+)/i',
  199. ),
  200. 'ratio' => 16 / 9,
  201. 'control_bar_height' => 25,
  202. );
  203. return $codecs;
  204. }
  205. /**
  206. * Callback for Archive.org codec.
  207. *
  208. * @see video_filter_codec_info()
  209. */
  210. function video_filter_archive($video) {
  211. $video['source'] = 'http://www.archive.org/embed/' . $video['codec']['matches'][1];
  212. return video_filter_iframe($video);
  213. }
  214. /**
  215. * Callback for Blip.tv codec.
  216. *
  217. * @see video_filter_codec_info()
  218. */
  219. function video_filter_bliptv($video) {
  220. $id = $video['codec']['matches'][1];
  221. // Since video ID in URL is different than in embed code, use API to lookup
  222. // the embed code video ID. Adapted from emfield.module.
  223. $result = drupal_http_request('http://blip.tv/file/' . $id . '?skin=api');
  224. if ($result->code == 200) {
  225. $parser = drupal_xml_parser_create($result->data);
  226. $vals = array();
  227. $index = array();
  228. xml_parse_into_struct($parser, $result->data, $vals, $index);
  229. xml_parser_free($parser);
  230. $response = array();
  231. // @todo: What's $arghash supposed to be? It's undefined.
  232. $response['_emfield_arghash'] = $arghash;
  233. $level = array();
  234. $start_level = 1;
  235. foreach ($vals as $xml_elem) {
  236. if ($xml_elem['type'] == 'open') {
  237. if (array_key_exists('attributes', $xml_elem)) {
  238. list($level[$xml_elem['level']], $extra) = array_values($xml_elem['attributes']);
  239. }
  240. else {
  241. $level[$xml_elem['level']] = $xml_elem['tag'];
  242. }
  243. }
  244. if ($xml_elem['type'] == 'complete') {
  245. $php_stmt = '$response';
  246. while ($start_level < $xml_elem['level']) {
  247. $php_stmt .= '[$level[' . $start_level . ']]';
  248. $start_level++;
  249. }
  250. $php_stmt .= '[$xml_elem[\'tag\']][] = $xml_elem[\'value\'];' . $php_stmt . '[$xml_elem[\'tag\']][] = $xml_elem[\'attributes\'];';
  251. eval($php_stmt);
  252. $start_level--;
  253. }
  254. }
  255. $id = $response['EMBEDLOOKUP'][0];
  256. // Protect from XSS.
  257. if (preg_match("/[^A-Za-z0-9]/", $id, $matches)) {
  258. watchdog('Video Filter', 'A faulty Blip.tv ID has been detected.');
  259. $id = 0;
  260. }
  261. }
  262. $video['source'] = 'http://blip.tv/play/' . $id;
  263. $params = array(
  264. 'allowscriptaccess' => 'always',
  265. );
  266. return video_filter_flash($video, $params);
  267. }
  268. /**
  269. * Callback for Capped codec.
  270. *
  271. * @see video_filter_codec_info()
  272. */
  273. function video_filter_capped($video) {
  274. $video['source'] = 'http://capped.micksam7.com/playeralt.swf?vid=' . $video['codec']['matches'][1];
  275. return video_filter_flash($video);
  276. }
  277. /**
  278. * Callback for College Humor codec.
  279. *
  280. * @see video_filter_codec_info()
  281. */
  282. function video_filter_collegehumor($video) {
  283. $video['source'] = 'http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=' . $video['codec']['matches'][1] . '&amp;fullscreen=1';
  284. return video_filter_flash($video);
  285. }
  286. /**
  287. * Callback for DailyMotion codec.
  288. *
  289. * @see video_filter_codec_info()
  290. */
  291. function video_filter_dailymotion($video) {
  292. $video['source'] = 'http://www.dailymotion.com/swf/' . $video['codec']['matches'][1];
  293. return video_filter_flash($video);
  294. }
  295. /**
  296. * Callback for Flickr Slideshows codec.
  297. *
  298. * @see video_filter_codec_info()
  299. */
  300. function video_filter_flickr_slideshows($video) {
  301. $slideshow_player_url = 'http://www.flickr.com/apps/slideshow/show.swf?v=67348';
  302. $video['source'] = $slideshow_player_url . ($video['autoplay'] ? '&amp;autoplay=1' : '');
  303. $user_name = $video['codec']['matches'][1];
  304. $set_id = $video['codec']['matches'][2];
  305. $params['flashvars'] = "&amp;offsite=true&amp;lang=en-us&amp;page_show_url=%2Fphotos%2F$user_name%2Fsets%2F$set_id%2Fshow%2F&amp;page_show_back_url=%2Fphotos%2F$user_name%2Fsets%2F$set_id%2F&amp;set_id=$set_id&amp;jump_to=";
  306. return video_filter_flash($video, $params);
  307. }
  308. /**
  309. * Callback for Flickr Video codec.
  310. *
  311. * @see video_filter_codec_info()
  312. */
  313. function video_filter_flickr_video($video) {
  314. $video['source'] = 'http://www.flickr.com/apps/video/stewart.swf?v=1.161';
  315. $params['flashvars'] = '&amp;photo_id=' . $video['codec']['matches'][2] . '&amp;flickr_show_info_box=true';
  316. return video_filter_flash($video, $params);
  317. }
  318. /**
  319. * Callback for Game Trailers codec.
  320. *
  321. * @see video_filter_codec_info()
  322. */
  323. function video_filter_gametrailers($video) {
  324. if (is_numeric($video['codec']['matches'][1])) {
  325. $match = $video['codec']['matches'][1];
  326. }
  327. elseif (is_numeric($video['codec']['matches'][2])) {
  328. $match = $video['codec']['matches'][2];
  329. }
  330. $video['source'] = 'http://media.mtvnservices.com/embed/mgid:moses:video:gametrailers.com:' . $match;
  331. return video_filter_iframe($video);
  332. }
  333. /**
  334. * Callback for Game Videos codec.
  335. *
  336. * @see video_filter_codec_info()
  337. */
  338. function video_filter_gamevideos($video) {
  339. $video['source'] = 'http://gamevideos.1up.com/swf/gamevideos12.swf?embedded=1&amp;fullscreen=1&amp;autoplay=0&amp;src=http://gamevideos.1up.com/do/videoListXML%3Fid%3D' . $video['codec']['matches'][1];
  340. return video_filter_flash($video);
  341. }
  342. /**
  343. * Callback for GodTube codec.
  344. *
  345. * @see video_filter_codec_info()
  346. */
  347. function video_filter_godtube($video) {
  348. $video['source'] = 'http://www.godtube.com/embed/watch/' . $video['codec']['matches'][1];
  349. return video_filter_iframe($video);
  350. }
  351. /**
  352. * Callback for Google Video codec.
  353. *
  354. * @see video_filter_codec_info()
  355. */
  356. function video_filter_google($video) {
  357. $video['source'] = 'http://video.google.com/googleplayer.swf?docId=' . $video['codec']['matches'][1];
  358. return video_filter_flash($video);
  359. }
  360. /**
  361. * Callback for Meta Cafe codec.
  362. *
  363. * @see video_filter_codec_info()
  364. */
  365. function video_filter_metacafe($video) {
  366. $video['source'] = 'http://metacafe.com/fplayer/' . $video['codec']['matches'][1] . '/' . $video['codec']['matches'][2] . '.swf';
  367. return video_filter_flash($video);
  368. }
  369. /**
  370. * Callback for MySpace codec.
  371. *
  372. * @see video_filter_codec_info()
  373. */
  374. function video_filter_myspace($video) {
  375. // The last match is the ID we need.
  376. $last = count($video['codec']['matches']);
  377. $video['source'] = 'http://mediaservices.myspace.com/services/media/embed.aspx/m=' . $video['codec']['matches'][$last - 1];
  378. return video_filter_flash($video, $params);
  379. }
  380. /**
  381. * Callback for Picasa Slideshows codec.
  382. *
  383. * @see video_filter_codec_info()
  384. */
  385. function video_filter_picasa_slideshows($video) {
  386. $video['source'] = 'http://picasaweb.google.com/s/c/bin/slideshow.swf';
  387. $user_name = $video['codec']['matches'][1];
  388. $set_id = $video['codec']['matches'][2];
  389. $params['flashvars'] = "host=picasaweb.google.com&amp;&amp;feat=flashalbum&amp;RGB=0x000000&amp;feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F" . $user_name . "%2Falbumid%2F" . $set_id . "%3Falt%3Drss%26kind%3Dphoto%26" . ($video['autoplay'] ? '' : '&amp;noautoplay=1');
  390. return video_filter_flash($video, $params);
  391. }
  392. /**
  393. * Callback for Slideshare codec.
  394. *
  395. * @see video_filter_codec_info()
  396. */
  397. function video_filter_slideshare($video) {
  398. $video['source'] = 'http://www.slideshare.net/slideshow/embed_code/' . $video['codec']['matches'][1];
  399. return video_filter_iframe($video);
  400. }
  401. /**
  402. * Callback for Streamhoster codec.
  403. *
  404. * @see video_filter_codec_info()
  405. */
  406. function video_filter_streamhoster($video) {
  407. $video['source'] = 'http://public.streamhoster.com/Resources/Flash/JWFLVMediaPlayer/mediaplayer.swf';
  408. $params = array('allowscriptaccess' => 'always');
  409. $protocol = $video['codec']['matches'][1];
  410. if ($protocol == 'rtmp') {
  411. $params['flashvars'] = 'file=' . urlencode('/' . $video['codec']['matches'][4]);
  412. $params['flashvars'] .= '&amp;streamer=' . urlencode('rtmp://' . $video['codec']['matches'][2] . '.streamhoster.com/' . $video['codec']['matches'][3]);
  413. $params['flashvars'] .= '&amp;type=rtmp';
  414. }
  415. elseif ($protocol == 'http') {
  416. $params['flashvars'] = 'file=' . urlencode('http://' . $video['codec']['matches'][2] . '.streamhoster.com/' . $video['codec']['matches'][3] . '/' . $video['codec']['matches'][4]);
  417. $params['flashvars'] .= '&amp;type=video';
  418. }
  419. $params['flashvars'] .= '&amp;width=' . $video['width'];
  420. $params['flashvars'] .= '&amp;height=' . $video['height'];
  421. $params['flashvars'] .= !empty($video['autoplay']) ? '&amp;autostart=true' : '&amp;autostart=false';
  422. return video_filter_flash($video, $params);
  423. }
  424. /**
  425. * Callback for Teachertube codec.
  426. *
  427. * @see video_filter_codec_info()
  428. */
  429. function video_filter_teachertube($video) {
  430. $video['source'] = 'http://www.teachertube.com/embed/player.swf';
  431. $params['flashvars'] = 'file=http://www.teachertube.com/embedFLV.php?pg=video_' . $video['codec']['matches'][1] . '&amp;menu=false&amp;frontcolor=ffffff&amp;lightcolor=FF0000&amp;logo=http://www.teachertube.com/www3/images/greylogo.swf&amp;skin=http://www.teachertube.com/embed/overlay.swf&amp;volume=80&amp;controlbar=over&amp;displayclick=link&amp;viral.link=http://www.teachertube.com/viewVideo.php?video_id=' . $video['codec']['matches'][1] . '&amp;stretching=exactfit&amp;plugins=viral-2&amp;viral.callout=none&amp;viral.onpause=false';
  432. return video_filter_flash($video, $params);
  433. }
  434. /**
  435. * Callback for Vimeo codec.
  436. *
  437. * @see video_filter_codec_info()
  438. */
  439. function video_filter_vimeo($video) {
  440. $video['source'] = 'http://www.vimeo.com/moogaloop.swf?clip_id=' . $video['codec']['matches'][1] . '&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;autoplay=' . $video['autoplay'];
  441. return video_filter_flash($video);
  442. }
  443. /**
  444. * HTML5 callback for Vimeo codec.
  445. *
  446. * @see video_filter_codec_info()
  447. */
  448. function video_filter_vimeo_html5($video) {
  449. $video['source'] = 'http://player.vimeo.com/video/' . $video['codec']['matches'][1] . ($video['autoplay'] ? '?autoplay=1' : '');
  450. return video_filter_iframe($video);
  451. }
  452. /**
  453. * Callback for YouTube codec.
  454. *
  455. * @see video_filter_codec_info()
  456. */
  457. function video_filter_youtube($video) {
  458. $attributes = array(
  459. 'rel' => $video['related'] ? 'rel=1' : 'rel=0',
  460. 'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
  461. 'fs' => 'fs=1',
  462. );
  463. $video['source'] = 'http://www.youtube.com/v/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
  464. $params['wmode'] = 'opaque';
  465. return video_filter_flash($video, $params);
  466. }
  467. /**
  468. * HTML5 callback for YouTube codec.
  469. *
  470. * @see video_filter_codec_info()
  471. */
  472. function video_filter_youtube_html5($video) {
  473. $attributes = array(
  474. 'rel' => $video['related'] ? 'rel=1' : 'rel=0',
  475. 'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
  476. 'wmode' => 'wmode=opaque',
  477. );
  478. $video['source'] = 'http://www.youtube.com/embed/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
  479. return video_filter_iframe($video);
  480. }
  481. /**
  482. * HTML5 callback for YouTube (Playlist) codec.
  483. *
  484. * @see video_filter_codec_info()
  485. */
  486. function video_filter_youtube_playlist_html5($video) {
  487. $attributes = array(
  488. 'rel' => $video['related'] ? 'rel=1' : 'rel=0',
  489. 'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
  490. 'wmode' => 'wmode=opaque',
  491. );
  492. $video['source'] = 'http://www.youtube.com/embed/videoseries?list=' . $video['codec']['matches'][1] . '&amp;' . implode('&amp;', $attributes);
  493. return video_filter_iframe($video);
  494. }
  495. /**
  496. * Callback for Wistia codec.
  497. *
  498. * Adapted from the media_wistia module.
  499. *
  500. * @see video_filter_codec_info()
  501. */
  502. function video_filter_wistia_html5($video) {
  503. $video_code = $video['codec']['matches'][6];
  504. $matches = $video['codec']['matches'];
  505. $embed_type = ($matches[3] == 'projects' || $matches[5] == 'playlists') ? 'playlists' : 'iframe';
  506. // Get embed code via oEmbed.
  507. $endpoint = 'http://fast.wistia.com/oembed';
  508. $options = array(
  509. 'url' => "http://fast.wistia.com/embed/{$embed_type}/{$video_code}",
  510. 'width' => $video['width'],
  511. 'height' => $video['height'],
  512. );
  513. $data = video_filter_oembed_request($endpoint, $options);
  514. $html = $data['html'];
  515. // See if the video source is already an iframe src.
  516. $pattern = '@https?://fast.wistia.com/embed/(iframe|playlists)/[a-zA-Z0-9]+\?+.+@';
  517. $matches = array();
  518. if (preg_match($pattern, $video['source'], $matches)) {
  519. // Replace the oEmbed iframe src with that provided in the token, in order
  520. // to support embed builder URLs.
  521. $pattern = '@https?://fast.wistia.com/embed/(iframe|playlists)/[a-zA-Z0-9]+\?[^"]+@';
  522. $replacement = $matches[0];
  523. $html = preg_replace($pattern, $replacement, $html);
  524. }
  525. return $html;
  526. }