class FeedsSimplePieParser in Feeds 7.2
Same name and namespace in other branches
- 6 plugins/FeedsSimplePieParser.inc \FeedsSimplePieParser
- 7 plugins/FeedsSimplePieParser.inc \FeedsSimplePieParser
Class definition for Common Syndication Parser.
Parses RSS and Atom feeds.
Hierarchy
- class \FeedsConfigurable
- class \FeedsPlugin implements FeedsSourceInterface
- class \FeedsParser
- class \FeedsSimplePieParser
- class \FeedsParser
- class \FeedsPlugin implements FeedsSourceInterface
Expanded class hierarchy of FeedsSimplePieParser
4 string references to 'FeedsSimplePieParser'
- FeedsMapperFileTestCase::test in tests/
feeds_mapper_file.test - Basic test loading a single entry CSV file.
- FeedsSyndicationParserTestCase::test in tests/
feeds_parser_syndication.test - Run tests.
- feeds_requirements in ./
feeds.install - Implements hook_requirements().
- _feeds_feeds_plugins in ./
feeds.plugins.inc - Break out for feeds_feed_plugins().
File
- plugins/
FeedsSimplePieParser.inc, line 63 - Contains FeedsSimplePieParser and related classes.
View source
class FeedsSimplePieParser extends FeedsParser {
/**
* Implements FeedsParser::parse().
*/
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
feeds_include_simplepie();
// Initialize SimplePie.
$parser = new SimplePie();
$parser
->set_raw_data($fetcher_result
->getRaw());
$parser
->set_stupidly_fast(TRUE);
$parser
->encode_instead_of_strip(FALSE);
// @todo Is caching effective when we pass in raw data?
$parser
->enable_cache(TRUE);
$parser
->set_cache_location($this
->cacheDirectory());
$parser
->init();
// Construct the standard form of the parsed feed.
$result = new FeedsParserResult();
$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++) {
$item = array();
$simplepie_item = $parser
->get_item($i);
$item['title'] = html_entity_decode(($title = $simplepie_item
->get_title()) ? $title : $this
->createTitle($simplepie_item
->get_content()));
$item['description'] = $simplepie_item
->get_content();
$item['url'] = html_entity_decode($simplepie_item
->get_link());
// Use UNIX time. If no date is defined, fall back to REQUEST_TIME.
$item['timestamp'] = $simplepie_item
->get_date("U");
if (empty($item['timestamp'])) {
$item['timestamp'] = REQUEST_TIME;
}
$item['guid'] = $simplepie_item
->get_id();
// Use URL as GUID if there is no GUID.
if (empty($item['guid'])) {
$item['guid'] = $item['url'];
}
$author = $simplepie_item
->get_author();
$item['author_name'] = isset($author->name) ? html_entity_decode($author->name) : '';
$item['author_link'] = isset($author->link) ? $author->link : '';
$item['author_email'] = isset($author->email) ? $author->email : '';
// Enclosures.
$enclosures = $simplepie_item
->get_enclosures();
if (is_array($enclosures)) {
foreach ($enclosures as $enclosure) {
$item['enclosures'][] = new FeedsSimplePieEnclosure($enclosure);
}
}
// Location.
$latitude = $simplepie_item
->get_latitude();
$longitude = $simplepie_item
->get_longitude();
if (!is_null($latitude) && !is_null($longitude)) {
$item['location_latitude'][] = $latitude;
$item['location_longitude'][] = $longitude;
}
// Extract tags related to the item.
$simplepie_tags = $simplepie_item
->get_categories();
$tags = array();
$domains = array();
if (count($simplepie_tags) > 0) {
foreach ($simplepie_tags as $tag) {
$tags[] = (string) $tag->term;
$domain = (string) $tag
->get_scheme();
if (!empty($domain)) {
if (!isset($domains[$domain])) {
$domains[$domain] = array();
}
$domains[$domain][] = count($tags) - 1;
}
}
}
$item['domains'] = $domains;
$item['tags'] = $tags;
// Allow parsing to be extended.
$this
->parseExtensions($item, $simplepie_item);
$item['raw'] = $simplepie_item->data;
$result->items[] = $item;
}
// Release parser.
unset($parser);
return $result;
}
/**
* Allow extension of FeedsSimplePie item parsing.
*/
protected function parseExtensions(&$item, $simplepie_item) {
}
/**
* Return mapping sources.
*/
public function getMappingSources() {
return array(
'title' => array(
'name' => t('Title'),
'description' => t('Title of the feed item.'),
),
'description' => array(
'name' => t('Description'),
'description' => t('Description of the feed item.'),
),
'author_name' => array(
'name' => t('Author name'),
'description' => t('Name of the feed item\'s author.'),
),
'author_link' => array(
'name' => t('Author link'),
'description' => t('Link to the feed item\'s author.'),
),
'author_email' => array(
'name' => t('Author email'),
'description' => t('Email address of the feed item\'s author.'),
),
'timestamp' => array(
'name' => t('Published date'),
'description' => t('Published date as UNIX time GMT of the feed item.'),
),
'url' => array(
'name' => t('Item URL (link)'),
'description' => t('URL of the feed item.'),
),
'guid' => array(
'name' => t('Item GUID'),
'description' => t('Global Unique Identifier of the feed item.'),
),
'tags' => array(
'name' => t('Categories'),
'description' => t('An array of categories that have been assigned to the feed item.'),
),
'domains' => array(
'name' => t('Category domains'),
'description' => t('Domains of the categories.'),
),
'location_latitude' => array(
'name' => t('Latitudes'),
'description' => t('An array of latitudes assigned to the feed item.'),
),
'location_longitude' => array(
'name' => t('Longitudes'),
'description' => t('An array of longitudes assigned to the feed item.'),
),
'enclosures' => array(
'name' => t('Enclosures'),
'description' => t('An array of enclosures attached to the feed item.'),
),
) + parent::getMappingSources();
}
/**
* Overrides FeedsParser::providesSourceTitle().
*
* This parser supports retrieving a title from the source.
*/
public function providesSourceTitle() {
return TRUE;
}
/**
* Returns cache directory. Creates it if it doesn't exist.
*/
protected function cacheDirectory() {
$directory = 'public://simplepie';
file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
return $directory;
}
/**
* Generate a title from a random text.
*/
protected function createTitle($text = FALSE) {
// Explode to words and use the first 3 words.
$words = preg_split("/[\\s,]+/", $text);
$words = array_slice($words, 0, 3);
return implode(' ', $words);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsConfigurable:: |
protected | property | Holds the actual configuration information. | |
FeedsConfigurable:: |
protected | property | CTools export enabled status of this object. | |
FeedsConfigurable:: |
protected | property | CTools export type of this object. | |
FeedsConfigurable:: |
protected | property | An unique identifier for the configuration. | |
FeedsConfigurable:: |
public | function | Similar to setConfig but adds to existing configuration. | |
FeedsConfigurable:: |
public | function | Returns configuration form for this object. | 6 |
FeedsConfigurable:: |
public | function | Submission handler for configForm(). | 2 |
FeedsConfigurable:: |
public | function | Validation handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Copy a configuration. | 1 |
FeedsConfigurable:: |
public | function | Determine whether this object is persistent. | 1 |
FeedsConfigurable:: |
public | function | Determines whether this object is persistent and enabled. | 1 |
FeedsConfigurable:: |
public | function | Implements getConfig(). | 1 |
FeedsConfigurable:: |
public | function | Returns whether or not the configurable has a config form. | |
FeedsConfigurable:: |
public | function | Determine whether this object is enabled. | |
FeedsConfigurable:: |
public | function | Set configuration. | |
FeedsConfigurable:: |
public | function | Validates the configuration. | 2 |
FeedsConfigurable:: |
public | function | Overrides magic method __get(). | |
FeedsConfigurable:: |
public | function | Override magic method __isset(). This is needed due to overriding __get(). | |
FeedsParser:: |
public | function | Clear all caches for results for given source. | |
FeedsParser:: |
public | function | Get list of mapped sources. | 1 |
FeedsParser:: |
public | function | Get an element identified by $element_key of the given item. The element key corresponds to the values in the array returned by FeedsParser::getMappingSources(). | 1 |
FeedsParser:: |
public | function |
Implements FeedsPlugin::pluginType(). Overrides FeedsPlugin:: |
|
FeedsPlugin:: |
protected | property | The plugin definition. | |
FeedsPlugin:: |
public static | function | Get all available plugins. | |
FeedsPlugin:: |
public static | function | Gets all available plugins of a particular type. | |
FeedsPlugin:: |
public static | function | Determines whether given plugin is derived from given base plugin. | |
FeedsPlugin:: |
public | function |
Overrides FeedsConfigurable::configDefaults(). Overrides FeedsConfigurable:: |
4 |
FeedsPlugin:: |
public | function |
Implements FeedsConfigurable::dependencies(). Overrides FeedsConfigurable:: |
1 |
FeedsPlugin:: |
public | function |
Returns TRUE if $this->sourceForm() returns a form. Overrides FeedsSourceInterface:: |
|
FeedsPlugin:: |
public static | function |
Instantiates a FeedsPlugin object. Overrides FeedsConfigurable:: |
|
FeedsPlugin:: |
public static | function | Loads on-behalf implementations from mappers/ directory. | |
FeedsPlugin:: |
public | function | Returns the plugin definition. | |
FeedsPlugin:: |
public | function |
Save changes to the configuration of this object.
Delegate saving to parent (= Feed) which will collect
information from this object by way of getConfig() and store it. Overrides FeedsConfigurable:: |
1 |
FeedsPlugin:: |
protected | function | Sets the plugin definition. | |
FeedsPlugin:: |
public | function |
Implements FeedsSourceInterface::sourceDefaults(). Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
public | function |
A source is being deleted. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public | function |
Callback methods, exposes source form. Overrides FeedsSourceInterface:: |
3 |
FeedsPlugin:: |
public | function |
Validation handler for sourceForm. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public | function |
A source is being saved. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public static | function | Determines the type of a plugin. | |
FeedsPlugin:: |
protected | function |
Constructs a FeedsPlugin object. Overrides FeedsConfigurable:: |
|
FeedsSimplePieParser:: |
protected | function | Returns cache directory. Creates it if it doesn't exist. | |
FeedsSimplePieParser:: |
protected | function | Generate a title from a random text. | |
FeedsSimplePieParser:: |
public | function |
Return mapping sources. Overrides FeedsParser:: |
|
FeedsSimplePieParser:: |
public | function |
Implements FeedsParser::parse(). Overrides FeedsParser:: |
|
FeedsSimplePieParser:: |
protected | function | Allow extension of FeedsSimplePie item parsing. | |
FeedsSimplePieParser:: |
public | function |
Overrides FeedsParser::providesSourceTitle(). Overrides FeedsParser:: |