2 error_reporting(E_ERROR | E_WARNING | E_PARSE);
4 /* remove ill effects of magic quotes */
6 if (get_magic_quotes_gpc()) {
7 function stripslashes_deep($value) {
8 $value = is_array($value) ?
9 array_map('stripslashes_deep', $value) : stripslashes($value);
13 $_POST = array_map('stripslashes_deep', $_POST);
14 $_GET = array_map('stripslashes_deep', $_GET);
15 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
16 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
19 require_once "sessions.php";
20 require_once "modules/backend-rpc.php";
22 /* if ($_REQUEST["debug"]) {
23 define('DEFAULT_ERROR_LEVEL', E_ALL);
25 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
28 error_reporting(DEFAULT_ERROR_LEVEL); */
30 require_once "sanity_check.php";
31 require_once "config.php";
33 require_once "db.php";
34 require_once "db-prefs.php";
35 require_once "functions.php";
37 no_cache_incantation();
39 if (ENABLE_TRANSLATIONS == true) {
43 $script_started = getmicrotime();
45 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
48 if (DB_TYPE == "mysql") {
51 // PG seems to display its own errors just fine by default.
55 init_connection($link);
57 $op = $_REQUEST["op"];
58 $subop = $_REQUEST["subop"];
59 $mode = $_REQUEST["mode"];
61 $print_exec_time = false;
63 if ((!$op || $op == "rpc" || $op == "rss" ||
64 ($op == "view" && $mode != "zoom") ||
65 $op == "digestSend" || $op == "viewfeed" || $op == "publish" ||
66 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
67 header("Content-Type: application/xml; charset=utf-8");
69 if (ENABLE_GZIP_OUTPUT) {
70 ob_start("ob_gzhandler");
74 if (!$_REQUEST["noxml"]) {
75 header("Content-Type: text/html; charset=utf-8");
77 header("Content-Type: text/plain; charset=utf-8");
82 header("Content-Type: application/xml");
83 print_error_xml(7); exit;
86 if (SINGLE_USER_MODE) {
87 authenticate_user($link, "admin", null);
90 if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
91 && $op != "rss" && $op != "getUnread" && $op != "publish" && $op != "getProfiles") {
93 if ($op == "rpc" || $op == "viewfeed" || $op == "view") {
94 print_error_xml(6); die;
98 <p>Error: Not logged in.</p>
99 <script type=\"text/javascript\">
100 if (parent.window != 'undefined') {
101 parent.window.location = \"tt-rss.php\";
103 window.location = \"tt-rss.php\";
112 $purge_intervals = array(
113 0 => __("Use default"),
114 -1 => __("Never purge"),
115 5 => __("1 week old"),
116 14 => __("2 weeks old"),
117 31 => __("1 month old"),
118 60 => __("2 months old"),
119 90 => __("3 months old"));
121 $update_intervals = array(
122 0 => __("Default interval"),
123 -1 => __("Disable updates"),
124 15 => __("Each 15 minutes"),
125 30 => __("Each 30 minutes"),
127 240 => __("Each 4 hours"),
128 720 => __("Each 12 hours"),
130 10080 => __("Weekly"));
132 $update_intervals_nodefault = array(
133 -1 => __("Disable updates"),
134 15 => __("Each 15 minutes"),
135 30 => __("Each 30 minutes"),
137 240 => __("Each 4 hours"),
138 720 => __("Each 12 hours"),
140 10080 => __("Weekly"));
142 $update_methods = array(
145 2 => __("SimplePie"));
147 if (DEFAULT_UPDATE_METHOD == "1") {
148 $update_methods[0] .= ' (SimplePie)';
150 $update_methods[0] .= ' (Magpie)';
153 $access_level_names = array(
155 5 => __("Power User"),
156 10 => __("Administrator"));
158 require_once "modules/pref-prefs.php";
159 require_once "modules/popup-dialog.php";
160 require_once "modules/help.php";
161 require_once "modules/pref-feeds.php";
162 require_once "modules/pref-filters.php";
163 require_once "modules/pref-labels.php";
164 require_once "modules/pref-users.php";
166 if (!sanity_check($link)) { return; }
168 switch($op) { // Select action according to $op value.
170 // Handle remote procedure calls.
171 handle_rpc_request($link);
175 if (ENABLE_GZIP_OUTPUT) {
176 ob_start("ob_gzhandler");
179 $tags = $_REQUEST["tags"];
181 $subop = $_REQUEST["subop"];
185 db_query($link, "UPDATE ttrss_user_entries SET
186 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
187 ccache_zero_all($link, $_SESSION["uid"]);
192 $cat_id = db_escape_string($_REQUEST["cid"]);
193 toggle_collapse_cat($link, $cat_id);
198 db_query($link, "UPDATE ttrss_feed_categories
199 SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
204 $corder = db_escape_string($_REQUEST["corder"]);
206 $cats = split(",", $corder);
208 for ($i = 0; $i < count($cats); $i++) {
212 db_query($link, "UPDATE ttrss_feed_categories
213 SET order_id = '$i' WHERE id = '$cat_id' AND
214 owner_uid = " . $_SESSION["uid"]);
223 $_SESSION["viewfeed:counters_stamp"] = time();
225 outputFeedList($link, $tags);
230 $id = db_escape_string($_REQUEST["id"]);
231 $cids = split(",", db_escape_string($_REQUEST["cids"]));
232 $mode = db_escape_string($_REQUEST["mode"]);
233 $omode = db_escape_string($_REQUEST["omode"]);
235 $csync = $_REQUEST["csync"];
239 // in prefetch mode we only output requested cids, main article
240 // just gets marked as read (it already exists in client cache)
243 outputArticleXML($link, $id, false);
244 } else if ($mode == "zoom") {
245 outputArticleXML($link, $id, false, true, true);
247 catchupArticleById($link, $id, 0);
250 if (!$_SESSION["bw_limit"]) {
251 foreach ($cids as $cid) {
253 outputArticleXML($link, $cid, false, false);
258 // if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
260 if (time() - $_SESSION["view:counters_stamp"] > 5 && $mode == "prefetch") {
262 getAllCounters($link, $omode);
264 $_SESSION["view:counters_stamp"] = time();
272 $print_exec_time = true;
273 $timing_info = getmicrotime();
277 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
279 $omode = db_escape_string($_REQUEST["omode"]);
281 $feed = db_escape_string($_REQUEST["feed"]);
282 $subop = db_escape_string($_REQUEST["subop"]);
283 $view_mode = db_escape_string($_REQUEST["view_mode"]);
284 $limit = (int) get_pref($link, "DEFAULT_ARTICLE_LIMIT");
285 $cat_view = db_escape_string($_REQUEST["cat"]);
286 $next_unread_feed = db_escape_string($_REQUEST["nuf"]);
287 $offset = db_escape_string($_REQUEST["skip"]);
288 $vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
289 $csync = $_REQUEST["csync"];
290 $order_by = db_escape_string($_REQUEST["order_by"]);
292 /* Updating a label ccache means recalculating all of the caches
293 * so for performance reasons we don't do that here */
295 // if (time() - $_SESSION["viewfeed:ccache_update_stamp"] > 120) {
297 ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
299 $_SESSION["viewfeed:ccache_update_stamp"] = time();
302 set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
303 set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
304 set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
306 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
307 db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW()
308 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
311 if (!$next_unread_feed) {
312 print "<headlines id=\"$feed\" is_cat=\"$cat_view\"><![CDATA[";
314 print "<headlines id=\"$next_unread_feed\" is_cat=\"$cat_view\"><![CDATA[";
317 $override_order = false;
321 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
322 $override_order = "date_entered";
324 $override_order = "date_entered DESC";
329 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
330 $override_order = "title DESC, date_entered";
332 $override_order = "title, date_entered DESC";
337 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
338 $override_order = "score, date_entered";
340 $override_order = "score DESC, date_entered DESC";
345 $ret = outputHeadlinesList($link, $feed, $subop,
346 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
347 $vgroup_last_feed, $override_order);
349 $topmost_article_ids = $ret[0];
350 $headlines_count = $ret[1];
351 $returned_feed = $ret[2];
352 $disable_cache = $ret[3];
353 $vgroup_last_feed = $ret[4];
355 print "]]></headlines>";
357 print "<headlines-count value=\"$headlines_count\"/>";
358 print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
360 $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
363 if ($headlines_unread == -1) {
364 $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
368 print "<headlines-unread value=\"$headlines_unread\"/>";
369 printf("<disable-cache value=\"%d\"/>", $disable_cache);
371 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("10", $timing_info);
373 if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
375 foreach ($topmost_article_ids as $id) {
376 outputArticleXML($link, $id, $feed, false);
381 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
384 // if (get_pref($link, "SYNC_COUNTERS") ||
385 // time() - $_SESSION["get_all_counters_stamp"] > $viewfeed_ctr_interval) {
386 // print "<counters>";
387 // getAllCounters($link, $omode, $feed);
388 // print "</counters>";
391 if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop ||
392 time() - $_SESSION["viewfeed:counters_stamp"] > 5) {
395 getAllCounters($link, $omode, $feed);
397 $_SESSION["viewfeed:counters_stamp"] = time();
401 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
403 print_runtime_info($link);
409 module_pref_feeds($link);
413 module_pref_filters($link);
414 break; // pref-filters
417 module_pref_labels($link);
418 break; // pref-labels
421 module_pref_prefs($link);
425 module_pref_users($link);
426 break; // prefs-users
433 module_popup_dialog($link);
436 case "pref-pub-items":
437 module_pref_pub_items($link);
438 break; // pref-pub-items
440 case "globalUpdateFeeds":
441 // update feeds of all users, may be used anonymously
444 // Update all feeds needing a update.
445 update_daemon_common($link, 0, true, true);
449 <message msg=\"All feeds updated\"/>
451 break; // globalUpdateFeeds
453 case "pref-feed-browser":
454 module_pref_feed_browser($link);
455 break; // pref-feed-browser
458 $key = db_escape_string($_REQUEST["key"]);
459 $limit = (int)db_escape_string($_REQUEST["limit"]);
461 $result = db_query($link, "SELECT login, owner_uid
462 FROM ttrss_user_prefs, ttrss_users WHERE
463 pref_name = '_PREFS_PUBLISH_KEY' AND
465 ttrss_users.id = owner_uid");
467 if (db_num_rows($result) == 1) {
468 $owner = db_fetch_result($result, 0, "owner_uid");
469 $login = db_fetch_result($result, 0, "login");
471 generate_syndicated_feed($link, $owner, -2, false, $limit);
474 print "<error>User not found</error>";
479 $feed = db_escape_string($_REQUEST["id"]);
480 $user = db_escape_string($_REQUEST["user"]);
481 $pass = db_escape_string($_REQUEST["pass"]);
482 $is_cat = $_REQUEST["is_cat"] != false;
483 $limit = (int)db_escape_string($_REQUEST["limit"]);
485 $search = db_escape_string($_REQUEST["q"]);
486 $match_on = db_escape_string($_REQUEST["m"]);
487 $search_mode = db_escape_string($_REQUEST["smode"]);
489 if (SINGLE_USER_MODE) {
490 authenticate_user($link, "admin", null);
493 if (!$_SESSION["uid"] && $user && $pass) {
494 authenticate_user($link, $user, $pass);
497 if ($_SESSION["uid"] ||
498 http_authenticate_user($link)) {
500 generate_syndicated_feed($link, 0, $feed, $is_cat, $limit,
501 $search, $search_mode, $match_on);
506 $login = db_escape_string($_REQUEST["login"]);
507 $fresh = $_REQUEST["fresh"] == "1";
509 header("Content-Type: text/plain; charset=utf-8");
511 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
513 if (db_num_rows($result) == 1) {
514 $uid = db_fetch_result($result, 0, "id");
516 print getGlobalUnread($link, $uid);
520 print getFeedArticles($link, -3, false, true, $uid);
524 print "-1;User not found";
527 $print_exec_time = false;
531 header("Content-Type: text/plain");
532 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
533 $print_exec_time = false;
537 header("Content-Type: text/plain");
538 send_headlines_digests($link);
539 $print_exec_time = false;
543 $login = db_escape_string($_REQUEST["login"]);
544 $password = db_escape_string($_REQUEST["password"]);
546 if (authenticate_user($link, $login, $password)) {
547 $result = db_query($link, "SELECT * FROM ttrss_settings_profiles
548 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
550 print "<select style='width: 100%' name='profile'>";
552 print "<option value='0'>" . __("Default profile") . "</option>";
554 while ($line = db_fetch_assoc($result)) {
556 $title = $line["title"];
558 print "<option value='$id'>$title</option>";
567 } // Select action according to $op value.
569 // We close the connection to database.
573 <?php if ($print_exec_time) { ?>
574 <!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->