00001 <?php
00018 error_reporting(E_ALL | E_STRICT);
00019 date_default_timezone_set("America/Los_Angeles");
00020
00021 require_once("models/soc1c.php");
00022 require_once("models/api1c.php");
00023
00024 isset($_GET) ? $get = $_GET : $get = array();
00025 isset($_POST) ? $post = $_POST : $post = array();
00026 isset($_SESSION) ? $session = $_SESSION : $session = array();
00027 isset($_SERVER) ? $server = $_SERVER : $server = array();
00028 isset($_FILE) ? $file = $_FILE : $server = array();
00029 isset($argv[1]) ? $server['PATH_INFO'] = trim($argv[1]) : "";
00030
00031 session_start();
00032 if (isset($_FILE)) {
00033 $file = $_FILE;
00034 } else {
00035 $file = NULL;
00036 }
00037 if (isset($_SERVER['PATH_INFO']) && trim (substr($_SERVER['PATH_INFO'],1))) {
00038 $api = new SOC_API1C(new SOC_Configuration("SOC API 1C - Schedule of Classes","soc1c.conf"));
00039 if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] === '/help') {
00040 header("Location: " . $api->get("soc_uri") . "/help.php");
00041 exit(0);
00042 }
00043
00044 if (isset($_GET['refresh'])){
00045 $refreshkey = $api->get("soc_cache_refresh_key");
00046 if ($refreshkey === false) {
00047 die("Refresh from API not turned on");
00048 }
00049 $keyprovided = urldecode($_GET['refresh']);
00050 if (strcmp($refreshkey, $keyprovided) !== 0) {
00051 die("What? $keyprovided ");
00052 }
00053 $api->set("cache_replace",true);
00054 }
00055 $api->eventloop($_GET, $_POST, $_SESSION, $_SERVER, $file);
00056 header("Content Type: ".$api->contentType());
00057 if ($api->errorCount() == 0) {
00058 if (isset($_GET['jsonp_callback'])) {
00059 $jsonp_callback = strip_tags(str_replace(array('"',"'",' '),'', urldecode($_GET['jsonp_callback'])));
00060 echo $jsonp_callback. '('.$api->render().')';
00061 } else {
00062 echo $api->render();
00063 }
00064 } else {
00065 if (isset($_GET['jsonp_callback'])) {
00066 $jsonp_callback = strip_tags(str_replace(array('"',"'",' '),'', urldecode($_GET['jsonp_callback'])));
00067 echo 'var ' . $jsonp_callback. ' = function () { return ('.json_encode(array('error' => $api->errors())).');};';
00068 } else {
00069 echo json_encode(array('error' => $api->errors()));
00070 }
00071 }
00072 $api->close();
00073 } else {
00074 header("Location: ../help");
00075 exit(0);
00076 }
00077 ?>