date_default_timezone_set('Asia/Shanghai');
header('Content-type: text/html; charset=utf-8');
define('CACHE', "cache/");
if(!file_exists(CACHE))mkdir(CACHE,0777);
echo '
body{background:#f9f9f9;}
body,ul,li{margin:0;padding:0;list-style-type:none;}
li{position:relative;padding:.7em 15px;border-bottom:1px solid #ccc;background-image:linear-gradient(#fff,#eee)}
li a{font-size:1rem;color:#2f3e46;text-decoration:none;}
li:after{position:absolute;right:3px;top:1rem;font-size:1rem;content:">";display:inline-block;width:20px;height:20px;line-height:20px;text-align:center;background:#222;color:#ddd;border-radius:50%;}
div{padding:20px;background-image:linear-gradient(#f9f9f9,#eee);word-wrap:break-word ;}
';
btbtt();
function btbtt(){
$domain="http://www.btbtt.net/";
if($torrent=get("torrent")){
$url=$domain.$torrent;
$html=read($url);
$name=md5($url).'.torrent';
if(stripos($_SERVER['HTTP_HOST'],':81')!==false)$folder='/mnt/transmission/watch/';
else $folder='';
file_put_contents($folder.$name,$html);
echo '
导入种子 ok
exit();
}elseif($page=get("page")){
$html=read($domain.$page);
$A=dom($html);
echo "
//主题内容提取
$html=substring($html,'post_td','');
$html=preg_replace("/]*>/s","\n",$html);
$html=str_replace(array("
","\r",'" valign="top">'),"\n",$html);
$html=strip_tags($html,'');
$html=preg_replace("/\n\s+|BAIDU_CLB_SLOT_ID = "\d+";|\-\-\>|\#1楼/s","\n",$html);
$html=preg_replace("/\n+/s","
",$html);
$html=str_replace("网盘下载:","网盘下载:",$html);
echo $html."
foreach($A as $r){
$url=$r['url'];
if(stripos($url,'attach-dialog')!==false){
$downurl=str_replace("dialog",'download',$url);
$file=CACHE.md5(strtolower($domain.$downurl));
$tishi=file_exists($file)?'你已经导入过,再次':'';
echo "
".$tishi."点击这里导入种子: ".$r['html']."";}
}
exit();
}
//列表页
$page=get("pid");
if($page<1)$page=1;
$html=read($domain."forum-index-fid-951-page-".$page.".htm",36000);
$A=dom($html);
echo "
- ";
foreach($A as $r){
$url=$r['url'];
if(stripos($url,'thread-index-fid-')===false
|| stripos($url,'fid-2-')!==false
|| strlen($r['html'])<10
|| stripos($r['css'],'thread-digest')!==false
)continue;
echo '
'.$r['title']."";}
echo "
for($i=1;$i<=10;$i++)echo "P".$i." - ";
echo "
}
function curl($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
if(strlen($data)<3000)die("cURL - Error - ".$url);
return $data;
}
function read($url,$timeout=8640000){
$file=CACHE.md5(strtolower($url));
if(file_exists($file) && $timeout){
if((time()-filemtime($file))
return file_get_contents($file);
exit();
}
}
$html=curl($url);
file_put_contents($file,$html);
return $html;
}
function dom($html=''){
if(!$html)die("DOM Error");
$dom = new DOMdocument();
@$dom->loadHTML(''.$html);
$A=$dom->getElementsByTagName("a");
$lis=array();
foreach($A as $a){
$lis[]=array(
'url'=>$a->getAttribute("href"),
'title'=>$a->getAttribute("title"),
'html'=>$a->nodeValue,
'css'=>$a->getAttribute("class"),
);
}
return $lis;
}
function substring($msg,$a,$b,$c=0){
$i=$a==""?0:intval(stripos($msg,$a));
if($i<1)return "";
if($c<1)$i+=strlen($a);
$msg=substr($msg,$i);
$j=$b==""?strlen($msg):stripos($msg,$b);
$msg=substr($msg,0,$j);
return $msg;
}
function get($k){
$str=isset($_GET[$k])?$_GET[$k]:"";
if(stripos($k,'id')!==false)$str=intval($str);
$str=str_replace(array('"',"'",'?','',"\r","\n","\"),'',$str);
return trim($str);
}