X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=sidebyside;f=functions.php;h=6169f93a8cd4b827e3c4f3537e3460d842e0922d;hb=d9fa39f1d444fbd5a909aabe19dfc50aa8601131;hp=a58613ccb7d63f5fb2bada6d8a04d98d79e7540c;hpb=59e2aab4687694d6e64d56e8751a1d1eff3fd609;p=tt-rss.git diff --git a/functions.php b/functions.php index a58613cc..6169f93a 100644 --- a/functions.php +++ b/functions.php @@ -1,4 +1,4 @@ -]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $html, $matches)) { + // Attempt to grab a favicon link from their webpage url + $linkUrl = html_entity_decode($matches[1]); + + if (substr($linkUrl, 0, 1) == '/') { + $urlParts = parse_url($url); + $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].$linkUrl; + } else if (substr($linkUrl, 0, 7) == 'http://') { + $faviconURL = $linkUrl; + } else if (substr($url, -1, 1) == '/') { + $faviconURL = $url.$linkUrl; + } else { + $faviconURL = $url.'/'.$linkUrl; } - chmod($icon_file, 0644); + } else { + // If unsuccessful, attempt to "guess" the favicon location + $urlParts = parse_url($url); + $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].'/favicon.ico'; + } + } + + // Run a test to see if what we have attempted to get actually exists. + if(USE_CURL_FOR_ICONS || url_validate($faviconURL)) { + return $faviconURL; + } else { + return false; + } + } + + function url_validate($link) { + + $url_parts = @parse_url($link); + + if ( empty( $url_parts["host"] ) ) + return false; + + if ( !empty( $url_parts["path"] ) ) { + $documentpath = $url_parts["path"]; + } else { + $documentpath = "/"; + } + + if ( !empty( $url_parts["query"] ) ) + $documentpath .= "?" . $url_parts["query"]; + + $host = $url_parts["host"]; + $port = $url_parts["port"]; + + if ( empty($port) ) + $port = "80"; + + $socket = @fsockopen( $host, $port, $errno, $errstr, 30 ); + + if ( !$socket ) + return false; - error_reporting (DEFAULT_ERROR_LEVEL); + fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n"); + + $http_response = fgets( $socket, 22 ); + + $responses = "/(200 OK)|(30[0-9] Moved)/"; + if ( preg_match($responses, $http_response) ) { + fclose($socket); + return true; + } else { + return false; + } + + } + + function check_feed_favicon($site_url, $feed, $link) { + $favicon_url = get_favicon_url($site_url); + +# print "FAVICON [$site_url]: $favicon_url\n"; + + error_reporting(0); - } + $icon_file = ICONS_DIR . "/$feed.ico"; + + if ($favicon_url && !file_exists($icon_file)) { + $contents = fetch_file_contents($favicon_url); + + $fp = fopen($icon_file, "w"); + + if ($fp) { + fwrite($fp, $contents); + fclose($fp); + chmod($icon_file, 0644); + } } + + error_reporting(DEFAULT_ERROR_LEVEL); + } function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) { - if (WEB_DEMO_MODE) return; - if (DAEMON_REFRESH_ONLY && !$_GET["daemon"] && !$ignore_daemon) { return; } @@ -275,31 +360,13 @@ } - if (RSS_BACKEND_TYPE == "magpie") { - error_reporting(0); - $rss = fetch_rss($fetch_url); - error_reporting (DEFAULT_ERROR_LEVEL); - } else if (RSS_BACKEND_TYPE == "simplepie") { - - if (!file_exists(SIMPLEPIE_CACHE_DIR)) { - mkdir(SIMPLEPIE_CACHE_DIR); - } - - $rss = new SimplePie(); - $rss->feed_url($fetch_url); - $rss->cache_location(SIMPLEPIE_CACHE_DIR); - $rss->init(); - } + error_reporting(0); + $rss = fetch_rss($fetch_url); + error_reporting (DEFAULT_ERROR_LEVEL); $feed = db_escape_string($feed); - $rss_check = $rss; - - if (RSS_BACKEND_TYPE == "simplepie") { - $rss_check = $rss->data; - } - - if ($rss_check) { + if ($rss) { // db_query($link, "BEGIN"); @@ -312,29 +379,21 @@ $owner_uid = db_fetch_result($result, 0, "owner_uid"); - if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid)) { - check_feed_favicon($feed_url, $feed, $link); + if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) { + check_feed_favicon($rss->channel["link"], $feed, $link); } if (!$registered_title || $registered_title == "[Unknown]") { - if (RSS_BACKEND_TYPE == "magpie") { - $feed_title = db_escape_string($rss->channel["title"]); - } else { - $feed_title = $rss->get_feed_title(); - } + $feed_title = db_escape_string($rss->channel["title"]); db_query($link, "UPDATE ttrss_feeds SET title = '$feed_title' WHERE id = '$feed'"); } - if (RSS_BACKEND_TYPE == "magpie") { - $site_url = $rss->channel["link"]; - // weird, weird Magpie - if (!$site_url) $site_url = db_escape_string($rss->channel["link_"]); - } else { - $site_url = $rss->get_feed_link(); - } + $site_url = $rss->channel["link"]; + // weird, weird Magpie + if (!$site_url) $site_url = db_escape_string($rss->channel["link_"]); if ($site_url && $orig_site_url != db_escape_string($site_url)) { db_query($link, "UPDATE ttrss_feeds SET @@ -343,11 +402,7 @@ // print "I: " . $rss->channel["image"]["url"]; - if (RSS_BACKEND_TYPE == "magpie") { - $icon_url = $rss->image["url"]; - } else { - $icon_url = $rss->get_image_url(); # FIXME - } + $icon_url = $rss->image["url"]; if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) { $icon_url = db_escape_string($icon_url); @@ -359,8 +414,10 @@ $result = db_query($link, "SELECT reg_exp, ttrss_filter_types.name AS name, - ttrss_filter_actions.name AS action + ttrss_filter_actions.name AS action, + action_param FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE + enabled = true AND owner_uid = $owner_uid AND ttrss_filter_types.id = filter_type AND ttrss_filter_actions.id = action_id AND @@ -371,19 +428,15 @@ $filter["reg_exp"] = $line["reg_exp"]; $filter["action"] = $line["action"]; - + $filter["action_param"] = $line["action_param"]; + array_push($filters[$line["name"]], $filter); } - if (RSS_BACKEND_TYPE == "magpie") { - $iterator = $rss->items; - - if (!$iterator || !is_array($iterator)) $iterator = $rss->entries; - if (!$iterator || !is_array($iterator)) $iterator = $rss; + $iterator = $rss->items; - } else { - $iterator = $rss->get_items(); - } + if (!$iterator || !is_array($iterator)) $iterator = $rss->entries; + if (!$iterator || !is_array($iterator)) $iterator = $rss; if (!is_array($iterator)) { /* db_query($link, "UPDATE ttrss_feeds @@ -394,142 +447,116 @@ foreach ($iterator as $item) { - if (RSS_BACKEND_TYPE == "magpie") { - - $entry_guid = $item["id"]; - - if (!$entry_guid) $entry_guid = $item["guid"]; - if (!$entry_guid) $entry_guid = $item["link"]; - - if (!$entry_guid) continue; - - $entry_timestamp = ""; + $entry_guid = $item["id"]; - $rss_2_date = $item['pubdate']; - $rss_1_date = $item['dc']['date']; - $atom_date = $item['issued']; - if (!$atom_date) $atom_date = $item['updated']; + if (!$entry_guid) $entry_guid = $item["guid"]; + if (!$entry_guid) $entry_guid = $item["link"]; + if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]); + + if (!$entry_guid) continue; + + $entry_timestamp = ""; + + $rss_2_date = $item['pubdate']; + $rss_1_date = $item['dc']['date']; + $atom_date = $item['issued']; + if (!$atom_date) $atom_date = $item['updated']; + + if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date); + if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date); + if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date); - if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date); - if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date); - if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date); - - if ($entry_timestamp == "") { - $entry_timestamp = time(); - $no_orig_date = 'true'; - } else { - $no_orig_date = 'false'; - } - - $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); - - $entry_title = $item["title"]; - - // strange Magpie workaround - $entry_link = $item["link_"]; - if (!$entry_link) $entry_link = $item["link"]; - - if (!$entry_title) continue; - if (!$entry_link) continue; - - $entry_content = $item["content:escaped"]; - - if (!$entry_content) $entry_content = $item["content:encoded"]; - if (!$entry_content) $entry_content = $item["content"]; - if (!$entry_content) $entry_content = $item["atom_content"]; - if (!$entry_content) $entry_content = $item["summary"]; - if (!$entry_content) $entry_content = $item["description"]; - - // if (!$entry_content) continue; - - // WTF - if (is_array($entry_content)) { - $entry_content = $entry_content["encoded"]; - if (!$entry_content) $entry_content = $entry_content["escaped"]; - } - - // print_r($item); - // print_r(htmlspecialchars($entry_content)); - // print "
"; - - $entry_content_unescaped = $entry_content; - $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); - - $entry_comments = $item["comments"]; - - $entry_author = db_escape_string($item['dc']['creator']); - - $entry_guid = db_escape_string($entry_guid); - - $result = db_query($link, "SELECT id FROM ttrss_entries - WHERE guid = '$entry_guid'"); - - $entry_content = db_escape_string($entry_content); - $entry_title = db_escape_string($entry_title); - $entry_link = db_escape_string($entry_link); - $entry_comments = db_escape_string($entry_comments); - - $num_comments = db_escape_string($item["slash"]["comments"]); - - if (!$num_comments) $num_comments = 0; + if ($entry_timestamp == "") { + $entry_timestamp = time(); + $no_orig_date = 'true'; + } else { + $no_orig_date = 'false'; + } + + $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); + + $entry_title = trim(strip_tags($item["title"])); + + // strange Magpie workaround + $entry_link = $item["link_"]; + if (!$entry_link) $entry_link = $item["link"]; + + if (!$entry_title) continue; +# if (!$entry_link) continue; + + $entry_link = strip_tags($entry_link); + + $entry_content = $item["content:escaped"]; + + if (!$entry_content) $entry_content = $item["content:encoded"]; + if (!$entry_content) $entry_content = $item["content"]; + if (!$entry_content) $entry_content = $item["atom_content"]; + if (!$entry_content) $entry_content = $item["summary"]; + if (!$entry_content) $entry_content = $item["description"]; + +// if (!$entry_content) continue; + + // WTF + if (is_array($entry_content)) { + $entry_content = $entry_content["encoded"]; + if (!$entry_content) $entry_content = $entry_content["escaped"]; + } + +// print_r($item); +// print_r(htmlspecialchars($entry_content)); +// print "
"; + + $entry_content_unescaped = $entry_content; + $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); - } else if (RSS_BACKEND_TYPE == "simplepie") { + $entry_comments = strip_tags($item["comments"]); - $entry_guid = $item->get_id(); + $entry_author = db_escape_string(strip_tags($item['dc']['creator'])); - if (!$entry_guid) { - $entry_guid = $item->get_permalink(); + if ($item['author']) { + if (!$entry_author) { + $entry_author = db_escape_string(strip_tags($item['author']['name'])); } - - if (!$entry_guid) continue; - - $entry_timestamp = $item->get_date("U"); - - if ($entry_timestamp == "") { - $entry_timestamp = time(); - $no_orig_date = 'true'; - } else { - $no_orig_date = 'false'; + + if (!$entry_author) { + $entry_author = db_escape_string(strip_tags($item['author']['email'])); } - - $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); - - $entry_title = $item->get_title(); - $entry_link = $item->get_permalink(); - - if (!$entry_title) continue; - if (!$entry_link) continue; - $entry_content = $item->get_description(); - -// print_r(htmlspecialchars($entry_content)); -// print "
"; - - $entry_content_unescaped = $entry_content; - $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); - - $entry_comments = ""; # FIXME - - $entry_author = $item->get_author(0); + if (!$entry_author) { + $entry_author = db_escape_string(strip_tags($item['author'])); + } + } - $entry_author = db_escape_string($entry_author->name); - - $entry_guid = db_escape_string($entry_guid); + if (preg_match('/^[\t\n\r ]*$/', $entry_author)) $entry_author = ''; - $result = db_query($link, "SELECT id FROM ttrss_entries - WHERE guid = '$entry_guid'"); - - $entry_content = db_escape_string($entry_content); - $entry_title = db_escape_string($entry_title); - $entry_link = db_escape_string($entry_link); - $entry_comments = db_escape_string($entry_comments); - - $num_comments = 0; # FIXME - - if (!$num_comments) $num_comments = 0; + $entry_guid = db_escape_string(strip_tags($entry_guid)); + + $result = db_query($link, "SELECT id FROM ttrss_entries + WHERE guid = '$entry_guid'"); + $entry_content = db_escape_string($entry_content); + $entry_title = db_escape_string($entry_title); + $entry_link = db_escape_string($entry_link); + $entry_comments = db_escape_string($entry_comments); + + $num_comments = db_escape_string($item["slash"]["comments"]); + + if (!$num_comments) $num_comments = 0; + + $dc_subject = $item['dc']['subject']; + + $subject_tags = false; + + if (is_array($dc_subject)) { + $subject_tags = $dc_subject; + } else if ($dc_subject) { + $subject_tags = array($dc_subject); } + # sanitize content + + $entry_content = sanitize_rss($entry_content); + db_query($link, "BEGIN"); if (db_num_rows($result) == 0) { @@ -598,7 +625,7 @@ // check for user post link to main table // do we allow duplicate posts with same GUID in different feeds? - if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid)) { + if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) { $dupcheck_qpart = "AND feed_id = '$feed'"; } else { $dupcheck_qpart = ""; @@ -606,9 +633,12 @@ // error_reporting(0); - $filter_name = get_filter_name($entry_title, $entry_content, + $tuple = get_filter_name($entry_title, $entry_content, $entry_link, $filters); + $filter_name = $tuple[0]; + $filter_param = $tuple[1]; + if ($filter_name == "filter") { continue; } @@ -646,7 +676,7 @@ $post_needs_update = false; - if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid) && + if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid, false) && ($content_hash != $orig_content_hash)) { $post_needs_update = true; } @@ -676,7 +706,7 @@ num_comments = '$num_comments' WHERE id = '$ref_id'"); - if (get_pref($link, "MARK_UNREAD_ON_UPDATE")) { + if (get_pref($link, "MARK_UNREAD_ON_UPDATE", $owner_uid, false)) { db_query($link, "UPDATE ttrss_user_entries SET last_read = null, unread = true WHERE ref_id = '$ref_id'"); } else { @@ -703,6 +733,27 @@ $entry_tags = $entry_tags[1]; + # check for manual tags + + if ($filter_name == "tag") { + + $manual_tags = trim_array(split(",", $filter_param)); + + foreach ($manual_tags as $tag) { + if (tag_is_valid($tag)) { + array_push($entry_tags, $tag); + } + } + } + + if ($subject_tags) { + foreach ($subject_tags as $tag) { + if (tag_is_valid($tag)) { + array_push($entry_tags, $tag); + } + } + } + if (count($entry_tags) > 0) { db_query($link, "BEGIN"); @@ -791,7 +842,7 @@ foreach ($filters["title"] as $filter) { $reg_exp = $filter["reg_exp"]; if (preg_match("/$reg_exp/i", $title)) { - return $filter["action"]; + return array($filter["action"], $filter["action_param"]); } } } @@ -800,7 +851,7 @@ foreach ($filters["content"] as $filter) { $reg_exp = $filter["reg_exp"]; if (preg_match("/$reg_exp/i", $content)) { - return $filter["action"]; + return array($filter["action"], $filter["action_param"]); } } } @@ -810,7 +861,7 @@ $reg_exp = $filter["reg_exp"]; if (preg_match("/$reg_exp/i", $title) || preg_match("/$reg_exp/i", $content)) { - return $filter["action"]; + return array($filter["action"], $filter["action_param"]); } } } @@ -820,7 +871,7 @@ foreach ($filters["link"] as $filter) { $reg_exp = $filter["reg_exp"]; if (preg_match("/$reg_exp/i", $link)) { - return $filter["action"]; + return array($filter["action"], $filter["action_param"]); } } } @@ -828,6 +879,51 @@ return false; } + function get_filter_matches($title, $content, $link, $filters) { + + $matches = array(); + + if ($filters["title"]) { + foreach ($filters["title"] as $filter) { + $reg_exp = $filter["reg_exp"]; + if (preg_match("/$reg_exp/i", $title)) { + array_push($matches, array($filter["action"], $filter["action_param"])); + } + } + } + + if ($filters["content"]) { + foreach ($filters["content"] as $filter) { + $reg_exp = $filter["reg_exp"]; + if (preg_match("/$reg_exp/i", $content)) { + array_push($matches, array($filter["action"], $filter["action_param"])); + } + } + } + + if ($filters["both"]) { + foreach ($filters["both"] as $filter) { + $reg_exp = $filter["reg_exp"]; + if (preg_match("/$reg_exp/i", $title) || + preg_match("/$reg_exp/i", $content)) { + array_push($matches, array($filter["action"], $filter["action_param"])); + } + } + } + + if ($filters["link"]) { + $reg_exp = $filter["reg_exp"]; + foreach ($filters["link"] as $filter) { + $reg_exp = $filter["reg_exp"]; + if (preg_match("/$reg_exp/i", $link)) { + array_push($matches, array($filter["action"], $filter["action_param"])); + } + } + } + + return $matches; + } + function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link, $rtl_content = false, $last_updated = false, $last_error = false) { @@ -852,7 +948,8 @@ $link_title = "Updated: $last_updated"; } - $feed = "$feed_title"; + $feed = "$feed_title"; print "
  • "; if (get_pref($link, 'ENABLE_FEED_ICONS')) { @@ -970,14 +1067,23 @@ return true; } - function authenticate_user($link, $login, $password) { + function authenticate_user($link, $login, $password, $force_auth = false) { if (!SINGLE_USER_MODE) { $pwd_hash = 'SHA1:' . sha1($password); - - $result = db_query($link, "SELECT id,login,access_level FROM ttrss_users WHERE - login = '$login' AND pwd_hash = '$pwd_hash'"); + + if ($force_auth && defined('_DEBUG_USER_SWITCH')) { + $query = "SELECT id,login,access_level + FROM ttrss_users WHERE + login = '$login'"; + } else { + $query = "SELECT id,login,access_level + FROM ttrss_users WHERE + login = '$login' AND pwd_hash = '$pwd_hash'"; + } + + $result = db_query($link, $query); if (db_num_rows($result) == 1) { $_SESSION["uid"] = db_fetch_result($result, 0, "id"); @@ -1104,6 +1210,14 @@ function login_sequence($link) { 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); + } + } + if (!validate_session($link)) { logout_user(); $redirect_uri = get_login_redirect(); @@ -1210,6 +1324,8 @@ 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"); @@ -1218,12 +1334,21 @@ $error_code = 5; } + if (DB_TYPE == "mysql") { + $result = db_query($link, "SELECT true", false); + if (db_num_rows($result) != 1) { + $error_code = 10; + } + } + + error_reporting (DEFAULT_ERROR_LEVEL); + if ($error_code != 0) { - print_error_xml(5); + print_error_xml($error_code); return false; } else { return true; - } + } } function file_is_locked($filename) { @@ -1261,7 +1386,8 @@ } function catchup_feed($link, $feed, $cat_view) { - if (preg_match("/^[0-9][0-9]*$/", $feed) != false && $feed >= 0) { + + if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { if ($cat_view) { @@ -1336,11 +1462,12 @@ "SELECT int_id FROM - ttrss_user_entries,ttrss_entries + ttrss_user_entries,ttrss_entries,ttrss_feeds WHERE - ref_id = id AND + ref_id = ttrss_entries.id AND + ttrss_user_entries.feed_id = ttrss_feeds.id AND $sql_exp AND - owner_uid = " . $_SESSION["uid"]); + ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); while ($tmp_line = db_fetch_assoc($tmp2_result)) { db_query($link, "UPDATE @@ -1402,13 +1529,26 @@ } } - function getAllCounters($link) { - getLabelCounters($link); + function getAllCounters($link, $omode = "tflc") { +/* getLabelCounters($link); getFeedCounters($link); getTagCounters($link); getGlobalCounters($link); if (get_pref($link, 'ENABLE_FEED_CATS')) { getCategoryCounters($link); + } */ + + if (!$omode) $omode = "tflc"; + + getGlobalCounters($link); + + if (strchr($omode, "l")) getLabelCounters($link); + if (strchr($omode, "f")) getFeedCounters($link); + if (strchr($omode, "t")) getTagCounters($link); + if (strchr($omode, "c")) { + if (get_pref($link, 'ENABLE_FEED_CATS')) { + getCategoryCounters($link); + } } } @@ -1417,7 +1557,7 @@ FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id AND unread = true)) AS unread FROM ttrss_feeds WHERE - owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id"); + hidden = false AND owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id"); while ($line = db_fetch_assoc($result)) { $line["cat_id"] = sprintf("%d", $line["cat_id"]); @@ -1435,6 +1575,7 @@ } $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query + AND hidden = false AND owner_uid = " . $_SESSION["uid"]); $cat_feeds = array(); @@ -1470,7 +1611,9 @@ $match_part = "marked = true"; } else if ($n_feed > 0) { - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE parent_feed = '$n_feed' + $result = db_query($link, "SELECT id FROM ttrss_feeds + WHERE parent_feed = '$n_feed' + AND hidden = false AND owner_uid = " . $_SESSION["uid"]); if (db_num_rows($result) > 0) { @@ -1479,12 +1622,15 @@ while ($line = db_fetch_assoc($result)) { array_push($linked_feeds, "feed_id = " . $line["id"]); } + + array_push($linked_feeds, "feed_id = $n_feed"); $match_part = implode(" OR ", $linked_feeds); $result = db_query($link, "SELECT COUNT(int_id) AS unread - FROM ttrss_user_entries - WHERE unread = true AND ($match_part) AND owner_uid = " . $_SESSION["uid"]); + FROM ttrss_user_entries + WHERE unread = true AND ($match_part) + AND owner_uid = " . $_SESSION["uid"]); $unread = 0; @@ -1499,6 +1645,7 @@ $match_part = "feed_id = '$n_feed'"; } } else if ($feed < -10) { + $label_id = -$feed - 11; $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE @@ -1510,8 +1657,11 @@ if ($match_part) { $result = db_query($link, "SELECT count(int_id) AS unread - FROM ttrss_user_entries - WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]); + FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE + ttrss_user_entries.feed_id = ttrss_feeds.id AND + ttrss_user_entries.ref_id = ttrss_entries.id AND + ttrss_feeds.hidden = false AND + unread = true AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); } else { @@ -1522,16 +1672,24 @@ } $unread = db_fetch_result($result, 0, "unread"); + return $unread; } /* FIXME this needs reworking */ - function getGlobalUnread($link) { - $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries + function getGlobalUnread($link, $user_id = false) { + + if (!$user_id) { + $user_id = $_SESSION["uid"]; + } + + $result = db_query($link, "SELECT count(ttrss_entries.id) as c_id FROM ttrss_entries,ttrss_user_entries,ttrss_feeds WHERE unread = true AND + ttrss_user_entries.feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND - owner_uid = " . $_SESSION["uid"]); + hidden = false AND + ttrss_user_entries.owner_uid = '$user_id'"); $c_id = db_fetch_result($result, 0, "c_id"); return $c_id; } @@ -1540,7 +1698,17 @@ if ($global_unread == -1) { $global_unread = getGlobalUnread($link); } - print ""; + print ""; + + $result = db_query($link, "SELECT COUNT(id) AS fn FROM + ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); + + $subscribed_feeds = db_fetch_result($result, 0, "fn"); + + print ""; + } function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) { @@ -1567,7 +1735,7 @@ $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) FROM ttrss_user_entries WHERE int_id = post_int_id AND unread = true)) AS count FROM ttrss_tags - WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name"); + WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name ORDER BY tag_name"); $tags = array(); @@ -1607,9 +1775,10 @@ $old_counters = $_SESSION["lctr_last_value"]; $lctrs_modified = false; - $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries + $result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_entries,ttrss_user_entries,ttrss_feeds WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND - unread = true AND owner_uid = ".$_SESSION["uid"]); + ttrss_user_entries.feed_id = ttrss_feeds.id AND + unread = true AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); $count = db_fetch_result($result, 0, "count"); @@ -1631,10 +1800,12 @@ error_reporting (0); - $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries + $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds WHERE (" . $line["sql_exp"] . ") AND unread = true AND + ttrss_feeds.hidden = false AND + ttrss_user_entries.feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND - owner_uid = ".$_SESSION["uid"]); + ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); $count = db_fetch_result($tmp_result, 0, "count"); @@ -1778,7 +1949,11 @@ } function subscribe_to_feed($link, $feed_link, $cat_id = 0) { - + + $feed_link = trim(preg_replace("/^feed:/", "", $feed_link)); + + if ($feed_link == "") return; + if ($cat_id == "0" || !$cat_id) { $cat_qpart = "NULL"; } else { @@ -1846,7 +2021,7 @@ print "