Typecho实现评论显示操作系统和评论来源

    1,050

首先打开 functions.php 文件,粘贴下面的代码

【pigeon主题可以放在14-15行】

// 获取浏览器信息
function getBrowser($agent)
{
    if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) {
        $outputer = 'Internet Explore';
    } else if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) {
      $str1 = explode('Firefox/', $regs[0]);
$FireFox_vern = explode('.', $str1[1]);
        $outputer = 'FireFox';
    } else if (preg_match('/Maxthon([\d]*)\/([^\s]+)/i', $agent, $regs)) {
      $str1 = explode('Maxthon/', $agent);
$Maxthon_vern = explode('.', $str1[1]);
        $outputer = 'MicroSoft Edge';
    } else if (preg_match('#360([a-zA-Z0-9.]+)#i', $agent, $regs)) {
$outputer = '360 Fast Browser';
    } else if (preg_match('/Edge([\d]*)\/([^\s]+)/i', $agent, $regs)) {
        $str1 = explode('Edge/', $regs[0]);
$Edge_vern = explode('.', $str1[1]);
        $outputer = 'MicroSoft Edge';
    } else if (preg_match('/UC/i', $agent)) {
        $str1 = explode('rowser/',  $agent);
$UCBrowser_vern = explode('.', $str1[1]);
        $outputer = 'UC Browser';
    }  else if (preg_match('/QQ/i', $agent, $regs)||preg_match('/QQ Browser\/([^\s]+)/i', $agent, $regs)) {
        $str1 = explode('rowser/',  $agent);
$QQ_vern = explode('.', $str1[1]);
        $outputer = 'QQ Browser';
    } else if (preg_match('/UBrowser/i', $agent, $regs)) {
        $str1 = explode('rowser/',  $agent);
$UCBrowser_vern = explode('.', $str1[1]);
        $outputer = 'UC Browser';
    }  else if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) {
        $outputer = 'Opera';
    } else if (preg_match('/Chrome([\d]*)\/([^\s]+)/i', $agent, $regs)) {
$str1 = explode('Chrome/', $agent);
$chrome_vern = explode('.', $str1[1]);
        $outputer = 'Google Chrome';
    } else if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) {
        $str1 = explode('Version/',  $agent);
$safari_vern = explode('.', $str1[1]);
        $outputer = 'Safari';
    } else{
        $outputer = 'Google Chrome';
    }
    echo $outputer;
}
// 获取操作系统信息
function getOs($agent)
{
    $os = false;
    if (preg_match('/win/i', $agent)) {
        if (preg_match('/nt 6.0/i', $agent)) {
            $os = 'Windows Vista · ';
        } else if (preg_match('/nt 6.1/i', $agent)) {
            $os = 'Windows 7 · ';
        } else if (preg_match('/nt 6.2/i', $agent)) {
            $os = 'Windows 8 · ';
        } else if(preg_match('/nt 6.3/i', $agent)) {
            $os = 'Windows 8.1 · ';
        } else if(preg_match('/nt 5.1/i', $agent)) {
            $os = 'Windows XP · ';
        } else if (preg_match('/nt 10.0/i', $agent)) {
            $os = 'Windows 10 · ';
        } else{
            $os = 'Windows X64 · ';
        }
    } else if (preg_match('/android/i', $agent)) {
    if (preg_match('/android 9/i', $agent)) {
                $os = 'Android Pie · ';
        }
    else if (preg_match('/android 8/i', $agent)) {
            $os = 'Android Oreo · ';
        }
    else{
            $os = 'Android · ';
    }
    }
    else if (preg_match('/ubuntu/i', $agent)) {
        $os = 'Ubuntu · ';
    } else if (preg_match('/linux/i', $agent)) {
        $os = 'Linux · ';
    } else if (preg_match('/iPhone/i', $agent)) {
        $os = 'iPhone · ';
    } else if (preg_match('/mac/i', $agent)) {
        $os = 'MacOS · ';
    }else if (preg_match('/fusion/i', $agent)) {
        $os = 'Android · ';
    } else {
        $os = 'Linux · ';
    }
    echo $os;
}

comments.php 中找到合适位置(比如评论作者的后面)添加以下代码

【pigeon主题可以放在39行,也可以用我的模板,直接替换39行】
模板

[hide]

//pigeon主题
<div class="comment_author"><?php echo $author ?><i class="text-primary">•</i><?php getOs($comments->agent); ?><?php getBrowser($comments->agent); ?><?php

[/hide]

其他主题↓

<?php getOs($comments->agent); ?><?php getBrowser($comments->agent); ?>

[tabs]
[tab-pane label="转载信息"]
本文内容为转载
原文:https://blog.sdgou.cc/archives/80.html
作者:三道勾
[/tab-pane]
[/tabs]

Comments | 10 条评论
  • 哈哈哈

    这是效果

  • 申奥

    看看效果

  • 漫川

    拿走代码了

  • 乐豪源站

    牛逼牛逼

  • 乐豪

    11111

  • GG

    哈哈哈哈:&(蛆音娘_摊手)

  • 小稚

    瞅瞅

  • 小王

    看一看

  • 茜茜

    代码拿走了

  • 菜鸟博客

    看看看看看看看

消息盒子
# 您需要首次评论以获取消息 #
# 您需要首次评论以获取消息 #

只显示最新10条未读和已读信息