media.inc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @file
  4. * Define the WYSIWYG browser plugin.
  5. */
  6. /**
  7. * Implementation of WYSIWYG's hook_INCLUDE_plugin().
  8. */
  9. function media_media_plugin() {
  10. // Include the required browser JS.
  11. // @todo: wyswiyg should allow libraries and multiple js files
  12. // to be defined by this hook.
  13. // @see http://drupal.org/node/1039076
  14. media_include_browser_js();
  15. // Plugin definition
  16. $plugins['media'] = array(
  17. 'title' => t(media_variable_get('wysiwyg_title')),
  18. 'vendor url' => 'http://drupal.org/project/media',
  19. 'icon path' => drupal_get_path('module', 'media') . '/images',
  20. 'icon file' => 'wysiwyg-media.gif',
  21. 'icon title' => t(media_variable_get('wysiwyg_icon_title')),
  22. // @todo: move this to the plugin directory for the wysiwyg plugin.
  23. 'js path' => drupal_get_path('module', 'media') . '/js',
  24. 'js file' => 'wysiwyg-media.js',
  25. 'css file' => NULL,
  26. 'css path' => NULL,
  27. 'settings' => array(
  28. 'global' => array(
  29. 'types' => media_variable_get('wysiwyg_allowed_types'),
  30. 'id' => 'media_wysiwyg',
  31. ),
  32. ),
  33. );
  34. return $plugins;
  35. }
  36. /**
  37. * Prepares the page to be able to launch the media browser.
  38. *
  39. * Defines default variables.
  40. */
  41. function media_include_browser_js() {
  42. static $included;
  43. if ($included) {
  44. return;
  45. }
  46. $included = TRUE;
  47. module_load_include('inc', 'media', 'includes/media.browser');
  48. $javascript = media_browser_js();
  49. foreach ($javascript as $key => $definitions) {
  50. foreach ($definitions as $definition) {
  51. $function = 'drupal_add_' . $key;
  52. // Since the arguments to pass are variable, use call_user_func_array().
  53. // This will not handle all potential drupal_add_*() functions directly
  54. // but covers the js and library needed here, which are unlikely to be
  55. // expanded since this function is only a workaround for a wysiwyg limitation.
  56. call_user_func_array($function, $definition);
  57. }
  58. }
  59. // Add wysiwyg-specific settings.
  60. $settings = array('blacklist' => array('src', 'fid', 'view_mode', 'format'));
  61. drupal_add_js(array('media' => $settings), 'setting');
  62. }
  63. /**
  64. * Element validate callback for the media WYSIWYG button.
  65. */
  66. function media_wysiwyg_button_element_validate($element, &$form_state) {
  67. if (!empty($element['#value'])) {
  68. $format = filter_format_load($form_state['build_info']['args'][0]->format);
  69. $filters = filter_list_format($format->format);
  70. if (empty($filters['media_filter']->status)) {
  71. form_error($element, t('The <em>Convert Media tags to markup</em> filter must be enabled for the <a href="@format-link">@format format</a> in order to use the Media browser WYSIWYG button.', array(
  72. '@format-link' => url('admin/config/content/formats/' . $format->format, array('query' => array('destination' => $_GET['q']))),
  73. '@format' => $format->name,
  74. )));
  75. }
  76. }
  77. return $element;
  78. }