|
|
@@ -79,13 +79,7 @@ class Dispatcher implements CakeEventListener {
|
|
|
* @return array
|
|
|
**/
|
|
|
public function implementedEvents() {
|
|
|
- return array(
|
|
|
- 'Dispatcher.beforeDispatch' => array(
|
|
|
- array('callable' => array($this, 'asset')),
|
|
|
- array('callable' => array($this, 'cached')),
|
|
|
- array('callable' => array($this, 'parseParams')),
|
|
|
- )
|
|
|
- );
|
|
|
+ return array('Dispatcher.beforeDispatch' => 'parseParams');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -283,141 +277,4 @@ class Dispatcher implements CakeEventListener {
|
|
|
include APP . 'Config' . DS . 'routes.php';
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Checks whether the response was cached and set the body accordingly.
|
|
|
- *
|
|
|
- * @param CakeEvent $event containing the request and response object
|
|
|
- * @return CakeResponse with cached content if found, null otherwise
|
|
|
- */
|
|
|
- public function cached($event) {
|
|
|
- $path = $event->data['request']->here();
|
|
|
- if (Configure::read('Cache.check') === true) {
|
|
|
- if ($path == '/') {
|
|
|
- $path = 'home';
|
|
|
- }
|
|
|
- $path = strtolower(Inflector::slug($path));
|
|
|
-
|
|
|
- $filename = CACHE . 'views' . DS . $path . '.php';
|
|
|
-
|
|
|
- if (!file_exists($filename)) {
|
|
|
- $filename = CACHE . 'views' . DS . $path . '_index.php';
|
|
|
- }
|
|
|
- if (file_exists($filename)) {
|
|
|
- $controller = null;
|
|
|
- $view = new View($controller);
|
|
|
- $result = $view->renderCache($filename, microtime(true));
|
|
|
- if ($result !== false) {
|
|
|
- $event->data['response']->body($result);
|
|
|
- return $event->data['response'];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * Checks if a requested asset exists and sends it to the browser
|
|
|
- *
|
|
|
- * @param CakeEvent $event containing the request and response object
|
|
|
- * @return CakeResponse if the client is requesting a recognized asset, null otherwise
|
|
|
- */
|
|
|
- public function asset($event) {
|
|
|
- $url = $event->data['request']->url;
|
|
|
- $response = $event->data['response'];
|
|
|
-
|
|
|
- if (strpos($url, '..') !== false || strpos($url, '.') === false) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- $filters = Configure::read('Asset.filter');
|
|
|
- $isCss = (
|
|
|
- strpos($url, 'ccss/') === 0 ||
|
|
|
- preg_match('#^(theme/([^/]+)/ccss/)|(([^/]+)(?<!css)/ccss)/#i', $url)
|
|
|
- );
|
|
|
- $isJs = (
|
|
|
- strpos($url, 'cjs/') === 0 ||
|
|
|
- preg_match('#^/((theme/[^/]+)/cjs/)|(([^/]+)(?<!js)/cjs)/#i', $url)
|
|
|
- );
|
|
|
-
|
|
|
- if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) {
|
|
|
- $response->statusCode(404);
|
|
|
- $event->stopPropagation();
|
|
|
- return $response;
|
|
|
- } elseif ($isCss) {
|
|
|
- include WWW_ROOT . DS . $filters['css'];
|
|
|
- $event->stopPropagation();
|
|
|
- return $response;
|
|
|
- } elseif ($isJs) {
|
|
|
- include WWW_ROOT . DS . $filters['js'];
|
|
|
- $event->stopPropagation();
|
|
|
- return $response;
|
|
|
- }
|
|
|
-
|
|
|
- $pathSegments = explode('.', $url);
|
|
|
- $ext = array_pop($pathSegments);
|
|
|
- $parts = explode('/', $url);
|
|
|
- $assetFile = null;
|
|
|
-
|
|
|
- if ($parts[0] === 'theme') {
|
|
|
- $themeName = $parts[1];
|
|
|
- unset($parts[0], $parts[1]);
|
|
|
- $fileFragment = urldecode(implode(DS, $parts));
|
|
|
- $path = App::themePath($themeName) . 'webroot' . DS;
|
|
|
- if (file_exists($path . $fileFragment)) {
|
|
|
- $assetFile = $path . $fileFragment;
|
|
|
- }
|
|
|
- } else {
|
|
|
- $plugin = Inflector::camelize($parts[0]);
|
|
|
- if (CakePlugin::loaded($plugin)) {
|
|
|
- unset($parts[0]);
|
|
|
- $fileFragment = urldecode(implode(DS, $parts));
|
|
|
- $pluginWebroot = CakePlugin::path($plugin) . 'webroot' . DS;
|
|
|
- if (file_exists($pluginWebroot . $fileFragment)) {
|
|
|
- $assetFile = $pluginWebroot . $fileFragment;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($assetFile !== null) {
|
|
|
- $event->stopPropagation();
|
|
|
- $this->_deliverAsset($response, $assetFile, $ext);
|
|
|
- return $response;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * Sends an asset file to the client
|
|
|
- *
|
|
|
- * @param CakeResponse $response The response object to use.
|
|
|
- * @param string $assetFile Path to the asset file in the file system
|
|
|
- * @param string $ext The extension of the file to determine its mime type
|
|
|
- * @return void
|
|
|
- */
|
|
|
- protected function _deliverAsset(CakeResponse $response, $assetFile, $ext) {
|
|
|
- ob_start();
|
|
|
- $compressionEnabled = Configure::read('Asset.compress') && $response->compress();
|
|
|
- if ($response->type($ext) == $ext) {
|
|
|
- $contentType = 'application/octet-stream';
|
|
|
- $agent = env('HTTP_USER_AGENT');
|
|
|
- if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
|
|
|
- $contentType = 'application/octetstream';
|
|
|
- }
|
|
|
- $response->type($contentType);
|
|
|
- }
|
|
|
- if (!$compressionEnabled) {
|
|
|
- $response->header('Content-Length', filesize($assetFile));
|
|
|
- }
|
|
|
- $response->cache(filemtime($assetFile));
|
|
|
- $response->send();
|
|
|
- ob_clean();
|
|
|
- if ($ext === 'css' || $ext === 'js') {
|
|
|
- include $assetFile;
|
|
|
- } else {
|
|
|
- readfile($assetFile);
|
|
|
- }
|
|
|
-
|
|
|
- if ($compressionEnabled) {
|
|
|
- ob_end_flush();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|