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 creation of urls using Contenido_UrlBuilder_MR.
* Will be called by chain 'Contenido.Frontend.CreateURL'.
* @deprecated Some parts of the function are replaced against new Url building
* @param string $url URL to rebuild
// NOTE: try to use new way of url building
// TODO: Usage of ContenidoUrl class is not fully discussed!
if (!isset($notFirstCall)) {
$GLOBALS['cfg']['url_builder'] = array(
'classname' => 'Contenido_UrlBuilder_MR',
'what' => 'mod_rewrite/classes/Contenido_UrlBuilder_MR.class.php'
cInclude('classes', 'mp/ContenidoUrl.class.php');
$newUrl = ContenidoUrl::build($url);
// TODO: Use this untill the code above is not cleared up
if (!isset
($mrUrlBuilder)) {
cInclude('plugins', 'mod_rewrite/classes/Contenido_UrlBuilder_MR.class.php');
$mrUrlBuilder->buildUrl(array($url));
$newUrl =
$mrUrlBuilder->getUrl();
$urlDebug['out'] =
$newUrl;
$GLOBALS['mpDebug']->addDebug($urlDebug, 'mr_build_new_url() in -> out');
// the old code 4 url building
$isXHTML = (getEffectiveSetting('generator', 'xhtml', 'false') == 'false') ? false : true;
// cleanup any existing & entities
$url = str_replace('&', '&', $url);
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'];
$comp = @parse_url($path);
if (isset($comp['path']) && (strpos($url, $comp['path']) === 0)) {
$url = substr($url, strlen($comp['path']));
$aUrl = ModRewrite::get_client_full_url_parts($url);
if (preg_match("/^front_content\.php(.*|.+?)/i", $aUrl['url'], $arr_hits) == 1) {
$url = $aUrl['htmlpath'] . ModRewrite::build_new_url($arr_hits[1]);
$GLOBALS['mpDebug']->addDebug($url, 'mr_build_new_url() nomatch');
// replace & against entity, if xhtml is to use
$url = str_replace('&', '&', $url);
$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] . mr_build_new_url("front_content.php" . $arr_matches[2]) . $arr_matches[3];'),
"/([\"|\'|=])index_controller\.php(.?|.+?)([\"|\'|>])/i",
create_function('$arr_matches' , 'return $arr_matches[1] . mr_build_new_url("front_content.php" . $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 select 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;
* Returns value of an array key (assoziative or indexed).
* Shortcut function for some ways to access to arrays:
* if (is_array($foo) && isset($foo['bar']) && $foo['bar'] == 'yieeha') {
* // new, more readable way:
* if (mr_arrayValue($foo, 'bar') == 'yieeha') {
* if (is_array($foo) && isset($foo['bar'])) {
* $jep = mr_arrayValue($foo, 'bar', 'yummy');
* @param array $array The array
* @param mixed $key Position of an indexed array or key of an assoziative array
* @param mixed $default Default value to return
* @return mixed Either the found value or the default value
} elseif (!isset
($array[$key])) {
* Request cleanup function. Request data is allways tainted and must be filtered.
* Pass the array to cleanup using several options.
* Emulates array_walk_recursive().
* @param mixed $data Data to cleanup
* @param array $options Default options array, provides only 'filter' key with several
* filter functions which are to execute as follows:
* $options['filter'] = array('trim', 'myFilterFunc');
* If no filter functions are set, 'trim', 'strip_tags' and 'stripslashes'
* will be used by default.
* A userdefined function must accept the value as a parameter and must return
* the filtered parameter, e. g.
* function myFilter($data) {
* // do what you want with the data, e. g. cleanup of xss content
* @return mixed Cleaned data
$options['filter'] =
array('trim', 'strip_tags', 'stripslashes');
foreach ($data as $p =>
$v) {
foreach ($options['filter'] as $filter) {
} elseif ($filter ==
'strip_tags') {
} elseif ($filter ==
'stripslashes') {
Documentation generated on Sun, 03 Aug 2008 22:22:01 +0200 by phpDocumentor 1.4.0