mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-12 11:34:09 +02:00
Little refactoring to reduce logic on index.php.
Moved RssExpander as a core logic system to lib/Bridge.php Signed-off-by: teromene <teromene@teromene.fr>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once 'bridges/RssExpander.php';
|
||||
define("RSS", 'http://feeds.feedburner.com/Freenews-Freebox?format=xml');
|
||||
define("FREENEWS_RSS", 'http://feeds.feedburner.com/Freenews-Freebox?format=xml');
|
||||
class Freenews extends RssExpander {
|
||||
|
||||
public function loadMetadatas() {
|
||||
@@ -21,8 +20,7 @@ class Freenews extends RssExpander {
|
||||
}
|
||||
|
||||
public function collectData(array $param){
|
||||
$param['url'] = RSS;
|
||||
parent::collectData($param);
|
||||
parent::collectExpandableDatas($param, FREENEWS_RSS);
|
||||
}
|
||||
|
||||
protected function parseRSSItem($newsItem) {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require_once 'bridges/RssExpander.php';
|
||||
define("RSS_PREFIX", "http://feeds.gawker.com/");
|
||||
define("RSS_SUFFIX", "/full");
|
||||
|
||||
class Gawker extends RssExpander{
|
||||
|
||||
public function loadMetadatas() {
|
||||
@@ -34,7 +34,7 @@ class Gawker extends RssExpander{
|
||||
$param['url'] = $this->toURI(strtolower($param['site']));
|
||||
}
|
||||
// $this->message("loading feed from ".$this->getURI());
|
||||
parent::collectData($param);
|
||||
parent::collectExpandableDatas($param, $name);
|
||||
}
|
||||
|
||||
protected function parseRSSItem($newsItem) {
|
||||
|
@@ -1,11 +1,7 @@
|
||||
<?php
|
||||
require_once 'bridges/RssExpander.php';
|
||||
define("SEXE", "http://sexes.blogs.liberation.fr");
|
||||
define("SEXE_FEED", "http://sexes.blogs.liberation.fr/feeds/");
|
||||
/**
|
||||
* As it seems that Les 400 culs currently offer a full feed, we won't change it content here.
|
||||
* But I'm ready for the day where it will ... again ... provide some truncated content
|
||||
*/
|
||||
|
||||
class Les400Culs extends RssExpander{
|
||||
|
||||
public function loadMetadatas() {
|
||||
@@ -20,8 +16,7 @@ class Les400Culs extends RssExpander{
|
||||
|
||||
|
||||
public function collectData(array $param){
|
||||
$param['url'] = SEXE_FEED;
|
||||
parent::collectData($param);
|
||||
parent::collectExpandableDatas($param, SEXE_FEED);
|
||||
}
|
||||
|
||||
protected function parseRSSItem($newsItem) {
|
||||
|
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A class providing facilities for RSS expansion. The goal here is to facilitate, as much as possible, writing bridges such as FreeNews, Gawker and other ones
|
||||
* @name RssExpander
|
||||
* @description Un bridge générique d'expansion automatique de contenu RSS ... pour tous ces sites qui ont un flux RSS mochement tonqué.
|
||||
* @update 15/03/2015
|
||||
* @use1(url="URL du flux dont vous souhaitez le contenu complet")
|
||||
*/
|
||||
|
||||
abstract class RssExpander extends HttpCachingBridgeAbstract{
|
||||
public $name;
|
||||
public $uri;
|
||||
public $description;
|
||||
public function collectData(array $param){
|
||||
if (empty($param['url'])) {
|
||||
$this->returnError('There is no $param[\'url\'] for this RSS expander', 404);
|
||||
}
|
||||
// $this->message("Loading from ".$param['url']);
|
||||
// Notice WE DO NOT use cache here on purpose : we want a fresh view of the RSS stream each time
|
||||
$rssContent = simplexml_load_file($param['url']) or $this->returnError('Could not request '.$param['url'], 404);
|
||||
// $this->message("loaded RSS from ".$param['url']);
|
||||
// TODO insert RSS format detection
|
||||
// we suppose for now, we have some RSS 2.0
|
||||
$this->collect_RSS_2_0_data($rssContent);
|
||||
}
|
||||
|
||||
protected function collect_RSS_2_0_data($rssContent) {
|
||||
$rssContent = $rssContent->channel[0];
|
||||
// $this->message("RSS content is ===========\n".var_export($rssContent, true)."===========");
|
||||
$this->load_RSS_2_0_feed_data($rssContent);
|
||||
foreach($rssContent->item as $item) {
|
||||
// $this->message("parsing item ".var_export($item, true));
|
||||
$this->items[] = $this->parseRSSItem($item);
|
||||
}
|
||||
}
|
||||
|
||||
protected function RSS_2_0_time_to_timestamp($item) {
|
||||
return DateTime::createFromFormat('D, d M Y H:i:s e', $item->pubDate)->getTimestamp();
|
||||
}
|
||||
|
||||
// TODO set title, link, description, language, and so on
|
||||
protected function load_RSS_2_0_feed_data($rssContent) {
|
||||
$this->name = trim($rssContent->title);
|
||||
$this->uri = trim($rssContent->link);
|
||||
$this->description = trim($rssContent->description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method should return, from a source RSS item given by lastRSS, one of our Items objects
|
||||
* @param $item the input rss item
|
||||
* @return a RSS-Bridge Item, with (hopefully) the whole content)
|
||||
*/
|
||||
abstract protected function parseRSSItem($item);
|
||||
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getURI(){
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
}
|
@@ -1,7 +1,4 @@
|
||||
<?php
|
||||
|
||||
require_once 'bridges/RssExpander.php';
|
||||
|
||||
define("THE_OATMEAL", "http://theoatmeal.com/");
|
||||
define("THE_OATMEAL_RSS", "http://feeds.feedburner.com/oatmealfeed");
|
||||
|
||||
@@ -18,8 +15,7 @@ class TheOatmealBridge extends RssExpander{
|
||||
}
|
||||
|
||||
public function collectData(array $param){
|
||||
$param['url'] = THE_OATMEAL_RSS;
|
||||
parent::collectData($param);
|
||||
parent::collectExpandableDatas($param, THE_OATMEAL_RSS);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user