]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
UI improvements
[tt-rss.git] / backend.php
index ee8b089d1df990bd40db176f6d25832b59b0293b..1a53d1c68d5abdc5f32d6076b7245de29653d555 100644 (file)
@@ -1,11 +1,8 @@
 <?php
        require_once "sessions.php";
        require_once "modules/backend-rpc.php";
-       
-       header("Cache-Control: no-cache, must-revalidate");
-       header("Pragma: no-cache");
-       header("Expires: -1");
-       
+
+
 /*     if ($_GET["debug"]) {
                define('DEFAULT_ERROR_LEVEL', E_ALL);
        } else {
@@ -14,9 +11,7 @@
        
        error_reporting(DEFAULT_ERROR_LEVEL); */
 
-       $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";
 
+       no_cache_incantation();
+
+       $script_started = getmicrotime();
+
+       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
+
+       if (!$link) {
+               if (DB_TYPE == "mysql") {
+                       print mysql_error();
+               }
+               // PG seems to display its own errors just fine by default.             
+               return;
+       }
+
+       if (DB_TYPE == "pgsql") {
+               pg_query("set client_encoding = 'UTF-8'");
+               pg_set_client_encoding("UNICODE");
+       }
+
+       $op = $_REQUEST["op"];
+
        $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) {
                header("Content-Type: application/xml");
                print_error_xml(7); exit;
        }
-
-       if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss" && $op != "getUnread") {
+       
+       if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" 
+                       && $op != "rss" && $op != "getUnread") {
 
                if ($op == "rpc") {
                        print_error_xml(6); die;
@@ -47,9 +66,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/pref-users.php";
        require_once "modules/pref-feed-browser.php"; 
 
-       $script_started = getmicrotime();
-
-       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
-
-       if (!$link) {
-               if (DB_TYPE == "mysql") {
-                       print mysql_error();
-               }
-               // PG seems to display its own errors just fine by default.             
-               return;
-       }
-
-       if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'utf-8'");
-       }
 
        if (!sanity_check($link)) { return; }
 
 
                        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 "</table></div>";
+                       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 "</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)'>";
                                }
 
                                                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)\"
 
                                        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") {