Source for file class.modrewritecontroller.php
Documentation is available at class.modrewritecontroller.php
* Includes Mod Rewrite controller class.
* @author Murat Purc <murat@purc.de>
* @copyright © Murat Purc 2008
* Mod Rewrite controller class. Extracts url parts and sets some necessary globals like:
* @author Murat Purc <murat@purc.de>
* Contenido configuration array (see $GLOBALS['cfg'])
* Mod Rewrite configuration array (see $GLOBALS['cfg']['mod_rewrite'])
* Extracted request uri path parts by path separator '/'
* Extracted article name from request uri
* Remaining path for path resolver (see $GLOBALS['path'])
* Client id used by this class
* Flag about occured errors
* Constructor, sets several properties.
$this->_aCfg =
& $GLOBALS['cfg'];
$this->_aCfgMR =
& $GLOBALS['cfg']['mod_rewrite'];
* Getter for overwritten client id (see $GLOBALS['client'])
return $GLOBALS['client'];
* Getter for overwritten change client id (see $GLOBALS['changeclient'])
* @return int Change client id
return $GLOBALS['changeclient'];
* Getter for article id (see $GLOBALS['idart'])
return $GLOBALS['idart'];
* Getter for category id (see $GLOBALS['idcat'])
* @return int Category id
return $GLOBALS['idcat'];
* Getter for language id (see $GLOBALS['lang'])
* @return int Language id
* Getter for change language id (see $GLOBALS['change_lang'])
* @return int Change language id
return $GLOBALS['changelang'];
* Getter for path (see $GLOBALS['path'])
* @return string Path, used by path resolver
* Getter for occured error state
* @return bool Flag for occured error
* Main function to call for mod rewrite related preprocessing jobs.
* Executes some private functions to extract request uri and to set needed membervariables
* (client, language, article id, category id, etc.)
$GLOBALS['mpDebug']->addDebug($GLOBALS['client'], 'ModRewriteController::execute() $GLOBALS[\'client\']');
$GLOBALS['mpDebug']->addDebug($GLOBALS['lang'], 'ModRewriteController::execute() $GLOBALS[\'lang\']');
// second call after setting client and language
$GLOBALS['mpDebug']->addDebug($this->_aParts, 'ModRewriteController::execute() after _setPathresolverSetting');
$GLOBALS['mpDebug']->addDebug($this->_aParts, 'ModRewriteController::execute() _setIdart');
* Extracts request uri and sets member variables $this->_sArtName and $this->_aParts
$uri =
$_SERVER['REQUEST_URI'];
// check for defined rootdir
if ($this->_aCfgMR['rootdir'] !==
'/' &&
strpos($_SERVER['REQUEST_URI'], $uri) ===
0) {
# $GLOBALS['mpDebug']->addDebug($this->_aParts, 'ModRewriteController::_extractRequestUri() $this->_aParts 3.');
if (isset
($aUrlComponents['path']) &&
$aUrlComponents['path'] !==
'/') {
if ($secondCall ==
true) {
// check for routing definition
$aUrlComponents['path'] =
$this->_aCfgMR['routing'][$aUrlComponents['path']];
if (strpos($aUrlComponents['path'], 'front_content.php') !==
false) {
// routing destination contains front_content.php
// set client language, if not set before
$aPaths =
explode('/', $aUrlComponents['path']);
foreach ($aPaths as $p =>
$item) {
// pathinfo would also work
$GLOBALS['mpDebug']->addDebug($this->_aParts, 'ModRewriteController::_extractRequestUri() $this->_aParts');
// loop parts array and remove existing 'front_content.php'
foreach($this->_aParts as $p =>
$item) {
if ($item ==
'front_content.php') {
# $GLOBALS['mpDebug']->addDebug($this->_aParts, 'ModRewriteController::_extractRequestUri() $this->_aParts 2.');
// set parts property top null, if needed
# $GLOBALS['mpDebug']->addDebug($this->_aParts, 'ModRewriteController::_extractRequestUri() $this->_aParts 3.');
// set artname to null if needed
# $GLOBALS['mpDebug']->addDebug($this->_sArtName, 'ModRewriteController::_extractRequestUri() $this->_sArtName');
* Overrides local mod rewrite cfg settings with client settings from database
if (isset
($GLOBALS['client']) &&
!empty($GLOBALS['client']) &&
!isset
($GLOBALS['changeclient'])) {
} elseif (isset
($GLOBALS['changeclient']) &&
!empty($GLOBALS['changeclient'])) {
// set global $GLOBALS['client'] variable
* Preprocesses article name and parts list, sets article name and parts list
* if settings for usage of categories as a html file is active and valid.
// check for html file only links and prepare variables
if (count($aParts) >
0) {
$this->_sArtName =
(isset
($aParts[1]) &&
strlen($aParts[1]) >
0) ?
$aParts[1] :
false;
if ($this->_aCfgMR['use_client_name'] ==
1) {
if (empty($GLOBALS['changeclient']) || (int)
$GLOBALS['changeclient'] ==
0) {
$GLOBALS['changeclient'] =
$GLOBALS['load_client'];
if (isset
($GLOBALS['client']) &&
$GLOBALS['changeclient'] !==
$GLOBALS['client']) {
// overwrite existing global $GLOBALS['client'] variable
$GLOBALS['client'] =
$GLOBALS['changeclient'];
# $GLOBALS['mpDebug']->addDebug($GLOBALS['changeclient'], 'ModRewriteController::_setClientId() $GLOBALS[\'changeclient\']');
# $GLOBALS['mpDebug']->addDebug($this->_iClientMR, 'ModRewriteController::_setClientId() $this->_iClientMR');
if ($this->_aCfgMR['use_language_name'] ==
1) {
// thanks to Nicolas Dickinson for multi Client/Language BugFix
# $GLOBALS['mpDebug']->addDebug($GLOBALS['changelang'], 'ModRewriteController::_setLanguageId() $GLOBALS[\'changelang\']');
if (empty($GLOBALS['changelang']) || (int)
$GLOBALS['changelang'] ==
0) {
unset
($GLOBALS['changelang']);
$GLOBALS['lang'] =
$GLOBALS['changelang'];
* Sets path resolver and category id
// TODO: time to get catid is to long
if (!isset
($GLOBALS['lang'])) {
if (!isset
($GLOBALS['load_lang'])) {
// load_client is set in frontend/config.php
$GLOBALS['lang'] =
$GLOBALS['load_lang'];
// get client id from table
cInclude('classes', 'contenido/class.clientslang.php');
$clCol =
new cApiClientLanguageCollection();
$clCol->setWhere('idclient', $GLOBALS['client']);
if ($clItem =
$clCol->next()) {
$GLOBALS['lang'] =
$clItem->get('idlang');
$GLOBALS['idcat'] =
prResolvePathViaURLNames($this->_sPath);
if (!$GLOBALS['idcat'] || (int)
$GLOBALS['idcat'] ==
0) {
// set this flag, it's used in front_content.php
unset
($GLOBALS['idcat']);
// unset $this->_sPath if $GLOBALS['idcat'] could set, otherwhise it would be resolved again.
$GLOBALS['mpDebug']->addDebug($GLOBALS['idcat'], 'ModRewriteController->_setPathresolverSetting $GLOBALS[\'idcat\']');
$GLOBALS['mpDebug']->addDebug($this->_sPath, 'ModRewriteController->_setPathresolverSetting $this->_sPath');
// startarticle name in url
// stored articlename is the default one, remove it mr_get_idart()
// will find the real article name
if (isset
($GLOBALS['idcat']) && isset
($this->_sArtName) &&
!isset
($GLOBALS['idart'])) {
// existing idcat without article name and idart
} elseif (!isset
($GLOBALS['idcat']) && isset
($this->_sArtName) &&
!isset
($GLOBALS['idart'])) {
// no idcat and idart but article name
if (isset
($GLOBALS['idart']) &&
(!$GLOBALS['idart'] || (int)
$GLOBALS['idart'] ==
0)) {
if ($this->_aCfgMR['redirect_invalid_article_to_errorsite'] ==
1) {
unset
($GLOBALS['idart']);
$GLOBALS['mpDebug']->addDebug($GLOBALS['idart'], 'ModRewriteController->_setIdart $GLOBALS[\'idart\']');
* Returns state of parts property
* @return bool True if $this->_aParts propery is an array and contains items
Documentation generated on Thu, 19 Jun 2008 22:43:51 +0200 by phpDocumentor 1.4.0