/** * @param \Enlight_Controller_EventArgs $args */ public function onPostDispatch(\Enlight_Controller_EventArgs $args) { $exceptions = $args->getResponse()->getException(); if (empty($exceptions)) { return; } foreach ($exceptions as $exception) { $this->exceptions[] = $exception; } }
/** * Checks the url / the request and passes it around if necessary. * * @param Enlight_Controller_EventArgs $args */ public function onPreDispatch(Enlight_Controller_EventArgs $args) { $request = $args->getRequest(); $response = $args->getResponse(); if ($response->isException() || $request->isPost() || $request->isXmlHttpRequest() || $request->has('callback') || $request->getModuleName() && $request->getModuleName() != 'frontend' || !$request->getParam('rewriteAlias') && !$request->getParam('rewriteOld') || !Shopware()->Session()->Bot && !$request->getCookie()) { return; } $router = $args->getSubject()->Router(); $query = $request->getQuery(); $location = $router->assemble($query); $current = $request->getScheme() . '://' . $request->getHttpHost() . $request->getRequestUri(); if ($location !== $current) { $response->setRedirect($location, 301); } }
/** * Event listener method * * @param Enlight_Controller_EventArgs $args */ public function onDispatchLoopShutdown(Enlight_Controller_EventArgs $args) { $request = $args->getRequest(); $response = $args->getResponse(); if ($response->isException() || $request->isXmlHttpRequest() || $request->getModuleName() != 'frontend' || $request->getControllerName() == 'captcha' ) { return; } if (!Shopware()->Shop()->get('esi')) { $this->updateLog($request, $response); } }
/** * Checks the url / the request and passes it around if necessary. * * @param Enlight_Controller_EventArgs $args */ public function onPreDispatch(Enlight_Controller_EventArgs $args) { $request = $args->getRequest(); $response = $args->getResponse(); if ($response->isException() || $request->isPost() || $request->isXmlHttpRequest() || $request->has('callback') || $request->getModuleName() != 'frontend' || !$request->getParam('rewriteAlias')) { return; } $router = $args->getSubject()->Router(); $query = $request->getQuery(); $location = $router->assemble($query); // Fix shop redirect / if it's not a seo url if (preg_match('#\\/[0-9]+$#', $location, $match) > 0) { $location = $request->getBaseUrl() . '/'; } $current = $request->getScheme() . '://' . $request->getHttpHost() . $request->getRequestUri(); if ($location !== $current) { $response->setRedirect($location, 301); } }
/** * This pre-dispatch event-hook checks permissions * * @param \Enlight_Controller_EventArgs $args * @return void */ public function onFrontPreDispatch(Enlight_Controller_EventArgs $args) { $request = $args->getRequest(); $response = $args->getResponse(); if ($request->getModuleName() != 'api') { return; } /** @var $auth Shopware_Components_Auth */ $auth = $this->get('auth'); $result = $auth->authenticate(); if (!$result->isValid()) { $request->setControllerName('index'); $request->setActionName('noauth'); return; } $identity = $result->getIdentity(); $db = $this->get('db'); $select = $db->select()->from('s_core_auth')->where('username LIKE ?', $identity['username']); $user = $db->query($select)->fetchObject(); if (!empty($user->roleID)) { $user->role = $this->get('models')->find('Shopware\\Models\\User\\Role', $user->roleID); } $auth->getStorage()->write($user); $rawBody = $request->getRawBody(); try { $input = Zend_Json::decode($rawBody); } catch (Zend_Json_Exception $e) { $response->setHttpResponseCode(400); $request->setControllerName('index'); $request->setActionName('invalid'); return; } foreach ((array) $input as $key => $value) { if ($value !== null) { $request->setPost($key, $value); } } }
/** * Adds the headers to the response once it's created */ public function onRouteStartUp(\Enlight_Controller_EventArgs $args) { $response = $args->getResponse(); $request = $args->getRequest(); $this->setUp($request, $response); }
/** * Listener method for the Enlight_Controller_Front_RouteStartup event. * Adds the user-agent and the remote-address to the log component. * Sets the request and the response object into the Zend_Wildfire_Channel_HttpHeaders. * * @param Enlight_Event_EventArgs $args */ public function onRouteStartup(Enlight_Controller_EventArgs $args) { $request = $args->getRequest(); $response = $args->getResponse(); /** @var $log Zend_Log */ $log = $this->Resource(); $log->setEventItem('remote_address', $request->getClientIp(false)); $log->setEventItem('user_agent', $request->getHeader('USER_AGENT')); $channel = $this->FirebugChannel(); $channel->setRequest($request); $channel->setResponse($response); }
/** * Event listener method * * @param Enlight_Controller_EventArgs $args */ public function onRouteShutdown(Enlight_Controller_EventArgs $args) { $request = $args->getRequest(); $response = $args->getResponse(); $bootstrap = $this->Application()->Bootstrap(); if ($bootstrap->issetResource('Shop')) { $shop = $this->Application()->Shop(); if ($request->isSecure() && $request->getHttpHost() !== $shop->getSecureHost()) { $newPath = $request::SCHEME_HTTPS . '://' . $shop->getSecureHost() . $shop->getBasePath(); } elseif (!$request->isSecure() && $request->getHttpHost() !== $shop->getHost()) { $newPath = $request::SCHEME_HTTP . '://' . $shop->getHost() . $shop->getBasePath(); } // Strip /shopware.php/ from string and perform a redirect $preferBasePath = $this->Application()->Config()->preferBasePath; if ($preferBasePath && strpos($request->getPathInfo(), '/shopware.php/') === 0) { $removePath = $request->getBasePath() . '/shopware.php'; $newPath = str_replace($removePath, $request->getBasePath(), $request->getRequestUri()); } if (isset($newPath)) { // reset the cookie so only one valid cookie will be set IE11 fix $response->setCookie("session-" . $shop->getId(), '', -1); $response->setRedirect($newPath, 301); } else { $this->upgradeShop($request, $response); $this->initServiceMode($request); } } $this->fixRequest($request); $this->initConfig($request); }
/** * Do http caching jobs * * @param \Enlight_Controller_EventArgs $args */ public function onPreDispatch(\Enlight_Controller_EventArgs $args) { $this->action = $args->getSubject(); $this->request = $args->getRequest(); $this->response = $args->getResponse(); $this->Application()->Events()->registerListener(new Enlight_Event_Handler_Default('Enlight_Controller_Action_PostDispatchSecure', array($this, 'onPostDispatch'))); }
/** * Do http caching jobs * * @param \Enlight_Controller_EventArgs $args */ public function onPreDispatch($args) { $this->action = $action = $args->getSubject(); $this->request = $request = $args->getRequest(); $this->response = $response = $args->getResponse(); if ($request->getHeader('Surrogate-Capability') === false) { return; } $this->initConfig(); if ($request->getModuleName() != 'frontend' && $request->getModuleName() != 'widgets') { return; } if (!Shopware()->Shop()->get('esi')) { return; } // Allow esi tags $this->response->setHeader('Surrogate-Control', 'content="ESI/1.0"'); $this->setControllerOptions(); $this->setCacheHeaders(); $this->setNoCacheCookie(); $this->setCacheIdHeader(); }
/** * Event listener method * * @param Enlight_Controller_EventArgs $args */ public function onRouteShutdown(Enlight_Controller_EventArgs $args) { $request = $args->getRequest(); $response = $args->getResponse(); $bootstrap = $this->Application()->Bootstrap(); if ($bootstrap->issetResource('Shop')) { $shop = $this->Application()->Shop(); if ($request->isSecure() && $request->getHttpHost() !== $shop->getSecureHost()) { $newPath = $request::SCHEME_HTTPS . '://' . $shop->getSecureHost(); } elseif ($request->getHttpHost() !== $shop->getHost()) { $newPath = $request::SCHEME_HTTP . '://' . $shop->getHost(); } if(isset($newPath)) { $url = sprintf('%s%s', $newPath, $request->getRequestUri() ); $response->setRedirect($url, 301); } else { $this->upgradeShop($request, $response); $this->initServiceMode($request); } } $this->fixRequest($request); $this->initConfig($request); }