mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-12-18 08:54:20 +03:00
[FeedExpander] Rewrite on latest commit
parent
caa502b720
commit
090d2158fe
2 changed files with 108 additions and 129 deletions
108
FeedExpander.md
Normal file
108
FeedExpander.md
Normal file
|
@ -0,0 +1,108 @@
|
|||
`FeedExpander` extends [`HttpCachingBridgeAbstract`](HttpCachingBridgeAbstract) and adds functions to collect data from existing feeds.
|
||||
|
||||
**Usage example**: _You have discovered a site that provides feeds which are hidden and inaccessible by normal means. You want your bridge to directly read the feeds and provide them via **RSS-Bridge**_
|
||||
|
||||
To create a new Bridge extending `FeedExpander` you must implement all required functions of [`BridgeAbstract`](BridgeAbstract). You may also use all functions defined by [`HttpCachingBridgeAbstract`](HttpCachingBridgeAbstract). `FeedExpander` additionally provides following functions:
|
||||
|
||||
* [`parseItem`](#the-parseItem-function) (**required**)
|
||||
* [`getName`](#the-getName-function)
|
||||
* [`getURI`](#the-getURI-function)
|
||||
* [`getDescription`](#the-getDescription-function)
|
||||
|
||||
Find a [template](#template) at the end of this file.
|
||||
|
||||
**Notice:** For a standard RSS 2.0 feed only `collectData` and [`parseItem`](#the-parseItem-function) need to be implemented. `collectData` should call `$this->collectExpandableDatas('your URI here');` to automatically load feed items and header data (will subsequently call `parseItem` for each item found in the feed).
|
||||
|
||||
## The `parseItem` function
|
||||
|
||||
This function receives one item from the current feed and should return one **RSS-Bridge** item.
|
||||
|
||||
**Notice:** The following code sample is just an example. Implementation depends on your requirements!
|
||||
|
||||
```PHP
|
||||
protected function parseItem($feedItem){
|
||||
$item = array();
|
||||
$item['title'] = $feedItem->title;
|
||||
$item['uri'] = $feedItem->link;
|
||||
$item['author'] = $feedItem->autor;
|
||||
$item['timestamp'] = $this->RSS_2_0_time_to_timestamp($feedItem);
|
||||
$item['content'] = $feedItem->content;
|
||||
|
||||
return $item;
|
||||
}
|
||||
```
|
||||
|
||||
### Helper functions
|
||||
|
||||
The `FeedExpander` already provides a set of functions to parse RSS or ATOM items based on the specifications. Where possible make use of these functions:
|
||||
|
||||
Function | Description
|
||||
---------|------------
|
||||
`parseATOMItem` | Parses an item from a ATOM 1.0 feed
|
||||
`parseRSS_0_9_1_Item` | Parses an item from an RSS 0.91 feed
|
||||
`parseRSS_1_0_Item` | Parses an item from an RSS 1.0 feed
|
||||
`parseRSS_2_0_Item` | Parses an item from an RSS 2.0 feed
|
||||
|
||||
These functions will attempt to load as many data as possible from a feed item. However not all functions return all item data. Find a list off supported item tags and paramters in the following list:
|
||||
|
||||
Function | uri | title | timestamp | author | content
|
||||
---------|-----|-------|-----------|--------|--------
|
||||
`parseATOMItem` | id | title | updated | author | content
|
||||
`parseRSS_0_9_1_Item` | link | title | | | description
|
||||
`parseRSS_1_0_Item` | link | title | dc:date | dc:creator | description
|
||||
`parseRSS_2_0_Item` | link | title | pubDate, dc:date | author, dc:creator | description
|
||||
|
||||
## The `getName` function
|
||||
|
||||
Returns the name of the current feed.
|
||||
|
||||
```PHP
|
||||
return $this->name;
|
||||
```
|
||||
|
||||
**Notice:** Only implement this function if you require different behavior!
|
||||
|
||||
## The `getURI` function
|
||||
|
||||
Return the uri for the current feed.
|
||||
|
||||
```PHP
|
||||
return $this->uri;
|
||||
```
|
||||
|
||||
**Notice:** Only implement this function if you require different behavior!
|
||||
|
||||
## The `getDescription` function
|
||||
|
||||
Returns the description for the current bridge.
|
||||
|
||||
```PHP
|
||||
return $this->description;
|
||||
```
|
||||
|
||||
**Notice:** Only implement this function if you require different behavior!
|
||||
|
||||
# Template
|
||||
|
||||
This is the template for a new bridge:
|
||||
|
||||
```PHP
|
||||
<?php
|
||||
class MySiteBridge extends FeedExpander {
|
||||
|
||||
const MAINTAINER = 'No maintainer';
|
||||
const NAME = 'Unnamed bridge';
|
||||
const URI = '';
|
||||
const DESCRIPTION = 'No description provided';
|
||||
const PARAMETERS = array();
|
||||
|
||||
public function collectData(){
|
||||
$this->collectExpandableDatas('your feed URI');
|
||||
}
|
||||
|
||||
protected function parseItem($feedItem){
|
||||
return $this->parseRSS_2_0_Item($feedItem);
|
||||
}
|
||||
}
|
||||
// Imaginary empty line!
|
||||
```
|
129
RssExpander.md
129
RssExpander.md
|
@ -1,129 +0,0 @@
|
|||
`RssExpander` extends [`HttpCachingBridgeAbstract`](HttpCachingBridgeAbstract) and adds functions to collect data from existing RSS feeds.
|
||||
|
||||
**Usage example**: _You have discovered a site that provides RSS feeds which are hidden and inaccessible by normal means. Tough it is possible if you know the URL. You want your bridge to directly read the feeds and provide them via **RSS-Bridge**_
|
||||
|
||||
To create a new Bridge extending `RssExpander` you must implement all required functions of [`BridgeAbstract`](BridgeAbstract). You may also use all functions defined by [`HttpCachingBridgeAbstract`](HttpCachingBridgeAbstract). `RssExpander` additionally provides following functions:
|
||||
|
||||
* [`parseRSSItem`](#the-parseRSSItem-function) (**required**)
|
||||
* [`collectExpandableDatas`](#the-collectExpandableDatas-function)
|
||||
* [`collect_RSS_2_0_data`](#the-collect_RSS_2_0_data-function)
|
||||
* [`RSS_2_0_time_to_timestamp`](#the-RSS_2_0_time_to_timestamp-function)
|
||||
* [`load_RSS_2_0_feed_data`](#the-load_RSS_2_0_feed_data-function)
|
||||
* [`getDescription`](#the-getDescription-function)
|
||||
|
||||
Find a [template](#template) at the end of this file.
|
||||
|
||||
**Notice:** For a standard RSS 2.0 feed only [`parseRSSItem`](#the-parseRSSItem-function) needs to be implemented.
|
||||
|
||||
## The `parseRSSItem` function
|
||||
|
||||
This function receives one item from the current RSS feed and should return one element of the [Item](BridgeAbstract#items) class.
|
||||
|
||||
**Notice:** The following code sample is just an example. Implementation depends on your requirements!
|
||||
|
||||
```PHP
|
||||
protected function parseRSSItem($rssItem){
|
||||
$item = new \Item();
|
||||
$item->title = $rssItem->title;
|
||||
$item->uri = $rssItem->link;
|
||||
$item->author = $rssItem->autor;
|
||||
$item->timestamp = $this->RSS_2_0_time_to_timestamp($rssItem);
|
||||
$item->content = $rssItem->content;
|
||||
|
||||
return $item;
|
||||
}
|
||||
```
|
||||
|
||||
**Notice:** This function is automatically called by the [`collect_RSS_2_0_data`](#the-collect_RSS_2_0_data-function) function, unless the bridge implements that function differently.
|
||||
|
||||
## The `collectExpandableDatas` function
|
||||
|
||||
This function loads the RSS data from a given URL.
|
||||
|
||||
```PHP
|
||||
public function collectExpandableDatas(array $param, $name){
|
||||
if (empty($name))
|
||||
$this->returnServerError('There is no $name for this RSS expander');
|
||||
|
||||
$content = $this->getContents($name) or $this->returnServerError('Could not request ' . $name . '!');
|
||||
$rssContent = simplexml_load_string($content);
|
||||
$this->collect_RSS_2_0_data($rssContent);
|
||||
}
|
||||
```
|
||||
|
||||
**Notice:** Only implement this function if you require different behavior!
|
||||
|
||||
## The `collect_RSS_2_0_data` function
|
||||
|
||||
This function will iterate over the contents of an RSS 2.0 feed
|
||||
|
||||
```PHP
|
||||
protected function collect_RSS_2_0_data($rssContent){
|
||||
$channelData = $rssContent->channel[0];
|
||||
$this->load_RSS_2_0_feed_data($channelData);
|
||||
foreach($channelData->item as $item){
|
||||
$this->items[] = $this->parseRSSItem($item);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Notice:** Only implement this function if you require different behavior!
|
||||
|
||||
## The `RSS_2_0_time_to_timestamp` function
|
||||
|
||||
This function will convert the RSS 2.0 times to a timestamp valid for **RSS-Bridge**
|
||||
|
||||
```PHP
|
||||
protected function RSS_2_0_time_to_timestamp($item) {
|
||||
return DateTime::createFromFormat('D, d M Y H:i:s e', $item->pubDate)->getTimestamp();
|
||||
}
|
||||
```
|
||||
|
||||
**Notice:** Only implement this function if you require different behavior!
|
||||
|
||||
## The `load_RSS_2_0_feed_data` function
|
||||
|
||||
This function will load header information from the current RSS feed.
|
||||
|
||||
```PHP
|
||||
protected function load_RSS_2_0_feed_data($rssContent) {
|
||||
$this->name = $rssContent->title;
|
||||
$this->uri = $rssContent->link;
|
||||
$this->description = $rssContent->description;
|
||||
}
|
||||
```
|
||||
|
||||
**Notice:** Only implement this function if you require different behavior!
|
||||
|
||||
## The `getDescription` function
|
||||
|
||||
This function returns the description for the current bridge.
|
||||
|
||||
```PHP
|
||||
return $this->description;
|
||||
```
|
||||
|
||||
**Notice:** Only implement this function if you require different behavior!
|
||||
|
||||
# Template
|
||||
|
||||
This is the template for a new bridge:
|
||||
|
||||
```PHP
|
||||
<?php
|
||||
class MySiteBridge extends RssExpander{
|
||||
public function loadMetadatas(){
|
||||
$this->maintainer = 'No maintainer';
|
||||
$this->name = 'Unnamed bridge';
|
||||
$this->uri = '';
|
||||
$this->description = 'No description provided';
|
||||
$this->parameters = array();
|
||||
}
|
||||
|
||||
public function collectData(array $params){
|
||||
// Implement your bridge here!
|
||||
parent::collectExpandableDatas($params, 'your RSS URL');
|
||||
}
|
||||
}
|
||||
// Imaginary empty line!
|
||||
```
|
Loading…
Reference in a new issue