优化代码逻辑

This commit is contained in:
gently 2020-02-13 20:49:21 +08:00
parent d096415e77
commit 5e6117518c
2 changed files with 23 additions and 21 deletions

View File

@ -180,12 +180,18 @@ class addressMaker{
* @param array $arr_whitelist * @param array $arr_whitelist
* @return false|int * @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){ if(count($arr_src) < 1){
return false; return false;
} }
foreach($arr_whitelist as $wlk => $wlv){
if(-1 === $wlv){
unset($arr_whitelist[$wlk]);
}
}
$str_result = ''; $str_result = '';
$line_count = 0; $line_count = 0;
@ -200,23 +206,23 @@ class addressMaker{
continue; continue;
} }
if(isset($arr_whitelist[$main_domain]) && (-1 === $arr_whitelist[$main_domain])){
unset($arr_whitelist[$main_domain]);
}
$arr_subdomains = array_unique($arr_subdomains);
if( if(
(1 !== $arr_format['full_domain']) (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))
&& (!array_key_exists($main_domain, $arr_whitelist) || $arr_whitelist[$main_domain] > 0) && (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"; $str_result .= str_replace('{DOMAIN}', $main_domain, $arr_format['format']) . "\n";
$line_count ++; $line_count ++;
continue; 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)){ if(array_key_exists($subdomain, $arr_whitelist)){
continue; continue;
} }
@ -234,17 +240,13 @@ class addressMaker{
for($pos = 3; $pos <= $tmp_domain_len; $pos ++){ for($pos = 3; $pos <= $tmp_domain_len; $pos ++){
$arr_tmp = array_slice($arr_tmp_domain, -1 * $pos); $arr_tmp = array_slice($arr_tmp_domain, -1 * $pos);
$tmp = implode('.', $arr_tmp); $tmp = implode('.', $arr_tmp);
if(isset($arr_whitelist[$tmp]) && (-1 === $arr_whitelist[$tmp])){
unset($arr_whitelist[$tmp]);
}
if(array_key_exists($tmp, $arr_whitelist)){ if(array_key_exists($tmp, $arr_whitelist)){
$matched_flag = $arr_whitelist[$tmp] === 1; $matched_flag = $arr_whitelist[$tmp] === 1;
if($matched_flag){
$arr_written[$subdomain] = $pos;
}
break; 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)){ if(!array_key_exists($tmp, $arr_written)){
$str_result .= str_replace('{DOMAIN}', $tmp, $arr_format['format']) . "\n"; $str_result .= str_replace('{DOMAIN}', $tmp, $arr_format['format']) . "\n";
$line_count ++; $line_count ++;

View File

@ -2,7 +2,7 @@
//white_domain_list //white_domain_list
//白名单机制...,白名单是 //白名单机制...,白名单是
//@date 2018年12月23日 //@date 2018年12月23日
//value=-1,代表失效本条规则,暂只支持单域名(针对引入外部白名单时的精确控制) //value=-1,代表失效本条规则,暂只支持单域名(针对引入外部白名单时的精确控制),当处于strict_mode时排除此key单条关闭strict_mode
//value=0,代表仅加白单条域名 //value=0,代表仅加白单条域名
//value=1,代表其下级域名全部加白例如3级域名则其4级子域名全部加白 //value=1,代表其下级域名全部加白例如3级域名则其4级子域名全部加白
//value=2,代表仅加白主域名及其子域名,即如果是主域名,加白全部,如果是子域名,加白命中的单条 //value=2,代表仅加白主域名及其子域名,即如果是主域名,加白全部,如果是子域名,加白命中的单条
@ -27,7 +27,7 @@ return array(
'edge.yunjiasu.com' => 0, //百度云加速javascript快速加载功能 'edge.yunjiasu.com' => 0, //百度云加速javascript快速加载功能
'cd.bendibao.com' => 0, //成都本地宝 'cd.bendibao.com' => 0, //成都本地宝
'm.qpic.cn' => 0, // qq微信QQ空间等用到的静态资源域名 'm.qpic.cn' => 0, // qq微信QQ空间等用到的静态资源域名
'ipify.org' => 0, // 获得公网 IP 'ipify.org' => 1, // 获得公网 IP
'pass.1688.com' => 0, // 阿里巴巴网站访问不正常 'pass.1688.com' => 0, // 阿里巴巴网站访问不正常
'cedexis.net' => 0, // windowsupdate CNAME 'cedexis.net' => 0, // windowsupdate CNAME
'y0.cn' => 0, // 短网址服务,涉及本次丁香医生实时疫情页面 http://y0.cn/sari 'y0.cn' => 0, // 短网址服务,涉及本次丁香医生实时疫情页面 http://y0.cn/sari
@ -52,10 +52,10 @@ return array(
'rarbg.to' => 0, //BT站 'rarbg.to' => 0, //BT站
'herokuapp.com' => 0, 'herokuapp.com' => -1,
'vidoza.net' => 0, 'vidoza.net' => -1,
'nahnoji.cz' => 1, 'nahnoji.cz' => 1,
'cloudfront.net' => 0, 'cloudfront.net' => -1,
/**notracking 提议加白的一批域名 start**/ /**notracking 提议加白的一批域名 start**/
'scribol.com' => 0, 'scribol.com' => 0,