Enhanced route system and option handling
authorAlexander Ebert <ebert@woltlab.com>
Tue, 25 Dec 2012 16:21:28 +0000 (17:21 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 25 Dec 2012 16:21:28 +0000 (17:21 +0100)
Closes #996

wcfsetup/install/files/lib/data/option/OptionEditor.class.php
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php
wcfsetup/install/files/lib/system/request/Route.class.php
wcfsetup/install/files/lib/system/request/RouteHandler.class.php

index ca76f14f8f44f1dba4e062a0703fc2057b0204f9..23554332680ecfdd6ba7a981ad75c493a93a30e2 100644 (file)
@@ -85,53 +85,33 @@ class OptionEditor extends DatabaseObjectEditor implements IEditableCachedObject
                CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.option.php');
                
                // reset options.inc.php files
-               $sql = "SELECT  package, packageID, packageDir
-                       FROM    wcf".WCF_N."_package
-                       WHERE   isApplication = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array(1));
-               while ($row = $statement->fetchArray()) {
-                       if ($row['package'] == 'com.woltlab.wcf') $packageDir = WCF_DIR;
-                       else $packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']);
-                       $filename = FileUtil::addTrailingSlash($packageDir).self::FILENAME;
-                       if (file_exists($filename)) {
-                               if (!@touch($filename, 1)) {
-                                       if (!@unlink($filename)) {
-                                               self::rebuildFile($filename, $row['packageID']);
-                                       }
-                               }
-                       }
-               }
+               self::rebuild();
        }
        
        /**
         * Rebuilds the option file.
-        * 
-        * @param       string          $filename
-        * @param       integer         $packageID
         */
-       public static function rebuildFile($filename, $packageID) {
+       public static function rebuild() {
                $buffer = '';
                
                // file header
                $buffer .= "<?php\n/**\n* generated at ".gmdate('r')."\n*/\n";
                
                // get all options
-               $options = Option::getOptions($packageID);
+               $options = Option::getOptions();
                foreach ($options as $optionName => $option) {
                        $buffer .= "if (!defined('".$optionName."')) define('".$optionName."', ".(($option->optionType == 'boolean' || $option->optionType == 'integer') ? intval($option->optionValue) : "'".addcslashes($option->optionValue, "'\\")."'").");\n";
                }
                unset($options);
                
                // file footer
-               $buffer .= "?>";
+               $buffer .= "\n";
                
                // open file
-               $file = new File($filename);
+               $file = new File(WCF_DIR.'options.inc.php');
                
                // write buffer
                $file->write($buffer);
-               unset($buffer);
                
                // close file
                $file->close();
index 46d353b152e0f836e9b7e1835b6995b824e8a2a7..9444520ff2af07f2e539055b23076c10650a4b42 100644 (file)
@@ -323,17 +323,14 @@ class WCF {
        }
        
        /**
-        * Includes the options file.
-        * If the option file doesn't exist, the rebuild of it is started.
-        * 
-        * @param       string          $filename
+        * Loads the options file, automatically created if not exists.
         */
-       protected function loadOptions($filename = null, $packageID = 1) {
-               if ($filename === null) $filename = WCF_DIR.'options.inc.php';
+       protected function loadOptions() {
+               $filename = WCF_DIR.'options.inc.php';
                
                // create options file if doesn't exist
                if (!file_exists($filename) || filemtime($filename) <= 1) {
-                       \wcf\data\option\OptionEditor::rebuildFile($filename, $packageID);
+                       \wcf\data\option\OptionEditor::rebuild();
                }
                require_once($filename);
        }
@@ -473,9 +470,6 @@ class WCF {
                                throw new SystemException('Unable to load configuration for '.$package->package);
                        }
                        
-                       // load options
-                       $this->loadOptions($packageDir.'options.inc.php', $application->packageID);
-                       
                        // start application if not within ACP
                        if (!class_exists('wcf\system\WCFACP', false)) {
                                // add template path and abbreviation
index cf2b632c1af6f0c288106fbbc70f6c2c6a4f669b..129de73da8c9ad6a06d262746236c320ba29d02e 100644 (file)
@@ -79,7 +79,7 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag
                        // delete categories
                        $sql = "DELETE FROM     wcf".WCF_N."_".$this->tableName."_category
                                WHERE           categoryName = ?
-                               AND packageID = ?";
+                               AND             packageID = ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        
                        foreach ($categories as $category) {
index e32f6d8107867f31795979cf8bc1c859438188db..df1e52af52b36a4b53f325996fad080ce9a9e115 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\system\request;
+use wcf\util\HeaderUtil;
+
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\SystemException;
 use wcf\system\SingletonFactory;
@@ -69,6 +71,15 @@ class RequestHandler extends SingletonFactory {
                        $routeData = RouteHandler::getInstance()->getRouteData();
                        $controller = $routeData['controller'];
                        
+                       /*
+                        * @todo redirect to landing page once page menu items support controller based URLs (see https://github.com/WoltLab/WCF/issues/998)
+                        * 
+                       if (RouteHandler::getInstance()->isDefaultController()) {
+                               HeaderUtil::redirect(..., true);
+                               exit;
+                       }
+                       */
+                       
                        // validate class name
                        if (!preg_match('~^[a-z0-9_]+$~i', $controller)) {
                                throw new SystemException("Illegal class name '".$controller."'");
index 77b5837ccaf36a11961428784511791ae31c107a..5e1b9316bd540834d75aa86a6f16ea1218f3b077 100644 (file)
@@ -154,6 +154,10 @@ class Route {
                                if (isset($this->parameterOptions[$schemaPart])) {
                                        // default value is provided
                                        if ($this->parameterOptions[$schemaPart]['default'] !== null) {
+                                               if ($schemaPart == 'controller') {
+                                                       $data['isDefaultController'] = true;
+                                               }
+                                               
                                                $data[$schemaPart] = $this->parameterOptions[$schemaPart]['default'];
                                                continue;
                                        }
@@ -166,6 +170,10 @@ class Route {
                        }
                }
                
+               if (!isset($data['isDefaultController'])) {
+                       $data['isDefaultController'] = true;
+               }
+               
                $this->routeData = $data;
                
                // adds route controller if given
index 8eed3bc8b9e498e1740b95ff2b7fab6d2d6fb1a0..0e408ff2b0741ce61c686afcbeacfaf76c360994 100644 (file)
@@ -43,6 +43,12 @@ class RouteHandler extends SingletonFactory {
         */
        protected static $secure = null;
        
+       /**
+        * true, if default controller is used (support for custom landing page)
+        * @var boolean
+        */
+       protected $isDefaultController = false;
+       
        /**
         * list of available routes
         * @var array<wcf\system\request\Route>
@@ -67,6 +73,8 @@ class RouteHandler extends SingletonFactory {
        
        /**
         * Adds default routes.
+        * 
+        * @todo add support for custom default controllers (see https://github.com/WoltLab/WCF/issues/1000)
         */
        protected function addDefaultRoutes() {
                $acpRoute = new Route('ACP_default', true);
@@ -117,6 +125,10 @@ class RouteHandler extends SingletonFactory {
                        
                        if ($route->matches($pathInfo)) {
                                $this->routeData = $route->getRouteData();
+                               
+                               $this->isDefaultController = $this->routeData['isDefaultController'];
+                               unset($this->routeData['isDefaultController']);
+                               
                                $this->registerRouteData();
                                return true;
                        }
@@ -125,6 +137,15 @@ class RouteHandler extends SingletonFactory {
                return false;
        }
        
+       /**
+        * Returns true, if route uses default controller.
+        * 
+        * @return      boolean
+        */
+       public function isDefaultController() {
+               return $this->isDefaultController;
+       }
+       
        /**
         * Returns parsed route data
         *