X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=sidebyside;f=functions.php;h=161335c96536d128dc596235f7b96d9b3ca36428;hb=3809b27874608388ec145d76b6da28b1e7eadab1;hp=8d69cc0b96ab43fedde3a6dbe2822eb95850a1fb;hpb=32d2181b921907f42d6f30b06c6637f11dc7fe59;p=tt-rss.git diff --git a/functions.php b/functions.php index 8d69cc0b..161335c9 100644 --- a/functions.php +++ b/functions.php @@ -1,6 +1,6 @@ "Detect automatically", + "auto" => "Detect automatically", + "ca_CA" => "Català", "en_US" => "English", + "es_ES" => "Español", + "de_DE" => "Deutsch", "fr_FR" => "Français", "hu_HU" => "Magyar (Hungarian)", "it_IT" => "Italiano", @@ -37,7 +40,7 @@ } if (ENABLE_TRANSLATIONS == true) { // If translations are enabled. - require_once "accept-to-gettext.php"; + require_once "lib/accept-to-gettext.php"; require_once "lib/gettext/gettext.inc"; function startup_gettext() { @@ -105,6 +108,7 @@ require_once "lib/simplepie/simplepie.inc"; require_once "lib/magpierss/rss_fetch.inc"; require_once 'lib/magpierss/rss_utils.inc'; + require_once 'lib/htmlpurifier/library/HTMLPurifier.auto.php'; /** * Print a timestamped debug message. @@ -358,11 +362,17 @@ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); curl_setopt($ch, CURLOPT_TIMEOUT, 45); curl_exec($ch); - curl_close($ch); - fclose($fp); + + if (strpos(curl_getinfo($ch, CURLINFO_CONTENT_TYPE), "image/") !== false) { + curl_close($ch); + fclose($fp); + $contents = file_get_contents($tmpfile); + } else { + curl_close($ch); + fclose($fp); + } } - $contents = file_get_contents($tmpfile); unlink($tmpfile); return $contents; @@ -495,11 +505,11 @@ function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) { - if (!$_GET["daemon"] && !$ignore_daemon) { + if (!$_REQUEST["daemon"] && !$ignore_daemon) { return false; } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: start"); } @@ -518,19 +528,18 @@ } else { $result = db_query($link, "SELECT id,update_interval,auth_login, - auth_pass,cache_images,update_method,hidden,last_updated + auth_pass,cache_images,update_method,last_updated FROM ttrss_feeds WHERE id = '$feed'"); } if (db_num_rows($result) == 0) { - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: feed $feed [$feed_url] NOT FOUND/SKIPPED"); } return false; } - $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden")); $update_method = db_fetch_result($result, 0, "update_method"); $last_updated = db_fetch_result($result, 0, "last_updated"); @@ -550,7 +559,7 @@ $use_simplepie = ENABLE_SIMPLEPIE; } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("use simplepie: $use_simplepie (feed setting: $update_method)\n"); } @@ -578,11 +587,11 @@ } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: fetching [$fetch_url]..."); } - if (!defined('DAEMON_EXTENDED_DEBUG') && !$_GET['xdebug']) { + if (!defined('DAEMON_EXTENDED_DEBUG') && !$_REQUEST['xdebug']) { error_reporting(0); } @@ -600,14 +609,14 @@ $rss->set_output_encoding('UTF-8'); if (SIMPLEPIE_CACHE_IMAGES && $cache_images) { - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("enabling image cache"); } $rss->set_image_handler('./image.php', 'i'); } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("feed update interval (sec): " . get_feed_update_interval($link, $feed)*60); } @@ -622,7 +631,7 @@ // print_r($rss); - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: fetch done, parsing..."); } else { error_reporting (DEFAULT_ERROR_LEVEL); @@ -638,7 +647,7 @@ if ($fetch_ok) { - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: processing feed data..."); } @@ -660,7 +669,7 @@ } if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) { - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: checking favicon..."); } @@ -675,7 +684,7 @@ $feed_title = db_escape_string($rss->channel["title"]); } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: registering title: $feed_title"); } @@ -706,7 +715,7 @@ db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'"); } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: loading filters..."); } @@ -728,7 +737,7 @@ // clear any errors and mark feed as updated if fetched okay // even if it's blank - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: entry iterator is not an array, no articles?"); } @@ -738,15 +747,14 @@ return; // no articles } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: processing articles..."); } foreach ($iterator as $item) { - if ($_GET['xdebug']) { + if ($_REQUEST['xdebug'] == 2) { print_r($item); - } if ($use_simplepie) { @@ -763,7 +771,7 @@ if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]); } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: guid $entry_guid"); } @@ -793,7 +801,7 @@ $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: date $entry_timestamp [$entry_timestamp_fmt]"); } @@ -811,7 +819,7 @@ if (!$entry_link) $entry_link = $item["link"]; } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: title $entry_title"); } @@ -847,7 +855,7 @@ } } - if ($_GET["xdebug"]) { + if ($_REQUEST["xdebug"] == 2) { print "update_rss_feed: content: "; print_r(htmlspecialchars($entry_content)); } @@ -925,7 +933,7 @@ } } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: category tags:"); print_r($additional_tags); } @@ -1040,7 +1048,7 @@ $entry_content = sanitize_article_content($entry_content); $entry_title = sanitize_article_content($entry_title); - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: done collecting data [TITLE:$entry_title]"); } @@ -1048,7 +1056,7 @@ if (db_num_rows($result) == 0) { - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: base guid not found"); } @@ -1107,7 +1115,7 @@ if (db_num_rows($result) == 1) { - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: base guid found, checking for user record"); } @@ -1125,7 +1133,7 @@ // do we allow duplicate posts with same GUID in different feeds? if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) { - $dupcheck_qpart = "AND feed_id = '$feed'"; + $dupcheck_qpart = "AND (feed_id = '$feed' OR feed_id IS NULL)"; } else { $dupcheck_qpart = ""; } @@ -1135,7 +1143,7 @@ $article_filters = get_article_filters($filters, $entry_title, $entry_content, $entry_link, $entry_timestamp); - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: article filters: "); if (count($article_filters) != 0) { print_r($article_filters); @@ -1151,19 +1159,22 @@ $score = calculate_article_score($article_filters); - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: initial score: $score"); } - $result = db_query($link, - "SELECT ref_id, int_id FROM ttrss_user_entries WHERE + $query = "SELECT ref_id, int_id FROM ttrss_user_entries WHERE ref_id = '$ref_id' AND owner_uid = '$owner_uid' - $dupcheck_qpart"); + $dupcheck_qpart"; + +// if ($_REQUEST["xdebug"]) print "$query\n"; + + $result = db_query($link, $query); // okay it doesn't exist - create user entry if (db_num_rows($result) == 0) { - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: user record not found, creating..."); } @@ -1203,11 +1214,15 @@ $entry_int_id = db_fetch_result($result, 0, "int_id"); } } else { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { + _debug("update_rss_feed: user record FOUND"); + } + $entry_ref_id = db_fetch_result($result, 0, "ref_id"); $entry_int_id = db_fetch_result($result, 0, "int_id"); } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: RID: $entry_ref_id, IID: $entry_int_id"); } @@ -1262,18 +1277,18 @@ db_query($link, "COMMIT"); - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: assigning labels..."); } assign_article_to_labels($link, $entry_ref_id, $article_filters, $owner_uid); - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: looking for enclosures..."); } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { print_r($enclosures); } @@ -1296,7 +1311,7 @@ db_query($link, "COMMIT"); - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: looking for tags..."); } @@ -1343,7 +1358,7 @@ // print "

TAGS: "; print_r($entry_tags); print "

"; - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { print_r($entry_tags); } @@ -1375,27 +1390,18 @@ db_query($link, "COMMIT"); } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: article processed"); } } if (!$last_updated) { - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: new feed, catching it up..."); } catchup_feed($link, $feed, false, $owner_uid); } - if (!$hidden) { - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { - _debug("update_rss_feed: updating counters cache..."); - } - - // disabled, purge_feed() does that... - //ccache_update($link, $feed, $owner_uid); - } - purge_feed($link, $feed, 0); db_query($link, "UPDATE ttrss_feeds @@ -1411,7 +1417,7 @@ $error_msg = mb_substr(magpie_error(), 0, 250); } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: error fetching feed: $error_msg"); } @@ -1426,7 +1432,7 @@ unset($rss); } - if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: done"); } @@ -1579,6 +1585,17 @@ $rtl_content = false, $last_updated = false, $last_error = false, $fg_content = false, $bg_content = false) { + if (!$feed_title) $feed_title = getFeedTitle($link, $feed_id, false); + if (!$unread) $unread = getFeedUnread($link, $feed_id); + + if ($unread > 0) $class .= "Unread"; + + if (!$icon_file) $icon_file = getFeedIcon($feed_id); + + if (strpos($icon_file, "images") !== false) { + $icon_file = theme_image($link, $icon_file); + } + if (file_exists($icon_file) && filesize($icon_file) > 0) { $feed_icon = ""; } else { @@ -1666,16 +1683,25 @@ } } - function initialize_user_prefs($link, $uid) { + function initialize_user_prefs($link, $uid, $profile = false) { $uid = db_escape_string($uid); + if (!$profile) { + $profile = "NULL"; + $profile_qpart = "AND profile IS NULL"; + } else { + $profile_qpart = "AND profile = '$profile'"; + } + + if (get_schema_version($link) < 63) $profile_qpart = ""; + db_query($link, "BEGIN"); $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs"); $u_result = db_query($link, "SELECT pref_name - FROM ttrss_user_prefs WHERE owner_uid = '$uid'"); + FROM ttrss_user_prefs WHERE owner_uid = '$uid' $profile_qpart"); $active_prefs = array(); @@ -1687,9 +1713,16 @@ if (array_search($line["pref_name"], $active_prefs) === FALSE) { // print "adding " . $line["pref_name"] . "
"; - db_query($link, "INSERT INTO ttrss_user_prefs - (owner_uid,pref_name,value) VALUES - ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')"); + if (get_schema_version($link) < 63) { + db_query($link, "INSERT INTO ttrss_user_prefs + (owner_uid,pref_name,value) VALUES + ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')"); + + } else { + db_query($link, "INSERT INTO ttrss_user_prefs + (owner_uid,pref_name,value, profile) VALUES + ('$uid', '".$line["pref_name"]."','".$line["def_value"]."', $profile)"); + } } } @@ -1712,7 +1745,7 @@ function http_authenticate_user($link) { - error_log("http_authenticate_user: ".$_SERVER["PHP_AUTH_USER"]."\n", 3, '/tmp/tt-rss.log'); +// error_log("http_authenticate_user: ".$_SERVER["PHP_AUTH_USER"]."\n", 3, '/tmp/tt-rss.log'); if (!$_SERVER["PHP_AUTH_USER"]) { @@ -1740,6 +1773,7 @@ $pwd_hash1 = encrypt_password($password); $pwd_hash2 = encrypt_password($password, $login); + $login = db_escape_string($login); if (defined('ALLOW_REMOTE_USER_AUTH') && ALLOW_REMOTE_USER_AUTH && $_SERVER["REMOTE_USER"] && $login != "admin") { @@ -1767,9 +1801,6 @@ db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . $_SESSION["uid"]); - $user_theme = get_user_theme_path($link); - - $_SESSION["theme"] = $user_theme; $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; $_SESSION["pwd_hash"] = db_fetch_result($result, 0, "pwd_hash"); @@ -1785,9 +1816,6 @@ $_SESSION["uid"] = 1; $_SESSION["name"] = "admin"; - $user_theme = get_user_theme_path($link); - - $_SESSION["theme"] = $user_theme; $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; initialize_user_prefs($link, $_SESSION["uid"]); @@ -1857,12 +1885,16 @@ if (SESSION_CHECK_ADDRESS && $_SESSION["uid"]) { if ($_SESSION["ip_address"]) { if ($_SESSION["ip_address"] != $_SERVER["REMOTE_ADDR"]) { - $_SESSION["login_error_msg"] = "Session failed to validate (incorrect IP)"; + $_SESSION["login_error_msg"] = __("Session failed to validate (incorrect IP)"); return false; } } } + if ($_SESSION["ref_schema_version"] != get_schema_version($link, true)) { + return false; + } + if ($_SESSION["uid"]) { $result = db_query($link, @@ -1890,14 +1922,6 @@ function login_sequence($link, $mobile = false) { if (!SINGLE_USER_MODE) { - if (defined('_DEBUG_USER_SWITCH') && $_SESSION["uid"]) { - $swu = db_escape_string($_REQUEST["swu"]); - if ($swu) { - $_SESSION["prefs_cache"] = false; - return authenticate_user($link, $swu, null, true); - } - } - $login_action = $_POST["login_action"]; # try to authenticate user if called from login form @@ -1910,14 +1934,28 @@ $_POST["password"] = ""; $_SESSION["language"] = $_POST["language"]; + $_SESSION["ref_schema_version"] = get_schema_version($link, true); $_SESSION["bw_limit"] = !!$_POST["bw_limit"]; + if ($_POST["profile"]) { + + $profile = db_escape_string($_POST["profile"]); + + $result = db_query($link, "SELECT id FROM ttrss_settings_profiles + WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + $_SESSION["profile"] = $profile; + $_SESSION["prefs_cache"] = array(); + } + } + header("Location: " . $_SERVER["REQUEST_URI"]); exit; return; } else { - $_SESSION["login_error_msg"] = "Incorrect username or password"; + $_SESSION["login_error_msg"] = __("Incorrect username or password"); } } @@ -1953,16 +1991,91 @@ } } + function theme_image($link, $filename) { + if ($link) { + $theme_path = get_user_theme_path($link); + + if ($theme_path && is_file($theme_path.$filename)) { + return $theme_path.$filename; + } else { + return $filename; + } + } else { + return $filename; + } + } + + function get_user_theme($link) { + + if (get_schema_version($link) >= 63) { + $theme_name = get_pref($link, "_THEME_ID"); + if (is_dir("themes/$theme_name")) { + return $theme_name; + } else { + return ''; + } + } else { + return ''; + } + + } + function get_user_theme_path($link) { - $result = db_query($link, "SELECT theme_path - FROM - ttrss_themes,ttrss_users - WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]); - if (db_num_rows($result) != 0) { - return db_fetch_result($result, 0, "theme_path"); + + if (get_schema_version($link) >= 63) { + $theme_name = get_pref($link, "_THEME_ID"); + + if ($theme_name && is_dir("themes/$theme_name")) { + $theme_path = "themes/$theme_name/"; + } else { + $theme_name = ''; + } } else { - return null; + $theme_path = ''; } + + return $theme_path; + } + + function get_user_theme_options($link) { + $t = get_user_theme_path($link); + + if ($t) { + if (is_file("$t/theme.ini")) { + $ini = parse_ini_file("$t/theme.ini", true); + if ($ini['theme']['version']) { + return $ini['theme']['options']; + } + } + } + return false; + } + + + function get_all_themes() { + $themes = glob("themes/*"); + + asort($themes); + + $rv = array(); + + foreach ($themes as $t) { + if (is_file("$t/theme.ini")) { + $ini = parse_ini_file("$t/theme.ini", true); + if ($ini['theme']['version'] && !$ini['theme']['disabled']) { + $entry = array(); + $entry["path"] = $t; + $entry["base"] = basename($t); + $entry["name"] = $ini['theme']['name']; + $entry["version"] = $ini['theme']['version']; + $entry["author"] = $ini['theme']['author']; + $entry["options"] = $ini['theme']['options']; + array_push($rv, $entry); + } + } + } + + return $rv; } function smart_date_time($timestamp) { @@ -2016,13 +2129,23 @@ return "even"; } + function get_schema_version($link, $nocache = false) { + if (!$_SESSION["schema_version"] || $nocache) { + $result = db_query($link, "SELECT schema_version FROM ttrss_version"); + $version = db_fetch_result($result, 0, "schema_version"); + $_SESSION["schema_version"] = $version; + return $version; + } else { + return $_SESSION["schema_version"]; + } + } + function sanity_check($link) { error_reporting(0); $error_code = 0; - $result = db_query($link, "SELECT schema_version FROM ttrss_version"); - $schema_version = db_fetch_result($result, 0, "schema_version"); + $schema_version = get_schema_version($link); if ($schema_version != SCHEMA_VERSION) { $error_code = 5; @@ -2125,7 +2248,7 @@ if (!$owner_uid) $owner_uid = $_SESSION['uid']; if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { - + if ($cat_view) { if ($feed >= 0) { @@ -2289,9 +2412,10 @@ if (!$omode) $omode = "flc"; getGlobalCounters($link); - + getVirtCounters($link); + if (strchr($omode, "l")) getLabelCounters($link); - if (strchr($omode, "f")) getFeedCounters($link, SMART_RPC_COUNTERS, $active_feed); + if (strchr($omode, "f")) getFeedCounters($link, $active_feed); if (strchr($omode, "t")) getTagCounters($link); if (strchr($omode, "c")) { if (get_pref($link, 'ENABLE_FEED_CATS')) { @@ -2319,7 +2443,7 @@ ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]); while ($line = db_fetch_assoc($result)) { - $line["cat_id"] = sprintf("%d", $line["cat_id"]); + $line["cat_id"] = (int) $line["cat_id"]; print ""; @@ -2347,7 +2471,6 @@ $age_qpart = getMaxAgeSubquery(); $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query - AND hidden = false AND owner_uid = " . $owner_uid); $cat_feeds = array(); @@ -2373,7 +2496,7 @@ return $unread; } else if ($cat == -1) { - return getFeedUnread($link, -1) + getFeedUnread($link, -2) + getFeedUnread($link, -3); + return getFeedUnread($link, -1) + getFeedUnread($link, -2) + getFeedUnread($link, -3) + getFeedUnread($link, 0); } else if ($cat == -2) { $result = db_query($link, " @@ -2381,7 +2504,7 @@ ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND ttrss_labels2.owner_uid = '$owner_uid' - AND unread = true AND hidden = false AND feed_id = ttrss_feeds.id + AND unread = true AND feed_id = ttrss_feeds.id AND ttrss_user_entries.owner_uid = '$owner_uid'"); $unread = db_fetch_result($result, 0, "unread"); @@ -2413,7 +2536,7 @@ ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND ttrss_labels2.owner_uid = '$owner_uid' AND ttrss_labels2.id = '$label_id' - AND unread = true AND hidden = false AND feed_id = ttrss_feeds.id + AND unread = true AND feed_id = ttrss_feeds.id AND ttrss_user_entries.owner_uid = '$owner_uid'"); if (db_num_rows($result) != 0) { @@ -2426,7 +2549,7 @@ function getFeedArticles($link, $feed, $is_cat = false, $unread_only = false, $owner_uid = false) { - $n_feed = sprintf("%d", $feed); + $n_feed = (int) $feed; if (!$owner_uid) $owner_uid = $_SESSION["uid"]; @@ -2440,6 +2563,15 @@ if ($is_cat) { return getCategoryUnread($link, $n_feed, $owner_uid); + } if ($feed != "0" && $n_feed == 0) { + + $result = db_query($link, "SELECT SUM((SELECT COUNT(int_id) + FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id + AND ref_id = id AND $age_qpart + AND $unread_qpart)) AS count FROM ttrss_tags + WHERE owner_uid = $owner_uid AND tag_name = '$feed'"); + return db_fetch_result($result, 0, "count"); + } else if ($n_feed == -1) { $match_part = "marked = true"; } else if ($n_feed == -2) { @@ -2456,11 +2588,10 @@ } } else if ($n_feed == -4) { $match_part = "true"; - } else if ($n_feed > 0) { + } else if ($n_feed >= 0) { $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE parent_feed = '$n_feed' - AND hidden = false AND owner_uid = " . $owner_uid); if (db_num_rows($result) > 0) { @@ -2474,7 +2605,7 @@ $match_part = implode(" OR ", $linked_feeds); - $result = db_query($link, "SELECT COUNT(int_id) AS unread + $tmp_result = db_query($link, "SELECT COUNT(int_id) AS unread FROM ttrss_user_entries,ttrss_entries WHERE $unread_qpart AND ttrss_user_entries.ref_id = ttrss_entries.id AND @@ -2485,14 +2616,18 @@ $unread = 0; # this needs to be rewritten - while ($line = db_fetch_assoc($result)) { + while ($line = db_fetch_assoc($tmp_result)) { $unread += $line["unread"]; } return $unread; } else { - $match_part = "feed_id = '$n_feed'"; + if ($n_feed != 0) { + $match_part = "feed_id = '$n_feed'"; + } else { + $match_part = "feed_id IS NULL"; + } } } else if ($feed < -10) { @@ -2503,14 +2638,22 @@ } if ($match_part) { - - $result = db_query($link, "SELECT count(int_id) AS unread - FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE - ttrss_user_entries.feed_id = ttrss_feeds.id AND + + if ($n_feed != 0) { + $from_qpart = "ttrss_user_entries,ttrss_feeds,ttrss_entries"; + $feeds_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND"; + } else { + $from_qpart = "ttrss_user_entries,ttrss_entries"; + } + + $query = "SELECT count(int_id) AS unread + FROM $from_qpart WHERE ttrss_user_entries.ref_id = ttrss_entries.id AND - ttrss_feeds.hidden = false AND $age_qpart AND - $unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = " . $owner_uid); + $feeds_qpart + $unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = $owner_uid"; + + $result = db_query($link, $query); } else { @@ -2557,17 +2700,14 @@ } - function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) { - - if ($smart_mode) { - if (!$_SESSION["tctr_last_value"]) { - $_SESSION["tctr_last_value"] = array(); - } - } + function getSubscribedFeeds($link) { + $result = db_query($link, "SELECT COUNT(id) AS fn FROM + ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); - $old_counters = $_SESSION["tctr_last_value"]; + return db_fetch_result($result, 0, "fn"); + } - $tctrs_modified = false; + function getTagCounters($link) { $age_qpart = getMaxAgeSubquery(); @@ -2586,36 +2726,16 @@ foreach (array_keys($tags) as $tag) { $unread = $tags[$tag]; - $tag = htmlspecialchars($tag); - - if (!$smart_mode || $old_counters[$tag] != $unread) { - $old_counters[$tag] = $unread; - $tctrs_modified = true; - print ""; - } - + print ""; } - - if ($smart_mode && $tctrs_modified) { - $_SESSION["tctr_last_value"] = $old_counters; - } - } - function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) { - - $age_qpart = getMaxAgeSubquery(); - - if ($smart_mode) { - if (!$_SESSION["lctr_last_value"]) { - $_SESSION["lctr_last_value"] = array(); - } - } + function getVirtCounters($link, $ret_mode = false) { $ret_arr = array(); - for ($i = -1; $i >= -4; $i--) { + for ($i = 0; $i >= -4; $i--) { $count = getFeedUnread($link, $i); @@ -2632,65 +2752,50 @@ $ret_arr[$i]["counter"] = $count; $ret_arr[$i]["description"] = getFeedTitle($link, $i); } - - } + } - $old_counters = $_SESSION["lctr_last_value"]; - $lctrs_modified = false; + return $ret_arr; + } + function getLabelCounters($link, $ret_mode = false) { - $owner_uid = $_SESSION["uid"]; + $age_qpart = getMaxAgeSubquery(); - $result = db_query($link, "SELECT id, caption FROM ttrss_labels2 - WHERE owner_uid = '$owner_uid'"); - - while ($line = db_fetch_assoc($result)) { - - $id = -$line["id"] - 11; - - $label_name = $line["caption"]; - $count = getFeedUnread($link, $id); - - if (!$smart_mode || $old_counters[$id] != $count) { - $old_counters[$id] = $count; - $lctrs_modified = true; - if (!$ret_mode) { + $owner_uid = $_SESSION["uid"]; + + $result = db_query($link, "SELECT id, caption FROM ttrss_labels2 + WHERE owner_uid = '$owner_uid'"); - if (get_pref($link, 'EXTENDED_FEEDLIST')) { - $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; - } else { - $xmsg_part = ""; - } + while ($line = db_fetch_assoc($result)) { + + $id = -$line["id"] - 11; + + $label_name = $line["caption"]; + $count = getFeedUnread($link, $id); - print ""; - } else { - $ret_arr[$id]["counter"] = $count; - $ret_arr[$id]["description"] = $label_name; - } + if (!$ret_mode) { + + if (get_pref($link, 'EXTENDED_FEEDLIST')) { + $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; + } else { + $xmsg_part = ""; } - - error_reporting (DEFAULT_ERROR_LEVEL); - } - if ($smart_mode && $lctrs_modified) { - $_SESSION["lctr_last_value"] = $old_counters; - } + print ""; + } else { + $ret_arr[$id]["counter"] = $count; + $ret_arr[$id]["description"] = $label_name; + } + } + return $ret_arr; } - function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS, $active_feed = false) { + function getFeedCounters($link, $active_feed = false) { $age_qpart = getMaxAgeSubquery(); - if ($smart_mode) { - if (!$_SESSION["fctr_last_value"]) { - $_SESSION["fctr_last_value"] = array(); - } - } - - $old_counters = $_SESSION["fctr_last_value"]; - $query = "SELECT ttrss_feeds.id, ttrss_feeds.title, ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, @@ -2727,38 +2832,29 @@ $count += db_fetch_result($tmp_result, 0, "unread"); - if (!$smart_mode || $old_counters[$id] != $count) { - $old_counters[$id] = $count; - $fctrs_modified = true; - - if ($last_error) { - $error_part = "error=\"$last_error\""; - } else { - $error_part = ""; - } - - if ($has_img) { - $has_img_part = "hi=\"$has_img\""; - } else { - $has_img_part = ""; - } + if ($last_error) { + $error_part = "error=\"$last_error\""; + } else { + $error_part = ""; + } - if ($active_feed && $id == $active_feed) { - $has_title_part = "title=\"" . htmlspecialchars($line["title"]) . "\""; - } else { - $has_title_part = ""; - } + if ($has_img) { + $has_img_part = "hi=\"$has_img\""; + } else { + $has_img_part = ""; + } - if (get_pref($link, 'EXTENDED_FEEDLIST')) { - $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; - } + if ($active_feed && $id == $active_feed) { + $has_title_part = "title=\"" . htmlspecialchars($line["title"]) . "\""; + } else { + $has_title_part = ""; + } - print ""; + if (get_pref($link, 'EXTENDED_FEEDLIST')) { + $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; } - } - if ($smart_mode && $fctrs_modified) { - $_SESSION["fctr_last_value"] = $old_counters; + print ""; } } @@ -2791,18 +2887,16 @@ print ""; } - function subscribe_to_feed($link, $feed_link, $cat_id = 0, + function subscribe_to_feed($link, $url, $cat_id = 0, $auth_login = '', $auth_pass = '') { - # check for feed:http://url - $feed_link = trim(preg_replace("/^feed:/", "", $feed_link)); + $parts = parse_url($url); - # check for feed://URL - if (strpos($feed_link, "//") === 0) { - $feed_link = "http:$feed_link"; - } + if (!validate_feed_url($url)) return 2; - if ($feed_link == "") return; + if ($parts['scheme'] == 'feed') $parts['scheme'] = 'http'; + + $url = make_url_from_parts($parts); if ($cat_id == "0" || !$cat_id) { $cat_qpart = "NULL"; @@ -2812,29 +2906,29 @@ $result = db_query($link, "SELECT id FROM ttrss_feeds - WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); + WHERE feed_url = '$url' AND owner_uid = ".$_SESSION["uid"]); if (db_num_rows($result) == 0) { $result = db_query($link, "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id, auth_login,auth_pass) - VALUES ('".$_SESSION["uid"]."', '$feed_link', + VALUES ('".$_SESSION["uid"]."', '$url', '[Unknown]', $cat_qpart, '$auth_login', '$auth_pass')"); $result = db_query($link, - "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' + "SELECT id FROM ttrss_feeds WHERE feed_url = '$url' AND owner_uid = " . $_SESSION["uid"]); $feed_id = db_fetch_result($result, 0, "id"); if ($feed_id) { - update_rss_feed($link, $feed_link, $feed_id, true); + update_rss_feed($link, $url, $feed_id, true); } - return true; + return 1; } else { - return false; + return 0; } } @@ -2859,8 +2953,11 @@ } else { $is_selected = ""; } + + $title = truncate_string(htmlspecialchars($line["title"]), 40); + printf("", - $line["id"], htmlspecialchars($line["title"])); + $line["id"], $title); } print ""; @@ -2919,6 +3016,33 @@ } + function getFeedIcon($id) { + switch ($id) { + case 0: + return "images/archive.png"; + break; + case -1: + return "images/mark_set.png"; + break; + case -2: + return "images/pub_set.png"; + break; + case -3: + return "images/fresh.png"; + break; + case -4: + return "images/tag.png"; + break; + default: + if ($id < -10) { + return "images/label.png"; + } else { + return ICONS_URL . "/$id.ico"; + } + break; + } + } + function getFeedTitle($link, $id) { if ($id == -1) { return __("Starred articles"); @@ -2928,6 +3052,8 @@ return __("Fresh articles"); } else if ($id == -4) { return __("All articles"); + } else if ($id === 0 || $id === "0") { + return __("Archived articles"); } else if ($id < -10) { $label_id = -$id - 11; $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE id = '$label_id'"); @@ -2945,9 +3071,8 @@ return "Unknown feed ($id)"; } } else { - return "getFeedTitle($id) failed"; + return $id; } - } function get_session_cookie_name() { @@ -2965,11 +3090,24 @@ } } - print ""; + print ""; + print ""; print ""; print ""; print ""; + print ""; + + print ""; + + print ""; + + print ""; + print ""; @@ -3035,6 +3173,9 @@ print ""; + print ""; + print ""; } @@ -3051,7 +3192,7 @@ if (ENABLE_UPDATE_DAEMON) { print ""; + (int) file_is_locked("update_daemon.lock") . "\"/>"; if (time() - $_SESSION["daemon_stamp_check"] > 30) { @@ -3179,11 +3320,12 @@ if ($search && $search_mode == "all_feeds") { $query_strategy_part = "ttrss_entries.id > 0"; $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; + /* tags */ } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) { $query_strategy_part = "ttrss_entries.id > 0"; $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title,"; - } else if ($feed >= 0 && $search && $search_mode == "this_cat") { + } else if ($feed > 0 && $search && $search_mode == "this_cat") { $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; @@ -3212,7 +3354,7 @@ $query_strategy_part = "ttrss_entries.id > 0"; } - } else if ($feed >= 0) { + } else if ($feed > 0) { if ($cat_view) { @@ -3244,6 +3386,8 @@ $query_strategy_part = "feed_id = '$feed'"; } } + } else if ($feed == 0) { // starred virtual feed + $query_strategy_part = "feed_id IS NULL"; } else if ($feed == -1) { // starred virtual feed $query_strategy_part = "marked = true"; $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; @@ -3307,69 +3451,23 @@ $feed_title = ""; - if ($search && $search_mode == "all_feeds") { - $feed_title = __("Search results")." ($search)"; - } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { - $feed_title = __("Search results")." ($search, $feed)"; - } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { - $feed_title = $feed; - } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) { - + if ($search) { + $feed_title = "Search results"; + } else { if ($cat_view) { - - if ($feed != 0) { - $result = db_query($link, "SELECT title FROM ttrss_feed_categories - WHERE id = '$feed' AND owner_uid = $owner_uid"); - $feed_title = db_fetch_result($result, 0, "title"); - } else { - $feed_title = __("Uncategorized"); - } - - if ($search) { - $feed_title = __("Searched for")." $search ($feed_title)"; - } - + $feed_title = getCategoryTitle($link, $feed); } else { - - $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds - WHERE id = '$feed' AND owner_uid = $owner_uid"); + if ((int)$feed == $feed && $feed > 0) { + $result = db_query($link, "SELECT title,site_url,last_error + FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = $owner_uid"); - $feed_title = db_fetch_result($result, 0, "title"); - $feed_site_url = db_fetch_result($result, 0, "site_url"); - $last_error = db_fetch_result($result, 0, "last_error"); - - if ($search) { - $feed_title = __("Searched for") . " $search ($feed_title)"; - } - } - - } else if ($feed == -1) { - $feed_title = __("Starred articles"); - if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } - } else if ($feed == -2) { - if (!$cat_view) { - $feed_title = __("Published articles"); - if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } - } else { - $feed_title = __("Labels"); - } - } else if ($feed == -3) { - $feed_title = __("Fresh articles"); - if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } - } else if ($feed == -4) { - $feed_title = __("All articles"); - if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } - } else if ($feed < -10) { - $label_id = -$feed - 11; - $result = db_query($link, "SELECT caption FROM ttrss_labels2 - WHERE id = '$label_id'"); - $feed_title = db_fetch_result($result, 0, "caption"); - - if ($search) { - $feed_title = __("Searched for") . " $search ($feed_title)"; + $feed_title = db_fetch_result($result, 0, "title"); + $feed_site_url = db_fetch_result($result, 0, "site_url"); + $last_error = db_fetch_result($result, 0, "last_error"); + } else { + $feed_title = getFeedTitle($link, $feed); + } } - } else { - $feed_title = "?"; } $content_query_part = "content as content_preview,"; @@ -3390,16 +3488,15 @@ if (!$override_order) { $order_by = "ttrss_feeds.title, $order_by"; } + } - // Special output for Fresh feed + if ($feed != "0") { + $from_qpart = "ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part"; + $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND"; -/* if ($feed == -3) { - $group_limit_part = "(select count(*) from - ttrss_user_entries AS t1, ttrss_entries AS t2 where - t1.ref_id = t2.id and t1.owner_uid = 2 and - t1.feed_id = ttrss_user_entries.feed_id and - t2.updated > ttrss_entries.updated) <= 5 AND"; -} */ + } else { + $from_qpart = "ttrss_entries,ttrss_user_entries$ext_tables_part + LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)"; } $query = "SELECT DISTINCT @@ -3407,18 +3504,17 @@ ttrss_entries.id,ttrss_entries.title, updated, note, - unread,feed_id,marked,published,link,last_read, + unread,feed_id,marked,published,link,last_read,orig_feed_id, ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms, $vfeed_query_part $content_query_part ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms, author,score FROM - ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part + $from_qpart WHERE $group_limit_part - ttrss_feeds.hidden = false AND - ttrss_user_entries.feed_id = ttrss_feeds.id AND + $feed_check_qpart ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.owner_uid = '$owner_uid' AND $search_query_part @@ -3426,7 +3522,7 @@ $query_strategy_part ORDER BY $order_by $limit_query_part $offset_query_part"; - if ($_GET["debug"]) print $query; + if ($_REQUEST["debug"]) print $query; $result = db_query($link, $query); @@ -3440,7 +3536,7 @@ note, ttrss_entries.id as id,title, updated, - unread,feed_id, + unread,feed_id,orig_feed_id, marked,link,last_read, ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms, $vfeed_query_part @@ -3460,15 +3556,15 @@ } return array($result, $feed_title, $feed_site_url, $last_error); - + } function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat, $limit, $search, $search_mode, $match_on) { - $note_style = "background-color : #fff7d5; border-width : 1px; ". + $note_style = "float : right; background-color : #fff7d5; border-width : 1px; ". "padding : 5px; border-style : dashed; border-color : #e7d796;". - "margin-top : 5px; color : #9a8c59;"; + "margin-bottom : 1em; color : #9a8c59;"; if (!$limit) $limit = 30; @@ -3509,13 +3605,15 @@ print "" . htmlspecialchars($line["title"]) . ""; - print ""; print $line["note"]; print ""; } + + print sanitize_rss($link, $line["content_preview"], false, $owner_uid); print "]]>"; print ""; @@ -3544,9 +3642,20 @@ } } + function strip_tags_long($string, $allowed) { + + $config = HTMLPurifier_Config::createDefault(); + + $config->set('HTML', 'Allowed', $allowed); + $purifier = new HTMLPurifier($config); + + return $purifier->purify($string); + + } + // http://ru2.php.net/strip-tags - function strip_tags_long($textstring, $allowed){ +/* function strip_tags_long($textstring, $allowed){ while($textstring != strip_tags($textstring, $allowed)) { while (strlen($textstring) != 0) @@ -3563,25 +3672,30 @@ $textstring = $safetext; } return $textstring; - } +} */ - function sanitize_rss($link, $str, $force_strip_tags = false) { + function sanitize_rss($link, $str, $force_strip_tags = false, $owner = false) { $res = $str; - if (get_pref($link, "STRIP_UNSAFE_TAGS") || $force_strip_tags) { + if (!$owner) $owner = $_SESSION["uid"]; + + if (get_pref($link, "STRIP_UNSAFE_TAGS", $owner) || $force_strip_tags) { + +// $res = strip_tags_long($res, +// "


    1. "); $res = strip_tags_long($res, - "


        1. "); + "p,a[href],i,em,b,strong,code,pre,blockquote,br,img[src|alt|title],ul,ol,li,h1,h2,h3,h4"); -// $res = preg_replace("/\r\n|\n|\r/", "", $res); -// $res = strip_tags_long($res, "


          "); } - if (get_pref($link, "STRIP_IMAGES")) { - + if (get_pref($link, "STRIP_IMAGES", $owner)) { $res = preg_replace('/]+>/is', '', $res); + } + if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { + $res = preg_replace("/href=/i", "target=\"_blank\" href=", $res); } return $res; @@ -3711,7 +3825,6 @@ ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id AND include_in_digest = true AND $interval_query - AND hidden = false AND ttrss_user_entries.owner_uid = $user_id AND unread = true ORDER BY ttrss_feeds.title, date_entered DESC @@ -3932,6 +4045,9 @@ unread = NOT unread,last_read = NOW() WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); } + + $feed_id = getArticleFeed($link, $id); + ccache_update($link, $feed_id, $_SESSION["uid"]); } function make_guid_from_title($title) { @@ -3953,6 +4069,9 @@ $catchup_feed_link = "javascript:catchupCurrentFeed()"; $catchup_sel_link = "javascript:catchupSelection()"; + $archive_sel_link = "javascript:archiveSelection()"; + $delete_sel_link = "javascript:deleteSelection()"; + if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { $sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)"; @@ -3987,7 +4106,27 @@ print "". truncate_string($feed_title,30).""; } else { - print $feed_title; + if ($feed_id < -10) { + $label_id = -11-$feed_id; + + $result = db_query($link, "SELECT fg_color, bg_color + FROM ttrss_labels2 WHERE id = '$label_id' AND owner_uid = " . + $_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + $fg_color = db_fetch_result($result, 0, "fg_color"); + $bg_color = db_fetch_result($result, 0, "bg_color"); + + print ""; + print $feed_title; + print ""; + } else { + print $feed_title; + } + + } else { + print $feed_title; + } } if ($search) { @@ -4015,7 +4154,8 @@ onmouseover=\"enable_selection(false)\" onmouseout=\"enable_selection(true)\" onclick=\"toggleHeadlineActions()\" id=\"headlineActionsDrop\">". - __("Actions...") . "   + __("Actions...") . "   "; print "
            "; @@ -4024,12 +4164,19 @@
          •   ".__('Unread')."
          •   ".__('Starred')."
          •   ".__('Published')."
          • - -
          • ".__('Mark as read:')."
          • -
          •   ".__('Selection')."
          • "; +
          • ".__('Selection:')."
          • +
          •   ".__('Mark as read')."
          • "; + +// print "
          •   ".__('Entire feed'). +// "
          • "; + + if ($feed_id != "0") { + print "
          •   ".__('Archive')."
          • "; + } else { + print "
          •   ".__('Move back')."
          • "; + print "
          •   ".__('Delete')."
          • "; - print "
          •   ".__('Entire feed'). - "
          • "; + } //print "
          • --------
          • "; print "
          • ".__('Assign label:')."
          • "; @@ -4075,8 +4222,7 @@ $tmp_category"; + id=\"FCATN-$cat_id\" $browse_cat_link/>$tmp_category"; print ""; @@ -4101,56 +4247,16 @@ if (get_pref($link, 'ENABLE_FEED_CATS')) { - if ($_COOKIE["ttrss_vf_vclps"] == 1) { - $cat_hidden = true; - } else { - $cat_hidden = false; - } + $cat_hidden = get_pref($link, "_COLLAPSED_SPECIAL"); printCategoryHeader($link, -1, $cat_hidden, false); } - $num_starred = getFeedUnread($link, -1); - $num_published = getFeedUnread($link, -2); - $num_fresh = getFeedUnread($link, -3); - $num_total = getFeedUnread($link, -4); - - $class = "virt"; - - if ($num_total > 0) $class .= "Unread"; - - printFeedEntry(-4, $class, __("All articles"), $num_total, - "images/tag.png", $link); - - $class = "virt"; - - if ($num_fresh > 0) $class .= "Unread"; - - printFeedEntry(-3, $class, __("Fresh articles"), $num_fresh, - "images/fresh.png", $link); - - $class = "virt"; - - if ($num_starred > 0) $class .= "Unread"; - - $is_ie = (strpos($_SESSION["client.userAgent"], "MSIE") !== false); - - if ($is_ie) { - $mark_img_ext = "gif"; - } else { - $mark_img_ext = "png"; + foreach (array(-4, -3, -1, -2, 0) as $i) { + printFeedEntry($i, "virt", false, false, + false, $link); } - printFeedEntry(-1, $class, __("Starred articles"), $num_starred, - "images/mark_set.$mark_img_ext", $link); - - $class = "virt"; - - if ($num_published > 0) $class .= "Unread"; - - printFeedEntry(-2, $class, __("Published articles"), $num_published, - "images/pub_set.gif", $link); - if (get_pref($link, 'ENABLE_FEED_CATS')) { print "
        2. "; } @@ -4164,11 +4270,7 @@ if (db_num_rows($result) > 0) { if (get_pref($link, 'ENABLE_FEED_CATS')) { - if ($_COOKIE["ttrss_vf_lclps"] == 1) { - $cat_hidden = true; - } else { - $cat_hidden = false; - } + $cat_hidden = get_pref($link, "_COLLAPSED_LABELS"); printCategoryHeader($link, -2, $cat_hidden, true); @@ -4181,16 +4283,10 @@ $label_id = -$line['id'] - 11; $count = getFeedUnread($link, $label_id); - - $class = "label"; - - if ($count > 0) { - $class .= "Unread"; - } printFeedEntry($label_id, - $class, $line["caption"], - $count, "images/label.png", $link, + "label", $line["caption"], + $count, false, $link, false, false, false, $line['fg_color'], $line['bg_color']); @@ -4235,13 +4331,12 @@ ON (ttrss_feeds.id = feed_id) WHERE - ttrss_feeds.hidden = false AND ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL ORDER BY $order_by_qpart"; $result = db_query($link, $query); - $actid = $_GET["actid"]; + $actid = $_REQUEST["actid"]; /* real feeds */ @@ -4255,14 +4350,14 @@ while ($line = db_fetch_assoc($result)) { - $feed = trim($line["title"]); + $feed = htmlspecialchars(trim($line["title"])); if (!$feed) $feed = "[Untitled]"; $feed_id = $line["id"]; $unread = $line["unread"]; - $subop = $_GET["subop"]; + $subop = $_REQUEST["subop"]; if (get_pref($link, 'HEADLINES_SMART_DATE')) { $last_updated = smart_date_time(strtotime($line["last_updated_noms"])); @@ -4300,8 +4395,6 @@ $class = "feed"; } - if ($unread > 0) $class .= "Unread"; - if ($actid == $feed_id) { $class .= "Selected"; } @@ -4320,19 +4413,17 @@ // workaround for NULL category if ($category == __("Uncategorized")) { - if ($_COOKIE["ttrss_vf_uclps"] == 1) { - $collapsed = "t"; - } + $collapsed = get_pref($link, "_COLLAPSED_UNCAT"); } - $cat_id = sprintf("%d", $cat_id); + $cat_id = (int) $cat_id; printCategoryHeader($link, $cat_id, $collapsed, true); } printFeedEntry($feed_id, $class, $feed, $unread, - ICONS_URL."/$feed_id.ico", $link, $rtl_content, + false, $link, $rtl_content, $last_updated, $line["last_error"]); ++$lnum; @@ -4378,13 +4469,8 @@ foreach (array_keys($tags) as $tag) { $unread = $tags[$tag]; - $class = "tag"; - - if ($unread > 0) { - $class .= "Unread"; - } - + printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); } @@ -4436,6 +4522,7 @@ function tag_is_valid($tag) { if ($tag == '') return false; if (preg_match("/^[0-9]*$/", $tag)) return false; + if (mb_strlen($tag) > 250) return false; if (function_exists('iconv')) { $tag = iconv("utf-8", "utf-8", $tag); @@ -4446,11 +4533,16 @@ return true; } - function render_login_form($link, $mobile = false) { - if (!$mobile) { + function render_login_form($link, $mobile = 0) { + switch ($mobile) { + case 0: require_once "login_form.php"; - } else { + break; + case 1: require_once "mobile/login_form.php"; + break; + case 2: + require_once "mobile/classic/login_form.php"; } } @@ -4464,18 +4556,21 @@ } function format_warning($msg, $id = "") { + global $link; return "
          - $msg
          "; + $msg"; } function format_notice($msg) { - return "
          - $msg
          "; + global $link; + return "
          + $msg
          "; } function format_error($msg) { - return "
          - $msg
          "; + global $link; + return "
          + $msg
          "; } function print_notice($msg) { @@ -4496,26 +4591,64 @@ return vsprintf(__(array_shift($args)), $args); } + function format_inline_player($link, $url, $ctype) { + + $entry = ""; + + if (($ctype == __("audio/mpeg")) && (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { + + $entry .= " + "; + } + + /* + + if (substr($ctype,0,6)=="audio/" || $ctype=="application/ogg" || $ctype=="application/x-ogg") { + $entry .= " "; + if (($ctype == __("audio/mpeg")) && + (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { + $entry .= "".__('Switch to Flash Player').""; + $entry .= ""; + } + } elseif (substr($ctype,0,6)=="video/") { + $entry .= ""; + } */ + + + + return $entry; + } + function outputArticleXML($link, $id, $feed_id, $mark_as_read = true, $zoom_mode = false) { /* we can figure out feed_id from article id anyway, why do we - * pass feed_id here? */ + * pass feed_id here? let's ignore the argument :( */ $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries WHERE ref_id = '$id'"); - $feed_id = db_fetch_result($result, 0, "feed_id"); + $feed_id = (int) db_fetch_result($result, 0, "feed_id"); if (!$zoom_mode) { print "
          $num_comments comments"; + $entry_comments = "$num_comments comments"; } else { if ($line["comments"] && $line["link"] != $line["comments"]) { - $entry_comments = "comments"; + $entry_comments = "comments"; } } @@ -4602,7 +4730,7 @@ print "
          $parsed_updated
          "; if ($line["link"]) { - print "
          " . + print ""; } else { print "
          " . $line["title"] . "$entry_author
          "; @@ -4613,38 +4741,60 @@ if (!$entry_comments) $entry_comments = " "; # placeholder print "
          - Tags "; + Tags "; if (!$zoom_mode) { print "$tags_str (+)"; - if (defined('_ENABLE_INLINE_VIEW')) { - - print "Inline"; - - } - - print "Zoom"; $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); - print "PubNote"; + } else { + $tags_str = strip_tags($tags_str); + print "$tags_str"; } print "
          "; print "
          $entry_comments
          "; + if ($line["orig_feed_id"]) { + + $tmp_result = db_query($link, "SELECT * FROM ttrss_archived_feeds + WHERE id = ".$line["orig_feed_id"]); + + if (db_num_rows($tmp_result) != 0) { + + print "
          "; + print __("Originally from:"); + + print " "; + + $tmp_line = db_fetch_assoc($tmp_result); + + print "" . + $tmp_line['title'] . ""; + + print " "; + + print ""; + print ""; + + print "
          "; + } + } + print "
          "; print "
          " . $feed_icon . "
          "; @@ -4653,19 +4803,14 @@ $article_content = sanitize_rss($link, $line["content"]); - if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { - $article_content = preg_replace("/href=/i", "target=\"_blank\" href=", - $article_content); - } - - print $article_content; - print "
          "; if ($line['note']) { print format_article_note($id, $line['note']); } print "
          "; + print $article_content; + $result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE post_id = '$id' AND content_url != ''"); @@ -4683,16 +4828,9 @@ $filename = substr($url, strrpos($url, "/")+1); - $entry = ""; - - if (($ctype == __("audio/mpeg")) && - (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { - - $entry .= " "; - - } + $entry = format_inline_player($link, $url, $ctype); - $entry .= "" . + $entry .= " " . $filename . " (" . $ctype . ")" . ""; array_push($entries_html, $entry); @@ -4708,12 +4846,14 @@ print "
          "; - if (!preg_match("/\"".htmlspecialchars($entry["filename"])."\"

          "; + if (!get_pref($link, "STRIP_IMAGES")) { + if ($always_display_enclosures || !preg_match("/\"".htmlspecialchars($entry["filename"])."\"

          "; + } } } } @@ -4742,8 +4882,8 @@ } else { print "
          -
          "; +
          "; print ""; } @@ -4769,8 +4909,8 @@ $subop_split = split(":", $subop); if ($subop == "CatchupSelected") { - $ids = split(",", db_escape_string($_GET["ids"])); - $cmode = sprintf("%d", $_GET["cmode"]); + $ids = split(",", db_escape_string($_REQUEST["ids"])); + $cmode = sprintf("%d", $_REQUEST["cmode"]); catchupArticlesById($link, $ids, $cmode); } @@ -4829,14 +4969,14 @@ /// START ///////////////////////////////////////////////////////////////////////////////// - $search = db_escape_string($_GET["query"]); + $search = db_escape_string($_REQUEST["query"]); if ($search) { $disable_cache = true; } - $search_mode = db_escape_string($_GET["search_mode"]); - $match_on = db_escape_string($_GET["match_on"]); + $search_mode = db_escape_string($_REQUEST["search_mode"]); + $match_on = db_escape_string($_REQUEST["match_on"]); if (!$match_on) { $match_on = "both"; @@ -4844,12 +4984,12 @@ $real_offset = $offset * $limit; - if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info); + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info); $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order, $real_offset); - if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info); + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info); $result = $qfh_ret[0]; $feed_title = $qfh_ret[1]; @@ -4896,6 +5036,8 @@ $num_unread = 0; $cur_feed_title = ''; + $fresh_intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60; + while ($line = db_fetch_assoc($result)) { $class = ($lnum % 2) ? "even" : "odd"; @@ -4913,15 +5055,22 @@ array_push($topmost_article_ids, $id); } - if ($line["last_read"] == "" && - ($line["unread"] != "t" && $line["unread"] != "1")) { + if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) { - $update_pic = "\"Updated\""; } else { $update_pic = "\"Updated\""; } + + if (sql_bool_to_bool($line["unread"]) && + time() - strtotime($line["updated_noms"]) < $fresh_intl) { + + $update_pic = "\"Fresh\""; + } if ($line["unread"] == "t" || $line["unread"] == "1") { $class .= "Unread"; @@ -4931,30 +5080,26 @@ $is_unread = false; } - $is_ie = (strpos($_SESSION["client.userAgent"], "MSIE") !== false); - - if ($is_ie) { - $mark_img_ext = "gif"; - } else { - $mark_img_ext = "png"; - } - if ($line["marked"] == "t" || $line["marked"] == "1") { - $marked_pic = "\"Unstar"; + $marked_pic = "\"Unstar"; } else { - $marked_pic = "\"Star"; + $marked_pic = "\"Star"; } if ($line["published"] == "t" || $line["published"] == "1") { - $published_pic = "\"Unpublish"; } else { - $published_pic = "\"Publish"; } @@ -4984,13 +5129,14 @@ $score = $line["score"]; - $score_pic = get_score_pic($score); + $score_pic = theme_image($link, + "images/" . get_score_pic($score)); /* $score_title = __("(Click to change)"); $score_pic = ""; */ - $score_pic = ""; if ($score > 500) { @@ -5026,7 +5172,7 @@ $cur_feed_title = htmlspecialchars($cur_feed_title); - $vf_catchup_link = "(mark as read)"; + $vf_catchup_link = "(".__('mark as read').")"; print "". "
          $feed_icon_img
          ". @@ -5057,11 +5203,11 @@ # truncate_string($line["feed_title"],30)." "; # } else { - print ""; + print ""; print "" . + onclick=\"return false\">" . $line["title"]; if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { @@ -5085,11 +5231,15 @@ "; } } + +// print ""; + print ""; # } - print "$updated_fmt "; + print "$updated_fmt "; print "$score_pic"; @@ -5109,7 +5259,7 @@ $cur_feed_title = htmlspecialchars($cur_feed_title); - $vf_catchup_link = "(mark as read)"; + $vf_catchup_link = "(".__('mark as read').")"; $has_feed_icon = feed_has_icon($feed_id); @@ -5182,16 +5332,18 @@ print ""; - if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { - $line["content_preview"] = preg_replace("/href=/i", - "target=\"_blank\" href=", $line["content_preview"]); - } - if ($show_excerpt) { print "
          "; - print truncate_string(strip_tags($line["content_preview"]), 100); + + $content_preview = trim(truncate_string(strip_tags($line["content_preview"]), 100)); + + if (strlen($content_preview) != 0) { + print $content_preview; + } else { + print __('Click to expand article'); + } print "
          "; } @@ -5199,9 +5351,34 @@ onclick=\"cdmClicked($id)\" id=\"CICD-$id\" $cdm_cstyle>"; -// print "
          "; + if ($line["orig_feed_id"]) { - print sanitize_rss($link, $line["content_preview"]); + $tmp_result = db_query($link, "SELECT * FROM ttrss_archived_feeds + WHERE id = ".$line["orig_feed_id"]); + + if (db_num_rows($tmp_result) != 0) { + + print "
          "; + print __("Originally from:"); + + print " "; + + $tmp_line = db_fetch_assoc($tmp_result); + + print "" . + $tmp_line['title'] . ""; + + print " "; + + print ""; + print ""; + + print "
          "; + } + } + +// print "
          "; print "
          "; if ($line['note']) { @@ -5209,6 +5386,8 @@ } print "
          "; + print sanitize_rss($link, $line["content_preview"]); + $article_content = $line["content_preview"]; $e_result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE @@ -5227,16 +5406,9 @@ $filename = substr($url, strrpos($url, "/")+1); - $entry = ""; - - if (($ctype == __("audio/mpeg")) && - (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { - - $entry .= " "; - - } + $entry = format_inline_player($link, $url, $ctype); - $entry .= "" . + $entry .= " " . $filename . " (" . $ctype . ")" . ""; array_push($entries_html, $entry); @@ -5250,12 +5422,19 @@ array_push($entries, $entry); } - if (!preg_match("/img/i", $article_content)) { - foreach ($entries as $entry) { - if (preg_match("/image/", $entry["type"])) { - print "

          \"".htmlspecialchars($entry["filename"])."\"

          "; + $tmp_result = db_query($link, "SELECT always_display_enclosures FROM + ttrss_feeds WHERE id = ".$line['feed_id']." AND owner_uid = ".$_SESSION["uid"]); + + $always_display_enclosures = db_fetch_result($tmp_result, 0, "always_display_enclosures"); + + if (!get_pref($link, "STRIP_IMAGES")) { + if ($always_display_enclosures || !preg_match("/img/i", $article_content)) { + foreach ($entries as $entry) { + if (preg_match("/image/", $entry["type"])) { + print "

          \"".htmlspecialchars($entry["filename"])."\"

          "; + } } } } @@ -5312,10 +5491,9 @@ $tags_str = format_tags_string(get_article_tags($link, $id), $id); -// print ""; - print " - Tags + Tags $tags_str (+)"; @@ -5456,7 +5634,8 @@ } $url_path .= $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); - $url_path .= "/backend.php?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY"); + $url_path .= "/backend.php?op=publish&key=" . + get_pref($link, "_PREFS_PUBLISH_KEY", $_SESSION["uid"]); return $url_path; } @@ -5469,8 +5648,14 @@ * @return void */ function clear_feed_articles($link, $id) { - $result = db_query($link, "DELETE FROM ttrss_user_entries + + if ($id != 0) { + $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]); + } else { + $result = db_query($link, "DELETE FROM ttrss_user_entries + WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]); + } $result = db_query($link, "DELETE FROM ttrss_entries WHERE (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); @@ -5661,13 +5846,13 @@ if ($score > 100) { return "score_high.png"; } else if ($score > 0) { - return "score_half_high.png"; + return "score_half_high.png"; } else if ($score < -100) { - return "score_low.png"; + return "score_low.png"; } else if ($score < 0) { - return "score_half_low.png"; + return "score_half_low.png"; } else { - return "score_neutral.png"; + return "score_neutral.png"; } } @@ -6086,11 +6271,13 @@ $num_tags = 0; - if ($_SESSION["theme"] == "3pane") { +/* if (get_user_theme($link) == "3pane") { $tag_limit = 3; } else { $tag_limit = 6; - } + } */ + + $tag_limit = 6; $formatted_tags = array(); @@ -6098,11 +6285,17 @@ $num_tags++; $tag_escaped = str_replace("'", "\\'", $tag); + if (mb_strlen($tag) > 30) { + $tag = truncate_string($tag, 30); + } + $tag_str = "$tag"; array_push($formatted_tags, $tag_str); + + $tmp_tags_str = implode(", ", $formatted_tags); - if ($num_tags == $tag_limit) { + if ($num_tags == $tag_limit || mb_strlen($tmp_tags_str) > 150) { break; } } @@ -6140,13 +6333,154 @@ $note_escaped = htmlspecialchars($note, ENT_QUOTES); $str = "
          "; + $str .= $note; $str .= "
          "; $str .= "". __('edit note').""; $str .= "
          "; - $str .= $note; $str .= "
          "; return $str; } + + function toggle_collapse_cat($link, $cat_id) { + if ($cat_id > 0) { + db_query($link, "UPDATE ttrss_feed_categories SET + collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " . + $_SESSION["uid"]); + } else { + $pref_name = ''; + + switch ($cat_id) { + case -1: + $pref_name = '_COLLAPSED_SPECIAL'; + break; + case -2: + $pref_name = '_COLLAPSED_LABELS'; + break; + case 0: + $pref_name = '_COLLAPSED_UNCAT'; + break; + } + + if ($pref_name) { + if (get_pref($link, $pref_name)) { + set_pref($link, $pref_name, 'false'); + } else { + set_pref($link, $pref_name, 'true'); + } + } + } + } + + function remove_feed($link, $id, $owner_uid) { + + if ($id > 0) { + + /* save starred articles in Archived feed */ + + db_query($link, "BEGIN"); + + /* prepare feed if necessary */ + + $result = db_query($link, "SELECT id FROM ttrss_archived_feeds + WHERE id = '$id'"); + + if (db_num_rows($result) == 0) { + db_query($link, "INSERT INTO ttrss_archived_feeds + (id, owner_uid, title, feed_url, site_url) + SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds + WHERE id = '$id'"); + } + + db_query($link, "UPDATE ttrss_user_entries SET feed_id = NULL, + orig_feed_id = '$id' WHERE feed_id = '$id' AND + marked = true AND owner_uid = $owner_uid"); + + /* remove the feed */ + + db_query($link, "DELETE FROM ttrss_feeds + WHERE id = '$id' AND owner_uid = $owner_uid"); + + db_query($link, "COMMIT"); + +/* if (file_exists(ICONS_DIR . "/$id.ico")) { + unlink(ICONS_DIR . "/$id.ico"); + } */ + + ccache_remove($link, $id, $owner_uid); + + } else { + label_remove($link, -11-$id, $owner_uid); + ccache_remove($link, -11-$id, $owner_uid); + } + } + + function remove_feed_category($link, $id, $owner_uid) { + + db_query($link, "DELETE FROM ttrss_feed_categories + WHERE id = '$id' AND owner_uid = $owner_uid"); + + ccache_remove($link, $id, $owner_uid, true); + } + + function archive_article($link, $id, $owner_uid) { + db_query($link, "BEGIN"); + + $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries + WHERE ref_id = '$id' AND owner_uid = $owner_uid"); + + if (db_num_rows($result) != 0) { + + /* prepare the archived table */ + + $feed_id = (int) db_fetch_result($result, 0, "feed_id"); + + if ($feed_id) { + $result = db_query($link, "SELECT id FROM ttrss_archived_feeds + WHERE id = '$feed_id'"); + + if (db_num_rows($result) == 0) { + db_query($link, "INSERT INTO ttrss_archived_feeds + (id, owner_uid, title, feed_url, site_url) + SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds + WHERE id = '$feed_id'"); + } + + db_query($link, "UPDATE ttrss_user_entries + SET orig_feed_id = feed_id, feed_id = NULL + WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); + } + } + + db_query($link, "COMMIT"); + } + + function getArticleFeed($link, $id) { + $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries + WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + return db_fetch_result($result, 0, "feed_id"); + } else { + return 0; + } + } + + function make_url_from_parts($parts) { + $url = $parts['scheme'] . '://' . $parts['host']; + + if ($parts['path']) $url .= $parts['path']; + if ($parts['query']) $url .= '?' . $parts['query']; + + return $url; + } + + function validate_feed_url($url) { + $parts = parse_url($url); + + return ($parts['scheme'] == 'http' || $parts['scheme'] == 'feed' || $parts['scheme'] == 'https'); + + } + ?>