Révision ba3b3627
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc | ||
---|---|---|
323 | 323 |
$element = array(); |
324 | 324 |
// Render the file entity, for sites using the file_entity rendering method. |
325 | 325 |
if (variable_get('media_wysiwyg_default_render', 'file_entity') == 'file_entity') { |
326 |
$element['content'] = file_view($file, $tag_info['view_mode']); |
|
326 |
$element['content'] = file_view($file, $tag_info['view_mode'], $langcode);
|
|
327 | 327 |
} |
328 | 328 |
$element['content']['file'] = media_wysiwyg_get_file_without_label($file, $tag_info['view_mode'], $settings, $langcode); |
329 | 329 |
// Overwrite or set the file #alt attribute if it has been set in this |
... | ... | |
388 | 388 |
} |
389 | 389 |
|
390 | 390 |
/** |
391 |
* Parse the field array from the collapsed AJAX string. |
|
391 |
* Parse the 'fields' entry of $tag_info into structured, sanitized fields data. |
|
392 |
* |
|
393 |
* The keys of the fields array are the string equivalent of accessing the |
|
394 |
* field's value, e.g. 'field_file_image_alt_text[und][0][value]' and the value |
|
395 |
* is the actual field value. These parts are turned into sanitized fields data |
|
396 |
* arrays with the full hierarchy of language, deltas, data column and finally |
|
397 |
* value. |
|
398 |
* |
|
399 |
* Only configured or programmed fields present in the site's installation is |
|
400 |
* parsed and returned. |
|
401 |
* |
|
402 |
* @param array $tag_info |
|
403 |
* Media token as PHP array equivalent. |
|
404 |
* |
|
405 |
* @return array |
|
406 |
* An array of fields with sanitized field data structures. |
|
392 | 407 |
*/ |
393 |
function media_wysiwyg_filter_field_parser($tag_info) { |
|
408 |
function media_wysiwyg_filter_field_parser(array $tag_info) {
|
|
394 | 409 |
$fields = array(); |
395 | 410 |
if (isset($tag_info['fields'])) { |
396 |
// Field names that end in [format] are associated with long-text fields that may have HTML Entities. |
|
397 |
// Those values will need to be URLDecoded as well as HTMLDecoded. |
|
411 |
// Field value reference candidates (keys) that end in [format] are |
|
412 |
// associated with long-text fields that may have HTML Entities. Those |
|
413 |
// values will need to be URLDecoded as well as HTMLDecoded. |
|
398 | 414 |
$url_encoded_fields = array(); |
399 |
foreach($tag_info['fields'] as $field_name => $field_value) {
|
|
400 |
if (preg_match('/\[format\]$/', $field_name) > 0){
|
|
401 |
$url_encoded_fields[] = preg_replace('/\[format\]$/', '[value]', $field_name);
|
|
415 |
foreach ($tag_info['fields'] as $candidate => $field_value) {
|
|
416 |
if (preg_match('/\[format\]$/', $candidate) > 0) {
|
|
417 |
$url_encoded_fields[] = preg_replace('/\[format\]$/', '[value]', $candidate);
|
|
402 | 418 |
} |
403 | 419 |
} |
404 | 420 |
|
405 |
foreach($tag_info['fields'] as $field_name => $field_value) { |
|
406 |
if (strpos($field_name, 'field_') === 0) { |
|
407 |
$parsed_field = explode('[', str_replace(']', '', $field_name)); |
|
408 |
$ref = &$fields; |
|
421 |
foreach ($tag_info['fields'] as $candidate => $field_value) { |
|
422 |
if (strpos($candidate, 'field_') === 0) { |
|
423 |
$parsed_field = explode('[', str_replace(']', '', $candidate)); |
|
424 |
// We are garuanteed to have a value in $parsed_field[0]. |
|
425 |
$info = field_info_field($parsed_field[0]); |
|
426 |
if (!$info) { |
|
427 |
// Not an existing/configured field. |
|
428 |
continue; |
|
429 |
} |
|
409 | 430 |
|
410 | 431 |
// Certain types of fields, because of differences in markup, end up |
411 | 432 |
// here with incomplete arrays. Make a best effort to support as many |
412 | 433 |
// types of fields as possible. |
413 | 434 |
// Single-value select lists show up here with only 2 array items. |
414 | 435 |
if (count($parsed_field) == 2) { |
415 |
$info = field_info_field($parsed_field[0]); |
|
416 | 436 |
if ($info && !empty($info['columns'])) { |
417 | 437 |
// Assume single-value. |
418 | 438 |
$parsed_field[] = 0; |
... | ... | |
422 | 442 |
} |
423 | 443 |
// Multi-value select lists show up here with 3 array items. |
424 | 444 |
elseif (count($parsed_field) == 3 && (empty($parsed_field[2]) || is_numeric($parsed_field[2]))) { |
425 |
$info = field_info_field($parsed_field[0]); |
|
426 | 445 |
// They just need the value column. |
427 | 446 |
$parsed_field[3] = key($info['columns']); |
428 | 447 |
} |
429 | 448 |
|
430 | 449 |
// Each key of the field needs to be the child of the previous key. |
450 |
$ref = &$fields; |
|
431 | 451 |
foreach ($parsed_field as $key) { |
432 | 452 |
if (!isset($ref[$key])) { |
433 | 453 |
$ref[$key] = array(); |
434 | 454 |
} |
435 | 455 |
$ref = &$ref[$key]; |
436 | 456 |
} |
437 |
|
|
438 | 457 |
// The value should be set at the deepest level. |
439 |
if (in_array($field_name, $url_encoded_fields)){
|
|
458 |
if (in_array($candidate, $url_encoded_fields)) {
|
|
440 | 459 |
// Fields that use rich-text markup will be urlencoded. |
441 | 460 |
$ref = urldecode(decode_entities($field_value)); |
442 | 461 |
} |
... | ... | |
446 | 465 |
} |
447 | 466 |
} |
448 | 467 |
} |
468 |
// Strip fields for empty values. This is necessary to do post parsing of |
|
469 |
// all field entries as they may refer to the same field several times. |
|
470 |
foreach ($fields as $field_name => $field_languages) { |
|
471 |
$info = field_info_field($field_name); |
|
472 |
if (isset($field_languages) && is_array($field_languages)) { |
|
473 |
foreach ($field_languages as $lang => $items) { |
|
474 |
$fields[$field_name][$lang] = _field_filter_items($info, $items); |
|
475 |
} |
|
476 |
} |
|
477 |
} |
|
449 | 478 |
} |
450 | 479 |
return $fields; |
451 | 480 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules