Source for file functions.mod_rewrite.php
Documentation is available at functions.mod_rewrite.php
* Defines the 'modrewrite' related functions
* @author Stefan Seifarth / stese
* @copyright © www.polycoder.de
* @author Murat Purc <murat@purc.de>
/******************************************
* File : functions.mod_rewrite.php
* Descr : Defines the 'modrewrite' related
* Author : Stefan Seifarth
******************************************/
cInclude('classes', 'contenido/class.articlelanguage.php');
* get language id from language name
* thanks to Nicolas Dickinson for multi
* @param string language name
* @return integer language id
FROM " .
$cfg["tab"]["lang"] .
" as l
LEFT JOIN " .
$cfg["tab"]["clients_lang"] .
" AS cl ON l.idlang = cl.idlang
cl.idclient = '". (int)
$int_client .
"' AND
l.name = '" .
urldecode($str_languagename) .
"'";
$int_lang_id =
$aData['idlang'];
* get client id from client name
* @param string client name
* @return integer client id
FROM " .
$cfg["tab"]["clients"] .
"
WHERE name = '" .
urldecode($str_clientname) .
"'";
$int_client_id =
$aData['idclient'];
* get recent article from websafe name tree
* @param string Websafe name
* @param integer category id
* @return integer recent article id
function mr_get_idart ( $str_artname =
"", $int_id =
0, $int_lang_id =
0 ) {
// only article name were given
// get all basic category ids with parentid=0
$sql =
"SELECT idcat FROM " .
$cfg["tab"]["cat"] .
" WHERE parentid = '0'";
while ($db->next_record()) {
$arr_idcats[] =
"idcat = '" .
$db->f("idcat") .
"'";
$str_where =
" AND ( " .
join(" OR ", $arr_idcats) .
")";
$str_where =
" AND ca.idcat = '$int_id'";
FROM " .
$cfg["tab"]["art_lang"] .
" al
LEFT JOIN " .
$cfg["tab"]["cat_art"] .
" ca
WHERE al.urlname = '$str_artname'" .
$str_where;
$int_idart =
$aData['idart'];
// plugin Advanced Mod Rewrite - Murat Purc (aka xmurrix)
* Processes mod_rewrite related job after moving a category up.
* Will be called as a action code from table con_actions.
* @param int $idcat Id of category beeing moved up
$cat =
new cApiCategory($idcat);
if (!$cat->get('preid')) {
foreach ($arr_idlang as $int_idlang) {
// set new urlname - because original set urlname isn't validated for double entries in same parent category
* Processes mod_rewrite related job after moving a category down.
* Will be called as a action code from table con_actions.
* @param int $idcat Id of category beeing moved down
$cat =
new cApiCategory($idcat);
foreach ($arr_idlang as $int_idlang) {
// set new urlname - because original set urlname isn't validated for double entries in same parent category
* Processes mod_rewrite related job after moving a category subtree.
* Will be called as a action code from table con_actions.
* @param int $idcat Id of category where the subtree has beeen moved
$cat =
new cApiCategory($idcat);
foreach ($arr_idlang as $int_idlang) {
// set new urlname - because original set urlname isn't validated for double entries in same parent category
* Processes mod_rewrite related job after editing a article first time.
* Will be called as a action code from table con_actions.
* @param int $newIdart Id of new edited article
global $client, $title, $urlname, $idcat;
$a_languages =
getLanguagesByClient($client);
foreach ($a_languages as $tmp_lang) {
* Processes mod_rewrite related job after editing a article.
* Will be called as a action code from table con_actions.
* @param int $idart Id of edited article
global $urlname, $title, $idartlang, $idcat;
if (isset
($arr_art['idart']) && isset
($arr_art['idlang'])) {
* Processes mod_rewrite related job for articles beeing moved.
* Will be called by chain 'Contenido.Article.conMoveArticles_Loop'.
* @param array $param Assoziative array with record entries
* @return array Loop through of arguments
// too defensive but secure way
} elseif (!isset
($param['idartlang'])) {
} elseif (!isset
($param['idart'])) {
if (count($arr_art) ==
2) {
* Processes mod_rewrite related job for duplicated articles.
* Will be called by chain 'Contenido.Article.conCopyArtLang_AfterInsert'.
* @param array $param Assoziative array with record entries
* @return array Loop through of arguments
// too defensive but secure way
} elseif (!isset
($param['title'])) {
} elseif (!isset
($param['idart'])) {
} elseif (!isset
($param['idlang'])) {
* Processes mod_rewrite related job for synchronized articles.
* Will be called by chain 'Contenido.Article.conSyncArticle_AfterInsert'.
* @param array $param Assoziative array with record entries as follows:
* 'src_art_lang' => Recordset (assoziative array) of source item from con_art_lang table
* 'dest_art_lang' => Recordset (assoziative array) of inserted destination item from con_art_lang table
* @return array Loop through of argument
// too defensive but secure way
} elseif (!isset
($param['src_art_lang']) ||
!is_array($param['src_art_lang'])) {
} elseif (!isset
($param['dest_art_lang']) ||
!is_array($param['dest_art_lang'])) {
} elseif (!isset
($param['dest_art_lang']['idart'])) {
} elseif (!isset
($param['dest_art_lang']['idlang'])) {
if (!isset
($param['src_art_lang']['urlname'])) {
$artLang =
new cApiArticleLanguage($param['src_art_lang']['idartlang']);
$urlname =
$artLang->get('urlname');
$urlname =
$param['src_art_lang']['urlname'];
* Works as a wrapper for ModRewrite::build_new_url() function.
* Will be called by chain 'Contenido.Frontend.CreateURL'.
* @param string $url URL to rebuild
$isXHTML =
(getEffectiveSetting('generator', 'xhtml', 'false') ==
'false') ?
false :
true;
// cleanup any existing & entities
if ($cfg['mod_rewrite']['use'] ==
1) {
// now a little hack to replace occuring index_controller.php against
// front_content.php. This happens using $auth->url()/$auth->purl()
// which composes the URL using $PHP_SELF
if (strpos($url, 'index_controller.php') !==
false) {
$url =
str_replace('index_controller.php', 'front_content.php', $url);
// self_url returns url including absoute path from root (/cms/foobar.php)
$path =
$GLOBALS['cfgClient'][$GLOBALS['client']]['path']['htmlpath'];
if (isset
($comp['path']) &&
(strpos($url, $comp['path']) ===
0)) {
if (preg_match("/^front_content\.php(.*|.+?)/i", $aUrl['url'], $arr_hits) ==
1) {
$GLOBALS['mpDebug']->addDebug($url, 'mr_build_new_url() nomatch');
// replace & against entity, if xhtml is to use
$GLOBALS['mpDebug']->addDebug($urlDebug, 'mr_build_new_url() in -> out');
* mr_build_generated_code()
* Replaces existing ancors inside passed code, while rebuilding the urls.
* Will be called by chain 'Contenido.Content.conGenerateCode' or
* 'Contenido.Frontend.HTMLCodeOutput' depening on mod_rewrite settings.
* @param string $code Code to prepare
* @return string New code
$GLOBALS['mpDebug']->addDebug($code, 'mr_build_generated_code() in');
// mod rewrite is activated
if ($cfg['mod_rewrite']['use'] ==
1) {
$sseStarttime =
getmicrotime();
// edit 060603 - anchor hack
"/<a([^>]*)href\s*=\s*[\"|\'][\/]#(.?|.+?)[\"|\']([^>]*)>/i",
create_function('$arr_matches' , 'return ModRewrite::rewrite_html_anchor($arr_matches);'),
// remove fucking tinymce single quote entities:
// IE hack with wrong base href interpretation
$code =
preg_replace("/([\"|\'|=])upload\/(.?|.+?)([\"|\'|>])/ie", "stripslashes('\\1${str_base_uri}upload/\\2\\3')", $code);
// ok let it beginn, start mod rewrite class
"/([\"|\'|=])front_content\.php(.?|.+?)([\"|\'|>])/i",
create_function('$arr_matches' , 'return $arr_matches[1] . ModRewrite::build_new_url($arr_matches[2]) . $arr_matches[3];'),
$sseEndtime =
getmicrotime();
// anchor hack for non modrewrite websites
"/<a([^>]*)href\s*=\s*[\"|\'][\/]#(.?|.+?)[\"|\']([^>]*)>/i",
create_function('$arr_matches' , 'return ModRewrite::contenido_html_anchor($arr_matches, $GLOBALS["is_XHTML"]);'),
$GLOBALS['mpDebug']->addDebug($code, 'mr_build_generated_code() out');
// print "\n\n<!-- modrewrite generation time: " . ($sseEndtime - $sseStarttime) . " seconds -->";
* Sets language of client, like done in front_content.php
* @param int $client Client id
if ($GLOBALS['lang'] || (int)
$GLOBALS['lang'] >
0) {
// there is nothing to do
// use the first language of this client
if (isset
($GLOBALS['load_lang'])) {
// load_client is set in frontend/config.php
$GLOBALS['lang'] =
$GLOBALS['load_lang'];
// try to get clients language from table
$sql =
"SELECT B.idlang FROM
".
$GLOBALS['cfg']['tab']['clients_lang'].
" AS A,
".
$GLOBALS['cfg']['tab']['lang'].
" AS B
A.idclient='" .
((int)
$client) .
"' AND
$GLOBALS['lang'] =
$aData['idlang'];
* Loads Advanced Mod Rewrite configuration for passed client using serialized
* file containing the settings.
* File is placed in /contenido/mod_rewrite/includes/and is named like
* config.mod_rewrite_{client_id}.php.
* @param int $clientId Id of client
$clientId = (int)
$clientId;
} elseif (isset
($aLoaded[$clientId])) {
$options['key'] =
$cfg['path']['contenido'] .
$cfg['path']['plugins'] .
'mod_rewrite/includes/config.mod_rewrite_' .
$clientId .
'.php';
$config =
ConfigFactory::get('serializer', $options);
$mrConfig =
$config->get();
// merge mod rewrite configuration with global cfg array
// couldn't load configuration, set defaults
include_once($cfg['path']['contenido'] .
$cfg['path']['plugins'] .
'mod_rewrite/includes/config.mod_rewrite_default.php');
$aLoaded[$clientId] =
true;
* Database query helper. Used to execute a selece statement and to return the result of first
* Minimizes following code:
* $db = new DB_Contenido();
* $sql = "SELECT * FROM foo WHERE bar='foobar'";
* $sql = "SELECT * FROM foo WHERE bar='foobar'";
* $data = mr_query_n_next_record($sql);
* @param string $query Query to execute
* @return mixed Assoziative array including recordset or null
$db =
new DB_Contenido();
return ($db->next_record()) ?
$db->Record :
null;
Documentation generated on Sun, 20 Jul 2008 16:26:48 +0200 by phpDocumentor 1.4.0