function renderData($data) { if (empty($_REQUEST['output'])) { $_REQUEST['output'] = PAGEID === 'api' ? 'json' : 'html'; } $o = $_REQUEST['output']; switch ($o) { case 'html': header('Content-Type: text/html'); return WhomsyView::template($o, $data); break; case 'xml': header('Content-Type: application/xml'); return WhomsyView::template($o, $data); break; default: // json $data['message'] = htmlentities($data['message']); $json = json_encode($data); if (!empty($_REQUEST['callback'])) { //header('application/javascript'); return htmlentities($_REQUEST['callback']) . '(' . $json . ')'; } else { //header('application/json'); return $json; } break; } }
// make sense of the request $url = parse_url($_SERVER['REQUEST_URI']); if (empty($_REQUEST) && !empty($url['query'])) { // dreamhost quirk with phpcgi parse_str($url['query'], $_REQUEST); } $url = $url['path']; $self = dirname($_SERVER['PHP_SELF']); if ($self !== '/') { // app not in the server root $url = str_replace($self, '', $url); $self = $self . '/'; } $url = ltrim($url, '/'); $request = explode('/', $url); if (!in_array($request[0], array_keys($conf))) { $request[0] = 'home'; } // define useful constants define('HOME', $self); define('PAGEID', $request[0]); // the requested page define('DOMAIN', !empty($_REQUEST['domain']) ? $_REQUEST['domain'] : @$request[1]); // domain, if any $conf = $conf[PAGEID]; // config for the requested page // the "business" logic $data = WhomsyModel::getData($conf, DOMAIN); // render the view WhomsyView::render($data, $conf);