From d7529a2cd2665b7a90297f28d3b8bfd6e3a53228 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 8 Apr 2016 12:30:59 +0200 Subject: [PATCH] Added method to retrieve the current page id --- .../lib/system/request/Request.class.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/request/Request.class.php b/wcfsetup/install/files/lib/system/request/Request.class.php index 1634c80d05..31436fd3f6 100644 --- a/wcfsetup/install/files/lib/system/request/Request.class.php +++ b/wcfsetup/install/files/lib/system/request/Request.class.php @@ -1,11 +1,12 @@ * @package com.woltlab.wcf * @subpackage system.request @@ -29,6 +30,12 @@ class Request { */ protected $metaData; + /** + * current page id + * @var integer + */ + protected $pageID; + /** * page name * @var string @@ -155,4 +162,28 @@ class Request { return false; } + + /** + * Returns the current page id. + * + * @return integer current page id or `0` if unknown + */ + public function getPageID() { + if ($this->pageID === null) { + if (isset($this->metaData['cms'])) { + $this->pageID = $this->metaData['cms']['pageID']; + } + else { + $page = PageCache::getInstance()->getPageByController($this->className); + if ($page !== null) { + $this->pageID = $page->pageID; + } + else { + $this->pageID = 0; + } + } + } + + return $this->pageID; + } } -- 2.20.1