AFF窝 - typecho 2020-08-23T18:58:00+08:00 Typecho https://www.affwo.com/feed/atom/tag/typecho/ <![CDATA[Typecho获取文章缩略图]]> https://www.affwo.com/230.html 2020-08-23T18:58:00+08:00 2020-08-23T18:58:00+08:00 admin https://www.affwo.com 主题functions.php添加以下代码

    function img_postthumb($thumbThis) {
    $db = Typecho_Db::get();
    $rs = $db->fetchRow($db->select('table.contents.text')
        ->from('table.contents')
        ->where('table.contents.cid=?', $thumbThis->cid)
        ->order('table.contents.cid', Typecho_Db::SORT_ASC)
        ->limit(1));
    preg_match_all('/\<img.*?src\="(.*?)"[^>]*>/i', $rs['text'], $thumbUrl);  //通过正则式获取图片地址
    preg_match_all('/\!\[.*?\]\((http(s)?:\/\/.*?(jpg|png))/i', $rs['text'], $patternMD);  //通过正则式获取图片地址
    preg_match_all('/\[.*?\]:\s*(http(s)?:\/\/.*?(jpg|png))/i', $rs['text'], $patternMDfoot);  //通过正则式获取图片地址
    if(count($thumbUrl[0])>0){
        return $thumbUrl[1][0];  //当找到一个src地址的时候,输出缩略图
    }else if(count($patternMD[0])>0){
        return $patternMD[1][0];
    }else if(count($patternMDfoot[0])>0){
        return $patternMDfoot[1][0];
    }else{
        //在主题根目录下的 /img 目录下放随机图片 thumb_开头
        //如:thumb_1.jpg
        return $thumbThis->widget('Widget_Options')->themeUrl."/img/thumb_".rand(1,5).".jpg";
    }
}

index.php等文件里调用方式

<img src="<?php echo img_postthumb($this); ?>"
]]>
<![CDATA[修改Typecho程序中Gravatar生成的默认头像,提供Gravatar高速镜像]]> https://www.affwo.com/226.html 2020-08-18T14:34:00+08:00 2020-08-18T14:34:00+08:00 admin https://www.affwo.com 由于默认头像要链接到国外的网站,速度很慢,这边提供我们自己的镜像供大家使用:
镜像地址:https://gravatar.dubook.cc

修改文件路径:

/var/Typecho/Common.php

修改937行内容-图片教程:
1.jpg
修改为:
2.jpg

修改937行内容-文字教程:

$url = $isSecure ? 'https://secure.gravatar.com' : 'http://www.gravatar.com';

修改为:

$url = $isSecure ? 'https://gravatar.dubook.cc' : 'https://gravatar.dubook.cc';
]]>