Exemplo n.º 1
0
 public function render()
 {
     $baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/');
     $basePath = preg_replace('#https?://[^/]+#A', '', $baseUrl);
     $this->setTempPath($basePath . $this->relativeTempPath);
     $this->setMedia(null);
     $this->setType('text/css');
     $this->setTitle(null);
     $this->setAlternate(null);
     $args = array();
     if (func_num_args() > 0) {
         foreach (func_get_args() as $arg) {
             if (is_array($arg) && isset($arg['config'])) {
                 if (isset($arg['config']['media'])) {
                     $this->setMedia($arg['config']['media']);
                 }
                 if (isset($arg['config']['type'])) {
                     $this->setType($arg['config']['type']);
                 }
                 if (isset($arg['config']['title'])) {
                     $this->setTitle($arg['config']['title']);
                 }
                 if (isset($arg['config']['alternate'])) {
                     $this->setAlternate($arg['config']['alternate']);
                 }
             } else {
                 $args[] = $arg;
             }
         }
     }
     call_user_func_array(array($this, 'parent::render'), $args);
 }
 public function createTemplate($class = NULL)
 {
     $latte = $this->latteFactory->create();
     $template = $class ? new $class($latte) : new Template($latte);
     $template->getLatte()->addFilter(NULL, 'Nette\\Templating\\Helpers::loader');
     if ($latte->onCompile instanceof Traversable) {
         $latte->onCompile = iterator_to_array($latte->onCompile);
     }
     array_unshift($latte->onCompile, function ($latte) {
         $latte->getParser()->shortNoEscape = TRUE;
         $latte->getCompiler()->addMacro('cache', new CacheMacro($latte->getCompiler()));
         UIMacros::install($latte->getCompiler());
         FormMacros::install($latte->getCompiler());
     });
     $latte->addFilter('url', 'rawurlencode');
     // back compatiblity
     foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) {
         $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
     }
     $template->user = $this->user;
     $template->netteHttpResponse = $this->httpResponse;
     $template->netteCacheStorage = $this->httpRequest;
     $template->baseUri = $template->baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/');
     $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
     if (!isset($template->flashes) || !is_array($template->flashes)) {
         $template->flashes = array();
     }
     $template->setTranslator($this->translator);
     $template->_control = $this->linker;
     return $template;
 }
Exemplo n.º 3
0
 /**
  * @return \Nette\Http\Url|\Nette\Http\UrlScript
  */
 public function create()
 {
     $url = $this->httpRequest->getUrl();
     if (!$url->getHost()) {
         $url = $this->fallbackUrl;
     }
     return $url;
 }
 public function render()
 {
     $basePath = $this->request->getUrl()->getBasePath();
     $data = "var base_path = \"" . $basePath . '";';
     /** @var Html $el */
     $el = Html::el("script")->type("text/javascript");
     $el->setText($data);
     echo $el;
 }
Exemplo n.º 5
0
 /**
  * @return \Texy
  */
 public function createTexyForPage()
 {
     $texy = new \Texy();
     $texy->headingModule->top = 3;
     $texy->setOutputMode(\Texy::HTML5);
     // Images
     $texy->imageModule->root = $this->request->getUrl()->getBaseUrl() . $this->imagesRoot;
     $texy->imageModule->fileRoot = $this->imagesFileRoot;
     $texy->addHandler('block', [$this, 'blockHandler']);
     return $texy;
 }
Exemplo n.º 6
0
 public function compileConfig()
 {
     $repositories = $this->getAll();
     $domain = $this->httpRequest->getUrl()->getHostUrl();
     $config = ['homepage' => $domain, 'repositories' => []];
     foreach ($this->parameters as $property => $value) {
         $config[$property] = $value;
     }
     foreach ($repositories as $repository) {
         $config['repositories'][] = ['type' => $repository->type, 'url' => $repository->url];
     }
     $json = Json::encode($config, Json::PRETTY);
     FileSystem::write($this->configFile, $json);
 }
Exemplo n.º 7
0
 public function render()
 {
     $baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/');
     $basePath = preg_replace('#https?://[^/]+#A', '', $baseUrl);
     $this->setTempPath($basePath . $this->relativeTempPath);
     $args = array();
     if (func_num_args() > 0) {
         foreach (func_get_args() as $arg) {
             if (!is_array($arg) || !isset($arg['config'])) {
                 $args[] = $arg;
             }
         }
     }
     call_user_func_array(array($this, 'parent::render'), $args);
 }
Exemplo n.º 8
0
 function __construct($from, $fromName = NULL, Nette\Bridges\ApplicationLatte\ILatteFactory $latteFactory, Nette\Application\LinkGenerator $linkGenerator, Nette\Http\Request $httpRequest)
 {
     $this->from($from, $fromName);
     $this->latteFactory = $latteFactory;
     $this->linkGenerator = $linkGenerator;
     $this->refUrl = $httpRequest->getUrl();
 }
 public function handleSuccess($form)
 {
     $form->getPresenter()->absoluteUrls = true;
     $url = $this->httpRequest->getUrl();
     $path = "{$url->scheme}://{$url->host}{$url->scriptPath}";
     $oldPath = $path . $this->websiteManager->routePrefix;
     $newPath = $path . $form['routePrefix']->getValue();
     if ($form['routePrefix']->getValue() == '') {
         $oldPath .= '/';
     }
     if ($this->websiteManager->routePrefix == '') {
         $newPath .= '/';
     }
     $form->getPresenter()->flashMessage('Administration settings has been updated', 'success');
     $form->getPresenter()->redirectUrl(str_replace($oldPath, $newPath, $form->getPresenter()->link('this')));
 }
Exemplo n.º 10
0
 /**
  * @see Nette\Application\Control#render()
  */
 public function render()
 {
     if ($this->staticMap) {
         $this->getTemplate()->height = $this->height;
         $this->getTemplate()->width = $this->width;
         $this->getTemplate()->zoom = $this->zoom;
         $this->getTemplate()->position = $this->coordinates;
         $this->getTemplate()->markers = $this->markers;
         $this->getTemplate()->clickable = $this->clickable;
         $this->getTemplate()->setFile(dirname(__FILE__) . '/static.latte');
     } else {
         //forward compatibility
         $currentUrl = '/' . $this->httpRequest->getUrl()->getRelativeUrl();
         if (preg_match('/\\?/i', $currentUrl)) {
             $currentUrl .= '&do=';
         } else {
             $currentUrl .= '?do=';
         }
         $map = array('position' => $this->coordinates, 'height' => $this->height, 'width' => $this->width, 'zoom' => $this->zoom, 'type' => $this->type, 'scrollable' => $this->scrollable, 'key' => $this->key, 'bound' => $this->bound, 'cluster' => $this->markerClusterer);
         $this->getTemplate()->map = \Nette\Utils\Json::encode($map);
         $this->getTemplate()->waypointlimit = $this->waypoint_limit;
         $this->getTemplate()->preserveViewport = $this->preserveViewport;
         $this->getTemplate()->markersFallbackUrl = $currentUrl . 'map-markers';
         $this->getTemplate()->waypointsFallbackUrl = $currentUrl . 'map-waypoints';
         $this->getTemplate()->setFile(dirname(__FILE__) . '/template.latte');
     }
     $this->getTemplate()->render();
 }
Exemplo n.º 11
0
 public function update(Items\Base $item = NULL, $data)
 {
     try {
         $actualUrl = $this->request->getUrl();
         $urlScript = new Nette\Http\UrlScript($data);
         $urlScript->setScriptPath($actualUrl->getScriptPath());
         if ($urlScript->getHost() == $actualUrl->getHost()) {
             $request = new Nette\Http\Request($urlScript);
             $appRequest = $this->router->match($request);
             if (!is_null($appRequest)) {
                 $data = $appRequest->getPresenterName();
                 $data .= ':' . $appRequest->getParameter('action');
                 $fragment = $urlScript->getFragment();
                 if ($fragment != '') {
                     $data .= '#' . $fragment;
                 }
                 $parameters = $appRequest->getParameters();
                 unset($parameters['action']);
                 if (count($parameters) > 0) {
                     $data .= ', ' . Nette\Utils\Json::encode($parameters);
                 }
             }
         }
     } catch (Nette\InvalidArgumentException $e) {
     }
     return $data;
 }
Exemplo n.º 12
0
 /**
  * Translates the given string.
  * @param  string   message
  * @param  int      plural count
  * @return string   translated string
  */
 public function translate($message, $param1 = null, $param2 = null, $param3 = null)
 {
     $langFrom = $this->getLangFrom();
     $langTo = $this->getLangTo();
     // If languages are same or no languages given, return original message
     if ($langFrom == $langTo || !$langFrom || !$langTo || empty($message) || is_numeric($message)) {
         return sprintf($message, $param1, $param2, $param3);
     } else {
         // Fetch translated strings
         $translationsArray = $this->getTranslationsArray();
         $stringsArray = $this->getStringsArray();
         // Check for given message if is translated
         $messageTranslated = isset($translationsArray[$langFrom][md5($message)][$langTo]) ? $translationsArray[$langFrom][md5($message)][$langTo] : null;
         if (!empty($messageTranslated)) {
             $messageOut = sprintf($messageTranslated, $param1, $param2, $param3);
         } else {
             // The string should not be translated, please log where it is found!
             if (!$this->isUsedToTranslate($message)) {
                 $this->logger->log('String that should not be translated found', 'DbTranslator', $this->httpRequest->getUrl(), $message);
                 return sprintf($message, $param1, $param2, $param3);
             }
             // Check for given message if is in untranslated cache
             $messageCached = isset($stringsArray[md5($message)]) ? $stringsArray[md5($message)] : null;
             if (!empty($messageCached)) {
                 $messageOut = sprintf($messageCached, $param1, $param2);
             } else {
                 // String is not translated yet
                 $messageOut = sprintf($message, $param1, $param2, $param3);
                 $this->saveNonTranslatedString($message);
             }
         }
         return $messageOut;
     }
 }
Exemplo n.º 13
0
 private function redirectBack()
 {
     $referrer = $this->request->getReferer();
     $current = $this->request->getUrl();
     if ($referrer && !$referrer->isEqual($current)) {
         header('Location: ' . $referrer);
         exit;
     }
 }
Exemplo n.º 14
0
 /**
  * Save web passage uri to session
  * @return void
  */
 public function saveState()
 {
     $url = (string) $this->request->getUrl();
     if ($url) {
         $passage = $this->session->getSection('web_passage')->web_passage ?: [];
         if ($url === reset($passage)) {
             return;
         }
         if (strpos($url, '?do=') || strpos($url, '&do=')) {
             return;
         }
         if (sizeof($passage) > self::WEB_PASSAGE_MAX_URLS) {
             array_pop($passage);
         }
         array_unshift($passage, $url);
         $this->session->getSection('web_passage')->web_passage = $passage;
     }
 }
Exemplo n.º 15
0
 /**
  */
 public function renderShow($seo_url)
 {
     dump(func_get_args());
     $httpRequest = new Nette\Http\Request(new Nette\Http\UrlScript($_SERVER['REQUEST_URI']));
     dump($httpRequest->getUrl());
     dump($httpRequest->getMethod());
     dump($httpRequest->getHeaders());
     // get article
     $this->template->article = $this->_articleModel->fetchSingle($seo_url);
 }
Exemplo n.º 16
0
 /**
  */
 public function renderDefault($city)
 {
     dump(func_get_args());
     $httpRequest = new Nette\Http\Request(new Nette\Http\UrlScript($_SERVER['REQUEST_URI']));
     dump($httpRequest->getUrl());
     dump($httpRequest->getMethod());
     dump($httpRequest->getHeaders());
     // get city
     $this->template->city = $city;
 }
Exemplo n.º 17
0
 /**
  * Creates template and registers helpers and latte filter
  * @param  UI\Presenter $presenter
  * @param  string		$file	Filepath to file
  * @param  string|NULL	$lang	Lang code (length=2)
  * @param  string		$class	Name of template class
  * @throws InvalidArgumentException
  * @return Nette\Templating\IFileTemplate
  */
 public function createTemplate(UI\Presenter $presenter, $file = NULL, $lang = NULL, $class = NULL)
 {
     $this->translator->setLangTo($lang);
     $latte = $this->latteFactory->create();
     $template = $class ? new $class($latte) : new Nette\Bridges\ApplicationLatte\Template($latte);
     $template->getLatte()->addFilter(NULL, 'Nette\\Templating\\Helpers::loader');
     $template->getLatte()->addFilter(NULL, '\\Helpers::loader');
     array_unshift($latte->onCompile, function ($latte) {
         $latte->getParser()->shortNoEscape = TRUE;
         $latte->getCompiler()->addMacro('cache', new CacheMacro($latte->getCompiler()));
         Nette\Bridges\ApplicationLatte\UIMacros::install($latte->getCompiler());
         FormMacros::install($latte->getCompiler());
     });
     $latte->addFilter('url', 'rawurlencode');
     // back compatiblity
     foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) {
         $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
     }
     $template->setTranslator($this->translator);
     if (!is_null($file)) {
         $template->setFile($this->appDir . $file);
     }
     // default parameters
     $template->control = $template->_control = $presenter;
     $template->presenter = $template->_presenter = $presenter;
     if ($presenter instanceof UI\Presenter) {
         $template->user = $presenter->getUser();
         $template->netteHttpResponse = $this->httpResponse;
         $template->netteCacheStorage = $this->netteCacheStorage;
         $template->baseUri = $template->baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/');
         $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
         // flash message
         if ($presenter->hasFlashSession()) {
             $id = $presenter->getParameterId('flash');
             $template->flashes = $presenter->getFlashSession()->{$id};
         }
     }
     if (!isset($template->flashes) || !is_array($template->flashes)) {
         $template->flashes = array();
     }
     return $template;
 }
Exemplo n.º 18
0
 /**
  * @param Request $request
  * @param Parameters $parameters
  * @param ITranslator $translator
  * @param IStorage $cacheStorage
  */
 public function __construct(Request $request, Parameters $parameters, ITranslator $translator, IStorage $cacheStorage)
 {
     $this->request = $request;
     $this->parameters = $parameters;
     $this->translator = $translator;
     $this->cacheStorage = $cacheStorage;
     $cacheDir = $this->parameters->dirs->imageCache;
     $url = $this->request->getUrl();
     $basePath = $url->basePath;
     $isAbsolute = $cacheDir[0] === '/' || $cacheDir[1] === ':';
     $this->cacheDir = $isAbsolute ? $cacheDir : WWW_DIR . "/{$cacheDir}";
     $this->cacheDirUrl = "{$basePath}{$cacheDir}";
     if (isset($this->parameters->dirs->domainDir)) {
         $domainDir = $this->parameters->dirs->domainDir;
         $this->domainDir = $domainDir;
     }
     $this->domainDirUrl = rtrim($url->baseUrl, '/');
     FileSystem::createDir($this->cacheDir);
     return $this;
 }
Exemplo n.º 19
0
 public function __construct($imageTempDir, $wwwImageTemp, $sourceDir, Http\Request $request)
 {
     if ($wwwImageTemp && substr($wwwImageTemp, -1) == '/') {
         $wwwImageTemp = rtrim($wwwImageTemp, '/');
     }
     $this->imageTempDir = $imageTempDir;
     $this->wwwImageTemp = $wwwImageTemp;
     $this->sourceDir = $sourceDir;
     $url = $request->getUrl();
     $this->basePath = $url->getBasePath();
     $this->hostUrl = $url->getHostUrl();
 }
Exemplo n.º 20
0
 /**
  * @return void
  */
 private function returnBack()
 {
     $currentUrl = $this->request->getUrl();
     $refererUrl = $this->request->getReferer();
     if ($refererUrl === NULL) {
         throw new \RuntimeException('Unable to redirect back because your browser did not send referrer');
     } elseif ($refererUrl->isEqual($currentUrl)) {
         throw new \RuntimeException('Unable to redirect back because it would create loop');
     }
     header('Location: ' . $refererUrl);
     exit;
 }
Exemplo n.º 21
0
 /**
  * Returns the Current URL, stripping it of known FB parameters that should
  * not persist.
  *
  * @internal
  * @return \Nette\Http\UrlScript The current URL
  */
 public function getCurrentUrl()
 {
     $url = clone $this->httpRequest->getUrl();
     if ($this->config->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
         $url->setHost($_SERVER['HTTP_X_FORWARDED_HOST']);
     }
     if ($this->config->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
         $url->setScheme($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ? 'https' : 'http');
     }
     parse_str($url->getQuery(), $query);
     $query = array_diff_key($query, array_flip($this->config->dropQueryParams));
     $url->setQuery($query);
     return $url;
 }
Exemplo n.º 22
0
 /**
  * @param \TpMerchantConfig $config
  * @param IWriter $writer
  * @param Request $request
  */
 public function __construct(\TpMerchantConfig $config, IWriter $writer = NULL, Request $request = NULL)
 {
     try {
         if ($request) {
             parent::__construct($config, $request->getUrl()->getQueryParameters());
         } else {
             parent::__construct($config);
         }
     } catch (\TpMissingParameterException $e) {
         $this->error = $e;
     }
     $this->writer = $writer;
     if ($this->writer) {
         $this->writer->setReceiver($this);
     }
 }
 /**
  * Najdi aktuální Node z httpRequestu
  * @param RecursiveComponentIterator $components
  * @param \Illagrenan\Navigation\NavigationNode $base
  * @return \Illagrenan\Navigation\NavigationNode|boolean
  */
 private function findCurrent(RecursiveIteratorIterator $components, NavigationNode $base)
 {
     $currentUrl = $this->httpRequest->getUrl();
     /* @var $oneNode NavigationNode */
     foreach ($components as $oneNode) {
         // Node využívá plink
         if ($oneNode->isPlinkPresent() && $oneNode->getPlink() == $this->getCurrentNetteRequest()) {
             return $oneNode;
         } elseif ($currentUrl->isEqual($oneNode->getUrl())) {
             return $oneNode;
         }
     }
     // Aktuální node může být ta, která se ptá
     // Node využívá plink
     if ($base->isPlinkPresent() && $base->getPlink() == $this->getCurrentNetteRequest()) {
         return $base;
     } elseif ($currentUrl->isEqual($base->getUrl())) {
         return $base;
     }
     return FALSE;
 }
Exemplo n.º 24
0
 /**
  * @param Url $refUrl
  * @param IRouter $router
  */
 public function __construct(Request $request, Application\IRouter $router)
 {
     //	$this->refUrl = $refUrl;
     $this->refUrl = new Url($request->getUrl());
     $this->router = $router;
 }
Exemplo n.º 25
0
 /**
  * @return string
  */
 protected function getBaseUrl()
 {
     return rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/');
 }
Exemplo n.º 26
0
 public static function getBasePath(\Nette\Http\Request $request)
 {
     return rtrim($request->getUrl()->getBasePath(), '/');
 }
 /**
  * @param \Nette\Http\Request
  */
 public function log(\Nette\Http\Request $req)
 {
     $this->server->send('access', array('ua' => $req->getHeader('User-Agent'), 'ip' => $req->getRemoteAddress(), 'host' => $req->getRemoteHost(), 'method' => $req->getMethod(), 'url' => (string) $req->getUrl(), 'memory' => function_exists('memory_get_peak_usage') ? number_format(memory_get_peak_usage() / 1000000, 2, '.', ' ') : 'n/a', 'time' => number_format((microtime(TRUE) - \Nette\Diagnostics\Debugger::$time) * 1000, 1, '.', ' '), 'referer' => (string) $req->getHeader('Referer')));
 }
Exemplo n.º 28
0
 public function getUrl()
 {
     return $this->request->getUrl();
 }
Exemplo n.º 29
0
 /**
  * @param \Nette\Http\Request $request
  * @return string
  */
 private function detectFormat(HttpRequest $request)
 {
     $header = $request->getHeader('Accept');
     // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
     foreach ($this->formats as $format => $fullFormatName) {
         $fullFormatName = Strings::replace($fullFormatName, '/\\//', '\\/');
         if (Strings::match($header, "/{$fullFormatName}/")) {
             return $format;
         }
     }
     // Try retrieve fallback from URL.
     $path = $request->getUrl()->getPath();
     $formats = array_keys($this->formats);
     $formats = implode('|', $formats);
     if (Strings::match($path, "/\\.({$formats})\$/")) {
         list($path, $format) = explode('.', $path);
         return $format;
     }
     return $this->defaultFormat;
 }
Exemplo n.º 30
0
 public function setImageFileRoot($imageRoot)
 {
     $this->fileRoot = $this->request->getUrl()->getBaseUrl() . $imageRoot;
 }