Skip to content
Snippets Groups Projects
Commit 0932c959 authored by Alex Barth's avatar Alex Barth
Browse files

#912630 twistor, alex_b: FeedsParserResult: make items accessible for modification.

parent 12ba86a0
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@
Feeds 7.x 2.0 XXXXXXXXXXXXXXXXXXX
---------------------------------
- #912630 twistor, alex_b: FeedsParserResult: make items accessible for
modification.
- #933306 alex_b: Fix Feeds creates subscriptions for not existing importers.
- #946822 twistor: FeedsSitemapParser broken: Serialization of
'SimpleXMLElement' is not allowed.
......
......@@ -96,7 +96,7 @@ function hook_feeds_plugins() {
*/
function hook_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
// For example, set title of imported content:
$result->setTitle('Import number ' . my_module_import_id());
$result->title = 'Import number ' . my_module_import_id();
}
/**
......
......@@ -424,7 +424,7 @@ function feeds_node_validate($node, $form, &$form_state) {
if (trim($node->title) == '') {
try {
$source->addConfig($last_feeds);
if (!$last_title = $source->preview()->getTitle()) {
if (!$last_title = $source->preview()->title) {
throw new Exception();
}
}
......
......@@ -18,7 +18,7 @@ class FeedsOPMLParser extends FeedsParser {
feeds_include_library('opml_parser.inc', 'opml_parser');
$opml = opml_parser_parse($fetcher_result->getRaw());
$result = new FeedsParserResult($opml['items']);
$result->setTitle($opml['title']);
$result->title = $opml['title'];
return $result;
}
......
......@@ -5,11 +5,11 @@
* A result of a parsing stage.
*/
class FeedsParserResult extends FeedsResult {
protected $title;
protected $description;
protected $link;
protected $items;
protected $current_item;
public $title;
public $description;
public $link;
public $items;
public $current_item;
/**
* Constructor.
......@@ -21,31 +21,6 @@ class FeedsParserResult extends FeedsResult {
$this->items = $items;
}
/**
* @return
* A string that is the feed's title.
*/
public function getTitle() {
return $this->title;
}
/**
* @return
* A string that is the feed's description.
*/
public function getDescription() {
return $this->description;
}
/**
* @return
* A string that is the link to the feed's site (not the actual URL of the
* feed). Falls back to URL if not available.
*/
public function getLink() {
return $this->link;
}
/**
* @todo Move to a nextItem() based approach, not consuming the item array.
* Can only be done once we don't cache the entire batch object between page
......@@ -67,51 +42,6 @@ class FeedsParserResult extends FeedsResult {
public function currentItem() {
return empty($this->current_item) ? NULL : $this->current_item;
}
/**
* Set title.
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* Set description.
*/
public function setDescription($description) {
$this->description = $description;
}
/**
* Set link.
*/
public function setLink($link) {
$this->link = $link;
}
/**
* Set items.
*
* @param $items
* An array of the items in the feed. Cannot be NULL.
*/
public function setItems($items) {
$this->items = $items;
}
/**
* Add an item.
*/
public function addItem($item) {
$this->items[] = $item;
}
/**
* Get number of items.
*/
public function getItemCount() {
return count($this->items);
}
}
/**
......
......@@ -75,9 +75,9 @@ class FeedsSimplePieParser extends FeedsParser {
// Construct the standard form of the parsed feed
$result = new FeedsParserResult();
$result->setTitle(html_entity_decode(($title = $parser->get_title()) ? $title : $this->createTitle($parser->get_description())));
$result->setDescription($parser->get_description());
$result->setLink(html_entity_decode($parser->get_link()));
$result->title = html_entity_decode(($title = $parser->get_title()) ? $title : $this->createTitle($parser->get_description()));
$result->description = $parser->get_description();
$result->link = html_entity_decode($parser->get_link());
$items_num = $parser->get_item_quantity();
for ($i = 0; $i < $items_num; $i++) {
......@@ -137,7 +137,7 @@ class FeedsSimplePieParser extends FeedsParser {
$this->parseExtensions($item, $simplepie_item);
$item['raw'] = $simplepie_item->data;
$result->addItem($item);
$result->items[] = $item;
}
// Release parser.
unset($parser);
......
......@@ -26,7 +26,7 @@ class FeedsSitemapParser extends FeedsParser {
if ($url->priority) {
$item['priority'] = (string) $url->priority;
}
$result->addItem($item);
$result->items[] = $item;
}
date_default_timezone_set($tz);
return $result;
......
......@@ -15,9 +15,9 @@ class FeedsSyndicationParser extends FeedsParser {
feeds_include_library('common_syndication_parser.inc', 'common_syndication_parser');
$feed = common_syndication_parser_parse($fetcher_result->getRaw());
$result = new FeedsParserResult();
$result->setTitle($feed['title']);
$result->setDescription($feed['description']);
$result->setLink($feed['link']);
$result->title = $feed['title'];
$result->description = $feed['description'];
$result->link = $feed['link'];
if (is_array($feed['items'])) {
foreach ($feed['items'] as $item) {
if (isset($item['geolocations'])) {
......@@ -25,7 +25,7 @@ class FeedsSyndicationParser extends FeedsParser {
$item['geolocations'][$k] = new FeedsGeoTermElement($v);
}
}
$result->addItem($item);
$result->items[] = $item;
}
}
return $result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment