From 91a540177d080d48ea605472f79e1e612b1e1524 Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Thu, 8 May 2025 10:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96=E5=85=AD?= =?UTF-8?q?=E4=B8=AA=E6=9C=88=E4=BB=A5=E5=86=85=E7=9A=84=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/information.php | 38 ++++++++++++++----------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/application/controllers/information.php b/application/controllers/information.php index 182ba278..891993c1 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -1092,23 +1092,7 @@ class Information extends CI_Controller $data_H1 = array(); $data_H1['infocategory'] = $this->Information_model->get_detail_by_path($information->is_path, 1); //信息所属分类,获取信息顶级节点内容 $data_H1['author'] = ''; //获取作者信息 - - $meta_news_createdate = get_meta($information->ic_id, 'meta_news_createdate'); - - // 六个月以前的文章不显示发布时间 - if (empty($meta_news_createdate) || !strtotime($meta_news_createdate)) { - $data_H1['meta_news_createdate'] = NULL; - } else { - $publish_date = new DateTime($meta_news_createdate, new DateTimeZone('UTC')); - $current_date = new DateTime('now', new DateTimeZone('UTC')); - $interval = $current_date->diff($publish_date); - - if ($interval->y > 0 || ($interval->m > 6) || ($interval->m == 6 && $interval->d > 0)) { - $data_H1['meta_news_createdate'] = NULL; - } else { - $data_H1['meta_news_createdate'] = $meta_news_createdate; - } - } + $data_H1['meta_news_createdate'] = $this->get_publish_date_in_6_month($information); $author = $this->Operator_model->get_author_nikename($information->ic_author); if (!empty($author)) { @@ -1499,6 +1483,26 @@ class Information extends CI_Controller file_put_contents($html_path, $template, LOCK_EX); } + // 六个月以前的文章不显示发布时间 + private function get_publish_date_in_6_month($information) + { + $publish_date_in_6_month = NULL; + $meta_news_createdate = get_meta($information->ic_id, 'meta_news_createdate'); + + if (!empty($meta_news_createdate) && strtotime($meta_news_createdate)) { + $publish_date = new DateTime($meta_news_createdate, new DateTimeZone('UTC')); + $current_date = new DateTime('now', new DateTimeZone('UTC')); + $interval = $current_date->diff($publish_date); + $total_months = $interval->y * 12 + $interval->m; + + if ($total_months < 6) { + $publish_date_in_6_month = $meta_news_createdate; + } + } + + return $publish_date_in_6_month; + } + public function test_recommand() { $information = $this->Information_model->Detail($this->input->get('is_id'));