2 error_reporting(E_ERROR | E_WARNING | E_PARSE);
4 /* remove ill effects of magic quotes */
6 if (get_magic_quotes_gpc()) {
7 $_GET = array_map('stripslashes', $_GET);
8 $_POST = array_map('stripslashes', $_POST);
9 $_REQUEST = array_map('stripslashes', $_REQUEST);
10 $_COOKIE = array_map('stripslashes', $_COOKIE);
13 require_once "sessions.php";
14 require_once "modules/backend-rpc.php";
16 /* if ($_GET["debug"]) {
17 define('DEFAULT_ERROR_LEVEL', E_ALL);
19 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
22 error_reporting(DEFAULT_ERROR_LEVEL); */
24 require_once "sanity_check.php";
25 require_once "config.php";
27 require_once "db.php";
28 require_once "db-prefs.php";
29 require_once "functions.php";
31 no_cache_incantation();
33 if (ENABLE_TRANSLATIONS == true) {
37 $script_started = getmicrotime();
39 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
42 if (DB_TYPE == "mysql") {
45 // PG seems to display its own errors just fine by default.
49 init_connection($link);
51 $op = $_REQUEST["op"];
52 $mode = $_REQUEST["mode"];
54 $print_exec_time = false;
56 if ((!$op || $op == "rpc" || $op == "rss" ||
57 ($op == "view" && $mode != "zoom") ||
58 $op == "digestSend" || $op == "viewfeed" || $op == "publish" ||
59 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
60 header("Content-Type: application/xml; charset=utf-8");
62 if (ENABLE_GZIP_OUTPUT) {
63 ob_start("ob_gzhandler");
67 if (!$_REQUEST["noxml"]) {
68 header("Content-Type: text/html; charset=utf-8");
70 header("Content-Type: text/plain; charset=utf-8");
75 header("Content-Type: application/xml");
76 print_error_xml(7); exit;
79 if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
80 && $op != "rss" && $op != "getUnread" && $op != "publish") {
82 if ($op == "rpc" || $op == "viewfeed" || $op == "view") {
83 print_error_xml(6); die;
87 <p>Error: Not logged in.</p>
88 <script type=\"text/javascript\">
89 if (parent.window != 'undefined') {
90 parent.window.location = \"tt-rss.php\";
92 window.location = \"tt-rss.php\";
101 $purge_intervals = array(
102 0 => __("Use default"),
103 -1 => __("Never purge"),
104 5 => __("1 week old"),
105 14 => __("2 weeks old"),
106 31 => __("1 month old"),
107 60 => __("2 months old"),
108 90 => __("3 months old"));
110 $update_intervals = array(
111 0 => __("Default interval"),
112 -1 => __("Disable updates"),
113 15 => __("Each 15 minutes"),
114 30 => __("Each 30 minutes"),
116 240 => __("Each 4 hours"),
117 720 => __("Each 12 hours"),
119 10080 => __("Weekly"));
121 $update_methods = array(
124 2 => __("SimplePie"));
126 if (ENABLE_SIMPLEPIE) {
127 $update_methods[0] .= ' (SimplePie)';
129 $update_methods[0] .= ' (Magpie)';
132 $access_level_names = array(
134 5 => __("Power User"),
135 10 => __("Administrator"));
137 require_once "modules/pref-prefs.php";
138 require_once "modules/popup-dialog.php";
139 require_once "modules/help.php";
140 require_once "modules/pref-feeds.php";
141 require_once "modules/pref-filters.php";
142 require_once "modules/pref-labels.php";
143 require_once "modules/pref-users.php";
144 require_once "modules/pref-feed-browser.php";
146 if (!sanity_check($link)) { return; }
148 switch($op) { // Select action according to $op value.
150 // Handle remote procedure calls.
151 handle_rpc_request($link);
155 if (ENABLE_GZIP_OUTPUT) {
156 ob_start("ob_gzhandler");
159 $tags = $_GET["tags"];
161 $subop = $_GET["subop"];
165 db_query($link, "UPDATE ttrss_user_entries SET
166 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
167 ccache_zero_all($link, $_SESSION["uid"]);
172 $cat_id = db_escape_string($_GET["cid"]);
174 db_query($link, "UPDATE ttrss_feed_categories SET
175 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
181 db_query($link, "UPDATE ttrss_feed_categories
182 SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
187 $corder = db_escape_string($_GET["corder"]);
189 $cats = split(",", $corder);
191 for ($i = 0; $i < count($cats); $i++) {
195 db_query($link, "UPDATE ttrss_feed_categories
196 SET order_id = '$i' WHERE id = '$cat_id' AND
197 owner_uid = " . $_SESSION["uid"]);
206 outputFeedList($link, $tags);
211 $id = db_escape_string($_GET["id"]);
212 $feed_id = db_escape_string($_GET["feed"]);
213 $cids = split(",", db_escape_string($_GET["cids"]));
214 $mode = db_escape_string($_GET["mode"]);
215 $omode = db_escape_string($_GET["omode"]);
217 $csync = $_GET["csync"];
221 // in prefetch mode we only output requested cids, main article
222 // just gets marked as read (it already exists in client cache)
225 outputArticleXML($link, $id, $feed_id);
226 } else if ($mode == "zoom") {
227 outputArticleXML($link, $id, $feed_id, true, true);
229 catchupArticleById($link, $id, 0);
230 ccache_update($link, $feed_id, $_SESSION["uid"]);
233 if (!$_SESSION["bw_limit"]) {
234 foreach ($cids as $cid) {
236 outputArticleXML($link, $cid, $feed_id, false);
242 // if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
244 getAllCounters($link, $omode);
253 $print_exec_time = true;
254 $timing_info = getmicrotime();
258 if ($_GET["debug"]) $timing_info = print_checkpoint("0", $timing_info);
260 $omode = db_escape_string($_GET["omode"]);
262 $feed = db_escape_string($_GET["feed"]);
263 $subop = db_escape_string($_GET["subop"]);
264 $view_mode = db_escape_string($_GET["view_mode"]);
265 $limit = db_escape_string($_GET["limit"]);
266 $cat_view = db_escape_string($_GET["cat"]);
267 $next_unread_feed = db_escape_string($_GET["nuf"]);
268 $offset = db_escape_string($_GET["skip"]);
269 $vgroup_last_feed = db_escape_string($_GET["vgrlf"]);
270 $csync = $_GET["csync"];
271 $order_by = db_escape_string($_GET["order_by"]);
273 /* Updating a label ccache means recalculating all of the caches
274 * so for performance reasons we don't do that here */
276 if (time() - $_SESSION["viewfeed:ccache_update_stamp"] > 120) {
278 ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
280 $_SESSION["viewfeed:ccache_update_stamp"] = time();
283 set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
284 set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
285 set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
287 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
288 db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW()
289 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
292 print "<headlines id=\"$feed\" is_cat=\"$cat_view\"><![CDATA[";
294 $override_order = false;
298 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
299 $override_order = "updated";
301 $override_order = "updated DESC";
306 $override_order = "updated DESC";
310 $override_order = "score DESC";
314 $ret = outputHeadlinesList($link, $feed, $subop,
315 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
316 $vgroup_last_feed, $override_order);
318 $topmost_article_ids = $ret[0];
319 $headlines_count = $ret[1];
320 $returned_feed = $ret[2];
321 $disable_cache = $ret[3];
322 $vgroup_last_feed = $ret[4];
324 print "]]></headlines>";
326 print "<headlines-count value=\"$headlines_count\"/>";
327 print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
329 $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
332 if ($headlines_unread == -1) {
333 $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
337 print "<headlines-unread value=\"$headlines_unread\"/>";
338 printf("<disable-cache value=\"%d\"/>", $disable_cache);
340 if ($_GET["debug"]) $timing_info = print_checkpoint("10", $timing_info);
342 if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
344 foreach ($topmost_article_ids as $id) {
345 outputArticleXML($link, $id, $feed, false);
350 if ($_GET["debug"]) $timing_info = print_checkpoint("20", $timing_info);
353 // if (get_pref($link, "SYNC_COUNTERS") ||
354 // time() - $_SESSION["get_all_counters_stamp"] > $viewfeed_ctr_interval) {
355 // print "<counters>";
356 // getAllCounters($link, $omode, $feed);
357 // print "</counters>";
360 if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop ||
361 time() - $_SESSION["viewfeed:counters_stamp"] > 60) {
364 getAllCounters($link, $omode, $feed);
366 $_SESSION["viewfeed:counters_stamp"] = time();
370 if ($_GET["debug"]) $timing_info = print_checkpoint("30", $timing_info);
372 print_runtime_info($link);
378 module_pref_feeds($link);
382 module_pref_filters($link);
383 break; // pref-filters
386 module_pref_labels($link);
387 break; // pref-labels
390 module_pref_prefs($link);
394 module_pref_users($link);
395 break; // prefs-users
402 module_popup_dialog($link);
405 case "pref-pub-items":
406 module_pref_pub_items($link);
407 break; // pref-pub-items
409 case "globalUpdateFeeds":
410 // update feeds of all users, may be used anonymously
413 // Update all feeds needing a update.
414 update_daemon_common($link, 0, true, true);
418 <message msg=\"All feeds updated\"/>
420 break; // globalUpdateFeeds
422 case "pref-feed-browser":
423 module_pref_feed_browser($link);
424 break; // pref-feed-browser
427 $key = db_escape_string($_GET["key"]);
428 $limit = (int)db_escape_string($_GET["limit"]);
430 $result = db_query($link, "SELECT login, owner_uid
431 FROM ttrss_user_prefs, ttrss_users WHERE
432 pref_name = '_PREFS_PUBLISH_KEY' AND
434 ttrss_users.id = owner_uid");
436 if (db_num_rows($result) == 1) {
437 $owner = db_fetch_result($result, 0, "owner_uid");
438 $login = db_fetch_result($result, 0, "login");
440 generate_syndicated_feed($link, $owner, -2, false, $limit);
443 print "<error>User not found</error>";
448 $feed = db_escape_string($_GET["id"]);
449 $user = db_escape_string($_GET["user"]);
450 $pass = db_escape_string($_GET["pass"]);
451 $is_cat = $_GET["is_cat"] != false;
452 $limit = (int)db_escape_string($_GET["limit"]);
454 $search = db_escape_string($_GET["q"]);
455 $match_on = db_escape_string($_GET["m"]);
456 $search_mode = db_escape_string($_GET["smode"]);
458 if (!$_SESSION["uid"] && $user && $pass) {
459 authenticate_user($link, $user, $pass);
462 if ($_SESSION["uid"] ||
463 http_authenticate_user($link)) {
465 generate_syndicated_feed($link, 0, $feed, $is_cat, $limit,
466 $search, $search_mode, $match_on);
470 case "labelFromSearch":
471 $search = db_escape_string($_GET["search"]);
472 $search_mode = db_escape_string($_GET["smode"]);
473 $match_on = db_escape_string($_GET["match"]);
474 $is_cat = db_escape_string($_GET["is_cat"]);
475 $title = db_escape_string($_GET["title"]);
476 $feed = sprintf("%d", $_GET["feed"]);
478 $label_qparts = array();
480 $search_expr = getSearchSql($search, $match_on);
484 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
486 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
489 if ($search_mode == "all_feeds") {
491 } else if ($search_mode == "this_cat") {
493 $tmp_result = db_query($link, "SELECT cat_id
494 FROM ttrss_feeds WHERE id = '$feed'");
496 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
499 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
501 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
504 $search_expr .= " AND ttrss_feeds.id = $feed ";
509 $search_expr = db_escape_string($search_expr);
514 $result = db_query($link,
515 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
516 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
518 break; // labelFromSearch
521 $login = db_escape_string($_GET["login"]);
523 header("Content-Type: text/plain; charset=utf-8");
525 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
527 if (db_num_rows($result) == 1) {
528 $uid = db_fetch_result($result, 0, "id");
529 print getGlobalUnread($link, $uid);
531 print "-1;User not found";
534 $print_exec_time = false;
538 header("Content-Type: text/plain");
539 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
540 $print_exec_time = false;
544 header("Content-Type: text/plain");
545 send_headlines_digests($link);
546 $print_exec_time = false;
549 } // Select action according to $op value.
551 // We close the connection to database.
555 <?php if ($print_exec_time) { ?>
556 <!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->