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); ?>"
]]>修改文件路径:
/var/Typecho/Common.php
修改937行内容-图片教程:
修改为:
修改937行内容-文字教程:
$url = $isSecure ? 'https://secure.gravatar.com' : 'http://www.gravatar.com';
修改为:
$url = $isSecure ? 'https://gravatar.dubook.cc' : 'https://gravatar.dubook.cc';
]]>