function log_api($module) { $ua = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/MIT[\s%20]+Mobile[\s\/]+([\w\.]+)\s*(.+)/', $ua, $matches)) { if (strpos($matches[2], 'Android')) { $platform = 'android'; } else { $platform = 'iphone'; } } elseif ($ua == 'Apache-HttpClient/UNAVAILABLE') { $platform = 'android'; } else { $platform = reset(explode(" ", $ua)); } PageViews::log_api($module, $platform); }
case 3: $id = isset($parts[1]) ? $parts[1] : ''; $command = isset($parts[2]) ? $parts[2] : ''; if (!$module = APIModule::factory($id, $command, $args)) { throw new Exception("Module $id cannot be loaded"); } break; default: throw new Exception("Invalid API request: '{$_SERVER['REQUEST_URI']}'", 1); break; } /* log the api call */ PageViews::log_api($id, Kurogo::deviceClassifier()->getPlatform()); $module->executeCommand(); } else { $id = $parts[0]; $page = 'index'; /* see if there's a redirect for this path */ if ($url_redirects = Kurogo::getSiteSection('urls')) { if (array_key_exists($id, $url_redirects)) { if (preg_match("#^http(s)?://#", $url_redirects[$id])) { $url = $url_redirects[$id]; } else { $parts[0] = $url_redirects[$id]; $url = URL_PREFIX . implode("/", $parts);
<?php require_once "../../config/mobi_web_constants.php"; require_once WEBROOT . "api/api_header.php"; PageViews::log_api('newsoffice', 'iphone'); define("FEED_STATE_NULL", 0); define("FEED_STATE_FRESH", 1); $channels = array(0 => 'All News', 1 => 'Engineering', 2 => 'Business', 3 => 'Science', 5 => 'Architecture and Planning', 6 => 'Humanities, Arts, and Social Sciences', 99 => 'Campus'); $channel_id = $_REQUEST['channel'] ? $_REQUEST['channel'] : 0; $cache_file = $cache_dir . $channel_id . '.xml'; $news_url = NEWSOFFICE_FEED_URL; $query = array('type' => 'dev'); if ($channel_id) { $query['category'] = $channel_id; } $xmldoc = new DOMDocument(); $is_fresh = FALSE; $loaded = load_from_cache($xmldoc, $channel_id); //$query['lastModified'] = $loaded; switch ($loaded) { case FEED_STATE_FRESH: break; case FEED_STATE_NULL: unset($query['lastModified']); default: // the HTTP extension is not currently installed in our build of PHP // so we just suppress warnings for 304 codes $error_reporting = intval(ini_get('error_reporting')); error_reporting($error_reporting & ~E_WARNING); $body = file_get_contents(NEWSOFFICE_FEED_URL . '?' . http_build_query($query)); error_reporting($error_reporting);
<? require_once "../config/mobi_web_constants.php"; require_once("api_header.php"); $module = $_REQUEST['module']; PageViews::log_api($module, 'iphone'); switch ($module) { case 'emergency': require('emergency.php'); break; case 'people': require('people.php'); break; case 'stellar': require('stellar.php'); break; case 'calendar': require('calendar.php'); break; case 'push': require('apns_push.php'); break; default: $data = Array('error' => 'not a valid query'); echo json_encode($data);
<? require_once "../../config/mobi_web_constants.php"; require_once WEBROOT . "shuttleschedule/shuttle_lib.php"; $APIROOT = WEBROOT . "/api"; require_once $APIROOT . "/api_header.php"; PageViews::log_api('shuttles', 'iphone'); $data = Array(); $command = $_REQUEST['command']; switch ($command) { case 'stops': $stops = NextBusReader::get_all_stops(); $data = array_values($stops); break; case 'stopInfo': $stops = NextBusReader::get_all_stops(); $time = time(); $stopId = $_REQUEST['id']; $stopInfo = $stops[$stopId]; if (!$stopInfo) { error_log("failed to get stop info for $stopId"); $data = Array('error' => 'could not get stop info'); } $data['stops'] = Array(); foreach ($stopInfo['routes'] as $route) { $gpsActive = ShuttleSchedule::is_running($route) && NextBusReader::gps_active($route); $stopTimes = list_stop_times($route, $time, $gpsActive, $stopId);
function _outputAPICall() { require_once realpath(LIB_DIR.'/PageViews.php'); if (isset($_REQUEST['module']) && $_REQUEST['module']) { $id = $_REQUEST['module']; $api = realpath_exists(LIB_DIR."/api/$id.php"); if ($id == 'shuttles') { $id = 'transit'; $api = realpath_exists(LIB_DIR."/api/$id.php"); } if ($api) { PageViews::log_api($id, $GLOBALS['deviceClassifier']->getPlatform()); $GLOBALS['siteConfig']->loadAPIFile($id, true, true); require_once($api); exit; } } _404(); }
<? require_once dirname(__FILE__) . "/../config/mobi_web_constants.php"; require_once WEBROOT . "api/api_header.php"; PageViews::log_api('map', 'iphone'); switch ($_REQUEST['command']) { case 'categories': require_once LIBDIR . "campus_map.php"; $categories = Buildings::category_titles(); $result = array(); foreach ($categories as $category => $category_text) { $result[] = array( 'categoryName' => $category_text, 'categoryId' => $category, 'categoryItems' => get_category($category), ); } echo json_encode($result); break; case 'category': require_once LIBDIR . "campus_map.php"; if ($category = $_REQUEST['id']) { $places = get_category($category); echo json_encode($places); } break; case 'categorytitles': require_once LIBDIR . "campus_map.php"; $categories = category_titles_wrapper();
$module = CoreAPIModule::factory($command, $args); break; case 3: $id = isset($parts[1]) ? $parts[1] : ''; $command = isset($parts[2]) ? $parts[2] : ''; $module = APIModule::factory($id, $command, $args); break; default: throw new Exception("Invalid API request: '{$_SERVER['REQUEST_URI']}'", 1); break; } /* log the api call */ PageViews::log_api($id, $GLOBALS['deviceClassifier']->getPlatform()); $module->executeCommand(); } else { $id = $parts[0]; /* see if there's a redirect for this path */ if ($url_redirects = $GLOBALS['siteConfig']->getSection('urls', ConfigFile::SUPRESS_ERRORS)) { if (array_key_exists($id, $url_redirects)) { if (preg_match("#^http(s)?://#", $url_redirects[$id])) { $url = $url_redirects[$id]; } else { $parts[0] = $url_redirects[$id]; $url = URL_PREFIX . implode("/", $parts); }