/** * @param \Ark8\Security\Authorizators\Request $request * @return array * @throws \Nette\InvalidStateException */ private function getSignal(Request $request) { $params = $request->getParameters(); if ($this->httpRequest->isAjax()) { $params += $request->getPost(); } elseif (($tmp = $request->getPost(Presenter::SIGNAL_KEY)) !== NULL) { $params[self::SIGNAL_KEY] = $tmp; } $signal = NULL; $signalReceiver = ''; if (isset($params[Presenter::SIGNAL_KEY])) { $param = $params[Presenter::SIGNAL_KEY]; $pos = strrpos($param, '-'); if ($pos) { $signalReceiver = substr($param, 0, $pos); $signal = substr($param, $pos + 1); } else { $signalReceiver = $this->getUniqueId(); $signal = $param; } if ($signal == NULL) { // intentionally == $signal = NULL; } } return [$signal, explode('-', $signalReceiver)]; }
/** * @param Application\Application $application */ public function __invoke(Application\Application $application) { // Redirect only normal request if ($this->httpRequest->isAjax()) { return; } // Sets the flag for the response handled by the GET switch param and the type of the view. if ($this->deviceView->hasSwitchParam()) { if ($response = $this->getRedirectResponseBySwitchParam()) { $response->send($this->httpRequest, $this->httpResponse); exit; } return; } // If the device view is either the full view or not the mobile view if ($this->deviceView->isFullView() || $this->deviceView->isNotMobileView()) { return; } // Redirects to the tablet version and set the 'tablet' device view in a cookie. if ($this->hasTabletRedirect()) { if ($response = $this->getTabletRedirectResponse()) { $response->send($this->httpRequest, $this->httpResponse); exit; } return; } // Redirects to the mobile version and set the 'mobile' device view in a cookie. if ($this->hasMobileRedirect()) { if ($response = $this->getMobileRedirectResponse()) { $response->send($this->httpRequest, $this->httpResponse); exit; } return; } // No need to redirect // Sets the flag for the response handler $this->onResponseHandler->needModifyResponse(); // Checking the need to modify the Response and set closure if ($this->needTabletResponseModify()) { $this->deviceView->setTabletView(); return; } // Checking the need to modify the Response and set closure if ($this->needPhoneResponseModify()) { $this->deviceView->setPhoneView(); return; } // Sets the closure modifier mobile Response if ($this->needMobileResponseModify()) { $this->deviceView->setMobileView(); return; } // Sets the closure modifier not_mobile Response if ($this->needNotMobileResponseModify()) { $this->deviceView->setNotMobileView(); return; } }
public function render() { if ($this->httpRequest->isAjax()) { if (!isset($this->myPresenter->payload->snippets)) { $this->myPresenter->payload->snippets = []; } $this->myPresenter->payload->snippets[$this->getSnippetId('state')] = $this->getStateElement()->render(); } else { echo Html::el('span', ['id' => $this->getSnippetId('state')])->add($this->getStateElement()); } }
/** * @return Nette\Application\IResponse */ public function run(Application\Request $request) { $this->request = $request; if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) { $refUrl = clone $this->httpRequest->getUrl(); $url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath())); if ($url !== NULL && !$this->httpRequest->getUrl()->isEqual($url)) { return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY); } } $params = $request->getParameters(); if (!isset($params['callback'])) { throw new Application\BadRequestException('Parameter callback is missing.'); } $params['presenter'] = $this; $callback = $params['callback']; $reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback)); $params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params); if ($this->context) { foreach ($reflection->getParameters() as $param) { if ($param->getClassName()) { unset($params[$param->getPosition()]); } } $params = Nette\DI\Helpers::autowireArguments($reflection, $params, $this->context); $params['presenter'] = $this; } $response = call_user_func_array($callback, $params); if (is_string($response)) { $response = array($response, array()); } if (is_array($response)) { list($templateSource, $templateParams) = $response; $response = $this->createTemplate()->setParameters($templateParams); if (!$templateSource instanceof \SplFileInfo) { $response->getLatte()->setLoader(new Latte\Loaders\StringLoader); } $response->setFile($templateSource); } if ($response instanceof Application\UI\ITemplate) { return new Responses\TextResponse($response); } else { return $response; } }
/** * Is AJAX request? * @return bool */ public function isAjax() { if ($this->ajaxMode === NULL) { $this->ajaxMode = $this->httpRequest->isAjax(); } return $this->ajaxMode; }
/** * @param \Nette\Application\Request $request * @return \Nette\Application\IResponse * @throws \Nette\Application\BadRequestException */ public function run(Application\Request $request) { $this->request = $request; if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) { $refUrl = clone $this->httpRequest->getUrl(); $url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath())); if ($url !== NULL && !$this->httpRequest->getUrl()->isEqual($url)) { return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY); } } $params = $request->getParameters(); if (!isset($params['id'])) { throw new Application\BadRequestException('Parameter id is missing.'); } if (NULL === ($item = $this->context->getService('webloader.cache')->getItem(\Nette\Utils\Strings::webalize($params['id'])))) { return new Responses\TextResponse(''); } return new \Lohini\WebLoader\WebLoaderResponse($item[WebLoader::CONTENT], $item[WebLoader::CONTENT_TYPE], $item[WebLoader::ETAG]); }
/** * Handles incoming request and sets translations. */ private function processRequest() { if ($this->httpRequest->isMethod('post') && $this->httpRequest->isAjax() && $this->httpRequest->getHeader(self::XHR_HEADER)) { $data = json_decode(file_get_contents('php://input')); if ($data) { $this->translator->setCurrentLang($data->{self::LANGUAGE_KEY}); if ($data->{self::NAMESPACE_KEY}) { $this->translator->setNamespace($data->{self::NAMESPACE_KEY}); } unset($data->{self::LANGUAGE_KEY}, $data->{self::NAMESPACE_KEY}); foreach ($data as $string => $translated) { $this->translator->setTranslation($string, $translated); } } exit; } }
/** * @param Application\Request $request * * @return Application\IResponse * * @throws Application\BadRequestException */ public function run(Application\Request $request) { $this->request = $request; if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) { $refUrl = clone $this->httpRequest->getUrl(); $url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath())); if ($url !== NULL && !$this->httpRequest->getUrl()->isEqual($url)) { return new Application\Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY); } } $params = $request->getParameters(); if (!isset($params['action'])) { throw new Application\BadRequestException('Parameter action is missing.'); } if (!isset($params['id'])) { throw new Application\BadRequestException('Parameter id is missing.'); } // calls $this->action<Action>() if (!($response = $this->tryCall(Application\UI\Presenter::formatActionMethod(Utils\Strings::capitalize($params['action'])), $params))) { throw new Application\BadRequestException('Action not callable.'); } return $response; }
public function __invoke($application, $request) { if ($this->httpRequest->isAjax() && count($application->getRequests()) > 1) { $this->onResponseHandler->markForward(); } }
/** * @inheritdoc */ public function isAjax() { return $this->current->isAjax(); }