Source for file class.modrewrite.php
Documentation is available at class.modrewrite.php
* Include class to create websafe names
* @author Stefan Seifarth / stese
* @copyright © www.polycoder.de
* @author Murat Purc <murat@purc.de>
/******************************************
* File : class.modrewrite.php
* Descr : class to create websafe names
* Author : Stefan Seifarth / stese
* Class to create websafe names
* TODO: Adapt to PHP 5 coding standards...
* @author Stefan Seifarth / stese
return ($cfg['mod_rewrite']['use'] ==
1) ?
true :
false;
* Check categories on websafe name
* Check all categories in the main parent
* category on existing same websafe name
* @param string Websafe name to check
* @param integer current category id
* @param integer current language id
* @return boolean true if websafename already exists, false if not
function in_category ( $str_name =
"", $int_id =
0, $int_lang_id =
0) {
$sql =
"SELECT parentid FROM " .
$cfg["tab"]["cat"] .
" WHERE idcat = '$int_id'";
$int_parent_id =
($aData['parentid'] >
0 ) ? (int)
$aData['parentid'] :
0;
$str_where =
" c.parentid = '$int_parent_id' AND";
$str_where.=
" cl.idlang = '" .
$int_lang_id .
"' AND
cl.urlname = '" .
$str_name .
"' AND
// check if websafe name is in this category
$sql =
"SELECT count(cl.idcat) as numcats FROM " .
$cfg["tab"]["cat_lang"] .
" cl LEFT JOIN " .
$cfg["tab"]["cat"] .
" c ON cl.idcat = c.idcat WHERE " .
$str_where;
return ($aData['numcats'] >
0) ?
true :
false;
* Check articles on websafe name
* Check all articles in the current category
* on existing same websafe name
* @param string Websafe name to check
* @param integer current article id
* @param integer current language id
* @return boolean true if websafename already exists, false if not
function in_articles ( $str_name =
"", $int_id =
0, $int_lang_id =
0, $int_idcat =
0) {
$int_category_id =
$int_idcat;
// get category id if not set
$sql =
"SELECT idcat FROM " .
$cfg["tab"]["cat_art"] .
" WHERE idart = '$int_id'";
$int_category_id =
($aData['idcat'] >
0 ) ? (int)
$aData['idcat'] :
0;
$str_where =
" ca.idcat = '$int_category_id' AND";
$str_where.=
" al.idlang = '" .
$int_lang_id .
"' AND
al.urlname = '" .
$str_name .
"' AND
// check if websafe name is in this category
$sql =
"SELECT count(al.idart) as numcats FROM " .
$cfg["tab"]["art_lang"] .
" al LEFT JOIN " .
$cfg["tab"]["cat_art"] .
" ca ON al.idart = ca.idart WHERE " .
$str_where;
return ($aData['numcats'] >
0) ?
true :
false;
* set websafe name in article list
* insert new websafe name in article list
* @param string original name (will be converted)
* @param integer current article id
* @param integer current language id
* @return boolean true if insert was successfully
function set_article ( $str_name =
"", $int_id =
0, $int_lang_id =
0, $int_idcat =
0) {
$str_new_name =
str_replace( $cfg["mod_rewrite"]['article_seperator'], $cfg["mod_rewrite"]['article_word_seperator'], $str_new_name );
// check for double word seperators
if ( strlen(trim($cfg["mod_rewrite"]['article_word_seperator'])) >
0 ) {
while ( ereg($cfg["mod_rewrite"]['article_word_seperator'].
$cfg["mod_rewrite"]['article_word_seperator'],$str_new_name) ) {
$str_new_name =
str_replace($cfg["mod_rewrite"]['article_word_seperator'].
$cfg["mod_rewrite"]['article_word_seperator'], $cfg["mod_rewrite"]['article_word_seperator'],$str_new_name);
// check if websafe name already exists
// create new websafe name if exists
$str_new_name =
$str_new_name .
$int_id;
// check again - and set name
// insert websafe name in article list
$sql =
"UPDATE " .
$cfg["tab"]["art_lang"] .
" SET urlname = '$str_new_name' WHERE idart = '$int_id' AND idlang = '$int_lang_id'";
* set websafe name in category list
* insert new websafe name in category list
* @param string original name (will be converted) or alias
* @param integer current article id
* @param integer current language id
* @return boolean true if insert was successfully
function set_category ( $str_name =
"", $int_id =
0, $int_lang_id =
0) {
$str_new_name =
str_replace( $cfg["mod_rewrite"]['category_seperator'], $cfg["mod_rewrite"]['category_word_seperator'], $str_new_name );
$str_new_name =
str_replace( $cfg["mod_rewrite"]['article_seperator'], $cfg["mod_rewrite"]['category_word_seperator'], $str_new_name );
// check for double word seperators
if ( strlen(trim($cfg["mod_rewrite"]['category_word_seperator'])) >
0 ) {
while ( ereg($cfg["mod_rewrite"]['category_word_seperator'].
$cfg["mod_rewrite"]['category_word_seperator'],$str_new_name) ) {
$str_new_name =
str_replace($cfg["mod_rewrite"]['category_word_seperator'].
$cfg["mod_rewrite"]['category_word_seperator'], $cfg["mod_rewrite"]['category_word_seperator'],$str_new_name);
// check if websafe name already exists
// create new websafe name if exists
$str_new_name =
$str_new_name .
$int_id;
// check again - and set name
// insert websafe name in article list
$sql =
"UPDATE " .
$cfg["tab"]["cat_lang"] .
" SET urlname = '$str_new_name' WHERE idcat = '$int_id' AND idlang = '$int_lang_id'";
* get_id_from_idartlang()
* get article id and language id from article language id
* @param integer current article id
* @return Array Array with idart and idlang of current article
$sql =
"SELECT idart, idlang FROM " .
$cfg["tab"]["art_lang"] .
" WHERE idartlang = '$int_id'";
* get category name from category id and language id
* @param integer category id
* @param integer language id
* @return string category name
function get_catname ( $int_id =
0, $int_lang_id =
0 ) {
$sql =
"SELECT name FROM " .
$cfg["tab"]["cat_lang"] .
" WHERE idcat = '$int_id' AND idlang = '$int_lang_id'";
* get article name from article id and language id
* @param integer article id
* @param integer language id
* @return string article name
$sql =
"SELECT title FROM " .
$cfg["tab"]["art_lang"] .
" WHERE idart = '$int_id' AND idlang = '$int_lang_id'";
* get language ids from category id
* @param integer category id
* @return array used language ids
$sql =
"SELECT idlang FROM " .
$cfg["tab"]["cat_lang"] .
" WHERE idcat = '$int_id'";
$arr_languages =
Array();
while ($db->next_record()) {
$arr_languages[] =
$db->f("idlang");
* get article title, language id
* @param integer idartlang
* @return array title, idlang
$sql =
"SELECT urlname, idlang FROM " .
$cfg["tab"]["art_lang"] .
" WHERE idartlang = '$int_id'";
* build a recursiv path for mod_rewrite rule like
* server directories ( dir1/dir2/dir3 )
* @param integer latest category id
* @return string linkpath with correct uri
$arr_directories =
Array();
$int_tmp_idcat =
$int_id;
$str_join_parameter =
'/';
while ($bool_finish ==
false ) {
$sql =
"SELECT cl.urlname, c.parentid
FROM " .
$cfg["tab"]["cat_lang"] .
" cl
LEFT JOIN " .
$cfg["tab"]["cat"] .
" c
WHERE cl.idcat = '$int_tmp_idcat'
AND cl.idlang = '$int_lang_id'";
$arr_directories[] =
$aData['urlname'];
$int_tmp_idcat =
$aData['parentid'];
if ($aData['parentid'] ==
0 ||
$aData['parentid'] ==
$int_lastid) {
$str_join_parameter =
$cfg["mod_rewrite"]['category_seperator'];
// reverse array entries and create directory string
* return full contenido url from single anchor
* @param array $arr_matches [0] = complete anchor, [1] = pre arguments, [2] = anchor name, [3] = post arguments
* @return string new anchor
global $parts, $idcat, $idart, $artname, $client, $lang, $sess;
if (isset
( $artname ) &&
strlen($artname) >
0 ) {
$str_idart =
'&idart=' .
$idart;
// check for additional parameter in url
$arr_ignored_params =
array ( 'idcat', 'idart', 'lang', 'client', 'idcatart', 'changelang', 'changeclient', 'idartlang', 'parts', 'artname' );
//print_r ( $arr_matches);
if (isset
($_GET) &&
count($_GET)>
0 ) {
foreach ( $_GET as $str_key =>
$str_value) {
$arr_no_anchor =
explode("#",$str_value);
$str_new_url =
'<a' .
$arr_matches[1] .
'href="' .
$sess->url(
) .
'"' .
$arr_matches[3] .
'>';
* return full contenido url from single anchor
* @param array $arr_matches [0] = complete anchor, [1] = pre arguments, [2] = anchor name, [3] = post arguments
* @return string new anchor
global $parts, $idcat, $idart, $artname, $client, $lang, $sess;
$str_join_parameter =
$str_xhtml ?
'&' :
'&';
foreach ( $_GET as $str_key =>
$str_value ) {
$arr_no_anchor =
explode("#",$str_value);
$str_new_url =
'<a' .
$arr_matches[1] .
'href="' .
$sess->url( 'front_content.php?' .
implode($str_join_parameter, $arr_params) .
'#' .
$arr_matches[2] ) .
'"' .
$arr_matches[3] .
'>';
* build new url from given arguments
* get querystring of front_content.php and
* convert this url to the new mod_rewrite url
* method will be startet before the complete
* output of the front site will be executed
* @deprecated Functionaliy will be managed by Contenido_UrlBuilder_MR
* Is no more used and should removed, Murat Purc
* @param string given arguments
* @modified Stefan Seifarth 2005-08-14
global $cfg, $lang, $client;
$str_join_parameter =
"/";
$str_file_extension =
"";
$str_join_parameter =
$cfg['mod_rewrite']['category_seperator'];
$str_file_extension =
$cfg['mod_rewrite']['file_extension'];
// check arguments ... and split
$arr_args =
explode("#", $str_args);
$str_args =
$arr_args[0];
// extract arguments into current scope
// some preparations to avoid too much checks in further code blocks
$idcat =
(isset
($idcat)) ? (int)
$idcat :
0;
$idart =
(isset
($idart)) ? (int)
$idart :
0;
$idcatart =
(isset
($idcatart)) ? (int)
$idcatart :
0;
$idartlang =
(isset
($idartlang)) ? (int)
$idartlang :
0;
$changelang =
(isset
($changelang)) ? (int)
$changelang :
0;
$changeclient =
(isset
($changeclient)) ? (int)
$changeclient :
0;
// get additional non contenido parameters
$str_additional_params =
'';
$arr_additional_params =
array();
$arr_param_pairs =
split( "&", $str_args );
$arr_ignored_params =
array ( 'idcat', 'idart', 'lang', 'client', 'idcatart', 'changelang', 'changeclient', 'idartlang' );
foreach ( $arr_param_pairs as $str_pair ) {
$arr_param =
split ( "=", $str_pair );
foreach ( $arr_ignored_params as $str_key ) {
if ( $bol_found_bad ==
false ) {
if ( count ( $arr_additional_params ) >
0 ) {
$str_glue =
( $str_xhtml ==
true ) ?
'&' :
'&';
$str_additional_params =
'?' .
implode ( $str_glue, $arr_additional_params );
$idlang =
($changelang >
0) ?
$changelang :
$lang;
$idclient =
($changeclient >
0) ?
$changeclient :
$client;
if ( $cfg['mod_rewrite']['use_client'] ==
1 ) {
if ( $cfg['mod_rewrite']['use_client_name'] ==
1 ) {
$arr_parts[] =
$idclient;
if ( $cfg['mod_rewrite']['use_language'] ==
1 ) {
if ( $cfg['mod_rewrite']['use_language_name'] ==
1 ) {
$str_new_url =
$cfg['mod_rewrite']['rootdir'];
if ($idcatart >
0 &&
$idcat ==
0 &&
$idart ==
0 &&
$idartlang ==
0) {
$sql =
"SELECT idcat, idart FROM " .
$cfg["tab"]["cat_art"] .
" WHERE idcatart = '$idcatart'";
$idcat =
$aData['idcat'];
$idart =
$aData['idart'];
// check if article id is given and set article url
if ($idart >
0 &&
$idartlang ==
0) {
} elseif ($idartlang >
0 &&
$idart ==
0) {
// check if only article id is given, cat id have to rebuild
if ($idart >
0 &&
$idcat ==
0 &&
$idartlang ==
0) {
$sql =
"SELECT idcat FROM " .
$cfg["tab"]["cat_art"] .
" WHERE idart = '$idart'";
$idcat =
$aData['idcat'];
if ($idartlang >
0 &&
$idcat ==
0 &&
$idart ==
0) {
FROM " .
$cfg["tab"]["art_lang"] .
" al
LEFT JOIN " .
$cfg["tab"]["cat_art"] .
" ca ON al.idart = ca.idart
WHERE al.idartlang = '$idartlang'";
$idcat =
$aData['idcat'];
// we have category but no article name and start article name should be added to url
if ($idcat >
0 &&
$str_article ==
'' &&
$cfg['mod_rewrite']['add_startart_name_to_url']) {
if ($cfg['mod_rewrite']['default_startart_name'] ==
'') {
// no default article name is configured get startarticle
cInclude('classes', 'class.article.php');
$artColl =
new ArticleCollection(array('idcat' =>
$idcat, 'start' =>
1));
if ($artItem =
$artColl->startArticle()) {
$idart =
$artItem->get('idart');
// use default start article name
$str_article =
$cfg['mod_rewrite']['default_startart_name'];
$str_file_extension =
$cfg['mod_rewrite']['file_extension'];
// ok build dir list, if idcat found ...
// check start directory settings
if ( $cfg['mod_rewrite']['startfromroot'] ==
0 ) {
// splitt string in array
$arr_categories =
split( $str_join_parameter, $str_categories);
// implode array with categories to new string
$str_categories =
join ( $str_join_parameter, $arr_categories );
if (strlen($str_categories)>
0) {
$arr_parts[] =
$str_categories;
$str_parts =
implode( $str_join_parameter, $arr_parts);
$str_parts.=
$cfg['mod_rewrite']['article_seperator'];
} else if ((int)
$cfg['mod_rewrite']['use_categories_as_html_file'] !=
1 &&
strlen($str_parts) >
0) {
$str_parts.=
$str_join_parameter;
if ( $cfg['mod_rewrite']['use_lowercase_uri'] ==
1 ) {
$str_full_url =
$str_new_url .
strtolower( $str_parts .
$str_article .
$str_file_extension ) .
$str_additional_params .
$str_anchor;
$str_full_url =
$str_new_url .
$str_parts .
$str_article .
$str_file_extension .
$str_additional_params .
$str_anchor;
while ( eregi($str_join_parameter.
$str_join_parameter, $str_full_url) ) {
$str_full_url =
eregi_replace ( $str_join_parameter.
$str_join_parameter, $str_join_parameter, $str_full_url );
if (substr ($str_full_url, -
2) ==
"?=") {
* get article websafe name from article id and language id
* @param integer article id
* @param integer language id
* @return string article websafe name
$sql =
"SELECT urlname FROM " .
$cfg["tab"]["art_lang"] .
" WHERE idart = '$int_id' AND idlang = '$int_lang_id'";
* get_art_lang_websafename()
* get article websafe name from idartlang
* @param integer idartlang
* @return string article websafe name
$sql =
"SELECT urlname FROM " .
$cfg["tab"]["art_lang"] .
" WHERE idartlang = '$int_id'";
* @param integer language id
* @return string language name
$sql =
"SELECT name FROM " .
$cfg["tab"]["clients"] .
" WHERE idclient = '$int_id'";
* get name of language id
* @param integer language id
* @return string language name
$sql =
"SELECT name FROM " .
$cfg["tab"]["lang"] .
" WHERE idlang = '$int_id'";
* Returns name of language
* @param int $int_id Language id
* @return array Assoziative array containing lanuage names ($a[id] = 'name')
if (isset
($aName[$int_id])) {
$sql =
"SELECT name FROM " .
$cfg["tab"]["lang"] .
" WHERE idlang = '$int_id'";
$aName[$int_id] =
$aData['name'];
* get_client_full_url_parts()
* Splits passed argument into scheme://host and path/query.
* input = http://host/front_content.php?idcat=123
* return = array('htmlpath' => 'http://host', 'url' => 'front_content.php?idcat=123')
* @param string $url URL to split
* @return array Assoziative array including the two parts:
* - array('htmlpath' => $path, 'url' => $url)
global $cfg, $cfgClient, $client;
$clientPath =
$cfgClient[$client]['path']['htmlpath'];
if (stristr($url, $clientPath) !==
false) {
// url includes full html path (scheme host path, etc.)
// check if path matches to defined rootdir from mod_rewrite conf
if (isset
($aComp['path']) &&
$aComp['path'] !==
$cfg['mod_rewrite']['rootdir']) {
// replace not matching path agaings configured one
// this will replace e. g. "http://host/cms/" against "http://host/"
$htmlPath =
str_replace($aComp['path'], $cfg['mod_rewrite']['rootdir'], $htmlPath);
return array('htmlpath' =>
$htmlPath, 'url' =>
$url);
* reset_categories_aliases()
* method to reset all aliases in categories
$db =
new DB_Contenido();
$sql =
"UPDATE " .
$cfg["tab"]["cat_lang"] .
" SET urlname = ''";
$sql =
"SELECT name, idcat, idlang FROM " .
$cfg["tab"]["cat_lang"];
while ( $db->next_record() ) {
* reset_articles_aliases()
* method to reset all aliases in articles
$db =
new DB_Contenido();
$sql =
"UPDATE " .
$cfg["tab"]["art_lang"] .
" SET urlname = ''";
$sql =
"SELECT title, idart, idlang FROM " .
$cfg["tab"]["art_lang"];
while ( $db->next_record() ) {
* method to reset all aliases (category and article)
* Used to postprocess resolved path
* Error site handling if category not found
* if percentage == 100 and there is no 100 percentage result value,
* error site will be shown - can be adjust by user settings for
* smooth similar effects - 80 to 95 will be best but have to check by user
* @param array $results Pathresolver results array
* @return mixed Categoryid or false
$intMinPercentage =
$cfg["mod_rewrite"]['category_resolve_min_percentage'];
if (isset
($intMinPercentage) && (int)
$intMinPercentage >
0 &&
$results[$catId] <
$intMinPercentage) {
* Analyses the settings for usage of categories as a html file and returns
* the result as a boolean
* @return bool True if settings are active and valid otherwhise false.
if ((int)
$cfg["mod_rewrite"]['use_categories_as_html_file'] ==
1
&&
strlen($cfg["mod_rewrite"]['article_seperator']) >
0
&&
strlen($cfg["mod_rewrite"]['category_seperator']) >
0
&&
$cfg["mod_rewrite"]['category_seperator'] !=
$cfg["mod_rewrite"]['article_seperator']) {
// settings are ok, return true
// settings are are deactivated or faulty
Documentation generated on Sun, 03 Aug 2008 22:21:45 +0200 by phpDocumentor 1.4.0