2 error_reporting(E_ERROR | E_WARNING | E_PARSE
);
4 /* remove ill effects of magic quotes */
6 if (get_magic_quotes_gpc()) {
7 $_REQUEST = array_map('stripslashes', $_REQUEST);
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 ($_REQUEST["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 $subop = $_REQUEST["subop"];
53 $mode = $_REQUEST["mode"];
55 $print_exec_time = false;
57 if ((!$op ||
$op == "rpc" ||
$op == "rss" ||
58 ($op == "view" && $mode != "zoom") ||
59 $op == "digestSend" ||
$op == "viewfeed" ||
$op == "publish" ||
60 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
61 header("Content-Type: application/xml; charset=utf-8");
63 if (ENABLE_GZIP_OUTPUT
) {
64 ob_start("ob_gzhandler");
68 if (!$_REQUEST["noxml"]) {
69 header("Content-Type: text/html; charset=utf-8");
71 header("Content-Type: text/plain; charset=utf-8");
76 header("Content-Type: application/xml");
77 print_error_xml(7); exit;
80 if (SINGLE_USER_MODE
) {
81 authenticate_user($link, "admin", null);
84 if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
85 && $op != "rss" && $op != "getUnread" && $op != "publish" && $op != "getProfiles") {
87 if ($op == "rpc" ||
$op == "viewfeed" ||
$op == "view") {
88 print_error_xml(6); die;
92 <p>Error: Not logged in.</p>
93 <script type=\"text/javascript\">
94 if (parent.window != 'undefined') {
95 parent.window.location = \"tt-rss.php\";
97 window.location = \"tt-rss.php\";
106 $purge_intervals = array(
107 0 => __("Use default"),
108 -1 => __("Never purge"),
109 5 => __("1 week old"),
110 14 => __("2 weeks old"),
111 31 => __("1 month old"),
112 60 => __("2 months old"),
113 90 => __("3 months old"));
115 $update_intervals = array(
116 0 => __("Default interval"),
117 -1 => __("Disable updates"),
118 15 => __("Each 15 minutes"),
119 30 => __("Each 30 minutes"),
121 240 => __("Each 4 hours"),
122 720 => __("Each 12 hours"),
124 10080 => __("Weekly"));
126 $update_intervals_nodefault = array(
127 -1 => __("Disable updates"),
128 15 => __("Each 15 minutes"),
129 30 => __("Each 30 minutes"),
131 240 => __("Each 4 hours"),
132 720 => __("Each 12 hours"),
134 10080 => __("Weekly"));
136 $update_methods = array(
139 2 => __("SimplePie"));
141 if (ENABLE_SIMPLEPIE
) {
142 $update_methods[0] .= ' (SimplePie)';
144 $update_methods[0] .= ' (Magpie)';
147 $access_level_names = array(
149 5 => __("Power User"),
150 10 => __("Administrator"));
152 require_once "modules/pref-prefs.php";
153 require_once "modules/popup-dialog.php";
154 require_once "modules/help.php";
155 require_once "modules/pref-feeds.php";
156 require_once "modules/pref-filters.php";
157 require_once "modules/pref-labels.php";
158 require_once "modules/pref-users.php";
160 if (!sanity_check($link)) { return; }
162 switch($op) { // Select action according to $op value.
164 // Handle remote procedure calls.
165 handle_rpc_request($link);
169 if (ENABLE_GZIP_OUTPUT
) {
170 ob_start("ob_gzhandler");
173 $tags = $_REQUEST["tags"];
175 $subop = $_REQUEST["subop"];
179 db_query($link, "UPDATE ttrss_user_entries SET
180 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
181 ccache_zero_all($link, $_SESSION["uid"]);
186 $cat_id = db_escape_string($_REQUEST["cid"]);
187 toggle_collapse_cat($link, $cat_id);
192 db_query($link, "UPDATE ttrss_feed_categories
193 SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
198 $corder = db_escape_string($_REQUEST["corder"]);
200 $cats = split(",", $corder);
202 for ($i = 0; $i < count($cats); $i++
) {
206 db_query($link, "UPDATE ttrss_feed_categories
207 SET order_id = '$i' WHERE id = '$cat_id' AND
208 owner_uid = " . $_SESSION["uid"]);
217 $_SESSION["viewfeed:counters_stamp"] = time();
219 outputFeedList($link, $tags);
224 $id = db_escape_string($_REQUEST["id"]);
225 $cids = split(",", db_escape_string($_REQUEST["cids"]));
226 $mode = db_escape_string($_REQUEST["mode"]);
227 $omode = db_escape_string($_REQUEST["omode"]);
229 $csync = $_REQUEST["csync"];
233 // in prefetch mode we only output requested cids, main article
234 // just gets marked as read (it already exists in client cache)
237 outputArticleXML($link, $id, false);
238 } else if ($mode == "zoom") {
239 outputArticleXML($link, $id, false, true, true);
241 catchupArticleById($link, $id, 0);
244 if (!$_SESSION["bw_limit"]) {
245 foreach ($cids as $cid) {
247 outputArticleXML($link, $cid, false, false);
252 // if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
254 if (time() - $_SESSION["view:counters_stamp"] > 5 && $mode == "prefetch") {
256 getAllCounters($link, $omode);
258 $_SESSION["view:counters_stamp"] = time();
266 $print_exec_time = true;
267 $timing_info = getmicrotime();
271 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
273 $omode = db_escape_string($_REQUEST["omode"]);
275 $feed = db_escape_string($_REQUEST["feed"]);
276 $subop = db_escape_string($_REQUEST["subop"]);
277 $view_mode = db_escape_string($_REQUEST["view_mode"]);
278 $limit = (int) get_pref($link, "DEFAULT_ARTICLE_LIMIT");
279 $cat_view = db_escape_string($_REQUEST["cat"]);
280 $next_unread_feed = db_escape_string($_REQUEST["nuf"]);
281 $offset = db_escape_string($_REQUEST["skip"]);
282 $vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
283 $csync = $_REQUEST["csync"];
284 $order_by = db_escape_string($_REQUEST["order_by"]);
286 /* Updating a label ccache means recalculating all of the caches
287 * so for performance reasons we don't do that here */
289 // if (time() - $_SESSION["viewfeed:ccache_update_stamp"] > 120) {
291 ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
293 $_SESSION["viewfeed:ccache_update_stamp"] = time();
296 set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
297 set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
298 set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
300 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
301 db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW()
302 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
305 if (!$next_unread_feed) {
306 print "<headlines id=\"$feed\" is_cat=\"$cat_view\"><![CDATA[";
308 print "<headlines id=\"$next_unread_feed\" is_cat=\"$cat_view\"><![CDATA[";
311 $override_order = false;
315 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
316 $override_order = "updated";
318 $override_order = "updated DESC";
323 $override_order = "updated DESC";
327 $override_order = "score DESC";
331 $ret = outputHeadlinesList($link, $feed, $subop,
332 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
333 $vgroup_last_feed, $override_order);
335 $topmost_article_ids = $ret[0];
336 $headlines_count = $ret[1];
337 $returned_feed = $ret[2];
338 $disable_cache = $ret[3];
339 $vgroup_last_feed = $ret[4];
341 print "]]></headlines>";
343 print "<headlines-count value=\"$headlines_count\"/>";
344 print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
346 $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
349 if ($headlines_unread == -1) {
350 $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
354 print "<headlines-unread value=\"$headlines_unread\"/>";
355 printf("<disable-cache value=\"%d\"/>", $disable_cache);
357 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("10", $timing_info);
359 if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
361 foreach ($topmost_article_ids as $id) {
362 outputArticleXML($link, $id, $feed, false);
367 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
370 // if (get_pref($link, "SYNC_COUNTERS") ||
371 // time() - $_SESSION["get_all_counters_stamp"] > $viewfeed_ctr_interval) {
372 // print "<counters>";
373 // getAllCounters($link, $omode, $feed);
374 // print "</counters>";
377 if (get_pref($link, 'COMBINED_DISPLAY_MODE') ||
$subop ||
378 time() - $_SESSION["viewfeed:counters_stamp"] > 5) {
381 getAllCounters($link, $omode, $feed);
383 $_SESSION["viewfeed:counters_stamp"] = time();
387 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
389 print_runtime_info($link);
395 module_pref_feeds($link);
399 module_pref_filters($link);
400 break; // pref-filters
403 module_pref_labels($link);
404 break; // pref-labels
407 module_pref_prefs($link);
411 module_pref_users($link);
412 break; // prefs-users
419 module_popup_dialog($link);
422 case "pref-pub-items":
423 module_pref_pub_items($link);
424 break; // pref-pub-items
426 case "globalUpdateFeeds":
427 // update feeds of all users, may be used anonymously
430 // Update all feeds needing a update.
431 update_daemon_common($link, 0, true, true);
435 <message msg=\"All feeds updated\"/>
437 break; // globalUpdateFeeds
439 case "pref-feed-browser":
440 module_pref_feed_browser($link);
441 break; // pref-feed-browser
444 $key = db_escape_string($_REQUEST["key"]);
445 $limit = (int)db_escape_string($_REQUEST["limit"]);
447 $result = db_query($link, "SELECT login, owner_uid
448 FROM ttrss_user_prefs, ttrss_users WHERE
449 pref_name = '_PREFS_PUBLISH_KEY' AND
451 ttrss_users.id = owner_uid");
453 if (db_num_rows($result) == 1) {
454 $owner = db_fetch_result($result, 0, "owner_uid");
455 $login = db_fetch_result($result, 0, "login");
457 generate_syndicated_feed($link, $owner, -2, false, $limit);
460 print "<error>User not found</error>";
465 $feed = db_escape_string($_REQUEST["id"]);
466 $user = db_escape_string($_REQUEST["user"]);
467 $pass = db_escape_string($_REQUEST["pass"]);
468 $is_cat = $_REQUEST["is_cat"] != false;
469 $limit = (int)db_escape_string($_REQUEST["limit"]);
471 $search = db_escape_string($_REQUEST["q"]);
472 $match_on = db_escape_string($_REQUEST["m"]);
473 $search_mode = db_escape_string($_REQUEST["smode"]);
475 if (SINGLE_USER_MODE
) {
476 authenticate_user($link, "admin", null);
479 if (!$_SESSION["uid"] && $user && $pass) {
480 authenticate_user($link, $user, $pass);
483 if ($_SESSION["uid"] ||
484 http_authenticate_user($link)) {
486 generate_syndicated_feed($link, 0, $feed, $is_cat, $limit,
487 $search, $search_mode, $match_on);
492 $login = db_escape_string($_REQUEST["login"]);
494 header("Content-Type: text/plain; charset=utf-8");
496 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
498 if (db_num_rows($result) == 1) {
499 $uid = db_fetch_result($result, 0, "id");
500 print getGlobalUnread($link, $uid);
502 print "-1;User not found";
505 $print_exec_time = false;
509 header("Content-Type: text/plain");
510 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
511 $print_exec_time = false;
515 header("Content-Type: text/plain");
516 send_headlines_digests($link);
517 $print_exec_time = false;
521 $login = db_escape_string($_REQUEST["login"]);
522 $password = db_escape_string($_REQUEST["password"]);
524 if (authenticate_user($link, $login, $password)) {
525 $result = db_query($link, "SELECT * FROM ttrss_settings_profiles
526 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
528 print "<select style='width: 100%' name='profile'>";
530 print "<option value='0'>" . __("Default profile") . "</option>";
532 while ($line = db_fetch_assoc($result)) {
534 $title = $line["title"];
536 print "<option value='$id'>$title</option>";
545 } // Select action according to $op value.
547 // We close the connection to database.
551 <?php
if ($print_exec_time) { ?
>
552 <!-- <?php
echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->