예제 #1
0
파일: view.php 프로젝트: stoyan/whomsy
 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;
     }
 }
예제 #2
0
파일: index.php 프로젝트: stoyan/whomsy
// 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);