X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=classes%2Ffeeds.php;h=49adf38795b8381d0182ab43d08e383a051971f7;hb=87764a50cf08f33008a0f83d91b4d807643db67c;hp=2e9aea6861e7220ded425401b72943e6ddb37add;hpb=f10808259c286cb4ebc6318a71eee470066fc6ef;p=tt-rss.git diff --git a/classes/feeds.php b/classes/feeds.php index 2e9aea68..49adf387 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -1,47 +1,24 @@ 0) { - $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true); - } else if ($cat_id == 0 || $cat_id == -2) { - $cat_unread = getCategoryUnread($this->link, $cat_id); - } - - $obj['id'] = 'CAT:' . $cat_id; - $obj['items'] = array(); - $obj['name'] = getCategoryTitle($this->link, $cat_id); - $obj['type'] = 'feed'; - $obj['unread'] = (int) $cat_unread; - $obj['hidden'] = $hidden; - $obj['bare_id'] = $cat_id; + function csrf_ignore($method) { + $csrf_ignored = array("index"); - return $obj; + return array_search($method, $csrf_ignored) !== false; } - private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { - $obj = array(); - $feed_id = (int) $feed_id; - - if (!$title) - $title = getFeedTitle($this->link, $feed_id, false); - - if ($unread === false) - $unread = getFeedUnread($this->link, $feed_id, false); + private function make_gradient($end, $class) { + $start = $class == "even" ? "#f0f0f0" : "#ffffff"; - $obj['id'] = 'FEED:' . $feed_id; - $obj['name'] = $title; - $obj['unread'] = (int) $unread; - $obj['type'] = 'feed'; - $obj['error'] = $error; - $obj['updated'] = $updated; - $obj['icon'] = getFeedIcon($feed_id); - $obj['bare_id'] = $feed_id; - - return $obj; + return "style='background: linear-gradient(left , $start 6%, $end 100%); + background: -o-linear-gradient(left , $start 6%, $end 100%); + background: -moz-linear-gradient(left , $start 6%, $end 100%); + background: -webkit-linear-gradient(left , $start 6%, $end 100%); + background: -ms-linear-gradient(left , $start 6%, $end 100%); + background: -webkit-gradient(linear, left top, right top, + color-stop(0.06, $start), color-stop(1, $end));'"; } private function format_headline_subtoolbar($feed_site_url, $feed_title, @@ -68,6 +45,8 @@ class Feeds extends Protected_Handler { $tog_marked_link = "selectionToggleMarked()"; $tog_published_link = "selectionTogglePublished()"; + $set_score_link = "setSelectionScore()"; + if ($is_cat) $cat_q = "&is_cat=$is_cat"; if ($search) { @@ -82,6 +61,7 @@ class Feeds extends Protected_Handler { // right part $reply .= ""; + $reply .= ""; if ($feed_site_url) { $target = "target=\"_blank\""; @@ -96,6 +76,8 @@ class Feeds extends Protected_Handler { $reply .= $feed_title; } + $reply .= ""; + $reply .= " ".__('Selection:').""; $reply .= ""; + $reply .= ""; if ($feed_id != "0") { $reply .= ""; @@ -156,7 +139,7 @@ class Feeds extends Protected_Handler { private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgr_last_feed = false, - $override_order = false) { + $override_order = false, $include_children = false) { $disable_cache = false; @@ -171,25 +154,26 @@ class Feeds extends Protected_Handler { $method_split = explode(":", $method); -/* if ($method == "CatchupSelected") { - $ids = explode(",", db_escape_string($_REQUEST["ids"])); - $cmode = sprintf("%d", $_REQUEST["cmode"]); + if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) { + // Update the feed if required with some basic flood control - catchupArticlesById($this->link, $ids, $cmode); - } */ - - //if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) { - // update_rss_feed($this->link, $feed, true); - //} + $result = db_query($this->link, + "SELECT cache_images,cache_content,".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated + FROM ttrss_feeds WHERE id = '$feed'"); - if ($method == "MarkAllRead") { - catchup_feed($this->link, $feed, $cat_view); + if (db_num_rows($result) != 0) { + $last_updated = strtotime(db_fetch_result($result, 0, "last_updated")); + $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); + $cache_content = sql_bool_to_bool(db_fetch_result($result, 0, "cache_content")); - if (get_pref($this->link, 'ON_CATCHUP_SHOW_NEXT_FEED')) { - if ($next_unread_feed) { - $feed = $next_unread_feed; + if (!$cache_images && !$cache_content && time() - $last_updated > 120 || isset($_REQUEST['DevForceUpdate'])) { + include "rssfuncs.php"; + update_rss_feed($this->link, $feed, true, true); + } else { + db_query($this->link, "UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01' + WHERE id = '$feed'"); + } } - } } if ($method_split[0] == "MarkAllReadGR") { @@ -207,7 +191,7 @@ class Feeds extends Protected_Handler { } } - if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { + if (is_numeric($feed) && $feed > 0) { $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); @@ -235,11 +219,7 @@ class Feeds extends Protected_Handler { } @$search_mode = db_escape_string($_REQUEST["search_mode"]); - @$match_on = db_escape_string($_REQUEST["match_on"]); - - if (!$match_on) { - $match_on = "both"; - } + $match_on = "both"; // deprecated, TODO: remove if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info); @@ -249,7 +229,8 @@ class Feeds extends Protected_Handler { } // error_log("search_mode: " . $search_mode); $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view, - $search, $search_mode, $match_on, $override_order, $offset); + $search, $search_mode, $match_on, $override_order, $offset, 0, + false, 0, $include_children); if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info); @@ -257,21 +238,29 @@ class Feeds extends Protected_Handler { $feed_title = $qfh_ret[1]; $feed_site_url = $qfh_ret[2]; $last_error = $qfh_ret[3]; + $cache_content = true; $vgroup_last_feed = $vgr_last_feed; -// if (!$offset) { - - if (db_num_rows($result) > 0) { - $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, - $feed_title, - $feed, $cat_view, $search, $match_on, $search_mode, $view_mode, - $last_error); - } -// } + $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, + $feed_title, + $feed, $cat_view, $search, $match_on, $search_mode, $view_mode, + $last_error); $headlines_count = db_num_rows($result); + if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) { + $button_plugins = array(); + foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) { + $pclass = "button_" . trim($p); + + if (class_exists($pclass)) { + $plugin = new $pclass($link); + array_push($button_plugins, $plugin); + } + } + } + if (db_num_rows($result) > 0) { $lnum = $offset; @@ -284,13 +273,13 @@ class Feeds extends Protected_Handler { if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info); while ($line = db_fetch_assoc($result)) { - $class = ($lnum % 2) ? "even" : "odd"; $id = $line["id"]; $feed_id = $line["feed_id"]; $label_cache = $line["label_cache"]; $labels = false; + $label_row_style = ""; if ($label_cache) { $label_cache = json_decode($label_cache, true); @@ -305,6 +294,22 @@ class Feeds extends Protected_Handler { if (!is_array($labels)) $labels = get_article_labels($this->link, $id); + if (count($labels) > 0) { + for ($i = 0; $i < min(4, count($labels)); $i++) { + $bg = rgb2hsl(_color_unpack($labels[$i][3])); + + if ($bg && $bg[1] > 0) { + $bg[1] = 0.1; + $bg[2] = 1; + + $bg = _color_pack(hsl2rgb($bg)); + $label_row_style = $this->make_gradient($bg, $class);; + + break; + } + } + } + $labels_str = ""; $labels_str .= format_article_labels($labels, $id); $labels_str .= ""; @@ -389,7 +394,7 @@ class Feeds extends Protected_Handler { $score_pic = ""; */ - $score_pic = ""; if ($score > 500) { @@ -424,7 +429,7 @@ class Feeds extends Protected_Handler { $cur_feed_title = htmlspecialchars($cur_feed_title); - $vf_catchup_link = "(".__('mark as read').")"; + $vf_catchup_link = "(".__('mark as read').")"; $reply['content'] .= "
". "
$feed_icon_img
". @@ -437,7 +442,7 @@ class Feeds extends Protected_Handler { $mouseover_attrs = "onmouseover='postMouseIn($id)' onmouseout='postMouseOut($id)'"; - $reply['content'] .= "
"; + $reply['content'] .= "
"; $reply['content'] .= "
$update_pic
"; @@ -528,7 +533,7 @@ class Feeds extends Protected_Handler { $mouseover_attrs = "onmouseover='postMouseIn($id)' onmouseout='postMouseOut($id)'"; - $reply['content'] .= "
"; $reply['content'] .= "
"; @@ -543,6 +548,9 @@ class Feeds extends Protected_Handler { $reply['content'] .= "
"; + $reply['content'] .= "
" . + htmlspecialchars(strip_tags($line['title'])) . "
"; + $reply['content'] .= " @@ -550,7 +558,7 @@ class Feeds extends Protected_Handler { title=\"".htmlspecialchars($line['title'])."\" target=\"_blank\" href=\"". htmlspecialchars($line["link"])."\">". - truncate_string($line["title"], 100) . + $line["title"] . " $entry_author"; $reply['content'] .= $labels_str; @@ -616,7 +624,7 @@ class Feeds extends Protected_Handler { $reply['content'] .= " "; $reply['content'] .= ""; - $reply['content'] .= ""; + $reply['content'] .= ""; $reply['content'] .= "
"; } @@ -624,6 +632,10 @@ class Feeds extends Protected_Handler { $feed_site_url = $line["site_url"]; + if ($cache_content && $line["cached_content"] != "") { + $line["content_preview"] =& $line["cached_content"]; + } + $article_content = sanitize($this->link, $line["content_preview"], false, false, $feed_site_url); @@ -634,7 +646,7 @@ class Feeds extends Protected_Handler { $reply['content'] .= "
"; $reply['content'] .= ""; - $reply['content'] .= $expand_cdm ? $article_content : ''; + $reply['content'] .= $article_content; $reply['content'] .= ""; /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM @@ -671,14 +683,14 @@ class Feeds extends Protected_Handler { if ($num_comments > 0) { if ($line["comments"]) { - $comments_url = $line["comments"]; + $comments_url = htmlspecialchars($line["comments"]); } else { - $comments_url = $line["link"]; + $comments_url = htmlspecialchars($line["link"]); } $entry_comments = "$num_comments comments"; } else { if ($line["comments"] && $line["link"] != $line["comments"]) { - $entry_comments = "comments"; + $entry_comments = "comments"; } } @@ -694,32 +706,14 @@ class Feeds extends Protected_Handler { //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); - $reply['content'] .= "PubNote"; - - $reply['content'] .= "link, 'images/art-email.png')."\" - style=\"cursor : pointer\" - onclick=\"emailArticle($id)\" - alt='Zoom' title='".__('Forward by email')."'>"; - - if (ENABLE_TWEET_BUTTON) { - $reply['content'] .= "link, 'images/art-tweet.png')."\" - class='tagsPic' style=\"cursor : pointer\" - onclick=\"tweetArticle($id)\" - alt='Zoom' title='".__('Share on Twitter')."'>"; + foreach ($button_plugins as $p) { + $reply['content'] .= $p->render($id, $line); } - $reply['content'] .= "link, 'images/art-share.png')."\" - class='tagsPic' style=\"cursor : pointer\" - onclick=\"shareArticle(".$line['int_id'].")\" - alt='Zoom' title='".__('Share by URL')."'>"; - $reply['content'] .= "Dismiss"; + title='".__('Close article')."'>"; $reply['content'] .= "
"; $reply['content'] .= "
"; @@ -789,171 +783,6 @@ class Feeds extends Protected_Handler { $vgroup_last_feed, $reply); } - private function outputFeedList($special = true) { - - $feedlist = array(); - - $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS'); - - $feedlist['identifier'] = 'id'; - $feedlist['label'] = 'name'; - $feedlist['items'] = array(); - - $owner_uid = $_SESSION["uid"]; - - /* virtual feeds */ - - if ($special) { - - if ($enable_cats) { - $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL"); - $cat = $this->feedlist_init_cat(-1, $cat_hidden); - } else { - $cat['items'] = array(); - } - - foreach (array(-4, -3, -1, -2, 0) as $i) { - array_push($cat['items'], $this->feedlist_init_feed($i)); - } - - if ($enable_cats) { - array_push($feedlist['items'], $cat); - } else { - $feedlist['items'] = array_merge($feedlist['items'], $cat['items']); - } - - $result = db_query($this->link, "SELECT * FROM - ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption"); - - if (db_num_rows($result) > 0) { - - if (get_pref($this->link, 'ENABLE_FEED_CATS')) { - $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS"); - $cat = $this->feedlist_init_cat(-2, $cat_hidden); - } else { - $cat['items'] = array(); - } - - while ($line = db_fetch_assoc($result)) { - - $label_id = -$line['id'] - 11; - $count = getFeedUnread($this->link, $label_id); - - $feed = $this->feedlist_init_feed($label_id, false, $count); - - $feed['fg_color'] = $line['fg_color']; - $feed['bg_color'] = $line['bg_color']; - - array_push($cat['items'], $feed); - } - - if ($enable_cats) { - array_push($feedlist['items'], $cat); - } else { - $feedlist['items'] = array_merge($feedlist['items'], $cat['items']); - } - } - } - -/* if (get_pref($this->link, 'ENABLE_FEED_CATS')) { - if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) { - $order_by_qpart = "order_id,category,unread DESC,title"; - } else { - $order_by_qpart = "order_id,category,title"; - } - } else { - if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) { - $order_by_qpart = "unread DESC,title"; - } else { - $order_by_qpart = "title"; - } - } */ - - /* real feeds */ - - if ($enable_cats) - $order_by_qpart = "ttrss_feed_categories.order_id,category, - ttrss_feeds.order_id,title"; - else - $order_by_qpart = "title"; - - $age_qpart = getMaxAgeSubquery(); - - $query = "SELECT ttrss_feeds.id, ttrss_feeds.title, - ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms, - cat_id,last_error, - ttrss_feed_categories.title AS category, - ttrss_feed_categories.collapsed, - value AS unread - FROM ttrss_feeds LEFT JOIN ttrss_feed_categories - ON (ttrss_feed_categories.id = cat_id) - LEFT JOIN ttrss_counters_cache - ON - (ttrss_feeds.id = feed_id) - WHERE - ttrss_feeds.owner_uid = '$owner_uid' - ORDER BY $order_by_qpart"; - - $result = db_query($this->link, $query); - - $actid = $_REQUEST["actid"]; - - if (db_num_rows($result) > 0) { - - $category = ""; - - if (!$enable_cats) - $cat['items'] = array(); - else - $cat = false; - - while ($line = db_fetch_assoc($result)) { - - $feed = htmlspecialchars(trim($line["title"])); - - if (!$feed) $feed = "[Untitled]"; - - $feed_id = $line["id"]; - $unread = $line["unread"]; - - $cat_id = $line["cat_id"]; - $tmp_category = $line["category"]; - if (!$tmp_category) $tmp_category = __("Uncategorized"); - - if ($category != $tmp_category && $enable_cats) { - - $category = $tmp_category; - - $collapsed = sql_bool_to_bool($line["collapsed"]); - - // workaround for NULL category - if ($category == __("Uncategorized")) { - $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT"); - } - - if ($cat) array_push($feedlist['items'], $cat); - - $cat = $this->feedlist_init_cat($cat_id, $collapsed); - } - - $updated = make_local_datetime($this->link, $line["updated_noms"], false); - - array_push($cat['items'], $this->feedlist_init_feed($feed_id, - $feed, $unread, $line['last_error'], $updated)); - } - - if ($enable_cats) { - array_push($feedlist['items'], $cat); - } else { - $feedlist['items'] = array_merge($feedlist['items'], $cat['items']); - } - - } - - return $feedlist; - } - - function catchupAll() { db_query($this->link, "UPDATE ttrss_user_entries SET last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); @@ -966,29 +795,6 @@ class Feeds extends Protected_Handler { toggle_collapse_cat($this->link, $cat_id, $mode); } - function index() { - $root = (bool)$_REQUEST["root"]; - - if (!$root) { - print json_encode($this->outputFeedList($this->link)); - } else { - - $feeds = $this->outputFeedList($this->link, false); - - $root = array(); - $root['id'] = 'root'; - $root['name'] = __('Feeds'); - $root['items'] = $feeds['items']; - - $fl = array(); - $fl['identifier'] = 'id'; - $fl['label'] = 'name'; - $fl['items'] = array($root); - - print json_encode($fl); - } - } - function view() { $timing_info = getmicrotime(); @@ -1002,7 +808,7 @@ class Feeds extends Protected_Handler { $method = db_escape_string($_REQUEST["m"]); $view_mode = db_escape_string($_REQUEST["view_mode"]); $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT"); - @$cat_view = db_escape_string($_REQUEST["cat"]) == "true"; + @$cat_view = $_REQUEST["cat"] == "true"; @$next_unread_feed = db_escape_string($_REQUEST["nuf"]); @$offset = db_escape_string($_REQUEST["skip"]); @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]); @@ -1048,7 +854,7 @@ class Feeds extends Protected_Handler { set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit); set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by); - if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) { + if (!$cat_view && is_numeric($feed) && $feed > 0) { db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW() WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); } @@ -1100,7 +906,7 @@ class Feeds extends Protected_Handler { $ret = $this->format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, - $vgroup_last_feed, $override_order); + $vgroup_last_feed, $override_order, true); $topmost_article_ids = $ret[0]; $headlines_count = $ret[1];