mirror of
https://github.com/privacy-protection-tools/anti-AD.git
synced 2025-02-13 17:12:41 +08:00
优化代码逻辑
This commit is contained in:
parent
d096415e77
commit
5e6117518c
@ -180,12 +180,18 @@ class addressMaker{
|
||||
* @param array $arr_whitelist
|
||||
* @return false|int
|
||||
*/
|
||||
public static function write_to_file(array $arr_src, array $arr_format, $arr_whitelist = array()){
|
||||
public static function write_to_file(array $arr_src, array $arr_format, array $arr_whitelist = array()){
|
||||
|
||||
if(count($arr_src) < 1){
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($arr_whitelist as $wlk => $wlv){
|
||||
if(-1 === $wlv){
|
||||
unset($arr_whitelist[$wlk]);
|
||||
}
|
||||
}
|
||||
|
||||
$str_result = '';
|
||||
$line_count = 0;
|
||||
|
||||
@ -200,23 +206,23 @@ class addressMaker{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isset($arr_whitelist[$main_domain]) && (-1 === $arr_whitelist[$main_domain])){
|
||||
unset($arr_whitelist[$main_domain]);
|
||||
}
|
||||
|
||||
$arr_subdomains = array_unique($arr_subdomains);
|
||||
|
||||
if(
|
||||
(1 !== $arr_format['full_domain'])
|
||||
&& (in_array($main_domain, $arr_subdomains) || in_array('www.' . $main_domain, $arr_subdomains))
|
||||
&& (!array_key_exists($main_domain, $arr_whitelist) || $arr_whitelist[$main_domain] > 0)
|
||||
&& (!array_key_exists($main_domain, $arr_whitelist))
|
||||
&& (in_array($main_domain, $arr_subdomains)
|
||||
|| in_array('www.' . $main_domain, $arr_subdomains)
|
||||
|| in_array('.' . $main_domain, $arr_subdomains)
|
||||
)
|
||||
){
|
||||
$str_result .= str_replace('{DOMAIN}', $main_domain, $arr_format['format']) . "\n";
|
||||
$line_count ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach($arr_subdomains as $subdomain){
|
||||
$arr_subdomains = array_fill_keys($arr_subdomains, 2);
|
||||
|
||||
foreach($arr_subdomains as $subdomain => $__){
|
||||
if(array_key_exists($subdomain, $arr_whitelist)){
|
||||
continue;
|
||||
}
|
||||
@ -234,17 +240,13 @@ class addressMaker{
|
||||
for($pos = 3; $pos <= $tmp_domain_len; $pos ++){
|
||||
$arr_tmp = array_slice($arr_tmp_domain, -1 * $pos);
|
||||
$tmp = implode('.', $arr_tmp);
|
||||
if(isset($arr_whitelist[$tmp]) && (-1 === $arr_whitelist[$tmp])){
|
||||
unset($arr_whitelist[$tmp]);
|
||||
}
|
||||
|
||||
if(array_key_exists($tmp, $arr_whitelist)){
|
||||
$matched_flag = $arr_whitelist[$tmp] === 1;
|
||||
if($matched_flag){
|
||||
$arr_written[$subdomain] = $pos;
|
||||
}
|
||||
break;
|
||||
}elseif(($tmp === $subdomain) || in_array($tmp, $arr_subdomains)){
|
||||
}
|
||||
|
||||
if(($tmp === $subdomain) || array_key_exists($tmp, $arr_subdomains)){
|
||||
if(!array_key_exists($tmp, $arr_written)){
|
||||
$str_result .= str_replace('{DOMAIN}', $tmp, $arr_format['format']) . "\n";
|
||||
$line_count ++;
|
||||
|
@ -2,7 +2,7 @@
|
||||
//white_domain_list
|
||||
//白名单机制...,白名单是
|
||||
//@date 2018年12月23日
|
||||
//value=-1,代表失效本条规则,暂只支持单域名(针对引入外部白名单时的精确控制)
|
||||
//value=-1,代表失效本条规则,暂只支持单域名(针对引入外部白名单时的精确控制),当处于strict_mode时,排除此key,单条关闭strict_mode
|
||||
//value=0,代表仅加白单条域名
|
||||
//value=1,代表其下级域名全部加白(例如3级域名,则其4级子域名全部加白)
|
||||
//value=2,代表仅加白主域名及其子域名,即如果是主域名,加白全部,如果是子域名,加白命中的单条
|
||||
@ -27,7 +27,7 @@ return array(
|
||||
'edge.yunjiasu.com' => 0, //百度云加速javascript快速加载功能
|
||||
'cd.bendibao.com' => 0, //成都本地宝
|
||||
'm.qpic.cn' => 0, // qq,微信,QQ空间等用到的静态资源域名
|
||||
'ipify.org' => 0, // 获得公网 IP
|
||||
'ipify.org' => 1, // 获得公网 IP
|
||||
'pass.1688.com' => 0, // 阿里巴巴网站访问不正常
|
||||
'cedexis.net' => 0, // windowsupdate CNAME
|
||||
'y0.cn' => 0, // 短网址服务,涉及本次丁香医生实时疫情页面 http://y0.cn/sari
|
||||
@ -52,10 +52,10 @@ return array(
|
||||
'rarbg.to' => 0, //BT站
|
||||
|
||||
|
||||
'herokuapp.com' => 0,
|
||||
'vidoza.net' => 0,
|
||||
'herokuapp.com' => -1,
|
||||
'vidoza.net' => -1,
|
||||
'nahnoji.cz' => 1,
|
||||
'cloudfront.net' => 0,
|
||||
'cloudfront.net' => -1,
|
||||
|
||||
/**notracking 提议加白的一批域名 start**/
|
||||
'scribol.com' => 0,
|
||||
|
Loading…
Reference in New Issue
Block a user