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 (SINGLE_USER_MODE
) {
80 authenticate_user($link, "admin", null);
83 if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
84 && $op != "rss" && $op != "getUnread" && $op != "publish") {
86 if ($op == "rpc" ||
$op == "viewfeed" ||
$op == "view") {
87 print_error_xml(6); die;
91 <p>Error: Not logged in.</p>
92 <script type=\"text/javascript\">
93 if (parent.window != 'undefined') {
94 parent.window.location = \"tt-rss.php\";
96 window.location = \"tt-rss.php\";
105 $purge_intervals = array(
106 0 => __("Use default"),
107 -1 => __("Never purge"),
108 5 => __("1 week old"),
109 14 => __("2 weeks old"),
110 31 => __("1 month old"),
111 60 => __("2 months old"),
112 90 => __("3 months old"));
114 $update_intervals = array(
115 0 => __("Default interval"),
116 -1 => __("Disable updates"),
117 15 => __("Each 15 minutes"),
118 30 => __("Each 30 minutes"),
120 240 => __("Each 4 hours"),
121 720 => __("Each 12 hours"),
123 10080 => __("Weekly"));
125 $update_methods = array(
128 2 => __("SimplePie"));
130 if (ENABLE_SIMPLEPIE
) {
131 $update_methods[0] .= ' (SimplePie)';
133 $update_methods[0] .= ' (Magpie)';
136 $access_level_names = array(
138 5 => __("Power User"),
139 10 => __("Administrator"));
141 require_once "modules/pref-prefs.php";
142 require_once "modules/popup-dialog.php";
143 require_once "modules/help.php";
144 require_once "modules/pref-feeds.php";
145 require_once "modules/pref-filters.php";
146 require_once "modules/pref-labels.php";
147 require_once "modules/pref-users.php";
149 if (!sanity_check($link)) { return; }
151 switch($op) { // Select action according to $op value.
153 // Handle remote procedure calls.
154 handle_rpc_request($link);
158 if (ENABLE_GZIP_OUTPUT
) {
159 ob_start("ob_gzhandler");
162 $tags = $_GET["tags"];
164 $subop = $_GET["subop"];
168 db_query($link, "UPDATE ttrss_user_entries SET
169 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
170 ccache_zero_all($link, $_SESSION["uid"]);
175 $cat_id = db_escape_string($_GET["cid"]);
176 toggle_collapse_cat($link, $cat_id);
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 $_SESSION["viewfeed:counters_stamp"] = time();
208 outputFeedList($link, $tags);
213 $id = db_escape_string($_GET["id"]);
214 $feed_id = db_escape_string($_GET["feed"]);
215 $cids = split(",", db_escape_string($_GET["cids"]));
216 $mode = db_escape_string($_GET["mode"]);
217 $omode = db_escape_string($_GET["omode"]);
219 $csync = $_GET["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, $feed_id);
228 } else if ($mode == "zoom") {
229 outputArticleXML($link, $id, $feed_id, true, true);
231 catchupArticleById($link, $id, 0);
232 ccache_update($link, $feed_id, $_SESSION["uid"]);
235 if (!$_SESSION["bw_limit"]) {
236 foreach ($cids as $cid) {
238 outputArticleXML($link, $cid, $feed_id, false);
243 // if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
245 if (time() - $_SESSION["view:counters_stamp"] > 3 && $mode == "prefetch") {
247 getAllCounters($link, $omode);
249 $_SESSION["view:counters_stamp"] = time();
257 $print_exec_time = true;
258 $timing_info = getmicrotime();
262 if ($_GET["debug"]) $timing_info = print_checkpoint("0", $timing_info);
264 $omode = db_escape_string($_GET["omode"]);
266 $feed = db_escape_string($_GET["feed"]);
267 $subop = db_escape_string($_GET["subop"]);
268 $view_mode = db_escape_string($_GET["view_mode"]);
269 $limit = db_escape_string($_GET["limit"]);
270 $cat_view = db_escape_string($_GET["cat"]);
271 $next_unread_feed = db_escape_string($_GET["nuf"]);
272 $offset = db_escape_string($_GET["skip"]);
273 $vgroup_last_feed = db_escape_string($_GET["vgrlf"]);
274 $csync = $_GET["csync"];
275 $order_by = db_escape_string($_GET["order_by"]);
277 /* Updating a label ccache means recalculating all of the caches
278 * so for performance reasons we don't do that here */
280 // if (time() - $_SESSION["viewfeed:ccache_update_stamp"] > 120) {
282 ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
284 $_SESSION["viewfeed:ccache_update_stamp"] = time();
287 set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
288 set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
289 set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
291 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
292 db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW()
293 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
296 if (!$next_unread_feed) {
297 print "<headlines id=\"$feed\" is_cat=\"$cat_view\"><![CDATA[";
299 print "<headlines id=\"$next_unread_feed\" is_cat=\"$cat_view\"><![CDATA[";
302 $override_order = false;
306 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
307 $override_order = "updated";
309 $override_order = "updated DESC";
314 $override_order = "updated DESC";
318 $override_order = "score DESC";
322 $ret = outputHeadlinesList($link, $feed, $subop,
323 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
324 $vgroup_last_feed, $override_order);
326 $topmost_article_ids = $ret[0];
327 $headlines_count = $ret[1];
328 $returned_feed = $ret[2];
329 $disable_cache = $ret[3];
330 $vgroup_last_feed = $ret[4];
332 print "]]></headlines>";
334 print "<headlines-count value=\"$headlines_count\"/>";
335 print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
337 $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
340 if ($headlines_unread == -1) {
341 $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
345 print "<headlines-unread value=\"$headlines_unread\"/>";
346 printf("<disable-cache value=\"%d\"/>", $disable_cache);
348 if ($_GET["debug"]) $timing_info = print_checkpoint("10", $timing_info);
350 if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
352 foreach ($topmost_article_ids as $id) {
353 outputArticleXML($link, $id, $feed, false);
358 if ($_GET["debug"]) $timing_info = print_checkpoint("20", $timing_info);
361 // if (get_pref($link, "SYNC_COUNTERS") ||
362 // time() - $_SESSION["get_all_counters_stamp"] > $viewfeed_ctr_interval) {
363 // print "<counters>";
364 // getAllCounters($link, $omode, $feed);
365 // print "</counters>";
368 if (get_pref($link, 'COMBINED_DISPLAY_MODE') ||
$subop ||
369 time() - $_SESSION["viewfeed:counters_stamp"] > 60) {
372 getAllCounters($link, $omode, $feed);
374 $_SESSION["viewfeed:counters_stamp"] = time();
378 if ($_GET["debug"]) $timing_info = print_checkpoint("30", $timing_info);
380 print_runtime_info($link);
386 module_pref_feeds($link);
390 module_pref_filters($link);
391 break; // pref-filters
394 module_pref_labels($link);
395 break; // pref-labels
398 module_pref_prefs($link);
402 module_pref_users($link);
403 break; // prefs-users
410 module_popup_dialog($link);
413 case "pref-pub-items":
414 module_pref_pub_items($link);
415 break; // pref-pub-items
417 case "globalUpdateFeeds":
418 // update feeds of all users, may be used anonymously
421 // Update all feeds needing a update.
422 update_daemon_common($link, 0, true, true);
426 <message msg=\"All feeds updated\"/>
428 break; // globalUpdateFeeds
430 case "pref-feed-browser":
431 module_pref_feed_browser($link);
432 break; // pref-feed-browser
435 $key = db_escape_string($_GET["key"]);
436 $limit = (int)db_escape_string($_GET["limit"]);
438 $result = db_query($link, "SELECT login, owner_uid
439 FROM ttrss_user_prefs, ttrss_users WHERE
440 pref_name = '_PREFS_PUBLISH_KEY' AND
442 ttrss_users.id = owner_uid");
444 if (db_num_rows($result) == 1) {
445 $owner = db_fetch_result($result, 0, "owner_uid");
446 $login = db_fetch_result($result, 0, "login");
448 generate_syndicated_feed($link, $owner, -2, false, $limit);
451 print "<error>User not found</error>";
456 $feed = db_escape_string($_GET["id"]);
457 $user = db_escape_string($_GET["user"]);
458 $pass = db_escape_string($_GET["pass"]);
459 $is_cat = $_GET["is_cat"] != false;
460 $limit = (int)db_escape_string($_GET["limit"]);
462 $search = db_escape_string($_GET["q"]);
463 $match_on = db_escape_string($_GET["m"]);
464 $search_mode = db_escape_string($_GET["smode"]);
466 if (SINGLE_USER_MODE
) {
467 authenticate_user($link, "admin", null);
470 if (!$_SESSION["uid"] && $user && $pass) {
471 authenticate_user($link, $user, $pass);
474 if ($_SESSION["uid"] ||
475 http_authenticate_user($link)) {
477 generate_syndicated_feed($link, 0, $feed, $is_cat, $limit,
478 $search, $search_mode, $match_on);
483 $login = db_escape_string($_GET["login"]);
485 header("Content-Type: text/plain; charset=utf-8");
487 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
489 if (db_num_rows($result) == 1) {
490 $uid = db_fetch_result($result, 0, "id");
491 print getGlobalUnread($link, $uid);
493 print "-1;User not found";
496 $print_exec_time = false;
500 header("Content-Type: text/plain");
501 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
502 $print_exec_time = false;
506 header("Content-Type: text/plain");
507 send_headlines_digests($link);
508 $print_exec_time = false;
511 } // Select action according to $op value.
513 // We close the connection to database.
517 <?php
if ($print_exec_time) { ?
>
518 <!-- <?php
echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->