You are here

protected function OpmlParser::getItems in Feeds 8.3

Returns a flattened array of feed items.

Parameters

array $outlines: A nested array of outlines.

array $categories: For internal use only.

Return value

array The flattened list of feed items.

1 call to OpmlParser::getItems()
OpmlParser::parse in src/Feeds/Parser/OpmlParser.php
Parses content returned by fetcher.

File

src/Feeds/Parser/OpmlParser.php, line 59

Class

OpmlParser
Defines an OPML feed parser.

Namespace

Drupal\feeds\Feeds\Parser

Code

protected function getItems(array $outlines, array $categories = []) {
  $items = [];
  foreach ($outlines as $outline) {

    // PHPunit is being weird about our array appending.
    // @codeCoverageIgnoreStart
    $outline += [
      '#title' => '',
      '#text' => '',
      '#xmlurl' => '',
      '#htmlurl' => '',
      'outlines' => [],
    ];

    // @codeCoverageIgnoreEnd
    $item = new OpmlItem();

    // Assume it is an actual feed if the URL is set.
    if ($outline['#xmlurl']) {
      $outline['#title'] ? $item
        ->set('title', $outline['#title']) : $item
        ->set('title', $outline['#text']);
      $item
        ->set('categories', $categories)
        ->set('xmlurl', $outline['#xmlurl'])
        ->set('htmlurl', $outline['#htmlurl']);
      $items[] = $item;
    }

    // Get sub elements.
    if ($outline['outlines']) {
      $sub_categories = array_merge($categories, [
        $outline['#text'],
      ]);
      $items = array_merge($items, $this
        ->getItems($outline['outlines'], $sub_categories));
    }
  }
  return $items;
}