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

Documentation generated on Thu, 19 Jun 2008 22:43:47 +0200 by phpDocumentor 1.4.0