rendered paste body1<?php
echo "<br /><br />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 "<br /><br />Querying MySQL ...";
$sql = "SELECT * FROM tm_template_categories ORDER BY name ASC";
$res = mysql_query($sql) or die(mysql_error()."<br>".$sql);
$h_replace = array("<b>","</b>","<i>","</i>","<u>","</u>", "&", "&", " ","/"," ");
$h_by = array("","","","","","","and","and"," ","","-");
$t_replace = array("and","-");
$t_by = array("&"," ");
echo "<br /><br />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."<br />";
$link = '<tr><td style="text-align: left;"> <a href="'.$cat.'.html" title="'.$data['title'].'">';
$link .= $data['name'].'</a></td></tr>';
$html_menu .= htmlspecialchars($link)."<br />\n";
$txt_menu .= $link."\n";
}
echo "<br /><br />Replacing Menu in main.tmpl ...";
$text = file_get_contents("templates/main.tmpl");
$text = str_replace("!!MENU!!", "<!--Menu Goes Here-->MenuScript<!--Menu Ends Here-->", $text);
$text = preg_replace('/^<\!--Menu[[:space:]]Goes[[:space:]]Here--\>(.*)<\!--Menu[[:space:]]Ends[[:space:]]Here--\>$/', "<!--Menu Goes Here-->MenuScript<!--Menu Ends Here-->", $text);
//echo preg_match('/^<\!--Menu[[:space:]]Goes[[:space:]]Here--\>(.*)<\!--Menu[[:space:]]Ends[[:space:]]Here--\>$/', $text);
$text = str_replace("<!--Menu Goes Here-->MenuScript<!--Menu Ends Here-->", "<!--Menu Goes Here-->\n".$txt_menu."\n<!--Menu Ends Here-->", $text);
write_file("templates/main.tmpl",$text);
echo "<br />Done !";
echo "<br /><br />Replacing Menu in showthumbs.tmpl ...";
$text = file_get_contents("templates/showthumbs.tmpl");
$text = str_replace("!!MENU!!", "<!--Menu Goes Here-->MenuScript<!--Menu Ends Here-->", $text);
$text = preg_replace('/^<\!--Menu[[:space:]]Goes[[:space:]]Here--\>(.*)<\!--Menu[[:space:]]Ends[[:space:]]Here--\>$/', "<!--Menu Goes Here-->MenuScript<!--Menu Ends Here-->", $text);
$text = str_replace("<!--Menu Goes Here-->MenuScript<!--Menu Ends Here-->", "<!--Menu Goes Here-->\n".$txt_menu."\n<!--Menu Ends Here-->", $text);
write_file("templates/showthumbs.tmpl",$text);
echo "<br />Done !";
echo "<br /><br />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 "<br />Done !";
echo "<br />All Done !";
echo htmlspecialchars($text);
?>
<!-- New Htaccess data :<br />
<? echo $html_htaccess; ?>
<br /><br />
New HTLM menu :<br />
<? echo $html_menu;
mysql_close(); ?>
-->