You are here

protected function FeedsQueryPathParser::parseSourceElement in Feeds QueryPath Parser 7

Same name and namespace in other branches
  1. 6 FeedsQueryPathParser.inc \FeedsQueryPathParser::parseSourceElement()
1 call to FeedsQueryPathParser::parseSourceElement()
FeedsQueryPathParser::parse in ./FeedsQueryPathParser.inc
Implements FeedsParser::parse().

File

./FeedsQueryPathParser.inc, line 81
Provides the class for FeedsQueryPathParser.

Class

FeedsQueryPathParser
@file

Code

protected function parseSourceElement($item, $query, $source) {
  $attr = $this->source_config['attrs'][$source];
  if ($query == '' && $attr == '') {
    return;
  }
  if ($query != '') {
    $item = qp($item, $query);
  }
  $results = array();
  foreach ($item as $k => $i) {
    if ($attr != '') {
      $results[] = $i
        ->attr($attr);
    }
    else {
      if (in_array($source, $this->rawXML)) {
        $results[] = $i
          ->html();
      }
      else {
        $results[] = $i
          ->text();
      }
    }
  }
  $this
    ->debug($results, $source);

  /**
   * If there is one result, return it directly.  If there are no results,
   * return. Otherwise return the results.
   */
  if (count($results) === 1) {
    return $results[0];
  }
  if (count($results) === 0) {
    return;
  }
  return $results;
}