]> git.wh0rd.org - tt-rss.git/blobdiff - classes/feeds.php
Merge branch 'otp' of fturco/tt-rss into master
[tt-rss.git] / classes / feeds.php
index 878306730b49bc50b7b44a05fe77ae2cebd5f45a..98507d361a7e076db3e47f06dd8ab2b4f4ce2862 100755 (executable)
@@ -202,7 +202,11 @@ class Feeds extends Handler_Protected {
                                        $cache_images = $row["cache_images"];
 
                                        if (!$cache_images && time() - $last_updated > 120) {
-                                               RSSUtils::update_rss_feed($feed, true);
+                                           try {
+                                                       RSSUtils::update_rss_feed($feed, true);
+                                               } catch (PDOException $e) {
+                                               user_error("PDO Exception while doing on-demand feed update for $feed: " . $e->getMessage(), E_USER_NOTICE);
+                        }
                                        } else {
                                                $sth = $this->pdo->prepare("UPDATE ttrss_feeds 
                                 SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
@@ -339,6 +343,8 @@ class Feeds extends Handler_Protected {
                                $label_cache = $line["label_cache"];
                                $labels = false;
 
+                               $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' onmouseout='postMouseOut($id)'";
+
                                if ($label_cache) {
                                        $label_cache = json_decode($label_cache, true);
 
@@ -367,29 +373,13 @@ class Feeds extends Handler_Protected {
                                        ++$num_unread;
                                }
 
-                               if ($line["marked"]) {
-                                       $marked_pic = "<img
-                    src=\"images/mark_set.png\"
-                    class=\"markedPic\" alt=\"Unstar article\"
-                    onclick='toggleMark($id)'>";
-                                       $class .= " marked";
-                               } else {
-                                       $marked_pic = "<img
-                    src=\"images/mark_unset.png\"
-                    class=\"markedPic\" alt=\"Star article\"
-                    onclick='toggleMark($id)'>";
-                               }
+                               $marked_pic_src = $line["marked"] ? "mark_set.png" : "mark_unset.png";
+                               $class .= $line["marked"] ? " marked" : "";
+                               $marked_pic = "<img src=\"images/$marked_pic_src\" class=\"markedPic\" onclick='toggleMark($id)'>";
 
-                               if ($line["published"]) {
-                                       $published_pic = "<img src=\"images/pub_set.png\"
-                    class=\"pubPic\"
-                        alt=\"Unpublish article\" onclick='togglePub($id)'>";
-                                       $class .= " published";
-                               } else {
-                                       $published_pic = "<img src=\"images/pub_unset.png\"
-                    class=\"pubPic\"
-                    alt=\"Publish article\" onclick='togglePub($id)'>";
-                               }
+                               $published_pic_src = $line["published"] ? "pub_set.png" : "pub_unset.png";
+                               $class .= $line["published"] ? " published" : "";
+                $published_pic = "<img src=\"images/$published_pic_src\" class=\"pubPic\" onclick='togglePub($id)'>";
 
                                $updated_fmt = make_local_datetime($line["updated"], false, false, false, true);
                                $date_entered_fmt = T_sprintf("Imported at %s",
@@ -456,9 +446,6 @@ class Feeds extends Handler_Protected {
                                                }
                                        }
 
-                                       $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
-                    onmouseout='postMouseOut($id)'";
-
                                        $reply['content'] .= "<div class='hl hlMenuAttach $class' data-orig-feed-id='$feed_id' data-article-id='$id' id='RROW-$id' $mouseover_attrs>";
 
                                        $reply['content'] .= "<div class='hlLeft'>";
@@ -551,9 +538,6 @@ class Feeds extends Handler_Protected {
                                                }
                                        }
 
-                                       $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
-                    onmouseout='postMouseOut($id)'";
-
                                        $expanded_class = $expand_cdm ? "expanded" : "expandable";
 
                                        $tmp_content = "<div class=\"cdm $hlc_suffix $expanded_class $class\"
@@ -573,7 +557,9 @@ class Feeds extends Handler_Protected {
 
                                        if ($highlight_words && count($highlight_words) > 0) {
                                                foreach ($highlight_words as $word) {
-                                                       $line["title"] = preg_replace("/(\Q$word\E)/i",
+                                                   $word = preg_quote($word, "/");
+
+                                                       $line["title"] = preg_replace("/($word)/i",
                                                                "<span class=\"highlight\">$1</span>", $line["title"]);
                                                }
                                        }
@@ -1016,6 +1002,8 @@ class Feeds extends Handler_Protected {
        }
 
        function quickAddFeed() {
+               print "<form onsubmit='return false'>";
+
                print_hidden("op", "rpc");
                print_hidden("method", "addfeed");
 
@@ -1080,10 +1068,8 @@ class Feeds extends Handler_Protected {
                                <label for=\"feedDlg_loginCheck\">".
                                __('This feed requires authentication.')."</div>";
 
-               print "</form>";
-
                print "<div class=\"dlgButtons\">
-                       <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
+                       <button dojoType=\"dijit.form.Button\" class=\"btn-primary\" type=\"submit\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
 
                if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER)) {
                        print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
@@ -1092,6 +1078,8 @@ class Feeds extends Handler_Protected {
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
                        </div>";
 
+               print "</form>";
+
                //return;
        }
 
@@ -1149,6 +1137,8 @@ class Feeds extends Handler_Protected {
                $active_feed_id = sprintf("%d", $this->params[0]);
                $is_cat = $this->params[1] != "false";
 
+               print "<form onsubmit='return false;'>";
+
                print "<div class=\"dlgSec\">".__('Look for')."</div>";
 
                print "<div class=\"dlgSecCont\">";
@@ -1175,9 +1165,11 @@ class Feeds extends Handler_Protected {
                                </div>";
                }
 
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
+               print "<button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"btn-primary\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
                <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>
                </div>";
+
+               print "</form>";
        }
 
        function update_debugger() {
@@ -1279,6 +1271,7 @@ class Feeds extends Handler_Protected {
                                        if ($feed > 0) {
                                                $children = Feeds::getChildCategories($feed, $owner_uid);
                                                array_push($children, $feed);
+                                               $children = array_map("intval", $children);
 
                                                $children = join(",", $children);
 
@@ -1445,7 +1438,7 @@ class Feeds extends Handler_Protected {
                } else if ($n_feed >= 0) {
 
                        if ($n_feed != 0) {
-                               $match_part = "feed_id = '$n_feed'";
+                               $match_part = "feed_id = " . (int)$n_feed;
                        } else {
                                $match_part = "feed_id IS NULL";
                        }
@@ -1680,7 +1673,7 @@ class Feeds extends Handler_Protected {
 
                        $cat_feeds = array();
                        while ($line = $sth->fetch()) {
-                               array_push($cat_feeds, "feed_id = " . $line["id"]);
+                               array_push($cat_feeds, "feed_id = " . (int)$line["id"]);
                        }
 
                        if (count($cat_feeds) == 0) return 0;
@@ -1895,8 +1888,9 @@ class Feeds extends Handler_Protected {
                                        if ($include_children) {
                                                # sub-cats
                                                $subcats = Feeds::getChildCategories($feed, $owner_uid);
-
                                                array_push($subcats, $feed);
+                                               $subcats = array_map("intval", $subcats);
+
                                                $query_strategy_part = "cat_id IN (".
                                                        implode(",", $subcats).")";
 
@@ -2104,9 +2098,9 @@ class Feeds extends Handler_Protected {
                                                $sanity_interval_qpart
                                                $first_id_query_strategy_part ORDER BY $order_by LIMIT 1";
 
-                               if ($_REQUEST["debug"]) {
+                               /*if ($_REQUEST["debug"]) {
                                        print $query;
-                               }
+                               }*/
 
                                $res = $pdo->query($query);
 
@@ -2152,7 +2146,7 @@ class Feeds extends Handler_Protected {
                                        $query_strategy_part ORDER BY $order_by
                                        $limit_query_part $offset_query_part";
 
-                       if ($_REQUEST["debug"]) print $query;
+                       //if ($_REQUEST["debug"]) print $query;
 
                        $res = $pdo->query($query);