function __autoload($ClassName) { // echo $ClassName; if (class_exists('HTMLPurifier_Bootstrap', FALSE) && HTMLPurifier_Bootstrap::autoload($ClassName)) { return true; } if (!class_exists('Gdn_FileSystem', FALSE)) { return false; } if (substr($ClassName, 0, 4) === 'Gdn_') { $LibraryFileName = 'class.' . strtolower(substr($ClassName, 4)) . '.php'; } else { $LibraryFileName = 'class.' . strtolower($ClassName) . '.php'; } if (!is_null($ApplicationManager = Gdn::Factory('ApplicationManager'))) { $ApplicationWhiteList = Gdn::Factory('ApplicationManager')->EnabledApplicationFolders(); } else { $ApplicationWhiteList = NULL; } $LibraryPath = FALSE; // If this is a model, look in the models folder(s) if (strtolower(substr($ClassName, -5)) == 'model') { $LibraryPath = Gdn_FileSystem::FindByMapping('library_mappings.php', 'Library', PATH_APPLICATIONS, $ApplicationWhiteList, 'models' . DS . $LibraryFileName); } if ($LibraryPath === FALSE) { $LibraryPath = Gdn_FileSystem::FindByMapping('library_mappings.php', 'Library', PATH_LIBRARY, array('core', 'database', 'vendors' . DS . 'phpmailer', 'vendors' . DS . 'htmlpurifier'), $LibraryFileName); } // If it still hasn't been found, check for modules if ($LibraryPath === FALSE) { $LibraryPath = Gdn_FileSystem::FindByMapping('library_mappings.php', 'Library', PATH_APPLICATIONS, $ApplicationWhiteList, 'modules' . DS . $LibraryFileName); } if ($LibraryPath !== FALSE) { include_once $LibraryPath; } }
function Gdn_Autoload($ClassName) { if (!class_exists('Gdn_FileSystem', FALSE)) { return false; } if (!class_exists('Gdn_LibraryMap', FALSE)) { return false; } if (!class_exists('Gdn', FALSE)) { return false; } if (substr($ClassName, 0, 4) === 'Gdn_') { $LibraryFileName = 'class.' . strtolower(substr($ClassName, 4)) . '.php'; } else { $LibraryFileName = 'class.' . strtolower($ClassName) . '.php'; } if (!is_null($ApplicationManager = Gdn::Factory('ApplicationManager'))) { $ApplicationWhiteList = Gdn::Factory('ApplicationManager')->EnabledApplicationFolders(); } else { $ApplicationWhiteList = NULL; } $LibraryPath = FALSE; // If this is a model, look in the models folder(s) if (strtolower(substr($ClassName, -5)) == 'model') { $LibraryPath = Gdn_FileSystem::FindByMapping('library', PATH_APPLICATIONS, $ApplicationWhiteList, 'models' . DS . $LibraryFileName); } if (Gdn::PluginManager() instanceof Gdn_PluginManager) { // Look for plugin files. if ($LibraryPath === FALSE) { $PluginFolders = Gdn::PluginManager()->EnabledPluginFolders(); $LibraryPath = Gdn_FileSystem::FindByMapping('library', PATH_PLUGINS, $PluginFolders, $LibraryFileName); } // Look harder for plugin files. if ($LibraryPath === FALSE) { $LibraryPath = Gdn_FileSystem::FindByMapping('plugin', FALSE, FALSE, $ClassName); } } // Look for the class in the applications' library folders. if ($LibraryPath === FALSE) { $LibraryPath = Gdn_FileSystem::FindByMapping('library', PATH_APPLICATIONS, $ApplicationWhiteList, "library/{$LibraryFileName}"); } // Look for the class in the core. if ($LibraryPath === FALSE) { $LibraryPath = Gdn_FileSystem::FindByMapping('library', PATH_LIBRARY, array('core', 'database', 'vendors' . DS . 'phpmailer'), $LibraryFileName); } // If it still hasn't been found, check for modules if ($LibraryPath === FALSE) { $LibraryPath = Gdn_FileSystem::FindByMapping('library', PATH_APPLICATIONS, $ApplicationWhiteList, 'modules' . DS . $LibraryFileName); } if ($LibraryPath !== FALSE) { include_once $LibraryPath; } }
/** * Searches through the /cache/controller_mappings.php file for the requested * controller. If it doesn't find it, it searches through the entire * application's folders for the requested controller. If it finds the * controller, it adds the mapping to /cache/controller_mappings.php so it * won't need to search again. If it doesn't find the controller file * anywhere, it throws a fatal error. * * @param boolean $ThrowErrorOnFailure * @todo $ThrowErrorOnFailure needs a description. */ private function _FetchController($ThrowErrorOnFailure = FALSE) { $ControllerWhiteList = $this->EnabledApplicationFolders(); // Don't include it if it's already been included if (!class_exists($this->ControllerName())) { $PathParts = array('controllers'); if ($this->_ControllerFolder != '') { $PathParts[] = $this->_ControllerFolder; } $PathParts[] = strtolower($this->_ControllerName) . '.php'; $ControllerFileName = CombinePaths($PathParts); // Force the mapping to search in the app folder if it was in the request if ($this->_ApplicationFolder != '' && InArrayI($this->_ApplicationFolder, $ControllerWhiteList)) { // Limit the white list to the specified application folder $ControllerWhiteList = array($this->_ApplicationFolder); } $ControllerPath = Gdn_FileSystem::FindByMapping('controller_mappings.php', 'Controller', PATH_APPLICATIONS, $ControllerWhiteList, $ControllerFileName); if ($ControllerPath !== FALSE) { // Strip the "Application Folder" from the controller path (this is // used by the controller for various purposes. ie. knowing which // application to search in for a view file). $this->_ApplicationFolder = explode(DS, str_replace(PATH_APPLICATIONS . DS, '', $ControllerPath)); $this->_ApplicationFolder = $this->_ApplicationFolder[0]; // Load the application's master controller if (!class_exists($this->_ApplicationFolder . 'Controller')) { include CombinePaths(array(PATH_APPLICATIONS, $this->_ApplicationFolder, 'controllers', 'appcontroller.php')); } // Now load the library (no need to check for existence - couldn't // have made it here if it didn't exist). include $ControllerPath; } } if (!class_exists($this->ControllerName())) { if ($ThrowErrorOnFailure === TRUE) { if (ForceBool(Gdn::Config('Garden.Debug'))) { trigger_error(ErrorMessage('Controller not found: ' . $this->ControllerName(), 'Dispatcher', '_FetchController'), E_USER_ERROR); } else { // Return a 404 message list($this->_ApplicationFolder, $this->_ControllerName, $this->_ControllerMethod) = explode('/', $this->Routes['Default404']); $ControllerFileName = CombinePaths(array('controllers', strtolower($this->_ControllerName) . '.php')); $ControllerPath = Gdn_FileSystem::FindByMapping('controller_mappings.php', 'Controller', PATH_APPLICATIONS, $ControllerWhiteList, $ControllerFileName); include CombinePaths(array(PATH_APPLICATIONS, $this->_ApplicationFolder, 'controllers', 'appcontroller.php')); include $ControllerPath; } } return FALSE; } else { return TRUE; } }
public function Gdn_Dispatcher_BeforeDispatch_Handler($Sender) { $Request = Gdn::Request(); $RequestUri = $Request->RequestUri(); if (Gdn::Router()->GetRoute($RequestUri) === False) { $RequestArgs = SplitUpString($RequestUri, '/', 'strtolower'); if (array_key_exists(0, $RequestArgs)) { $ApplicationFolders = $Sender->EnabledApplicationFolders(); $bFoundApplication = in_array($RequestArgs[0], $ApplicationFolders); if ($bFoundApplication === False) { $PathParts = array('controllers', 'class.' . $RequestArgs[0] . 'controller.php'); $ControllerFileName = CombinePaths($PathParts); $ControllerPath = Gdn_FileSystem::FindByMapping('controller', PATH_APPLICATIONS, $ApplicationFolders, $ControllerFileName); if (!$ControllerPath || !file_exists($ControllerPath)) { $Sender->EventArguments['RequestUri'] =& $RequestUri; $Sender->FireEvent('BeforeGetRoute'); $NewRequest = CandyModel::GetRouteRequestUri($RequestUri); if ($NewRequest) { $Request->WithURI($NewRequest); } } } } } }