From e5c9ab9c5c05b7f00c0f3e7609659c8c3be7053e Mon Sep 17 00:00:00 2001 From: kokororin Date: Fri, 14 Jul 2017 11:08:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84cid=E5=8F=8Amid=E7=9A=84?= =?UTF-8?q?=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Access_Core.php | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Access_Core.php b/Access_Core.php index d3af8c3..1dbddb2 100644 --- a/Access_Core.php +++ b/Access_Core.php @@ -265,7 +265,7 @@ class Access_Core * @access public * @return void */ - public function writeLogs($url = null) + public function writeLogs($archive = null, $url = null, $content_id = null, $meta_id = null) { if ($this->isAdmin()) { return; @@ -282,6 +282,16 @@ class Access_Core $entrypoint = $this->getEntryPoint(); $referer = $this->request->getReferer(); $time = Helper::options()->gmtTime + (Helper::options()->timezone - Helper::options()->serverTimezone); + + if ($archive != null) { + $parsedArchive = $this->parseArchive($archive); + $content_id = $parsedArchive['content_id']; + $meta_id = $parsedArchive['meta_id']; + } else { + $content_id = is_numeric($content_id) ? $content_id : null; + $meta_id = is_numeric($meta_id) ? $meta_id : null; + } + $rows = array( 'ua' => $this->ua->getUA(), 'browser_id' => $this->ua->getBrowserID(), @@ -297,7 +307,8 @@ class Access_Core 'entrypoint' => $entrypoint, 'entrypoint_domain' => parse_url($entrypoint, PHP_URL_HOST), 'time' => $time, - // 'content_id' => , + 'content_id' => $content_id, + 'meta_id' => $meta_id, 'robot' => $this->ua->isRobot() ? 1 : 0, 'robot_id' => $this->ua->getRobotID(), 'robot_version' => $this->ua->getRobotVersion(), @@ -308,4 +319,30 @@ class Access_Core } catch (Exception $e) {} catch (Typecho_Db_Query_Exception $e) {} } + /** + * 解析archive对象 + * + * @access public + * @return array + */ + public function parseArchive($archive) { + // 暂定首页的meta_id为0 + $content_id = null; + $meta_id = null; + if ($archive->is('index')) { + $meta_id = 0; + } elseif ($archive->is('post') || $archive->is('page')) { + $content_id = $archive->cid; + } elseif ($archive->is('tag')) { + $meta_id = $archive->tags[0]['mid']; + } elseif ($archive->is('category')) { + $meta_id = $archive->categories[0]['mid']; + } elseif ($archive->is('archive', 404)) {} + + return array( + 'content_id' => $content_id, + 'meta_id' => $meta_id, + ); + } + }