From 1bb8f0071974c48ca4abdaf1b813f5aae3219499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E6=82=A0=E7=84=B6?= Date: Fri, 14 May 2021 22:40:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=80=89=E6=8B=A9=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E5=BC=A0=E5=9B=BE=E7=89=87=E4=B8=BA=E5=A4=B4=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions.php | 23 +++++++++++++++++++++++ index.php | 2 +- post.php | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/functions.php b/functions.php index 8bb363c..443ed75 100644 --- a/functions.php +++ b/functions.php @@ -40,6 +40,12 @@ function themeConfig($form) { $defaultPostIMG = new Typecho_Widget_Helper_Form_Element_Text('defaultPostIMG', NULL, NULL, _t('没有设置文章头图的就用这里的图片啦') , _t('http://...')); $form->addInput($defaultPostIMG); + $enableFirstIMG = new Typecho_Widget_Helper_Form_Element_Radio('enableFirstIMG', array( + '1' => _t('cool') , + '0' => _t('nope') + ) , '1', _t('是否使用文章第一张图片作为文章首图') , _t('当没有设置头图时
默认为开启
p.s 不会选择[photo]短代码中的图片')); + $form->addInput($enableFirstIMG); + $headerLOGO = new Typecho_Widget_Helper_Form_Element_Text('headerLOGO', NULL, NULL, _t('头部logo') , _t('如果留空则不显示')); $form->addInput($headerLOGO); @@ -754,3 +760,20 @@ function Links($sorts = NULL) { } echo $link ? $link : '
  • 暂无链接
  • '; } + +/** +* 获取文章首图 +*/ +function getPostImg($archive) { + $img = array(); + // 匹配 img 的 src 的正则表达式 + preg_match_all("//i", $archive->content, $img); + // 判断是否匹配到图片 + if (count($img) > 0 && count($img[0]) > 0) { + // 返回图片 + return $img[1][0]; + } else { + // 如果没有匹配到就返回 false + return false; + } +} diff --git a/index.php b/index.php index 193300e..634b866 100644 --- a/index.php +++ b/index.php @@ -5,7 +5,7 @@ * * @package G * @author 季悠然 - * @version 2.4.2 + * @version 2.4.3 * @link https://gundam.exia.xyz/ */ diff --git a/post.php b/post.php index ebc8d23..64d01d9 100644 --- a/post.php +++ b/post.php @@ -11,7 +11,7 @@ ?>
    -
    +

    title();?>