From: Andrew Dolgov Date: Fri, 25 Jan 2008 17:46:01 +0000 (+0100) Subject: allow per-feed update method selection X-Git-Tag: 1.2.20~54 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=16211ddbf24c978d88d8eb434ab57d7824827dbd;p=tt-rss.git allow per-feed update method selection --- diff --git a/backend.php b/backend.php index 8af861fd..c8271f4f 100644 --- a/backend.php +++ b/backend.php @@ -119,11 +119,17 @@ 1440 => __("Daily"), 10080 => __("Weekly")); - $update_method = array( + $update_methods = array( 0 => __("Use default"), 1 => __("Magpie"), 2 => __("SimplePie")); - + + if (ENABLE_SIMPLEPIE) { + $update_methods[0] .= ' (SimplePie)'; + } else { + $update_methods[0] .= ' (Magpie)'; + } + $access_level_names = array( 0 => __("User"), 10 => __("Administrator")); diff --git a/functions.php b/functions.php index 4e4e8ef0..6cc3b678 100644 --- a/functions.php +++ b/functions.php @@ -68,12 +68,9 @@ define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')'); 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_utils.inc'; - } + require_once "simplepie/simplepie.inc"; + require_once "magpierss/rss_fetch.inc"; + require_once 'magpierss/rss_utils.inc'; function _debug($msg) { $ts = strftime("%H:%M:%S", time()); @@ -478,13 +475,13 @@ } $result = db_query($link, "SELECT id,update_interval,auth_login, - auth_pass,cache_images + auth_pass,cache_images,update_method FROM ttrss_feeds WHERE id = '$feed' AND $updstart_thresh_qpart"); } else { $result = db_query($link, "SELECT id,update_interval,auth_login, - auth_pass,cache_images + auth_pass,cache_images,update_method FROM ttrss_feeds WHERE id = '$feed'"); } @@ -496,13 +493,25 @@ return; } + $update_method = db_fetch_result($result, 0, "update_method"); + db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW() WHERE id = '$feed'"); $auth_login = db_fetch_result($result, 0, "auth_login"); $auth_pass = db_fetch_result($result, 0, "auth_pass"); - if (!ENABLE_SIMPLEPIE) { + if (ENABLE_SIMPLEPIE) { + $use_simplepie = $update_method != 1; + } else { + $use_simplepie = $update_method == 2; + } + + if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + _debug("use simplepie: $use_simplepie (feed setting: $update_method)\n"); + } + + if (!$use_simplepie) { $auth_login = urlencode($auth_login); $auth_pass = urlencode($auth_pass); } @@ -534,7 +543,7 @@ error_reporting(0); } - if (!ENABLE_SIMPLEPIE) { + if (!$use_simplepie) { $rss = fetch_rss($fetch_url); } else { if (!is_dir(SIMPLEPIE_CACHE_DIR)) { @@ -543,7 +552,7 @@ $rss = new SimplePie(); $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT); - $rss->set_timeout(10); +# $rss->set_timeout(10); $rss->set_feed_url($fetch_url); $rss->set_output_encoding('UTF-8'); @@ -578,7 +587,7 @@ $feed = db_escape_string($feed); - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $fetch_ok = !$rss->error(); } else { $fetch_ok = !!$rss; @@ -601,7 +610,7 @@ $owner_uid = db_fetch_result($result, 0, "owner_uid"); - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $site_url = $rss->get_link(); } else { $site_url = $rss->channel["link"]; @@ -617,7 +626,7 @@ if (!$registered_title || $registered_title == "[Unknown]") { - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $feed_title = db_escape_string($rss->get_title()); } else { $feed_title = db_escape_string($rss->channel["title"]); @@ -632,7 +641,7 @@ } // weird, weird Magpie - if (!ENABLE_SIMPLEPIE) { + if (!$use_simplepie) { if (!$site_url) $site_url = db_escape_string($rss->channel["link_"]); } @@ -643,7 +652,7 @@ // print "I: " . $rss->channel["image"]["url"]; - if (!ENABLE_SIMPLEPIE) { + if (!$use_simplepie) { $icon_url = $rss->image["url"]; } else { $icon_url = $rss->get_image_url(); @@ -683,7 +692,7 @@ array_push($filters[$line["name"]], $filter); } - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $iterator = $rss->get_items(); } else { $iterator = $rss->items; @@ -720,7 +729,7 @@ } - if (ENABLE_SIMPLEPIE) { + if ($use_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()); @@ -742,7 +751,7 @@ $entry_timestamp = ""; - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $entry_timestamp = strtotime($item->get_date()); } else { $rss_2_date = $item['pubdate']; @@ -768,13 +777,13 @@ $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $entry_title = $item->get_title(); } else { $entry_title = trim(strip_tags($item["title"])); } - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $entry_link = $item->get_link(); } else { // strange Magpie workaround @@ -790,7 +799,7 @@ $entry_link = strip_tags($entry_link); - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $entry_content = $item->get_description(); } else { $entry_content = $item["content:escaped"]; @@ -819,7 +828,7 @@ $entry_content_unescaped = $entry_content; - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $entry_comments = strip_tags($item->data["comments"]); if ($item->get_author()) { $entry_author_item = $item->get_author(); @@ -866,7 +875,7 @@ $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250); $entry_author = mb_substr($entry_author, 0, 250); - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $num_comments = 0; #FIXME# } else { $num_comments = db_escape_string($item["slash"]["comments"]); @@ -876,7 +885,7 @@ // parse entries into tags - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $additional_tags = array(); $additional_tags_src = $item->get_categories(); @@ -937,7 +946,7 @@ $enclosures = array(); - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $encs = $item->get_enclosures(); if (is_array($encs)) { @@ -1308,7 +1317,7 @@ } else { - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { $error_msg = mb_substr($rss->error(), 0, 250); } else { $error_msg = mb_substr(magpie_error(), 0, 250); @@ -1325,7 +1334,7 @@ last_updated = NOW() WHERE id = '$feed'"); } - if (ENABLE_SIMPLEPIE) { + if ($use_simplepie) { unset($rss); } diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index c3197716..749f4dc0 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -4,6 +4,7 @@ global $update_intervals; global $purge_intervals; + global $update_methods; $subop = $_REQUEST["subop"]; $quiet = $_REQUEST["quiet"]; @@ -259,6 +260,17 @@ print ""; + $update_method = db_fetch_result($result, 0, "update_method"); + + print "".__('Update using:').""; + + print ""; + + print_select_hash("update_method", $update_method, $update_methods, + "class=\"iedit\""); + + print ""; + $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login")); print "".__('Login:').""; @@ -374,6 +386,7 @@ db_escape_string($_POST["include_in_digest"])); $cache_images = checkbox_to_sql_bool( db_escape_string($_POST["cache_images"])); + $update_method = (int) db_escape_string($_POST["update_method"]); if (get_pref($link, 'ENABLE_FEED_CATS')) { if ($cat_id && $cat_id != 0) { @@ -411,7 +424,8 @@ rtl_content = $rtl_content, hidden = $hidden, $cache_images_qpart - include_in_digest = $include_in_digest + include_in_digest = $include_in_digest, + update_method = '$update_method' WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); if (get_pref($link, 'ENABLE_FEED_CATS')) {