Revision 2b3c8cc1
Added by Assos Assos about 9 years ago
drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc | ||
---|---|---|
56 | 56 |
* @see hook_media_wysiwyg_token_to_markup_alter() |
57 | 57 |
*/ |
58 | 58 |
function media_wysiwyg_token_to_markup($match, $wysiwyg = FALSE) { |
59 |
static $recursion_stop; |
|
59 | 60 |
$settings = array(); |
60 | 61 |
$match = str_replace("[[", "", $match); |
61 | 62 |
$match = str_replace("]]", "", $match); |
... | ... | |
107 | 108 |
if (!$file) { |
108 | 109 |
throw new Exception('Could not load media object'); |
109 | 110 |
} |
111 |
// Check if we've got a recursion. Happens because a file_load() may |
|
112 |
// triggers file_entity_is_page() which then again triggers a file load. |
|
113 |
if (isset($recursion_stop[$file->fid])) { |
|
114 |
return ''; |
|
115 |
} |
|
116 |
$recursion_stop[$file->fid] = TRUE; |
|
117 |
|
|
110 | 118 |
$tag_info['file'] = $file; |
111 | 119 |
|
112 | 120 |
// The class attributes is a string, but drupal requires it to be |
... | ... | |
117 | 125 |
|
118 | 126 |
// Grab the potentially overrided fields from the file. |
119 | 127 |
$fields = media_wysiwyg_filter_field_parser($tag_info); |
128 |
foreach ($fields as $key => $value) { |
|
129 |
$file->{$key} = $value; |
|
130 |
} |
|
120 | 131 |
|
121 | 132 |
$attributes = is_array($tag_info['attributes']) ? $tag_info['attributes'] : array(); |
122 | 133 |
$attribute_whitelist = variable_get('media_wysiwyg_wysiwyg_allowed_attributes', _media_wysiwyg_wysiwyg_allowed_attributes_default()); |
... | ... | |
165 | 176 |
|
166 | 177 |
if ($wysiwyg) { |
167 | 178 |
$settings['wysiwyg'] = $wysiwyg; |
168 |
// If sending markup to a WYSIWYG, we need to pass the file infomation so |
|
179 |
// If sending markup to a WYSIWYG, we need to pass the file information so
|
|
169 | 180 |
// that an inline macro can be generated when the WYSIWYG is detached. |
170 | 181 |
// The WYSIWYG plugin is expecting this information in the |
171 | 182 |
// Drupal.settings.mediaDataMap variable. |
... | ... | |
178 | 189 |
); |
179 | 190 |
drupal_add_js(array('mediaDataMap' => array($file->fid => $data)), 'setting'); |
180 | 191 |
$element['#attributes']['data-fid'] = $file->fid; |
192 |
$element['#attributes']['data-media-element'] = '1'; |
|
181 | 193 |
$element['#attributes']['class'][] = 'media-element'; |
182 | 194 |
} |
183 | 195 |
else { |
184 | 196 |
// Display the field elements. |
185 | 197 |
$element = array(); |
198 |
// Render the file entity, for sites using the file_entity rendering method. |
|
199 |
if (variable_get('media_wysiwyg_default_render', 'file_entity') == 'file_entity') { |
|
200 |
$element['content'] = file_view($file, $tag_info['view_mode']); |
|
201 |
} |
|
186 | 202 |
$element['content']['file'] = media_wysiwyg_get_file_without_label($file, $tag_info['view_mode'], $settings); |
187 | 203 |
// Overwrite or set the file #alt attribute if it has been set in this |
188 | 204 |
// instance. |
... | ... | |
194 | 210 |
if (!empty($element['content']['file']['#attributes']['title'])) { |
195 | 211 |
$element['content']['file']['#title'] = $element['content']['file']['#attributes']['title']; |
196 | 212 |
} |
197 |
field_attach_prepare_view('file', array($file->fid => $file), $tag_info['view_mode']); |
|
198 |
entity_prepare_view('file', array($file->fid => $file)); |
|
199 |
$element['content'] += field_attach_view('file', $file, $tag_info['view_mode']); |
|
213 |
// For sites using the legacy field_attach rendering method, attach fields. |
|
214 |
if (variable_get('media_wysiwyg_default_render', 'file_entity') == 'field_attach') { |
|
215 |
field_attach_prepare_view('file', array($file->fid => $file), $tag_info['view_mode']); |
|
216 |
entity_prepare_view('file', array($file->fid => $file)); |
|
217 |
$element['content'] += field_attach_view('file', $file, $tag_info['view_mode']); |
|
218 |
} |
|
200 | 219 |
if (count(element_children($element['content'])) > 1) { |
201 | 220 |
// Add surrounding divs to group them together. |
202 | 221 |
// We dont want divs when there are no additional fields to allow files |
... | ... | |
208 | 227 |
'media-' . $element['content']['file']['#view_mode'] |
209 | 228 |
); |
210 | 229 |
} |
230 |
|
|
231 |
// Conditionally add a pre-render if the media filter output is be cached. |
|
232 |
$filters = filter_get_filters(); |
|
233 |
if (!isset($filters['media_filter']['cache']) || $filters['media_filter']['cache']) { |
|
234 |
$element['#pre_render'][] = 'media_wysiwyg_pre_render_cached_filter'; |
|
235 |
} |
|
211 | 236 |
} |
212 | 237 |
drupal_alter('media_wysiwyg_token_to_markup', $element, $tag_info, $settings); |
213 |
return drupal_render($element); |
|
238 |
$output = drupal_render($element); |
|
239 |
unset($recursion_stop[$file->fid]); |
|
240 |
return $output; |
|
214 | 241 |
} |
215 | 242 |
|
216 | 243 |
/** |
... | ... | |
241 | 268 |
return $fields; |
242 | 269 |
} |
243 | 270 |
|
244 |
/** |
|
245 |
* Builds a map of media tags in the element. |
|
246 |
* |
|
247 |
* Builds a map of the media tags in an element that are being rendered to their |
|
248 |
* rendered HTML. The map is stored in JS, so we can transform them when the |
|
249 |
* editor is being displayed. |
|
250 |
*/ |
|
251 |
function media_wysiwyg_pre_render_text_format($element) { |
|
252 |
// filter_process_format() copies properties to the expanded 'value' child |
|
253 |
// element. |
|
254 |
if (!isset($element['format'])) { |
|
255 |
return $element; |
|
256 |
} |
|
257 |
|
|
258 |
$field = &$element['value']; |
|
259 |
$settings = array( |
|
260 |
'field' => $field['#id'], |
|
261 |
); |
|
262 |
|
|
263 |
$tagmap = _media_wysiwyg_generate_tagMap($field['#value']); |
|
264 |
|
|
265 |
if (isset($tagmap)) { |
|
266 |
drupal_add_js(array('tagmap' => $tagmap), 'setting'); |
|
267 |
} |
|
268 |
return $element; |
|
269 |
} |
|
270 |
|
|
271 | 271 |
/** |
272 | 272 |
* Creates map of inline media tags. |
273 | 273 |
* |
... | ... | |
357 | 357 |
drupal_alter('media_wysiwyg_wysiwyg_allowed_view_modes', $view_modes, $file); |
358 | 358 |
return $view_modes; |
359 | 359 |
} |
360 |
|
|
361 |
/** |
|
362 |
* #pre_render callback: Modify the element if the render cache is filtered. |
|
363 |
*/ |
|
364 |
function media_wysiwyg_pre_render_cached_filter($element) { |
|
365 |
// Remove contextual links since they are not compatible with cached filtered |
|
366 |
// text. |
|
367 |
if (isset($element['content']['#contextual_links'])) { |
|
368 |
unset($element['content']['#contextual_links']); |
|
369 |
} |
|
370 |
|
|
371 |
return $element; |
|
372 |
} |
Also available in: Unified diff
Weekly update of contrib modules