/** * @param Nette\Web\IHttpRequest $httpRequest * @return Nette\Application\PresenterRequest|NULL */ public function match(\Nette\Http\IRequest $httpRequest) { /** @var $appRequest \Nette\Application\Request */ $appRequest = parent::match($httpRequest); // doplněno: pokud match vrátí NULL, musíme také vrátit NULL if (!$appRequest) { return $appRequest; } // musím si přeložit host, kvůli localhostu to není dané if (strpos($httpRequest->url->host, '.localhost') !== false && !\Nette\Environment::isProduction()) { // jsme na localhostu $host = substr($httpRequest->url->host, 0, strripos($httpRequest->url->host, '.localhost')); // musíme si doménu osamostatnit od .localhost $host = str_replace('_', '.', $host); // na lokálu mám místo teček podtržení } else { // jsme na produkci $host = $httpRequest->url->host; } // zkusím zda je soubor již v cache if (is_file(WEB_DIR . '/' . $host . '/cache' . $httpRequest->url->path)) { return new Nette\Application\Request('Frontend', 'POST', array('action' => 'cache', 'file' => WEB_DIR . '/' . $host . '/cache' . $httpRequest->url->path)); } /* if ($params = $this->doFilterParams($this->getRequestParams($appRequest), $appRequest, self::WAY_IN)) { return $this->setRequestParams($appRequest, $params); } */ // $pages = $this->context->createPages(); $data = array('action' => 'default'); return new Nette\Application\Request('Frontend', 'POST', $data); }
/** * Maps HTTP request to a Request object. * * @return Request|NULL * @override */ public function match(IRequest $httpRequest) { if ($this->isMobile($httpRequest)) { return parent::match($httpRequest); } else { return NULL; } }
/** * @param \Nette\Application\Request * @param Nette\Web\Uri * @return string */ public function constructUrl(\Nette\Application\Request $appRequest, \Nette\Http\Url $refUri) { if ($params = $this->doFilterParams($this->getRequestParams($appRequest), $appRequest, self::WAY_OUT)) { $appRequest = $this->setRequestParams($appRequest, $params); return parent::constructUrl($appRequest, $refUri); } return NULL; }
/** * @param Application\Request $appRequest * @param Nette\Http\Url $refUrl * @return NULL|string */ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $refUrl) { $parameters = $appRequest->getParameters(); if (isset($parameters['action']) && $parameters['action'] == FALSE) { $parameters['action'] = NULL; } $appRequest->setParameters($parameters); return parent::constructUrl($appRequest, $refUrl); }
public function match(Nette\Http\IRequest $httpRequest) { $appRequest = parent::match($httpRequest); if (empty($appRequest->parameters)) { return null; } if (!$this->articleManager->getArticleUrl($appRequest->parameters['url'])) { return null; } return $appRequest; }
public function __construct($mask, array $defaults = [], ImageProvider $imageProvider) { $this->imageProvider = $imageProvider; $defaults['presenter'] = 'Nette:Micro'; $defaults['callback'] = function ($presenter) { $parameters = $presenter->getRequest()->getParameters(); $image = $this->imageProvider->provideImage($parameters); $image->send(); }; parent::__construct($mask, $defaults); }
public function __construct($metadata) { $map = array("cs/jquery-ajax" => 66, "cs/invoice-control" => 53, "cs/treeview" => 78, "cs/cnb" => 34, "cs/file-downloader" => 80, "cs/scriptloader" => 81, "cs/live-form-validation" => 55, "cs/multiplefileupload" => 11, "cs/webloader" => 39, "cs/confirmationdialog" => 65, "cs/prototype-ajax" => 83, "cs/headercontrol" => 9, "cs/curl-wrapper" => 69, "cs/pdfresponse" => 7, "cs/datetimepicker" => 84, "cs/gui-for-acl" => 85, "cs/mootools-ajax" => 86, "cs/pswdinput" => 4, "cs/multiplefileupload/jak-na-vlastni-interface" => 11, "cs/dependentselectbox" => 3, "cs/suggestinput" => 1, "cs/tabella" => 87, "cs/userpanel" => 88, "cs/navigationpanel" => 5, "cs/presenterlinkpanel" => 64, "cs/phpedpanel" => 63, "cs/template-translator" => 62, "cs/componenttreepanel" => 61, "cs/imageselectbox" => 89, "cs/bigfiletools" => 60, "cs/dateinput" => 59, "cs/gmapformcontrol" => 17, "cs/json-rpc" => 56, "cs/mailpanel" => 57, "cs/textcaptcha" => 79, "cs/twitter-control" => 2, "cs/json-rpc2" => 56, "cs/live-form-validation-for-nette-2-0" => 55, "en/live-form-validation-for-nette-2-0" => 55, "cs/form-container-replicator" => 68, "cs/xdebugtracepanel" => 20, "en/form-container-replicator" => 68, "cs/email-protection" => 90, "cs/twitter" => 14, "cs/eciovni" => 53, "en/eciovni" => 53, "cs/gotopanel" => 10, "en/gotopanel" => 10, "cs/nette-ajax-js" => 26, "en/nette-ajax-js" => 26, "cs/sessionpanel" => 38, "cs/markette-gopay" => 24, "cs/niftygrid" => 52, "cs/redis-storage" => 72, "cs/dropbox-api" => 51, "cs/extensions-list" => 50, "cs/composer-extension" => 13, "cs/google-oauth2" => 49, "cs/eventcalendar" => 48, "cs/gps-picker" => 35, "en/gps-picker" => 35, "cs/gitbranch-debug-panel" => 47, "cs/facebook-connect-for-nette" => 46, "cs/menu" => 22, "cs/multi-authenticator" => 25, "cs/header" => 9, "cs/grido" => 45, "cs/mail-library" => 44, "en/mail-library" => 44, "cs/pdfresponse2" => 43, "cs/thumbnail-helper" => 42, "cs/cachepanel" => 92); $metadata['id'] = array(self::PATTERN => '(cs|en)/[a-z0-9-]+', self::FILTER_IN => function ($slug) use($map) { if (!array_key_exists(Strings::lower($slug), $map)) { return NULL; } return $map[Strings::lower($slug)]; }); parent::__construct('<id>', $metadata, self::ONE_WAY); }
/** * @param \Nette\Application\Request $appRequest * @param \Nette\Http\Url $refUrl * @return string|null */ public function constructUrl(Request $appRequest, Url $refUrl) { $presenter = $appRequest->getPresenterName(); if (!Strings::startsWith($presenter, self::SUBMODULE_NAME . ':')) { return null; } if (Strings::endsWith($presenter, ':' . self::DEFAULT_PRESENTER)) { $presenter = substr($presenter, 0, -strlen(':' . self::DEFAULT_PRESENTER)); } $appRequest->setPresenterName(substr($presenter, strlen(self::SUBMODULE_NAME . ':'))); return parent::constructUrl($appRequest, $refUrl); }
/** * @return \Nette\Application\IRouter */ public static function createRouter() { Route::$defaultFlags = Route::SECURED; $router = new RouteList(); $router[] = new Route('sign/<action>[/<id>]', array("module" => "Service", 'presenter' => 'Sign', 'action' => 'default')); $router[] = new Route('dashboard/<presenter>/<action>[/<id>]', array("module" => "Dashboard", 'presenter' => 'Homepage', 'action' => 'default')); $router[] = new Route('works/<presenter>/<action>[/<id>]', array("module" => "Works", 'presenter' => 'Homepage', 'action' => 'default')); $router[] = new Route('school/<presenter>/<action>[/<id>]', array("module" => "School", 'presenter' => 'Homepage', 'action' => 'default')); $router[] = new Route('activity/<presenter>/<action>[/<id>]', array("module" => "Activity", 'presenter' => 'Homepage', 'action' => 'default')); $router[] = new Route('<presenter>/<action>[/<id>]', array("module" => "Front", 'presenter' => 'Homepage', 'action' => 'default')); return $router; }
public function match(\Nette\Http\IRequest $httpRequest) { $request = parent::match($httpRequest); if (isset($request->parameters['nice_url_segment'])) { if (array_key_exists($request->parameters['nice_url_segment'], $this->redirections)) { $request->setPresenterName('Front:Redirections'); $request->setParameters(array('presenter' => 'Redirections', 'action' => 'Default', 'id' => $this->redirections[$request->parameters['nice_url_segment']])); return $request; } } return NULL; }
/** * Constructs absolute URL from Request object * * @param \Nette\Application\Request $appRequest * @param \Nette\Http\Url $refUrl * @return string|NULL */ public function constructUrl(Application\Request $appRequest, \Nette\Http\Url $refUrl) { if ($appRequest->getPresenterName() != $this->getTargetPresenter()) { return NULL; } $params = $appRequest->getParameters(); if (!isset($params['id']) && isset($params[0])) { $params['id'] = $params[0]; unset($params[0]); $appRequest->setParameters($params); } return parent::constructUrl($appRequest, $refUrl); }
/** * {@inheritDoc} */ public function constructUrl(\Nette\Application\Request $appRequest, \Nette\Http\Url $refUrl) { if (!$this->matchMethod($appRequest)) { return null; } $parameters = $appRequest->parameters; // is matched, remove _method parameter ! if (isset($parameters)) { unset($parameters['_method']); $appRequest->setParameters($parameters); } return parent::constructUrl($appRequest, $refUrl); }
/** * @param bool $enableSsl * * @return Nette\Application\IRouter */ public function createRouter($enableSsl = TRUE) { if ($enableSsl === TRUE) { Route::$defaultFlags = Route::SECURED; } $router = new RouteList(); $router[] = $frontRouter = new RouteList('Front'); $frontRouter[] = new Route('[<locale=cs [a-z]{2}>/]tag/<tag>', 'Tag:default'); $frontRouter[] = new Route('[<locale=cs [a-z]{2}>/]type/<type>', 'Type:default'); $frontRouter[] = new Route('[<locale=cs [a-z]{2}>/]post/<id>[-<slug>]', 'Detail:default'); $frontRouter[] = new Route('[<locale=cs [a-z]{2}>/]<presenter>/<action>[/<id>]', 'Homepage:default'); return $router; }
public function match(\Nette\Http\IRequest $httpRequest) { $httpMethod = $httpRequest->getMethod(); $flags = $this->getFlags(); if (($flags & self::RESTFUL) == self::RESTFUL) { $presenterRequest = parent::match($httpRequest); if ($presenterRequest != NULL) { switch ($httpMethod) { case 'GET': $action = 'default'; break; case 'POST': $action = 'create'; break; case 'PUT': $action = 'update'; break; case 'PATCH': $action = 'update'; break; case 'DELETE': $action = 'delete'; break; default: $action = 'default'; } $params = $presenterRequest->getParameters(); $params['action'] = $action; $presenterRequest->setParameters($params); return $presenterRequest; } else { return NULL; } } if (($flags & self::METHOD_POST) == self::METHOD_POST && $httpMethod != 'POST') { return NULL; } if (($flags & self::METHOD_GET) == self::METHOD_GET && $httpMethod != 'GET') { return NULL; } if (($flags & self::METHOD_PUT) == self::METHOD_PUT && $httpMethod != 'PUT') { return NULL; } if (($flags & self::METHOD_PATCH) == self::METHOD_PATCH && $httpMethod != 'PATCH') { return NULL; } if (($flags & self::METHOD_DELETE) == self::METHOD_DELETE && $httpMethod != 'DELETE') { return NULL; } return parent::match($httpRequest); }
public function match(\Nette\Http\IRequest $httpRequest) { $httpMethod = $httpRequest->getMethod(); if (($this->flags & self::RESTFUL) == self::RESTFUL) { $presenterRequest = parent::match($httpRequest); if ($presenterRequest != NULL) { $payload = null; $payloadParameters = array(); switch ($httpMethod) { case 'GET': $action = 'default'; break; case 'POST': $action = 'create'; break; case 'PUT': $action = 'update'; $payload = file_get_contents("php://input"); parse_str($payload, $payloadParameters); break; case 'DELETE': $action = 'delete'; break; default: $action = 'default'; } $parameters = $presenterRequest->getParameters(); $parameters['action'] = $action; $parameters['payload'] = $payload; $parameters = array_merge($parameters, $payloadParameters); $presenterRequest->setParameters($parameters); return $presenterRequest; } else { return NULL; } } if (($this->flags & self::METHOD_POST) == self::METHOD_POST && $httpMethod != 'POST') { return NULL; } if (($this->flags & self::METHOD_GET) == self::METHOD_GET && $httpMethod != 'GET') { return NULL; } if (($this->flags & self::METHOD_PUT) == self::METHOD_PUT && $httpMethod != 'PUT') { return NULL; } if (($this->flags & self::METHOD_DELETE) == self::METHOD_DELETE && $httpMethod != 'DELETE') { return NULL; } return parent::match($httpRequest); }
public function match(Nette\Http\IRequest $httpRequest) { if (($request = parent::match($httpRequest)) === NULL) { return; } if (!$this->locale) { $parameters = $request->getParameters(); if (isset($parameters['contentLang']) && $parameters['contentLang'] !== $this->defaultLanguage) { $this->pageListener->setLocale($this->languageRepository->findOneBy(array('alias' => $parameters['contentLang']))); } $this->locale = TRUE; } return $request; }
public function __construct($mask, $metadata = [], Languages $languages) { if (count($languages->getLanguages()) > 1) { $mask = $this->languageMask . $mask; if (!isset(Route::$styles['lang'])) { Route::addStyle('lang'); Route::setStyleProperty('lang', Route::FILTER_IN, function ($code) use($languages) { $languages->setCurrent($code); return $languages->getCurrent()->code; }); } } parent::__construct($mask, $metadata); }
public function match(IRequest $httpRequest) { $httpMethod = $httpRequest->getMethod(); if (($this->flags & self::RESTFUL) == self::RESTFUL) { $presenterRequest = parent::match($httpRequest); if ($presenterRequest != NULL) { switch ($httpMethod) { //see: http://en.wikipedia.org/wiki/Representational_state_transfer#RESTful_web_APIs case 'GET': $action = 'get'; break; case 'POST': $action = 'post'; break; //CREATE //CREATE case 'PUT': $action = 'put'; break; //UPDATE //UPDATE case 'DELETE': $action = 'delete'; break; default: $action = 'get'; } $params = $presenterRequest->getParameters(); $params['action'] = $action; $presenterRequest->setParameters($params); return $presenterRequest; } else { return NULL; } } if (($this->flags & self::METHOD_POST) == self::METHOD_POST && $httpMethod != 'POST') { return NULL; } if (($this->flags & self::METHOD_GET) == self::METHOD_GET && $httpMethod != 'GET') { return NULL; } if (($this->flags & self::METHOD_PUT) == self::METHOD_PUT && $httpMethod != 'PUT') { return NULL; } if (($this->flags & self::METHOD_DELETE) == self::METHOD_DELETE && $httpMethod != 'DELETE') { return NULL; } return parent::match($httpRequest); }
/** * @param IRequest $httpRequest * @return \Nette\Application\Request|NULL */ public function match(IRequest $httpRequest) { $appRequest = parent::match($httpRequest); if (!isset($appRequest->parameters['id'])) { return NULL; } $id = $appRequest->parameters['id']; if (!is_numeric($id)) { $article = NULL; try { $article = $this->articlesRepository->getOneWhere(['url' => $id]); } catch (BadRequestException $exc) { return NULL; } $appRequest->parameters['id'] = $article->id(); } return $appRequest; }
/** * @return RouteList */ protected function createWeb() { $router = new RouteList(); if ($this->httpRequest->isSecured()) { Route::$defaultFlags = Route::SECURED; } // FRONT =========================================== $router[] = $front = new RouteList('Front'); $front[] = new Route('sitemap.xml', 'Generator:sitemap'); $front[] = new Route('<slug [a-zA-Z0-9\\-\\.]+/[a-zA-Z0-9\\-\\.]+>/', ['presenter' => 'Addon', 'action' => 'detail', 'slug' => [Route::FILTER_IN => [$this->addonsHelper, 'addonIn'], Route::FILTER_OUT => [$this->addonsHelper, 'addonOut']]]); $front[] = new Route('<slug [a-zA-Z0-9\\-\\.]+>/', ['presenter' => 'List', 'action' => 'owner', 'slug' => [Route::FILTER_IN => [$this->addonsHelper, 'ownerIn'], Route::FILTER_OUT => [$this->addonsHelper, 'ownerOut']]]); $front[] = new Route('all/', 'List:default'); $front[] = new Route('search/', 'List:search'); $front[] = new Route('search/<tag>', 'List:tag'); $front[] = new Route('status/', 'Status:default'); $front[] = new Route('<presenter>/<action>', 'Home:default'); return $router; }
public function match(\Nette\Http\IRequest $request) { /** * @var $appRequest \Nette\Application\Request */ $appRequest = parent::match($request); if (!isset($appRequest->parameters['id'])) { return NULL; } if (!is_numeric($appRequest->parameters['id'])) { $page = $this->database->query("SELECT contentId FROM route WHERE url = ?", $appRequest->parameters['id'])->fetch(); if ($page == NULL) { return NULL; } $appRequest->parameters['id'] = $page->contentId; } return $appRequest; }
/** * @param string * @param string * @param array * @param Validator */ public function __construct($mask, array $defaults, Generator $generator) { $this->defaults = $defaults; $this->generator = $generator; $defaults[NULL][self::FILTER_OUT] = function ($parameters) { $width = $this->acquireArgument('width', $parameters); $height = $this->acquireArgument('height', $parameters); if (!$this->generator->getValidator()->validate($width, $height)) { throw new NotAllowedImageException("Image with size {$width}x{$height} is not allowed - check your 'webimages.rules' please."); } if (isset($this->defaults[NULL][self::FILTER_OUT])) { $parameters = call_user_func($this->defaults[NULL][self::FILTER_OUT], $parameters); } return $parameters; }; $defaults['presenter'] = 'Nette:Micro'; $defaults['callback'] = $this; parent::__construct($mask, $defaults); }
/** * @return \Nette\Application\IRouter */ public function createRouter() { Route::$defaultFlags = Route::SECURED; $router = new RouteList(); // CLI $router[] = new CliRouter(array('action' => 'Cli:Help:default')); // Setup router $router[] = new Route('index.php', 'Homepage:default', Route::ONE_WAY); $router[] = new Route('api/github', 'Api:Github:postReceive'); // same as Packagist's route $router[] = new Route('page/<slug ([a-z][a-z0-9.-]*(?:/[a-z][a-z0-9.-]*)?)>', 'Page:default'); $router[] = new Route('special/<action>[.<type=html (html|xml)>]', 'Special:default'); $router[] = new Route('<id>[/<action>]', array('presenter' => 'Detail', 'action' => 'default', 'id' => array(Route::PATTERN => '[^/]+/[^/]+', Route::FILTER_IN => array($this->packageRouterHelper, 'filterIn'), Route::FILTER_OUT => array($this->packageRouterHelper, 'filterOut')))); $router[] = new Route('<vendor>', array('presenter' => 'List', 'action' => 'default', 'vendor' => array(Route::FILTER_IN => array($this->vendorRouteHelper, 'filterIn'), Route::FILTER_OUT => array($this->vendorRouteHelper, 'filterOut')))); $router[] = new Route('<? cs|en>', 'Homepage:default', Route::ONE_WAY); $router[] = new OldAddonsRoute(array('presenter' => 'Detail', 'action' => 'default')); $router[] = new Route('<presenter>[/<action>]', 'Homepage:default'); return $router; }
/** * Maps HTTP request to a PresenterRequest object. * @param Nette\Http\IRequest * @return \Nette\Application\Request|NULL * @throws \Nette\InvalidStateException */ public function match(\Nette\Http\IRequest $httpRequest) { if (($presenterRequest = parent::match($httpRequest)) === NULL) { return NULL; } $params = $presenterRequest->params; if (!isset($params[static::FILE_KEY])) { throw new \Nette\InvalidStateException('Missing file in route definition.'); } // Find file $file = $this->getFile($params[static::FILE_KEY]); if (!$file) { return NULL; } $params[static::FILE_KEY] = $file; $presenterRequest->params = $params; return $presenterRequest; }
/** * @return \Nette\Application\IRouter */ public static function createRouter() { Route::addStyle('itemname'); Route::setStyleProperty('itemname', Route::FILTER_OUT, function ($url) { return Strings::webalize($url); }); Route::addStyle('category'); Route::setStyleProperty('category', Route::FILTER_OUT, function ($url) { return Strings::webalize($url); }); $router = new RouteList(); $router[] = new Route('//api.%domain%/%basePath%/<action>[/<id>]', 'Api:default'); //$router[] = new Route('//api.%domain%/%basePath%/v1/user[/<user>]/<action>[/<id>]', 'Api:user'); $router[] = new Route('//api.%domain%/%basePath%/v2/<action>[/<id>]', 'Api:default'); $router[] = new Route('item[/<item>-<itemname>]', 'Item:default', Route::SECURED); $router[] = new Route('category[/<id>-<category_name>]', 'Category:default', Route::SECURED); $router[] = new Route('login', 'Login:default', Route::SECURED . Route::SECURED); $router[] = new Route('register', 'Register:default', Route::SECURED); $router[] = new Route('<presenter>/<action>[/<id>]', 'Main:default', Route::SECURED); //$router[] = new Route('api/<presenter>/<action>[/<id>]', 'Api:default'); return $router; }
public function match(IRequest $httpRequest) { $appRequest = parent::match($httpRequest); if (!$appRequest) { return NULL; } $method = $httpRequest->getMethod(); if (!in_array($method, array('GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'))) { return NULL; } if ($this->flags & self::RESTFUL) { $action = self::$restDictionary[$method]; $params = $appRequest->getParameters(); $params['action'] = $action; $appRequest->setParameters($params); return $appRequest; } if (($this->flags & self::METHOD_GET) === self::METHOD_GET && $method !== 'GET') { return NULL; } if (($this->flags & self::METHOD_POST) === self::METHOD_POST && $method !== 'POST') { return NULL; } if (($this->flags & self::METHOD_PUT) === self::METHOD_PUT && $method !== 'PUT') { return NULL; } if (($this->flags & self::METHOD_DELETE) === self::METHOD_DELETE && $method !== 'DELETE') { return NULL; } if (($this->flags & self::METHOD_PATCH) === self::METHOD_PATCH && $method !== 'PATCH') { return NULL; } if (($this->flags & self::METHOD_OPTIONS) === self::METHOD_OPTIONS && $method !== 'OPTIONS') { return NULL; } return $appRequest; }
/** * @param Http\IRequest $httpRequest * @return Application\Request|NULL */ public function match(Http\IRequest $httpRequest) { $appRequest = parent::match($httpRequest); if (!$appRequest) { return NULL; } // Check requested method $methodFlag = $this->getMethod($httpRequest); if (!$this->isMethod($methodFlag)) { return NULL; } // If there is action dictionary, set method if ($this->actionDictionary) { $parameters = $appRequest->getParameters(); $parameters['action'] = $this->actionDictionary[$methodFlag]; $parameters['action'] = self::formatActionName($this->actionDictionary[$methodFlag], $parameters); $appRequest->setParameters($parameters); } return $appRequest; }
public function __construct() { parent::__construct('public/media/_cache/<size>/<format>/<type>/<url .+>', array('presenter' => 'Cms:File', 'action' => 'image', 'url' => array(self::VALUE => '', self::FILTER_IN => NULL, self::FILTER_OUT => NULL))); }
/** * Maps HTTP request to a PresenterRequest object. * @param \Nette\Http\IRequest * @return \Nette\Application\Request|NULL * @throws \Nette\InvalidStateException */ public function match(\Nette\Http\IRequest $httpRequest) { if (($presenterRequest = parent::match($httpRequest)) === NULL) { return NULL; } $params = $presenterRequest->params; if (!isset($params[static::FORMAT_KEY])) { throw new \Nette\InvalidStateException('Missing format in route definition.'); } if (!isset($params[static::IMAGE_KEY])) { throw new \Nette\InvalidStateException('Missing id in route definition.'); } // Find image $image = $this->getImage($params[static::IMAGE_KEY]); if (!$image) { return NULL; } $params[static::IMAGE_KEY] = $image; // Find format $format = $this->getFormat($params[static::FORMAT_KEY]); if (!$format) { return NULL; } $params[static::FORMAT_KEY] = $format; // Set path parameter $params[static::PATH_PARAMETER] = $httpRequest->url->path; $presenterRequest->params = $params; return $presenterRequest; }
public function __construct() { parent::__construct('public/media/<url .+>', array('presenter' => 'Cms:File', 'action' => 'default', 'url' => array(self::VALUE => '', self::FILTER_IN => NULL, self::FILTER_OUT => NULL))); }