/** * @param string $unsubscribeLink * @return $this * @throws EmailException */ public function unsubscribeLink($unsubscribeLink) { if (!Nette\Utils\Validators::isUrl($unsubscribeLink)) { throw new EmailException('Email is not valid', EmailException::INVALID_EMAIL); } $this->unsubscribeLink = $unsubscribeLink; return $this; }
/** * @param Github $github */ protected function reformatMarkdownLinks(Github $github) { $github->content = Strings::replace($github->content, '#\\[(.*)\\]\\((.+)\\)#iU', function ($matches) use($github) { list($all, $title, $url) = $matches; if (!Validators::isUrl($url)) { $url = $github->linker->getBlobUrl($matches[2]); } return sprintf('[%s](%s)', $title, $url); }); }
/** * Redirects using JavaScript. * @param string $url * @return void */ public static function redirectUrl($url) { if (FALSE === Validators::isUrl($url)) { throw new \Nette\InvalidArgumentException($url . " is not valid URL."); } $template = new FileTemplate(dirname(__FILE__) . '/' . self::$TEMPLATE_DIR . '/iframeRedirect.latte'); $template->registerHelperLoader('Nette\\Templating\\Helpers::loader'); $template->registerFilter(new \Nette\Latte\Engine()); $template->url = $url; $template->render(); exit; }
/** * Get Image from source * @param mixed $source Source of image * @return array|NULL ["image" => Nette\Utils\Image, "filename" => string] */ public function getImageInfo($source) { if (is_string($source)) { foreach ($this->dirs as $dir) { if (file_exists($dir . $source)) { $path_parts = pathinfo($source); $filename = $path_parts['filename']; return ["image" => Image::fromFile($dir . $source), "filename" => $filename, "lazy" => TRUE, "params" => ["dir" => $path_parts['dirname'], "ext" => $path_parts['extension']]]; } elseif (Validators::isUrl($source)) { return ["image" => Image::fromFile($source), "filename" => basename($source)]; } } } }
public function pingback_ping($source, $target) { if (!Validators::isUrl($source)) { return $this->xmlrpc_fault(self::RESPONSE_FAULT_SOURCE); } if (!Validators::isUrl($target)) { return $this->xmlrpc_fault(self::RESPONSE_FAULT_TARGET); } $curl = curl_init($target); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $headers = http_parse_headers(curl_exec($curl)); curl_close($curl); if (isset($headers['X-Pingback']) && !empty($headers['X-Pingback'])) { $this->pingback_url = $headers['X-Pingback']; } else { if (preg_match(self::REGEXP_PINGBACK_LINK, file_get_contents($target), $match)) { $this->pingback_url = $match[1]; } else { return $this->xmlrpc_fault(self::RESPONSE_FAULT_TARGET_INVALID); } } $content = file_get_contents($source); if ($content !== false) { $doc = new \DOMDocument(); @$doc->loadHTML($content); foreach ($doc->getElementsByTagName('a') as $link) { if ($link->getAttribute('href') == $target) { break; } } } else { return $this->xmlrpc_fault(self::RESPONSE_FAULT_SOURCE_LINK); } return xmlrpc_encode([$this->responses[self::RESPONSE_SUCCESS]]); //musí odkazovat na post id //pokud v databázi neexistuje záznam o pingback, pak přistoupit na vzdálenou stránku //parsování titulku ze vzdálené stránky }
/** * Is control's value valid URL? * @return bool */ public static function validateUrl(IControl $control) { if (Validators::isUrl($value = $control->getValue())) { return TRUE; } elseif (Validators::isUrl($value = "http://{$value}")) { $control->setValue($value); return TRUE; } return FALSE; }
/** * Validate URL * @param string $value * @param Rule $rule * @throws ValidationException */ public static function validateUrl($value, Rule $rule) { if (!Validators::isUrl($value)) { throw ValidationException::createFromRule($rule, $value); } }
/** * URL validator: is control's value valid URL? * @param TextBase * @return bool */ public static function validateUrl(TextBase $control) { return Validators::isUrl($control->getValue()) || Validators::isUrl('http://' . $control->getValue()); }
/** * @param $destination * @param array $args * @return BrowserSession|Nette\Application\Request */ public function presenter($destination = NULL, $args = array()) { if ($destination !== NULL) { if (preg_match('~^\\:?([a-z0-9_]+)(:[a-z0-9_]+)*\\:?$~i', $destination)) { $args = array(0 => '//' . ltrim($destination, '/')) + func_get_args(); $url = new Nette\Http\UrlScript(call_user_func_array(array($this->linkGenerator, 'link'), $args)); } elseif (Nette\Utils\Validators::isUrl($destination)) { $url = new Nette\Http\UrlScript($destination); } else { $url = clone $this->httpServerUrl; $url->setPath($destination); } $this->url((string) $url); return $this; } $appRequest = NULL; $currentUrl = new Nette\Http\UrlScript($this->url()); parse_str($currentUrl->query, $query); $router = $this->serviceLocator->getByType('Nette\\Application\\IRouter'); /** @var Nette\Application\IRouter[]|Nette\Application\IRouter $router */ if (!class_exists('Kdyby\\Console\\CliRouter')) { $appRequest = $router->match(new Nette\Http\Request($currentUrl, $query, array(), array(), array(), array(), 'GET')); } else { foreach ($router as $route) { if ($route instanceof Kdyby\Console\CliRouter || $route instanceof Nette\Application\Routers\CliRouter) { continue; } if ($appRequest = $route->match(new Nette\Http\Request($currentUrl, $query, array(), array(), array(), array(), 'GET'))) { break; } } } return $appRequest; }
/** * @param string $value * @return string */ private function processLinkAnnotations($value) { list($url, $description) = Strings::split($value); if (Validators::isUrl($url)) { return $this->linkBuilder->build($url, $description ?: $url); } return null; }
public function isUrl() { return Validators::isUrl($this->link) or preg_match('~^/[^/]~', $this->link) or $this->link[0] == '#'; }
/** * URL string cleanup. * @param string * @return string */ public static function filterUrl($s) { return Validators::isUrl('http://' . $s) ? 'http://' . $s : $s; }
/** * Resolves links in documentation. * * @param string $text Processed documentation text * @param \ApiGen\ReflectionElement $context Reflection object * * @return string */ private function resolveLinks($text, ReflectionElement $context) { $that = $this; return preg_replace_callback('~{@(?:link|see)\\s+([^}]+)}~', function ($matches) use($context, $that) { // Texy already added <a> so it has to be stripped list($url, $description) = $that->split(strip_tags($matches[1])); if (Nette\Utils\Validators::isUrl($url)) { return $that->link($url, $description ?: $url); } return $that->resolveLink($matches[1], $context) ?: $matches[1]; }, $text); }
/** * Nastaví URL na kterou bude uživatel z Facebook.com přesměrován * Přijímá nette zápis odkazů (např.: Homepage:default) nebo absolutní URL * @param string $redirectUri * @throws \Nette\InvalidArgumentException * @return void */ public function setRedirectUri($redirectUri) { /* @var $currentPresenter \Nette\Application\UI\Presenter */ $currentPresenter = $this->application->getPresenter(); $netteAbsoluteLinkPrexix = "//"; try { if (\Nette\Utils\Strings::startsWith($redirectUri, "//")) { $netteAbsoluteLinkPrexix = ""; } $absoluteUri = $currentPresenter->link($netteAbsoluteLinkPrexix . $redirectUri); if (\Nette\Utils\Strings::startsWith($absoluteUri, "error:")) { throw new \Nette\Application\UI\InvalidLinkException(); } } catch (\Nette\Application\UI\InvalidLinkException $exc) { if (Validators::isUrl($redirectUri) === TRUE) { $absoluteUri = $redirectUri; } else { throw new Exceptions\InvalidRedirectUriException("Given \"" . $redirectUri . "\" is not valid absolute URL or nette link."); } } $this->redirectUri = $absoluteUri; }
/** * @return string */ public function getUrl() { if ($this->isAutoUrl() && isset($this->request)) { $url = $this->request->url; } else { $url = $this->url; } if (Validators::isUrl($url)) { return $url; } else { trigger_error('Url "' . $url . '" is not valid url address.!', E_USER_WARNING); } }
/** * @param $unsubscribeLink * @throws \Exception */ public function setUnsubscribeLink($unsubscribeLink) { if (!Validators::isUrl($unsubscribeLink)) { throw new \Exception("Link has bad format"); } $this->unsubscribeLink = $unsubscribeLink; }