Source for file class.modrewrite.php

Documentation is available at class.modrewrite.php

  1. <?php
  2. /**
  3.  * Include class to create websafe names
  4.  *
  5.  * @author      Stefan Seifarth / stese
  6.  * @copyright   © www.polycoder.de
  7.  * @author      Murat Purc <murat@purc.de>
  8.  * @date        04.12.2004
  9.  * @date        28.12.2005
  10.  * @package     Contenido
  11.  * @subpackage  ModRewrite
  12.  */
  13.  
  14. /******************************************
  15.  * File      :   class.modrewrite.php
  16.  * Project   :   Contenido
  17.  * Descr     :   class to create websafe names
  18.  *
  19.  * Author    :   Stefan Seifarth / stese
  20.  * Created   :   04.12.2004
  21.  * Modified  :   28.12.2005
  22.  *
  23.  * © www.polycoder.de
  24.  */
  25.  
  26.  
  27. if(!defined('CON_FRAMEWORK')) {
  28.     die('Illegal call');
  29. }
  30.  
  31.  
  32. /**
  33.  * Class to create websafe names
  34.  *
  35.  * TODO: Adapt to PHP 5 coding standards...
  36.  *
  37.  * @author      Stefan Seifarth / stese
  38.  * @package     Contenido
  39.  * @subpackage  ModRewrite
  40.  */
  41. class ModRewrite {
  42.  
  43.     /**
  44.      * Constructor Function
  45.      */
  46.     function ModRewrite({
  47.         // empty
  48.     }
  49.  
  50.  
  51.     function is_enabled(){
  52.         global $cfg;
  53.         return ($cfg['mod_rewrite']['use'== 1true false;
  54.     }
  55.  
  56.     /**
  57.      * in_categories()
  58.      *
  59.      * Check categories on websafe name
  60.      *
  61.      * Check all categories in the main parent
  62.      * category on existing same websafe name
  63.      *
  64.      * @param    string    Websafe name to check
  65.      * @param    integer    current category id
  66.      * @param    integer current language id
  67.      * @return     boolean    true if websafename already exists, false if not
  68.      */
  69.     function in_category $str_name ""$int_id 0$int_lang_id 0{
  70.         global $cfg;
  71.  
  72.         // get parentid
  73.         $int_parent_id 0;
  74.         $sql "SELECT parentid FROM " $cfg["tab"]["cat"" WHERE idcat = '$int_id'";
  75.         if ($aData mr_query_n_next_record($sql)) {
  76.             $int_parent_id ($aData['parentid'? (int) $aData['parentid'0;
  77.         }
  78.  
  79.         $str_where " c.parentid = '$int_parent_id' AND";
  80.         $str_where.= "     cl.idlang = '" $int_lang_id "' AND
  81.                         cl.urlname = '" $str_name "' AND
  82.         cl.idcat <> '$int_id'";
  83.  
  84.         // check if websafe name is in this category
  85.         $int_count 0;
  86.         $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;
  87.         if ($aData mr_query_n_next_record($sql)) {
  88.             return ($aData['numcats'0true false;
  89.         }
  90.  
  91.         return false;
  92.     // end function
  93.  
  94.  
  95.     /**
  96.      * in_articles()
  97.      *
  98.      * Check articles on websafe name
  99.      *
  100.      * Check all articles in the current category
  101.      * on existing same websafe name
  102.      *
  103.      * @param    string    Websafe name to check
  104.      * @param    integer    current article id
  105.      * @param    integer current language id
  106.      * @return     boolean    true if websafename already exists, false if not
  107.      */
  108.     function in_articles $str_name ""$int_id 0$int_lang_id 0$int_idcat 0{
  109.         global $cfg;
  110.  
  111.         // handle multipages
  112.         $int_category_id 0;
  113.         if ($int_idcat 0{
  114.             $int_category_id $int_idcat;
  115.         else {
  116.             // get category id if not set
  117.             $sql "SELECT idcat FROM " $cfg["tab"]["cat_art"" WHERE idart = '$int_id'";
  118.             if ($aData mr_query_n_next_record($sql)) {
  119.                 $int_category_id ($aData['idcat'? (int) $aData['idcat'0;
  120.             }
  121.         }
  122.  
  123.         $str_where " ca.idcat = '$int_category_id' AND";
  124.         $str_where.= "     al.idlang = '" $int_lang_id "' AND
  125.                         al.urlname = '" $str_name "' AND
  126.         al.idart <> '$int_id'";
  127.  
  128.         // check if websafe name is in this category
  129.         $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;
  130.         if ($aData mr_query_n_next_record($sql)) {
  131.             return ($aData['numcats'0true false;
  132.         }
  133.  
  134.         return false;
  135.     // end function
  136.  
  137.  
  138.     /**
  139.      * set_article()
  140.      *
  141.      * set websafe name in article list
  142.      *
  143.      * insert new websafe name in article list
  144.      *
  145.      * @param    string    original name (will be converted)
  146.      * @param    integer    current article id
  147.      * @param    integer current language id
  148.      * @return     boolean    true if insert was successfully
  149.      */
  150.     function set_article $str_name ""$int_id 0$int_lang_id 0$int_idcat 0{
  151.         global $cfg;
  152.  
  153.         // create websafe name
  154.         $str_new_name capiStrCleanURLCharacters(html_entity_decode($str_name));
  155.  
  156.         // only html files part
  157.             $str_new_name str_replace$cfg["mod_rewrite"]['article_seperator']$cfg["mod_rewrite"]['article_word_seperator']$str_new_name );
  158.         }
  159.  
  160.         // check for double word seperators
  161.         if strlen(trim($cfg["mod_rewrite"]['article_word_seperator'])) {
  162.             while ereg($cfg["mod_rewrite"]['article_word_seperator'].$cfg["mod_rewrite"]['article_word_seperator'],$str_new_name) ) {
  163.                 $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);
  164.             }
  165.         }
  166.  
  167.         // check if websafe name already exists
  168.         if ModRewrite::in_articles($str_new_name$int_id$int_lang_id$int_idcat) ) {
  169.             // create new websafe name if exists
  170.             $str_new_name $str_new_name $int_id;
  171.         }
  172.  
  173.         // check again - and set name
  174.         if (!ModRewrite::in_articles($str_new_name$int_id$int_lang_id$int_idcat)) {
  175.  
  176.             // insert websafe name in article list
  177.             $db new DB_Contenido;
  178.             $sql "UPDATE " $cfg["tab"]["art_lang"" SET urlname = '$str_new_name' WHERE idart = '$int_id' AND idlang = '$int_lang_id'";
  179.             return $db->query($sql);
  180.  
  181.         else {
  182.             return false;
  183.         }
  184.     // end function
  185.  
  186.  
  187.     /**
  188.      * set_category()
  189.      *
  190.      * set websafe name in category list
  191.      *
  192.      * insert new websafe name in category list
  193.      *
  194.      * @param    string    original name (will be converted) or alias
  195.      * @param    integer    current article id
  196.      * @param    integer current language id
  197.      * @return     boolean    true if insert was successfully
  198.      */
  199.     function set_category $str_name ""$int_id 0$int_lang_id 0{
  200.         global $cfg;
  201.  
  202.         // create websafe name
  203.         $str_new_name capiStrCleanURLCharacters(html_entity_decode($str_name));
  204.  
  205.         // only html files part
  206.             $str_new_name str_replace$cfg["mod_rewrite"]['category_seperator']$cfg["mod_rewrite"]['category_word_seperator']$str_new_name );
  207.             $str_new_name str_replace$cfg["mod_rewrite"]['article_seperator']$cfg["mod_rewrite"]['category_word_seperator']$str_new_name );
  208.         }
  209.  
  210.         // check for double word seperators
  211.         if strlen(trim($cfg["mod_rewrite"]['category_word_seperator'])) {
  212.          while ereg($cfg["mod_rewrite"]['category_word_seperator'].$cfg["mod_rewrite"]['category_word_seperator'],$str_new_name) ) {
  213.              $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);
  214.          }
  215.         }
  216.  
  217.         // check if websafe name already exists
  218.         if (ModRewrite::in_category($str_new_name$int_id$int_lang_id)) {
  219.             // create new websafe name if exists
  220.             $str_new_name $str_new_name $int_id;
  221.         }
  222.  
  223.  
  224.         // check again - and set name
  225.         if (!ModRewrite::in_category($str_new_name$int_id$int_lang_id)) {
  226.  
  227.             // insert websafe name in article list
  228.             $db new DB_Contenido;
  229.             $sql "UPDATE " $cfg["tab"]["cat_lang"" SET urlname = '$str_new_name' WHERE idcat = '$int_id' AND idlang = '$int_lang_id'";
  230.             return $db->query($sql);
  231.  
  232.         else {
  233.             return false;
  234.         }
  235.     // end function
  236.  
  237.  
  238.     /**
  239.      * get_id_from_idartlang()
  240.      *
  241.      * get article id and language id from article language id
  242.      *
  243.      * @param    integer    current article id
  244.      * @return     Array    Array with idart and idlang of current article
  245.      */
  246.     function get_id_from_idartlang $int_id {
  247.         global $cfg;
  248.         $sql "SELECT idart, idlang FROM " $cfg["tab"]["art_lang"" WHERE idartlang = '$int_id'";
  249.         if ($aData mr_query_n_next_record($sql)) {
  250.             return $aData;
  251.         }
  252.         return array();
  253.     }    // end function
  254.  
  255.  
  256.     /**
  257.      * get_catname()
  258.      *
  259.      * get category name from category id and language id
  260.      *
  261.      * @param    integer    category id
  262.      * @param    integer    language id
  263.      * @return     string    category name
  264.      */
  265.     function get_catname $int_id 0$int_lang_id {
  266.         global $cfg;
  267.         $sql "SELECT name FROM " $cfg["tab"]["cat_lang"" WHERE idcat = '$int_id' AND idlang = '$int_lang_id'";
  268.         if ($aData mr_query_n_next_record($sql)) {
  269.             return $aData['name'];
  270.         }
  271.         return '';
  272.     }    // end function
  273.  
  274.  
  275.     /**
  276.      * get_arttitle()
  277.      *
  278.      * get article name from article id and language id
  279.      *
  280.      * @param    integer    article id
  281.      * @param    integer    language id
  282.      * @return     string    article name
  283.      */
  284.     function get_arttitle $int_id 0$int_lang_id {
  285.         global $cfg;
  286.         $sql "SELECT title FROM " $cfg["tab"]["art_lang"" WHERE idart = '$int_id' AND idlang = '$int_lang_id'";
  287.         if ($aData mr_query_n_next_record($sql)) {
  288.             return $aData['title'];
  289.         }
  290.         return '';
  291.     }    // end function
  292.  
  293.  
  294.     /**
  295.      * get_cat_languages()
  296.      *
  297.      * get language ids from category id
  298.      *
  299.      * @param    integer    category id
  300.      * @return     array    used language ids
  301.      */
  302.     function get_cat_languages $int_id {
  303.         global $cfg;
  304.  
  305.         $db new DB_Contenido;
  306.         $sql "SELECT idlang FROM " $cfg["tab"]["cat_lang"" WHERE idcat = '$int_id'";
  307.         $db->query($sql);
  308.  
  309.         $arr_languages Array();
  310.         while ($db->next_record()) {
  311.             $arr_languages[$db->f("idlang");
  312.         }
  313.  
  314.         return $arr_languages;
  315.  
  316.     }    // end function
  317.  
  318.  
  319.     /**
  320.      * get_artids()
  321.      *
  322.      * get article title, language id
  323.      *
  324.      * @param    integer    idartlang
  325.      * @return     array    title, idlang
  326.      */
  327.     function get_artids $int_id {
  328.         global $cfg;
  329.         $sql "SELECT urlname, idlang FROM " $cfg["tab"]["art_lang"" WHERE idartlang = '$int_id'";
  330.         if ($aData mr_query_n_next_record($sql)) {
  331.             return $aData;
  332.         }
  333.         return array();
  334.     }    // end function
  335.  
  336.  
  337.     /**
  338.      * build_recursiv_path()
  339.      *
  340.      * build a recursiv path for mod_rewrite rule like
  341.      * server directories ( dir1/dir2/dir3 )
  342.      *
  343.      * @param    integer    latest category id
  344.      * @return     string    linkpath with correct uri
  345.      */
  346.     function build_recursiv_path $int_id 0$int_lang_id 0$int_lastid {
  347.         global $cfg;
  348.  
  349.         $arr_directories Array();
  350.         $bool_finish false;
  351.         $int_tmp_idcat $int_id;
  352.         $str_join_parameter '/';
  353.  
  354.         while ($bool_finish == false {
  355.             $sql "SELECT cl.urlname, c.parentid
  356.                     FROM " $cfg["tab"]["cat_lang"" cl
  357.                     LEFT JOIN  " $cfg["tab"]["cat"" c
  358.             ON cl.idcat = c.idcat
  359.             WHERE cl.idcat = '$int_tmp_idcat'
  360.             AND cl.idlang = '$int_lang_id'";
  361.             if ($aData mr_query_n_next_record($sql)) {
  362.                 $arr_directories[$aData['urlname'];
  363.                 $int_tmp_idcat     $aData['parentid'];
  364.  
  365.                 if ($aData['parentid'== || $aData['parentid'== $int_lastid{
  366.                     $bool_finish true;
  367.                 }
  368.             else {
  369.                 $bool_finish true;
  370.             }
  371.         }
  372.  
  373.         // only html files part
  374.             $str_join_parameter $cfg["mod_rewrite"]['category_seperator'];
  375.         }
  376.  
  377.         // reverse array entries and create directory string
  378.         $str_path join($str_join_parameter,array_reverse($arr_directories));
  379.  
  380.         return $str_path;
  381.  
  382.     }    // end function
  383.  
  384.  
  385.     /**
  386.      * return full contenido url from single anchor
  387.      *
  388.      * @param array $arr_matches [0] = complete anchor, [1] = pre arguments, [2] = anchor name, [3] = post arguments
  389.      * @return string new anchor
  390.      */
  391.     function rewrite_html_anchor$arr_matches array() ) {
  392.         global $parts$idcat$idart$artname$client$lang$sess;
  393.  
  394.         // set article name
  395.         $str_idart '';
  396.         if (isset $artname && strlen($artname{
  397.             $str_idart '&idart=' $idart;
  398.         }
  399.  
  400.         // check for additional parameter in url
  401.         $arr_ignored_params array 'idcat''idart''lang''client''idcatart''changelang''changeclient''idartlang''parts''artname' );
  402.         $str_other_params '';
  403.  
  404.         //print_r ( $arr_matches);
  405.  
  406.         if (isset($_GET&& count($_GET)>{
  407.             //print_r ( $_GET);
  408.  
  409.             foreach $_GET as $str_key => $str_value{
  410.                 if (!in_array($str_key$arr_ignored_params&& strlen(trim($str_value)) {
  411.                     $arr_no_anchor explode("#",$str_value);
  412.  
  413.                     $str_other_params .= '&' urlencode(urldecode($str_key)) '=' urlencode(urldecode($str_value));
  414.                 }
  415.             }
  416.         }
  417.         $str_new_url '<a' $arr_matches[1'href="' $sess->url(
  418.             'front_content.php?' .
  419.             'idcat=' $idcat .
  420.             '&client=' $client .
  421.             '&changelang=' $lang .
  422.         $str_idart .
  423.         $str_other_params .
  424.             '#' $arr_matches[2]
  425.         '"' $arr_matches[3'>';
  426.  
  427.         return $str_new_url;
  428.     }
  429.  
  430.  
  431.     /**
  432.      * return full contenido url from single anchor
  433.      *
  434.      * @param array $arr_matches [0] = complete anchor, [1] = pre arguments, [2] = anchor name, [3] = post arguments
  435.      * @return string new anchor
  436.      */
  437.     function contenido_html_anchor$arr_matches array()$str_xhtml true {
  438.         global $parts$idcat$idart$artname$client$lang$sess;
  439.  
  440.         $arr_params array();
  441.         $str_join_parameter $str_xhtml '&amp;' '&';
  442.  
  443.         foreach $_GET as $str_key => $str_value {
  444.             $arr_no_anchor explode("#",$str_value);
  445.             $arr_params[urlencode(urldecode($str_key)) '=' urlencode(urldecode($arr_no_anchor[0]));
  446.         }
  447.  
  448.         $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'>';
  449.  
  450.         return $str_new_url;
  451.     }
  452.  
  453.  
  454.     /**
  455.      * build_new_url()
  456.      *
  457.      * build new url from given arguments
  458.      *
  459.      * get querystring of front_content.php and
  460.      * convert this url to the new mod_rewrite url
  461.      * method will be startet before the complete
  462.      * output of the front site will be executed
  463.      *
  464.      * @deprecated Functionaliy will be managed by Contenido_UrlBuilder_MR
  465.      *              Is no more used and should removed, Murat Purc
  466.      *
  467.      * @param    string   given arguments
  468.      * @return   string   new url
  469.      * @modified Stefan Seifarth 2005-08-14
  470.      */
  471.     function build_new_url $str_args ""$str_xhtml true {
  472.         global $cfg$lang$client;
  473.  
  474.         $str_new_url "";
  475.         $str_categories "";
  476.         $str_article "";
  477.         $arr_args array();
  478.         $str_join_parameter "/";
  479.         $str_file_extension "";
  480.         $arr_parts array();
  481.  
  482.         // only html files part
  483.             $str_join_parameter $cfg['mod_rewrite']['category_seperator'];
  484.             $str_file_extension $cfg['mod_rewrite']['file_extension'];
  485.         }
  486.  
  487.         // check arguments ... and split
  488.         $str_anchor "";
  489.         // check for anchor
  490.         $arr_args explode("#"$str_args);
  491.         if (is_array($arr_args&& count($arr_args)>1{
  492.             $str_args $arr_args[0];
  493.             $str_anchor '#' urlencode(urldecode($arr_args[1]));
  494.         }
  495.  
  496.         $str_args str_replace('?'''$str_args);
  497.         $str_args str_replace('&amp;''&'$str_args);
  498.         // extract arguments into current scope
  499.         parse_str ($str_args);
  500.  
  501.         // some preparations to avoid too much checks in further code blocks
  502.         $idcat        (isset($idcat)) ? (int) $idcat 0;
  503.         $idart        (isset($idart)) ? (int) $idart 0;
  504.         $idcatart     (isset($idcatart)) ? (int) $idcatart 0;
  505.         $idartlang    (isset($idartlang)) ? (int) $idartlang 0;
  506.         $changelang   (isset($changelang)) ? (int) $changelang 0;
  507.         $changeclient (isset($changeclient)) ? (int) $changeclient 0;
  508.  
  509.         // get additional non contenido parameters
  510.         $str_additional_params '';
  511.         $arr_additional_params array();
  512.         $arr_param_pairs split"&"$str_args );
  513.  
  514.         $arr_ignored_params array 'idcat''idart''lang''client''idcatart''changelang''changeclient''idartlang' );
  515.  
  516.         foreach $arr_param_pairs as $str_pair {
  517.             $bol_found_bad false;
  518.             $arr_param split "="$str_pair );
  519.  
  520.             foreach $arr_ignored_params as $str_key {
  521.                 if $str_key == strtolower(trim($arr_param[0])) ) {
  522.                     $bol_found_bad true;
  523.                     break;
  524.                 }
  525.             }
  526.  
  527.             if $bol_found_bad == false {
  528.                 $arr_additional_params[urlencode(urldecode($arr_param[0])) '=' urlencode(urldecode($arr_param[1]));
  529.             }
  530.         }
  531.  
  532.         if count $arr_additional_params {
  533.             $str_glue $str_xhtml == true '&amp;' '&';
  534.             $str_additional_params '?' implode $str_glue$arr_additional_params );
  535.         }
  536.  
  537.         $idlang   ($changelang 0$changelang $lang;
  538.         $idclient ($changeclient 0$changeclient $client;
  539.  
  540.         // set client?
  541.         if $cfg['mod_rewrite']['use_client'== {
  542.             if $cfg['mod_rewrite']['use_client_name'== {
  543.                 $arr_parts[urlencode(ModRewrite::get_client_name($idclient));
  544.             else {
  545.                 $arr_parts[$idclient;
  546.             }
  547.         }
  548.  
  549.         // set language?
  550.         if $cfg['mod_rewrite']['use_language'== {
  551.             if $cfg['mod_rewrite']['use_language_name'== {
  552.                 $arr_parts[urlencode(ModRewrite::get_language_name($idlang));
  553.             else {
  554.                 $arr_parts[$idlang;
  555.             }
  556.         }
  557.  
  558.         // define rootpath ...
  559.         $str_new_url $cfg['mod_rewrite']['rootdir'];
  560.  
  561.         // handle idcatart
  562.         if ($idcatart && $idcat == && $idart == && $idartlang == 0{
  563.             $sql "SELECT idcat, idart FROM " $cfg["tab"]["cat_art"" WHERE idcatart = '$idcatart'";
  564.             if ($aData mr_query_n_next_record($sql)) {
  565.                 $idcat $aData['idcat'];
  566.                 $idart $aData['idart'];
  567.             }
  568.         }
  569.  
  570.         // check if article id is given and set article url
  571.         if ($idart && $idartlang == 0{
  572.             $str_article ModRewrite::get_art_websafename $idart$idlang );
  573.         elseif ($idartlang && $idart == 0{
  574.             // handle idartlang
  575.             $str_article ModRewrite::get_art_lang_websafename $idartlang );
  576.         }
  577.  
  578.         // check if only article id is given, cat id have to rebuild
  579.         if ($idart && $idcat == && $idartlang == 0{
  580.             $sql "SELECT idcat FROM " $cfg["tab"]["cat_art"" WHERE idart = '$idart'";
  581.             if ($aData mr_query_n_next_record($sql)) {
  582.                 $idcat $aData['idcat'];
  583.             }
  584.         }
  585.  
  586.         // idartlang is given
  587.         if ($idartlang && $idcat == && $idart == 0{
  588.             $sql "SELECT ca.idcat
  589.                     FROM " $cfg["tab"]["art_lang"" al
  590.                     LEFT JOIN " $cfg["tab"]["cat_art"" ca ON al.idart = ca.idart
  591.             WHERE al.idartlang = '$idartlang'";
  592.             if ($aData mr_query_n_next_record($sql)) {
  593.                 $idcat $aData['idcat'];
  594.             }
  595.         }
  596.  
  597.         // we have category but no article name and start article name should be added to url
  598.         if ($idcat && $str_article == '' && $cfg['mod_rewrite']['add_startart_name_to_url']{
  599.             if ($cfg['mod_rewrite']['default_startart_name'== ''{
  600.  
  601.                 // no default article name is configured get startarticle
  602.                 cInclude('classes''class.article.php');
  603.                 $artColl new ArticleCollection(array('idcat' => $idcat'start' => 1));
  604.                 if ($artItem $artColl->startArticle()) {
  605.                     $idart       $artItem->get('idart');
  606.                     $str_article ModRewrite::get_art_websafename($idart$idlang);
  607.                 }
  608.  
  609.             else {
  610.  
  611.                 // use default start article name
  612.                 $str_article $cfg['mod_rewrite']['default_startart_name'];
  613.             }
  614.         }
  615.  
  616.         if ($str_article{
  617.             $str_file_extension $cfg['mod_rewrite']['file_extension'];
  618.         }
  619.  
  620.         // ok build dir list, if idcat found ...
  621.         if ($idcat 0{
  622.  
  623.             $str_categories ModRewrite::build_recursiv_path $idcat$idlang );
  624.  
  625.             // check start directory settings
  626.             if $cfg['mod_rewrite']['startfromroot'== {
  627.                 // splitt string in array
  628.                 $arr_categories split$str_join_parameter$str_categories);
  629.  
  630.                 // remove first category
  631.                 $str_first_cat array_shift $arr_categories );
  632.  
  633.                 // implode array with categories to new string
  634.                 $str_categories join $str_join_parameter,  $arr_categories );
  635.             }
  636.  
  637.             if (strlen($str_categories)0{
  638.                 $arr_parts[$str_categories;
  639.             }
  640.         }
  641.         $str_parts implode$str_join_parameter$arr_parts);
  642.  
  643.         // only html files part
  644.         if (strlen($str_parts&& strlen($str_article0
  645.             $str_parts.= $cfg['mod_rewrite']['article_seperator'];
  646.         else if ((int)$cfg['mod_rewrite']['use_categories_as_html_file'!= && strlen($str_parts0{
  647.             $str_parts.= $str_join_parameter;
  648.         }
  649.  
  650.         // using lowercase uri?
  651.         if $cfg['mod_rewrite']['use_lowercase_uri'== {
  652.             $str_full_url $str_new_url strtolower$str_parts $str_article $str_file_extension $str_additional_params $str_anchor;
  653.         else {
  654.             $str_full_url $str_new_url $str_parts $str_article $str_file_extension $str_additional_params $str_anchor;
  655.         }
  656.  
  657.         // remove double slashes
  658.         while eregi($str_join_parameter.$str_join_parameter$str_full_url) ) {
  659.             $str_full_url eregi_replace $str_join_parameter.$str_join_parameter$str_join_parameter$str_full_url );
  660.         }
  661.  
  662.         if (substr ($str_full_url-2== "?="{
  663.             $str_full_url substr_replace($str_full_url""-2);
  664.         }
  665.  
  666.         return $str_full_url;
  667.  
  668.     // end function
  669.  
  670.  
  671.     /**
  672.      * get_art_websafename()
  673.      *
  674.      * get article websafe name from article id and language id
  675.      *
  676.      * @param    integer    article id
  677.      * @param    integer    language id
  678.      * @return     string    article websafe name
  679.      */
  680.     function get_art_websafename $int_id 0$int_lang_id {
  681.         global $cfg;
  682.         $sql "SELECT urlname FROM " $cfg["tab"]["art_lang"" WHERE idart = '$int_id' AND idlang = '$int_lang_id'";
  683.         if ($aData mr_query_n_next_record($sql)) {
  684.             return urldecode($aData['urlname']);
  685.         }
  686.         return null;
  687.     }    // end function
  688.  
  689.  
  690.     /**
  691.      * get_art_lang_websafename()
  692.      *
  693.      * get article websafe name from idartlang
  694.      *
  695.      * @param    integer    idartlang
  696.      * @return     string    article websafe name
  697.      */
  698.     function get_art_lang_websafename $int_id {
  699.         global $cfg;
  700.         $sql "SELECT urlname FROM " $cfg["tab"]["art_lang"" WHERE idartlang = '$int_id'";
  701.         if ($aData mr_query_n_next_record($sql)) {
  702.             return urldecode($aData['urlname']);
  703.         }
  704.         return null;
  705.     }    // end function
  706.  
  707.  
  708.     /**
  709.      * get_client_name()
  710.      *
  711.      * get name of client id
  712.      *
  713.      * @param    integer    language id
  714.      * @return     string    language name
  715.      */
  716.     function get_client_name $int_id {
  717.         global $cfg;
  718.         $sql "SELECT name FROM " $cfg["tab"]["clients"" WHERE idclient = '$int_id'";
  719.         if ($aData mr_query_n_next_record($sql)) {
  720.             return $aData['name'];
  721.         }
  722.         return null;
  723.     }    // end function
  724.  
  725.  
  726.     /**
  727.      * get_language_name()
  728.      *
  729.      * get name of language id
  730.      *
  731.      * @param    integer    language id
  732.      * @return     string    language name
  733.      */
  734.     function get_language_name_old $int_id {
  735.         global $cfg;
  736.         $sql "SELECT name FROM " $cfg["tab"]["lang"" WHERE idlang = '$int_id'";
  737.         if ($aData mr_query_n_next_record($sql)) {
  738.             return $aData['name'];
  739.         }
  740.         return null;
  741.     }    // end function
  742.  
  743.  
  744.     /**
  745.      * Returns name of language
  746.      *
  747.      * @param   int   $int_id  Language id
  748.      * @return  array  Assoziative array containing lanuage names ($a[id] = 'name')
  749.      */
  750.     function get_language_name $int_id {
  751.         global $cfg;
  752.         static $aName;
  753.         if (!isset($aName)) {
  754.             $aName array();
  755.         }
  756.  
  757.         if (isset($aName[$int_id])) {
  758.             return $aName[$int_id];
  759.         }
  760.  
  761.  
  762.         $sql "SELECT name FROM " $cfg["tab"]["lang"" WHERE idlang = '$int_id'";
  763.         if ($aData mr_query_n_next_record($sql)) {
  764.             $aName[$int_id$aData['name'];
  765.         else {
  766.             $aName[$int_id'';
  767.         }
  768.  
  769.         return $aName[$int_id];
  770.     }    // end function
  771.  
  772.  
  773.     /**
  774.      * get_client_full_url_parts()
  775.      * Splits passed argument into scheme://host and path/query.
  776.      *
  777.      * Example:
  778.      * input  = http://host/front_content.php?idcat=123
  779.      * return = array('htmlpath' => 'http://host', 'url' => 'front_content.php?idcat=123')
  780.      *
  781.      * @param  string  $url  URL to split
  782.      * @return array  Assoziative array including the two parts:
  783.      *                 - array('htmlpath' => $path, 'url' => $url)
  784.      */
  785.     function get_client_full_url_parts($url{
  786.         global $cfg$cfgClient$client;
  787.         $clientPath $cfgClient[$client]['path']['htmlpath'];
  788.  
  789.         if (stristr($url$clientPath!== false{
  790.  
  791.             // url includes full html path (scheme host path, etc.)
  792.             $url      str_replace($clientPath''$url);
  793.             $htmlPath $clientPath;
  794.             $aComp    parse_url($htmlPath);
  795.  
  796.             // check if path matches to defined rootdir from mod_rewrite conf
  797.             if (isset($aComp['path']&& $aComp['path'!== $cfg['mod_rewrite']['rootdir']{
  798.                 // replace not matching path agaings configured one
  799.                 // this will replace e. g. "http://host/cms/" against "http://host/"
  800.                 $htmlPath str_replace($aComp['path']$cfg['mod_rewrite']['rootdir']$htmlPath);
  801.                 if (substr($htmlPathstrlen($htmlPath)-1== '/'{
  802.                     // remove last slash
  803.                     $htmlPath substr($htmlPath0strlen($htmlPath)-1);
  804.                 }
  805.             }
  806.         else {
  807.             $htmlPath '';
  808.         }
  809.         return array('htmlpath' => $htmlPath'url' => $url);
  810.     }
  811.  
  812.  
  813.     /**
  814.      * reset_categories_aliases()
  815.      *
  816.      * method to reset all aliases in categories
  817.      */
  818.     function reset_categories_aliases({
  819.         global $cfg;
  820.  
  821.         $db new DB_Contenido();
  822.  
  823.         // empty all aliases
  824.         $sql "UPDATE " $cfg["tab"]["cat_lang"" SET urlname = ''";
  825.         $db->query($sql);
  826.  
  827.         // get all categories
  828.         $sql "SELECT name, idcat, idlang FROM " $cfg["tab"]["cat_lang"];
  829.         $db->query($sql);
  830.  
  831.         while $db->next_record() ) {
  832.             //set new alias
  833.             ModRewrite::set_category($db->f('name')$db->f('idcat')$db->f('idlang'));
  834.         }
  835.         unset ($db);
  836.     }
  837.  
  838.  
  839.     /**
  840.      * reset_articles_aliases()
  841.      *
  842.      * method to reset all aliases in articles
  843.      */
  844.     function reset_articles_aliases ({
  845.         global $cfg;
  846.  
  847.         $db new DB_Contenido();
  848.  
  849.         // empty all aliases
  850.         $sql "UPDATE " $cfg["tab"]["art_lang"" SET urlname = ''";
  851.         $db->query($sql);
  852.  
  853.         // get all articles
  854.         $sql "SELECT title, idart, idlang FROM " $cfg["tab"]["art_lang"];
  855.         $db->query($sql);
  856.  
  857.         while $db->next_record() ) {
  858.             //set new alias
  859.             ModRewrite::set_article($db->f('title')$db->f('idart')$db->f('idlang'));
  860.         }
  861.  
  862.         unset ($db);
  863.     }
  864.  
  865.     /**
  866.      * reset_aliases()
  867.      *
  868.      * method to reset all aliases (category and article)
  869.      */
  870.     function reset_aliases ({
  871.     }
  872.  
  873.  
  874.     /**
  875.      * Used to postprocess resolved path
  876.      *
  877.      * Error site handling if category not found
  878.      *
  879.      * if percentage == 100 and there is no 100 percentage result value,
  880.      * error site will be shown - can be adjust by user settings for
  881.      * smooth similar effects - 80 to 95 will be best but have to check by user
  882.      *
  883.      * @param   array  $results  Pathresolver results array
  884.      * @return  mixed  Categoryid or false
  885.      */
  886.     function get_id_from_pathresolver_result($results{
  887.         global $cfg;
  888.  
  889.         $intMinPercentage $cfg["mod_rewrite"]['category_resolve_min_percentage'];
  890.         $catId key($results);
  891.  
  892.         if (isset($intMinPercentage&& (int)$intMinPercentage && $results[$catId$intMinPercentage{
  893.             return false;
  894.         else {
  895.             return $catId;
  896.         }
  897.     }
  898.  
  899.  
  900.     /**
  901.      * Analyses the settings for usage of categories as a html file and returns
  902.      * the result as a boolean
  903.      *
  904.      * @return  bool  True if settings are active and valid otherwhise false.
  905.      */
  906.         global $cfg;
  907.  
  908.         if ((int) $cfg["mod_rewrite"]['use_categories_as_html_file'== 1
  909.             && strlen($cfg["mod_rewrite"]['article_seperator']0
  910.             && strlen($cfg["mod_rewrite"]['category_seperator']0
  911.             && $cfg["mod_rewrite"]['category_seperator'!= $cfg["mod_rewrite"]['article_seperator']{
  912.             // settings are ok, return true
  913.             return true;
  914.         else {
  915.             // settings are are deactivated or faulty
  916.             return false;
  917.         }
  918.     }
  919.  
  920. // end class

Documentation generated on Sun, 03 Aug 2008 22:21:45 +0200 by phpDocumentor 1.4.0