Projet

Général

Profil

Révision f066bdb5

Ajouté par Assos Assos il y a plus de 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/feeds_xpathparser/FeedsXPathParserBase.inc
57 57
    $this->rawXML = array_keys(array_filter($source_config['rawXML']));
58 58
    // Set link.
59 59
    $fetcher_config = $source->getConfigFor($source->importer->fetcher);
60
    $parser_result->link = $fetcher_config['source'];
60
    $parser_result->link = isset($fetcher_config['source']) ? $fetcher_config['source'] : '';
61 61

  
62 62
    $this->xpath = new FeedsXPathParserDOMXPath($this->doc);
63 63
    $config = array();
......
175 175
    $form = array();
176 176
    $importer = feeds_importer($this->id);
177 177
    $importer_config = $importer->getConfig();
178
    $mappings_ = $importer_config['processor']['config']['mappings'];
178
    $mappings_ = $importer->processor->getMappings();
179 179

  
180 180
    if (empty($source_config)) {
181 181
      $source_config = $this->getConfig();
......
195 195
      }
196 196
    }
197 197

  
198
    $uniques = $mappings = array();
199
    foreach ($mappings_ as $mapping) {
200
      if (strpos($mapping['source'], 'xpathparser:') === 0) {
201
        $mappings[$mapping['source']] = $mapping['target'];
202
        if ($mapping['unique']) {
203
          $uniques[] = $mapping['target'];
204
        }
205
      }
206
    }
198
    $uniques = $this->getUniques();
199
    $mappings = $this->getOwnMappings();
200
    $targets = $importer->processor->getMappingTargets();
201

  
207 202
    $form['xpath'] = array(
208 203
      '#type' => 'fieldset',
209 204
      '#tree' => TRUE,
......
251 246
    foreach ($mappings as $source => $target) {
252 247
      $form['xpath']['sources'][$source] = array(
253 248
        '#type' => 'textfield',
254
        '#title' => check_plain($target),
249
        '#title' => isset($targets[$target]['name']) ? check_plain($targets[$target]['name']) : check_plain($target),
255 250
        '#description' => t('The XPath query to run.'),
256 251
        '#default_value' => isset($source_config['sources'][$source]) ? $source_config['sources'][$source] : '',
257 252
        '#maxlength' => 1024,
......
269 264
    $form['xpath']['rawXML'] = array(
270 265
      '#type' => 'checkboxes',
271 266
      '#title' => t('Select the queries you would like to return raw XML or HTML'),
272
      '#options' => $mappings,
267
      '#options' => $this->getOwnMappings(TRUE),
273 268
      '#default_value' => isset($source_config['rawXML']) ? $source_config['rawXML'] : array(),
274 269
    );
275 270
    $form['xpath']['exp'] = array(
......
309 304
    $form['xpath']['exp']['debug'] = array(
310 305
      '#type' => 'checkboxes',
311 306
      '#title' => t('Debug query'),
312
      '#options' => array_merge(array('context' => 'context'), $mappings),
307
      '#options' => array_merge(array('context' => t('Context')), $this->getOwnMappings(TRUE)),
313 308
      '#default_value' => isset($source_config['exp']['debug']) ? $source_config['exp']['debug'] : array(),
314 309
    );
315 310
    return $form;
......
449 444
   * Overrides parent::getMappingSources().
450 445
   */
451 446
  public function getMappingSources() {
452
    $mappings = $this->filterMappings(feeds_importer($this->id)->processor->config['mappings']);
447
    $mappings = $this->getOwnMappings();
453 448
    $next = 0;
454 449
    if (!empty($mappings)) {
455
      $keys = array_keys($mappings);
456
      $last_mapping = end($keys);
457
      $next = explode(':', $last_mapping);
458
      $next = $next[1] + 1;
450
      // Mappings can be re-ordered, so find the max.
451
      foreach (array_keys($mappings) as $key) {
452
        list(, $index) = explode(':', $key);
453
        if ($index > $next) {
454
          $next = $index;
455
        }
456
      }
457
      $next++;
459 458
    }
460 459
    return array(
461 460
      'xpathparser:' . $next => array(
......
465 464
    ) + parent::getMappingSources();
466 465
  }
467 466

  
467
  /**
468
   * Gets the unique mappings targets that are used by this parser.
469
   *
470
   * @return array
471
   *   An array of mappings keyed source => target.
472
   */
473
  protected function getUniques() {
474
    $uniques = array();
475
    $importer = feeds_importer($this->id);
476

  
477
    $targets = $importer->processor->getMappingTargets();
478
    foreach ($importer->processor->getMappings() as $mapping) {
479
      if (!empty($mapping['unique'])) {
480
        $uniques[$mapping['source']] = $targets[$mapping['target']]['name'];
481
      }
482
    }
483

  
484
    return $uniques;
485
  }
486

  
468 487
  /**
469 488
   * Gets the mappings that are defined by this parser.
470 489
   *
......
473 492
   * @return array
474 493
   *   An array of mappings keyed source => target.
475 494
   */
476
  protected function getOwnMappings() {
477
    $importer_config = feeds_importer($this->id)->getConfig();
478
    return $this->filterMappings($importer_config['processor']['config']['mappings']);
495
  protected function getOwnMappings($label = FALSE) {
496
    $importer = feeds_importer($this->id);
497
    $mappings = $this->filterMappings($importer->processor->getMappings());
498
    if ($label) {
499
      $targets = $importer->processor->getMappingTargets();
500
      foreach ($mappings as $source => $target) {
501
        $mappings[$source] = isset($targets[$target]['name']) ? $targets[$target]['name'] : $target;
502
      }
503
    }
504

  
505
    return $mappings;
479 506
  }
480 507

  
481 508
  /**
......
487 514
   * @return array
488 515
   *   An array of mappings keyed source => target.
489 516
   */
490
  protected function filterMappings($mappings) {
517
  protected function filterMappings(array $mappings) {
491 518
    $our_mappings = array();
492 519
    foreach ($mappings as $mapping) {
493 520
      if (strpos($mapping['source'], 'xpathparser:') === 0) {
......
504 531
   *   The previous value of use_errors.
505 532
   */
506 533
  protected function errorStart() {
534
    libxml_clear_errors();
507 535
    return libxml_use_internal_errors(TRUE);
508 536
  }
509 537

  
......
541 569
    libxml_use_internal_errors($use);
542 570
  }
543 571

  
572
  /**
573
   * Overrides parent::hasSourceConfig().
574
   *
575
   * Stop Feeds from building our form over and over again.
576
   */
577
  public function hasSourceConfig() {
578
    return TRUE;
579
  }
580

  
544 581
}

Formats disponibles : Unified diff