mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-05-05 13:44:43 -04:00
Création de lib_opml pour alléger lib_rss
Et suppression de fonctions inutilisées
This commit is contained in:
@@ -283,6 +283,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
|
||||
}
|
||||
|
||||
public function importExportAction () {
|
||||
require_once(LIB_PATH . '/lib_opml.php');
|
||||
$catDAO = new FreshRSS_CategoryDAO ();
|
||||
$this->view->categories = $catDAO->listCategories ();
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php if ($this->req == 'export') { ?>
|
||||
<?php echo '<?xml version="1.0" encoding="UTF-8" ?>'; // résout bug sur certain serveur ?>
|
||||
<?php
|
||||
require_once(LIB_PATH . '/lib_opml.php');
|
||||
if ($this->req == 'export') {
|
||||
echo '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
?>
|
||||
<!-- Generated by <?php echo Minz_Configuration::title (); ?> -->
|
||||
<opml version="2.0">
|
||||
<head>
|
||||
|
||||
121
lib/lib_opml.php
Normal file
121
lib/lib_opml.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
function opml_export ($cats) {
|
||||
$txt = '';
|
||||
|
||||
foreach ($cats as $cat) {
|
||||
$txt .= '<outline text="' . $cat['name'] . '">' . "\n";
|
||||
|
||||
foreach ($cat['feeds'] as $feed) {
|
||||
$txt .= "\t" . '<outline text="' . $feed->name () . '" type="rss" xmlUrl="' . $feed->url () . '" htmlUrl="' . $feed->website () . '" description="' . htmlspecialchars($feed->description(), ENT_COMPAT, 'UTF-8') . '" />' . "\n";
|
||||
}
|
||||
|
||||
$txt .= '</outline>' . "\n";
|
||||
}
|
||||
|
||||
return $txt;
|
||||
}
|
||||
|
||||
function opml_import ($xml) {
|
||||
$xml = html_only_entity_decode($xml); //!\ Assume UTF-8
|
||||
|
||||
$dom = new DOMDocument();
|
||||
$dom->recover = true;
|
||||
$dom->strictErrorChecking = false;
|
||||
$dom->loadXML($xml);
|
||||
$dom->encoding = 'UTF-8';
|
||||
|
||||
$opml = simplexml_import_dom($dom);
|
||||
|
||||
if (!$opml) {
|
||||
throw new FreshRSS_Opml_Exception ();
|
||||
}
|
||||
|
||||
$catDAO = new FreshRSS_CategoryDAO();
|
||||
$catDAO->checkDefault();
|
||||
$defCat = $catDAO->getDefault();
|
||||
|
||||
$categories = array ();
|
||||
$feeds = array ();
|
||||
|
||||
foreach ($opml->body->outline as $outline) {
|
||||
if (!isset ($outline['xmlUrl'])) {
|
||||
// Catégorie
|
||||
$title = '';
|
||||
|
||||
if (isset ($outline['text'])) {
|
||||
$title = (string) $outline['text'];
|
||||
} elseif (isset ($outline['title'])) {
|
||||
$title = (string) $outline['title'];
|
||||
}
|
||||
|
||||
if ($title) {
|
||||
// Permet d'éviter les soucis au niveau des id :
|
||||
// ceux-ci sont générés en fonction de la date,
|
||||
// un flux pourrait être dans une catégorie X avec l'id Y
|
||||
// alors qu'il existe déjà la catégorie X mais avec l'id Z
|
||||
// Y ne sera pas ajouté et le flux non plus vu que l'id
|
||||
// de sa catégorie n'exisera pas
|
||||
$title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
|
||||
$catDAO = new FreshRSS_CategoryDAO ();
|
||||
$cat = $catDAO->searchByName ($title);
|
||||
if ($cat === false) {
|
||||
$cat = new FreshRSS_Category ($title);
|
||||
$values = array (
|
||||
'name' => $cat->name (),
|
||||
'color' => $cat->color ()
|
||||
);
|
||||
$cat->_id ($catDAO->addCategory ($values));
|
||||
}
|
||||
|
||||
$feeds = array_merge ($feeds, getFeedsOutline ($outline, $cat->id ()));
|
||||
}
|
||||
} else {
|
||||
// Flux rss sans catégorie, on récupère l'ajoute dans la catégorie par défaut
|
||||
$feeds[] = getFeed ($outline, $defCat->id());
|
||||
}
|
||||
}
|
||||
|
||||
return array ($categories, $feeds);
|
||||
}
|
||||
|
||||
/**
|
||||
* import all feeds of a given outline tag
|
||||
*/
|
||||
function getFeedsOutline ($outline, $cat_id) {
|
||||
$feeds = array ();
|
||||
|
||||
foreach ($outline->children () as $child) {
|
||||
if (isset ($child['xmlUrl'])) {
|
||||
$feeds[] = getFeed ($child, $cat_id);
|
||||
} else {
|
||||
$feeds = array_merge(
|
||||
$feeds,
|
||||
getFeedsOutline ($child, $cat_id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $feeds;
|
||||
}
|
||||
|
||||
function getFeed ($outline, $cat_id) {
|
||||
$url = (string) $outline['xmlUrl'];
|
||||
$url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8');
|
||||
$title = '';
|
||||
if (isset ($outline['text'])) {
|
||||
$title = (string) $outline['text'];
|
||||
} elseif (isset ($outline['title'])) {
|
||||
$title = (string) $outline['title'];
|
||||
}
|
||||
$title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
|
||||
$feed = new FreshRSS_Feed ($url);
|
||||
$feed->_category ($cat_id);
|
||||
$feed->_name ($title);
|
||||
if (isset($outline['htmlUrl'])) {
|
||||
$feed->_website(htmlspecialchars((string)$outline['htmlUrl'], ENT_COMPAT, 'UTF-8'));
|
||||
}
|
||||
if (isset($outline['description'])) {
|
||||
$feed->_description(sanitizeHTML((string)$outline['description']));
|
||||
}
|
||||
return $feed;
|
||||
}
|
||||
133
lib/lib_rss.php
133
lib/lib_rss.php
@@ -98,33 +98,6 @@ function timestamptodate ($t, $hour = true) {
|
||||
return @date ($date, $t);
|
||||
}
|
||||
|
||||
function sortEntriesByDate ($entry1, $entry2) {
|
||||
return $entry2->date (true) - $entry1->date (true);
|
||||
}
|
||||
function sortReverseEntriesByDate ($entry1, $entry2) {
|
||||
return $entry1->date (true) - $entry2->date (true);
|
||||
}
|
||||
|
||||
function get_domain ($url) {
|
||||
return parse_url($url, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
function opml_export ($cats) {
|
||||
$txt = '';
|
||||
|
||||
foreach ($cats as $cat) {
|
||||
$txt .= '<outline text="' . $cat['name'] . '">' . "\n";
|
||||
|
||||
foreach ($cat['feeds'] as $feed) {
|
||||
$txt .= "\t" . '<outline text="' . $feed->name () . '" type="rss" xmlUrl="' . $feed->url () . '" htmlUrl="' . $feed->website () . '" description="' . htmlspecialchars($feed->description(), ENT_COMPAT, 'UTF-8') . '" />' . "\n";
|
||||
}
|
||||
|
||||
$txt .= '</outline>' . "\n";
|
||||
}
|
||||
|
||||
return $txt;
|
||||
}
|
||||
|
||||
function html_only_entity_decode($text) {
|
||||
static $htmlEntitiesOnly = null;
|
||||
if ($htmlEntitiesOnly === null) {
|
||||
@@ -144,112 +117,6 @@ function sanitizeHTML($data) {
|
||||
return html_only_entity_decode($simplePie->sanitize->sanitize($data, SIMPLEPIE_CONSTRUCT_MAYBE_HTML));
|
||||
}
|
||||
|
||||
function opml_import ($xml) {
|
||||
$xml = html_only_entity_decode($xml); //!\ Assume UTF-8
|
||||
|
||||
$dom = new DOMDocument();
|
||||
$dom->recover = true;
|
||||
$dom->strictErrorChecking = false;
|
||||
$dom->loadXML($xml);
|
||||
$dom->encoding = 'UTF-8';
|
||||
|
||||
$opml = simplexml_import_dom($dom);
|
||||
|
||||
if (!$opml) {
|
||||
throw new FreshRSS_Opml_Exception ();
|
||||
}
|
||||
|
||||
$catDAO = new FreshRSS_CategoryDAO();
|
||||
$catDAO->checkDefault();
|
||||
$defCat = $catDAO->getDefault();
|
||||
|
||||
$categories = array ();
|
||||
$feeds = array ();
|
||||
|
||||
foreach ($opml->body->outline as $outline) {
|
||||
if (!isset ($outline['xmlUrl'])) {
|
||||
// Catégorie
|
||||
$title = '';
|
||||
|
||||
if (isset ($outline['text'])) {
|
||||
$title = (string) $outline['text'];
|
||||
} elseif (isset ($outline['title'])) {
|
||||
$title = (string) $outline['title'];
|
||||
}
|
||||
|
||||
if ($title) {
|
||||
// Permet d'éviter les soucis au niveau des id :
|
||||
// ceux-ci sont générés en fonction de la date,
|
||||
// un flux pourrait être dans une catégorie X avec l'id Y
|
||||
// alors qu'il existe déjà la catégorie X mais avec l'id Z
|
||||
// Y ne sera pas ajouté et le flux non plus vu que l'id
|
||||
// de sa catégorie n'exisera pas
|
||||
$title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
|
||||
$catDAO = new FreshRSS_CategoryDAO ();
|
||||
$cat = $catDAO->searchByName ($title);
|
||||
if ($cat === false) {
|
||||
$cat = new FreshRSS_Category ($title);
|
||||
$values = array (
|
||||
'name' => $cat->name (),
|
||||
'color' => $cat->color ()
|
||||
);
|
||||
$cat->_id ($catDAO->addCategory ($values));
|
||||
}
|
||||
|
||||
$feeds = array_merge ($feeds, getFeedsOutline ($outline, $cat->id ()));
|
||||
}
|
||||
} else {
|
||||
// Flux rss sans catégorie, on récupère l'ajoute dans la catégorie par défaut
|
||||
$feeds[] = getFeed ($outline, $defCat->id());
|
||||
}
|
||||
}
|
||||
|
||||
return array ($categories, $feeds);
|
||||
}
|
||||
|
||||
/**
|
||||
* import all feeds of a given outline tag
|
||||
*/
|
||||
function getFeedsOutline ($outline, $cat_id) {
|
||||
$feeds = array ();
|
||||
|
||||
foreach ($outline->children () as $child) {
|
||||
if (isset ($child['xmlUrl'])) {
|
||||
$feeds[] = getFeed ($child, $cat_id);
|
||||
} else {
|
||||
$feeds = array_merge(
|
||||
$feeds,
|
||||
getFeedsOutline ($child, $cat_id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $feeds;
|
||||
}
|
||||
|
||||
function getFeed ($outline, $cat_id) {
|
||||
$url = (string) $outline['xmlUrl'];
|
||||
$url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8');
|
||||
$title = '';
|
||||
if (isset ($outline['text'])) {
|
||||
$title = (string) $outline['text'];
|
||||
} elseif (isset ($outline['title'])) {
|
||||
$title = (string) $outline['title'];
|
||||
}
|
||||
$title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
|
||||
$feed = new FreshRSS_Feed ($url);
|
||||
$feed->_category ($cat_id);
|
||||
$feed->_name ($title);
|
||||
if (isset($outline['htmlUrl'])) {
|
||||
$feed->_website(htmlspecialchars((string)$outline['htmlUrl'], ENT_COMPAT, 'UTF-8'));
|
||||
}
|
||||
if (isset($outline['description'])) {
|
||||
$feed->_description(sanitizeHTML((string)$outline['description']));
|
||||
}
|
||||
return $feed;
|
||||
}
|
||||
|
||||
|
||||
/* permet de récupérer le contenu d'un article pour un flux qui n'est pas complet */
|
||||
function get_content_by_parsing ($url, $path) {
|
||||
require_once (LIB_PATH . '/lib_phpQuery.php');
|
||||
|
||||
Reference in New Issue
Block a user