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 @@ ...@@ -3,6 +3,8 @@
Feeds 7.x 2.0 XXXXXXXXXXXXXXXXXXX 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. - #933306 alex_b: Fix Feeds creates subscriptions for not existing importers.
- #946822 twistor: FeedsSitemapParser broken: Serialization of - #946822 twistor: FeedsSitemapParser broken: Serialization of
'SimpleXMLElement' is not allowed. 'SimpleXMLElement' is not allowed.
......
...@@ -96,7 +96,7 @@ function hook_feeds_plugins() { ...@@ -96,7 +96,7 @@ function hook_feeds_plugins() {
*/ */
function hook_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) { function hook_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
// For example, set title of imported content: // 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) { ...@@ -424,7 +424,7 @@ function feeds_node_validate($node, $form, &$form_state) {
if (trim($node->title) == '') { if (trim($node->title) == '') {
try { try {
$source->addConfig($last_feeds); $source->addConfig($last_feeds);
if (!$last_title = $source->preview()->getTitle()) { if (!$last_title = $source->preview()->title) {
throw new Exception(); throw new Exception();
} }
} }
......
...@@ -18,7 +18,7 @@ class FeedsOPMLParser extends FeedsParser { ...@@ -18,7 +18,7 @@ class FeedsOPMLParser extends FeedsParser {
feeds_include_library('opml_parser.inc', 'opml_parser'); feeds_include_library('opml_parser.inc', 'opml_parser');
$opml = opml_parser_parse($fetcher_result->getRaw()); $opml = opml_parser_parse($fetcher_result->getRaw());
$result = new FeedsParserResult($opml['items']); $result = new FeedsParserResult($opml['items']);
$result->setTitle($opml['title']); $result->title = $opml['title'];
return $result; return $result;
} }
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
* A result of a parsing stage. * A result of a parsing stage.
*/ */
class FeedsParserResult extends FeedsResult { class FeedsParserResult extends FeedsResult {
protected $title; public $title;
protected $description; public $description;
protected $link; public $link;
protected $items; public $items;
protected $current_item; public $current_item;
/** /**
* Constructor. * Constructor.
...@@ -21,31 +21,6 @@ class FeedsParserResult extends FeedsResult { ...@@ -21,31 +21,6 @@ class FeedsParserResult extends FeedsResult {
$this->items = $items; $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. * @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 * Can only be done once we don't cache the entire batch object between page
...@@ -67,51 +42,6 @@ class FeedsParserResult extends FeedsResult { ...@@ -67,51 +42,6 @@ class FeedsParserResult extends FeedsResult {
public function currentItem() { public function currentItem() {
return empty($this->current_item) ? NULL : $this->current_item; 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 { ...@@ -75,9 +75,9 @@ class FeedsSimplePieParser extends FeedsParser {
// Construct the standard form of the parsed feed // Construct the standard form of the parsed feed
$result = new FeedsParserResult(); $result = new FeedsParserResult();
$result->setTitle(html_entity_decode(($title = $parser->get_title()) ? $title : $this->createTitle($parser->get_description()))); $result->title = html_entity_decode(($title = $parser->get_title()) ? $title : $this->createTitle($parser->get_description()));
$result->setDescription($parser->get_description()); $result->description = $parser->get_description();
$result->setLink(html_entity_decode($parser->get_link())); $result->link = html_entity_decode($parser->get_link());
$items_num = $parser->get_item_quantity(); $items_num = $parser->get_item_quantity();
for ($i = 0; $i < $items_num; $i++) { for ($i = 0; $i < $items_num; $i++) {
...@@ -137,7 +137,7 @@ class FeedsSimplePieParser extends FeedsParser { ...@@ -137,7 +137,7 @@ class FeedsSimplePieParser extends FeedsParser {
$this->parseExtensions($item, $simplepie_item); $this->parseExtensions($item, $simplepie_item);
$item['raw'] = $simplepie_item->data; $item['raw'] = $simplepie_item->data;
$result->addItem($item); $result->items[] = $item;
} }
// Release parser. // Release parser.
unset($parser); unset($parser);
......
...@@ -26,7 +26,7 @@ class FeedsSitemapParser extends FeedsParser { ...@@ -26,7 +26,7 @@ class FeedsSitemapParser extends FeedsParser {
if ($url->priority) { if ($url->priority) {
$item['priority'] = (string) $url->priority; $item['priority'] = (string) $url->priority;
} }
$result->addItem($item); $result->items[] = $item;
} }
date_default_timezone_set($tz); date_default_timezone_set($tz);
return $result; return $result;
......
...@@ -15,9 +15,9 @@ class FeedsSyndicationParser extends FeedsParser { ...@@ -15,9 +15,9 @@ class FeedsSyndicationParser extends FeedsParser {
feeds_include_library('common_syndication_parser.inc', 'common_syndication_parser'); feeds_include_library('common_syndication_parser.inc', 'common_syndication_parser');
$feed = common_syndication_parser_parse($fetcher_result->getRaw()); $feed = common_syndication_parser_parse($fetcher_result->getRaw());
$result = new FeedsParserResult(); $result = new FeedsParserResult();
$result->setTitle($feed['title']); $result->title = $feed['title'];
$result->setDescription($feed['description']); $result->description = $feed['description'];
$result->setLink($feed['link']); $result->link = $feed['link'];
if (is_array($feed['items'])) { if (is_array($feed['items'])) {
foreach ($feed['items'] as $item) { foreach ($feed['items'] as $item) {
if (isset($item['geolocations'])) { if (isset($item['geolocations'])) {
...@@ -25,7 +25,7 @@ class FeedsSyndicationParser extends FeedsParser { ...@@ -25,7 +25,7 @@ class FeedsSyndicationParser extends FeedsParser {
$item['geolocations'][$k] = new FeedsGeoTermElement($v); $item['geolocations'][$k] = new FeedsGeoTermElement($v);
} }
} }
$result->addItem($item); $result->items[] = $item;
} }
} }
return $result; 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