Source for file Contenido_UrlBuilder_MR.class.php
Documentation is available at Contenido_UrlBuilder_MR.class.php
* Contenido Content Management System
* Implementation of Contenido_UrlBuilder to build front_content.php URL
* @copyright © Murat Purc 2008
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
cInclude('classes', 'UrlBuilder/Contenido_UrlBuilder.class.php');
cInclude('classes', 'UrlBuilder/Contenido_UrlBuilderFactory.class.php');
* Class to build frontend urls for advandced mod rewrite plugin.
* Extends abstract Contenido_UrlBuilder class and implements singleton pattern.
* cInclude('classes', 'UrlBuilder/Contenido_UrlBuilder_MR.class.php');
* $url = 'front_content.php?idart=123';
* $mrUrlBuilder = Contenido_UrlBuilder_MR::getInstance();
* $mrUrlBuilder->buildUrl(array($url));
* $newUrl = $mrUrlBuilder->getUrl();
* @author Murat Purc <murat@purc.de>
* @copyright © Murat Purc 2008
* @var Contenido_UrlBuilder_MR
* Ampersant used for composing several parameter value pairs
* Is mod rewrite enabled?
* Mod Rewrite configuration
* Constructor, tries to set some member variables.
$this->sHttpBasePath =
'';
$this->_oDebug =
Contenido_mpDebug::getInstance();
$this->_bIsXHTML =
(getEffectiveSetting('generator', 'xhtml', 'false') ==
'false') ?
false :
true;
* Returns a instance of Contenido_UrlBuilder_MR
* @return Contenido_UrlBuilder_MR
if (self::$_instance ==
null) {
self::$_instance =
new Contenido_UrlBuilder_MR();
* Builds a URL based on defined mod rewrite settings.
* @param array $params Parameter array, provides only following parameters:
* $params[0] = 'front_content.php?idart=123...'
* @param boolean $bUseAbsolutePath Flag to use absolute path (not used at the moment)
* @return string New build url
public function buildUrl(array $params, $bUseAbsolutePath=
false) {
$url =
(isset
($params[0])) ?
$params[0] :
'';
if (preg_match("/^front_content\.php(.*|.+?)/i", $aUrl['url'], $aHits) ==
1) {
$url =
$aUrl['htmlpath'] .
self::_buildUrl($aHits[1]);
$this->_oDebug->addDebug($url, 'Contenido_UrlBuilder_MR::buildUrl() no match');
# $urlDebug['out'] = $url;
# $this->_oDebug->addDebug($urlDebug, 'Contenido_UrlBuilder_MR::buildUrl() in -> out');
* Builds the SEO-URL by analyzing passed arguments (parameter value pairs)
* @param string $args Arguments
* @return string New build pretty url
// check arguments, try to set anchor, if exists and do some cleanup
// extract arguments into arguments array
// set list of parameter which are to ignore while setting additional parameter
'idcat', 'idart', 'lang', 'client', 'idcatart', 'idartlang'
if ($this->_aMrCfg['use_language'] ==
1) {
$aIgnoredParams[] =
'changelang';
if ($this->_aMrCfg['use_client'] ==
1) {
$aIgnoredParams[] =
'changeclient';
// collect additional non contenido related parameters
foreach ($aArgs as $p =>
$v) {
// some presettings of variables
$iChangeClient =
(isset
($aArgs['changeclient'])) ? (int)
$aArgs['changeclient'] :
0;
$iChangeLang =
(isset
($aArgs['changelang'])) ? (int)
$aArgs['changelang'] :
0;
$iIdCat =
(isset
($aArgs['idcat'])) ? (int)
$aArgs['idcat'] :
0;
$iIdCatLang =
(isset
($aArgs['idcatlang'])) ? (int)
$aArgs['idcatlang'] :
0;
$iIdCatArt =
(isset
($aArgs['idcatart'])) ? (int)
$aArgs['idcatart'] :
0;
$iIdArt =
(isset
($aArgs['idart'])) ? (int)
$aArgs['idart'] :
0;
$iIdArtLang =
(isset
($aArgs['idartlang'])) ? (int)
$aArgs['idartlang'] :
0;
if ($this->_aMrCfg['use_client'] ==
1) {
$idclient =
($iChangeClient >
0) ?
$iChangeClient :
$GLOBALS['client'];
if ($this->_aMrCfg['use_client_name'] ==
1) {
// set language if desired
if ($this->_aMrCfg['use_language'] ==
1) {
$idlang =
($iChangeLang >
0) ?
$iChangeLang :
$GLOBALS['lang'];
if ($this->_aMrCfg['use_language_name'] ==
1) {
$aPretty =
$oMRUrlStack->getPrettyUrlParts('front_content.php?' .
$args);
$sPath =
(isset
($aPretty['urlpath'])) ?
$aPretty['urlpath'] :
'';
$sArticle =
(isset
($aPretty['urlname'])) ?
$aPretty['urlname'] :
'';
// check start directory settings
if ($this->_aMrCfg['startfromroot'] ==
0) {
// splitt string in array
##++## $aCategories = explode($this->_aMrCfg['category_seperator'], $sPath);
$aCategories =
explode('/', $sPath);
// implode array with categories to new string
##++## $sPath = implode($this->_aMrCfg['category_seperator'], $aCategories);
$sPath =
implode('/', $aCategories);
// category id was passed but not article id
if (($iIdCat >
0 ||
$iIdCatLang >
0) &&
$iIdCatArt ==
0 &&
$iIdArt ==
0 &&
$iIdArtLang ==
0) {
if ($this->_aMrCfg['add_startart_name_to_url']) {
if ($this->_aMrCfg['default_startart_name'] !==
'') {
// use default start article name
$sArticle =
$this->_aMrCfg['default_startart_name'];
// url is to create without article name
$sFileExt =
$this->_aMrCfg['file_extension'];
// add closing path seperator
$sPathAndArticle =
$sPath .
$sArticle .
$sFileExt;
if ($this->_aMrCfg['use_lowercase_uri'] ==
1) {
$sFullUrl =
$this->_aMrCfg['rootdir'] .
$sPathAndArticle .
$sParams .
$sAnchor;
#echo "<pre>Contenido_UrlBuilder_MR->_buildUrl: \$sFullUrl $sFullUrl</pre>";
// remove double or more join parameter
if (substr($sFullUrl, -
2) ==
'?=') {
#echo "<pre>Contenido_UrlBuilder_MR->_buildUrl: \$sFullUrl $sFullUrl</pre>";
// now convert url to an AMR url
$sFullUrl =
$oMrUrlUtil->toModRewriteUrl($sFullUrl);
Documentation generated on Tue, 25 Nov 2008 22:07:34 +0100 by phpDocumentor 1.4.1