Revision 2b3c8cc1
Added by Assos Assos about 9 years ago
drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.module | ||
---|---|---|
31 | 31 |
* Implements hook_menu(). |
32 | 32 |
*/ |
33 | 33 |
function media_wysiwyg_menu() { |
34 |
$items = array(); |
|
35 |
|
|
34 | 36 |
$items['media/%file/format-form'] = array( |
35 | 37 |
'title' => 'Style selector', |
36 | 38 |
'description' => 'Choose a format for a piece of media', |
37 | 39 |
'page callback' => 'drupal_get_form', |
38 | 40 |
'page arguments' => array('media_wysiwyg_format_form', 1), |
39 |
'access callback' => 'file_entity_access',
|
|
41 |
'access callback' => 'media_wysiwyg_access',
|
|
40 | 42 |
'access arguments' => array('view', 1), |
41 | 43 |
'file' => 'includes/media_wysiwyg.pages.inc', |
42 | 44 |
'theme callback' => 'media_dialog_get_theme_name', |
... | ... | |
46 | 48 |
return $items; |
47 | 49 |
} |
48 | 50 |
|
51 |
/** |
|
52 |
* Implements hook_permission(). |
|
53 |
*/ |
|
54 |
function media_wysiwyg_permission() { |
|
55 |
return array( |
|
56 |
'use media wysiwyg' => array( |
|
57 |
'title' => t('Use Media WYSIWYG in an editor'), |
|
58 |
// Marked restrict because the WYSIWYG forms generate image derivatives, |
|
59 |
// which could lead to a DoS security vulnerability. |
|
60 |
'restrict access' => TRUE, |
|
61 |
), |
|
62 |
); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* Access callback for WYSIWYG Media. |
|
67 |
*/ |
|
68 |
function media_wysiwyg_access($op, $file = NULL, $account = NULL) { |
|
69 |
return user_access('use media wysiwyg', $account) && file_entity_access($op, $file, $account); |
|
70 |
} |
|
71 |
|
|
49 | 72 |
/** |
50 | 73 |
* Implements hook_element_info_alter(). |
51 | 74 |
*/ |
... | ... | |
53 | 76 |
$types['text_format']['#pre_render'][] = 'media_wysiwyg_pre_render_text_format'; |
54 | 77 |
} |
55 | 78 |
|
79 |
/** |
|
80 |
* Builds a map of media tags in the element. |
|
81 |
* |
|
82 |
* Builds a map of the media tags in an element that are being rendered to their |
|
83 |
* rendered HTML. The map is stored in JS, so we can transform them when the |
|
84 |
* editor is being displayed. |
|
85 |
*/ |
|
86 |
function media_wysiwyg_pre_render_text_format($element) { |
|
87 |
// filter_process_format() copies properties to the expanded 'value' child |
|
88 |
// element. |
|
89 |
if (!isset($element['format'])) { |
|
90 |
return $element; |
|
91 |
} |
|
92 |
|
|
93 |
$field = &$element['value']; |
|
94 |
$settings = array( |
|
95 |
'field' => $field['#id'], |
|
96 |
); |
|
97 |
|
|
98 |
if (!isset($field['#value'])) { |
|
99 |
return $element; |
|
100 |
} |
|
101 |
|
|
102 |
$tagmap = _media_wysiwyg_generate_tagMap($field['#value']); |
|
103 |
|
|
104 |
if (isset($tagmap)) { |
|
105 |
$element['#attached']['js'][] = array( |
|
106 |
'data' => array( |
|
107 |
'tagmap' => $tagmap, |
|
108 |
), |
|
109 |
'type' => 'setting', |
|
110 |
); |
|
111 |
} |
|
112 |
|
|
113 |
// Load the media browser library. |
|
114 |
$element['#attached']['library'][] = array('media', 'media_browser'); |
|
115 |
$element['#attached']['library'][] = array('media', 'media_browser_settings'); |
|
116 |
|
|
117 |
// Add wysiwyg-specific settings. |
|
118 |
$settings = array('wysiwyg_allowed_attributes' => variable_get('media_wysiwyg_wysiwyg_allowed_attributes', _media_wysiwyg_wysiwyg_allowed_attributes_default())); |
|
119 |
$element['#attached']['js'][] = array( |
|
120 |
'data' => array( |
|
121 |
'media' => $settings, |
|
122 |
), |
|
123 |
'type' => 'setting', |
|
124 |
); |
|
125 |
|
|
126 |
// Add filter handling. |
|
127 |
$element['#attached']['js'][] = drupal_get_path('module', 'media_wysiwyg') . '/js/media_wysiwyg.filter.js'; |
|
128 |
|
|
129 |
// Add CKEditor-specific JS. |
|
130 |
if (module_exists('ckeditor')) { |
|
131 |
$element['#attached']['js'][] = array( |
|
132 |
'data' => drupal_get_path('module', 'media_wysiwyg') . '/wysiwyg_plugins/media_ckeditor/library.js', |
|
133 |
'type' => 'file', |
|
134 |
'scope' => 'footer', |
|
135 |
'weight' => -20, |
|
136 |
); |
|
137 |
} |
|
138 |
|
|
139 |
return $element; |
|
140 |
} |
|
141 |
|
|
56 | 142 |
/** |
57 | 143 |
* Implements hook_form_FORM_ID_alter(). |
58 | 144 |
*/ |
... | ... | |
121 | 207 |
); |
122 | 208 |
} |
123 | 209 |
|
210 |
$form['wysiwyg']['media_wysiwyg_default_render'] = array( |
|
211 |
'#type' => 'radios', |
|
212 |
'#title' => t('How should file entities be rendered within a text field?'), |
|
213 |
'#description' => t("Full file entity rendering is the best choice for most sites. It respects the file entity's display settings specified at admin/structure/file-types. If your site already uses the legacy method, note that changing this option will affect your site's markup. Testing it on a non-production site is recommended."), |
|
214 |
'#options' => array( |
|
215 |
'file_entity' => 'Full file entity rendering', |
|
216 |
'field_attach' => 'Legacy rendering (using field attach)', |
|
217 |
), |
|
218 |
'#default_value' => variable_get('media_wysiwyg_default_render', 'file_entity'), |
|
219 |
); |
|
220 |
|
|
124 | 221 |
$form['wysiwyg']['media_wysiwyg_wysiwyg_allowed_types'] = array( |
125 | 222 |
'#type' => 'checkboxes', |
126 | 223 |
'#title' => t('Allowed types in WYSIWYG'), |
... | ... | |
158 | 255 |
return $filters; |
159 | 256 |
} |
160 | 257 |
|
161 |
/** |
|
162 |
* Prepares the page to be able to launch the media browser. |
|
163 |
* |
|
164 |
* Defines default variables. |
|
165 |
*/ |
|
166 |
function media_wysiwyg_include_browser_js() { |
|
167 |
static $included; |
|
168 |
if ($included) { |
|
169 |
return; |
|
170 |
} |
|
171 |
$included = TRUE; |
|
172 |
module_load_include('inc', 'media', 'includes/media.browser'); |
|
173 |
$javascript = media_browser_js(); |
|
174 |
foreach ($javascript as $key => $definitions) { |
|
175 |
foreach ($definitions as $definition) { |
|
176 |
$function = 'drupal_add_' . $key; |
|
177 |
// Since the arguments to pass are variable, use call_user_func_array(). |
|
178 |
// This will not handle all potential drupal_add_*() functions directly |
|
179 |
// but covers the js and library needed here, which are unlikely to be |
|
180 |
// expanded since this function is only a workaround for a wysiwyg |
|
181 |
// limitation. |
|
182 |
call_user_func_array($function, $definition); |
|
183 |
} |
|
184 |
} |
|
185 |
// Add wysiwyg-specific settings. |
|
186 |
$settings = array('wysiwyg_allowed_attributes' => variable_get('media_wysiwyg_wysiwyg_allowed_attributes', _media_wysiwyg_wysiwyg_allowed_attributes_default())); |
|
187 |
drupal_add_js(array('media' => $settings), 'setting'); |
|
188 |
} |
|
189 |
|
|
190 | 258 |
/** |
191 | 259 |
* Implements hook_wysiwyg_include_directory(). |
192 | 260 |
*/ |
Also available in: Unified diff
Weekly update of contrib modules