video_filter.codecs.inc 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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['candidcareer'] = array(
  33. 'name' => t('Candid Career'),
  34. 'sample_url' => 'https://www.candidcareer.com/embed.php?vkey=ed5fdd900a274930252f&shared=CandidCareer&uid=30',
  35. 'callback' => 'video_filter_candidcareer',
  36. 'regexp' => '/candidcareer\.com\/embed\.php\?vkey=([a-zA-Z0-9\-_&;]+)shared=([a-zA-Z0-9\-_&;]+)uid=([a-zA-Z0-9\-_&;]+)/',
  37. 'ratio' => 16 / 9,
  38. 'control_bar_height' => 20,
  39. );
  40. $codecs['capped'] = array(
  41. 'name' => t('Capped'),
  42. 'sample_url' => 'http://capped.tv/playeralt.php?vid=some-title',
  43. 'callback' => 'video_filter_capped',
  44. 'regexp' => '/capped\.tv\/([a-zA-Z0-9\-_]+)/',
  45. 'ratio' => 425 / 355,
  46. );
  47. $codecs['collegehumor'] = array(
  48. 'name' => t('College Humor'),
  49. 'sample_url' => 'http://www.collegehumor.com/video:1234567890',
  50. 'callback' => 'video_filter_collegehumor',
  51. 'regexp' => '/collegehumor\.com\/video\:([0-9]+)/',
  52. 'ratio' => 16 / 9,
  53. 'control_bar_height' => 0,
  54. );
  55. $codecs['coub'] = array(
  56. 'name' => t('Coub'),
  57. 'sample_url' => 'http://coub.com/view/b7ghv',
  58. 'callback' => 'video_filter_coub',
  59. 'html5_callback' => 'video_filter_coub',
  60. 'regexp' => '/coub\.com\/view\/([a-z0-9]+)/i',
  61. 'ratio' => 4 / 3,
  62. );
  63. $codecs['dailymotion'] = array(
  64. 'name' => t('DailyMotion'),
  65. 'sample_url' => 'http://www.dailymotion.com/video/some_video_title',
  66. 'callback' => 'video_filter_dailymotion',
  67. 'html5_callback' => 'video_filter_dailymotion_html5',
  68. 'regexp' => '/dailymotion\.com\/video\/([a-z0-9\-_]+)/i',
  69. 'ratio' => 4 / 3,
  70. 'control_bar_height' => 20,
  71. );
  72. $codecs['democracynow_fullshow'] = array(
  73. 'name' => t('DemocracyNow Fullshow'),
  74. 'sample_url' => 'http://www.democracynow.org/shows/2015/3/20',
  75. 'callback' => 'video_filter_democracynow_fullshow',
  76. 'regexp' => '/democracynow\.org\/shows\/([0-9]+)\/([0-9]+)\/([0-9]+)/',
  77. 'ratio' => 16 / 9,
  78. 'control_bar_height' => 0,
  79. );
  80. $codecs['democracynow_story'] = array(
  81. 'name' => t('DemocracyNow Story'),
  82. 'sample_url' => 'http://www.democracynow.org/2015/3/23/yemen_in_crisis_us_closes_key',
  83. 'callback' => 'video_filter_democracynow_story',
  84. 'regexp' => '/democracynow\.org\/([0-9]+)\/([0-9]+)\/([0-9]+)\/([a-zA-Z0-9\-_]+)/',
  85. 'ratio' => 16 / 9,
  86. 'control_bar_height' => 0,
  87. );
  88. $codecs['flickr_slideshows'] = array(
  89. 'name' => t('Flickr Slideshows'),
  90. 'sample_url' => 'http://www.flickr.com/photos/username/sets/1234567890/show/',
  91. 'callback' => 'video_filter_flickr_slideshows',
  92. 'regexp' => '/flickr\.com\/photos\/([a-zA-Z0-9@_\-]+)\/sets\/([0-9]+)\/?[show]?\/?/i',
  93. 'ratio' => 4 / 3,
  94. 'control_bar_height' => 0,
  95. );
  96. $codecs['flickr_video'] = array(
  97. 'name' => t('Flickr Video'),
  98. 'sample_url' => 'http://www.flickr.com/photos/hansnilsson/1234567890/',
  99. 'callback' => 'video_filter_flickr_video',
  100. 'regexp' => '/flickr\.com\/photos\/([a-zA-Z0-9@_\-]+)\/([0-9]+)/',
  101. 'ratio' => 4 / 3,
  102. 'control_bar_height' => 0,
  103. );
  104. $codecs['foxnews'] = array(
  105. 'name' => t('Fox News'),
  106. 'sample_url' => 'http://video.foxnews.com/v/123456/the-title/',
  107. 'callback' => 'video_filter_foxnews',
  108. 'html5_callback' => 'video_filter_foxnews',
  109. 'regexp' => '/video\.foxnews\.com\/v\/([0-9]+)\/([a-zA-Z0-9\-]+)/i',
  110. 'ratio' => 466 / 263,
  111. 'control_bar_height' => 0,
  112. );
  113. $codecs['gametrailers'] = array(
  114. 'name' => t('Game Trailers'),
  115. 'sample_url' => 'http://www.gametrailers.com/video/some-title/12345',
  116. 'callback' => 'video_filter_gametrailers',
  117. 'regexp' => array(
  118. '/gametrailers\.com\/player\/([0-9]+)/',
  119. '/gametrailers\.com\/video\/([a-z0-9\-_]+)\/([0-9]+)/',
  120. ),
  121. 'ratio' => 16 / 9,
  122. );
  123. $codecs['gamevideos'] = array(
  124. 'name' => t('Game Videos'),
  125. 'sample_url' => 'http://gamevideos.1up.com/video/id/12345',
  126. 'callback' => 'video_filter_gamevideos',
  127. 'regexp' => '/gamevideos\.1up\.com\/video\/id\/([0-9]+)/',
  128. 'ratio' => 500 / 319,
  129. );
  130. $codecs['giphy'] = array(
  131. 'name' => t('Giphy'),
  132. 'sample_url' => 'http://giphy.com/gifs/disney-kids-peter-pan-[gif-id]',
  133. 'callback' => 'video_filter_giphy',
  134. 'html5_callback' => 'video_filter_giphy',
  135. 'regexp' => '/giphy\.com\/gifs\/(([a-zA-Z0-9\-]+)\-|)([a-zA-Z0-9]+)/i',
  136. 'ratio' => 16 / 9,
  137. );
  138. $codecs['godtube'] = array(
  139. 'name' => t('GodTube'),
  140. 'sample_url' => 'http://www.godtube.com/watch/?v=123abc',
  141. 'callback' => 'video_filter_godtube',
  142. 'regexp' => '/godtube\.com\/watch\/\?v=([a-z0-9\-_]+)/i',
  143. 'ratio' => 400 / 283,
  144. 'control_bar_height' => 40,
  145. );
  146. $codecs['google'] = array(
  147. 'name' => t('Google Video'),
  148. 'sample_url' => 'http://video.google.com/videoplay?docid=-uN1qUeId',
  149. 'callback' => 'video_filter_google',
  150. 'regexp' => '/video\.google\.[a-z]+\.?[a-z]+?\/videoplay\?docid=(\-?[0-9]+)/',
  151. 'ratio' => 400 / 326,
  152. );
  153. $codecs['instagram'] = array(
  154. 'name' => t('Instagram'),
  155. 'callback' => 'video_filter_instagram',
  156. 'sample_url' => 'http://instagram.com/p/uN1qUeId',
  157. 'regexp' => array(
  158. '/instagram\.com\/p\/([a-z0-9\-_]+)/i',
  159. '/instagr.am\/p\/([a-z0-9\-_]+)/i',
  160. ),
  161. 'ratio' => 612 / 710,
  162. );
  163. $codecs['metacafe'] = array(
  164. 'name' => t('Meta Cafe'),
  165. 'sample_url' => 'http://www.metacafe.com/watch/1234567890/some_title/',
  166. 'callback' => 'video_filter_metacafe',
  167. 'regexp' => '/metacafe\.com\/watch\/([a-z0-9\-_]+)\/([a-z0-9\-_]+)/i',
  168. 'ratio' => 400 / 313,
  169. 'control_bar_height' => 32,
  170. );
  171. $codecs['mailru'] = array(
  172. 'name' => t('Mail.Ru'),
  173. 'sample_url' => 'https://my.mail.ru/v/semenikhin_denis/video/_groupvideo/[video-id].html',
  174. 'callback' => 'video_filter_mailru',
  175. 'html5_callback' => 'video_filter_mailru',
  176. 'regexp' => '/my\.mail\.ru\/v\/(.*)\/([0-9]+)\.html/i',
  177. 'ratio' => 16 / 9,
  178. 'control_bar_height' => 0,
  179. );
  180. $codecs['myspace'] = array(
  181. 'name' => t('MySpace'),
  182. 'sample_url' => 'http://myspace.com/video/vid/1234567890',
  183. 'callback' => 'video_filter_myspace',
  184. 'regexp' => array(
  185. '/vids\.myspace\.com\/.*VideoID=([0-9]+)/i',
  186. '/myspace\.com\/video\/([a-z])+\/([0-9]+)/i',
  187. '/myspace\.com\/video\/([a-z0-9\-_]+)\/([a-z0-9\-_]+)\/([a-z0-9]+)/i',
  188. '/myspace\.com\/([a-z0-9\-_]+)\/videos\/([a-z0-9\-_]+)\/([a-z0-9]+)/i',
  189. ),
  190. 'ratio' => 620 / 400,
  191. 'control_bar_height' => 40,
  192. );
  193. $codecs['myvideo'] = array(
  194. 'name' => t('MyVideo'),
  195. 'sample_url' => 'http://www.myvideo.de/filme/story-title-1234567890',
  196. 'html5_callback' => 'video_filter_myvideo',
  197. 'callback' => 'video_filter_myvideo',
  198. 'regexp' => array(
  199. '/myvideo\.de\/(.+)\-([0-9]+)/i',
  200. ),
  201. 'ratio' => 400 / 283,
  202. );
  203. $codecs['picasa_slideshows'] = array(
  204. 'name' => t('Picasa Slideshows'),
  205. 'sample_url' => 'http://picasaweb.google.com/data/feed/base/user/USER_NAME/albumid/5568104935784209834?alt=rss&amp;kind=photo&amp;hl=en_US',
  206. 'callback' => 'video_filter_picasa_slideshows',
  207. 'instructions' => t('You must use the URL of the RSS feed for the Picasa album:') .
  208. '<ol>' .
  209. '<li>' . t('View the album in Picasa (you should see thumbnails, not a slideshow).') . '</li>' .
  210. '<li>' . t('Find the "RSS" link and click it.') . '</li>' .
  211. '<li>' . t('Copy the resulting URL from the browser address bar. Example:') . '<br />' .
  212. '<code>[video: http://picasaweb.google.com/data/feed/base/user/USER_NAME/albumid/5568104935784209834?alt=rss&amp;kind=photo&amp;hl=en_US]</code>' .
  213. '</li>' .
  214. '</ol>',
  215. 'regexp' => '/picasaweb\.google\.com\/data\/feed\/base\/user\/([a-zA-Z0-9@_\-\.]+)\/albumid\/([a-z0-9]+)/i',
  216. 'ratio' => 800 / 600,
  217. );
  218. $codecs['rutube'] = array(
  219. 'name' => t('Rutube'),
  220. 'sample_url' => 'http://rutube.ru/video/c80617086143e80ee08f760a2e9cbf43/?pl_type=source&pl_id=8188',
  221. 'html5_callback' => 'video_filter_rutube',
  222. 'callback' => 'video_filter_rutube',
  223. 'regexp' => array(
  224. '/rutube\.ru\/(.*)/i',
  225. ),
  226. 'ratio' => 16 / 9,
  227. );
  228. $codecs['slideshare'] = array(
  229. 'name' => t('Slideshare'),
  230. 'sample_url' => 'http://slideshare.net/1759622',
  231. 'callback' => 'video_filter_slideshare',
  232. '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'),
  233. 'regexp' => array(
  234. '/slideshare\.net\/\?id=([a-z0-9]+)/',
  235. '/slideshare\.net\/([a-z0-9]+)/',
  236. ),
  237. 'ratio' => 425 / 355,
  238. );
  239. $codecs['streamhoster'] = array(
  240. 'name' => t('Streamhoster'),
  241. 'sample_url' => 'http://web26.streamhoster.com/username/filename.flv',
  242. 'callback' => 'video_filter_streamhoster',
  243. 'regexp' => '/([a-z0-9]+)\:\/\/([a-z0-9\-_]+)\.streamhoster\.com\/([a-z0-9\-_]+)\/([a-z0-9\-_\.]+)/i',
  244. 'ratio' => 480 / 360,
  245. );
  246. $codecs['teachertube'] = array(
  247. 'name' => t('Teachertube'),
  248. 'sample_url' => 'http://www.teachertube.com/viewVideo.php?video_id=VIDEOID',
  249. 'callback' => 'video_filter_teachertube',
  250. 'regexp' => '/teachertube\.com\/viewVideo.php\?video_id\=([0-9]+)/i',
  251. 'ratio' => 16 / 9,
  252. );
  253. $codecs['ted'] = array(
  254. 'name' => t('TED'),
  255. 'sample_url' => 'https://www.ted.com/talks/[story-title]',
  256. 'instructions' => t('Click in Embed and copy the "Link to this talk" link and paste here.'),
  257. 'callback' => 'video_filter_ted',
  258. 'html5_callback' => 'video_filter_ted',
  259. 'regexp' => '/ted\.com\/talks\/lang\/([a-zA-Z]+)\/([a-zA-Z0-9\-_]+)(\.html)?/',
  260. 'ratio' => 4 / 3,
  261. );
  262. $codecs['twitch'] = array(
  263. 'name' => t('Twitch'),
  264. 'sample_url' => 'http://www.twitch.tv/uN1qUe-I_d',
  265. 'callback' => 'video_filter_twitch',
  266. 'regexp' => '/twitch\.tv\/([a-z0-9\-_]+)/i',
  267. 'ratio' => 16 / 9,
  268. );
  269. $codecs['ustream'] = array(
  270. 'name' => t('Ustream'),
  271. 'sample_url' => 'http://www.ustream.tv/recorded/111212121212',
  272. 'html5_callback' => 'video_filter_ustream',
  273. 'callback' => 'video_filter_ustream',
  274. 'regexp' => '/ustream\.tv\/recorded\/([0-9]+)/i',
  275. 'ratio' => 16 / 9,
  276. );
  277. $codecs['vbox'] = array(
  278. 'name' => t('Vbox7'),
  279. 'sample_url' => 'http://vbox7.com/play:b4a7291f3d',
  280. 'callback' => 'video_filter_vbox',
  281. 'regexp' => '/vbox7\.com\/play\:([a-z0-9]+)/i',
  282. 'ratio' => 400 / 345,
  283. );
  284. $codecs['vimeo'] = array(
  285. 'name' => t('Vimeo'),
  286. 'sample_url' => 'http://www.vimeo.com/123456',
  287. 'callback' => 'video_filter_vimeo',
  288. 'html5_callback' => 'video_filter_vimeo_html5',
  289. 'regexp' => '/vimeo\.com\/([0-9]+)/',
  290. 'ratio' => 16 / 9,
  291. 'control_bar_height' => 0,
  292. );
  293. $codecs['vine'] = array(
  294. 'name' => t('Vine'),
  295. 'sample_url' => 'https://www.vine.co/v/uN1qUeId',
  296. 'callback' => 'video_filter_vine',
  297. 'regexp' => '/vine\.co\/v\/([0-9a-z]+)/i',
  298. 'ratio' => 4 / 3,
  299. );
  300. $codecs['whatchado'] = array(
  301. 'name' => t('whatchado'),
  302. 'sample_url' => 'https://www.whatchado.com/de/some-title',
  303. 'callback' => 'video_filter_whatchado_whatchado',
  304. 'regexp' => array(
  305. '/whatchado\.com\/[a-z]{2}\/([\w-_]+)/i',
  306. ),
  307. 'ratio' => 960 / 540,
  308. );
  309. $codecs['wistia'] = array(
  310. 'name' => t('Wistia'),
  311. 'sample_url' => 'http://wistia.com/medias/9pj9n6ftlk',
  312. 'callback' => 'video_filter_wistia_html5',
  313. 'html5_callback' => 'video_filter_wistia_html5',
  314. 'regexp' => '@https?://(.+\.)?(wistia\.(com|net)|wi\.st)/((m|medias|projects)|embed/(iframe|playlists))/([a-zA-Z0-9]+)@',
  315. );
  316. $codecs['youku'] = array(
  317. 'name' => t('YouKu'),
  318. 'sample_url' => 'http://v.youku.com/v_show/id_XNjgzNDM4MzIw.html',
  319. 'callback' => 'video_filter_youku_html5',
  320. 'html5_callback' => 'video_filter_youku_html5',
  321. 'regexp' => array(
  322. '/youku\.com\/v_show\/id_([a-z0-9\-_=]+)\.html/i',
  323. '/youku\.com\/player\.php\/sid\/([a-z0-9\-_=]+)/i',
  324. ),
  325. 'ratio' => 16 / 9,
  326. 'control_bar_height' => 50,
  327. );
  328. $codecs['youtube'] = array(
  329. 'name' => t('YouTube'),
  330. 'sample_url' => 'http://www.youtube.com/watch?v=uN1qUeId',
  331. 'callback' => 'video_filter_youtube',
  332. 'html5_callback' => 'video_filter_youtube_html5',
  333. 'regexp' => array(
  334. '/youtube\.com\/watch\?.*?v=([a-z0-9\-_]+)/i',
  335. '/youtu.be\/([a-z0-9\-_]+)/i',
  336. '/youtube\.com\/v\/([a-z0-9\-_]+)/i',
  337. '/youtube\.com\/embed\/([a-z0-9\-_]+)/i',
  338. ),
  339. 'ratio' => 16 / 9,
  340. 'control_bar_height' => 0,
  341. );
  342. $codecs['youtube_playlist'] = array(
  343. 'name' => t('YouTube (Playlist)'),
  344. 'sample_url' => 'http://www.youtube.com/playlist?list=uN1qUeId',
  345. 'callback' => 'video_filter_youtube_playlist_html5',
  346. 'regexp' => array(
  347. '/youtube\.com\/playlist\?list=([a-z0-9\-_]+)/i',
  348. ),
  349. 'ratio' => 16 / 9,
  350. 'control_bar_height' => 0,
  351. );
  352. return $codecs;
  353. }
  354. /**
  355. * Callback for Archive.org codec.
  356. *
  357. * @see video_filter_codec_info()
  358. */
  359. function video_filter_archive($video) {
  360. $video['source'] = '//www.archive.org/embed/' . $video['codec']['matches'][1];
  361. return video_filter_iframe($video);
  362. }
  363. /**
  364. * Callback for Blip.tv codec.
  365. *
  366. * @see video_filter_codec_info()
  367. */
  368. function video_filter_bliptv($video) {
  369. $id = $video['codec']['matches'][1];
  370. // Since video ID in URL is different than in embed code, use API to lookup
  371. // the embed code video ID. Adapted from emfield.module.
  372. $result = drupal_http_request('http://blip.tv/file/' . $id . '?skin=api');
  373. if ($result->code == 200) {
  374. $parser = drupal_xml_parser_create($result->data);
  375. $vals = array();
  376. $index = array();
  377. xml_parse_into_struct($parser, $result->data, $vals, $index);
  378. xml_parser_free($parser);
  379. $response = array();
  380. // @todo: What's $arghash supposed to be? It's undefined.
  381. $response['_emfield_arghash'] = $arghash;
  382. $level = array();
  383. $start_level = 1;
  384. foreach ($vals as $xml_elem) {
  385. if ($xml_elem['type'] == 'open') {
  386. if (array_key_exists('attributes', $xml_elem)) {
  387. list($level[$xml_elem['level']], $extra) = array_values($xml_elem['attributes']);
  388. }
  389. else {
  390. $level[$xml_elem['level']] = $xml_elem['tag'];
  391. }
  392. }
  393. if ($xml_elem['type'] == 'complete') {
  394. $php_stmt = '$response';
  395. while ($start_level < $xml_elem['level']) {
  396. $php_stmt .= '[$level[' . $start_level . ']]';
  397. $start_level++;
  398. }
  399. $php_stmt .= '[$xml_elem[\'tag\']][] = $xml_elem[\'value\'];' . $php_stmt . '[$xml_elem[\'tag\']][] = $xml_elem[\'attributes\'];';
  400. eval($php_stmt);
  401. $start_level--;
  402. }
  403. }
  404. $id = $response['EMBEDLOOKUP'][0];
  405. // Protect from XSS.
  406. if (preg_match("/[^A-Za-z0-9]/", $id, $matches)) {
  407. watchdog('Video Filter', 'A faulty Blip.tv ID has been detected.');
  408. $id = 0;
  409. }
  410. }
  411. $video['source'] = '//blip.tv/play/' . $id;
  412. $params = array(
  413. 'allowscriptaccess' => 'always',
  414. );
  415. return video_filter_flash($video, $params);
  416. }
  417. /**
  418. * Callback for Candid Career codec.
  419. *
  420. * @see video_filter_codec_info()
  421. */
  422. function video_filter_candidcareer($video) {
  423. // Their urls contain & symbols which Drupal is encoding, so decode those.
  424. $decoded = decode_entities($video['codec']['matches'][0]);
  425. $video['source'] = '//' . $decoded;
  426. $video['attributes']['marginwidth'] = 0;
  427. $video['attributes']['marginheight'] = 0;
  428. return video_filter_iframe($video);
  429. }
  430. /**
  431. * Callback for Capped codec.
  432. *
  433. * @see video_filter_codec_info()
  434. */
  435. function video_filter_capped($video) {
  436. $video['source'] = '//capped.micksam7.com/playeralt.swf?vid=' . $video['codec']['matches'][1];
  437. return video_filter_flash($video);
  438. }
  439. /**
  440. * Callback for College Humor codec.
  441. *
  442. * @see video_filter_codec_info()
  443. */
  444. function video_filter_collegehumor($video) {
  445. $video['source'] = '//www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=' . $video['codec']['matches'][1] . '&amp;fullscreen=1';
  446. return video_filter_flash($video);
  447. }
  448. /**
  449. * HTML5 callback for Coub codec.
  450. *
  451. * @see video_filter_codec_info()
  452. */
  453. function video_filter_coub($video) {
  454. $attributes = array(
  455. 'autostart' => !empty($video['autoplay']) ? 'autoplay=true' : 'autoplay=false',
  456. 'originalSize' => !empty($video['originalSize']) ? 'originalSize=true' : 'originalSize=false',
  457. 'startWithHD' => !empty($video['startWithHD']) ? 'startWithHD=true' : 'startWithHD=false',
  458. 'muted' => !empty($video['muted']) ? 'muted=true' : 'muted=false',
  459. );
  460. $video['source'] = '//coub.com/embed/' . $video['codec']['matches'][1] . '?' . implode('&', $attributes);
  461. return video_filter_iframe($video);
  462. }
  463. /**
  464. * Callback for DailyMotion codec.
  465. *
  466. * @see video_filter_codec_info()
  467. */
  468. function video_filter_dailymotion($video) {
  469. $attributes = array(
  470. 'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
  471. );
  472. $video['source'] = '//www.dailymotion.com/swf/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
  473. return video_filter_flash($video);
  474. }
  475. /**
  476. * HTML5 callback for DailyMotion codec.
  477. *
  478. * @see video_filter_codec_info()
  479. */
  480. function video_filter_dailymotion_html5($video) {
  481. $attributes = array(
  482. 'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
  483. );
  484. $video['source'] = '//www.dailymotion.com/embed/video/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
  485. return video_filter_iframe($video);
  486. }
  487. /**
  488. * Callback for Flickr Slideshows codec.
  489. *
  490. * @see video_filter_codec_info()
  491. */
  492. function video_filter_flickr_slideshows($video) {
  493. $slideshow_player_url = 'http://www.flickr.com/apps/slideshow/show.swf?v=67348';
  494. $video['source'] = $slideshow_player_url . ($video['autoplay'] ? '&amp;autoplay=1' : '');
  495. $user_name = $video['codec']['matches'][1];
  496. $set_id = $video['codec']['matches'][2];
  497. $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=";
  498. return video_filter_flash($video, $params);
  499. }
  500. /**
  501. * Callback for DemocracyNow Fullshow codec.
  502. *
  503. * @see video_filter_codec_info()
  504. */
  505. function video_filter_democracynow_fullshow($video) {
  506. $video['source'] = 'http://www.democracynow.org/embed/show/' . $video['codec']['matches'][0];
  507. // The above is pulling in the url part of the regex, so we need to do a
  508. // search and replace to remove it.
  509. $toomuch = array("http://www.democracynow.org/embed/show/democracynow.org/shows/");
  510. $justright = array("http://www.democracynow.org/embed/show/");
  511. $replaced = str_replace($toomuch, $justright, $video);
  512. $video = $replaced;
  513. return video_filter_iframe($video);
  514. }
  515. /**
  516. * Callback for DemocracyNow story codec.
  517. *
  518. * @see video_filter_codec_info()
  519. */
  520. function video_filter_democracynow_story($video) {
  521. $video['source'] = 'http://www.democracynow.org/embed/story/' . $video['codec']['matches'][0];
  522. // The above is pulling in the url part of the regex, so we need to do a
  523. // search and replace to remove it.
  524. $toomuch = array("http://www.democracynow.org/embed/story/democracynow.org/");
  525. $justright = array("http://www.democracynow.org/embed/story/");
  526. $replaced = str_replace($toomuch, $justright, $video);
  527. $video = $replaced;
  528. return video_filter_iframe($video);
  529. }
  530. /**
  531. * Callback for Ted.com codec.
  532. *
  533. * @see video_filter_codec_info()
  534. */
  535. function video_filter_ted($video) {
  536. $video['source'] = '//embed.ted.com/talks/' . $video['codec']['matches'][3] . '.html';
  537. return video_filter_iframe($video);
  538. }
  539. /**
  540. * Callback for Flickr Video codec.
  541. *
  542. * @see video_filter_codec_info()
  543. */
  544. function video_filter_flickr_video($video) {
  545. $video['source'] = '//www.flickr.com/apps/video/stewart.swf?v=1.161';
  546. $params['flashvars'] = '&amp;photo_id=' . $video['codec']['matches'][2] . '&amp;flickr_show_info_box=true';
  547. return video_filter_flash($video, $params);
  548. }
  549. /**
  550. * Callback for Fox News codec.
  551. *
  552. * @see video_filter_codec_info()
  553. */
  554. function video_filter_foxnews($video) {
  555. $video_id = $video['codec']['matches'][1];
  556. $html = '<script type="text/javascript" src="http://video.foxnews.com/v/embed.js?id=' . $video_id . '&w=' . $video['width'] . '&h=' . $video['height'] . '"></script>';
  557. return $html;
  558. }
  559. /**
  560. * Callback for Game Trailers codec.
  561. *
  562. * @see video_filter_codec_info()
  563. */
  564. function video_filter_gametrailers($video) {
  565. if (is_numeric($video['codec']['matches'][1])) {
  566. $match = $video['codec']['matches'][1];
  567. }
  568. elseif (is_numeric($video['codec']['matches'][2])) {
  569. $match = $video['codec']['matches'][2];
  570. }
  571. $video['source'] = '//media.mtvnservices.com/embed/mgid:moses:video:gametrailers.com:' . $match;
  572. return video_filter_iframe($video);
  573. }
  574. /**
  575. * Callback for Game Videos codec.
  576. *
  577. * @see video_filter_codec_info()
  578. */
  579. function video_filter_gamevideos($video) {
  580. $video['source'] = '//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];
  581. return video_filter_flash($video);
  582. }
  583. /**
  584. * Callback for Giphy codec.
  585. *
  586. * @see video_filter_codec_info()
  587. */
  588. function video_filter_giphy($video) {
  589. $video['source'] = '//giphy.com/embed/' . $video['codec']['matches'][3];
  590. return video_filter_iframe($video);
  591. }
  592. /**
  593. * Callback for GodTube codec.
  594. *
  595. * @see video_filter_codec_info()
  596. */
  597. function video_filter_godtube($video) {
  598. $video['source'] = '//www.godtube.com/embed/watch/' . $video['codec']['matches'][1];
  599. return video_filter_iframe($video);
  600. }
  601. /**
  602. * Callback for Google Video codec.
  603. *
  604. * @see video_filter_codec_info()
  605. */
  606. function video_filter_google($video) {
  607. $video['source'] = '//video.google.com/googleplayer.swf?docId=' . $video['codec']['matches'][1];
  608. return video_filter_flash($video);
  609. }
  610. /**
  611. * Callback for Instagram codec.
  612. *
  613. * @see video_filter_codec_info()
  614. */
  615. function video_filter_instagram($video) {
  616. $html = &drupal_static(__FUNCTION__);
  617. $id = $video['codec']['matches'][1];
  618. if ($cache = cache_get('video_filter_instagram:' . $id)) {
  619. $html = $cache->data;
  620. }
  621. else {
  622. $endpoint = 'https://api.instagram.com/oembed';
  623. $options = array(
  624. 'url' => 'http://instagr.am/p/' . $id,
  625. );
  626. $data = video_filter_oembed_request($endpoint, $options);
  627. if (!empty($data['html'])) {
  628. $html = $data['html'];
  629. }
  630. cache_set('video_filter_instagram:' . $id, $html, 'cache');
  631. }
  632. return $html;
  633. }
  634. /**
  635. * Callback for Mail.Ru codec.
  636. *
  637. * @see video_filter_codec_info()
  638. */
  639. function video_filter_mailru($video) {
  640. $attributes = array(
  641. 'autoplay' => !empty($video['autoplay']) ? 'autoplay=' . (int) $video['autoplay'] : '',
  642. );
  643. $video['source'] = 'https://videoapi.my.mail.ru/videos/embed/v/' . $video['codec']['matches'][1] . '/' . $video['codec']['matches'][2] . '.html?' . implode('&', $attributes);
  644. return video_filter_iframe($video);
  645. }
  646. /**
  647. * Callback for Meta Cafe codec.
  648. *
  649. * @see video_filter_codec_info()
  650. */
  651. function video_filter_metacafe($video) {
  652. $video['source'] = '//metacafe.com/fplayer/' . $video['codec']['matches'][1] . '/' . $video['codec']['matches'][2] . '.swf';
  653. return video_filter_flash($video);
  654. }
  655. /**
  656. * Callback for MySpace codec.
  657. *
  658. * @see video_filter_codec_info()
  659. */
  660. function video_filter_myspace($video) {
  661. // The last match is the ID we need.
  662. $last = count($video['codec']['matches']);
  663. $video['source'] = '//mediaservices.myspace.com/services/media/embed.aspx/m=' . $video['codec']['matches'][$last - 1];
  664. return video_filter_flash($video, $params);
  665. }
  666. /**
  667. * Callback for MyVideo codec.
  668. *
  669. * @see video_filter_codec_info()
  670. */
  671. function video_filter_myvideo($video) {
  672. $video['source'] = 'http://www.myvideo.de/embedded/public/' . $video['codec']['matches'][2];
  673. return video_filter_iframe($video);
  674. }
  675. /**
  676. * Callback for Picasa Slideshows codec.
  677. *
  678. * @see video_filter_codec_info()
  679. */
  680. function video_filter_picasa_slideshows($video) {
  681. $video['source'] = '//picasaweb.google.com/s/c/bin/slideshow.swf';
  682. $user_name = $video['codec']['matches'][1];
  683. $set_id = $video['codec']['matches'][2];
  684. $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');
  685. return video_filter_flash($video, $params);
  686. }
  687. /**
  688. * Callback for Rutube codec.
  689. *
  690. * @see video_filter_codec_info()
  691. */
  692. function video_filter_rutube($video) {
  693. $attributes = array(
  694. 'skinColor' => (isset($video['skinColor']) && !empty($video['standardColor'])) ? 'skinColor=' . (string) $video['skinColor'] : '',
  695. 'sTitle' => (isset($video['sTitle']) && $video['sTitle'] == 1) ? 'sTitle=true' : 'sTitle=false',
  696. 'sAuthor' => (isset($video['sAuthor']) && $video['sAuthor'] == 1) ? 'sAuthor=true' : 'sAuthor=false',
  697. 'bmstart' => (isset($video['bmstart']) && $video['bmstart'] > 1) ? 'bmstart=' . (int) $video['bmstart'] : 'bmstart=false',
  698. );
  699. $endpoint = 'http://rutube.ru/api/oembed';
  700. $options = array(
  701. 'url' => $video['source'],
  702. 'format' => 'json',
  703. );
  704. $data = video_filter_oembed_request($endpoint, $options);
  705. if (!empty($data['html'])) {
  706. if (preg_match('/src="([^"]+)"/', $data['html'], $match)) {
  707. $video['source'] = $match[1] . '?' . implode('&', $attributes);
  708. return video_filter_iframe($video);
  709. }
  710. }
  711. }
  712. /**
  713. * Callback for Slideshare codec.
  714. *
  715. * @see video_filter_codec_info()
  716. */
  717. function video_filter_slideshare($video) {
  718. $video['source'] = '//www.slideshare.net/slideshow/embed_code/' . $video['codec']['matches'][1];
  719. return video_filter_iframe($video);
  720. }
  721. /**
  722. * Callback for Streamhoster codec.
  723. *
  724. * @see video_filter_codec_info()
  725. */
  726. function video_filter_streamhoster($video) {
  727. $video['source'] = '//public.streamhoster.com/Resources/Flash/JWFLVMediaPlayer/mediaplayer.swf';
  728. $params = array('allowscriptaccess' => 'always');
  729. $protocol = $video['codec']['matches'][1];
  730. if ($protocol == 'rtmp') {
  731. $params['flashvars'] = 'file=' . urlencode('/' . $video['codec']['matches'][4]);
  732. $params['flashvars'] .= '&amp;streamer=' . urlencode('rtmp://' . $video['codec']['matches'][2] . '.streamhoster.com/' . $video['codec']['matches'][3]);
  733. $params['flashvars'] .= '&amp;type=rtmp';
  734. }
  735. elseif ($protocol == 'http') {
  736. $params['flashvars'] = 'file=' . urlencode('http://' . $video['codec']['matches'][2] . '.streamhoster.com/' . $video['codec']['matches'][3] . '/' . $video['codec']['matches'][4]);
  737. $params['flashvars'] .= '&amp;type=video';
  738. }
  739. $params['flashvars'] .= '&amp;width=' . $video['width'];
  740. $params['flashvars'] .= '&amp;height=' . $video['height'];
  741. $params['flashvars'] .= !empty($video['autoplay']) ? '&amp;autostart=true' : '&amp;autostart=false';
  742. return video_filter_flash($video, $params);
  743. }
  744. /**
  745. * Callback for Twitch codec.
  746. *
  747. * @see video_filter_codec_info()
  748. */
  749. function video_filter_twitch($video) {
  750. $video['source'] = '//player.twitch.tv/?channel=' . $video['codec']['matches'][1] ;
  751. return video_filter_iframe($video);
  752. }
  753. /**
  754. * Callback for Teachertube codec.
  755. *
  756. * @see video_filter_codec_info()
  757. */
  758. function video_filter_teachertube($video) {
  759. $video['source'] = '//www.teachertube.com/embed/player.swf';
  760. $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';
  761. return video_filter_flash($video, $params);
  762. }
  763. /**
  764. * Callback for Ustream codec.
  765. *
  766. * @see video_filter_codec_info()
  767. */
  768. function video_filter_ustream($video) {
  769. $attributes = array(
  770. 'html5ui' => 'html5ui',
  771. 'autoplay' => isset($video['autoplay']) ? 'autoplay=' . (int) $video['autoplay'] : 'autoplay=0',
  772. );
  773. $video['source'] = 'http://www.ustream.tv/embed/recorded/' . $video['codec']['matches'][1] . '?' . implode('&', $attributes);
  774. return video_filter_iframe($video);
  775. }
  776. /**
  777. * Callback for VBox7 codec.
  778. *
  779. * @see video_filter_codec_info()
  780. */
  781. function video_filter_vbox($video) {
  782. $video['source'] = '//vbox7.com/emb/external.php?vid=' . $video['codec']['matches'][1];
  783. return video_filter_flash($video);
  784. }
  785. /**
  786. * Callback for Vimeo codec.
  787. *
  788. * @see video_filter_codec_info()
  789. */
  790. function video_filter_vimeo($video) {
  791. $attributes = array(
  792. 'autopause' => isset($video['autopause']) ? 'autopause=' . (int) $video['autopause'] : 'autopause=1',
  793. 'autoplay' => isset($video['autoplay']) ? 'autoplay=' . (int) $video['autoplay'] : 'autoplay=0',
  794. 'badge' => isset($video['badge']) ? 'badge=' . (int) $video['badge'] : 'badge=1',
  795. 'byline' => isset($video['byline']) ? 'byline=' . (int) $video['byline'] : 'byline=1',
  796. 'loop' => isset($video['loop']) ? 'loop=' . (int) $video['loop'] : 'loop=0',
  797. 'portrait' => isset($video['portrait']) ? 'portrait=' . (int) $video['portrait'] : 'portrait=1',
  798. 'title' => isset($video['title']) ? 'autopause=' . (int) $video['title'] : 'autopause=1',
  799. 'fullscreen' => isset($video['fullscreen']) ? 'fullscreen=' . (int) $video['fullscreen'] : 'fullscreen=1',
  800. );
  801. if (!empty($video['color'])) {
  802. $attributes['color'] = (string) $video['color'];
  803. }
  804. $video['source'] = '//www.vimeo.com/moogaloop.swf?clip_id=' . $video['codec']['matches'][1] . '&amp;server=www.vimeo.com&amp;' . implode('&amp;', $attributes);
  805. return video_filter_flash($video);
  806. }
  807. /**
  808. * HTML5 callback for Vimeo codec.
  809. *
  810. * @see video_filter_codec_info()
  811. */
  812. function video_filter_vimeo_html5($video) {
  813. $attributes = array(
  814. 'autopause' => isset($video['autopause']) ? 'autopause=' . (int) $video['autopause'] : 'autopause=1',
  815. 'autoplay' => isset($video['autoplay']) ? 'autoplay=' . (int) $video['autoplay'] : 'autoplay=0',
  816. 'badge' => isset($video['badge']) ? 'badge=' . (int) $video['badge'] : 'badge=1',
  817. 'byline' => isset($video['byline']) ? 'byline=' . (int) $video['byline'] : 'byline=1',
  818. 'loop' => isset($video['loop']) ? 'loop=' . (int) $video['loop'] : 'loop=0',
  819. 'portrait' => isset($video['portrait']) ? 'portrait=' . (int) $video['portrait'] : 'portrait=1',
  820. 'title' => isset($video['title']) ? 'autopause=' . (int) $video['title'] : 'autopause=1',
  821. 'fullscreen' => isset($video['fullscreen']) ? 'fullscreen=' . (int) $video['fullscreen'] : 'fullscreen=1',
  822. );
  823. if (!empty($video['color'])) {
  824. $attributes['color'] = (string) $video['color'];
  825. }
  826. $video['source'] = '//player.vimeo.com/video/' . $video['codec']['matches'][1] . '?' . implode('&', $attributes);
  827. return video_filter_iframe($video);
  828. }
  829. /**
  830. * Callback for Whatchadoo codec.
  831. *
  832. * @see video_filter_codec_info()
  833. */
  834. function video_filter_whatchado($video) {
  835. $video['source'] = '//www.whatchado.com/embed/player/' . $video['codec']['matches'][1];
  836. return video_filter_iframe($video);
  837. }
  838. /**
  839. * HTML5 callback for YouKu codec.
  840. *
  841. * @see video_filter_codec_info()
  842. */
  843. function video_filter_youku_html5($video) {
  844. $attributes = array();
  845. $video['source'] = 'http://player.youku.com/embed/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
  846. return video_filter_iframe($video);
  847. }
  848. /**
  849. * Callback for YouTube codec.
  850. *
  851. * @see video_filter_codec_info()
  852. */
  853. function video_filter_youtube($video) {
  854. $attributes = array(
  855. 'modestbranding' => !empty($video['modestbranding']) ? 'modestbranding=1' : 'modestbranding=0',
  856. 'rel' => !empty($video['related']) ? 'rel=1' : 'rel=0',
  857. 'autoplay' => !empty($video['autoplay']) ? 'autoplay=1' : 'autoplay=0',
  858. 'fs' => 'fs=1',
  859. 'loop' => !empty($video['loop']) ? 'loop=1' : 'loop=0',
  860. 'controls' => !empty($video['controls']) ? 'controls=1' : (!isset($video['controls']) ? 'controls=1' : 'controls=0'),
  861. 'autohide' => !empty($video['autohide']) ? 'autohide=1' : 'autohide=0',
  862. 'showinfo' => !empty($video['showinfo']) ? 'showinfo=1' : 'showinfo=0',
  863. 'theme' => !empty($video['theme']) ? 'theme=' . $video['theme'] : 'theme=dark',
  864. 'color' => !empty($video['color']) ? 'color=' . $video['color'] : 'color=red',
  865. 'enablejsapi' => !empty($video['enablejsapi']) ? 'enablejsapi=' . (int) $video['enablejsapi'] : 'enablejsapi=0',
  866. );
  867. if (!empty($video['loop'])) {
  868. $attributes['playlist'] = 'playlist=' . $video['codec']['matches'][1];
  869. }
  870. if (preg_match('/t=((\d+[m|s])?(\d+[s]?)?)/', $video['source'], $matches)) {
  871. $attributes['start'] = 'start=' . (preg_replace("/[^0-9]/", "", $matches[2]) * 60 + (preg_replace("/[^0-9]/", "", $matches[3])));
  872. }
  873. if (!empty($video['start'])) {
  874. if (preg_match('/((\d+[m|s])?(\d+[s]?)?)/', $video['start'], $matches)) {
  875. $attributes['start'] = 'start=' . (preg_replace("/[^0-9]/", "", $matches[2]) * 60 + (preg_replace("/[^0-9]/", "", $matches[3])));
  876. }
  877. }
  878. $video['source'] = '//www.youtube.com/embed/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
  879. $params['wmode'] = 'opaque';
  880. return video_filter_flash($video, $params);
  881. }
  882. /**
  883. * Callback for Vine codec.
  884. *
  885. * @see video_filter_codec_info()
  886. */
  887. function video_filter_vine($video) {
  888. $video['source'] = '//vine.co/v/' . $video['codec']['matches'][1] . '/embed/simple';
  889. return video_filter_iframe($video);
  890. }
  891. /**
  892. * HTML5 callback for YouTube codec.
  893. *
  894. * @see video_filter_codec_info()
  895. */
  896. function video_filter_youtube_html5($video) {
  897. $attributes = array(
  898. 'modestbranding' => !empty($video['modestbranding']) ? 'modestbranding=1' : 'modestbranding=0',
  899. 'html5' => 'html5=1',
  900. 'rel' => $video['related'] ? 'rel=1' : 'rel=0',
  901. 'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
  902. 'wmode' => 'wmode=opaque',
  903. 'loop' => !empty($video['loop']) ? 'loop=1' : 'loop=0',
  904. 'controls' => !empty($video['controls']) ? 'controls=1' : (!isset($video['controls']) ? 'controls=1' : 'controls=0'),
  905. 'autohide' => !empty($video['autohide']) ? 'autohide=1' : 'autohide=0',
  906. 'showinfo' => !empty($video['showinfo']) ? 'showinfo=1' : 'showinfo=0',
  907. 'theme' => !empty($video['theme']) ? 'theme=' . $video['theme'] : 'theme=dark',
  908. 'color' => !empty($video['color']) ? 'color=' . $video['color'] : 'color=red',
  909. 'enablejsapi' => !empty($video['enablejsapi']) ? 'enablejsapi=' . (int) $video['enablejsapi'] : 'enablejsapi=0',
  910. );
  911. if (!empty($video['loop'])) {
  912. $attributes['playlist'] = 'playlist=' . $video['codec']['matches'][1];
  913. }
  914. if (preg_match('/t=((\d+[m|s])?(\d+[s]?)?)/', $video['source'], $matches)) {
  915. $attributes['start'] = 'start=' . (preg_replace("/[^0-9]/", "", $matches[2]) * 60 + (preg_replace("/[^0-9]/", "", $matches[3])));
  916. }
  917. if (!empty($video['start'])) {
  918. if (preg_match('/((\d+[m|s])?(\d+[s]?)?)/', $video['start'], $matches)) {
  919. $attributes['start'] = 'start=' . (preg_replace("/[^0-9]/", "", $matches[2]) * 60 + (preg_replace("/[^0-9]/", "", $matches[3])));
  920. }
  921. }
  922. $video['source'] = '//www.youtube.com/embed/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
  923. return video_filter_iframe($video);
  924. }
  925. /**
  926. * HTML5 callback for YouTube (Playlist) codec.
  927. *
  928. * @see video_filter_codec_info()
  929. */
  930. function video_filter_youtube_playlist_html5($video) {
  931. $attributes = array(
  932. 'rel' => $video['related'] ? 'rel=1' : 'rel=0',
  933. 'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
  934. 'wmode' => 'wmode=opaque',
  935. );
  936. $video['source'] = '//www.youtube.com/embed/videoseries?list=' . $video['codec']['matches'][1] . '&amp;' . implode('&amp;', $attributes);
  937. return video_filter_iframe($video);
  938. }
  939. /**
  940. * Callback for Wistia codec.
  941. *
  942. * Adapted from the media_wistia module.
  943. *
  944. * @see video_filter_codec_info()
  945. */
  946. function video_filter_wistia_html5($video) {
  947. $video_code = $video['codec']['matches'][7];
  948. $matches = $video['codec']['matches'];
  949. $embed_type = ($matches[4] == 'projects' || $matches[6] == 'playlists') ? 'playlists' : 'iframe';
  950. // Get embed code via oEmbed.
  951. $endpoint = 'http://fast.wistia.com/oembed';
  952. $options = array(
  953. 'url' => "http://fast.wistia.com/embed/{$embed_type}/{$video_code}",
  954. 'width' => $video['width'],
  955. 'height' => $video['height'],
  956. );
  957. $data = video_filter_oembed_request($endpoint, $options);
  958. $html = $data['html'];
  959. // See if the video source is already an iframe src.
  960. $pattern = '@https?://fast.wistia.(com|net)/embed/(iframe|playlists)/[a-zA-Z0-9]+\?+.+@';
  961. $matches = array();
  962. if (preg_match($pattern, $video['source'], $matches)) {
  963. // Replace the oEmbed iframe src with that provided in the token, in order
  964. // to support embed builder URLs.
  965. $pattern = '@https?://fast.wistia.(com|net)/embed/(iframe|playlists)/[a-zA-Z0-9]+\?[^"]+@';
  966. $replacement = $matches[0];
  967. $html = preg_replace($pattern, $replacement, $html);
  968. }
  969. return $html;
  970. }