PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/backend.php

https://github.com/kpadilha/Tiny-Tiny-RSS
PHP | 153 lines | 114 code | 31 blank | 8 comment | 23 complexity | 1ef0eb6751c7b1da579cb8f434b1da8b MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.0, LGPL-3.0, GPL-3.0
  1. <?php
  2. set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
  3. get_include_path());
  4. /* remove ill effects of magic quotes */
  5. if (get_magic_quotes_gpc()) {
  6. function stripslashes_deep($value) {
  7. $value = is_array($value) ?
  8. array_map('stripslashes_deep', $value) : stripslashes($value);
  9. return $value;
  10. }
  11. $_POST = array_map('stripslashes_deep', $_POST);
  12. $_GET = array_map('stripslashes_deep', $_GET);
  13. $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
  14. $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
  15. }
  16. $op = $_REQUEST["op"];
  17. @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
  18. if (!$method)
  19. $method = 'index';
  20. else
  21. $method = strtolower($method);
  22. /* Public calls compatibility shim */
  23. $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
  24. "fbexport", "logout", "pubsub");
  25. if (array_search($op, $public_calls) !== false) {
  26. header("Location: public.php?" . $_SERVER['QUERY_STRING']);
  27. return;
  28. }
  29. @$csrf_token = $_REQUEST['csrf_token'];
  30. require_once "sessions.php";
  31. require_once "functions.php";
  32. require_once "config.php";
  33. require_once "db.php";
  34. require_once "db-prefs.php";
  35. startup_gettext();
  36. $script_started = microtime(true);
  37. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  38. if (!init_connection($link)) return;
  39. header("Content-Type: text/json; charset=utf-8");
  40. if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) {
  41. ob_start("ob_gzhandler");
  42. }
  43. if (SINGLE_USER_MODE) {
  44. authenticate_user($link, "admin", null);
  45. }
  46. if ($_SESSION["uid"]) {
  47. load_user_plugins($link, $_SESSION["uid"]);
  48. }
  49. $purge_intervals = array(
  50. 0 => __("Use default"),
  51. -1 => __("Never purge"),
  52. 5 => __("1 week old"),
  53. 14 => __("2 weeks old"),
  54. 31 => __("1 month old"),
  55. 60 => __("2 months old"),
  56. 90 => __("3 months old"));
  57. $update_intervals = array(
  58. 0 => __("Default interval"),
  59. -1 => __("Disable updates"),
  60. 15 => __("Each 15 minutes"),
  61. 30 => __("Each 30 minutes"),
  62. 60 => __("Hourly"),
  63. 240 => __("Each 4 hours"),
  64. 720 => __("Each 12 hours"),
  65. 1440 => __("Daily"),
  66. 10080 => __("Weekly"));
  67. $update_intervals_nodefault = array(
  68. -1 => __("Disable updates"),
  69. 15 => __("Each 15 minutes"),
  70. 30 => __("Each 30 minutes"),
  71. 60 => __("Hourly"),
  72. 240 => __("Each 4 hours"),
  73. 720 => __("Each 12 hours"),
  74. 1440 => __("Daily"),
  75. 10080 => __("Weekly"));
  76. $access_level_names = array(
  77. 0 => __("User"),
  78. 5 => __("Power User"),
  79. 10 => __("Administrator"));
  80. #$error = sanity_check($link);
  81. #if ($error['code'] != 0 && $op != "logout") {
  82. # print json_encode(array("error" => $error));
  83. # return;
  84. #}
  85. $op = str_replace("-", "_", $op);
  86. global $pluginhost;
  87. $override = $pluginhost->lookup_handler($op, $method);
  88. if (class_exists($op) || $override) {
  89. if ($override) {
  90. $handler = $override;
  91. } else {
  92. $handler = new $op($link, $_REQUEST);
  93. }
  94. if ($handler && implements_interface($handler, 'IHandler')) {
  95. if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
  96. if ($handler->before($method)) {
  97. if ($method && method_exists($handler, $method)) {
  98. $handler->$method();
  99. } else {
  100. if (method_exists($handler, "catchall")) {
  101. $handler->catchall($method);
  102. }
  103. }
  104. $handler->after();
  105. return;
  106. } else {
  107. header("Content-Type: text/json");
  108. print json_encode(array("error" => array("code" => 6)));
  109. return;
  110. }
  111. } else {
  112. header("Content-Type: text/json");
  113. print json_encode(array("error" => array("code" => 6)));
  114. return;
  115. }
  116. }
  117. }
  118. header("Content-Type: text/json");
  119. print json_encode(array("error" => array("code" => 7)));
  120. // We close the connection to database.
  121. db_close($link);
  122. ?>