From f27f47e2e39e9db4f9b7513f5c6deb3ed9cf038a Mon Sep 17 00:00:00 2001 From: augushong Date: Thu, 10 Aug 2023 10:22:41 +0800 Subject: [PATCH] =?UTF-8?q?ip=E8=84=B1=E6=95=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/model/PostVisit.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/model/PostVisit.php b/app/model/PostVisit.php index 25416e3..bd68cd8 100644 --- a/app/model/PostVisit.php +++ b/app/model/PostVisit.php @@ -42,7 +42,7 @@ class PostVisit extends Model if (empty($value)) { $current_ip = Request::ip(); - $ip = $this->getAttr('ip'); + $ip = $this->getAttr('ip_title'); if ($current_ip == $ip) { $value = '您的IP:' . $ip; @@ -54,6 +54,24 @@ class PostVisit extends Model return $value; } + public function getIpTitleAttr() + { + $value = $this->getAttr('ip'); + + if (empty($value)) { + return $value; + } + + $ip_pieces = explode('.', $value); + + $ip_pieces = array_slice($ip_pieces, 0, -2); + + $ip_pieces[] = '*'; + $ip_pieces[] = '*'; + + return implode('.', $ip_pieces); + } + public function getCreateTimeTitleAttr() { $value = $this->getData('create_time');