]> git.wh0rd.org Git - tt-rss.git/blob - public.php
move API to classes/
[tt-rss.git] / public.php
1 <?php
2         set_include_path(get_include_path() . PATH_SEPARATOR . "include");
3
4         /* remove ill effects of magic quotes */
5
6         if (get_magic_quotes_gpc()) {
7                 function stripslashes_deep($value) {
8                         $value = is_array($value) ?
9                                 array_map('stripslashes_deep', $value) : stripslashes($value);
10                                 return $value;
11                 }
12
13                 $_POST = array_map('stripslashes_deep', $_POST);
14                 $_GET = array_map('stripslashes_deep', $_GET);
15                 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
16                 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
17         }
18
19         require_once "functions.php";
20         require_once "sessions.php";
21         require_once "sanity_check.php";
22         require_once "config.php";
23         require_once "db.php";
24         require_once "db-prefs.php";
25
26         no_cache_incantation();
27
28         startup_gettext();
29
30         $script_started = getmicrotime();
31
32         $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
33
34         if (!init_connection($link)) return;
35
36         if (ENABLE_GZIP_OUTPUT) {
37                 ob_start("ob_gzhandler");
38         }
39
40         function __autoload($class) {
41                 $file = "classes/".strtolower(basename($class)).".php";
42                 if (file_exists($file)) {
43                         require $file;
44                 }
45         }
46
47         $method = $_REQUEST["op"];
48
49         $handler = new Public_Handler($link, $_REQUEST);
50
51         if ($handler->before($method)) {
52                 if ($method && method_exists($handler, $method)) {
53                         $handler->$method();
54                 } else if (method_exists($handler, 'index')) {
55                         $handler->index();
56                 }
57                 $handler->after();
58                 return;
59         }
60
61         header("Content-Type: text/plain");
62         print json_encode(array("error" => array("code" => 7)));
63
64         // We close the connection to database.
65         db_close($link);
66 ?>