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 ($abstract === '') $abstract = "暂无简介"; if ($type) echo $abstract; else return $abstract; } /* 获取列表缩略图 */ function _getThumbnails($item) { $result = []; $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) { $fields_thumb_arr = explode("\r\n", $item->fields->thumb); foreach ($fields_thumb_arr as $list) $result[] = $list; } /* 如果匹配到正则,则继续补充匹配到的图片 */ if (preg_match_all($pattern, $item->content, $thumbUrl)) { foreach ($thumbUrl[1] as $list) $result[] = $list; } if (preg_match_all($patternMD, $item->content, $thumbUrl)) { foreach ($thumbUrl[1] as $list) $result[] = $list; } if (preg_match_all($patternMDfoot, $item->content, $thumbUrl)) { foreach ($thumbUrl[1] as $list) $result[] = $list; } /* 如果上面的数量不足3个,则直接补充3个随即图进去 */ if (sizeof($result) < 3) { $custom_thumbnail = Helper::options()->JThumbnail; /* 将for循环放里面,减少一次if判断 */ if ($custom_thumbnail) { $custom_thumbnail_arr = explode("\r\n", $custom_thumbnail); for ($i = 0; $i < 3; $i++) { $result[] = $custom_thumbnail_arr[array_rand($custom_thumbnail_arr, 1)] . "?key=" . mt_rand(0, 1000000); } } else { for ($i = 0; $i < 3; $i++) { $result[] = 'https://cdn.jsdelivr.net/gh/HaoOuBa/Joe@master/assets/thumb/' . rand(1, 42) . '.jpg'; } } } return $result; } /* 获取父级评论 */ 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 && Helper::options()->JAside_Author_Nav !== "off") { $limit = Helper::options()->JAside_Author_Nav; $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $sql = "SELECT * FROM `{$prefix}contents` WHERE cid >= (SELECT floor( RAND() * ((SELECT MAX(cid) FROM `{$prefix}contents`)-(SELECT MIN(cid) FROM `{$prefix}contents`)) + (SELECT MIN(cid) FROM `{$prefix}contents`))) and type='post' and status='publish' and (password is NULL or password='') ORDER BY cid LIMIT $limit"; $result = $db->query($sql); foreach ($result as $item) { $item = Typecho_Widget::widget('Widget_Abstract_Contents')->push($item); $title = htmlspecialchars($item['title']); $permalink = $item['permalink']; echo "
  • {$title}
  • "; } } } function _curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if (strpos($url, 'https') !== false) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36'); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $result = curl_exec($ch); curl_close($ch); return $result; } /* 判断敏感词是否在字符串内 */ function _checkSensitiveWords($words_str, $str) { $words = explode("||", $words_str); if (empty($words)) { return false; } foreach ($words as $word) { if (false !== strpos($str, trim($word))) { return true; } } return false; }