Source for file class.modrewrite.php

Documentation is available at class.modrewrite.php

  1. <?php
  2. /**
  3.  * Includes 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. defined('CON_FRAMEWORK'or die('Illegal call');
  28.  
  29.  
  30. /**
  31.  * Class to create websafe names
  32.  *
  33.  * @author      Stefan Seifarth / stese
  34.  * @author      Murat Purc <murat@purc.de>
  35.  * @package     Contenido
  36.  * @subpackage  ModRewrite
  37.  */
  38. class ModRewrite extends ModRewriteBase {
  39.  
  40.  
  41.     /**
  42.      * Initialization, is to call at least once, also possible to call multible
  43.      * times, if different client configuration is to load.
  44.      *
  45.      * Loads configuration of passed client and sets some properties.
  46.      *
  47.      * @param  int  $clientId  Client id
  48.      */
  49.     public static function initialize($clientId{
  50.         mr_loadConfiguration($clientIdtrue);
  51.         parent::initialize();
  52.     }
  53.  
  54.  
  55.     /**
  56.      * Check categories on websafe name
  57.      *
  58.      * Check all categories in the main parent category on existing same websafe name
  59.      *
  60.      * @param   string  $sName    Websafe name to check
  61.      * @param   int     $iCatId   Current category id
  62.      * @param   int     $iLangId  Current language id
  63.      * @return     bool    True if websafename already exists, false if not
  64.      */
  65.     public static function isInCategories($sName=''$iCatId=0$iLangId=0{
  66.         $iCatId  = (int) $iCatId;
  67.         $iLangId = (int) $iLangId;
  68.  
  69.         $aTab parent::$_oGlobals->get('cfg/tab');
  70.  
  71.         // get parentid
  72.         $iParentId 0;
  73.         $sql "SELECT parentid FROM " $aTab['cat'" WHERE idcat = '$iCatId'";
  74.         if ($aData mr_queryAndNextRecord($sql)) {
  75.             $iParentId ($aData['parentid'? (int) $aData['parentid'0;
  76.         }
  77.  
  78.         // check if websafe name is in this category
  79.         $sql "SELECT count(cl.idcat) as numcats FROM " $aTab['cat_lang'" cl "
  80.              . "LEFT JOIN " $aTab['cat'" c ON cl.idcat = c.idcat WHERE "
  81.              . "c.parentid = '$iParentId' AND cl.idlang = '$iLangId "' AND "
  82.              . "cl.urlname = '" $sName "' AND cl.idcat <> '$iCatId'";
  83.         self::$_oDebug->log($sql'ModRewrite::isInCategories $sql');
  84.  
  85.         if ($aData mr_queryAndNextRecord($sql)) {
  86.             return ($aData['numcats'0true false;
  87.         }
  88.  
  89.         return false;
  90.     }
  91.  
  92.  
  93.     /**
  94.      * Check articles on websafe name.
  95.      *
  96.      * Check all articles in the current category on existing same websafe name.
  97.      *
  98.      * @param    string  $sName    Websafe name to check
  99.      * @param    int     $iArtId   Current article id
  100.      * @param    int     $iLangId  Current language id
  101.      * @param   int     $iCatId   Category id
  102.      * @return     bool    True if websafename already exists, false if not
  103.      */
  104.     public static function isInCatArticles($sName=''$iArtId=0$iLangId=0$iCatId=0{
  105.         $iArtId  = (int) $iArtId;
  106.         $iLangId = (int) $iLangId;
  107.         $iCatId  = (int) $iCatId;
  108.  
  109.         $aTab parent::$_oGlobals->get('cfg/tab');
  110.  
  111.         // handle multipages
  112.         if ($iCatId == 0{
  113.             // get category id if not set
  114.             $sql "SELECT idcat FROM " $aTab['cat_art'" WHERE idart = '$iArtId'";
  115.             if ($aData mr_queryAndNextRecord($sql)) {
  116.                 $iCatId ($aData['idcat'0? (int) $aData['idcat'0;
  117.             }
  118.         }
  119.  
  120.         // check if websafe name is in this category
  121.         $sql "SELECT count(al.idart) as numcats FROM " $aTab['art_lang'" al "
  122.              . "LEFT JOIN " $aTab['cat_art'" ca ON al.idart = ca.idart WHERE "
  123.              . " ca.idcat='$iCatId' AND al.idlang='$iLangId "' AND "
  124.              . "al.urlname='" $sName "' AND al.idart <> '$iArtId'";
  125.         if ($aData mr_queryAndNextRecord($sql)) {
  126.             return ($aData['numcats'0true false;
  127.         }
  128.  
  129.         return false;
  130.     }
  131.  
  132.  
  133.     /**
  134.      * Set websafe name in article list.
  135.      *
  136.      * Insert new websafe name in article list
  137.      *
  138.      * @param   string  $sName    Original name (will be converted)
  139.      * @param   int     $iArtId   Current article id
  140.      * @param   int     $iLangId  Current language id
  141.      * @param   int     $iCatId   Category id
  142.      * @return     bool    True if insert was successfully
  143.      */
  144.     public static function setArtWebsafeName($sName=''$iArtId=0$iLangId=0$iCatId=0{
  145.         $iArtId  = (int) $iArtId;
  146.         $iLangId = (int) $iLangId;
  147.         $iCatId  = (int) $iCatId;
  148.  
  149.         // get websafe name
  150.         $sNewName capiStrCleanURLCharacters(html_entity_decode($sName));
  151.  
  152.         // remove double or more separators
  153.         $sNewName mr_removeMultipleChars('-'$sNewName);
  154.  
  155.         // check if websafe name already exists
  156.         if (self::isInCatArticles($sNewName$iArtId$iLangId$iCatId)) {
  157.             // create new websafe name if exists
  158.             $sNewName $sNewName $iArtId;
  159.         }
  160.  
  161.         // check again - and set name
  162.         if (!self::isInCatArticles($sNewName$iArtId$iLangId$iCatId)) {
  163.             // insert websafe name in article list
  164.             $db  new DB_Contenido;
  165.             $tab parent::$_oGlobals->get('cfg/tab/art_lang');
  166.             $sql "UPDATE " $tab " SET urlname = '$sNewName' WHERE idart = '$iArtId' AND idlang = '$iLangId'";
  167.             return $db->query($sql);
  168.         else {
  169.             return false;
  170.         }
  171.     }
  172.  
  173.  
  174.     /**
  175.      * Set websafe name in category list.
  176.      *
  177.      * Insert new websafe name in category list.
  178.      *
  179.      * @param   string  $sName    Original name (will be converted) or alias
  180.      * @param   int     $iCatId   Category id
  181.      * @param   int     $iLangId  Language id
  182.      * @return  bool    True if insert was successfully
  183.      */
  184.     public static function setCatWebsafeName($sName=''$iCatId=0$iLangId=0{
  185.         $iCatId  = (int) $iCatId;
  186.         $iLangId = (int) $iLangId;
  187.  
  188.         // create websafe name
  189.         $sNewName capiStrCleanURLCharacters(html_entity_decode($sName));
  190.  
  191.         // remove double or more separators
  192.         $sNewName mr_removeMultipleChars('-'$sNewName);
  193.  
  194.         // check if websafe name already exists
  195.         if (self::isInCategories($sNewName$iCatId$iLangId)) {
  196.             // create new websafe name if exists
  197.             $sNewName $sNewName $iCatId;
  198.         }
  199.  
  200.         // check again - and set name
  201.         if (!self::isInCategories($sNewName$iCatId$iLangId)) {
  202.             // insert websafe name in article list
  203.             $db  new DB_Contenido;
  204.             $tag parent::$_oGlobals->get('cfg/tab/cat_lang');
  205.             $sql "UPDATE " $tag " SET urlname = '$sNewName' WHERE idcat = '$iCatId' AND idlang = '$iLangId'";
  206.  
  207.             self::$_oDebug->log(array(
  208.                 'sName'    => $sName,
  209.                 'iCatId'   => $iCatId,
  210.                 'iLangId'  => $iLangId,
  211.                 'sNewName' => $sNewName
  212.                 )'ModRewrite::setCatWebsafeName $data'
  213.             );
  214.  
  215.             return $db->query($sql);
  216.  
  217.         else {
  218.             return false;
  219.         }
  220.     }
  221.  
  222.  
  223.     /**
  224.      * Set urlpath of category
  225.      *
  226.      * @param   int     $iCatId   Category id
  227.      * @param   int     $iLangId  Language id
  228.      * @return  bool    True if insert was successfully
  229.      */
  230.     public static function setCatUrlPath($iCatId=0$iLangId=0{
  231.         $sPath ModRewrite::buildRecursivPath($iCatId$iLangId);
  232.  
  233.         // insert websafe name in article list
  234.         $db  new DB_Contenido;
  235.         $tab parent::$_oGlobals->get('cfg/tab/cat_lang');
  236.         $sql "UPDATE " $tab " SET urlpath = '$sPath' WHERE idcat = '$iCatId' AND idlang = '$iLangId'";
  237.  
  238.         self::$_oDebug->log(array(
  239.             'iCatId'   => $iCatId,
  240.             'iLangId'  => $iLangId,
  241.             'sPath'    => $sPath
  242.             )'ModRewrite::setCatUrlPath $data'
  243.         );
  244.  
  245.         return $db->query($sql);
  246.     }
  247.  
  248.  
  249.     /**
  250.      * Get article id and language id from article language id
  251.      *
  252.      * @param   int    $iArtlangId  Current article id
  253.      * @return  array  Array with idart and idlang of current article
  254.      */
  255.     public static function getArtIdByArtlangId($iArtlangId=0{
  256.         $iArtlangId = (int) $iArtlangId;
  257.         $tab parent::$_oGlobals->get('cfg/tab/art_lang');
  258.         $sql "SELECT idart, idlang FROM " $tab " WHERE idartlang = '$iArtlangId'";
  259.         if ($aData mr_queryAndNextRecord($sql)) {
  260.             return $aData;
  261.         }
  262.         return array();
  263.     }
  264.  
  265.  
  266.     /**
  267.      * Get article id by article websafe name
  268.      *
  269.      * @param   string  Websafe name
  270.      * @param   int     Category id
  271.      * @return  int     Recent article id
  272.      */
  273.     function getArtIdByWebsafeName($sArtName=''$iCatId=0$iLangId=0{
  274.         static $db;
  275.  
  276.         if (!isset($db)) {
  277.             $db new DB_Contenido;
  278.         }
  279.  
  280.         $aTab parent::$_oGlobals->get('cfg/tab');
  281.  
  282.         $iArtId false;
  283.  
  284.         $sWhere '';
  285.         if ((int) $iLangId !== 0{
  286.             $sWhere ' AND al.idlang=' $iLangId;
  287.         }
  288.         // only article name were given
  289.         if ($iCatId == 0{
  290.             // get all basic category ids with parentid=0
  291.             $aCatIds array();
  292.             $sql "SELECT idcat FROM " $aTab['cat'" WHERE parentid = '0'";
  293.             $db->query($sql);
  294.             while ($db->next_record()) {
  295.                 $aCatIds["idcat = '" $db->f('idcat'"'";
  296.             }
  297.             $sWhere .= " AND ( " join(" OR "$aCatIds")";
  298.         else {
  299.             $sWhere .= " AND ca.idcat = '$iCatId'";
  300.         }
  301.  
  302.         $sql "SELECT al.idart FROM " $aTab['art_lang'" al "
  303.              . "LEFT JOIN " $aTab['cat_art'" ca ON al.idart = ca.idart "
  304.              . "WHERE al.urlname = '$sArtName'$sWhere;
  305.  
  306.         if ($aData mr_queryAndNextRecord($sql)) {
  307.             $iArtId $aData['idart'];
  308.         }
  309.  
  310.         return $iArtId;
  311.     }
  312.  
  313.  
  314.     /**
  315.      * Get category name from category id and language id.
  316.      *
  317.      * @param   int     $iCatId   Category id
  318.      * @param   int     $iLangId  Language id
  319.      * @return  string  Category name
  320.      */
  321.     public static function getCatName($iCatId=0$iLangId=0{
  322.         $iCatId  = (int) $iCatId;
  323.         $iLangId = (int) $iLangId;
  324.         $key     $iCatId '-' $iLangId;
  325.  
  326.         $key 'mr_statics/catname_by_catid_idlang/' $iCatId '_' $iLangId;
  327.         $catName parent::$_oGlobals->get($key);
  328.         if ($catName !== null{
  329.             return $catName;
  330.         }
  331.  
  332.         $tab parent::$_oGlobals->get('cfg/tab/cat_lang');
  333.         $sql "SELECT name FROM " $tab " WHERE idcat = '$iCatId' AND idlang = '$iLangId'";
  334.         if ($aData mr_queryAndNextRecord($sql)) {
  335.             $catName $aData['name'];
  336.         else {
  337.             $catName '';
  338.         }
  339.  
  340.         parent::$_oGlobals->set($key$catName);
  341.         return $catName;
  342.     }
  343.  
  344.  
  345.     /**
  346.      * Funcion to return cat id by path.
  347.      *
  348.      * Caches the paths at first call to provode faster processing at further calls.
  349.      *
  350.      * @param   string  $path  Category path
  351.      * @return  int  Category id
  352.      */
  353.     public static function getCatIdByUrlPath($path{
  354.         if (strpos($path'/'=== 0{
  355.             $path substr($path1);
  356.         }
  357.         if (strrpos($path'/'=== strlen($path)-1{
  358.             $path substr($path0-1);
  359.         }
  360.  
  361.         $catSeperator '/';
  362.         $startFromRoot parent::getConfig('startfromroot');
  363.         $urls2lowercase parent::getConfig('use_lowercase_uri');
  364.  
  365.         $path str_replace('/'parent::getConfig('category_seperator')$path);
  366.  
  367.         $key 'mr_statics/cat_ids_and_urlpath';
  368.         $aPathsCache parent::$_oGlobals->get($keyarray());
  369.  
  370.         if (count($aPathsCache== 0{
  371.             $aTab   parent::$_oGlobals->get('cfg/tab');
  372.             $client parent::$_oGlobals->get('client');
  373.             $lang   parent::$_oGlobals->get('lang');
  374.             $db     new DB_Contenido();
  375.  
  376.             $sql "SELECT cl.idcat, cl.urlpath FROM " $aTab['cat_lang'" AS cl, " $aTab['cat'" AS c WHERE "
  377.                  . "c.idclient = " $client " AND c.idcat = cl.idcat AND cl.idlang = " $lang;
  378.             $db->query($sql);
  379.             while ($db->next_record()) {
  380.                 $urlPath $db->f('urlpath');
  381.                 if ($startFromRoot == && strpos($urlPath$catSeperator0{
  382.                     // paths are stored with prefixed main category, but created
  383.                     // urls doesn't contain the main cat, remove it...
  384.                     $urlPath substr($urlPathstrpos($urlPath$catSeperator)+1);
  385.                 }
  386.                 if ($urls2lowercase{
  387.                     $urlPath strtolower($urlPath);
  388.                 }
  389.  
  390.                 // store path
  391.                 $aPathsCache[$db->f('idcat')$urlPath;
  392.             }
  393.         }
  394.         parent::$_oGlobals->set($key$aPathsCache);
  395.  
  396.         // compare paths using the similar_text algorithm
  397.         $fPercent 0;
  398.         $aResults array();
  399.         foreach ($aPathsCache as $id => $pathItem{
  400.             similar_text($path$pathItem$fPercent);
  401.             $aResults[$id$fPercent;
  402.         }
  403.  
  404.         arsort($aResultsSORT_NUMERIC);
  405.         reset($aResults);
  406.  
  407.         parent::$_oDebug->addDebug($path'ModRewrite::getCatIdByUrlPath() $path');
  408.         parent::$_oDebug->addDebug($aPathsCache'ModRewrite::getCatIdByUrlPath() $aPathsCache');
  409.         parent::$_oDebug->addDebug($aResults'ModRewrite::getCatIdByUrlPath() $aResults');
  410.  
  411.         $iMinPercentage = (int) parent::getConfig('category_resolve_min_percentage'0);
  412.         $catId key($aResults);
  413.         if ($iMinPercentage && $aResults[$catId$iMinPercentage{
  414.             return 0;
  415.         else {
  416.             return $catId;
  417.         }
  418.     }
  419.  
  420.  
  421.     /**
  422.      * Get article name from article id and language id
  423.      *
  424.      * @NOTE: seems to be not used???
  425.      *
  426.      * @param   int     $iArtId   Article id
  427.      * @param   int     $iLangId  Language id
  428.      * @return  string  Article name
  429.      */
  430.     public static function getArtTitle($iArtId=0$iLangId=0{
  431.         $iArtId  = (int) $iArtId;
  432.         $iLangId = (int) $iLangId;
  433.  
  434.         $tab parent::$_oGlobals->get('cfg/tab/art_lang');
  435.  
  436.         $sql "SELECT title FROM " $tab " WHERE idart = '$iArtId' AND idlang = '$iLangId'";
  437.         if ($aData mr_queryAndNextRecord($sql)) {
  438.             return $aData['title'];
  439.         }
  440.         return '';
  441.     }
  442.  
  443.  
  444.     /**
  445.      * Get language ids from category id
  446.      *
  447.      * @param   int    $iCatId  Category id
  448.      * @return  array  Used language ids
  449.      */
  450.     public static function getCatLanguages($iCatId=0{
  451.         $iCatId = (int) $iCatId;
  452.  
  453.         $key 'mr_statics/cat_idlang_by_catid/' $iCatId;
  454.         $aLanguages parent::$_oGlobals->get($key);
  455.         if ($aLanguages !== null{
  456.             return $aLanguages;
  457.         }
  458.  
  459.         $aLanguages array();
  460.  
  461.         $db  new DB_Contenido();
  462.         $tab parent::$_oGlobals->get('cfg/tab/cat_lang');
  463.         $sql "SELECT idlang FROM " $tab " WHERE idcat = '$iCatId'";
  464.         $db->query($sql);
  465.         while ($db->next_record()) {
  466.             $aLanguages[$db->f('idlang');
  467.         }
  468.  
  469.         parent::$_oGlobals->set($key$aLanguages);
  470.         return $aLanguages;
  471.     }
  472.  
  473.  
  474.     /**
  475.      * Get article urlname and language id
  476.      *
  477.      * @param   int    $iArtlangId  idartlang
  478.      * @return  array  Urlname, idlang of empty array
  479.      */
  480.     public static function getArtIds($iArtlangId=0{
  481.         $iArtlangId = (int) $iArtlangId;
  482.         $tab parent::$_oGlobals->get('cfg/tab/art_lang');
  483.         $sql "SELECT urlname, idlang FROM " $tab " WHERE idartlang = '$iArtlangId'";
  484.         if ($aData mr_queryAndNextRecord($sql)) {
  485.             return $aData;
  486.         }
  487.         return array();
  488.     }
  489.  
  490.  
  491.     /**
  492.      * Build a recursiv path for mod_rewrite rule like server directories
  493.      * (dir1/dir2/dir3)
  494.      *
  495.      * @param   int     $iCatId   Latest category id
  496.      * @param   int     $iLangId  Language id
  497.      * @param   int     $iLastId  Last category id
  498.      * @return     string    linkpath with correct uri
  499.      */
  500.     public static function buildRecursivPath($iCatId=0$iLangId=0$iLastId=0{
  501.         $aDirectories   array();
  502.         $bFinish        false;
  503.         $iTmpCatId      $iCatId;
  504.  
  505.         $aTabs parent::$_oGlobals->get('cfg/tab');
  506.  
  507.         while ($bFinish == false{
  508.             $sql "SELECT cl.urlname, c.parentid FROM " $aTabs['cat_lang'" cl "
  509.                  . "LEFT JOIN " $aTabs['cat'" c ON cl.idcat = c.idcat "
  510.                  . "WHERE cl.idcat = '$iTmpCatId' AND cl.idlang = '$iLangId'";
  511.             if ($aData mr_queryAndNextRecord($sql)) {
  512.                 $aDirectories[$aData['urlname'];
  513.                 $iTmpCatId      $aData['parentid'];
  514.  
  515.                 if ($aData['parentid'== || $aData['parentid'== $iLastId{
  516.                     $bFinish true;
  517.                 }
  518.             else {
  519.                 $bFinish true;
  520.             }
  521.         }
  522.  
  523.         // reverse array entries and create directory string
  524.         $sPath join('/'array_reverse($aDirectories));
  525.  
  526.         return $sPath;
  527.     }
  528.  
  529.  
  530.     /**
  531.      * Return full contenido url from single anchor
  532.      *
  533.      * @param   array   $aMatches [0] = complete anchor, [1] = pre arguments, [2] = anchor name, [3] = post arguments
  534.      * @return  string  New anchor
  535.      */
  536.     public static function rewriteHtmlAnchor(array $aMatches=array()) {
  537.         $artname parent::$_oGlobals->get('artname');
  538.         $sess    parent::$_oGlobals->get('sess');
  539.  
  540.         // set article name
  541.         $sArtParam '';
  542.         if (isset($artname&& strlen($artname0{
  543.             $sArtParam '&idart=' parent::$_oGlobals->get('idart');
  544.         }
  545.  
  546.         // check for additional parameter in url
  547.         $aParamsToIgnore array ('idcat''idart''lang''client''idcatart''changelang''changeclient''idartlang''parts''artname');
  548.         $sOtherParams '';
  549.  
  550.         if (isset($_GET&& count($_GET0{
  551.             foreach ($_GET as $key => $value{
  552.                 if (!in_array($key$aParamsToIgnore&& strlen(trim($value)) 0{
  553.                     $aNoAnchor     explode('#'$value);
  554.                     $sOtherParams .= '&' urlencode(urldecode($key)) '=' urlencode(urldecode($value));
  555.                 }
  556.             }
  557.         }
  558.  
  559.         $idcat  parent::$_oGlobals->get('idcat');
  560.         $client parent::$_oGlobals->get('client');
  561.         $lang   parent::$_oGlobals->get('lang');
  562.  
  563.         $url $sess->url(
  564.             'front_content.php?' 'idcat=' $idcat '&client=' $client .
  565.             '&changelang=' $lang $sArtParam $sOtherParams '#' $aMatches[2]
  566.         );
  567.  
  568.         $sNewUrl '<a' $aMatches[1'href="' $url '"' $aMatches[3'>';
  569.  
  570.         return $sNewUrl;
  571.     }
  572.  
  573.  
  574.     /**
  575.      * Return full contenido url from single anchor
  576.      *
  577.      * @param   array   $aMatches [0] = complete anchor, [1] = pre arguments, [2] = anchor name, [3] = post arguments
  578.      * @return  string  New anchor
  579.      */
  580.     public static function contenidoHtmlAnchor(array $aMatches=array()$bXHTML=true{
  581.         $artname parent::$_oGlobals->get('artname');
  582.         $sess    parent::$_oGlobals->get('sess');
  583.  
  584.         $aParams    array();
  585.         $sAmpersand $bXHTML '&amp;' '&';
  586.  
  587.         foreach ($_GET as $key => $value{
  588.             $aNoAnchor explode('#'$value);
  589.             $aParams[urlencode(urldecode($key)) '=' urlencode(urldecode($aNoAnchor[0]));
  590.         }
  591.  
  592.         $url =  $sess->url'front_content.php?' implode($sAmpersand$aParams'#' $aMatches[2]);
  593.         $sNewUrl '<a' $aMatches[1'href="' $url '"' $aMatches[3'>';
  594.  
  595.         return $sNewUrl;
  596.     }
  597.  
  598.  
  599.     /**
  600.      * Get article websafe name from article id and language id.
  601.      *
  602.      * @param    int     $iArtId   Article id
  603.      * @param    int     $iLangId  Language id
  604.      * @return     string    Article websafe name
  605.      */
  606.     public static function getArtWebsafeName($iArtId=0$iLangId=0{
  607.         $iArtId  = (int) $iArtId;
  608.         $iLangId = (int) $iLangId;
  609.         $tab parent::$_oGlobals->get('cfg/tab/art_lang');
  610.         $sql "SELECT urlname FROM " $tab " WHERE "
  611.              . "idart = '" $iArtId "' AND idlang = '" $iLangId "'";
  612.         if ($aData mr_queryAndNextRecord($sql)) {
  613.             return urldecode($aData['urlname']);
  614.         }
  615.         return null;
  616.     }
  617.  
  618.  
  619.     /**
  620.      * Get article websafe name from idartlang.
  621.      *
  622.      * @param    int     $iArtLangId  idartlang
  623.      * @return     string    Article websafe name
  624.      */
  625.     public static function getArtLangWebsafeName($iArtLangId=0{
  626.         $iArtLangId = (int) $iArtLangId;
  627.         $tab parent::$_oGlobals->get('cfg/tab/art_lang');
  628.         $sql "SELECT urlname FROM " $tab " WHERE idartlang = '"$iArtLangId "'";
  629.         if ($aData mr_queryAndNextRecord($sql)) {
  630.             return urldecode($aData['urlname']);
  631.         }
  632.         return null;
  633.     }
  634.  
  635.  
  636.     /**
  637.      * Get name of client by id.
  638.      *
  639.      * @param   int     $clientId  Client id
  640.      * @return  string  Client name
  641.      */
  642.     public static function getClientName($clientId=0{
  643.         $clientId = (int) $clientId;
  644.  
  645.         $key 'mr_statics/clientname_by_clientid/' $clientId;
  646.         $clientName parent::$_oGlobals->get($key);
  647.         if ($clientName !== null{
  648.             return $clientName;
  649.         }
  650.  
  651.         $tab parent::$_oGlobals->get('cfg/tab/clients');
  652.         $sql "SELECT name FROM " $tab " WHERE idclient = '$clientId'";
  653.         if ($aData mr_queryAndNextRecord($sql)) {
  654.             $clientName $aData['name'];
  655.         else {
  656.             $clientName '';
  657.         }
  658.         parent::$_oGlobals->set($key$clientName);
  659.         return $clientName;
  660.     }
  661.  
  662.  
  663.     /**
  664.      * Get client id from client name
  665.      *
  666.      * @param   string   Client name
  667.      * @return  integer  Client id
  668.      */
  669.     public static function getClientId($sClientName=''{
  670.         $key 'mr_statics/clientid_by_name/' $sClientName;
  671.         $clientId parent::$_oGlobals->get($key);
  672.         if ($clientId !== null{
  673.             return $clientId;
  674.         }
  675.  
  676.         $tab parent::$_oGlobals->get('cfg/tab/clients');
  677.         $sql "SELECT idclient FROM " $tab " WHERE name = '" urldecode($sClientName"'";
  678.         if ($aData mr_queryAndNextRecord($sql)) {
  679.             $clientId $aData['idclient'];
  680.         else {
  681.             $clientId false;
  682.         }
  683.         parent::$_oGlobals->set($key$clientId);
  684.         return $clientId;
  685.     }
  686.  
  687.  
  688.     /**
  689.      * Returns name of language by id.
  690.      *
  691.      * @param   int     $languageId  Language id
  692.      * @return  string  Lanuage name
  693.      */
  694.     public static function getLanguageName($languageId=0{
  695.         $languageId = (int) $languageId;
  696.  
  697.         $key 'mr_statics/languagename_by_id/' $languageId;
  698.         $languageName parent::$_oGlobals->get($key);
  699.         if ($languageName !== null{
  700.             return $languageName;
  701.         }
  702.  
  703.         $tab parent::$_oGlobals->get('cfg/tab/lang');
  704.         $sql "SELECT name FROM " $tab " WHERE idlang = '$languageId'";
  705.         if ($aData mr_queryAndNextRecord($sql)) {
  706.             $languageName $aData['name'];
  707.         else {
  708.             $languageName '';
  709.         }
  710.         parent::$_oGlobals->set($key$languageName);
  711.         return $languageName;
  712.     }
  713.  
  714.  
  715.     /**
  716.      * Get language id from language name thanks to Nicolas Dickinson for multi
  717.      * Client/Language BugFix
  718.      *
  719.      * @param  string   $sLanguageName  Language name
  720.      * @param  int      $iClientId      Client id
  721.      * @return integer  Language id
  722.      */
  723.     public static function getLanguageId($sLanguageName=''$iClientId=1{
  724.         $iClientId = (int) $iClientId;
  725.  
  726.         $key 'mr_statics/langid_by_langname_clientid/' $sLanguageName '_' $iClientId;
  727.         $languageId parent::$_oGlobals->get($key);
  728.         if ($languageId !== null{
  729.             return $languageId;
  730.         }
  731.  
  732.         $aTab parent::$_oGlobals->get('cfg/tab');
  733.         $sql  "SELECT l.idlang FROM " $aTab['lang'" as l "
  734.               . "LEFT JOIN " $aTab['clients_lang'" AS cl ON l.idlang = cl.idlang "
  735.               . "WHERE cl.idclient = '"$iClientId "' AND l.name = '" urldecode($sLanguageName"'";
  736.         if ($aData mr_queryAndNextRecord($sql)) {
  737.             $languageId $aData['idlang'];
  738.         else {
  739.             $languageId false;
  740.         }
  741.         parent::$_oGlobals->set($key$languageId);
  742.         return $languageId;
  743.     }
  744.  
  745.  
  746.     /**
  747.      * Splits passed argument into scheme://host and path/query.
  748.      *
  749.      * Example:
  750.      * input  = http://host/front_content.php?idcat=123
  751.      * return = array('htmlpath' => 'http://host', 'url' => 'front_content.php?idcat=123')
  752.      *
  753.      * @param  string  $url  URL to split
  754.      * @return array   Assoziative array including the two parts:
  755.      *                  - array('htmlpath' => $path, 'url' => $url)
  756.      */
  757.     public static function getClientFullUrlParts($url{
  758.         $path 'cfgClient/' parent::$_oGlobals->get('client''/path/htmlpath';
  759.         $clientPath parent::$_oGlobals->get($path);
  760.  
  761.         if (stristr($url$clientPath!== false{
  762.  
  763.             // url includes full html path (scheme host path, etc.)
  764.             $url      str_replace($clientPath''$url);
  765.             $htmlPath $clientPath;
  766.             $aComp    parse_url($htmlPath);
  767.  
  768.             // check if path matches to defined rootdir from mod_rewrite conf
  769.             if (isset($aComp['path']&& $aComp['path'!== parent::getConfig('rootdir')) {
  770.                 // replace not matching path agaings configured one
  771.                 // this will replace e. g. "http://host/cms/" against "http://host/"
  772.                 $htmlPath str_replace($aComp['path']parent::getConfig('rootdir')$htmlPath);
  773.                 if (substr($htmlPathstrlen($htmlPath)-1== '/'{
  774.                     // remove last slash
  775.                     $htmlPath substr($htmlPath0strlen($htmlPath)-1);
  776.                 }
  777.             }
  778.         else {
  779.             $htmlPath '';
  780.         }
  781.         return array('htmlpath' => $htmlPath'url' => $url);
  782.     }
  783.  
  784.  
  785.     /**
  786.      * Function to preclean a url.
  787.      *
  788.      * Removes absolute path declaration '/front_content.php' or relative path
  789.      * definition to actual dir './front_content.php', ampersand entities '&amp;'
  790.      * and returns a url like 'front_content.php?idart=12&idlang=1'
  791.      *
  792.      * @param   string  $url  Url to clean
  793.      * @return  string  Cleaned Url
  794.      */
  795.     public static function urlPreClean($url{
  796.         // some preparation of different front_content.php occurence
  797.         if (strpos($url'./front_content.php'=== 0{
  798.             $url str_replace('./front_content.php''front_content.php'$url);
  799.         elseif (strpos($url'/front_content.php'=== 0{
  800.             $url str_replace('/front_content.php''front_content.php'$url);
  801.         }
  802.         $url str_replace('&amp;''&'$url);
  803.         return $url;
  804.     }
  805.  
  806.  
  807.     /**
  808.      * Method to reset all aliases in categories.
  809.      *
  810.      * Clears all urlname entries in cat_lang table, and sets the value for all
  811.      * existing entries.
  812.      */
  813.     public static function resetCategoriesAliases({
  814.         $db new DB_Contenido();
  815.  
  816.         $tab parent::$_oGlobals->get('cfg/tab/cat_lang');
  817.  
  818.         // empty all aliases
  819.         $db->query("UPDATE " $tab " SET urlname = ''");
  820.  
  821.         $aCats array();
  822.  
  823.         // get all categories
  824.         $db->query("SELECT name, idcat, idlang FROM " $tab);
  825.         while ($db->next_record()) {
  826.             //set new alias
  827.             self::setCatWebsafeName($db->f('name')$db->f('idcat')$db->f('idlang'));
  828.             $aCats[array('idcat' => $db->f('idcat')'idlang' => $db->f('idlang'));
  829.         }
  830.  
  831.         foreach ($aCats as $p => $item{
  832.             self::setCatUrlPath($item['idcat']$item['idlang']);
  833.         }
  834.  
  835.         unset($db$aCats);
  836.     }
  837.  
  838.  
  839.     /**
  840.      * Method to reset all aliases in articles.
  841.      *
  842.      * Clears all urlname entries in art_lang table, and sets the value for all
  843.      * existing entries.
  844.      */
  845.     public static function resetArticlesAliases({
  846.         $db new DB_Contenido();
  847.  
  848.         $tab parent::$_oGlobals->get('cfg/tab/art_lang');
  849.  
  850.         // empty all aliases
  851.         $db->query("UPDATE " $tab " SET urlname = ''");
  852.  
  853.         // get all articles
  854.         $db->query("SELECT title, idart, idlang FROM " $tab);
  855.         while ($db->next_record()) {
  856.             //set new alias
  857.             self::setArtWebsafeName($db->f('title')$db->f('idart')$db->f('idlang'));
  858.         }
  859.  
  860.         unset ($db);
  861.     }
  862.  
  863.  
  864.     /**
  865.      * Method to reset all aliases (categories and articles).
  866.      *
  867.      * Shortcut to resetArticlesAliases() and resetArticlesAliases()
  868.      */
  869.     public static function resetAliases({
  870.         self::resetCategoriesAliases();
  871.         self::resetArticlesAliases();
  872.     }
  873.  
  874.  
  875.     /**
  876.      * Used to postprocess resolved path
  877.      *
  878.      * Error site handling if category not found
  879.      *
  880.      * if percentage == 100 and there is no 100 percentage result value,
  881.      * error site will be shown - can be adjust by user settings for
  882.      * smooth similar effects - 80 to 95 will be best but have to check by user
  883.      *
  884.      * @deprecated Is no more used
  885.      * @todo remove usage at /contenido/includes/functions.pathresolver.php
  886.      *
  887.      * @param   array  $results  Pathresolver results array
  888.      * @return  mixed  Categoryid or false
  889.      */
  890.     public static function getIdFromPathresolverResult($results{
  891.         $iMinPercentage = (int) parent::getConfig('category_resolve_min_percentage'0);
  892.         $catId key($results);
  893.         if ($iMinPercentage && $results[$catId$iMinPercentage{
  894.             return false;
  895.         else {
  896.             return $catId;
  897.         }
  898.     }
  899.  
  900. }

Documentation generated on Sun, 08 Feb 2009 22:00:30 +0100 by phpDocumentor 1.4.1