str_replace help please.
Posted: Fri Apr 25, 2008 4:58 pm
Can someone tell me why the search and replace function isn't working for the first three $_GET['type']'s?
This isn't supposed to be a sold script rather a way for me to mass edit over 60000 .html pages in a day rather than 3 years.
Please help me.
This isn't supposed to be a sold script rather a way for me to mass edit over 60000 .html pages in a day rather than 3 years.
Please help me.
Code: Select all
<?php
set_time_limit(0);
if(isset($_GET['type']))
$siteFiles = glob_rec("*.html","/media/Storage/sites/client-XXX/");
if($_GET['type'] == 1) /**********************************************************************************************************/
{
$find = <<<EOF
<script type="text/javascript"><!--
google_ad_client = "change-adsense";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "336699";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
EOF;
$replace = <<<EOF
<script language="JavaScript" type="text/javascript">
<!--
ctxt_ad_partner = "9853490480";
ctxt_ad_section = "68180";
ctxt_ad_bg = "";
ctxt_ad_width = 728;
ctxt_ad_height = 90;
ctxt_ad_bc = "FFFFFF";
ctxt_ad_cc = "FFFFFF";
ctxt_ad_lc = "0000FF";
ctxt_ad_tc = "000000";
ctxt_ad_uc = "999999";
// -->
</script>
<script language="JavaScript" src="http://ypn-js.overture.com/partner/js/ypn.js">
</script>
EOF;
}
elseif($_GET['type'] == 2) /**********************************************************************************************************/
{
$find = <<<EOF
<script type="text/javascript"><!--
google_ad_client = "change-adsense";
google_ad_width = 250;
google_ad_height = 250;
google_ad_format = "250x250_as";
google_ad_type = "text";
google_ad_channel ="";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
EOF;
$replace = <<<EOF
<script language="JavaScript" type="text/javascript">
<!--
ctxt_ad_partner = "9853490480";
ctxt_ad_section = "68180";
ctxt_ad_bg = "";
ctxt_ad_width = 250;
ctxt_ad_height = 250;
ctxt_ad_bc = "FFFFFF";
ctxt_ad_cc = "FFFFFF";
ctxt_ad_lc = "0000FF";
ctxt_ad_tc = "000000";
ctxt_ad_uc = "999999";
// -->
</script>
<script language="JavaScript" src="http://ypn-js.overture.com/partner/js/ypn.js">
</script>
EOF;
}
elseif($_GET['type'] == 3) /**********************************************************************************************************/
{
$find = <<<EOF
<!-- Search Google -->
<center>
<form method="get" action="http://www.google.com/custom" target="_top">
<table bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle" width="75" height="32"></img></a>
<input type="text" name="q" size="31" maxlength="255" value=""></input>
<input type="submit" name="sa" value="Search"></input>
<input type="hidden" name="client" value="change-adsense"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="ISO-8859-1"></input>
<input type="hidden" name="oe" value="ISO-8859-1"></input>
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"></input>
<input type="hidden" name="hl" value="en"></input>
</td></tr></table>
</form>
</center>
<!-- Search Google -->
EOF;
$replace = <<<EOF
<center><script type="text/javascript"><!--
amazon_ad_tag = "neoelite-20"; amazon_ad_width = "728"; amazon_ad_height = "90";//--></script>
<script type="text/javascript" src="http://www.assoc-amazon.com/s/ads.js"></script></center>
EOF;
}
elseif($_GET['type'] == 4) /**********************************************************************************************************/
{
$find = <<<EOF
<hr width="800" noshade>
EOF;
$replace = <<<EOF
<center><script language="JavaScript" type="text/javascript">
<!--
ctxt_ad_partner = "9853490480";
ctxt_ad_section = "68180";
ctxt_ad_bg = "";
ctxt_ad_width = 728;
ctxt_ad_height = 90;
ctxt_ad_bc = "FFFFFF";
ctxt_ad_cc = "FFFFFF";
ctxt_ad_lc = "0000FF";
ctxt_ad_tc = "000000";
ctxt_ad_uc = "999999";
// -->
</script>
<script language="JavaScript" src="http://ypn-js.overture.com/partner/js/ypn.js">
</script>
</center>
<hr width="800" noshade>
EOF;
}
elseif($_GET['type'] == 5) /**********************************************************************************************************/
{
$find = <<<EOF
</head>
EOF;
$replace = <<<EOF
<script type="text/javascript"><!--
amzn_cl_tag="neoelite-20";
//--></script>
<script type="text/javascript" src="http://cls.assoc-amazon.com/s/cls.js"></script>
</head>
EOF;
}
else /*******************************************************************************************************************************/
{
echo "Choose:<br />";
echo "<a href='".$_SERVER['PHP_SELF']."?type=1'>Step 1</a><br />";
echo "<a href='".$_SERVER['PHP_SELF']."?type=2'>Step 2</a><br />";
echo "<a href='".$_SERVER['PHP_SELF']."?type=3'>Step 3</a><br />";
echo "<a href='".$_SERVER['PHP_SELF']."?type=4'>Step 4</a><br />";
echo "<a href='".$_SERVER['PHP_SELF']."?type=5'>Step 5</a><br />";
exit();
}
function glob_rec($pattern, $path) {
return explode("\n", shell_exec("find $path -name $pattern"));
}
$filesTotal = 0;
$filesHacked = 0;
foreach ($siteFiles as $filename) {
$file = file_get_contents($filename);
++$filesTotal;
$newfile = str_replace($find, $replace, $file);
if(!$file == $newfile)
++$filesHacked;
file_put_contents($filename,$newfile);
}
echo "<h1>".$filesTotal." Files Total / ".$filesHacked." files hacked / ".($filesHacked/$filesTotal)." Ratio</h1><br />";
echo "<a href='".$_SERVER['PHP_SELF']."'>Main Menu</a>";
if($_GET['type'] < 5)
echo " | <a href='".$_SERVER['PHP_SELF']."?type=".($_GET['type']+1)."'>Continue?</a>";