Typecho的Joe主题实现侧边栏互动读者-展示活跃用户

Typecho的Joe主题实现侧边栏互动读者-展示活跃用户

ZJ
ZJ
2022-09-15 / 0 评论 / 39 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年09月15日,已超过589天没有更新,若内容或图片失效,请留言反馈。
1.修改aside.php文件,新增如下代码,文件路径:usr/themes/Joe/public
<!--互动读者-->
<?php if ($this->options->JactiveUsers === 'on') : ?>
    <section class="aside aside-hunter-authors">
        <div class="joe_aside__item-title">
            <svg t="1622460301541" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2712" width="200" height="200"><path d="M896 128H128a32 32 0 0 0-32 32v576a32 32 0 0 0 32 32h288v-64H160V192h704v512h-256c-8.832 0-16.832 3.584-22.656 9.376l-159.968 160 45.248 45.248L621.248 768H896a32 32 0 0 0 32-32V160a32 32 0 0 0-32-32" fill="#181818" p-id="2713"></path><path d="M560 448a48 48 0 1 0-95.968-0.032A48 48 0 0 0 560 448M240 448a48 48 0 1 0 95.968 0.032A48 48 0 0 0 240 448M784 448a48 48 0 1 0-95.968-0.032A48 48 0 0 0 784 448" fill="#181818" p-id="2714"></path></svg>
            <span class="text">互动读者</span>
            <span class="line"></span>
        </div>
        <div class="hunter-cont">
            <ul class="hunter-authors">
                    <?php
                        $period = time() - 2592000; // 单位: 秒, 时间范围: 30天
                        $counts = Typecho_Db::get()->fetchAll(Typecho_Db::get()
                            ->select('COUNT(author) AS cnt', 'author', 'max(url) url', 'max(authorId) authorId', 'max(mail) mail')
                            ->from('table.comments')
                            ->where('created > ?', $period)
                            ->where('status = ?', 'approved')
                            ->where('type = ?', 'comment')
                            ->group('author')
                            ->order('cnt', Typecho_Db::SORT_DESC)
                            ->limit('4')
                        );
                        foreach ($counts as $count) {
                            $c_url = '<li><div class="item"><div class="hunter-avatar"><div class="vatar"><img src="' . _getAvatarUrlByMail($count['mail']) . '"></div></div><div class="item-main"><div><a target="_blank" href='. $count['url'] . '>' . $count['author'] . '</a>';
                            echo '' . $c_url . '';
                            autvip($count['mail']);
                            $allpostnum = allpostnum($count['authorId']);
                            echo ' <h4>评论 ' . $count['cnt'] . ' 次 | <i>'.$allpostnum.'</i>';
                            echo ' </h4></div></div></li>';
                        }
                    ?>
                
            </ul>
        </div>
    </section>
<?php endif; ?>

Test

2.修改core.php文件,底部新增,文件路径:usr/themes/Joe/core
/**
 * 显示用户等级,按邮箱
 */
function autvip($i){
    $db=Typecho_Db::get();
    $mail=$db->fetchAll($db->select(array('COUNT(cid)'=>'rbq'))->from('table.comments')->where('mail = ?', $i)/**->where('authorId = ?','0')**/);
    foreach ($mail as $sl){
        $rbq=$sl['rbq'];}
    if($rbq<1){
        echo '<span class="autlv aut-0">Lv.0</span>';
    }elseif ($rbq<10 && $rbq>0) {
        echo '<span class="autlv aut-1">Lv.1</span>';
    }elseif ($rbq<20 && $rbq>=10) {
        echo '<span class="autlv aut-2">Lv.2</span>';
    }elseif ($rbq<40 && $rbq>=20) {
        echo '<span class="autlv aut-3">Lv.3</span>';
    }elseif ($rbq<80 && $rbq>=40) {
        echo '<span class="autlv aut-4">Lv.4</span>';
    }elseif ($rbq<100 && $rbq>=80) {
        echo '<span class="autlv aut-5">Lv.5</span>';
    }elseif ($rbq>=100) {
        echo '<span class="autlv aut-6">Lv.6</span>';
    }
}

/**
*输出作者文章总数,可以指定
*/
function allpostnum($id){
    $db = Typecho_Db::get();
    $postnum=$db->fetchRow($db->select(array('COUNT(authorId)'=>'allpostnum'))->from ('table.contents')->where ('table.contents.authorId=?',$id)->where('table.contents.type=?', 'post'));
    $postnum = $postnum['allpostnum'];
    if($postnum=='0')
    {
        return '暂无文章';
    }
    else{
        return '文章 '.$postnum.' 篇';
    }
}

/* 通过邮箱生成头像地址 */
function _getAvatarUrlByMail($mail)
{
    $gravatarsUrl = Helper::options()->JCustomAvatarSource ? Helper::options()->JCustomAvatarSource : 'https://gravatar.ihuan.me/avatar/';
    $mailLower = strtolower($mail);
    $md5MailLower = md5($mailLower);
    $qqMail = str_replace('@qq.com', '', $mailLower);
    if (strstr($mailLower, "qq.com") && is_numeric($qqMail) && strlen($qqMail) < 11 && strlen($qqMail) > 4) {
        return 'https://thirdqq.qlogo.cn/g?b=qq&nk=' . $qqMail . '&s=100';
    } else {
        return $gravatarsUrl . $md5MailLower . '?d=mm';
    }
}

Test

3.修改include.php文件,底部新增,代码路径:usr/themes/Joe/public
<?php if ($this->options->JactiveUsers === 'on') : ?>
    <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/custom.css'); ?>">
<?php endif; ?>

Test

4.新增custom.css文件,文件路径:usr/themes/Joe/assets/css
.autlv {
  font-size: 10px;
  color: #fff;
  display: inline-block;
  vertical-align: text-top;
  font-weight: normal;
  border-radius: 2px;
  line-height: 1.4;
  padding: 0 4px;
  margin-left: 5px;
  letter-spacing: 0px;
}

.aut-0 {
  background: #d1d5dc;
}

.aut-1 {
  background: #448EF6;
}

.aut-2 {
  background: #f6b044;
}

.aut-3 {
  background: #c444f6;
}

.aut-4 {
  background: #f69644;
}

.aut-5 {
  background-image: -webkit-linear-gradient(0deg, #3ca5f6 0%, #a86af9 100%);
}

.aut-6 {
  background: #f64444;
}

.aside-hunter-authors {
  background: var(--background);
  margin-bottom: 15px;
}
.aside-hunter-authors .vs {
  border-radius: 100%;
}
.aside-hunter-authors ul {
  padding: 14px;
  list-style: none;
  line-height: 2.5;
}
.aside-hunter-authors .item {
  border-bottom: 1px dashed #eee;
  margin-bottom: 0px;
  position: relative;
  padding-bottom: 4px;
}
.aside-hunter-authors .item .hunter-avatar {
  float: left;
  line-height: 55px;
}
.aside-hunter-authors .item .hunter-avatar .vatar {
  position: relative;
}
.aside-hunter-authors .item .hunter-avatar .vatar img {
  width: 45px;
  border-radius: 100%;
}
.aside-hunter-authors .item .hunter-avatar .vatar .va_v_honor {
  position: absolute;
  bottom: 3px;
  right: 0px;
  width: 18px;
  height: 18px;
}
.aside-hunter-authors .item .item-main {
  min-height: 60px;
  margin-left: 60px;
  color: #393939;
}
.aside-hunter-authors .item .item-main h4 {
  font-size: 12px;
  line-height: 1;
  margin-bottom: 7px;
  font-weight: normal;
  color: #999;
}
.aside-hunter-authors .item .item-main h4 i {
  font-style: normal;
  color: #aaa;
  margin: 0 5px;
}

Test

5.修改functions.php文件,底部新增,文件路径:usr/themes/Joe
// 互动读者
$JactiveUsers = new Typecho_Widget_Helper_Form_Element_Select(
    'JactiveUsers',
    array('off' => '关闭(默认)', 'on' => '开启'),
    'off',
    '是否开启互动读者',
    '介绍:显示评论相关用户'
);
$JactiveUsers->setAttribute('class', 'joe_content joe_custom'); // 如果后台无法展示该设置,将joe_custom修改为joe_other
$form->addInput($JactiveUsers);

Test

本文共 158 个字数,平均阅读时长 ≈ 1分钟
0

评论 (0)

取消