You are here

class Entry in Feeds 8.3

Parses GeoRss data.

Hierarchy

  • class \Drupal\feeds\Zend\Extension\Georss\Entry extends \Zend\Feed\Reader\Extension\AbstractEntry

Expanded class hierarchy of Entry

1 file declares its use of Entry
EntryTest.php in tests/src/Unit/Zend/Extension/Georss/EntryTest.php
1 string reference to 'Entry'
feeds.services.yml in ./feeds.services.yml
feeds.services.yml
1 service uses Entry
feed.reader.georssentry in ./feeds.services.yml
Drupal\feeds\Zend\Extension\Georss\Entry

File

src/Zend/Extension/Georss/Entry.php, line 10

Namespace

Drupal\feeds\Zend\Extension\Georss
View source
class Entry extends AbstractEntry {

  /**
   * Returns the entry point.
   *
   * @param int $index
   *   The index of the point.
   *
   * @return string|null
   *   A geo point.
   */
  public function getGeoPoint($index = 0) {
    $points = $this
      ->getGeoPoints();
    return isset($points[$index]) ? $points[$index] : NULL;
  }

  /**
   * Get the entry points.
   *
   * @return array
   *   The geo entry points.
   */
  public function getGeoPoints() {
    if (!isset($this->data['georss'])) {
      $this
        ->populateData();
    }
    return $this->data['georss'];
  }

  /**
   * Populates the georss data.
   */
  protected function populateData() {
    $this->data['georss'] = [];
    $list = $this->xpath
      ->evaluate($this
      ->getXpathPrefix() . '//georss:point');
    foreach ($list as $point) {

      // Normalize whitespace.
      $parts = explode(' ', preg_replace('/\\s+/', ' ', trim($point->nodeValue)));
      if (count($parts) === 2) {
        $this->data['georss'][] = [
          'lat' => is_numeric($parts[0]) ? (double) $parts[0] : NULL,
          'lon' => is_numeric($parts[1]) ? (double) $parts[1] : NULL,
        ];
      }
    }
  }

  /**
   * Registers GeoRSS namespaces.
   */
  protected function registerNamespaces() {
    $this
      ->getXpath()
      ->registerNamespace('georss', 'http://www.georss.org/georss');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entry::getGeoPoint public function Returns the entry point.
Entry::getGeoPoints public function Get the entry points.
Entry::populateData protected function Populates the georss data.
Entry::registerNamespaces protected function Registers GeoRSS namespaces.