Source for file functions.mod_rewrite_setup.php

Documentation is available at functions.mod_rewrite_setup.php

  1. <?php
  2. /**
  3.  * Functions to upgrade to modrewrite, used by plugin setup
  4.  *
  5.  * @author      Stefan Seifarth / stese
  6.  * @copyright   © www.polycoder.de
  7.  * @package     Contenido
  8.  * @subpackage  ModRewrite
  9.  */
  10.  
  11.  
  12. /******************************************
  13. * File      :   functions.mod_rewrite_setup.php
  14. * Project   :   Contenido
  15. * Descr     :   functions to upgrade to modrewrite
  16. *
  17. * Author    :   Stefan Seifarth
  18. * Created   :   28.12.2005
  19. * Modified  :   28.12.2005
  20. * Modified  :   06.03.2008, Murat Purc, extracted from setup/lib directory
  21. * © www.polycoder.de
  22. */
  23. error_reporting (E_ALL E_NOTICE);
  24.  
  25.  
  26. /**
  27.  * upgradeModRewrite
  28.  * 
  29.  * handle upgrading of mod rewrite needed
  30.  * database table columns
  31.  */
  32. function upgradeModRewrite ({
  33.     global $cfg;
  34.  
  35.     $db new DB_Contenido();
  36.  
  37.     $sql "ALTER TABLE " $cfg["tab"]["art_lang"" ADD urlname VARCHAR( 128 ) AFTER title";
  38.     $db->query$sql );
  39.  
  40.     // check for empty article fields
  41.     $sql "SELECT idlang, title, idart FROM " $cfg["tab"]["art_lang"" WHERE urlname IS NULL OR urlname = ''";
  42.     $db->query($sql);
  43.     while $db->next_record() ) {
  44.         set_article($db->f('title')$db->f('idart')$db->f('idlang'));
  45.     }
  46.  
  47.     // check for empty category fields
  48.     $sql "SELECT name, idcat, idlang FROM " $cfg["tab"]["cat_lang"" WHERE urlname IS NULL OR urlname = ''";
  49.     $db->query($sql);
  50.     while $db->next_record() ) {
  51.         set_category($db->f('name')$db->f('idcat')$db->f('idlang'));
  52.     }
  53.  
  54. }
  55.  
  56.  
  57. function uninstallModRewrite({
  58.     global $cfg;
  59.     $db new DB_Contenido();
  60.     $sql "ALTER TABLE " $cfg["tab"]["art_lang"" DROP urlname";
  61.     $db->query$sql );
  62. }
  63.  
  64.  
  65. /**
  66.  * set_article()
  67.  *
  68.  * set websafe name in article list
  69.  *
  70.  * insert new websafe name in article list
  71.  *
  72.  * @param   string  original name (will be converted)
  73.  * @param   integer current article id
  74.  * @param   integer current language id
  75.  * @return  boolean true if insert was successfully
  76.  */
  77. function set_article $str_name ""$int_id 0$int_lang_id 0$int_idcat 0{
  78.     global $cfg;
  79.     static $db;
  80.     
  81.     if (!isset($db)) {
  82.         $db new DB_Contenido();
  83.     }
  84.     
  85.     // create websafe name
  86.     $str_new_name capiStrCleanURLCharacters($str_name);
  87.  
  88.     // check if websafe name already exists
  89.     if in_articles($str_new_name$int_id$int_lang_id$int_idcat) ) {
  90.         // create new websafe name if exists
  91.         $str_new_name capiStrCleanURLCharacters($str_name"_" $int_id;
  92.     
  93.  
  94.     // check again - and set name
  95.     if (!in_articles($str_new_name$int_id$int_lang_id$int_idcat)) {
  96.         // insert websafe name in article list
  97.         $sql "UPDATE " $cfg["tab"]["art_lang"" SET urlname = '" $str_new_name "' WHERE idart = '" $int_id "' AND idlang = '" $int_lang_id "'";
  98.         return $db->query($sql);
  99.     else {
  100.         return false;
  101.     }
  102. // end function
  103.  
  104.  
  105.  
  106.  
  107. /**
  108.  * set_category()
  109.  *
  110.  * set websafe name in category list
  111.  *
  112.  * insert new websafe name in category list
  113.  *
  114.  * @param   string  original name (will be converted)
  115.  * @param   integer current article id
  116.  * @param   integer current language id
  117.  * @return  boolean true if insert was successfully
  118.  */
  119. function set_category $str_name ""$int_id 0$int_lang_id 0{
  120.     global $cfg;
  121.     static $db;
  122.     
  123.     if (!isset($db)) {
  124.         $db new DB_Contenido();
  125.     }
  126.     
  127.     // create websafe name
  128.     $str_new_name capiStrCleanURLCharacters($str_name);
  129.  
  130.     // check if websafe name already exists
  131.     if (in_category($str_new_name$int_id$int_lang_id)) {
  132.     // create new websafe name if exists
  133.     $str_new_name capiStrCleanURLCharacters($str_name"_" $int_id;
  134.     }
  135.  
  136.  
  137.     // check again - and set name
  138.     if (!in_category($str_new_name$int_id$int_lang_id)) {
  139.         // insert websafe name in article list
  140.         $sql "UPDATE " $cfg["tab"]["cat_lang"" SET urlname = '$str_new_name' WHERE idcat = '$int_id' AND idlang = '$int_lang_id'";
  141.         return $db->query($sql);
  142.     else {
  143.         return false;
  144.     }
  145. // end function
  146.  
  147.  
  148.  
  149.     
  150. /**
  151.  * in_articles()
  152.  *
  153.  * Check articles on websafe name
  154.  *
  155.  * Check all articles in the current category
  156.  * on existing same websafe name
  157.  *
  158.  * @param   string  Websafe name to check
  159.  * @param   integer current article id
  160.  * @param   integer current language id
  161.  * @param   integer current category id
  162.  * @return  boolean true if websafename already exists, false if not
  163.  */
  164. function in_articles $str_name ""$int_id 0$int_lang_id 0$int_idcat 0{
  165.     global $cfg;
  166.     static $db;
  167.     
  168.     if (!isset($db)) {
  169.         $db new DB_Contenido();
  170.     }
  171.     
  172.     // handle multipages
  173.     if ($int_idcat 0{
  174.         $int_category_id $int_idcat;
  175.     else {
  176.         // get category id if not set
  177.         $sql "SELECT idcat FROM " $cfg["tab"]["cat_art"" WHERE idart = '$int_id'";
  178.         $db->query($sql);
  179.         $db->next_record();
  180.         $int_category_id ($db->f("idcat"$db->f("idcat""0";
  181.     }
  182.  
  183.     $str_where " ca.idcat = '$int_category_id' AND"
  184.                . " al.idlang = '" $int_lang_id "' AND"
  185.                . " al.urlname = '" $str_name "' AND"
  186.                . " al.idart <> '$int_id'";
  187.  
  188.     // check if websafe name is in this category
  189.     $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;
  190.     $db->query($sql);
  191.     $db->next_record();
  192.  
  193.     $int_count $db->f("numcats");
  194.  
  195.     return ($int_count 0true false;
  196. // end function
  197.  
  198.  
  199.  
  200. /**
  201.  * in_categories()
  202.  *
  203.  * Check categories on websafe name
  204.  *
  205.  * Check all categories in the main parent
  206.  * category on existing same websafe name
  207.  *
  208.  * @param   string  Websafe name to check
  209.  * @param   integer current category id
  210.  * @param   integer current language id
  211.  * @return  boolean true if websafename already exists, false if not
  212.  */
  213. function in_category $str_name ""$int_id 0$int_lang_id 0{
  214.     global $cfg;
  215.     static $db;
  216.     
  217.     if (!isset($db)) {
  218.         $db new DB_Contenido();
  219.     }
  220.  
  221.     // get parentid
  222.     $sql "SELECT parentid FROM " $cfg["tab"]["cat"" WHERE idcat = '$int_id'";
  223.     $db->query($sql);
  224.     $db->next_record();
  225.     $int_parent_id ($db->f("parentid"$db->f("parentid""0";
  226.  
  227.     $str_where " c.parentid = '$int_parent_id' AND"
  228.                . " cl.idlang = '" $int_lang_id "' AND"
  229.                . " cl.urlname = '" $str_name "' AND"
  230.                . " cl.idcat <> '$int_id'";
  231.  
  232.     // check if websafe name is in this category
  233.     $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;
  234.     $db->query($sql);
  235.     $db->next_record();
  236.  
  237.     $int_count $db->f("numcats");
  238.  
  239.     return ($int_count 0true false;
  240. // end function
  241.  
  242.  
  243. ?>

Documentation generated on Thu, 19 Jun 2008 22:44:02 +0200 by phpDocumentor 1.4.0