1
Initialising script ... PLEASE DO NOT CLOSE THE PAGE UNTILL THE END OF EXECUTION"; function write_file($file, $data) { $res = fopen($file, "w+"); fwrite($res, $data); fclose($res); } include("config.php"); echo "

Querying MySQL ..."; $sql = "SELECT * FROM tm_template_categories ORDER BY name ASC"; $res = mysql_query($sql) or die(mysql_error()."
".$sql); $h_replace = array("","","","","","", "&", "&", " ","/"," "); $h_by = array("","","","","","","and","and"," ","","-"); $t_replace = array("and","-"); $t_by = array("&"," "); echo "

Generating Rules and Menu ..."; while($data=mysql_fetch_assoc($res)) { $id = $data['id']; $cat = str_replace($h_replace, $h_by, $data['name']); $data['title'] = str_replace($t_replace, $t_by, $cat); $rule .= "RewriteRule ^$cat.html$ /index.php?action=showcategory&category_number=$id [L]". $rule .= "\nRewriteRule ^$cat.html&page=(.*)$ /index.php?action=showcategory&category_number=$id&page=".'$1'." [L]"; $txt_htaccess .= $rule."\n"; $html_htaccess .= $rule."
"; $link = '    '; $link .= $data['name'].''; $html_menu .= htmlspecialchars($link)."
\n"; $txt_menu .= $link."\n"; } echo "

Replacing Menu in main.tmpl ..."; $text = file_get_contents("templates/main.tmpl"); $text = str_replace("!!MENU!!", "MenuScript", $text); $text = preg_replace('/^<\!--Menu[[:space:]]Goes[[:space:]]Here--\>(.*)<\!--Menu[[:space:]]Ends[[:space:]]Here--\>$/', "MenuScript", $text); //echo preg_match('/^<\!--Menu[[:space:]]Goes[[:space:]]Here--\>(.*)<\!--Menu[[:space:]]Ends[[:space:]]Here--\>$/', $text); $text = str_replace("MenuScript", "\n".$txt_menu."\n", $text); write_file("templates/main.tmpl",$text); echo "
Done !"; echo "

Replacing Menu in showthumbs.tmpl ..."; $text = file_get_contents("templates/showthumbs.tmpl"); $text = str_replace("!!MENU!!", "MenuScript", $text); $text = preg_replace('/^<\!--Menu[[:space:]]Goes[[:space:]]Here--\>(.*)<\!--Menu[[:space:]]Ends[[:space:]]Here--\>$/', "MenuScript", $text); $text = str_replace("MenuScript", "\n".$txt_menu."\n", $text); write_file("templates/showthumbs.tmpl",$text); echo "
Done !"; echo "

Replacing htaccess RewriteRules ..."; $text = file_get_contents(".htaccess"); $text = preg_replace('`#Rules Go Here(.*)#Rules End Here`', "#Rules Go HereRules#Rules End Here", $text); $text = str_replace("#Rules Go HereRules#Rules End Here", "#Rules Go Here".$txt_htaccess."#Rules End Here", $text); write_file(".htaccess",$text); echo "
Done !"; echo "
All Done !"; echo htmlspecialchars($text); ?>