jamiew / forwardtrack
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
6191182
commit 6191182c511216c090678c8645393d14537684cb
tree 1fd4d5b27dea041c792336a36c289d1dc9f2ec17
parent 92f05c2b5c0fa0424576a1ebe84f6aebaebadb35
tree 1fd4d5b27dea041c792336a36c289d1dc9f2ec17
parent 92f05c2b5c0fa0424576a1ebe84f6aebaebadb35
forwardtrack / dispatch.php
| 92f05c2b » | jamiew | 2008-04-15 | 1 | <?php | |
| 2 | |||||
| 3 | require_once(dirname(__FILE__).'/config.inc.php'); | ||||
| 4 | require_once(dirname(__FILE__).'/lib/FT/App.class.php'); | ||||
| 5 | require_once(dirname(__FILE__).'/lib/FT/App/SiteApp.class.php'); | ||||
| 6 | require_once(dirname(__FILE__).'/lib/FT/App/CampaignApp.class.php'); | ||||
| 7 | require_once(dirname(__FILE__).'/lib/FT/App/AdminApp.class.php'); | ||||
| 8 | |||||
| 9 | $app_args = array('doc_root' => dirname(__FILE__), | ||||
| 10 | 'template_dir' => dirname(__FILE__) . '/style/templates', | ||||
| 11 | 'www_host' => $_SERVER['HTTP_HOST'], | ||||
| 12 | 'www_root' => "http://{$_SERVER['HTTP_HOST']}" . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'), | ||||
| 13 | /* | ||||
| 14 | 'www_root' => ($_SERVER['REQUEST_URI'] == $_SERVER['REDIRECT_URL']) | ||||
| 15 | ? "http://{$_SERVER['HTTP_HOST']}" . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/') | ||||
| 16 | : $_SERVER['SCRIPT_NAME'], | ||||
| 17 | */ | ||||
| 18 | 'path_info' => rtrim($_SERVER['PATH_INFO'], '/'), | ||||
| 19 | 'cache_dir' => dirname(__FILE__) . 'cache' // This was causing an array index warning | ||||
| 20 | ); | ||||
| 21 | |||||
| 22 | function remaining(&$path) | ||||
| 23 | { return array_splice($path, (key($path) + 1)); } | ||||
| 24 | |||||
| 25 | $path = explode('/', trim($_SERVER['PATH_INFO'], '/')); | ||||
| 26 | |||||
| 27 | switch($base = reset($path)) { | ||||
| 28 | |||||
| 29 | case 'admin': | ||||
| 30 | $app = FT_APP_ADMIN_APP_CLASS; $app = new $app($app_args); | ||||
| 31 | |||||
| 32 | switch($action = next($path)) { | ||||
| 33 | |||||
| 34 | case 'view': | ||||
| 35 | case 'stats': | ||||
| 36 | case 'map-data': | ||||
| 37 | if($campaign = next($path)) { | ||||
| 38 | $app->run(array('action' => $action, 'campaign' => $campaign, 'path' => remaining($path))); | ||||
| 39 | } else { | ||||
| 40 | end($path); | ||||
| 41 | $app->run(array('action' => $action, 'campaign' => null, 'path' => remaining($path))); | ||||
| 42 | } | ||||
| 43 | break; | ||||
| 44 | |||||
| 45 | case 'dump': | ||||
| 46 | case 'edit': | ||||
| 47 | case 'delete': | ||||
| 48 | if($campaign = next($path)) { | ||||
| 49 | $app->run(array('action' => $action, 'campaign' => $campaign, 'path' => remaining($path))); | ||||
| 50 | } else { | ||||
| 51 | $app->throw_error("missing campaign"); | ||||
| 52 | } | ||||
| 53 | break; | ||||
| 54 | |||||
| 55 | case 'install': | ||||
| 56 | case 'docs': | ||||
| 57 | case 'purge': | ||||
| 58 | case 'new': | ||||
| 59 | $app->run(array('action' => $action, 'campaign' => null, 'path' => remaining($path))); | ||||
| 60 | break; | ||||
| 61 | |||||
| 62 | case false: | ||||
| 63 | $app->run(); | ||||
| 64 | break; | ||||
| 65 | |||||
| 66 | default: | ||||
| 67 | prev($path); | ||||
| 68 | $app->run(array('action' => null, 'campaign' => null, 'path' => remaining($path))); | ||||
| 69 | break; | ||||
| 70 | |||||
| 71 | } | ||||
| 72 | |||||
| 73 | break; | ||||
| 74 | |||||
| 75 | case 'campaigns': | ||||
| 76 | |||||
| 77 | if($campaign = next($path)) { | ||||
| 78 | |||||
| 79 | $app = FT_APP_CAMPAIGN_APP_CLASS; $app = new $app($app_args); | ||||
| 80 | |||||
| 81 | switch($action = next($path)) { | ||||
| 82 | case 'preview': | ||||
| 83 | $app->run(array('action' => $action, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path))); | ||||
| 84 | break; | ||||
| 85 | |||||
| 86 | case 'register': | ||||
| 87 | case 'map': | ||||
| 88 | case 'map-data': | ||||
| 89 | if($node = next($path)) { | ||||
| 90 | $app->run(array('action' => $action, 'node' => $node, 'campaign' => $campaign, 'path' => remaining($path))); | ||||
| 91 | } else { | ||||
| 92 | end($path); | ||||
| 93 | $app->run(array('action' => $action, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path))); | ||||
| 94 | } | ||||
| 95 | break; | ||||
| 96 | |||||
| 97 | case 'impact': | ||||
| 98 | case 'browse': | ||||
| 99 | case 'invite': | ||||
| 100 | case 'accept': | ||||
| 101 | if($node = next($path)) { | ||||
| 102 | $app->run(array('action' => $action, 'node' => $node, 'campaign' => $campaign, 'path' => remaining($path))); | ||||
| 103 | } else { | ||||
| 104 | $app->throw_error("missing node"); | ||||
| 105 | } | ||||
| 106 | break; | ||||
| 107 | |||||
| 108 | case false: | ||||
| 109 | $app->run(array('action' => null, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path))); | ||||
| 110 | break; | ||||
| 111 | |||||
| 112 | default: | ||||
| 113 | prev($path); | ||||
| 114 | $app->run(array('action' => null, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path))); | ||||
| 115 | break; | ||||
| 116 | |||||
| 117 | } | ||||
| 118 | |||||
| 119 | } else { | ||||
| 120 | |||||
| 121 | $app = FT_APP_SITE_APP_CLASS; $app = new $app($app_args); | ||||
| 122 | |||||
| 123 | $app->run(array('action' => 'campaigns')); | ||||
| 124 | break; | ||||
| 125 | |||||
| 126 | } | ||||
| 127 | |||||
| 128 | break; | ||||
| 129 | |||||
| 130 | case false: | ||||
| 131 | $app = FT_APP_CAMPAIGN_APP_CLASS; $app = new $app($app_args); | ||||
| 132 | |||||
| 133 | $app->run(array('action' => null, 'node' => null, 'campaign' => null, 'path' => remaining($path))); | ||||
| 134 | break; | ||||
| 135 | |||||
| 136 | default: | ||||
| 137 | $app = FT_APP_SITE_APP_CLASS; $app = new $app($app_args); | ||||
| 138 | |||||
| 139 | $app->run(array('action' => $base, 'path' => remaining($path))); | ||||
| 140 | break; | ||||
| 141 | } | ||||
| 142 | |||||
| 143 | ?> | ||||
