本文记录对各种插件 handsome 主题做的魔改

user-agent

松鼠大大 开发的一款插件,这里搬运一下防止源失效。

修改 Handsome 主题,component 目录下的 comments.php 代码文件,

<span class="comment-author vcard">
    <b class="fn"><?php echo $author; ?></b>
    <?php if (!($GLOBALS["off_star_comment"] == "true" || Utils::getExpertValue("off_star_comment"))):?>
    <a data-coid="<?php echo $comments->coid; ?>" class="post-comment-star text-muted star_talk"><i class="glyphicon <?php
        $stars = Typecho_Cookie::get('extend_say_stars');
        if (empty($stars)) {
            $stars = array();
        } else {
            $stars = explode(',', $stars);
        }

        if (!in_array($comments->coid, $stars)) {
            echo 'glyphicon-heart-empty';
        } else {
            echo 'glyphicon-heart';
        }
        ?>"></i>&nbsp;<span class="star_count"><?php
            $stars = $comments->stars;
            echo ($stars) ? $stars : "";
            ?></span></a>
    <?php endif; ?>
</span>

添加代码<?php UserAgent_Plugin::get_useragent($comments->agent,$comments->ip); ?>,修改后代码如下:

<span class="comment-author vcard">
    <b class="fn"><?php echo $author; ?></b>
    <?php if (!($GLOBALS["off_star_comment"] == "true" || Utils::getExpertValue("off_star_comment"))):?>
    <a data-coid="<?php echo $comments->coid; ?>" class="post-comment-star text-muted star_talk"><i class="glyphicon <?php
        $stars = Typecho_Cookie::get('extend_say_stars');
        if (empty($stars)) {
            $stars = array();
        } else {
            $stars = explode(',', $stars);
        }

        if (!in_array($comments->coid, $stars)) {
            echo 'glyphicon-heart-empty';
        } else {
            echo 'glyphicon-heart';
        }
        ?>"></i>&nbsp;<span class="star_count"><?php
            $stars = $comments->stars;
            echo ($stars) ? $stars : "";
            ?></span></a>
    <?php endif; ?>
    <?php UserAgent_Plugin::get_useragent($comments->agent,$comments->ip); ?>
</span>

随机头图

修改 Handsome 主题,libs 目录下的 Content.php 代码文件,

/**
     * 处理具体的头图显示逻辑:当有头图时候,显示随机图片还是第一个附件还是一张图片还是thumb字段
     * @param $widget $this变量
     * @param int $index
     * @param $howToThumb 显示缩略图的方式,0,1,2,3
     * @param $thumbField thumb字段
     * @return string
     */
    public static function whenSwitchHeaderImgSrc($widget, $index, $howToThumb, $thumbField,$extra_content= "")
    {

        if ($howToThumb == '4'){//该种方式解析速度最快
            if (!empty($thumbField)) {
                return $thumbField;
            } else {
                return "";
            }
        }
        $randomNum = unserialize(INDEX_IMAGE_ARRAY);

        // 随机缩略图路径
        $random = STATIC_PATH . 'img/sj/' . @$randomNum[$index] . '.jpg';//如果有文章置顶,这里可能会导致index not undefined
        $pattern = '/\<img.*?src\=\"(.*?)\"[^>]*>/i';
        $patternMD = '/\!\[.*?\]\((http(s)?:\/\/.*?(jpg|png|JPEG|webp|jpeg|bmp|gif))/i';
        $patternMDfoot = '/\[.*?\]:\s*(http(s)?:\/\/.*?(jpg|png|JPEG|webp|jpeg|bmp|gif))/i';

        if ($howToThumb == '0') {
            return $random;
        } elseif ($howToThumb == '1' || $howToThumb == '2') {

            if (!empty($thumbField)) {
                return $thumbField;
            }

            //解析附件
            if ($widget!=null){
                $attach = @$widget->attachments(1)->attachment;
                if ($attach != null && isset($attach->isImage) && $attach->isImage == 1) {
                    return $attach->url;
                }
            }

            if ($widget != null){
                //解析文章内容,这个是最慢的
                $content = $widget->content;
            }else{
                $content = $extra_content;
            }


            if (preg_match_all($pattern, $content, $thumbUrl)) {
                $thumb = $thumbUrl[1][0];
            } elseif (preg_match_all($patternMD, $content, $thumbUrl)) {
                $thumb = $thumbUrl[1][0];
            } elseif (preg_match_all($patternMDfoot, $content, $thumbUrl)) {
                $thumb = $thumbUrl[1][0];
            } else {//文章中没有图片
                if ($howToThumb == '1') {
                    return '';
                } else {
                    return $random;
                }
            }
            return $thumb;

        } elseif ($howToThumb == '3') {
            if (!empty($thumbField)) {
                return $thumbField;
            } else {
                // return $random;
                return "https://www.dmoe.cc/random.php?".rand();
            }
        }else{
            return "";
        }
    }
最后修改:2022 年 04 月 16 日
如果觉得我的文章对你有用,请随意赞赏