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"];
53 $print_exec_time = false;
55 if ((!$op ||
$op == "rpc" ||
$op == "rss" ||
$op == "view" ||
56 $op == "digestSend" ||
$op == "viewfeed" ||
$op == "publish" ||
57 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
58 header("Content-Type: application/xml; charset=utf-8");
60 if (ENABLE_GZIP_OUTPUT
) {
61 ob_start("ob_gzhandler");
65 if (!$_REQUEST["noxml"]) {
66 header("Content-Type: text/html; charset=utf-8");
68 header("Content-Type: text/plain; charset=utf-8");
73 header("Content-Type: application/xml");
74 print_error_xml(7); exit;
77 if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
78 && $op != "rss" && $op != "getUnread" && $op != "publish") {
80 if ($op == "rpc" ||
$op == "viewfeed" ||
$op == "view") {
81 print_error_xml(6); die;
85 <p>Error: Not logged in.</p>
86 <script type=\"text/javascript\">
87 if (parent.window != 'undefined') {
88 parent.window.location = \"tt-rss.php\";
90 window.location = \"tt-rss.php\";
99 $purge_intervals = array(
100 0 => __("Use default"),
101 -1 => __("Never purge"),
102 5 => __("1 week old"),
103 14 => __("2 weeks old"),
104 31 => __("1 month old"),
105 60 => __("2 months old"),
106 90 => __("3 months old"));
108 $update_intervals = array(
109 0 => __("Default interval"),
110 -1 => __("Disable updates"),
111 15 => __("Each 15 minutes"),
112 30 => __("Each 30 minutes"),
114 240 => __("Each 4 hours"),
115 720 => __("Each 12 hours"),
117 10080 => __("Weekly"));
119 $update_methods = array(
122 2 => __("SimplePie"));
124 if (ENABLE_SIMPLEPIE
) {
125 $update_methods[0] .= ' (SimplePie)';
127 $update_methods[0] .= ' (Magpie)';
130 $access_level_names = array(
132 5 => __("Power User"),
133 10 => __("Administrator"));
135 require_once "modules/pref-prefs.php";
136 require_once "modules/popup-dialog.php";
137 require_once "modules/help.php";
138 require_once "modules/pref-feeds.php";
139 require_once "modules/pref-filters.php";
140 require_once "modules/pref-labels.php";
141 require_once "modules/pref-users.php";
142 require_once "modules/pref-feed-browser.php";
144 if (!sanity_check($link)) { return; }
146 switch($op) { // Select action according to $op value.
148 // Handle remote procedure calls.
149 handle_rpc_request($link);
153 if (ENABLE_GZIP_OUTPUT
) {
154 ob_start("ob_gzhandler");
157 $tags = $_GET["tags"];
159 $subop = $_GET["subop"];
163 db_query($link, "UPDATE ttrss_user_entries SET
164 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
168 $cat_id = db_escape_string($_GET["cid"]);
170 db_query($link, "UPDATE ttrss_feed_categories SET
171 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
177 db_query($link, "UPDATE ttrss_feed_categories
178 SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
183 $corder = db_escape_string($_GET["corder"]);
185 $cats = split(",", $corder);
187 for ($i = 0; $i < count($cats); $i++
) {
191 db_query($link, "UPDATE ttrss_feed_categories
192 SET order_id = '$i' WHERE id = '$cat_id' AND
193 owner_uid = " . $_SESSION["uid"]);
202 outputFeedList($link, $tags);
207 $id = db_escape_string($_GET["id"]);
208 $feed_id = db_escape_string($_GET["feed"]);
209 $cids = split(",", db_escape_string($_GET["cids"]));
210 $mode = db_escape_string($_GET["mode"]);
211 $omode = db_escape_string($_GET["omode"]);
213 $csync = $_GET["csync"];
217 // in prefetch mode we only output requested cids, main article
218 // just gets marked as read (it already exists in client cache)
221 outputArticleXML($link, $id, $feed_id);
222 } else if ($mode == "zoom") {
223 outputArticleXML($link, $id, $feed_id, true, true);
225 catchupArticleById($link, $id, 0);
228 if (!$_SESSION["bw_limit"]) {
229 foreach ($cids as $cid) {
231 outputArticleXML($link, $cid, $feed_id, false);
237 if (get_pref($link, "SYNC_COUNTERS") ||
($mode == "prefetch" && $csync)) {
239 getAllCounters($link, $omode);
248 $print_exec_time = true;
249 $timing_info = getmicrotime();
253 if ($_GET["debug"]) $timing_info = print_checkpoint("0", $timing_info);
255 $omode = db_escape_string($_GET["omode"]);
257 $feed = db_escape_string($_GET["feed"]);
258 $subop = db_escape_string($_GET["subop"]);
259 $view_mode = db_escape_string($_GET["view_mode"]);
260 $limit = db_escape_string($_GET["limit"]);
261 $cat_view = db_escape_string($_GET["cat"]);
262 $next_unread_feed = db_escape_string($_GET["nuf"]);
263 $offset = db_escape_string($_GET["skip"]);
264 $vgroup_last_feed = db_escape_string($_GET["vgrlf"]);
265 $csync = $_GET["csync"];
266 $order_by = db_escape_string($_GET["order_by"]);
268 set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
269 set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
270 set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
272 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
273 db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW()
274 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
277 print "<headlines id=\"$feed\"><![CDATA[";
281 generate_dashboard_feed($link);
285 $override_order = false;
289 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
290 $override_order = "updated";
292 $override_order = "updated DESC";
297 $override_order = "updated DESC";
301 $override_order = "score DESC";
305 $ret = outputHeadlinesList($link, $feed, $subop,
306 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
307 $vgroup_last_feed, $override_order);
309 $topmost_article_ids = $ret[0];
310 $headlines_count = $ret[1];
311 $returned_feed = $ret[2];
312 $disable_cache = $ret[3];
313 $vgroup_last_feed = $ret[4];
315 print "]]></headlines>";
317 print "<headlines-count value=\"$headlines_count\"/>";
318 print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
320 $headlines_unread = getFeedUnread($link, $returned_feed);
322 print "<headlines-unread value=\"$headlines_unread\"/>";
323 printf("<disable-cache value=\"%d\"/>", $disable_cache);
325 if ($_GET["debug"]) $timing_info = print_checkpoint("10", $timing_info);
327 if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
329 foreach ($topmost_article_ids as $id) {
330 outputArticleXML($link, $id, $feed, false);
336 if ($_GET["debug"]) $timing_info = print_checkpoint("20", $timing_info);
338 $viewfeed_ctr_interval = 300;
340 if ($csync ||
$_SESSION["bw_limit"]) {
341 $viewfeed_ctr_interval = 60;
344 if (get_pref($link, "SYNC_COUNTERS") ||
345 time() - $_SESSION["get_all_counters_stamp"] > $viewfeed_ctr_interval) {
347 getAllCounters($link, $omode, $feed);
351 if ($_GET["debug"]) $timing_info = print_checkpoint("30", $timing_info);
353 print_runtime_info($link);
359 module_pref_feeds($link);
363 module_pref_filters($link);
364 break; // pref-filters
367 module_pref_labels($link);
368 break; // pref-labels
371 module_pref_prefs($link);
375 module_pref_users($link);
376 break; // prefs-users
383 module_popup_dialog($link);
386 case "pref-pub-items":
387 module_pref_pub_items($link);
388 break; // pref-pub-items
390 case "globalUpdateFeeds":
391 // update feeds of all users, may be used anonymously
394 // Update all feeds needing a update.
395 update_daemon_common($link, 0, true, true);
398 // FIXME : old feed update way. To be removed.
399 //$result = db_query($link, "SELECT id FROM ttrss_users");
401 //while ($line = db_fetch_assoc($result)) {
402 // $user_id = $line["id"];
403 // print "<!-- updating feeds of uid $user_id -->";
404 // update_all_feeds($link, false, $user_id);
408 <message msg=\"All feeds updated\"/>
410 break; // globalUpdateFeeds
412 case "pref-feed-browser":
413 module_pref_feed_browser($link);
414 break; // pref-feed-browser
417 $key = db_escape_string($_GET["key"]);
419 $result = db_query($link, "SELECT login, owner_uid
420 FROM ttrss_user_prefs, ttrss_users WHERE
421 pref_name = '_PREFS_PUBLISH_KEY' AND
423 ttrss_users.id = owner_uid");
425 if (db_num_rows($result) == 1) {
426 $owner = db_fetch_result($result, 0, "owner_uid");
427 $login = db_fetch_result($result, 0, "login");
429 generate_syndicated_feed($link, $owner, -2, false);
432 print "<error>User not found</error>";
437 $feed = db_escape_string($_GET["id"]);
438 $user = db_escape_string($_GET["user"]);
439 $pass = db_escape_string($_GET["pass"]);
440 $is_cat = $_GET["is_cat"] != false;
442 $search = db_escape_string($_GET["q"]);
443 $match_on = db_escape_string($_GET["m"]);
444 $search_mode = db_escape_string($_GET["smode"]);
446 if (!$_SESSION["uid"] && $user && $pass) {
447 authenticate_user($link, $user, $pass);
450 if ($_SESSION["uid"] ||
451 http_authenticate_user($link)) {
453 generate_syndicated_feed($link, 0, $feed, $is_cat,
454 $search, $search_mode, $match_on);
458 case "labelFromSearch":
459 $search = db_escape_string($_GET["search"]);
460 $search_mode = db_escape_string($_GET["smode"]);
461 $match_on = db_escape_string($_GET["match"]);
462 $is_cat = db_escape_string($_GET["is_cat"]);
463 $title = db_escape_string($_GET["title"]);
464 $feed = sprintf("%d", $_GET["feed"]);
466 $label_qparts = array();
468 $search_expr = getSearchSql($search, $match_on);
472 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
474 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
477 if ($search_mode == "all_feeds") {
479 } else if ($search_mode == "this_cat") {
481 $tmp_result = db_query($link, "SELECT cat_id
482 FROM ttrss_feeds WHERE id = '$feed'");
484 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
487 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
489 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
492 $search_expr .= " AND ttrss_feeds.id = $feed ";
497 $search_expr = db_escape_string($search_expr);
502 $result = db_query($link,
503 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
504 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
506 break; // labelFromSearch
509 $login = db_escape_string($_GET["login"]);
511 header("Content-Type: text/plain; charset=utf-8");
513 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
515 if (db_num_rows($result) == 1) {
516 $uid = db_fetch_result($result, 0, "id");
517 print getGlobalUnread($link, $uid);
519 print "-1;User not found";
522 $print_exec_time = false;
526 header("Content-Type: text/plain");
527 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
528 $print_exec_time = false;
532 header("Content-Type: text/plain");
533 send_headlines_digests($link);
534 $print_exec_time = false;
537 } // Select action according to $op value.
539 // We close the connection to database.
543 <?php
if ($print_exec_time) { ?
>
544 <!-- <?php
echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->