video_filter.module 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <?php
  2. /**
  3. * @file
  4. * Video filter is a highly flexible and easy extendable filter module to embed
  5. * any type of video in your site using a simple tag.
  6. */
  7. module_load_include('inc', 'video_filter', 'video_filter.codecs');
  8. /**
  9. * Implements hook_filter_info().
  10. */
  11. function video_filter_filter_info() {
  12. $filters = array();
  13. $filters['video_filter'] = array(
  14. 'title' => t('Video Filter'),
  15. 'description' => t('Substitutes [video:URL] with embedded HTML.'),
  16. 'process callback' => '_video_filter_process',
  17. 'settings callback' => '_video_filter_settings',
  18. 'default settings' => array(
  19. 'video_filter_width' => '400',
  20. 'video_filter_height' => '400',
  21. 'video_filter_autoplay' => 1,
  22. 'video_filter_related' => 1,
  23. 'video_filter_html5' => 1,
  24. ),
  25. 'tips callback' => '_video_filter_tips',
  26. // See http://drupal.org/node/1061244.
  27. 'weight' => -1,
  28. );
  29. return $filters;
  30. }
  31. function _video_filter_settings($form, &$form_state, $filter, $format, $defaults, $filters) {
  32. $settings['video_filter_width'] = array(
  33. '#type' => 'textfield',
  34. '#title' => t('Default width setting'),
  35. '#default_value' => isset($filter->settings['video_filter_width']) ? $filter->settings['video_filter_width'] : $defaults['video_filter_width'],
  36. '#maxlength' => 4,
  37. );
  38. $settings['video_filter_height'] = array(
  39. '#type' => 'textfield',
  40. '#title' => t('Default height setting'),
  41. '#default_value' => isset($filter->settings['video_filter_height']) ? $filter->settings['video_filter_height'] : $defaults['video_filter_height'],
  42. '#maxlength' => 4,
  43. );
  44. $settings['video_filter_autoplay'] = array(
  45. '#type' => 'radios',
  46. '#title' => t('Default autoplay setting'),
  47. '#description' => t('Not all video formats support this setting.'),
  48. '#default_value' => isset($filter->settings['video_filter_autoplay']) ? $filter->settings['video_filter_autoplay'] : $defaults['video_filter_autoplay'],
  49. '#options' => array(
  50. 0 => t('No'),
  51. 1 => t('Yes'),
  52. ),
  53. );
  54. $settings['video_filter_related'] = array(
  55. '#type' => 'radios',
  56. '#title' => t('Related videos setting'),
  57. '#description' => t('Show "related videos"? Not all video formats support this setting.'),
  58. '#default_value' => isset($filter->settings['video_filter_related']) ? $filter->settings['video_filter_related'] : $defaults['video_filter_related'],
  59. '#options' => array(
  60. 0 => t('No'),
  61. 1 => t('Yes'),
  62. ),
  63. );
  64. $settings['video_filter_html5'] = array(
  65. '#type' => 'radios',
  66. '#title' => t('Use HTML5'),
  67. '#description' => t('Use HTML5 if the codec provides it. Makes your videos more device agnostic.'),
  68. '#default_value' => isset($filter->settings['video_filter_html5']) ? $filter->settings['video_filter_html5'] : $defaults['video_filter_html5'],
  69. '#options' => array(
  70. 0 => t('No'),
  71. 1 => t('Yes'),
  72. ),
  73. );
  74. return $settings;
  75. }
  76. function _video_filter_tips($filter, $format, $long = FALSE) {
  77. if ($long) {
  78. $codecs = video_filter_get_codec_info();
  79. $supported = array();
  80. $instructions = array();
  81. foreach ($codecs as $codec) {
  82. $supported[] = $codec['name'];
  83. $instructions[] = isset($codec['instructions']) ? '<li>' . $codec['name'] . ':<br/>' . $codec['instructions'] . '</li>' : '';
  84. }
  85. return t('
  86. <p><strong>Video Filter</strong></p>
  87. <p>You may insert videos from popular video sites by using a simple tag <code>[video:URL]</code>.</p>
  88. <p>Examples:</p>
  89. <ul>
  90. <li>Single video:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId]</code></li>
  91. <li>Random video out of multiple:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId1,http://www.youtube.com/watch?v=uN1qUeId2]</code></li>
  92. <li>Override default autoplay setting: <code>[video:http://www.youtube.com/watch?v=uN1qUeId autoplay:1]</code></li>
  93. <li>Override default width and height:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId width:X height:Y]</code></li>
  94. <li>Override default aspect ratio:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId ratio:4/3]</code></li>
  95. <li>Align the video:<br /><code>[video:http://www.youtube.com/watch?v=uN1qUeId align:right]</code></li>
  96. </ul>
  97. <p>Supported sites: @codecs.</p>
  98. <p>Special instructions:</p>
  99. <small>Some codecs need special input. You\'ll find those instructions here.</small>
  100. <ul>!instructions</ul>', array(
  101. '@codecs' => implode(', ', $supported),
  102. '!instructions' => implode('', $instructions),
  103. )
  104. );
  105. }
  106. else {
  107. return t('You may insert videos with [video:URL]');
  108. }
  109. }
  110. function _video_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
  111. if (preg_match_all('/\[video(\:(.+))?( .+)?\]/isU', $text, $matches_code)) {
  112. foreach ($matches_code[0] as $ci => $code) {
  113. $video = array(
  114. 'source' => $matches_code[2][$ci],
  115. 'autoplay' => $filter->settings['video_filter_autoplay'],
  116. 'related' => $filter->settings['video_filter_related'],
  117. );
  118. // Pick random out of multiple sources separated by comma (,).
  119. if (strstr($video['source'], ',')) {
  120. $sources = explode(',', $video['source']);
  121. $random = array_rand($sources, 1);
  122. $video['source'] = $sources[$random];
  123. }
  124. // Load all codecs.
  125. $codecs = video_filter_get_codec_info();
  126. // Find codec.
  127. foreach ($codecs as $codec_name => $codec) {
  128. if (!is_array($codec['regexp'])) {
  129. $codec['regexp'] = array($codec['regexp']);
  130. }
  131. // Try different regular expressions.
  132. foreach ($codec['regexp'] as $delta => $regexp) {
  133. if (preg_match($regexp, $video['source'], $matches)) {
  134. $video['codec'] = $codec;
  135. $video['codec']['delta'] = $delta;
  136. $video['codec']['matches'] = $matches;
  137. // Used in theme function:
  138. $video['codec']['codec_name'] = $codec_name;
  139. break 2;
  140. }
  141. }
  142. }
  143. // Codec found.
  144. if (isset($video['codec'])) {
  145. // Override default attributes.
  146. if ($matches_code[3][$ci] && preg_match_all('/\s+([a-zA-Z_]+)\:(\s+)?([0-9a-zA-Z\/]+)/i', $matches_code[3][$ci], $matches_attributes)) {
  147. foreach ($matches_attributes[0] as $ai => $attribute) {
  148. $video[$matches_attributes[1][$ai]] = $matches_attributes[3][$ai];
  149. }
  150. }
  151. // Use configured ratio if present, otherwise use that from the codec,
  152. // if set. Fall back to 1.
  153. $ratio = 1;
  154. if (isset($video['ratio']) && preg_match('/(\d+)\/(\d+)/', $video['ratio'], $tratio)) {
  155. // Validate given ratio parameter.
  156. $ratio = $tratio[1] / $tratio[2];
  157. }
  158. elseif (isset($video['codec']['ratio'])) {
  159. $ratio = $video['codec']['ratio'];
  160. }
  161. // Sets video width & height after any user input has been parsed.
  162. // First, check if user has set a width.
  163. if (isset($video['width']) && !isset($video['height'])) {
  164. $video['height'] = $filter->settings['video_filter_height'];
  165. }
  166. // Else, if user has set height.
  167. elseif (isset($video['height']) && !isset($video['width'])) {
  168. $video['width'] = $video['height'] * $ratio;
  169. }
  170. // Maybe both?
  171. elseif (isset($video['height']) && isset($video['width'])) {
  172. $video['width'] = $video['width'];
  173. $video['height'] = $video['height'];
  174. }
  175. // Fall back to defaults.
  176. elseif (!isset($video['height']) && !isset($video['width'])) {
  177. $video['width'] = $filter->settings['video_filter_width'] != '' ? $filter->settings['video_filter_width'] : 400;
  178. $video['height'] = $filter->settings['video_filter_height'] != '' ? $filter->settings['video_filter_height'] : 400;
  179. }
  180. // Default value for control bar height.
  181. $control_bar_height = 0;
  182. if (isset($video['control_bar_height'])) {
  183. // Respect control_bar_height option if present.
  184. $control_bar_height = $video['control_bar_height'];
  185. }
  186. elseif (isset($video['codec']['control_bar_height'])) {
  187. // Respect setting provided by codec otherwise.
  188. $control_bar_height = $video['codec']['control_bar_height'];
  189. }
  190. // Resize to fit within width and height repecting aspect ratio.
  191. if ($ratio) {
  192. $scale_factor = min(array(
  193. ($video['height'] - $control_bar_height),
  194. $video['width'] / $ratio,
  195. ));
  196. $video['height'] = round($scale_factor + $control_bar_height);
  197. $video['width'] = round($scale_factor * $ratio);
  198. }
  199. $video['autoplay'] = (bool) $video['autoplay'];
  200. $video['align'] = (isset($video['align']) && in_array($video['align'], array(
  201. 'left',
  202. 'right',
  203. 'center',
  204. ))) ? $video['align'] : NULL;
  205. // Let modules have final say on video parameters.
  206. drupal_alter('video_filter_video', $video);
  207. if (isset($video['codec']['html5_callback']) && $filter->settings['video_filter_html5'] == 1 && is_callable($video['codec']['html5_callback'], FALSE)) {
  208. $replacement = call_user_func($video['codec']['html5_callback'], $video);
  209. }
  210. elseif (is_callable($video['codec']['callback'], FALSE)) {
  211. $replacement = call_user_func($video['codec']['callback'], $video);
  212. }
  213. else {
  214. // Invalid callback.
  215. $replacement = '<!-- VIDEO FILTER - INVALID CALLBACK IN: ' . $pattern . ' -->';
  216. }
  217. }
  218. // Invalid format.
  219. else {
  220. $replacement = '<!-- VIDEO FILTER - INVALID CODEC IN: ' . $code . ' -->';
  221. }
  222. $text = str_replace($code, $replacement, $text);
  223. }
  224. }
  225. return $text;
  226. }
  227. /**
  228. * Wrapper that calls the theme function.
  229. */
  230. function video_filter_flash($video, $params = array()) {
  231. return theme('video_filter_flash', array('video' => $video, 'params' => $params));
  232. }
  233. /**
  234. * Wrapper that calls the theme function.
  235. */
  236. function video_filter_iframe($video) {
  237. return theme('video_filter_iframe', array('video' => $video));
  238. }
  239. function video_filter_get_codec_info() {
  240. static $codecs;
  241. if (!isset($codecs)) {
  242. $codecs = module_invoke_all('codec_info');
  243. drupal_alter('video_filter_codec_info', $codecs);
  244. }
  245. return $codecs;
  246. }
  247. /**
  248. * Function that outputs the <object> element.
  249. *
  250. * @ingroup themeable
  251. */
  252. function theme_video_filter_flash($variables) {
  253. $output = '';
  254. $video = $variables['video'];
  255. $params = isset($variables['params']) ? $variables['params'] : array();
  256. $classes = video_filter_get_classes($video);
  257. $attributes = '';
  258. if (!empty($video['attributes'])) {
  259. $attributes = drupal_attributes($video['attributes']);
  260. }
  261. $output .= '<div class="video-filter"><object class="' . implode(' ', $classes) . '" type="application/x-shockwave-flash" ';
  262. $output .= 'width="' . $video['width'] . '" height="' . $video['height'] . '" data="' . $video['source'] . '" ' . $attributes . '>' . "\n";
  263. $defaults = array(
  264. 'movie' => $video['source'],
  265. 'wmode' => 'transparent',
  266. 'allowFullScreen' => 'true',
  267. );
  268. $params = array_merge($defaults, (is_array($params) && count($params)) ? $params : array());
  269. foreach ($params as $name => $value) {
  270. $output .= ' <param name="' . $name . '" value="' . $value . '" />' . "\n";
  271. }
  272. $output .= '</object></div>' . "\n";
  273. return $output;
  274. }
  275. /**
  276. * Function that outputs HTML5 compatible iFrame for codecs that support it.
  277. *
  278. * @ingroup themeable
  279. */
  280. function theme_video_filter_iframe($variables) {
  281. $video = $variables['video'];
  282. $classes = video_filter_get_classes($video);
  283. $attributes = '';
  284. if (!empty($video['attributes'])) {
  285. $attributes = drupal_attributes($video['attributes']);
  286. }
  287. $output = '<div class="video-filter"><iframe src="' . $video['source'] . '" width="' . $video['width'] . '" height="' . $video['height'] . '" class="' . implode(' ', $classes) . '" frameborder="0"' . $attributes . '></iframe></div>';
  288. return $output;
  289. }
  290. /**
  291. * Implements hook_theme().
  292. */
  293. function video_filter_theme($existing, $type, $theme, $path) {
  294. return array(
  295. 'video_filter_flash' => array(
  296. 'variables' => array('video' => NULL, 'params' => NULL),
  297. ),
  298. 'video_filter_iframe' => array(
  299. 'variables' => array('video' => NULL, 'params' => NULL),
  300. ),
  301. 'video_filter_dashboard' => array(
  302. 'variables' => array('form' => NULL),
  303. 'template' => 'video_filter_dashboard',
  304. ),
  305. );
  306. }
  307. /**
  308. * Helper function that extracts some classes from $video.
  309. */
  310. function video_filter_get_classes($video) {
  311. $classes = array(
  312. 'video-filter',
  313. // Add codec name.
  314. 'video-' . $video['codec']['codec_name'],
  315. );
  316. // Add alignment.
  317. if (isset($video['align'])) {
  318. $classes[] = 'video-' . $video['align'];
  319. }
  320. // First match is the URL, we don't want that as a class.
  321. unset($video['codec']['matches'][0]);
  322. foreach ($video['codec']['matches'] as $match) {
  323. $classes[] = 'vf-' . strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $match));
  324. }
  325. return $classes;
  326. }
  327. /**
  328. * Implements hook_menu().
  329. */
  330. function video_filter_menu() {
  331. $items = array();
  332. $items['video_filter/dashboard/%'] = array(
  333. 'title' => 'Videofilter',
  334. 'description' => 'Dashboard',
  335. 'page callback' => 'video_filter_dashboard_page',
  336. 'access arguments' => array('access content'),
  337. 'type' => MENU_CALLBACK,
  338. 'page arguments' => array(2),
  339. 'theme callback' => '_video_filter_dashboard_theme',
  340. );
  341. $items['video_filter/instructions'] = array(
  342. 'title' => 'Videofilter instructions',
  343. 'description' => 'instructions',
  344. 'page callback' => 'video_filter_instructions_page',
  345. 'access arguments' => array('access content'),
  346. 'type' => MENU_CALLBACK,
  347. 'theme callback' => '_video_filter_dashboard_theme',
  348. );
  349. return $items;
  350. }
  351. /**
  352. * Return the theme name to be used when showing linkit dashboard
  353. */
  354. function _video_filter_dashboard_theme() {
  355. return variable_get('admin_theme', 'seven');
  356. }
  357. /**
  358. * Template preprocess function for video_filter_dashboard().
  359. */
  360. function template_preprocess_video_filter_dashboard(&$variables) {
  361. // Construct page title.
  362. $variables['head_title'] = t('Video filter dashboard');
  363. $variables['head'] = drupal_get_html_head();
  364. $variables['help'] = theme('help');
  365. $variables['language'] = $GLOBALS['language'];
  366. $variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
  367. $variables['messages'] = isset($variables['show_messages']) ? theme('status_messages') : '';
  368. $variables['css'] = drupal_add_css();
  369. $variables['styles'] = drupal_get_css();
  370. $variables['scripts'] = drupal_get_js();
  371. }
  372. /**
  373. * Creates the dashboard.
  374. */
  375. function video_filter_dashboard_page($editor) {
  376. module_invoke('admin_menu', 'suppress');
  377. // Add CSS.
  378. drupal_add_css(drupal_get_path('module', 'video_filter') . '/css/video_filter.css');
  379. switch ($editor) {
  380. case 'wysiwyg_tinymce':
  381. // Add JavaScript.
  382. drupal_add_js(wysiwyg_get_path('tinymce') . '/jscripts/tiny_mce/tiny_mce_popup.js');
  383. drupal_add_js(drupal_get_path('module', 'video_filter') . '/editors/tinymce/video_filter.js');
  384. break;
  385. case 'ckeditor':
  386. case 'wysiwyg_ckeditor':
  387. // Add JavaScript.
  388. drupal_add_js(drupal_get_path('module', 'video_filter') . '/editors/ckeditor/video_filter_dialog.js');
  389. break;
  390. case 'fckeditor':
  391. case 'wysiwyg_fckeditor':
  392. // Add JavaScript.
  393. drupal_add_js(drupal_get_path('module', 'video_filter') . '/editors/fckeditor/video_filter/video_filter_dialog.js');
  394. break;
  395. }
  396. $form = drupal_get_form('_video_filter_form');
  397. print theme('video_filter_dashboard', array('form' => render($form)));
  398. exit();
  399. }
  400. /**
  401. * Creates the instructions page.
  402. */
  403. function video_filter_instructions_page() {
  404. module_invoke('admin_menu', 'suppress');
  405. $form = drupal_get_form('_video_filter_instructions_form');
  406. print theme('video_filter_dashboard', array('form' => render($form)));
  407. exit();
  408. }
  409. function _video_filter_form() {
  410. $form['video_filter'] = array(
  411. '#type' => 'fieldset',
  412. '#title' => t('Insert Video'),
  413. '#weight' => 0,
  414. '#collapsible' => FALSE,
  415. '#collapsed' => FALSE,
  416. '#attributes' => array('class' => array('clearfix')),
  417. );
  418. $form['video_filter']['file_url'] = array(
  419. '#type' => 'textfield',
  420. '#title' => t('Video URL'),
  421. '#maxlength' => 255,
  422. '#size' => 80,
  423. '#default_value' => '',
  424. '#weight' => 1,
  425. );
  426. $form['video_filter']['width'] = array(
  427. '#type' => 'textfield',
  428. '#title' => t('Width'),
  429. '#maxlength' => 255,
  430. '#size' => 80,
  431. '#default_value' => '',
  432. '#weight' => 2,
  433. );
  434. $form['video_filter']['height'] = array(
  435. '#type' => 'textfield',
  436. '#title' => t('Height'),
  437. '#maxlength' => 255,
  438. '#size' => 80,
  439. '#default_value' => '',
  440. '#weight' => 3,
  441. );
  442. $form['video_filter']['align'] = array(
  443. '#type' => 'select',
  444. '#title' => t('Align'),
  445. '#default_value' => 'none',
  446. '#options' => array(
  447. 'none' => t('None'),
  448. 'left' => t('Left'),
  449. 'right' => t('Right'),
  450. 'center' => t('Center'),
  451. ),
  452. '#weight' => 4,
  453. );
  454. $form['video_filter']['autoplay'] = array(
  455. '#type' => 'checkbox',
  456. '#title' => t('Autoplay'),
  457. '#weight' => 5,
  458. );
  459. $form += _video_filter_instructions_form();
  460. $form['cancel'] = array(
  461. '#type' => 'button',
  462. '#value' => t('Cancel'),
  463. '#weight' => 98,
  464. );
  465. $form['insert'] = array(
  466. '#type' => 'button',
  467. '#value' => t('Insert'),
  468. '#weight' => 99,
  469. );
  470. return $form;
  471. }
  472. function _video_filter_instructions_form() {
  473. $form['instructions'] = array(
  474. '#type' => 'fieldset',
  475. '#title' => t('Instructions'),
  476. '#collapsible' => TRUE,
  477. '#collapsed' => TRUE,
  478. '#attributes' => array('class' => array('clearfix')),
  479. '#weight' => 97,
  480. );
  481. $text = '<p>' . t('Insert a 3rd party video from one of the following providers.') . '</p>';
  482. $text .= _video_filter_instructions();
  483. $form['instructions']['text'] = array(
  484. '#type' => 'item',
  485. '#markup' => $text,
  486. );
  487. return $form;
  488. }
  489. /**
  490. * Implements hook_ckeditor_plugin().
  491. */
  492. function video_filter_ckeditor_plugin() {
  493. $plugins = array();
  494. $plugins['video_filter'] = array(
  495. 'name' => 'video_filter',
  496. 'desc' => t('Plugin to directly embed videos with the video filter module.'),
  497. 'path' => drupal_get_path('module', 'video_filter') . '/editors/ckeditor/',
  498. 'buttons' => array(
  499. 'video_filter' => array(
  500. 'label' => t('Video filter'),
  501. 'icon' => 'video_filter.png',
  502. ),
  503. ),
  504. );
  505. return $plugins;
  506. }
  507. function video_filter_wysiwyg_plugin($editor, $version) {
  508. _video_filter_add_settings('wysiwyg_' . $editor);
  509. $plugins = array();
  510. switch ($editor) {
  511. case 'ckeditor':
  512. $plugins['video_filter'] = array(
  513. 'path' => drupal_get_path('module', 'video_filter') . '/editors/ckeditor/',
  514. 'buttons' => array('video_filter' => t('Video filter')),
  515. 'url' => 'http://drupal.org/project/video_filter',
  516. 'load' => TRUE,
  517. );
  518. break;
  519. case 'fckeditor':
  520. $plugins['video_filter'] = array(
  521. 'path' => drupal_get_path('module', 'video_filter') . '/editors/fckeditor/',
  522. 'buttons' => array('video_filter' => t('Video filter')),
  523. 'url' => 'http://drupal.org/project/video_filter',
  524. 'load' => TRUE,
  525. );
  526. break;
  527. case 'tinymce':
  528. $plugins['video_filter'] = array(
  529. 'path' => drupal_get_path('module', 'video_filter') . '/editors/tinymce',
  530. 'filename' => 'editor_plugin.js',
  531. 'buttons' => array('video_filter' => t('Video filter')),
  532. 'url' => 'http://drupal.org/project/video_filter',
  533. 'load' => TRUE,
  534. );
  535. break;
  536. }
  537. return $plugins;
  538. }
  539. /**
  540. * Implements hook_element_info_alter().
  541. */
  542. function video_filter_element_info_alter(&$types) {
  543. if (isset($types['text_format']['#pre_render']) && is_array($types['text_format']['#pre_render'])) {
  544. if (in_array('ckeditor_pre_render_text_format', $types['text_format']['#pre_render'])) {
  545. _video_filter_add_settings('ckeditor');
  546. }
  547. }
  548. }
  549. function _video_filter_add_settings($editor) {
  550. static $editor_settings_added = array();
  551. static $global_settings_added = FALSE;
  552. if (!isset($editor_settings_added[$editor])) {
  553. $editor_settings_added[$editor] = TRUE;
  554. // Add popup url.
  555. $settings = array(
  556. 'video_filter' => array(
  557. 'url' => array($editor => url('video_filter/dashboard/' . $editor)),
  558. 'instructions_url' => url('video_filter/instructions'),
  559. ),
  560. );
  561. drupal_add_js($settings, 'setting');
  562. }
  563. if (!$global_settings_added) {
  564. $global_settings_added = TRUE;
  565. // Add global settings for video_filter.
  566. $settings = array(
  567. 'video_filter' => array(
  568. 'modulepath' => drupal_get_path('module', 'video_filter'),
  569. ),
  570. );
  571. drupal_add_js($settings, 'setting');
  572. }
  573. }
  574. /**
  575. * Parses Codec into instructions for WYSIWYG popup.
  576. */
  577. function _video_filter_instructions() {
  578. $codecs = video_filter_get_codec_info();
  579. $output = '<ul>';
  580. foreach ($codecs as $codec) {
  581. $output .= '<li><strong>' . $codec['name'] . '</strong><br />' . $codec['sample_url'] . '</li>';
  582. }
  583. $output .= '</ul>';
  584. return $output;
  585. }
  586. /**
  587. * Requests data from an oEmbed provider.
  588. *
  589. * Note: This function currently only supports JSON responses.
  590. *
  591. * @param string $endpoint
  592. * The provider endpoint URL.
  593. * @param array $arguments
  594. * An associative array of URL arguments to send the provider.
  595. *
  596. * @return array|FALSE
  597. * An array of data if the request is successful, otherwise FALSE.
  598. *
  599. * @todo Support other response formats than JSON?
  600. */
  601. function video_filter_oembed_request($endpoint, array $arguments) {
  602. // Make HTTP request.
  603. $result = drupal_http_request(url($endpoint, array('query' => $arguments)));
  604. if ($data = json_decode($result->data)) {
  605. // Success.
  606. return (array) $data;
  607. }
  608. else {
  609. // Failure. Either the resource doesn't exist or there was an error with the
  610. // request.
  611. return FALSE;
  612. }
  613. }