getHost() public method

Returns the host part of URI.
public getHost ( ) : string
return string
 /**
  * Funkce pro odeslání GET požadavku bez čekání na získání odpovědi
  * @param string $url
  * @throws \Exception
  */
 public static function sendBackgroundGetRequest($url)
 {
     $url = new Url($url);
     $host = $url->getHost();
     if (empty($host)) {
         $host = 'localhost';
     }
     #region parametry připojení
     switch ($url->getScheme()) {
         case 'https':
             $scheme = 'ssl://';
             $port = 443;
             break;
         case 'http':
         default:
             $scheme = '';
             $port = 80;
     }
     $urlPort = $url->getPort();
     if (!empty($urlPort)) {
         $port = $urlPort;
     }
     #endregion
     $fp = @fsockopen($scheme . $host, $port, $errno, $errstr, self::REQUEST_TIMEOUT);
     if (!$fp) {
         Debugger::log($errstr, ILogger::ERROR);
         throw new \Exception($errstr, $errno);
     }
     $path = $url->getPath() . ($url->getQuery() != "" ? '?' . $url->getQuery() : '');
     fputs($fp, "GET " . $path . " HTTP/1.0\r\nHost: " . $host . "\r\n\r\n");
     fputs($fp, "Connection: close\r\n");
     fputs($fp, "\r\n");
 }
Ejemplo n.º 2
0
 private function process($url, string $directory, string $parameter, array &$dependencies = []) : string
 {
     $url = new Nette\Http\Url($url);
     $time = NULL;
     if ($url->getHost() && (!$this->request || $url->getHost() !== $this->request->getUrl()->getHost())) {
         $headers = @get_headers($url, TRUE);
         if (is_array($headers) && isset($headers['Last-Modified'])) {
             $time = (new DateTime($headers['Last-Modified']))->getTimestamp();
         }
     } elseif (is_file($filename = implode(DIRECTORY_SEPARATOR, [rtrim($directory, '\\/'), ltrim($url->getPath(), '\\/')]))) {
         $time = filemtime($filename);
         unset($dependencies[Nette\Caching\Cache::EXPIRE]);
         $dependencies[Nette\Caching\Cache::FILES] = $filename;
     }
     $url->setQueryParameter($parameter, $time ?: ($this->time ?: ($this->time = time())));
     return preg_replace($pattern = '#^(\\+|/+)#', preg_match($pattern, $url->getPath()) ? DIRECTORY_SEPARATOR : NULL, $url);
 }
Ejemplo n.º 3
0
 public function createComponentPlayer()
 {
     $host = explode(".", $this->playUrl->getHost());
     $provider = Nette\Utils\Strings::lower($host[count($host) - 2]);
     $handler = "\\App\\Controls\\" . ucfirst($provider) . "Player";
     if (class_exists($handler)) {
         $player = new $handler($this->playUrl);
     } else {
         $player = new \App\Controls\NoPlayer($this->playUrl);
     }
     return $player;
 }
 /**
  * Funkce pro doplnění základních parametrů do API
  * @param string $jsonString
  * @return string
  */
 private function replaceJsonVariables($jsonString)
 {
     $link = $this->link('//Default:default');
     $url = new Url($link);
     if (empty($url->host)) {
         $url = $this->getHttpRequest()->getUrl()->hostUrl;
         if (Strings::endsWith($url, '/')) {
             rtrim($url, '/');
         }
         $url .= $link;
         $url = new Url($url);
     }
     $hostUrl = Strings::endsWith($url->getHost(), '/') ? rtrim($url->getHost(), '/') : $url->getHost();
     $basePath = rtrim($url->getBasePath(), '/');
     $paramsArr = ['%VERSION%' => $this->getInstallVersion(), '%BASE_PATH%' => $basePath, '%HOST%' => $hostUrl];
     $arrSearch = [];
     $arrReplace = [];
     foreach ($paramsArr as $key => $value) {
         $arrSearch[] = $key;
         $arrReplace[] = $value;
     }
     return str_replace($arrSearch, $arrReplace, $jsonString);
 }
 /**
  * Constructs absolute URL from Request object.
  * @return string|NULL
  */
 public function constructUrl(Application\Request $appRequest, Nette\Http\Url $refUrl)
 {
     if ($this->flags & self::ONE_WAY) {
         return NULL;
     }
     $params = $appRequest->getParameters();
     $metadata = $this->metadata;
     $presenter = $appRequest->getPresenterName();
     $params[self::PRESENTER_KEY] = $presenter;
     if (isset($metadata[NULL][self::FILTER_OUT])) {
         $params = call_user_func($metadata[NULL][self::FILTER_OUT], $params);
         if ($params === NULL) {
             return NULL;
         }
     }
     if (isset($metadata[self::MODULE_KEY])) {
         // try split into module and [submodule:]presenter parts
         $module = $metadata[self::MODULE_KEY];
         if (isset($module['fixity']) && strncasecmp($presenter, $module[self::VALUE] . ':', strlen($module[self::VALUE]) + 1) === 0) {
             $a = strlen($module[self::VALUE]);
         } else {
             $a = strrpos($presenter, ':');
         }
         if ($a === FALSE) {
             $params[self::MODULE_KEY] = '';
         } else {
             $params[self::MODULE_KEY] = substr($presenter, 0, $a);
             $params[self::PRESENTER_KEY] = substr($presenter, $a + 1);
         }
     }
     foreach ($metadata as $name => $meta) {
         if (!isset($params[$name])) {
             continue;
             // retains NULL values
         }
         if (isset($meta['fixity'])) {
             if ($params[$name] === FALSE) {
                 $params[$name] = '0';
             }
             if (is_scalar($params[$name]) ? strcasecmp($params[$name], $meta[self::VALUE]) === 0 : $params[$name] === $meta[self::VALUE]) {
                 // remove default values; NULL values are retain
                 unset($params[$name]);
                 continue;
             } elseif ($meta['fixity'] === self::CONSTANT) {
                 return NULL;
                 // missing or wrong parameter '$name'
             }
         }
         if (is_scalar($params[$name]) && isset($meta['filterTable2'][$params[$name]])) {
             $params[$name] = $meta['filterTable2'][$params[$name]];
         } elseif (isset($meta['filterTable2']) && !empty($meta[self::FILTER_STRICT])) {
             return NULL;
         } elseif (isset($meta[self::FILTER_OUT])) {
             $params[$name] = call_user_func($meta[self::FILTER_OUT], $params[$name]);
         }
         if (isset($meta[self::PATTERN]) && !preg_match($meta[self::PATTERN], rawurldecode($params[$name]))) {
             return NULL;
             // pattern not match
         }
     }
     // compositing path
     $sequence = $this->sequence;
     $brackets = array();
     $required = NULL;
     // NULL for auto-optional
     $url = '';
     $i = count($sequence) - 1;
     do {
         $url = $sequence[$i] . $url;
         if ($i === 0) {
             break;
         }
         $i--;
         $name = $sequence[$i];
         $i--;
         // parameter name
         if ($name === ']') {
             // opening optional part
             $brackets[] = $url;
         } elseif ($name[0] === '[') {
             // closing optional part
             $tmp = array_pop($brackets);
             if ($required < count($brackets) + 1) {
                 // is this level optional?
                 if ($name !== '[!') {
                     // and not "required"-optional
                     $url = $tmp;
                 }
             } else {
                 $required = count($brackets);
             }
         } elseif ($name[0] === '?') {
             // "foo" parameter
             continue;
         } elseif (isset($params[$name]) && $params[$name] != '') {
             // intentionally ==
             $required = count($brackets);
             // make this level required
             $url = $params[$name] . $url;
             unset($params[$name]);
         } elseif (isset($metadata[$name]['fixity'])) {
             // has default value?
             if ($required === NULL && !$brackets) {
                 // auto-optional
                 $url = '';
             } else {
                 $url = $metadata[$name]['defOut'] . $url;
             }
         } else {
             return NULL;
             // missing parameter '$name'
         }
     } while (TRUE);
     // absolutize path
     if ($this->type === self::RELATIVE) {
         $url = '//' . $refUrl->getAuthority() . $refUrl->getBasePath() . $url;
     } elseif ($this->type === self::PATH) {
         $url = '//' . $refUrl->getAuthority() . $url;
     } else {
         $host = $refUrl->getHost();
         $host = ip2long($host) ? array($host) : array_reverse(explode('.', $host));
         $url = strtr($url, array('/%basePath%/' => $refUrl->getBasePath(), '%tld%' => $host[0], '%domain%' => isset($host[1]) ? "{$host['1']}.{$host['0']}" : $host[0]));
     }
     if (strpos($url, '//', 2) !== FALSE) {
         return NULL;
     }
     $url = ($this->flags & self::SECURED ? 'https:' : 'http:') . $url;
     // build query string
     if ($this->xlat) {
         $params = self::renameKeys($params, $this->xlat);
     }
     $sep = ini_get('arg_separator.input');
     $query = http_build_query($params, '', $sep ? $sep[0] : '&');
     if ($query != '') {
         // intentionally ==
         $url .= '?' . $query;
     }
     return $url;
 }
Ejemplo n.º 6
0
 /**
  * @param Request $appRequest
  * @param Url $refUrl
  * @return null|string
  */
 public function constructUrl(Request $appRequest, Url $refUrl)
 {
     // one way can't generate link
     if ($this->options['oneWay']) {
         return NULL;
     }
     $params = $this->clearParameters($appRequest->getParameters());
     $action = new Action($appRequest->getPresenterName() . ':' . $appRequest->getParameter('action'), $params);
     // ISource return NULL, not found url to generate
     if (($seoUrl = $this->source->toUrl($action)) === NULL) {
         return NULL;
     }
     if (!$seoUrl instanceof Url) {
         $seoUrl = new Url($seoUrl);
     }
     // host
     if ($seoUrl->getHost()) {
         $host = $refUrl->getHost();
         $parts = ip2long($host) ? [$host] : array_reverse(explode('.', $host));
         $host = strtr($seoUrl->getHost(), ['%tld%' => $parts[0], '%domain%' => isset($parts[1]) ? "{$parts['1']}.{$parts['0']}" : $parts[0], '%sld%' => isset($parts[1]) ? $parts[1] : '', '%host%' => $refUrl->getHost()]);
     } else {
         $host = $refUrl->getHost();
     }
     // path
     $path = $seoUrl->getPath();
     // query
     $query = $seoUrl->getQueryParameters() + $params;
     ksort($query);
     $seoUrl->setQuery($query);
     $query = $seoUrl->getQuery();
     // fragment
     $fragment = $seoUrl->getFragment();
     return ($this->options['secured'] ? 'https' : 'http') . '://' . $host . $refUrl->getBasePath() . ($path === '/' ? '' : $path) . ($query ? '?' . $query : '') . ($fragment ? '#' . $fragment : '');
 }
Ejemplo n.º 7
0
 /**
  * Constructs absolute URL from Request object.
  *
  * @return string|NULL
  */
 public function constructUrl(App\Request $appRequest, Http\Url $refUrl)
 {
     $params = $appRequest->getParameters();
     $query = $params;
     unset($query['action'], $query['page_id'], $query['slug'], $query['id'], $query['locale'], $query['prefix']);
     if (isset($params['slug'])) {
         $slug = strtolower($params['slug']);
     } else {
         if (isset($params['page_id'])) {
             $row = $this->slugManager->getSlugById($params['page_id']);
             // todo peekay Change cs for selected language
             if (isset($query['locale'])) {
                 unset($params['locale']);
             }
             if ($row) {
                 if (isset($params['locale'])) {
                     $slug = $row->{'slug_' . $params['locale']};
                 } else {
                     $slug = $row->{'slug'};
                 }
             } else {
                 return NULL;
             }
         } else {
             return NULL;
         }
     }
     if (isset($params['locale'])) {
         $locale = $params['locale'] . '/';
     } else {
         $locale = null;
     }
     if (isset($params['prefix'])) {
         $prefix = $params['prefix'] . '/';
     } else {
         $prefix = null;
     }
     $url = $refUrl->getScheme() . '://' . $refUrl->getHost() . $refUrl->getPath() . $locale . $prefix . $slug;
     $params = $appRequest->getParameters();
     if (isset($params['action']) && $params['action'] !== 'default') {
         $url .= $refUrl->getPath();
     }
     if (isset($params['id'])) {
         if ($params['action'] == 'default' && isset($params['action'])) {
             $url .= $refUrl->getPath();
         }
         $url .= $refUrl->getPath() . $params['id'];
     }
     if (count($query) > 0) {
         $queryString = '?';
         foreach ($query as $key => $parameter) {
             $queryString .= $key . '=' . $parameter . '&';
         }
         $finalQueryString = substr($queryString, 0, -1);
         $url .= $finalQueryString;
     }
     return $url;
 }
Ejemplo n.º 8
0
 /**
  * Constructs absolute URL from Request object.
  * @return string|NULL
  */
 public function constructUrl(array $params, Nette\Http\Url $refUrl)
 {
     if ($this->flags & self::ONE_WAY) {
         return NULL;
     }
     $metadata = $this->metadata;
     if (isset($metadata[NULL][self::FILTER_OUT])) {
         $params = call_user_func($metadata[NULL][self::FILTER_OUT], $params);
         if ($params === NULL) {
             return NULL;
         }
     }
     foreach ($metadata as $name => $meta) {
         if (!isset($params[$name])) {
             continue;
             // retains NULL values
         }
         if (isset($meta['fixity'])) {
             if ($params[$name] === FALSE) {
                 $params[$name] = '0';
             } elseif (is_scalar($params[$name])) {
                 $params[$name] = (string) $params[$name];
             }
             if ($params[$name] === $meta[self::VALUE]) {
                 // remove default values; NULL values are retain
                 unset($params[$name]);
                 continue;
             } elseif ($meta['fixity'] === self::CONSTANT) {
                 return NULL;
                 // missing or wrong parameter '$name'
             }
         }
         if (is_scalar($params[$name]) && isset($meta['filterTable2'][$params[$name]])) {
             $params[$name] = $meta['filterTable2'][$params[$name]];
         } elseif (isset($meta['filterTable2']) && !empty($meta[self::FILTER_STRICT])) {
             return NULL;
         } elseif (isset($meta[self::FILTER_OUT])) {
             $params[$name] = call_user_func($meta[self::FILTER_OUT], $params[$name]);
         }
         if (isset($meta[self::PATTERN]) && !preg_match($meta[self::PATTERN], rawurldecode($params[$name]))) {
             return NULL;
             // pattern not match
         }
     }
     // compositing path
     $sequence = $this->sequence;
     $brackets = [];
     $required = NULL;
     // NULL for auto-optional
     $url = '';
     $i = count($sequence) - 1;
     do {
         $url = $sequence[$i] . $url;
         if ($i === 0) {
             break;
         }
         $i--;
         $name = $sequence[$i];
         $i--;
         // parameter name
         if ($name === ']') {
             // opening optional part
             $brackets[] = $url;
         } elseif ($name[0] === '[') {
             // closing optional part
             $tmp = array_pop($brackets);
             if ($required < count($brackets) + 1) {
                 // is this level optional?
                 if ($name !== '[!') {
                     // and not "required"-optional
                     $url = $tmp;
                 }
             } else {
                 $required = count($brackets);
             }
         } elseif ($name[0] === '?') {
             // "foo" parameter
             continue;
         } elseif (isset($params[$name]) && $params[$name] != '') {
             // intentionally ==
             $required = count($brackets);
             // make this level required
             $url = $params[$name] . $url;
             unset($params[$name]);
         } elseif (isset($metadata[$name]['fixity'])) {
             // has default value?
             if ($required === NULL && !$brackets) {
                 // auto-optional
                 $url = '';
             } else {
                 $url = $metadata[$name]['defOut'] . $url;
             }
         } else {
             return NULL;
             // missing parameter '$name'
         }
     } while (TRUE);
     if ($this->type === self::HOST) {
         $host = $refUrl->getHost();
         $parts = ip2long($host) ? [$host] : array_reverse(explode('.', $host));
         $url = strtr($url, ['/%basePath%/' => $refUrl->getBasePath(), '%tld%' => $parts[0], '%domain%' => isset($parts[1]) ? "{$parts['1']}.{$parts['0']}" : $parts[0], '%sld%' => isset($parts[1]) ? $parts[1] : '', '%host%' => $host]);
         $url = ($this->scheme ?: $refUrl->getScheme()) . ':' . $url;
     } else {
         if ($this->lastRefUrl !== $refUrl) {
             $scheme = $this->scheme ?: $refUrl->getScheme();
             $basePath = $this->type === self::RELATIVE ? $refUrl->getBasePath() : '';
             $this->lastBaseUrl = $scheme . '://' . $refUrl->getAuthority() . $basePath;
             $this->lastRefUrl = $refUrl;
         }
         $url = $this->lastBaseUrl . $url;
     }
     if (strpos($url, '//', 7) !== FALSE) {
         return NULL;
     }
     // build query string
     if ($this->xlat) {
         $params = self::renameKeys($params, $this->xlat);
     }
     $sep = ini_get('arg_separator.input');
     $query = http_build_query($params, '', $sep ? $sep[0] : '&');
     if ($query != '') {
         // intentionally ==
         $url .= '?' . $query;
     }
     return $url;
 }