]*>/i';
$patternMD = '/\!\[.*?\]\((http(s)?:\/\/.*?(jpg|jpeg|gif|png|webp))/i';
$patternMDfoot = '/\[.*?\]:\s*(http(s)?:\/\/.*?(jpg|jpeg|gif|png|webp))/i';
if ($item->fields->thumb) {
$randomThumb = $item->fields->thumb;
} elseif (preg_match_all($pattern, $item->content, $thumbUrl)) {
$randomThumb = $thumbUrl[1][0];
} elseif (preg_match_all($patternMD, $item->content, $thumbUrl)) {
$randomThumb = $thumbUrl[1][0];
} elseif (preg_match_all($patternMDfoot, $item->content, $thumbUrl)) {
$randomThumb = $thumbUrl[1][0];
}
if ($type) echo $randomThumb;
else return $randomThumb;
}
function _getViews($item, $type = true)
{
$db = Typecho_Db::get();
$result = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $item->cid))['views'];
if ($type) echo number_format($result);
else return number_format($result);
}
function _getAgree($item, $type = true)
{
$db = Typecho_Db::get();
$result = $db->fetchRow($db->select('agree')->from('table.contents')->where('cid = ?', $item->cid))['agree'];
if ($type) echo number_format($result);
else return number_format($result);
}
function _parseAsideLink($link)
{
echo str_replace("#", "?scroll=", $link);
}
function _getAgentOS($agent)
{
$os = "Linux";
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;
}
function _getAgentBrowser($agent)
{
if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) {
$outputer = 'Internet Explore';
} else if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) {
$outputer = 'FireFox';
} else if (preg_match('/Maxthon([\d]*)\/([^\s]+)/i', $agent, $regs)) {
$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)) {
$outputer = 'MicroSoft Edge';
} else if (preg_match('/UC/i', $agent)) {
$outputer = 'UC Browser';
} else if (preg_match('/QQ/i', $agent, $regs) || preg_match('/QQ Browser\/([^\s]+)/i', $agent, $regs)) {
$outputer = 'QQ Browser';
} else if (preg_match('/UBrowser/i', $agent, $regs)) {
$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)) {
$outputer = 'Google Chrome';
} else if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) {
$outputer = 'Safari';
} else {
$outputer = 'Google Chrome';
}
echo $outputer;
}
function _parseAsideReply($text, $type = true)
{
if ($type) echo _parseReply(preg_replace('~{!{.*~', '# 图片回复', strip_tags($text)));
else echo preg_replace('~{!{.*~', '# 图片回复', strip_tags($text));
}
function _parseReply($text)
{
$text = preg_replace_callback(
'/\:\:\(\s*(呵呵|哈哈|吐舌|太开心|笑眼|花心|小乖|乖|捂嘴笑|滑稽|你懂的|不高兴|怒|汗|黑线|泪|真棒|喷|惊哭|阴险|鄙视|酷|啊|狂汗|what|疑问|酸爽|呀咩爹|委屈|惊讶|睡觉|笑尿|挖鼻|吐|犀利|小红脸|懒得理|勉强|爱心|心碎|玫瑰|礼物|彩虹|太阳|星星月亮|钱币|茶杯|蛋糕|大拇指|胜利|haha|OK|沙发|手纸|香蕉|便便|药丸|红领巾|蜡烛|音乐|灯泡|开心|钱|咦|呼|冷|生气|弱|吐血)\s*\)/is',
function ($match) {
return '';
},
$text
);
$text = preg_replace_callback(
'/\:\@\(\s*(高兴|小怒|脸红|内伤|装大款|赞一个|害羞|汗|吐血倒地|深思|不高兴|无语|亲亲|口水|尴尬|中指|想一想|哭泣|便便|献花|皱眉|傻笑|狂汗|吐|喷水|看不见|鼓掌|阴暗|长草|献黄瓜|邪恶|期待|得意|吐舌|喷血|无所谓|观察|暗地观察|肿包|中枪|大囧|呲牙|抠鼻|不说话|咽气|欢呼|锁眉|蜡烛|坐等|击掌|惊喜|喜极而泣|抽烟|不出所料|愤怒|无奈|黑线|投降|看热闹|扇耳光|小眼睛|中刀)\s*\)/is',
function ($match) {
return '';
},
$text
);
return $text;
}
function _getParentReply($parent)
{
if ($parent !== "0") {
$db = Typecho_Db::get();
$commentInfo = $db->fetchRow($db->select('author')->from('table.comments')->where('coid = ?', $parent));
echo '@ ' . $commentInfo['author'] . '
';
}
}
function _parseCommentReply($text)
{
$text = _parseReply($text);
$text = preg_replace('/\{!{(.*?)\}!}/', '', $text);
echo $text;
}
function _getLazyload($type = true)
{
if ($type) echo Helper::options()->JLazyload;
else return Helper::options()->JLazyload;
}
function _getAvatarLazyload($type = true)
{
if ($type) echo "https://cdn.jsdelivr.net/gh/HaoOuBa/Joe@master/assets/img/lazyload_avatar.png";
else return "https://cdn.jsdelivr.net/gh/HaoOuBa/Joe@master/assets/img/lazyload_avatar.png";
}
function _getAsideAuthorNav()
{
if (Helper::options()->JAside_Author_Nav !== "off") {
$db = Typecho_Db::get();
$adapterName = $db->getAdapterName();
if ($adapterName == 'pgsql' || $adapterName == 'Pdo_Pgsql' || $adapterName == 'Pdo_SQLite' || $adapterName == 'SQLite') {
$order_by = 'RANDOM()';
} else {
$order_by = 'RAND()';
}
$result = $db->fetchAll(
$db->select()
->from('table.contents')
->where('table.contents.status = ?', 'publish')
->where('table.contents.type = ?', 'post')
->where("table.contents.password IS NULL OR table.contents.password = ''")
->limit(Helper::options()->JAside_Author_Nav)
->order($order_by)
);
foreach ($result as $item) {
$obj = Typecho_Widget::widget('Widget_Abstract_Contents');
$item = $obj->push($item);
$title = htmlspecialchars($item['title']);
$permalink = $item['permalink'];
echo "
{$title}
";
}
}
}
function themeFields($layout)
{
$aside = new Typecho_Widget_Helper_Form_Element_Radio(
'aside',
array(
'on' => '开启',
'off' => '关闭'
),
'on',
'是否开启当前页面的侧边栏',
'介绍:用于单独设置当前页侧边栏的开启状态
注意:只有在外观设置侧边栏开启状态下生效'
);
$layout->addItem($aside);
$thumb = new Typecho_Widget_Helper_Form_Element_Textarea(
'thumb',
NULL,
NULL,
'自定义文章缩略图',
'填写时:将会显示填写的文章缩略图
不填写时:
1、若文章有图片则取文章内图片
2、若文章无图片,并且外观设置里未填写·自定义缩略图·选项,则取模板自带图片
3、若文章无图片,并且外观设置里填写了·自定义缩略图·选项,则取自定义缩略图图片'
);
$layout->addItem($thumb);
$abstract = new Typecho_Widget_Helper_Form_Element_Textarea(
'abstract',
NULL,
NULL,
'自定义文章摘要',
'填写时:将会显示填写的摘要
不填写时:默认取文章里的内容'
);
$layout->addItem($abstract);
}
class Widget_Contents_Hot extends Widget_Abstract_Contents
{
public function execute()
{
$this->parameter->setDefault(array('pageSize' => 10));
$this->db->fetchAll(
$this->select()->from('table.contents')
->where("table.contents.password IS NULL OR table.contents.password = ''")
->where('table.contents.status = ?', 'publish')
->where('table.contents.created <= ?', time())
->where('table.contents.type = ?', 'post')
->limit($this->parameter->pageSize)
->order('table.contents.views', Typecho_Db::SORT_DESC),
array($this, 'push')
);
}
}
class Widget_Contents_Sort extends Widget_Abstract_Contents
{
public function execute()
{
$this->parameter->setDefault(array('page' => 1, 'pageSize' => 10, 'type' => 'created'));
$offset = $this->parameter->pageSize * ($this->parameter->page - 1);
$this->db->fetchAll(
$this->select()
->from('table.contents')
->where('table.contents.type = ?', 'post')
->where('table.contents.status = ?', 'publish')
->limit($this->parameter->pageSize)
->offset($offset)
->order($this->parameter->type, Typecho_Db::SORT_DESC),
array($this, 'push')
);
}
}