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

Documentation generated on Mon, 19 May 2008 22:46:53 +0200 by phpDocumentor 1.4.0