CMS page data is now available in the Request object
authorAlexander Ebert <ebert@woltlab.com>
Fri, 4 Dec 2015 14:11:45 +0000 (15:11 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 4 Dec 2015 14:11:45 +0000 (15:11 +0100)
wcfsetup/install/files/lib/page/CmsPage.class.php
wcfsetup/install/files/lib/system/request/ControllerMap.class.php
wcfsetup/install/files/lib/system/request/Request.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php

index df64878fdc1e446fc2cc69a51c5e242159986cdd..8e5456e9d3280ca5915f562db67f83c5c06e9e4e 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\page;
 use wcf\data\page\Page;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\request\LinkHandler;
+use wcf\system\request\RequestHandler;
 use wcf\system\WCF;
 
 /**
@@ -43,8 +44,12 @@ class CmsPage extends AbstractPage {
        public function readParameters() {
                parent::readParameters();
                
-               if (isset($_GET['languageID'])) $this->languageID = intval($_GET['languageID']);
-               if (isset($_GET['pageID'])) $this->pageID = intval($_GET['pageID']);
+               $metaData = RequestHandler::getInstance()->getActiveRequest()->getMetaData();
+               if (isset($metaData['cms'], $metaData['cms']['pageID'])) {
+                       $this->pageID = $metaData['cms']['pageID'];
+                       
+                       if (isset($metaData['cms']['languageID'])) $this->languageID = $metaData['cms']['languageID'];
+               }
                
                if ($this->pageID) {
                        $this->page = new Page($this->pageID);
index 3dcb0149bdd61763f8bf61eba92ebba709b383d1..1bf707e48de6d5daccb5140d081a19c75d0ae9f6 100644 (file)
@@ -106,8 +106,10 @@ class ControllerMap extends SingletonFactory {
                                        'className' => CmsPage::class,
                                        'controller' => 'cms',
                                        'pageType' => 'page',
-                                       'languageID' => $matches['languageID'],
-                                       'pageID' => $matches['pageID']
+                                       
+                                       // CMS page meta data
+                                       'cmsPageID' => $matches['pageID'],
+                                       'cmsPageLanguageID' => $matches['languageID']
                                ];
                        }
                        else {
index 943110863d844ec45c0e80f835b6d48cae3fe025..35fb4d4f547d1b701b5606f2ec0d19d125a4093f 100644 (file)
@@ -18,6 +18,12 @@ class Request {
         */
        protected $className = '';
        
+       /**
+        * request meta data
+        * @var string[]
+        */
+       protected $metaData;
+       
        /**
         * page name
         * @var string
@@ -34,17 +40,19 @@ class Request {
         * request object
         * @var object
         */
-       protected $requestObject = null;
+       protected $requestObject;
        
        /**
         * Creates a new request object.
         * 
-        * @param       string          $className
-        * @param       string          $pageName
-        * @param       string          $pageType
+        * @param       string          $className      fully qualified name
+        * @param       string          $pageName       class name
+        * @param       string          $pageType       can be 'action', 'form' or 'page'
+        * @param       string[]        $metaData       additional meta data
         */
-       public function __construct($className, $pageName, $pageType) {
+       public function __construct($className, $pageName, $pageType, array $metaData) {
                $this->className = $className;
+               $this->metaData = $metaData;
                $this->pageName = $pageName;
                $this->pageType = $pageType;
        }
@@ -77,6 +85,15 @@ class Request {
                return $this->className;
        }
        
+       /**
+        * Returns request meta data.
+        * 
+        * @return      string[]
+        */
+       public function getMetaData() {
+               return $this->metaData;
+       }
+       
        /**
         * Returns the page name of this request.
         * 
index e1cfe6af6fa893cd3fe2c816b90b1d0343d13580..9ef31df7fb58ae3f33fbc02a0b734dc11ca0b98e 100644 (file)
@@ -177,10 +177,21 @@ class RequestHandler extends SingletonFactory {
                                }
                        }
                        
-                       $this->activeRequest = new Request($classData['className'], $classData['controller'], $classData['pageType']);
+                       // handle CMS page meta data
+                       $metaData = [];
+                       if (isset($routeData['cmsPageID'])) {
+                               $metaData['cms'] = [
+                                       'pageID' => $routeData['cmsPageID'],
+                                       'languageID' => $routeData['cmsPageLanguageID']
+                               ];
+                               
+                               unset($routeData['cmsPageID']);
+                               unset($routeData['cmsPageLanguageID']);
+                       }
+                       
+                       $this->activeRequest = new Request($classData['className'], $classData['controller'], $classData['pageType'], $metaData);
                }
                catch (SystemException $e) {
-                       die("<pre>".$e->getMessage());
                        throw new IllegalLinkException();
                }
        }
@@ -188,9 +199,9 @@ class RequestHandler extends SingletonFactory {
        /**
         * Redirects to the actual URL, e.g. controller has been aliased or mistyped (boardlist instead of board-list).
         * 
-        * @param       array<string>           $routeData
-        * @param       string                  $application
-        * @param       string                  $controller
+        * @param       string[]        $routeData
+        * @param       string          $application
+        * @param       string          $controller
         */
        protected function redirect(array $routeData, $application, $controller = null) {
                $routeData['application'] = $application;