]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
rework login process, drop http auth
[tt-rss.git] / backend.php
index ac984705311606b93251b4faec07f76fb2070fbe..b4eeaf5e0dcace95a6bb4a88715a386c8bbe0f8f 100644 (file)
@@ -1,7 +1,10 @@
 <?php
        require_once "sessions.php";
+       require_once "modules/backend-rpc.php";
        
        header("Cache-Control: no-cache, must-revalidate");
+       header("Cache-Control: no-cache, must-revalidate");
+
        header("Pragma: no-cache");
        header("Expires: -1");
        
@@ -15,7 +18,7 @@
 
        $op = $_REQUEST["op"];
 
-       define('SCHEMA_VERSION', 11);
+       define('SCHEMA_VERSION', 13);
 
        require_once "sanity_check.php";
        require_once "config.php";
        require_once "db-prefs.php";
        require_once "functions.php";
 
-       $print_exec_time = true;
+       $print_exec_time = false;
 
        if ((!$op || $op == "rpc" || $op == "rss" || $op == "digestSend" ||
                        $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
-               header("Content-Type: application/xml");
+               header("Content-Type: application/xml; charset=utf-8");
+       } else {
+               header("Content-Type: text/html; charset=utf-8");
        }
 
        if (!$op) {
@@ -46,9 +51,9 @@
                                <p>Error: Not logged in.</p>
                                <script type=\"text/javascript\">
                                        if (parent.window != 'undefined') {
-                                               parent.window.location = \"login.php\";         
+                                               parent.window.location = \"tt-rss.php\";                
                                        } else {
-                                               window.location = \"login.php\";
+                                               window.location = \"tt-rss.php\";
                                        }
                                </script>
                        </body></html>
        }
 
        $purge_intervals = array(
-               0  => "Use default",
-               -1 => "Never purge",
-               5  => "1 week old",
-               14 => "2 weeks old",
-               31 => "1 month old",
-               60 => "2 months old",
-               90 => "3 months old");
+               0  => _("Use default"),
+               -1 => _("Never purge"),
+               5  => _("1 week old"),
+               14 => _("2 weeks old"),
+               31 => _("1 month old"),
+               60 => _("2 months old"),
+               90 => _("3 months old"));
 
        $update_intervals = array(
-               0   => "Use default",
-               -1  => "Disable updates",
-               30  => "Each 30 minutes",
-               60  => "Hourly",
-               240 => "Each 4 hours",
-               720 => "Each 12 hours",
-               1440 => "Daily",
-               10080 => "Weekly");
+               0   => _("Use default"),
+               -1  => _("Disable updates"),
+               30  => _("Each 30 minutes"),
+               60  => _("Hourly"),
+               240 => _("Each 4 hours"),
+               720 => _("Each 12 hours"),
+               1440 => _("Daily"),
+               10080 => _("Weekly"));
+
 
        $access_level_names = array(
-               0 => "User"
-               10 => "Administrator");
+               0 => _("User")
+               10 => _("Administrator"));
 
+       require_once "modules/pref-prefs.php";
        require_once "modules/popup-dialog.php";
        require_once "modules/help.php";
        require_once "modules/pref-feeds.php";
        require_once "modules/pref-filters.php";
        require_once "modules/pref-labels.php";
        require_once "modules/pref-users.php";
-       require_once "modules/pref-prefs.php";
-       require_once "modules/backend-rpc.php";
+       require_once "modules/pref-feed-browser.php"; 
 
        $script_started = getmicrotime();
 
        }
 
        if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'utf-8'");
+               pg_query("set client_encoding = 'UTF-8'");
+               pg_set_client_encoding("UNICODE");
        }
 
        if (!sanity_check($link)) { return; }
 
                $result = db_query($link, "UPDATE ttrss_user_entries 
                        SET unread = false,last_read = NOW() 
-                       WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
+                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
 
                $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
                        SUBSTRING(updated,1,16) as updated,
 
                        print "<div class=\"postReply\">";
 
-                       print "<div class=\"postHeader\"><table width=\"100%\">";
+                       print "<div class=\"postHeader\">";
 
                        $entry_author = $line["author"];
 
                        if ($entry_author) {
-                               $entry_author = " - by $entry_author";
-                       }
-
-                       if ($line["link"]) {
-                               print "<tr><td width='70%'><a $link_target href=\"" . $line["link"] . "\">" . 
-                                       $line["title"] . "</a>$entry_author</td>";
-                       } else {
-                               print "<tr><td width='30%'>" . $line["title"] . "$entry_author</td>";
+                               $entry_author = _(" - by ") . $entry_author;
                        }
 
                        $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), 
                                strtotime($line["updated"]));
                
-                       print "<td class=\"postDate$rtl_class\">$parsed_updated</td>";
-                                               
-                       print "</tr>";
+                       print "<div class=\"postDate$rtl_class\">$parsed_updated</div>";
+
+                       if ($line["link"]) {
+                               print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" . 
+                                       $line["title"] . "</a>$entry_author</div>";
+                       } else {
+                               print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
+                       }
 
                        $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
                                ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
                        while ($tmp_line = db_fetch_assoc($tmp_result)) {
                                $num_tags++;
                                $tag = $tmp_line["tag_name"];                           
-                               $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, "; 
+                               $tag_str = "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, "; 
                                
-                               if ($num_tags == 5) {
+                               if ($num_tags == 6) {
                                        $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
-                               } else if ($num_tags < 5) {
+                               } else if ($num_tags < 6) {
                                        $tags_str .= $tag_str;
                                }
                                $f_tags_str .= $tag_str;
                        $tags_str = preg_replace("/, $/", "", $tags_str);
                        $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
 
-//                     $truncated_link = truncate_string($line["link"], 60);
+                       if (!$entry_comments) $entry_comments = "&nbsp;"; # placeholder
 
-                       if ($tags_str || $entry_comments) {
-                               print "<tr><td width='50%'>
-                                       $entry_comments</td>
-                                       <td align=\"right\">$tags_str</td></tr>";
-                       }
+                       if (!$tags_str) $tags_str = '<span class="tagList">'._('no tags').'</span>';
+
+                       print "<div style='float : right'>$tags_str 
+                               <a title=\"Edit tags for this article\" 
+                                       href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div>
+                               <div clear='both'>$entry_comments</div>";
 
-                       print "</table></div>";
+                       print "</div>";
 
                        print "<div class=\"postIcon\">" . $feed_icon . "</div>";
                        print "<div class=\"postContent\">";
                        
-                       if (db_num_rows($tmp_result) > 5) {
-                               print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
+                       if (db_num_rows($tmp_result) > 0) {
+                               print "<div id=\"allEntryTags\">"._('Tags:')."$f_tags_str</div>";
                        }
 
                        if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
                $limit = db_escape_string($_GET["limit"]);
                $cat_view = db_escape_string($_GET["cat"]);
                $next_unread_feed = db_escape_string($_GET["nuf"]);
+               $offset = db_escape_string($_GET["skip"]);
+
+               if (!$offset) $offset = 0;
 
                if ($subop == "undefined") $subop = "";
 
                                "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
                
                        if (db_num_rows($result) == 0) {
-                               print "<div align='center'>
-                                       Feed not found.</div>";
+                               print "<div align='center'>"._('Feed not found.')."</div>";
                                return;
                        }
                }
                        $match_on = "both";
                }
 
-               $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on);
+               $real_offset = $offset * $limit;
+
+               $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, 
+                       $search, $search_mode, $match_on, false, $real_offset);
 
                $result = $qfh_ret[0];
                $feed_title = $qfh_ret[1];
                print "<div id=\"headlinesContainer\" $rtl_tag>";
 
                if (!$result) {
-                       print "<div align='center'>
-                               Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
+                       print "<div align='center'>"._("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
                        return;
                }
-       
-               if (db_num_rows($result) > 0) {
 
-                       print_headline_subtoolbar($link, $feed_site_url, $feed_title, false, 
-                               $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode);
+               print_headline_subtoolbar($link, $feed_site_url, $feed_title, false, 
+                       $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode, 
+                       $offset, $limit);
+
+               print "<div id=\"headlinesInnerContainer\">";
 
-                       print "<div id=\"headlinesInnerContainer\">";
+               if (db_num_rows($result) > 0) {
+
+#                      print "\{$offset}";
 
                        if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
                                print "<table class=\"headlinesList\" id=\"headlinesList\" 
        
                                if ($line["marked"] == "t" || $line["marked"] == "1") {
                                        $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" 
+                                               class=\"markedPic\"
                                                alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
                                } else {
                                        $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" 
+                                               class=\"markedPic\"
                                                alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
                                }
 
                                                100);
                                }
 
+                               $entry_author = $line["author"];
+
+                               if ($entry_author) {
+                                       $entry_author = " - by $entry_author";
+                               }
+
                                if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
                                        
                                        print "<tr class='$class' id='RROW-$id'>";
                                                </td>";
                
                                        print "<td class='hlMarkedPic'>$marked_pic</td>";
-               
+
                                        if ($line["feed_title"]) {                      
                                                print "<td class='hlContent'>$content_link</td>";
                                                print "<td class='hlFeed'>
-                                                       <a href='javascript:viewfeed($feed_id)'>".
+                                                       <a href=\"javascript:viewfeed($feed_id, '', false)\">".
                                                                $line["feed_title"]."</a>&nbsp;</td>";
                                        } else {                        
                                                print "<td class='hlContent' valign='middle'>";
                                                print "<a href=\"javascript:view($id,$feed_id);\">" .
                                                        $line["title"];
 
-                                               if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
+                                               if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
                                                        if ($content_preview) {
                                                                print "<span class=\"contentPreview\"> - $content_preview</span>";
                                                        }
 
                                        print "<div class=\"cdmHeader\">";
 
-                                       print "<div style=\"float : right\">$updated_fmt,
-                                               <a class=\"cdmToggleLink\"
-                                                       href=\"javascript:toggleUnread($id)\">Toggle unread</a>
-                                       </div>";
+                                       print "<div class=\"articleUpdated\">$updated_fmt</div>";
                                        
                                        print "<a class=\"title\" 
                                                onclick=\"javascript:toggleUnread($id, 0)\"
                                                target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
 
+                                       print $entry_author;
+
                                        if ($line["feed_title"]) {      
                                                print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
                                        }
 
                                        print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
 
-                                       print "<div style=\"float : right\">$marked_pic</div>
-                                               <div lass=\"cdmFooter\">
-                                                       <input type=\"checkbox\" onclick=\"toggleSelectRowById(this, 
-                                                       'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
+                                       print "<div class=\"cdmFooter\">";
+
+                                       print "$marked_pic";
+
+                                       print "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this, 
+                                                       'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">";
+
+                                       $tags = get_article_tags($link, $id);
+
+                                       $tags_str = "";
+
+                                       foreach ($tags as $tag) {
+                                               $num_tags++;
+                                               $tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, "; 
+                                       }
+
+                                       $tags_str = preg_replace("/, $/", "", $tags_str);
+
+                                       if ($tags_str == "") $tags_str = "no tags";
+       
+                                       print " $tags_str <a title=\"Edit tags for this article\" 
+                                                       href=\"javascript:editArticleTags($id, $feed_id, true)\">(+)</a>";
+
+                                       print "</div>";
 
 #                                      print "<div align=\"center\"><a class=\"cdmToggleLink\"
 #                                                      href=\"javascript:toggleUnread($id)\">
                                print "</table>";
                        }
 
-                       print "</div>";
-
 //                     print_headline_subtoolbar($link, 
 //                             "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
 
 
                } else {
-                       print "<div class='whiteBox'>No articles found.</div>";
+                       print "<div class='whiteBox'>"._('No articles found.')."</div>";
                }
 
                print "</div>";
+
+               print "</div>";
        }
 
        if ($op == "pref-feeds") {
                module_pref_labels($link);
        }
 
-       if ($op == "error") {
-               print "<div width=\"100%\" align='center'>";
-               $msg = $_GET["msg"];
-               print $msg;
-               print "</div>";
+       if ($op == "pref-prefs") {
+               module_pref_prefs($link);
+       }
+
+       if ($op == "pref-users") {
+               module_pref_users($link);
        }
 
        if ($op == "help") {
 
        }
 
-       if ($op == "pref-prefs") {
-               module_pref_prefs($link);
-       }
-
-       if ($op == "pref-users") {
-               module_pref_users($link);
-       }
-
        if ($op == "user-details") {
 
                if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
        }
 
        if ($op == "pref-feed-browser") {
-
-               if (!ENABLE_FEED_BROWSER) {
-                       print "Feed browser is administratively disabled.";
-                       return;
-               }
-
-               $subop = $_REQUEST["subop"];
-
-               if ($subop == "details") {
-                       $id = db_escape_string($_GET["id"]);
-
-                       print "<div class=\"browserFeedInfo\">";
-                       print "<b>Feed information:</b>";
-                       print "<div class=\"detailsPart\">";
-
-                       $result = db_query($link, "SELECT 
-                                       feed_url,site_url,
-                                       SUBSTRING(last_updated,1,19) AS last_updated
-                               FROM ttrss_feeds WHERE id = '$id'");
-
-                       $feed_url = db_fetch_result($result, 0, "feed_url");
-                       $site_url = db_fetch_result($result, 0, "site_url");
-                       $last_updated = db_fetch_result($result, 0, "last_updated");
-
-                       if (get_pref($link, 'HEADLINES_SMART_DATE')) {
-                               $last_updated = smart_date_time(strtotime($last_updated));
-                       } else {
-                               $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
-                               $last_updated = date($short_date, strtotime($last_updated));
-                       }
-
-                       print "Site: <a target=\"_new\" href='$site_url'>$site_url</a> ".
-                               "(<a target=\"_new\" href='$feed_url'>feed</a>), ".
-                               "Last updated: $last_updated";
-
-                       print "</div>";
-
-                       $result = db_query($link, "SELECT 
-                                       ttrss_entries.title,
-                                       content,link,
-                                       substring(date_entered,1,19) as date_entered,
-                                       substring(updated,1,19) as updated
-                               FROM ttrss_entries,ttrss_user_entries
-                               WHERE   ttrss_entries.id = ref_id AND feed_id = '$id' 
-                               ORDER BY updated DESC LIMIT 5");
-
-                       if (db_num_rows($result) > 0) {
-                               
-                               print "<b>Last headlines:</b><br>";
-                               
-                               print "<div class=\"detailsPart\">";
-                               print "<ul class=\"compact\">";
-                               while ($line = db_fetch_assoc($result)) {
-
-                                       if (get_pref($link, 'HEADLINES_SMART_DATE')) {
-                                               $entry_dt = smart_date_time(strtotime($line["updated"]));
-                                       } else {
-                                               $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
-                                               $entry_dt = date($short_date, strtotime($line["updated"]));
-                                       }                               
-               
-                                       print "<li><a target=\"_new\" href=\"" . $line["link"] . "\">" . $line["title"] . "</a>" .
-                                               "&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";    
-                               }               
-                               print "</ul></div>";
-                       }
-
-                       print "</div>";
-                               
-                       return;
-               }
-
-               print "<p>This panel shows feeds subscribed by other users of this system, just in case you are interested in some of them too.</p>";
-
-               $limit = db_escape_string($_GET["limit"]);
-
-               if (!$limit) $limit = 25;
-
-               $owner_uid = $_SESSION["uid"];
-                       
-               $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
-                       FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf 
-                               WHERE tf.feed_url = ttrss_feeds.feed_url 
-                                       AND owner_uid = '$owner_uid') GROUP BY feed_url 
-                                               ORDER BY subscribers DESC LIMIT $limit");
-
-                       
-               print "<div style=\"float : right\">
-                       Top <select id=\"feedBrowserLimit\">";
-
-               foreach (array(25, 50, 100) as $l) {
-                       $issel = ($l == $limit) ? "selected" : "";
-                       print "<option $issel>$l</option>";
-               }
-                       
-               print "</select>
-                       <input type=\"submit\" class=\"button\"
-                               onclick=\"updateBigFeedBrowser()\" value=\"Show\">
-               </div>";
-
-               print "<p id=\"fbrOpToolbar\">Selection: 
-                       <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\" 
-                       disabled=\"true\" value=\"Subscribe\">";
-
-               print "<ul class='nomarks' id='browseBigFeedList'>";
-
-               $feedctr = 0;
-               
-               while ($line = db_fetch_assoc($result)) {
-                       $feed_url = $line["feed_url"];
-                       $subscribers = $line["subscribers"];
-               
-                       $det_result = db_query($link, "SELECT site_url,title,id 
-                               FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
-
-                       $details = db_fetch_assoc($det_result);
-               
-                       $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
-
-                       if (file_exists($icon_file) && filesize($icon_file) > 0) {
-                                       $feed_icon = "<img class=\"tinyFeedIcon\"       src=\"" . ICONS_URL . 
-                                               "/".$details["id"].".ico\">";
-                       } else {
-                               $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
-                       }
-
-                       $check_box = "<input onclick='toggleSelectFBListRow(this)' class='feedBrowseCB' 
-                               type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
-
-                       $class = ($feedctr % 2) ? "even" : "odd";
-
-                       print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
-                               "$feed_icon ";
-                               
-                       print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" . 
-                               $details["title"] ."</a>&nbsp;" .
-                               "<span class='subscribers'>($subscribers)</span>";
-                       
-                       print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
-                       print "</div>";
-                               
-                       print "</li>";
-
-                               ++$feedctr;
-               }
-
-               if ($feedctr == 0) {
-                       print "<li>No feeds found to subscribe.</li>";
-               }
-
-               print "</ul>";
-
-               print "</div>";
-
+               module_pref_feed_browser($link);
        }
 
        if ($op == "rss") {