| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
require_once dirname(__FILE__) . '/../SGL.php'; |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
class SGL_FrontController |
|---|
| 51 |
{ |
|---|
| 52 |
|
|---|
| 53 |
* Allow SGL_Output with its template methods to be extended. |
|---|
| 54 |
* |
|---|
| 55 |
* Remember to add your custom include path to the global config, ie a class |
|---|
| 56 |
* called FOO_Output will be discovered if it exists in seagull/lib/FOO/Output.php. |
|---|
| 57 |
* This means '/path/to/seagull/lib' must be added to |
|---|
| 58 |
* $conf['path']['additionalIncludePath']. The class definition would be: |
|---|
| 59 |
* |
|---|
| 60 |
* class FOO_Output extends SGL_Output {} |
|---|
| 61 |
* |
|---|
| 62 |
*/ |
|---|
| 63 |
function getOutputClass() |
|---|
| 64 |
{ |
|---|
| 65 |
if (SGL_Config::get('site.customOutputClassName')) { |
|---|
| 66 |
$className = SGL_Config::get('site.customOutputClassName'); |
|---|
| 67 |
} else { |
|---|
| 68 |
$className = 'SGL_Output'; |
|---|
| 69 |
} |
|---|
| 70 |
return $className; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
* Main invocation, init tasks plus main process. |
|---|
| 75 |
* |
|---|
| 76 |
*/ |
|---|
| 77 |
public static function run() |
|---|
| 78 |
{ |
|---|
| 79 |
if (!defined('SGL_INITIALISED')) { |
|---|
| 80 |
self::init(); |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
$input = SGL_Registry::singleton(); |
|---|
| 84 |
$req = SGL_Request::singleton(); |
|---|
| 85 |
|
|---|
| 86 |
if (PEAR::isError($req)) { |
|---|
| 87 |
|
|---|
| 88 |
SGL::displayStaticPage($req->getMessage()); |
|---|
| 89 |
} |
|---|
| 90 |
$input->setRequest($req); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
$c = SGL_Config::singleton(); |
|---|
| 94 |
$c->ensureModuleConfigLoaded($req->getModuleName()); |
|---|
| 95 |
|
|---|
| 96 |
$outputClass = self::getOutputClass(); |
|---|
| 97 |
$output = new $outputClass(); |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
//SGL_FrontController::testDbConnection($output); |
|---|
| 101 |
|
|---|
| 102 |
// run module init tasks |
|---|
| 103 |
//SGL_Task_InitialiseModules::run(); |
|---|
| 104 |
|
|---|
| 105 |
// see http://trac.seagullproject.org/wiki/Howto/PragmaticPatterns/InterceptingFilter |
|---|
| 106 |
if (!self::customFilterChain($input)) { |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
$aFilters = array( |
|---|
| 110 |
|
|---|
| 111 |
//'SGL_Task_Init', |
|---|
| 112 |
'SGL_Filter_StripMagicQuotes', |
|---|
| 113 |
'SGL_Filter_DiscoverClientOs', |
|---|
| 114 |
'SGL_Filter_ResolveManager', |
|---|
| 115 |
'SGL_Filter_CreateSession', |
|---|
| 116 |
'SGL_Filter_SetupLangSupport', |
|---|
| 117 |
'SGL_Filter_SetupLocale', |
|---|
| 118 |
'SGL_Filter_AuthenticateRequest', |
|---|
| 119 |
'SGL_Filter_DetectAdminMode', |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
'SGL_Filter_BuildHeaders', |
|---|
| 126 |
'SGL_Filter_BuildView', |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
'SGL_Filter_SetupGui', |
|---|
| 131 |
'SGL_Filter_BuildOutputData', |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
'SGL_MainProcess', |
|---|
| 135 |
|
|---|
| 136 |
$input->setFilters($aFilters); |
|---|
| 137 |
|
|---|
| 138 |
$chain = new SGL_FilterChain($input->getFilters()); |
|---|
| 139 |
$chain->doFilter($input, $output); |
|---|
| 140 |
SGL_Config::get('site.outputBuffering')) { |
|---|
| 141 |
ob_end_flush(); |
|---|
| 142 |
|
|---|
| 143 |
$output->data; |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
customFilterChain(&$input) |
|---|
| 147 |
|
|---|
| 148 |
$req = $input->getRequest(); |
|---|
| 149 |
|
|---|
| 150 |
$req->getType()) { |
|---|
| 151 |
|
|---|
| 152 |
SGL_REQUEST_BROWSER: |
|---|
| 153 |
SGL_REQUEST_CLI: |
|---|
| 154 |
$mgr = SGL_Inflector::getManagerNameFromSimplifiedName( |
|---|
| 155 |
$req->getManagerName()); |
|---|
| 156 |
|
|---|
| 157 |
if (SGL_Config::get("$mgr.filterChain")) { |
|---|
| 158 |
$aFilters = explode(',', SGL_Config::get("$mgr.filterChain")); |
|---|
| 159 |
$input->setFilters($aFilters); |
|---|
| 160 |
$ret = true; |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
} elseif (SGL_Config::get('site.filterChain')) { |
|---|
| 164 |
$aFilters = explode(',', SGL_Config::get('site.filterChain')); |
|---|
| 165 |
$input->setFilters($aFilters); |
|---|
| 166 |
$ret = true; |
|---|
| 167 |
|
|---|
| 168 |
$ret = false; |
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
SGL_REQUEST_AJAX: |
|---|
| 173 |
$moduleName = ucfirst($req->getModuleName()); |
|---|
| 174 |
$providerName = $moduleName . 'AjaxProvider'; |
|---|
| 175 |
SGL_Config::get("$providerName.filterChain")) { |
|---|
| 176 |
$aFilters = explode(',', SGL_Config::get("$providerName.filterChain")); |
|---|
| 177 |
|
|---|
| 178 |
$aFilters = array( |
|---|
| 179 |
'SGL_Task_Init', |
|---|
| 180 |
'SGL_Task_SetupORM', |
|---|
| 181 |
'SGL_Task_CreateSession', |
|---|
| 182 |
'SGL_Task_SetupLangSupport', |
|---|
| 183 |
'SGL_Task_AuthenticateAjaxRequest', |
|---|
| 184 |
'SGL_Task_BuildAjaxHeaders', |
|---|
| 185 |
'SGL_Task_CustomBuildOutputData', |
|---|
| 186 |
'SGL_Task_ExecuteAjaxAction', |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
$input->setFilters($aFilters); |
|---|
| 190 |
$ret = true; |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
SGL_REQUEST_AMF: |
|---|
| 194 |
$moduleName = ucfirst($req->getModuleName()); |
|---|
| 195 |
$providerName = $moduleName . 'AmfProvider'; |
|---|
| 196 |
SGL_Config::get("$providerName.filterChain")) { |
|---|
| 197 |
$aFilters = explode(',', SGL_Config::get("$providerName.filterChain")); |
|---|
| 198 |
|
|---|
| 199 |
$aFilters = array( |
|---|
| 200 |
'SGL_Task_Init', |
|---|
| 201 |
'SGL_Task_SetupORM', |
|---|
| 202 |
'SGL_Task_CreateSession', |
|---|
| 203 |
'SGL_Task_SetupLangSupport', |
|---|
| 204 |
'SGL_Task_ExecuteAmfAction', |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
$input->setFilters($aFilters); |
|---|
| 208 |
$ret = true; |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
$ret; |
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
testDbConnection($output) |
|---|
| 215 |
|
|---|
| 216 |
$originalErrorLevel = error_reporting(0); |
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
if (defined('SGL_INSTALLED')) { |
|---|
| 220 |
$dbh = SGL_DB::singleton(); |
|---|
| 221 |
PEAR::isError($dbh)) { |
|---|
| 222 |
|
|---|
| 223 |
SGL::displayErrorPage($output); |
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
error_reporting($originalErrorLevel); |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
init() |
|---|
| 231 |
|
|---|
| 232 |
self::setupMinimumEnv(); |
|---|
| 233 |
self::loadRequiredFiles(); |
|---|
| 234 |
|
|---|
| 235 |
$autoLoad = (is_file(SGL_VAR_DIR . '/INSTALL_COMPLETE.php')) |
|---|
| 236 |
true |
|---|
| 237 |
: false; |
|---|
| 238 |
$c = SGL_Config::singleton($autoLoad); |
|---|
| 239 |
|
|---|
| 240 |
$init = new SGL_TaskRunner(); |
|---|
| 241 |
$init->addData($c->getAll()); |
|---|
| 242 |
$init->addTask(new SGL_Task_SetupConstantsFinish()); |
|---|
| 243 |
|
|---|
| 244 |
$init->addTask(new SGL_Task_SetGlobals()); |
|---|
| 245 |
$init->addTask(new SGL_Task_ModifyIniSettings()); |
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
$init->addTask(new SGL_Task_SetBaseUrl()); |
|---|
| 249 |
|
|---|
| 250 |
$init->addTask(new SGL_Task_LoadCustomConfig()); |
|---|
| 251 |
$init->main(); |
|---|
| 252 |
define('SGL_INITIALISED', true); |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
loadRequiredFiles() |
|---|
| 256 |
|
|---|
| 257 |
$coreLibs = dirname(__FILE__); |
|---|
| 258 |
$aRequiredFiles = array( |
|---|
| 259 |
$coreLibs . '/Url.php', |
|---|
| 260 |
$coreLibs . '/HTTP.php', |
|---|
| 261 |
$coreLibs . '/Manager.php', |
|---|
| 262 |
$coreLibs . '/Output.php', |
|---|
| 263 |
$coreLibs . '/String.php', |
|---|
| 264 |
$coreLibs . '/Session.php', |
|---|
| 265 |
$coreLibs . '/Util.php', |
|---|
| 266 |
$coreLibs . '/Config.php', |
|---|
| 267 |
$coreLibs . '/ParamHandler.php', |
|---|
| 268 |
$coreLibs . '/Registry.php', |
|---|
| 269 |
$coreLibs . '/Request.php', |
|---|
| 270 |
$coreLibs . '/Inflector.php', |
|---|
| 271 |
$coreLibs . '/Date.php', |
|---|
| 272 |
$coreLibs . '/Array.php', |
|---|
| 273 |
$coreLibs . '/Error.php', |
|---|
| 274 |
$coreLibs . '/Cache.php', |
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
$coreLibs . '/Translation.php', |
|---|
| 278 |
$coreLibs . '/../data/ary.languages.php', |
|---|
| 279 |
|
|---|
| 280 |
$aRequiredFiles as $file) { |
|---|
| 281 |
$file; |
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
setupMinimumEnv() |
|---|
| 286 |
|
|---|
| 287 |
$init = new SGL_TaskRunner(); |
|---|
| 288 |
$init->addTask(new SGL_Task_SetupPaths()); |
|---|
| 289 |
$init->addTask(new SGL_Task_SetupConstantsStart()); |
|---|
| 290 |
$init->main(); |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
class SGL_ProcessRequest |
|---|
| 302 |
{ |
|---|
| 303 |
function process(SGL_Registry $input, SGL_Output $output) {} |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
class SGL_DecorateProcess extends SGL_ProcessRequest |
|---|
| 313 |
{ |
|---|
| 314 |
var $processRequest; |
|---|
| 315 |
|
|---|
| 316 |
function SGL_DecorateProcess($pr) |
|---|
| 317 |
{ |
|---|
| 318 |
$this->processRequest = $pr; |
|---|
| 319 |
} |
|---|
| 320 |
} |
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
class SGL_MainProcess extends SGL_ProcessRequest |
|---|
| 329 |
{ |
|---|
| 330 |
function process($input, $output) |
|---|
| 331 |
{ |
|---|
| 332 |
SGL::logMessage(null, PEAR_LOG_DEBUG); |
|---|
| 333 |
|
|---|
| 334 |
$req = $input->getRequest(); |
|---|
| 335 |
$mgr = $input->get('manager'); |
|---|
| 336 |
|
|---|
| 337 |
$mgr->validate($req, $input); |
|---|
| 338 |
$input->aggregate($output); |
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
if ($mgr->isValid()) { |
|---|
| 342 |
$ok = $mgr->process($input, $output); |
|---|
| 343 |
if (SGL_Error::count() && SGL_Session::getRoleId() != SGL_ADMIN |
|---|
| 344 |
&& SGL_Config::get('debug.production')) { |
|---|
| 345 |
$mgr->handleError(SGL_Error::getLast(), $output); |
|---|
| 346 |
} |
|---|
| 347 |
} |
|---|
| 348 |
SGL_Manager::display($output); |
|---|
| 349 |
$mgr->display($output); |
|---|
| 350 |
} |
|---|
| 351 |
} |
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
class SGL_OutputRendererStrategy |
|---|
| 360 |
{ |
|---|
| 361 |
|
|---|
| 362 |
* Prepare renderer options. |
|---|
| 363 |
* |
|---|
| 364 |
*/ |
|---|
| 365 |
function initEngine() {} |
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
* Abstract render method. |
|---|
| 369 |
* |
|---|
| 370 |
* @param SGL_View $view |
|---|
| 371 |
*/ |
|---|
| 372 |
function render($view) {} |
|---|
| 373 |
} |
|---|
| 374 |
?> |
|---|