Projet

Général

Profil

Révision 0b4524f6

Ajouté par Assos Assos il y a presque 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/feeds_xpathparser/FeedsXPathParserBase.inc
10 10
 */
11 11
abstract class FeedsXPathParserBase extends FeedsParser {
12 12

  
13
  /**
14
   * The DOMDocument used for parsing.
15
   *
16
   * @var DOMDocument
17
   */
18
  protected $doc;
19

  
20
  /**
21
   * The return value of libxml_disable_entity_loader().
22
   *
23
   * @var bool
24
   */
25
  protected $loader;
26

  
27
  /**
28
   * The elements that should be displayed in raw XML.
29
   *
30
   * @var array
31
   */
13 32
  protected $rawXML = array();
14
  protected $doc = NULL;
15
  protected $xpath = NULL;
33

  
34
  /**
35
   * The DOMXPath objet used for parsing.
36
   *
37
   * @var DOMXPath
38
   */
39
  protected $xpath;
16 40

  
17 41
  /**
18 42
   * Classes that use FeedsXPathParserBase must implement this.
......
82 106

  
83 107
    $all_nodes = $this->xpath->namespacedQuery($context_query, NULL, 'context');
84 108

  
109
    // The source config could have old values that don't exist in the importer.
110
    $sources = array_intersect_key($source_config['sources'], $mappings);
111

  
85 112
    foreach ($all_nodes as $node) {
86 113
      // Invoke a hook to check whether the domnode should be skipped.
87 114
      if (in_array(TRUE, module_invoke_all('feeds_xpathparser_filter_domnode', $node, $this->doc, $source), TRUE)) {
......
89 116
      }
90 117

  
91 118
      $parsed_item = $variables = array();
92
      foreach ($source_config['sources'] as $element_key => $query) {
119
      foreach ($sources as $element_key => $query) {
93 120
        // Variable substitution.
94 121
        $query = strtr($query, $variables);
95 122
        // Parse the item.
96 123
        $result = $this->parseSourceElement($query, $node, $element_key);
97 124
        if (isset($result)) {
98
          if (!is_array($result)) {
99
            $variables['$' . $mappings[$element_key]] = $result;
100
          }
101
          else {
102
            $variables['$' . $mappings[$element_key]] = '';
103
          }
125
          $variables['$' . $mappings[$element_key]] = is_array($result) ? reset($result) : $result;
104 126
          $parsed_item[$element_key] = $result;
105 127
        }
106 128
      }
......
532 554
   */
533 555
  protected function errorStart() {
534 556
    libxml_clear_errors();
557
    if (function_exists('libxml_disable_entity_loader')) {
558
      $this->loader = libxml_disable_entity_loader(TRUE);
559
    }
560

  
535 561
    return libxml_use_internal_errors(TRUE);
536 562
  }
537 563

  
......
567 593
    }
568 594
    libxml_clear_errors();
569 595
    libxml_use_internal_errors($use);
596

  
597
    if (function_exists('libxml_disable_entity_loader') && isset($this->loader)) {
598
      libxml_disable_entity_loader($this->loader);
599
      unset($this->loader);
600
    }
570 601
  }
571 602

  
572 603
  /**

Formats disponibles : Unified diff