<?php
require_once(dirname(__FILE__).'/config.inc.php');
require_once(dirname(__FILE__).'/lib/FT/App.class.php');
require_once(dirname(__FILE__).'/lib/FT/App/SiteApp.class.php');
require_once(dirname(__FILE__).'/lib/FT/App/CampaignApp.class.php');
require_once(dirname(__FILE__).'/lib/FT/App/AdminApp.class.php');
$app_args = array('doc_root' => dirname(__FILE__),
'template_dir' => dirname(__FILE__) . '/style/templates',
'www_host' => $_SERVER['HTTP_HOST'],
'www_root' => "http://{$_SERVER['HTTP_HOST']}" . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'),
/*
'www_root' => ($_SERVER['REQUEST_URI'] == $_SERVER['REDIRECT_URL'])
? "http://{$_SERVER['HTTP_HOST']}" . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/')
: $_SERVER['SCRIPT_NAME'],
*/
'path_info' => rtrim($_SERVER['PATH_INFO'], '/'),
'cache_dir' => dirname(__FILE__) . 'cache' // This was causing an array index warning
);
function remaining(&$path)
{ return array_splice($path, (key($path) + 1)); }
$path = explode('/', trim($_SERVER['PATH_INFO'], '/'));
switch($base = reset($path)) {
case 'admin':
$app = FT_APP_ADMIN_APP_CLASS; $app = new $app($app_args);
switch($action = next($path)) {
case 'view':
case 'stats':
case 'map-data':
if($campaign = next($path)) {
$app->run(array('action' => $action, 'campaign' => $campaign, 'path' => remaining($path)));
} else {
end($path);
$app->run(array('action' => $action, 'campaign' => null, 'path' => remaining($path)));
}
break;
case 'dump':
case 'edit':
case 'delete':
if($campaign = next($path)) {
$app->run(array('action' => $action, 'campaign' => $campaign, 'path' => remaining($path)));
} else {
$app->throw_error("missing campaign");
}
break;
case 'install':
case 'docs':
case 'purge':
case 'new':
$app->run(array('action' => $action, 'campaign' => null, 'path' => remaining($path)));
break;
case false:
$app->run();
break;
default:
prev($path);
$app->run(array('action' => null, 'campaign' => null, 'path' => remaining($path)));
break;
}
break;
case 'campaigns':
if($campaign = next($path)) {
$app = FT_APP_CAMPAIGN_APP_CLASS; $app = new $app($app_args);
switch($action = next($path)) {
case 'preview':
$app->run(array('action' => $action, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path)));
break;
case 'register':
case 'map':
case 'map-data':
if($node = next($path)) {
$app->run(array('action' => $action, 'node' => $node, 'campaign' => $campaign, 'path' => remaining($path)));
} else {
end($path);
$app->run(array('action' => $action, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path)));
}
break;
case 'impact':
case 'browse':
case 'invite':
case 'accept':
if($node = next($path)) {
$app->run(array('action' => $action, 'node' => $node, 'campaign' => $campaign, 'path' => remaining($path)));
} else {
$app->throw_error("missing node");
}
break;
case false:
$app->run(array('action' => null, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path)));
break;
default:
prev($path);
$app->run(array('action' => null, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path)));
break;
}
} else {
$app = FT_APP_SITE_APP_CLASS; $app = new $app($app_args);
$app->run(array('action' => 'campaigns'));
break;
}
break;
case false:
$app = FT_APP_CAMPAIGN_APP_CLASS; $app = new $app($app_args);
$app->run(array('action' => null, 'node' => null, 'campaign' => null, 'path' => remaining($path)));
break;
default:
$app = FT_APP_SITE_APP_CLASS; $app = new $app($app_args);
$app->run(array('action' => $base, 'path' => remaining($path)));
break;
}
?>