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_methods = array(
129 2 => __("SimplePie"));
131 if (ENABLE_SIMPLEPIE
) {
132 $update_methods[0] .= ' (SimplePie)';
134 $update_methods[0] .= ' (Magpie)';
137 $access_level_names = array(
139 5 => __("Power User"),
140 10 => __("Administrator"));
142 require_once "modules/pref-prefs.php";
143 require_once "modules/popup-dialog.php";
144 require_once "modules/help.php";
145 require_once "modules/pref-feeds.php";
146 require_once "modules/pref-filters.php";
147 require_once "modules/pref-labels.php";
148 require_once "modules/pref-users.php";
150 if (!sanity_check($link)) { return; }
152 switch($op) { // Select action according to $op value.
154 // Handle remote procedure calls.
155 handle_rpc_request($link);
159 if (ENABLE_GZIP_OUTPUT
) {
160 ob_start("ob_gzhandler");
163 $tags = $_REQUEST["tags"];
165 $subop = $_REQUEST["subop"];
169 db_query($link, "UPDATE ttrss_user_entries SET
170 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
171 ccache_zero_all($link, $_SESSION["uid"]);
176 $cat_id = db_escape_string($_REQUEST["cid"]);
177 toggle_collapse_cat($link, $cat_id);
182 db_query($link, "UPDATE ttrss_feed_categories
183 SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
188 $corder = db_escape_string($_REQUEST["corder"]);
190 $cats = split(",", $corder);
192 for ($i = 0; $i < count($cats); $i++
) {
196 db_query($link, "UPDATE ttrss_feed_categories
197 SET order_id = '$i' WHERE id = '$cat_id' AND
198 owner_uid = " . $_SESSION["uid"]);
207 $_SESSION["viewfeed:counters_stamp"] = time();
209 outputFeedList($link, $tags);
214 $id = db_escape_string($_REQUEST["id"]);
215 $cids = split(",", db_escape_string($_REQUEST["cids"]));
216 $mode = db_escape_string($_REQUEST["mode"]);
217 $omode = db_escape_string($_REQUEST["omode"]);
219 $csync = $_REQUEST["csync"];
223 // in prefetch mode we only output requested cids, main article
224 // just gets marked as read (it already exists in client cache)
227 outputArticleXML($link, $id, false);
228 } else if ($mode == "zoom") {
229 outputArticleXML($link, $id, false, true, true);
231 catchupArticleById($link, $id, 0);
234 if (!$_SESSION["bw_limit"]) {
235 foreach ($cids as $cid) {
237 outputArticleXML($link, $cid, false, false);
242 // if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
244 if (time() - $_SESSION["view:counters_stamp"] > 5 && $mode == "prefetch") {
246 getAllCounters($link, $omode);
248 $_SESSION["view:counters_stamp"] = time();
256 $print_exec_time = true;
257 $timing_info = getmicrotime();
261 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
263 $omode = db_escape_string($_REQUEST["omode"]);
265 $feed = db_escape_string($_REQUEST["feed"]);
266 $subop = db_escape_string($_REQUEST["subop"]);
267 $view_mode = db_escape_string($_REQUEST["view_mode"]);
268 $limit = (int) get_pref($link, "DEFAULT_ARTICLE_LIMIT");
269 $cat_view = db_escape_string($_REQUEST["cat"]);
270 $next_unread_feed = db_escape_string($_REQUEST["nuf"]);
271 $offset = db_escape_string($_REQUEST["skip"]);
272 $vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
273 $csync = $_REQUEST["csync"];
274 $order_by = db_escape_string($_REQUEST["order_by"]);
276 /* Updating a label ccache means recalculating all of the caches
277 * so for performance reasons we don't do that here */
279 // if (time() - $_SESSION["viewfeed:ccache_update_stamp"] > 120) {
281 ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
283 $_SESSION["viewfeed:ccache_update_stamp"] = time();
286 set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
287 set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
288 set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
290 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
291 db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW()
292 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
295 if (!$next_unread_feed) {
296 print "<headlines id=\"$feed\" is_cat=\"$cat_view\"><![CDATA[";
298 print "<headlines id=\"$next_unread_feed\" is_cat=\"$cat_view\"><![CDATA[";
301 $override_order = false;
305 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
306 $override_order = "updated";
308 $override_order = "updated DESC";
313 $override_order = "updated DESC";
317 $override_order = "score DESC";
321 $ret = outputHeadlinesList($link, $feed, $subop,
322 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
323 $vgroup_last_feed, $override_order);
325 $topmost_article_ids = $ret[0];
326 $headlines_count = $ret[1];
327 $returned_feed = $ret[2];
328 $disable_cache = $ret[3];
329 $vgroup_last_feed = $ret[4];
331 print "]]></headlines>";
333 print "<headlines-count value=\"$headlines_count\"/>";
334 print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
336 $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
339 if ($headlines_unread == -1) {
340 $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
344 print "<headlines-unread value=\"$headlines_unread\"/>";
345 printf("<disable-cache value=\"%d\"/>", $disable_cache);
347 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("10", $timing_info);
349 if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
351 foreach ($topmost_article_ids as $id) {
352 outputArticleXML($link, $id, $feed, false);
357 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
360 // if (get_pref($link, "SYNC_COUNTERS") ||
361 // time() - $_SESSION["get_all_counters_stamp"] > $viewfeed_ctr_interval) {
362 // print "<counters>";
363 // getAllCounters($link, $omode, $feed);
364 // print "</counters>";
367 if (get_pref($link, 'COMBINED_DISPLAY_MODE') ||
$subop ||
368 time() - $_SESSION["viewfeed:counters_stamp"] > 5) {
371 getAllCounters($link, $omode, $feed);
373 $_SESSION["viewfeed:counters_stamp"] = time();
377 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
379 print_runtime_info($link);
385 module_pref_feeds($link);
389 module_pref_filters($link);
390 break; // pref-filters
393 module_pref_labels($link);
394 break; // pref-labels
397 module_pref_prefs($link);
401 module_pref_users($link);
402 break; // prefs-users
409 module_popup_dialog($link);
412 case "pref-pub-items":
413 module_pref_pub_items($link);
414 break; // pref-pub-items
416 case "globalUpdateFeeds":
417 // update feeds of all users, may be used anonymously
420 // Update all feeds needing a update.
421 update_daemon_common($link, 0, true, true);
425 <message msg=\"All feeds updated\"/>
427 break; // globalUpdateFeeds
429 case "pref-feed-browser":
430 module_pref_feed_browser($link);
431 break; // pref-feed-browser
434 $key = db_escape_string($_REQUEST["key"]);
435 $limit = (int)db_escape_string($_REQUEST["limit"]);
437 $result = db_query($link, "SELECT login, owner_uid
438 FROM ttrss_user_prefs, ttrss_users WHERE
439 pref_name = '_PREFS_PUBLISH_KEY' AND
441 ttrss_users.id = owner_uid");
443 if (db_num_rows($result) == 1) {
444 $owner = db_fetch_result($result, 0, "owner_uid");
445 $login = db_fetch_result($result, 0, "login");
447 generate_syndicated_feed($link, $owner, -2, false, $limit);
450 print "<error>User not found</error>";
455 $feed = db_escape_string($_REQUEST["id"]);
456 $user = db_escape_string($_REQUEST["user"]);
457 $pass = db_escape_string($_REQUEST["pass"]);
458 $is_cat = $_REQUEST["is_cat"] != false;
459 $limit = (int)db_escape_string($_REQUEST["limit"]);
461 $search = db_escape_string($_REQUEST["q"]);
462 $match_on = db_escape_string($_REQUEST["m"]);
463 $search_mode = db_escape_string($_REQUEST["smode"]);
465 if (SINGLE_USER_MODE
) {
466 authenticate_user($link, "admin", null);
469 if (!$_SESSION["uid"] && $user && $pass) {
470 authenticate_user($link, $user, $pass);
473 if ($_SESSION["uid"] ||
474 http_authenticate_user($link)) {
476 generate_syndicated_feed($link, 0, $feed, $is_cat, $limit,
477 $search, $search_mode, $match_on);
482 $login = db_escape_string($_REQUEST["login"]);
484 header("Content-Type: text/plain; charset=utf-8");
486 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
488 if (db_num_rows($result) == 1) {
489 $uid = db_fetch_result($result, 0, "id");
490 print getGlobalUnread($link, $uid);
492 print "-1;User not found";
495 $print_exec_time = false;
499 header("Content-Type: text/plain");
500 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
501 $print_exec_time = false;
505 header("Content-Type: text/plain");
506 send_headlines_digests($link);
507 $print_exec_time = false;
511 $login = db_escape_string($_REQUEST["login"]);
512 $password = db_escape_string($_REQUEST["password"]);
514 if (authenticate_user($link, $login, $password)) {
515 $result = db_query($link, "SELECT * FROM ttrss_settings_profiles
516 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
518 print "<select style='width: 100%' name='profile'>";
520 print "<option value='0'>" . __("Default profile") . "</option>";
522 while ($line = db_fetch_assoc($result)) {
524 $title = $line["title"];
526 print "<option value='$id'>$title</option>";
536 } // Select action according to $op value.
538 // We close the connection to database.
542 <?php
if ($print_exec_time) { ?
>
543 <!-- <?php
echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->