Projet

Général

Profil

Paste
Télécharger (3,34 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / wysiwyg_plugins / media.inc @ 74f6bef0

1
<?php
2

    
3
/**
4
 * @file
5
 * Define the WYSIWYG browser plugin.
6
 */
7

    
8
/**
9
 * Implements WYSIWYG's hook_INCLUDE_plugin().
10
 */
11
function media_media_plugin() {
12
  // Include the required browser JS.
13
  // @todo: wyswiyg should allow libraries and multiple js files
14
  // to be defined by this hook.
15
  // @see http://drupal.org/node/1039076
16
  media_include_browser_js();
17

    
18
  // Add the filter handling.
19
  drupal_add_js(drupal_get_path('module', 'media') . '/js/media.filter.js');
20

    
21
  // Plugin definition.
22
  $plugins['media'] = array(
23
    'title' => variable_get('media__wysiwyg_title', t('Media browser')),
24
    'vendor url' => 'http://drupal.org/project/media',
25
    'icon path' => drupal_get_path('module', 'media') . '/images',
26
    'icon file' => 'wysiwyg-media.gif',
27
    'icon title' => variable_get('media__wysiwyg_icon_title', t('Add media')),
28
    // @todo: move this to the plugin directory for the wysiwyg plugin.
29
    'js path' => drupal_get_path('module', 'media') . '/js',
30
    'js file' => 'wysiwyg-media.js',
31
    'css file' => NULL,
32
    'css path' => NULL,
33
    'settings' => array(
34
      'global' => array(
35
        'enabledPlugins' => variable_get('media__wysiwyg_browser_plugins', array()),
36
        'file_directory' => variable_get('media__wysiwyg_upload_directory', ''),
37
        'types' => variable_get('media__wysiwyg_allowed_types', array('audio', 'image', 'video', 'document')),
38
        'id' => 'media_wysiwyg',
39
      ),
40
    ),
41
  );
42

    
43
  return $plugins;
44
}
45

    
46
/**
47
 * Prepares the page to be able to launch the media browser.
48
 *
49
 * Defines default variables.
50
 */
51
function media_include_browser_js() {
52
  static $included;
53
  if ($included) {
54
    return;
55
  }
56
  $included = TRUE;
57
  module_load_include('inc', 'media', 'includes/media.browser');
58
  $javascript = media_browser_js();
59
  foreach ($javascript as $key => $definitions) {
60
    foreach ($definitions as $definition) {
61
      $function = 'drupal_add_' . $key;
62
      // Since the arguments to pass are variable, use call_user_func_array().
63
      // This will not handle all potential drupal_add_*() functions directly
64
      // but covers the js and library needed here, which are unlikely to be
65
      // expanded since this function is only a workaround for a wysiwyg
66
      // limitation.
67
      call_user_func_array($function, $definition);
68
    }
69
  }
70
  // Add wysiwyg-specific settings.
71
  $settings = array('wysiwyg_allowed_attributes' => variable_get('media__wysiwyg_allowed_attributes', array('height', 'width', 'hspace', 'vspace', 'border', 'align', 'style', 'class', 'id', 'usemap', 'data-picture-group', 'data-picture-align')));
72
  drupal_add_js(array('media' => $settings), 'setting');
73
}
74

    
75
/**
76
 * Element validate callback for the media WYSIWYG button.
77
 */
78
function media_wysiwyg_button_element_validate($element, &$form_state) {
79
  if (!empty($element['#value'])) {
80
    $format = filter_format_load($form_state['build_info']['args'][0]->format);
81
    $filters = filter_list_format($format->format);
82
    if (empty($filters['media_filter']->status)) {
83
      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(
84
        '@format-link' => url('admin/config/content/formats/' . $format->format, array('query' => array('destination' => $_GET['q']))),
85
        '@format' => $format->name,
86
      )));
87
    }
88
  }
89

    
90
  return $element;
91
}