Projet

Général

Profil

Révision 05237dd8

Ajouté par Assos Assos il y a presque 7 ans

Weekly update of contrib modules

Voir les différences:

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', '/\[\[.+?"type":"media".+?\]\]/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 configure media_filter_paragraph_fix filter.
32
 */
33
function _media_filter_paragraph_fix_settings($form, &$form_state, $filter, $format, $defaults) {
34
  $filter->settings += $defaults;
35
  $settings['replace'] = array(
36
    '#type' => 'checkbox',
37
    '#title' => t('Replace paragraph tags with DIV.media-p tags'),
38
    '#default_value' => $filter->settings['replace'],
39
    '#description' => t('Default behaviour is to strip out parent P tags of media elements rather than replacing these.'),
40
  );
41
  return $settings;
42
}
43

  
30 44
/**
31 45
 * Filter callback to remove paragraph tags surrounding embedded media.
32 46
 */
33
function media_wysiwyg_filter_paragraph_fix($text) {
47
function media_wysiwyg_filter_paragraph_fix($text, $filter) {
34 48
  $html_dom = filter_dom_load($text);
49
  // Store Nodes to remove to avoid inferferring with the NodeList iteration.
50
  $dom_nodes_to_remove = array();
35 51
  foreach ($html_dom->getElementsByTagName('p') as $paragraph) {
36 52
    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);
53
      if (empty($filter->settings['replace'])) {
54
        $sibling = $paragraph->firstChild;
55
        do {
56
          $next = $sibling->nextSibling;
57
          $paragraph->parentNode->insertBefore($sibling, $paragraph);
58
        } while ($sibling = $next);
59
        $dom_nodes_to_remove[] = $paragraph;
60
      }
61
      else {
62
        // Clone the P node into a DIV node.
63
        $div = $html_dom->createElement('div');
64
        $sibling = $paragraph->firstChild;
65
        do {
66
          $next = $sibling->nextSibling;
67
          $div->appendChild($sibling);
68
        } while ($sibling = $next);
69

  
70
        $classes = array('media-p');
71
        if ($paragraph->hasAttributes()) {
72
          foreach ($paragraph->attributes as $attr) {
73
            $name = $attr->nodeName;
74
            $value = $attr->nodeValue;
75
            if (strtolower($name) == 'class') {
76
              $classes[] = $value;
77
            }
78
            else {
79
              // Supressing errors with ID attribute or duplicate properties.
80
              @$div->setAttribute($name, $value);
81
            }
82
          }
83
        }
84
        $div->setAttribute('class', implode(' ', $classes));
85

  
86
        $paragraph->parentNode->insertBefore($div, $paragraph);
87
        $dom_nodes_to_remove[] = $paragraph;
88
      }
43 89
    }
44 90
  }
91
  foreach ($dom_nodes_to_remove as $paragraph) {
92
    $paragraph->parentNode->removeChild($paragraph);
93
  }
45 94
  $text = filter_dom_serialize($html_dom);
46 95
  return $text;
47 96
}

Formats disponibles : Unified diff