backend.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. set_include_path(get_include_path() . PATH_SEPARATOR . "include");
  3. /* remove ill effects of magic quotes */
  4. if (get_magic_quotes_gpc()) {
  5. function stripslashes_deep($value) {
  6. $value = is_array($value) ?
  7. array_map('stripslashes_deep', $value) : stripslashes($value);
  8. return $value;
  9. }
  10. $_POST = array_map('stripslashes_deep', $_POST);
  11. $_GET = array_map('stripslashes_deep', $_GET);
  12. $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
  13. $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
  14. }
  15. function __autoload($class) {
  16. $file = "classes/".strtolower(basename($class)).".php";
  17. if (file_exists($file)) {
  18. require $file;
  19. }
  20. }
  21. $op = $_REQUEST["op"];
  22. require_once "functions.php";
  23. if ($op != "share") require_once "sessions.php";
  24. require_once "sanity_check.php";
  25. require_once "config.php";
  26. require_once "db.php";
  27. require_once "db-prefs.php";
  28. no_cache_incantation();
  29. startup_gettext();
  30. $script_started = getmicrotime();
  31. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  32. if (!$link) {
  33. if (DB_TYPE == "mysql") {
  34. print mysql_error();
  35. }
  36. // PG seems to display its own errors just fine by default.
  37. return;
  38. }
  39. init_connection($link);
  40. $method = strtolower($_REQUEST["method"]);
  41. $mode = $_REQUEST["mode"];
  42. /* if ((!$op || $op == "rss" || $op == "dlg") && !$_REQUEST["noxml"]) {
  43. header("Content-Type: application/xml; charset=utf-8");
  44. } else {
  45. header("Content-Type: text/plain; charset=utf-8");
  46. } */
  47. header("Content-Type: text/plain; charset=utf-8");
  48. if (ENABLE_GZIP_OUTPUT) {
  49. ob_start("ob_gzhandler");
  50. }
  51. if (SINGLE_USER_MODE) {
  52. authenticate_user($link, "admin", null);
  53. }
  54. $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
  55. "fbexport", "logout", "pubsub");
  56. if (array_search($op, $public_calls) !== false) {
  57. handle_public_request($link, $op);
  58. return;
  59. } else if (!($_SESSION["uid"] && validate_session($link))) {
  60. if ($op == 'pref-feeds' && $_REQUEST['method'] == 'add') {
  61. header("Content-Type: text/html");
  62. login_sequence($link);
  63. render_login_form($link);
  64. } else {
  65. header("Content-Type: text/plain");
  66. print json_encode(array("error" => array("code" => 6)));
  67. }
  68. return;
  69. }
  70. $purge_intervals = array(
  71. 0 => __("Use default"),
  72. -1 => __("Never purge"),
  73. 5 => __("1 week old"),
  74. 14 => __("2 weeks old"),
  75. 31 => __("1 month old"),
  76. 60 => __("2 months old"),
  77. 90 => __("3 months old"));
  78. $update_intervals = array(
  79. 0 => __("Default interval"),
  80. -1 => __("Disable updates"),
  81. 15 => __("Each 15 minutes"),
  82. 30 => __("Each 30 minutes"),
  83. 60 => __("Hourly"),
  84. 240 => __("Each 4 hours"),
  85. 720 => __("Each 12 hours"),
  86. 1440 => __("Daily"),
  87. 10080 => __("Weekly"));
  88. $update_intervals_nodefault = array(
  89. -1 => __("Disable updates"),
  90. 15 => __("Each 15 minutes"),
  91. 30 => __("Each 30 minutes"),
  92. 60 => __("Hourly"),
  93. 240 => __("Each 4 hours"),
  94. 720 => __("Each 12 hours"),
  95. 1440 => __("Daily"),
  96. 10080 => __("Weekly"));
  97. $update_methods = array(
  98. 0 => __("Default"),
  99. 1 => __("Magpie"),
  100. 2 => __("SimplePie"),
  101. 3 => __("Twitter OAuth"));
  102. if (DEFAULT_UPDATE_METHOD == "1") {
  103. $update_methods[0] .= ' (SimplePie)';
  104. } else {
  105. $update_methods[0] .= ' (Magpie)';
  106. }
  107. $access_level_names = array(
  108. 0 => __("User"),
  109. 5 => __("Power User"),
  110. 10 => __("Administrator"));
  111. $error = sanity_check($link);
  112. if ($error['code'] != 0 && $op != "logout") {
  113. print json_encode(array("error" => $error));
  114. return;
  115. }
  116. if (class_exists($op)) {
  117. $handler = new $op($link, $_REQUEST);
  118. if ($handler) {
  119. if ($handler->before()) {
  120. if ($method && method_exists($handler, $method)) {
  121. $handler->$method();
  122. } else if (method_exists($handler, 'index')) {
  123. $handler->index();
  124. }
  125. $handler->after();
  126. return;
  127. }
  128. }
  129. }
  130. switch($op) { // Select action according to $op value.
  131. case "pref-feeds":
  132. require_once "modules/pref-feeds.php";
  133. module_pref_feeds($link);
  134. break; // pref-feeds
  135. case "pref-filters":
  136. require_once "modules/pref-filters.php";
  137. module_pref_filters($link);
  138. break; // pref-filters
  139. case "pref-labels":
  140. require_once "modules/pref-labels.php";
  141. module_pref_labels($link);
  142. break; // pref-labels
  143. case "pref-prefs":
  144. require_once "modules/pref-prefs.php";
  145. module_pref_prefs($link);
  146. break; // pref-prefs
  147. case "pref-users":
  148. require_once "modules/pref-users.php";
  149. module_pref_users($link);
  150. break; // prefs-users
  151. case "help":
  152. require_once "modules/help.php";
  153. module_help($link);
  154. break; // help
  155. case "pref-instances":
  156. require_once "modules/pref-instances.php";
  157. module_pref_instances($link);
  158. break; // pref-instances
  159. case "digestTest":
  160. print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
  161. break; // digestTest
  162. case "digestSend":
  163. send_headlines_digests($link);
  164. break; // digestSend
  165. case "loading":
  166. header("Content-type: text/html");
  167. print __("Loading, please wait...") . " " .
  168. "<img src='images/indicator_tiny.gif'>";
  169. break; // loading
  170. default:
  171. header("Content-Type: text/plain");
  172. print json_encode(array("error" => array("code" => 7)));
  173. break; // fallback
  174. } // Select action according to $op value.
  175. // We close the connection to database.
  176. db_close($link);
  177. ?>