1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-15 22:55:56 +00:00

add experimental support for simplepie (once again)

This commit is contained in:
Andrew Dolgov
2007-08-23 10:37:39 +01:00
parent 9ff29d0c74
commit 9fdf7824f6
4 changed files with 193 additions and 93 deletions

View File

@@ -65,7 +65,11 @@
$op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) { $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
header("Content-Type: application/xml; charset=utf-8"); header("Content-Type: application/xml; charset=utf-8");
} else { } else {
if (!$_REQUEST["noxml"]) {
header("Content-Type: text/html; charset=utf-8"); header("Content-Type: text/html; charset=utf-8");
} else {
header("Content-Type: text/plain; charset=utf-8");
}
} }
if (!$op) { if (!$op) {

View File

@@ -150,7 +150,18 @@
// Connection charset for MySQL. Only enable if having charset-related // Connection charset for MySQL. Only enable if having charset-related
// errors with MySQL (mangled characters, errors when updating feeds, etc). // errors with MySQL (mangled characters, errors when updating feeds, etc).
define('CONFIG_VERSION', 8); define('ENABLE_SIMPLEPIE', false);
// Enables SimplePie RSS parsing library (experimental)
// When this option is disabled, tt-rss defaults to MagpieRSS.
// SimplePie is more robust, but it doesn't currently
// support HTTP Digest authentication, so you won't be able
// to access, for example, Livejournal friend-only posts.
define('SIMPLEPIE_CACHE_DIR', '/var/tmp/simplepie-ttrss-cache');
// Cache directory for SimplePie
define('CONFIG_VERSION', 9);
// Expected config version. Please update this option in config.php // Expected config version. Please update this option in config.php
// if necessary (after migrating all new options from this file). // if necessary (after migrating all new options from this file).

View File

@@ -64,8 +64,12 @@
define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')'); define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
if (ENABLE_SIMPLEPIE) {
require_once "simplepie/simplepie.inc";
} else {
require_once "magpierss/rss_fetch.inc"; require_once "magpierss/rss_fetch.inc";
require_once 'magpierss/rss_utils.inc'; require_once 'magpierss/rss_utils.inc';
}
include_once "tw/tw-config.php"; include_once "tw/tw-config.php";
include_once "tw/tw.php"; include_once "tw/tw.php";
@@ -430,11 +434,23 @@
_debug("update_rss_feed: fetching..."); _debug("update_rss_feed: fetching...");
} }
if (!defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { if (!defined('DAEMON_EXTENDED_DEBUG') && !$_GET['xdebug']) {
error_reporting(0); error_reporting(0);
} }
if (!ENABLE_SIMPLEPIE) {
$rss = fetch_rss($fetch_url); $rss = fetch_rss($fetch_url);
} else {
if (!is_dir(SIMPLEPIE_CACHE_DIR)) {
mkdir(SIMPLEPIE_CACHE_DIR);
}
$rss = new SimplePie($fetch_url, SIMPLEPIE_CACHE_DIR);
$rss->init();
$rss->handle_content_type();
}
// print_r($rss);
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: fetch done, parsing..."); _debug("update_rss_feed: fetch done, parsing...");
@@ -461,11 +477,18 @@
$owner_uid = db_fetch_result($result, 0, "owner_uid"); $owner_uid = db_fetch_result($result, 0, "owner_uid");
if (ENABLE_SIMPLEPIE) {
$site_url = $rss->get_link();
} else {
$site_url = $rss->channel["link"];
}
if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) { if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) {
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: checking favicon..."); _debug("update_rss_feed: checking favicon...");
} }
check_feed_favicon($rss->channel["link"], $feed, $link);
check_feed_favicon($site_url, $feed, $link);
} }
if (!$registered_title || $registered_title == "[Unknown]") { if (!$registered_title || $registered_title == "[Unknown]") {
@@ -480,9 +503,10 @@
title = '$feed_title' WHERE id = '$feed'"); title = '$feed_title' WHERE id = '$feed'");
} }
$site_url = $rss->channel["link"];
// weird, weird Magpie // weird, weird Magpie
if (!ENABLE_SIMPLEPIE) {
if (!$site_url) $site_url = db_escape_string($rss->channel["link_"]); if (!$site_url) $site_url = db_escape_string($rss->channel["link_"]);
}
if ($site_url && $orig_site_url != db_escape_string($site_url)) { if ($site_url && $orig_site_url != db_escape_string($site_url)) {
db_query($link, "UPDATE ttrss_feeds SET db_query($link, "UPDATE ttrss_feeds SET
@@ -491,7 +515,11 @@
// print "I: " . $rss->channel["image"]["url"]; // print "I: " . $rss->channel["image"]["url"];
if (!ENABLE_SIMPLEPIE) {
$icon_url = $rss->image["url"]; $icon_url = $rss->image["url"];
} else {
$icon_url = $rss->get_image_url();
}
if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) { if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) {
$icon_url = db_escape_string($icon_url); $icon_url = db_escape_string($icon_url);
@@ -527,10 +555,13 @@
array_push($filters[$line["name"]], $filter); array_push($filters[$line["name"]], $filter);
} }
if (ENABLE_SIMPLEPIE) {
$iterator = $rss->get_items();
} else {
$iterator = $rss->items; $iterator = $rss->items;
if (!$iterator || !is_array($iterator)) $iterator = $rss->entries; if (!$iterator || !is_array($iterator)) $iterator = $rss->entries;
if (!$iterator || !is_array($iterator)) $iterator = $rss; if (!$iterator || !is_array($iterator)) $iterator = $rss;
}
if (!is_array($iterator)) { if (!is_array($iterator)) {
/* db_query($link, "UPDATE ttrss_feeds /* db_query($link, "UPDATE ttrss_feeds
@@ -556,13 +587,21 @@
foreach ($iterator as $item) { foreach ($iterator as $item) {
if (ENABLE_SIMPLEPIE) {
$entry_guid = $item->get_id();
if (!$entry_guid) $entry_guid = $item->get_link();
if (!$entry_guid) $entry_guid = make_guid_from_title($item->get_title());
} else {
$entry_guid = $item["id"]; $entry_guid = $item["id"];
if (!$entry_guid) $entry_guid = $item["guid"]; if (!$entry_guid) $entry_guid = $item["guid"];
if (!$entry_guid) $entry_guid = $item["link"]; if (!$entry_guid) $entry_guid = $item["link"];
if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]); if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]);
}
if (defined('DAEMON_EXTENDED_DEBUG')) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: guid $entry_guid"); _debug("update_rss_feed: guid $entry_guid");
} }
@@ -570,6 +609,9 @@
$entry_timestamp = ""; $entry_timestamp = "";
if (ENABLE_SIMPLEPIE) {
$entry_timestamp = strtotime($item->get_date());
} else {
$rss_2_date = $item['pubdate']; $rss_2_date = $item['pubdate'];
$rss_1_date = $item['dc']['date']; $rss_1_date = $item['dc']['date'];
$atom_date = $item['issued']; $atom_date = $item['issued'];
@@ -578,6 +620,7 @@
if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date); if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date);
if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date); if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date);
if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date); if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
}
if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) { if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) {
$entry_timestamp = time(); $entry_timestamp = time();
@@ -588,17 +631,27 @@
$entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
if (ENABLE_SIMPLEPIE) {
$entry_title = $item->get_title();
} else {
$entry_title = trim(strip_tags($item["title"])); $entry_title = trim(strip_tags($item["title"]));
}
if (ENABLE_SIMPLEPIE) {
$entry_link = $item->get_link();
} else {
// strange Magpie workaround // strange Magpie workaround
$entry_link = $item["link_"]; $entry_link = $item["link_"];
if (!$entry_link) $entry_link = $item["link"]; if (!$entry_link) $entry_link = $item["link"];
}
if (!$entry_title) continue; if (!$entry_title) continue;
# if (!$entry_link) continue;
$entry_link = strip_tags($entry_link); $entry_link = strip_tags($entry_link);
if (ENABLE_SIMPLEPIE) {
$entry_content = $item->get_description();
} else {
$entry_content = $item["content:escaped"]; $entry_content = $item["content:escaped"];
if (!$entry_content) $entry_content = $item["content:encoded"]; if (!$entry_content) $entry_content = $item["content:encoded"];
@@ -607,13 +660,12 @@
if (!$entry_content) $entry_content = $item["summary"]; if (!$entry_content) $entry_content = $item["summary"];
if (!$entry_content) $entry_content = $item["description"]; if (!$entry_content) $entry_content = $item["description"];
// if (!$entry_content) continue;
// WTF // WTF
if (is_array($entry_content)) { if (is_array($entry_content)) {
$entry_content = $entry_content["encoded"]; $entry_content = $entry_content["encoded"];
if (!$entry_content) $entry_content = $entry_content["escaped"]; if (!$entry_content) $entry_content = $entry_content["escaped"];
} }
}
// print_r($item); // print_r($item);
// print_r(htmlspecialchars($entry_content)); // print_r(htmlspecialchars($entry_content));
@@ -621,6 +673,10 @@
$entry_content_unescaped = $entry_content; $entry_content_unescaped = $entry_content;
if (ENABLE_SIMPLEPIE) {
$entry_comments = strip_tags($item->data["comments"]);
$entry_author = $item->get_author();
} else {
$entry_comments = strip_tags($item["comments"]); $entry_comments = strip_tags($item["comments"]);
$entry_author = db_escape_string(strip_tags($item['dc']['creator'])); $entry_author = db_escape_string(strip_tags($item['dc']['creator']));
@@ -642,6 +698,7 @@
$entry_author = db_escape_string(strip_tags($item['author'])); $entry_author = db_escape_string(strip_tags($item['author']));
} }
} }
}
if (preg_match('/^[\t\n\r ]*$/', $entry_author)) $entry_author = ''; if (preg_match('/^[\t\n\r ]*$/', $entry_author)) $entry_author = '';
@@ -659,12 +716,27 @@
$entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250); $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250);
$entry_author = mb_substr($entry_author, 0, 250); $entry_author = mb_substr($entry_author, 0, 250);
if (ENABLE_SIMPLEPIE) {
$num_comments = 0; #FIXME#
} else {
$num_comments = db_escape_string($item["slash"]["comments"]); $num_comments = db_escape_string($item["slash"]["comments"]);
}
if (!$num_comments) $num_comments = 0; if (!$num_comments) $num_comments = 0;
// parse <category> entries into tags // parse <category> entries into tags
if (ENABLE_SIMPLEPIE) {
$additional_tags = array();
$additional_tags_src = $item->get_categories();
foreach ($additional_tags_src as $tobj) {
array_push($additional_tags, $tobj->get_term());
}
} else {
$t_ctr = $item['category#']; $t_ctr = $item['category#'];
$additional_tags = false; $additional_tags = false;
@@ -696,12 +768,13 @@
} }
} }
} }
}
# sanitize content # sanitize content
// $entry_content = sanitize_rss($entry_content); // $entry_content = sanitize_rss($entry_content);
if (defined('DAEMON_EXTENDED_DEBUG')) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: done collecting data [TITLE:$entry_title]"); _debug("update_rss_feed: done collecting data [TITLE:$entry_title]");
} }
@@ -709,7 +782,7 @@
if (db_num_rows($result) == 0) { if (db_num_rows($result) == 0) {
if (defined('DAEMON_EXTENDED_DEBUG')) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: base guid not found"); _debug("update_rss_feed: base guid not found");
} }
@@ -765,7 +838,7 @@
if (db_num_rows($result) == 1) { if (db_num_rows($result) == 1) {
if (defined('DAEMON_EXTENDED_DEBUG')) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: base guid found, checking for user record"); _debug("update_rss_feed: base guid found, checking for user record");
} }
@@ -792,7 +865,7 @@
$article_filters = get_article_filters($filters, $entry_title, $article_filters = get_article_filters($filters, $entry_title,
$entry_content, $entry_link); $entry_content, $entry_link);
if (defined('DAEMON_EXTENDED_DEBUG')) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: article filters: "); _debug("update_rss_feed: article filters: ");
if (count($article_filters) != 0) { if (count($article_filters) != 0) {
print_r($article_filters); print_r($article_filters);
@@ -813,7 +886,7 @@
// okay it doesn't exist - create user entry // okay it doesn't exist - create user entry
if (db_num_rows($result) == 0) { if (db_num_rows($result) == 0) {
if (defined('DAEMON_EXTENDED_DEBUG')) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: user record not found, creating..."); _debug("update_rss_feed: user record not found, creating...");
} }
@@ -895,7 +968,7 @@
db_query($link, "COMMIT"); db_query($link, "COMMIT");
if (defined('DAEMON_EXTENDED_DEBUG')) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: looking for tags..."); _debug("update_rss_feed: looking for tags...");
} }
@@ -942,6 +1015,10 @@
// print "<p>TAGS: "; print_r($entry_tags); print "</p>"; // print "<p>TAGS: "; print_r($entry_tags); print "</p>";
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
print_r($entry_tags);
}
if (count($entry_tags) > 0) { if (count($entry_tags) > 0) {
db_query($link, "BEGIN"); db_query($link, "BEGIN");
@@ -980,6 +1057,10 @@
} }
db_query($link, "COMMIT"); db_query($link, "COMMIT");
} }
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: article processed");
}
} }
db_query($link, "UPDATE ttrss_feeds db_query($link, "UPDATE ttrss_feeds
@@ -987,14 +1068,18 @@
// db_query($link, "COMMIT"); // db_query($link, "COMMIT");
} else {
if (ENABLE_SIMPLEPIE) {
$error_msg = mb_substr(db_escape_string($rss->error()), 0, 250);
} else { } else {
$error_msg = mb_substr(db_escape_string(magpie_error()), 0, 250); $error_msg = mb_substr(db_escape_string(magpie_error()), 0, 250);
}
db_query($link, db_query($link,
"UPDATE ttrss_feeds SET last_error = '$error_msg', "UPDATE ttrss_feeds SET last_error = '$error_msg',
last_updated = NOW() WHERE id = '$feed'"); last_updated = NOW() WHERE id = '$feed'");
} }
if (defined('DAEMON_EXTENDED_DEBUG')) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: done"); _debug("update_rss_feed: done");
} }

View File

@@ -1,7 +1,7 @@
<?php <?php
require_once "functions.php"; require_once "functions.php";
define('EXPECTED_CONFIG_VERSION', 8); define('EXPECTED_CONFIG_VERSION', 9);
define('SCHEMA_VERSION', 21); define('SCHEMA_VERSION', 21);
if (!file_exists("config.php")) { if (!file_exists("config.php")) {