diff --git a/class_rssfeed.php b/class_rssfeed.php deleted file mode 100755 index 59fd431..0000000 --- a/class_rssfeed.php +++ /dev/null @@ -1,277 +0,0 @@ - - * - * + 03/2013 - * Few changes, AutoblogRSS and FileRSSFeed - * @author Arthur Hoaro - */ -class RSSFeed { - protected $xml; - - /** - * Construct a RSS feed - */ - public function __construct() { - $template = << - - - - -END; - - $this->xml = new SimpleXMLElement($template); - } - - /** - * Set RSS Feed headers - * @param $title the title of the feed - * @param $link link to the website where you can find the RSS feed - * @param $description a description of the RSS feed - * @param $rsslink the link to this RSS feed - */ - public function setHeaders($title, $link, $description, $rsslink) { - $atomlink = $this->xml->channel->addChild("atom:link","","http://www.w3.org/2005/Atom"); - $atomlink->addAttribute("href",$rsslink); - $atomlink->addAttribute("rel","self"); - $atomlink->addAttribute("type","application/rss+xml"); - - $this->xml->channel->title = $title; - $this->xml->channel->link = $link; - $this->xml->channel->description = $description; - } - - /** - * Set the language of the RSS feed - * @param $lang the language of the RSS feed - */ - public function setLanguage($lang) { - $this->xml->channel->addChild("language",$lang); - } - /** - * Adds a picture to the RSS feed - * @param $url URL to the image - * @param $title The image title. Usually same as the RSS feed's title - * @param $link Where the image should link to. Usually same as the RSS feed's link - */ - public function setImage($url, $title, $link) { - $image = $this->xml->channel->addChild("image"); - $image->url = $url; - $image->title = $title; - $image->link = $link; - } - /** - * Add a item to the RSS feed - * @param $title The title of the RSS feed - * @param $link Link to the item's url - * @param $description The description of the item - * @param $author The author who wrote this item - * @param $guid Unique ID for this post - * @param $timestamp Unix timestamp for making a date - */ - public function addItem($title, $link, $description, $author, $guid, $timestamp) { - $item = $this->xml->channel->addChild("item"); - $item->title = $title; - $item->description = $description; - $item->link = $link; - $item->guid = $guid; - if( isset($guid['isPermaLink'])) - $item->guid['isPermaLink'] = $guid['isPermaLink']; - if( !empty( $author) ) - $item->author = $author; - $item->pubDate = date(DATE_RSS,intval($timestamp)); - } - /** - * Displays the RSS feed - */ - public function displayXML() { - header('Content-type: application/rss+xml; charset=utf-8'); - echo $this->xml->asXML(); - exit; - } - - public function getXML() { - return $this->xml; - } -} - -class RSSMerger { - private $feeds = array(); - - /** - * Constructs a RSSmerger object - */ - function __construct() { - - } - - /** - * Populates the feeds array from the given url which is a rss feed - * @param $url - */ - function add($xml) { - - foreach($xml->channel->item as $item) { - $item->sitetitle = $xml->channel->title; - $item->sitelink = $xml->channel->link; - - preg_match("/^[A-Za-z]{3}, ([0-9]{2}) ([A-Za-z]{3}) ([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) ([\+|\-]?[0-9]{4})$/", $item->pubDate, $match); - $item->time = time($match[4]+($match[6]/100),$match[5],$match[6],date("m",strtotime($match[2])),$match[1],$match[3]); - - $this->feeds[] = $item; - } - } - /** - * Comparing function for sorting the feeds - * @param $value1 - * @param $value2 - */ - function feeds_cmp($value1,$value2) { - if(intval($value1->time) == intval($value2->time)) - return 0; - - return (intval($value1->time) < intval($value2->time)) ? +1 : -1; - } - - /** - * Sorts the feeds array using the Compare function feeds_cmp - */ - function sort() { - usort($this->feeds,Array("RssMerger","feeds_cmp")); - } - - /** - * This function return the feed items. - * @param $limit how many feed items that should be returned - * @return the feeds array - */ - function getFeeds($limit) { - return array_slice($this->feeds,0,$limit); - } -} - -class FileRSSFeed extends RSSFeed { - protected $filename; - - public function __construct($filename) { - parent::__construct(); - $this->filename = $filename; - - $this->load(); - } - - public function load() { - if ( file_exists( $this->filename )) { - $this->xml = simplexml_load_file($this->filename); - } - } - - public function create($title, $link, $description, $rsslink) { - parent::setHeaders($title, $link, $description, $rsslink); - $this->write(); - } - - public function addItem($title, $link, $description, $author, $guid, $timestamp) { - parent::addItem($title, $link, $description, $author, $guid, $timestamp); - $this->write(); - } - - private function write() { - if ( file_exists( $this->filename )) { - unlink($this->filename); - } - - $outputXML = new RSSFeed(); - foreach($this->xml->channel->item as $f) { - $item = $outputXML->addItem($f->title,$f->link,$f->description,$f->author,$f->guid, strtotime($f->pubDate)); - } - - $merger = new RssMerger(); - $merger->add($outputXML->getXML()); - $merger->sort(); - - unset($this->xml->channel->item); - foreach($merger->getFeeds(20) as $f) { - parent::addItem($f->title,$f->link,$f->description,$f->author,$f->guid,$f->time); - } - - file_put_contents( $this->filename, $this->xml->asXML(), LOCK_EX ); - } -} - -class AutoblogRSS extends FileRSSFeed { - public function __construct($filename) { - parent::__construct($filename); - } - - public function addUnavailable($title, $folder, $siteurl, $rssurl) { - $path = pathinfo( $_SERVER['PHP_SELF'] ); - $autobHref = 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'. - $_SERVER["SERVER_NAME"].':'.$_SERVER["SERVER_PORT"]. $path['dirname'].'/'.$folder; - - parent::addItem( 'L\'autoblog "'. $title.'" est indisponible', $autobHref, - 'Autoblog: '.$title.'
- Site: '. $siteurl .'
- RSS: '.$rssurl.'
- Folder: '. $folder , - 'admin@'.$_SERVER['SERVER_NAME'], - $autobHref, - time() - ); - } - - public function addAvailable($title, $folder, $siteurl, $rssurl) { - $path = pathinfo( $_SERVER['PHP_SELF'] ); - $autobHref = 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'. - $_SERVER["SERVER_NAME"].':'.$_SERVER["SERVER_PORT"]. $path['dirname'].'/'.$folder; - - parent::addItem( 'L\'autoblog "'. $title.'" est de nouveau disponible', $autobHref, - 'Autoblog : '.$title.'
- Site: '. $siteurl .'
- RSS: '.$rssurl.'
- Folder: '. $folder , - 'admin@'.$_SERVER['SERVER_NAME'], - $autobHref, - time() - ); - } - - public function addCodeChanged($title, $folder, $siteurl, $rssurl, $code) { - $path = pathinfo( $_SERVER['PHP_SELF'] ); - $autobHref = 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'. - $_SERVER["SERVER_NAME"].':'.$_SERVER["SERVER_PORT"]. $path['dirname'].'/'.$folder; - - parent::addItem( 'L\'autoblog "'. $title.'" a renvoyé un code imprévu', $autobHref, - 'Code: '. $code .'
- Autoblog : '.$title.'
- Site: '. $siteurl .'
- RSS: '.$rssurl.'
- Folder: '. $folder , - 'admin@'.$_SERVER['SERVER_NAME'], - $autobHref, - time() - ); - } - - public function addNewAutoblog($title, $folder, $siteurl, $rssurl) { - $path = pathinfo( $_SERVER['PHP_SELF'] ); - $autobHref = 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'. - $_SERVER["SERVER_NAME"].':'.$_SERVER["SERVER_PORT"]. $path['dirname'].'/'.$folder; - - parent::addItem( 'L\'autoblog "'. $title.'" a été ajouté à la ferme', $autobHref, - 'Autoblog : '.$title.'
- Site: '. $siteurl .'
- RSS: '.$rssurl.'
- Folder: '. $folder , - 'admin@'.$_SERVER['SERVER_NAME'], - $autobHref, - time() - ); - } -} - -?> diff --git a/functions.php b/functions.php index 8d4ffec..2e3496f 100755 --- a/functions.php +++ b/functions.php @@ -12,7 +12,6 @@ define('LOCAL_URI', ''); if (!defined('AUTOBLOGS_FOLDER')) define('AUTOBLOGS_FOLDER', './autoblogs/'); if (!defined('DOC_FOLDER')) define('DOC_FOLDER', './docs/'); if (!defined('RESOURCES_FOLDER')) define('RESOURCES_FOLDER', './resources/'); -if (!defined('RSS_FILE')) define('RSS_FILE', RESOURCES_FOLDER.'rss.xml'); if (!defined('FOLDER_MAX_LENGTH')) define('FOLDER_MAX_LENGTH', 80); date_default_timezone_set('Europe/Paris'); setlocale(LC_TIME, 'fr_FR.UTF-8', 'fr_FR', 'fr'); @@ -133,11 +132,6 @@ UPDATE_TIMEOUT="'. getTimeout( $type ) .'"') ) else throw new Exception('Impossible de créer le répertoire.'); - /* @Mitsu: Il faudrait remonter les erreurs d'I/O */ - /* Comme ça ? :) */ - /* Arthur 29/04/13 : En fait c'était une mauvaise idée : on rend de nouveau bloquant l'écrire du flux RSS, qui est une feature mineure */ - // if(updateXML('new_autoblog_added', 'new', $foldername, $sitename, $siteurl, $rssurl) === FALSE) - // { throw new Exception('Impossible d\'écrire le fichier rss.json'); } updateXML('new_autoblog_added', 'new', $foldername, $sitename, $siteurl, $rssurl); } @@ -252,7 +246,7 @@ if(file_put_contents(RESOURCES_FOLDER.'rss.json', json_encode($json), LOCK_EX) = else { return TRUE; } } -function displayXMLstatus_tmp($status, $response_code, $autoblog_url, $autoblog_title, $autoblog_sourceurl, $autoblog_sourcefeed) { +function displayXMLstatus($status, $response_code, $autoblog_url, $autoblog_title, $autoblog_sourceurl, $autoblog_sourcefeed) { switch ($status) { case 'unavailable': @@ -270,17 +264,17 @@ function displayXMLstatus_tmp($status, $response_code, $autoblog_url, $autoblog_ } } -function displayXML_tmp() { +function displayXML() { header('Content-type: application/rss+xml; charset=utf-8'); echo ' '.serverUrl(true).''; -echo 'Projet Autoblog'. ((strlen(HEAD_TITLE)>0) ? ' | '. HEAD_TITLE : '').''.serverUrl(true),"Projet Autoblog - RSS : Ajouts et changements de disponibilité.".''; +echo 'Projet Autoblog'. ((strlen(HEAD_TITLE)>0) ? ' | '. HEAD_TITLE : '').''.serverUrl(true),"Projet Autoblog - RSS : Ajouts et changements de disponibilité.".''; if(file_exists(RESOURCES_FOLDER.'rss.json')) { $json = json_decode(file_get_contents(RESOURCES_FOLDER.'rss.json'), true); foreach ($json as $item) { - $description = displayXMLstatus_tmp($item['status'],$item['response_code'],$item['autoblog_url'],$item['autoblog_title'],$item['autoblog_sourceurl'],$item['autoblog_sourcefeed']); + $description = displayXMLstatus($item['status'],$item['response_code'],$item['autoblog_url'],$item['autoblog_title'],$item['autoblog_sourceurl'],$item['autoblog_sourcefeed']); $link = serverUrl(true).AUTOBLOGS_FOLDER.$item['autoblog_url']; $date = date("r", $item['timestamp']); print <<addUnavailable($ini['SITE_TITLE'], escape($_GET['check']), $ini['SITE_URL'], $ini['FEED_URL']); updateXML('unavailable', 'nxdomain', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']); } file_put_contents($errorlog, '..'); @@ -235,9 +232,6 @@ if (isset($_GET['check'])) /* code retour 200: flux disponible */ if($code[1] == "200") { if( $oldvalue !== null && $oldvalue != '' ) { - require_once('class_rssfeed.php'); - $rss = new AutoblogRSS(RSS_FILE); - $rss->addAvailable($ini['SITE_TITLE'], escape($_GET['check']), $ini['SITE_URL'], $ini['FEED_URL']); updateXML('available', '200', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']); } file_put_contents($errorlog, ''); @@ -246,9 +240,6 @@ if (isset($_GET['check'])) /* autre code retour: un truc a changé (redirection, changement de CMS, .. bref vvb.ini doit être corrigé) */ else { if( $oldvalue !== null && $oldvalue != '.' ) { - require_once('class_rssfeed.php'); - $rss = new AutoblogRSS(RSS_FILE); - $rss->addCodeChanged($ini['SITE_TITLE'], escape($_GET['check']), $ini['SITE_URL'], $ini['FEED_URL'], $code[1]); updateXML('moved', '3xx', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']); } file_put_contents($errorlog, '.'); @@ -355,7 +346,6 @@ if (isset($_GET['exportopml'])) // OPML /** * Site map - * NEW AUTOBLOG FOLDER - Need update **/ if (isset($_GET['sitemap'])) { @@ -541,6 +531,7 @@ if(!empty($_POST['socialaccount']) && !empty($_POST['socialinstance']) && ALLOW_ try { // TwitterBridge user will be allowed after Autoblog creation // TODO: Twitter user does not exist ? + // TODO: get remote like http://wwz.suumitsu.eu/twitter/whitelist.json, decode, check if is in array, return error or continue if($sitetype != 'twitter') { $headers = get_headers($rssurl, 1); if (strpos($headers[0], '200') === FALSE) @@ -669,7 +660,7 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY Projet Autoblog<?php if(strlen(HEAD_TITLE)>0) echo " | " . HEAD_TITLE; ?> - +