ACC SHELL
<?php
include "pripojenidb.php";
// ------------------------ mod_rewrite.class.php ------------------------
// verze 0.5 RC by Milan, WebRex (milan[at]webrex[dot]cz)
//
// zmeny:
// v0.1(02.04.2006) - alpha verze
// v0.5(02.04.2006) - RC verze
// - opravena funkcnost rekurzivni funkce
// ToDo:
// - lowercase nazvu, substituce nepovolenych znaku(mezera,?,&)
// ------------------------------------------------------------------------
// pouziti:
// $mod = new mod_rewrite("nespi2","cz","aktualniprojekty/nespi2",".html");
// $mod->mod_htaccess_recursive();
// ------------------------------------------------------------------------
class mod_rewrite
{
var $menu_table;
var $path;
var $suffix;
//konstruktor
function mod_rewrite($name, $lang, $path,$suffix)
{
$this->menu_table = $name."menu".$lang;
$this->path = $path;
$this->suffix = $suffix;
}
//vygeneruje .htaccess soubor s pravidly
function mod_htaccess()
{
$res = mysql_query("SELECT * FROM ".$this->menu_table);
$fw = fopen(".htaccess","w");
fwrite($fw,"Option FollowSymLinks\n");
fwrite($fw,"RewriteEngine On\n");
fwrite($fw,"RewriteBase /\n\n");
while($obj = mysql_fetch_object($res))
fwrite($fw,"RewriteRule ^".$obj->Nazev.$this->suffix." ".$this->path."/index.php?menu=".$obj->ID_menu."\n");
mysql_free_result($res);
fclose($fw);
return 1;
}
//pomocna funkce pro mod_htaccess_recursive() - samostatne nepouzivat
function helper($id,$indent,$level,$str,$fw)
{
if($level == 0)
$indent .= $str; //odsazeni
else
$indent .= $str."-"; //odsazeni
$level++;
$res = mysql_query("SELECT * FROM $this->menu_table WHERE Nadmenu = '".$id."'");
while($obj = mysql_fetch_object($res))
{
$str = $obj->Nazev;
fwrite($fw,"RewriteRule ^".$indent.$obj->Nazev.$this->suffix." ".$this->path."/index.php?menu=".$obj->ID_menu."\n"); //vypis lajnu
$this->helper(stripslashes($obj->ID_menu),$indent,$level,$str,$fw);
}
mysql_free_result($res);
}
//vygeneruje .htaccess soubor s pravidly(rekurzivni nazvy)
function mod_htaccess_recursive()
{
$fw = fopen(".htaccess","w");
fwrite($fw,"Option FollowSymLinks\n");
fwrite($fw,"RewriteEngine On\n");
fwrite($fw,"RewriteBase /\n\n");
$this->helper(0,"",0,"",$fw);
fclose($fw);
return 1;
}
//vygeneruje link dle mod_rewrite pravidel
function mod_link($link_id)
{
$res = mysql_query("SELECT * FROM ".$this->menu_table." WHERE ID_menu='".$link_id."'");
$obj = mysql_fetch_object($res);
mysql_free_result($res);
return ($obj->Nazev.$this->suffix);
}
//vygeneruje link dle mod_rewrite pravidel(rekurzivni nazev)
function mod_link_recursive($link_id)
{
$pole = array();
$id = $link_id;
$i = 0;
$res = mysql_query("SELECT * FROM ".$this->menu_table." WHERE ID_menu = '".$link_id."'");
$obj = mysql_fetch_object($res);
$pole[$i++] = $obj->Nazev;
mysql_free_result($res);
while($id != 0)
{
$res = mysql_query("SELECT * FROM ".$this->menu_table." WHERE ID_menu = '".$id."'");
$obj = mysql_fetch_object($res);
$pole[$i++] = $obj->Nazev;
$id = $obj->Nadmenu;
mysql_free_result($res);
}
$str = "";
for($i = count($pole)-1;$i > 0; $i--)
{
if($i > 1)
$str .= $pole[$i]."-";
else
$str .= $pole[$i];
}
return ($str.$this->suffix);
}
}
?>
ACC SHELL 2018