]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
add multiprocess update daemon
[tt-rss.git] / backend.php
index f83b71d5e10dafc07130972f4385376061481599..ea96a0e41207ce55f326e5398f643006ecc4c02e 100644 (file)
@@ -1,6 +1,15 @@
 <?php
        error_reporting(E_ERROR | E_WARNING | E_PARSE);
 
+       /* remove ill effects of magic quotes */
+
+       if (get_magic_quotes_gpc()) {
+               $_GET = array_map('stripslashes', $_GET);
+               $_POST = array_map('stripslashes', $_POST);
+               $_REQUEST = array_map('stripslashes', $_REQUEST);
+               $_COOKIE = array_map('stripslashes', $_COOKIE);
+       }
+
        require_once "sessions.php";
        require_once "modules/backend-rpc.php";
 
        require_once "functions.php";
 
        no_cache_incantation();
-       startup_gettext();
+
+       if (ENABLE_TRANSLATIONS == true) { 
+               startup_gettext();
+       }
 
        $script_started = getmicrotime();
 
        if (DB_TYPE == "pgsql") {
                pg_query("set client_encoding = 'UTF-8'");
                pg_set_client_encoding("UNICODE");
+       } else {
+               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
+                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
+//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
+               }
        }
 
        $op = $_REQUEST["op"];
        $print_exec_time = false;
 
        if ((!$op || $op == "rpc" || $op == "rss" || $op == "view" || 
-                       $op == "digestSend" || $op == "viewfeed" ||
+                       $op == "digestSend" || $op == "viewfeed" || $op == "publish" ||
                        $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
                header("Content-Type: application/xml; charset=utf-8");
-       } else {
-               header("Content-Type: text/html; charset=utf-8");
+               } else {
+               if (!$_REQUEST["noxml"]) {
+                       header("Content-Type: text/html; charset=utf-8");
+               } else {
+                       header("Content-Type: text/plain; charset=utf-8");
+               }
        }
 
        if (!$op) {
@@ -57,9 +78,9 @@
        }
        
        if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" 
-                       && $op != "rss" && $op != "getUnread") {
+                       && $op != "rss" && $op != "getUnread" && $op != "publish") {
 
-               if ($op == "rpc") {
+               if ($op == "rpc" || $op == "viewfeed" || $op == "view") {
                        print_error_xml(6); die;
                } else {
                        print "
        $update_intervals = array(
                0   => __("Use default"),
                -1  => __("Disable updates"),
+               15  => __("Each 15 minutes"),
                30  => __("Each 30 minutes"),
                60  => __("Hourly"),
                240 => __("Each 4 hours"),
        require_once "modules/pref-users.php";
        require_once "modules/pref-feed-browser.php"; 
 
-
        if (!sanity_check($link)) { return; }
 
        if ($op == "rpc") {
 
                if ($mode == "") {
                        outputArticleXML($link, $id, $feed_id);
-               } else if ($mode == "prefetch") {
+               } else {
                        catchupArticleById($link, $id, 0);
                }
 
 
        if ($op == "viewfeed") {
 
+               $print_exec_time = true;
+               $timing_info = getmicrotime();
+
                print "<reply>";
 
+               if ($_GET["debug"]) $timing_info = print_checkpoint("0", $timing_info);
+
                $omode = db_escape_string($_GET["omode"]);
 
                $feed = db_escape_string($_GET["feed"]);
                set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
                set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
 
+               if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
+                       db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW()
+                               WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
+               }
+
                print "<headlines id=\"$feed\"><![CDATA[";
 
-               outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view,
-                       $next_unread_feed, $offset);
+               $ret = outputHeadlinesList($link, $feed, $subop, 
+                       $view_mode, $limit, $cat_view, $next_unread_feed, $offset);
+
+               $topmost_article_ids = $ret[0];
+               $headlines_count = $ret[1];
+               $returned_feed = $ret[2];
+               $disable_cache = $ret[3];
 
                print "]]></headlines>";
 
+               print "<headlines-count value=\"$headlines_count\"/>";
+
+               $headlines_unread = getFeedUnread($link, $returned_feed);
+
+               print "<headlines-unread value=\"$headlines_unread\"/>";
+               printf("<disable-cache value=\"%d\"/>", $disable_cache);
+
+               if ($_GET["debug"]) $timing_info = print_checkpoint("10", $timing_info);
+
+               if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE')) {
+                       print "<articles>";
+                       foreach ($topmost_article_ids as $id) {
+                               outputArticleXML($link, $id, $feed, false);
+                       }
+                       print "</articles>";
+               }
+
+               if ($_GET["debug"]) $timing_info = print_checkpoint("20", $timing_info);
+
                print "<counters>";
-               getAllCounters($link, $omode);
+               getAllCounters($link, $omode, $feed);
                print "</counters>";
 
+               if ($_GET["debug"]) $timing_info = print_checkpoint("30", $timing_info);
+
+               print_runtime_info($link);
+
                print "</reply>";
        }
 
                module_popup_dialog($link);
        }
 
+       if ($op == "pref-pub-items") {
+               module_pref_pub_items($link);
+       }
+
+
        // update feeds of all users, may be used anonymously
        if ($op == "globalUpdateFeeds") {
 
                        SUBSTRING(last_login,1,16) AS last_login,
                        access_level,
                        (SELECT COUNT(int_id) FROM ttrss_user_entries 
-                               WHERE owner_uid = id) AS stored_articles
+                               WHERE owner_uid = id) AS stored_articles,
+                       SUBSTRING(created,1,16) AS created
                        FROM ttrss_users 
                        WHERE id = '$uid'");
                        
 
                $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
                        strtotime(db_fetch_result($result, 0, "last_login")));
+
+               $created = date(get_pref($link, 'LONG_DATE_FORMAT'),
+                       strtotime(db_fetch_result($result, 0, "created")));
+
                $access_level = db_fetch_result($result, 0, "access_level");
                $stored_articles = db_fetch_result($result, 0, "stored_articles");
 
 #              print "<tr><td>Username</td><td>$login</td></tr>";
 #              print "<tr><td>Access level</td><td>$access_level</td></tr>";
-               print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
-               print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
+               print "<tr><td>".__('Registered')."</td><td>$created</td></tr>";
+               print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>";
+               print "<tr><td>".__('Stored articles')."</td><td>$stored_articles</td></tr>";
 
                $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
                        WHERE owner_uid = '$uid'");
 
                $num_feeds = db_fetch_result($result, 0, "num_feeds");
 
-               print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
+               print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>";
 
 /*             $result = db_query($link, "SELECT 
                        SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size 
 
                print "</table>";
 
-               print "<h1>Subscribed feeds</h1>";
+               print "<h1>".__('Subscribed feeds')."</h1>";
 
                $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
                        WHERE owner_uid = '$uid' ORDER BY title");
                module_pref_feed_browser($link);
        }
 
+       if ($op == "publish") {
+               $key = db_escape_string($_GET["key"]);
+
+               $result = db_query($link, "SELECT login, owner_uid 
+                       FROM ttrss_user_prefs, ttrss_users WHERE
+                       pref_name = '_PREFS_PUBLISH_KEY' AND 
+                       value = '$key' AND 
+                       ttrss_users.id = owner_uid");
+
+               if (db_num_rows($result) == 1) {
+                       $owner = db_fetch_result($result, 0, "owner_uid");
+                       $login = db_fetch_result($result, 0, "login");
+
+                       generate_syndicated_feed($link, $owner, -2, false);
+
+               } else {
+                       print "<error>User not found</error>";
+               }
+
+       }
+
        if ($op == "rss") {
                $feed = db_escape_string($_GET["id"]);
                $user = db_escape_string($_GET["user"]);
                if ($_SESSION["uid"] ||
                        http_authenticate_user($link)) {
 
-                               generate_syndicated_feed($link, $feed, $is_cat, 
+                               generate_syndicated_feed($link, 0, $feed, $is_cat, 
                                        $search, $search_mode, $match_on);
                }
+
        }
 
        if ($op == "labelFromSearch") {