aboutsummaryrefslogtreecommitdiff
path: root/lib/lib_rss.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-01-04 01:47:07 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-01-04 01:47:07 +0100
commitd7c929e53b889460cd416d2864563e16200d2a01 (patch)
treeb91657455d48fa31aaa9b0bc6d8828db3622db1d /lib/lib_rss.php
parentcf8b3d080942ad682665569250038eda494d346b (diff)
parentc80ab2af7e0f6de4acf6dc02fab208d7b5baff45 (diff)
Merge remote-tracking branch 'origin/dev' into beta
Diffstat (limited to 'lib/lib_rss.php')
-rw-r--r--lib/lib_rss.php177
1 files changed, 29 insertions, 148 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index a1fadcb24..4f98ed14a 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -56,16 +56,6 @@ function checkUrl($url) {
}
}
-// vérifie qu'on est connecté
-function is_logged () {
- return Minz_Session::param ('mail') != false;
-}
-
-// vérifie que le système d'authentification est configuré
-function login_is_conf ($conf) {
- return $conf->mailLogin () != false;
-}
-
// tiré de Shaarli de Seb Sauvage //Format RFC 4648 base64url
function small_hash ($txt) {
$t = rtrim (base64_encode (hash ('crc32', $txt, true)), '=');
@@ -98,40 +88,20 @@ 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) {
- $htmlEntitiesOnly = array_flip(array_diff(
- get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'UTF-8'), //Decode HTML entities
- get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES, 'UTF-8') //Preserve XML entities
- ));
+ if (version_compare(PHP_VERSION, '5.3.4') >= 0) {
+ $htmlEntitiesOnly = array_flip(array_diff(
+ get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'UTF-8'), //Decode HTML entities
+ get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES, 'UTF-8') //Preserve XML entities
+ ));
+ } else {
+ $htmlEntitiesOnly = array_map('utf8_encode', array_flip(array_diff(
+ get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES), //Decode HTML entities
+ get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES) //Preserve XML entities
+ )));
+ }
}
return strtr($text, $htmlEntitiesOnly);
}
@@ -144,112 +114,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');
@@ -307,5 +171,22 @@ function uSecString() {
}
function invalidateHttpCache() {
- file_put_contents(DATA_PATH . '/touch.txt', uTimeString());
+ touch(LOG_PATH . '/' . Minz_Session::param('currentUser', '_') . '.log');
+ Minz_Session::_param('touch', uTimeString());
+}
+
+function usernameFromPath($userPath) {
+ if (preg_match('%/([a-z0-9]{1,16})_user\.php$%', $userPath, $matches)) {
+ return $matches[1];
+ } else {
+ return '';
+ }
+}
+
+function listUsers() {
+ return array_map('usernameFromPath', glob(DATA_PATH . '/*_user.php'));
+}
+
+function httpAuthUser() {
+ return isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : '';
}