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
defined('CON_FRAMEWORK') or die('Illegal call');
* Mod Rewrite controller class. Extracts url parts and sets some necessary globals like:
* @author Murat Purc <murat@purc.de>
* 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
* Flag about found routing definition
* Constructor, sets several properties.
* @param string $incommingUrl Incomming URL
* Getter for overwritten client id (see $GLOBALS['client'])
return parent::$_oGlobals->get('client');
* Getter for overwritten change client id (see $GLOBALS['changeclient'])
* @return int Change client id
return parent::$_oGlobals->get('changeclient');
* Getter for article id (see $GLOBALS['idart'])
return parent::$_oGlobals->get('idart');
* Getter for category id (see $GLOBALS['idcat'])
* @return int Category id
return parent::$_oGlobals->get('idcat');
* Getter for language id (see $GLOBALS['lang'])
* @return int Language id
return parent::$_oGlobals->get('lang');
* Getter for change language id (see $GLOBALS['change_lang'])
* @return int Change language id
return parent::$_oGlobals->get('changelang');
* Getter for path (see $GLOBALS['path'])
* @return string Path, used by path resolver
* Getter for resolved url
* @return string Resolved url
* Returns a flag about found routing definition
* return bool Flag about found routing
* 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.)
// second call after setting client and language
parent::$_oDebug->addDebug($this->_aParts, 'ModRewriteController::execute() _setIdart');
* Extracts request URI and sets member variables $this->_sArtName and $this->_aParts
* @param bool $secondCall Flag about second call of this function, is needed
* to re extract url if a routing definition was found
// check for defined rootdir
if (isset
($aUrlComponents['path'])) {
if ($secondCall ==
true) {
# parent::$_oDebug->addDebug($aUrlComponents, 'ModRewriteController::_extractRequestUri() 2. call $aUrlComponents');
// @todo: implement real redirect of old front_content.php style urls
// check for routing definition
if (is_array($routings) && isset
($routings[$aUrlComponents['path']])) {
$aUrlComponents['path'] =
$routings[$aUrlComponents['path']];
if (strpos($aUrlComponents['path'], 'front_content.php') !==
false) {
// routing destination contains front_content.php
// set client language, if not set before
$url =
mr_buildNewUrl($aUrlComponents['path']);
$aPaths =
explode('/', $aUrlComponents['path']);
foreach ($aPaths as $p =>
$item) {
// pathinfo would also work
if ($secondCall ==
true) {
// reprocess extracting client and language
parent::$_oDebug->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') {
// set parts property top null, if needed
// set artname to null if needed
* Tries to initialize the client id
$client =
parent::$_oGlobals->get('client', 0);
$changeclient =
parent::$_oGlobals->get('changeclient', 0);
if ($client >
0 &&
$changeclient ==
0) {
} elseif ($changeclient >
0) {
$this->_iClientMR =
parent::$_oGlobals->get('load_client');
// set global client variable
parent::$_oGlobals->set('client', (int)
$this->_iClientMR);
$client =
parent::$_oGlobals->get('client', 0);
$changeclient =
parent::$_oGlobals->get('changeclient', 0);
if (parent::getConfig('use_client_name') ==
1) {
if (empty($changeclient) || (int)
$changeclient ==
0) {
$changeclient =
parent::$_oGlobals->get('load_client');
if ($client >
0 &&
$changeclient !==
$client) {
// overwrite existing client variable
parent::$_oGlobals->set('client', $changeclient);
parent::$_oGlobals->set('changeclient', $changeclient);
if (parent::getConfig('use_language_name') ==
1) {
// thanks to Nicolas Dickinson for multi Client/Language BugFix
if ((int)
$changelang >
0) {
parent::$_oGlobals->set('lang', $changelang);
parent::$_oGlobals->set('changelang', $changelang);
* Sets path resolver and category id
$lang =
parent::$_oGlobals->get('lang');
if (parent::$_oGlobals->get('load_lang', 0) >
0) {
// load_client is set in frontend/config.php
$lang =
parent::$_oGlobals->get('load_lang');
// get client id from table
cInclude('classes', 'contenido/class.clientslang.php');
$clCol =
new cApiClientLanguageCollection();
$clCol->setWhere('idclient', parent::$_oGlobals->get('client'));
if ($clItem =
$clCol->next()) {
$lang =
$clItem->get('idlang');
parent::$_oGlobals->set('lang', $lang);
$idcat = (int)
ModRewrite::getCatIdByUrlPath($this->_sPath);
// category couldn't resolved
// unset $this->_sPath if $idcat could set, otherwhise it would be resolved again.
parent::$_oGlobals->set('idcat', $idcat);
parent::$_oDebug->addDebug($idcat, 'ModRewriteController->_setPathresolverSetting $idcat');
parent::$_oDebug->addDebug($this->_sPath, 'ModRewriteController->_setPathresolverSetting $this->_sPath');
// startarticle name in url
// stored articlename is the default one, remove it ModRewrite::getArtIdByWebsafeName()
// will find the real article name
$idcat =
parent::$_oGlobals->get('idcat');
$idart =
parent::$_oGlobals->get('idart');
if ($idcat !==
null &&
$this->_sArtName &&
$idart ==
null) {
// existing idcat with article name and no idart
} elseif ($idcat >
0 &&
$this->_sArtName ==
null &&
$idart ==
null) {
if (parent::getConfig('add_startart_name_to_url') &&
parent::getConfig('default_startart_name') ==
'') {
// existing idcat without article name and idart
cInclude('classes', 'class.article.php');
$artColl =
new ArticleCollection(array('idcat' =>
$idcat, 'start' =>
1));
if ($artItem =
$artColl->startArticle()) {
$idart =
$artItem->get('idart');
} elseif ($idcat ==
null &&
$idart ==
null && isset
($this->_sArtName)) {
// no idcat and idart but article name
if ($idart !==
null &&
(!$idart || (int)
$idart ==
0)) {
if (parent::getConfig('redirect_invalid_article_to_errorsite') ==
1) {
parent::$_oGlobals->set('idart', $idart);
parent::$_oDebug->addDebug($idart, 'ModRewriteController->_setIdart $idart');
* Does post validation of the extracted data.
* One main goal of this function is to prevent duplicated content, which could happen, if
* the configuration 'startfromroot' is activated.
if (parent::getConfig('startfromroot') ==
1 &&
parent::getConfig('prevent_duplicated_content') ==
1) {
// prevention of duplicated content if '/firstcat/' is directly requested!
$idcat =
parent::$_oGlobals->get('idcat');
$idart =
parent::$_oGlobals->get('idart');
$param .=
'idcat=' . (int)
$idcat;
$param .=
($param !==
'') ?
'&idart=' . (int)
$idart :
'idart=' . (int)
$idart;
// set client language, if not set before
mr_setClientLanguageId(parent::$_oGlobals->get('client'));
$url =
mr_buildNewUrl('front_content.php?' .
$param);
$incommingUrl =
(isset
($aUrlComponents['path'])) ?
$aUrlComponents['path'] :
'';
parent::$_oDebug->addDebug($url, 'ModRewriteController->_postValidation validate url');
parent::$_oDebug->addDebug($incommingUrl, 'ModRewriteController->_postValidation incommingUrl');
// now the new generated uri should be identical with the request uri
if ($incommingUrl !==
$url) {
parent::$_oGlobals->set('idcat', null);
* Parses the url using defined separators
* @param string $url Incoming url
* @return string Parsed url
$url =
$oMrUrlUtil->toContenidoUrl($url);
* Returns state of parts property.
* @return bool True if $this->_aParts propery is an array and contains items
Documentation generated on Sun, 08 Feb 2009 22:00:35 +0100 by phpDocumentor 1.4.1