Révision da542b7b
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc | ||
---|---|---|
5 | 5 |
* Functions related to the WYSIWYG editor and the media input filter. |
6 | 6 |
*/ |
7 | 7 |
|
8 |
define('MEDIA_WYSIWYG_TOKEN_REGEX', '/\[\[.*?\]\]/s'); |
|
8 |
define('MEDIA_WYSIWYG_TOKEN_REGEX', '/\[\[\{"fid".*?\]\]/s');
|
|
9 | 9 |
|
10 | 10 |
/** |
11 | 11 |
* Filter callback for media markup filter. |
... | ... | |
27 | 27 |
return $rendered_text; |
28 | 28 |
} |
29 | 29 |
|
30 |
/** |
|
31 |
* Filter callback to remove paragraph tags surrounding embedded media. |
|
32 |
*/ |
|
33 |
function media_wysiwyg_filter_paragraph_fix($text) { |
|
34 |
$html_dom = filter_dom_load($text); |
|
35 |
foreach ($html_dom->getElementsByTagName('p') as $paragraph) { |
|
36 |
if (preg_match(MEDIA_WYSIWYG_TOKEN_REGEX, $paragraph->nodeValue)) { |
|
37 |
$sibling = $paragraph->firstChild; |
|
38 |
do { |
|
39 |
$next = $sibling->nextSibling; |
|
40 |
$paragraph->parentNode->insertBefore($sibling, $paragraph); |
|
41 |
} while ($sibling = $next); |
|
42 |
$paragraph->parentNode->removeChild($paragraph); |
|
43 |
} |
|
44 |
} |
|
45 |
$text = filter_dom_serialize($html_dom); |
|
46 |
return $text; |
|
47 |
} |
|
48 |
|
|
30 | 49 |
/** |
31 | 50 |
* Parses the contents of a CSS declaration block. |
32 | 51 |
* |
... | ... | |
133 | 152 |
$tag_info['attributes']['class'] = explode(" ", $tag_info['attributes']['class']); |
134 | 153 |
} |
135 | 154 |
|
136 |
// Grab the potentially overrided fields from the file.
|
|
155 |
// Grab the potentially overridden fields from the file.
|
|
137 | 156 |
$fields = media_wysiwyg_filter_field_parser($tag_info); |
138 | 157 |
foreach ($fields as $key => $value) { |
139 | 158 |
$file->{$key} = $value; |
... | ... | |
146 | 165 |
|
147 | 166 |
if (!empty($tag_info['attributes']) && is_array($tag_info['attributes'])) { |
148 | 167 |
$settings['attributes'] = array_intersect_key($tag_info['attributes'], array_flip($attribute_whitelist)); |
149 |
$settings['fields'] = $fields; |
|
150 | 168 |
|
151 | 169 |
// Many media formatters will want to apply width and height independently |
152 | 170 |
// of the style attribute or the corresponding HTML attributes, so pull |
... | ... | |
172 | 190 |
} |
173 | 191 |
} |
174 | 192 |
} |
193 |
// Update file metadata from the potentially overridden tag info. |
|
194 |
foreach (array('width', 'height') as $dimension) { |
|
195 |
if (isset($settings['attributes'][$dimension])) { |
|
196 |
$file->metadata[$dimension] = $settings['attributes'][$dimension]; |
|
197 |
} |
|
198 |
} |
|
175 | 199 |
} |
176 | 200 |
catch (Exception $e) { |
177 | 201 |
watchdog('media', 'Unable to render media from %tag. Error: %error', array('%tag' => $tag, '%error' => $e->getMessage())); |
... | ... | |
266 | 290 |
$parsed_field = explode('[', str_replace(']', '', $field_name)); |
267 | 291 |
$ref = &$fields; |
268 | 292 |
|
293 |
// Certain types of fields, because of differences in markup, end up |
|
294 |
// here with incomplete arrays. Make a best effort to support as many |
|
295 |
// types of fields as possible. |
|
296 |
// Single-value select lists show up here with only 2 array items. |
|
297 |
if (count($parsed_field) == 2) { |
|
298 |
$info = field_info_field($parsed_field[0]); |
|
299 |
if ($info && !empty($info['columns'])) { |
|
300 |
// Assume single-value. |
|
301 |
$parsed_field[] = 0; |
|
302 |
// Next tack on the column for this field. |
|
303 |
$parsed_field[] = key($info['columns']); |
|
304 |
} |
|
305 |
} |
|
306 |
// Multi-value select lists show up here with 3 array items. |
|
307 |
elseif (count($parsed_field) == 3 && is_numeric($parsed_field[2])) { |
|
308 |
$info = field_info_field($parsed_field[0]); |
|
309 |
// They just need the value column. |
|
310 |
$parsed_field[3] = key($info['columns']); |
|
311 |
} |
|
312 |
|
|
269 | 313 |
// Each key of the field needs to be the child of the previous key. |
270 | 314 |
foreach ($parsed_field as $key) { |
271 | 315 |
if (!isset($ref[$key])) { |
... | ... | |
307 | 351 |
// between function calls. Since media_process_form is multiple times |
308 | 352 |
// with same form, this function is also called multiple times. |
309 | 353 |
static $tagmap = array(); |
310 |
preg_match_all("/\[\[.*?\]\]/s", $text, $matches, PREG_SET_ORDER);
|
|
354 |
preg_match_all(MEDIA_WYSIWYG_TOKEN_REGEX, $text, $matches, PREG_SET_ORDER);
|
|
311 | 355 |
foreach ($matches as $match) { |
312 | 356 |
// We see if tagContent is already in $tagMap, if not we add it |
313 | 357 |
// to $tagmap. If we return an empty array, we break embeddings of the same |
Formats disponibles : Unified diff
Weekly update of contrib modules