子比主题友链一键获取-增加友链检测功能-优化通知信息[已失效]

前言:

如果你是子比主题,在自己的友情链接申请页面,为了方便用户一键提交,弄个这个还是挺有用的。

图片[1]-子比主题友链一键获取-增加友链检测功能-优化通知信息[已失效]-樱花小镇

使用教程:

1.目前6.6版本,大概在在zibll文件夹的inc/functions/functions.php的1402行(也可以搜索关键词 【链接地址】找到)

图片[2]-子比主题友链一键获取-增加友链检测功能-优化通知信息[已失效]-樱花小镇

如图所示修改为以下代码,直接复制覆盖那一段

    $card .= '<div class="form-group">
                <label for="link_url" class="col-sm-2 control-label">链接地址</label>
                <div class="col-sm-9" style="display: flex;">
                <input type="text" class="form-control"  id="link_url" style="flex: 30px;" name="link_url" placeholder="链接地址(必填)"> 
                <a class= "newadd-btns but pw-1em mr6 jb-pink btn-newadd"  id="link_deta"  href="javascript:;" type="radio" name="type" onclick="sub()" ><i class="fa fa-search mr10"></i>一键获取</a>  
                <input type="text" style="display: none;" id="link_yes" name="link_yes" onfocus=this.blur() >
            </div>
            </div>';

2.然后到 在 themes/zibll/action/function.php里949行 【或者搜zib_ajax_verify_nonce()里面添加下面代码

图片[3]-子比主题友链一键获取-增加友链检测功能-优化通知信息[已失效]-樱花小镇
    if (empty($_POST['link_yes'])) {
        echo (json_encode(array('error' => 1, 'ys' => 'danger', 'msg' => '请使用一键获取功能')));
        exit();
    }

3.替换掉zibll的 /wp-content/themes/zibll/pages/links.php文件

<?php
/*
 * @Author: Qinver
 * @Url: zibll.com
 * @Date: 2021-04-11 21:36:20
 * @LastEditTime: 2022-04-20 19:58:09
 */

/**
 * Template name: Zibll-链接列表
 * Description:   sidebar page
 */

// 获取链接列表
function zib_page_links()
{
    $type          = 'card';
    $post_ID       = get_queried_object_id();
    $args_orderby  = get_post_meta($post_ID, 'page_links_orderby', true);
    $args_order    = get_post_meta($post_ID, 'page_links_order', true);
    $args_limit    = get_post_meta($post_ID, 'page_links_limit', true);
    $args_category = get_post_meta($post_ID, 'page_links_category', true);
    $args          = array(
        'orderby'  => $args_orderby ? $args_orderby : 'name', //排序方式
        'order'    => $args_order ? $args_order : 'ASC', //升序还是降序
        'limit'    => $args_limit ? $args_limit : -1, //最多显示数量
        'category' => $args_category, //以逗号分隔的类别ID列表
    );
    $links = get_bookmarks($args);

    $html = '';

    if ($links) {
        $html .= zib_links_box($links, $type, false);
    } elseif (is_super_admin()) {
        $html = '<a class="author-minicard links-card radius8" href="' . admin_url('link-manager.php') . '" target="_blank">添加链接</a>';
    } else {
        $html = '<div class="author-minicard links-card radius8">暂无链接</div>';
    }
    return $html;
}

get_header();
$post_id                     = get_queried_object_id();
$header_style                = zib_get_page_header_style();
$page_links_content_s        = get_post_meta($post_id, 'page_links_content_s', true);
$page_links_content_position = get_post_meta($post_id, 'page_links_content_position', true);
$page_links_submit_s         = get_post_meta($post_id, 'page_links_submit_s', true);

?>
<main class="container">
    <div class="content-wrap">
        <div class="content-layout">
            <?php while (have_posts()) : the_post(); ?>
                <?php echo zib_get_page_header(); ?>
                <?php
                if ($page_links_content_position != 'top') {
                    echo '<div class="zib-widget">' . zib_page_links() . '</div>';
                }
                if ($page_links_content_s) {
                    echo '<div class="zib-widget"><article class="article wp-posts-content">';
                    the_content();
                    echo '</article>';
                    wp_link_pages(
                        array(
                            'before' => '<p class="text-center post-nav-links radius8 padding-6">',
                            'after'  => '</p>',
                        )
                    );
                    echo '</div>';
                }
                if ($page_links_content_position == 'top') {
                    echo '<div class="zib-widget">' . zib_page_links() . '</div>';
                }
                if ($page_links_submit_s) {
                    $submit_args = array(
                        'title'    => get_post_meta($post_id, 'page_links_submit_title', true),
                        'subtitle' => get_post_meta($post_id, 'page_links_submit_subtitle', true),
                        'dec'      => get_post_meta($post_id, 'page_links_submit_dec', true),
                    );
                    echo zib_submit_links_card($submit_args);
                }
                ?>
                <?php ?>
            <?php endwhile; ?>
            <?php comments_template('/template/comments.php', true); ?>
        </div>
    </div>
     <script>
 function sub(){
       var obj = <?php echo json_encode((array('error' => 1, 'ys' => 'danger', 'msg' => '请填写链接名称'))); ?>;
     var url= $("#link_url").val();
     if (url == "") {
 return notyf('网址不能为空', 'warning'), !1;
        return false;
    }
            $.ajax({
                type: "GET",
                dataType: "json",
                url : "/link.php?url="+url,
                success: function (data) {
                    if(data.code == 1){
                        
                        $("#link_name").val(data.title);
                        $("#link_description").val(data["description"])
                        $("#link_image").val(data.url);
                        $("#link_yes").val(data.msg);
                         return notyf(data.msg, '');
                    } else {
                        $("#link_name").attr("disabled","disabled");
                        $("#link_description").attr("disabled","disabled");
                        $("#link_image").attr("disabled","disabled");
                        //  document.getElementById("link_deta").innerHTML=data.msg;
                         return notyf(data.msg, 'danger');
                } 
           }
       });
}
</script>
    <?php get_sidebar(); ?>
</main>
<?php
get_footer();

4.在你站点根目录下(比如www.sakura.vin的目录下),创建一个link.php文件(不是 links哦)填入代码

<?php
/**
 * 网站TDK信息查询
 */
/**
友情链接检测
**/
$max_allow_links = 1; // 最大许可检查的链接数目
function my_file_get_contents($url, $timeout = 30) {
    if (function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $file_contents = curl_exec($ch);
        curl_close($ch);
    } else if (ini_get('allow_url_fopen') == 1 || strtolower(ini_get('allow_url_fopen')) == 'on') {
        $file_contents = @file_get_contents($url);
    } else {
        $file_contents = '';
    }
    return $file_contents;
}
function isExistsContentUrl($url, &$retMsg, $mydomain = "") {
    if (!isset($url) || empty($url)) {
        $retMsg = "填写的URL为空";
        return false;
    }
    if (!isset($mydomain) || empty($mydomain)) {
        $mydomain = $_SERVER['SERVER_NAME'];
    }
    $resultContent = my_file_get_contents($url);
    if (trim($resultContent) == '') {
        $retMsg = "未获得URL相关数据,请重试!";
        return false;
    }
    if (strripos($resultContent, $mydomain)) {
        $retMsg = "检测已经通过";
        return true;
    } else {
        $retMsg = "请先添加本站域名到你的站点!";
        return false;
    }
}
$yu  =  $_SERVER['HTTP_HOST'];/*获取当前域名*/
$url = $_GET['url'];/*获取请求域名*/
$url1 =  preg_replace('#^(http(s?))?(://)#','', $url);/*处理域名HTTPS http*/
$data=curl("https://www.aizhan.com/cha/".$url1);
preg_match('/<span id=\"webpage_tdk_title\">(.*?)<\/span>/',$data,$title);//标题
preg_match('/<span id=\"webpage_tdk_keywords\">(.*?)<\/span>/',$data,$keywords);//关键词
preg_match('/<span id=\"webpage_tdk_description\">(.*?)<\/span>/',$data,$description);//描述
//不懂得大傻子别瞎几吧修改
$result = "";
$ret = isExistsContentUrl("$url", $result, "$yu");
if ($ret) {
    echo json_encode(array('code' => 1,'msg'  => '获取成功','url' => 'https://api.qqsuu.cn/api/favicon/get.php?url='.$url,'title' => $title[1],'keywords' => $keywords[1],'description' => $description[1]),320);   ;
} else {
    echo json_encode(array('code' => 0,'msg'  => $result,'url' => $result,'title' => $result,'keywords' => $result,'description' => $result),320);   ;
}
function curl($url){ //Curl GET
    $ch = curl_init();     // Curl 初始化  
    $timeout = 30;     // 超时时间:30s  
    $ua='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36';// 伪造抓取 UA  
    $ip = mt_rand(11, 191) . "." . mt_rand(0, 240) . "." . mt_rand(1, 240) . "." . mt_rand(1, 240);
    curl_setopt($ch, CURLOPT_URL, $url);// 设置 Curl 目标  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// Curl 请求有返回的值  
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);// 设置抓取超时时间  
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// 跟踪重定向  
    curl_setopt($ch, CURLOPT_REFERER, 'http://www.baidu.com/');//模拟来路
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip));  //伪造IP  
    curl_setopt($ch, CURLOPT_USERAGENT, $ua);// 伪造ua   
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// https请求 不验证证书和hosts  
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);//强制协议为1.0
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );//强制使用IPV4协议解析域名
    $content = curl_exec($ch);   
    curl_close($ch);// 结束 Curl  
    return $content;// 函数返回内容  
}
如果对你有用的话就支持一下叭·Thanks♪(・ω・)ノ
© 版权声明
THE END
喜欢就点赞转发支持一下吧(*╹▽╹*)~
点赞12 分享
评论 抢沙发
头像
你不说我怎么知道你在想什么诶
提交
头像

昵称

取消
昵称表情

    暂无评论内容