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.gif"; else return "https://cdn.jsdelivr.net/gh/HaoOuBa/Joe@master/assets/img/lazyload_avatar.gif"; } /* 查询文章浏览量 */ 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 _startCountTime() { global $timeStart; $mTime = explode(' ', microtime()); $timeStart = $mTime[1] + $mTime[0]; return true; } /* 页面结束计时 */ function _endCountTime($precision = 3) { global $timeStart, $timeEnd; $mTime = explode(' ', microtime()); $timeEnd = $mTime[1] + $mTime[0]; $timeTotal = number_format($timeEnd - $timeStart, $precision); echo $timeTotal < 1 ? $timeTotal * 1000 . 'ms' : $timeTotal . 's'; } /* 通过邮箱生成头像地址 */ function _getAvatarByMail($mail) { $gravatarsUrl = 'https://gravatar.helingqi.com/wavatar/'; $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) { echo 'https://thirdqq.qlogo.cn/g?b=qq&nk=' . $qqMail . '&s=100'; } else { echo $gravatarsUrl . $md5MailLower . '?d=mm'; } }; /* 获取侧边栏随机一言 */ function _getAsideAuthorMotto() { $JMottoRandom = explode("\r\n", Helper::options()->JAside_Author_Motto); echo $JMottoRandom[array_rand($JMottoRandom, 1)]; } /* 获取文章摘要 */ function _getAbstract($item, $type = true) { $abstract = ""; if ($item->password) { $abstract = "加密文章,请前往内页查看详情"; } else { if ($item->fields->abstract) { $abstract = $item->fields->abstract; } else { $abstract = strip_tags($item->excerpt); } } if ($type) echo $abstract; else return $abstract; } /* 获取文章缩略图 */ function _getThumbnail($item, $type = true) { $randomThumb = '/usr/themes/joe/assets/thumb/' . rand(1, 14) . '.png'; $custom_thumbnail = Helper::options()->JThumbnail; if ($custom_thumbnail) { $custom_thumbnail_arr = explode("\r\n", $custom_thumbnail); $randomThumb = $custom_thumbnail_arr[array_rand($custom_thumbnail_arr, 1)] . "?key=" . mt_rand(0, 1000000); } $pattern = '/\]*>/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 _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 _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}
  • "; } } }