作者:vbuilde
项目:framewor
public function render($rowData)
{
if ($this->_renderer) {
return call_user_func($this->_renderer, $this);
}
// Direct URL
if ($this->_url !== NULL) {
// URL callback
if (is_callable($this->_url)) {
$url = call_user_func($this->_url, $rowData);
} else {
$url = new Nette\Http\Url($this->_url);
foreach ($this->_table->getIdColumns() as $key) {
$url->appendQuery(array('record' . ucfirst($key) => isset($rowData->{$key}) ? $rowData->{$key} : NULL));
}
}
$this->element->href((string) $url);
// Standard action's URL
} else {
$this->element->href($this->_table->createActionLink($this->getName(), $rowData));
}
// Class
if (($class = $this->getClass($rowData)) !== NULL) {
$this->element->class .= " {$class}";
}
return (string) $this->element;
}
作者:bauer0
项目:unimapper-nett
public function constructUrl(Request $appRequest, Url $refUrl)
{
// Module prefix not match.
if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
return null;
}
$params = $appRequest->getParameters();
$urlStack = [];
// Module prefix
$moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName()));
$resourceName = array_pop($moduleFrags);
$urlStack += $moduleFrags;
// Resource
$urlStack[] = Strings::lower($resourceName);
// Id
if (isset($params['id']) && is_scalar($params['id'])) {
$urlStack[] = $params['id'];
unset($params['id']);
}
// Set custom action
if (isset($params['action']) && $this->_isApiAction($params['action'])) {
unset($params['action']);
}
$url = $refUrl->getBaseUrl() . implode('/', $urlStack);
// Add query parameters
if (!empty($params)) {
$url .= "?" . http_build_query($params);
}
return $url;
}
作者:metisf
项目:adye
/**
* @param Payment $payment
* @return Payment
*/
public static function addTrackingParameters(Payment $payment)
{
$resURL = $payment->getResURL();
$url = new Url($resURL);
$url->setQueryParameter('utm_nooverride', 1);
$payment->setResURL($url->getAbsoluteUrl());
return $payment;
}
作者:metisf
项目:paypa
public static function addTrackingParameters(Payment $payment)
{
$redirectUrls = $payment->getRedirectUrls();
$url = new Url($redirectUrls->getReturnUrl());
$url->setQueryParameter('utm_nooverride', 1);
$redirectUrls->setReturnUrl($url->getAbsoluteUrl());
$payment->setRedirectUrls($redirectUrls);
return $payment;
}
作者:nextra
项目:youtube-ap
/**
* Fetches video data by youtube url
* @param string $videoUrl YouTube url
* @return Video
*/
public function getVideoByUrl($videoUrl)
{
$url = new Nette\Http\Url($videoUrl);
if (stripos($url->host, 'youtu.be') !== false) {
return $this->getVideo(trim($url->getPath(), '/'));
}
$videoId = $url->getQueryParameter('v');
if (stripos($url->host, 'youtube.com') === false || $videoId === null) {
throw new Nette\InvalidArgumentException('videoUrl must be valid youtube url.');
}
return $this->getVideo($videoId);
}
作者:enuma
项目:applicatio
/**
* Restores request from session.
* @param string $key
*/
public function redirectToRequest($key)
{
$request = $this->requestStorage->loadRequest($key);
if (!$request) {
return;
}
$parameters = $request->getParameters();
$parameters[Presenter::FLASH_KEY] = $this->getParameter(Presenter::FLASH_KEY);
$parameters[RequestStorage::REQUEST_KEY] = $key;
$request->setParameters($parameters);
$refUrl = new Url($this->httpRequest->getUrl());
$refUrl->setPath($this->httpRequest->getUrl()->getScriptPath());
$url = $this->router->constructUrl($request, $refUrl);
$this->redirectUrl($url);
}
作者:TheTypoMaste
项目:SPHERE-Framewor
/**
* Constructs absolute URL from Request object.
*
* @param Nette\Application\Request
* @param Nette\Http\Url
*
* @return string|NULL
*/
public function constructUrl(Application\Request $appRequest, Nette\Http\Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return null;
}
$params = $appRequest->getParameters();
// presenter name
$presenter = $appRequest->getPresenterName();
if (strncasecmp($presenter, $this->module, strlen($this->module)) === 0) {
$params[self::PRESENTER_KEY] = substr($presenter, strlen($this->module));
} else {
return null;
}
// remove default values; NULL values are retain
foreach ($this->defaults as $key => $value) {
if (isset($params[$key]) && $params[$key] == $value) {
// intentionally ==
unset($params[$key]);
}
}
$url = ($this->flags & self::SECURED ? 'https://' : 'http://') . $refUrl->getAuthority() . $refUrl->getPath();
$sep = ini_get('arg_separator.input');
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
if ($query != '') {
// intentionally ==
$url .= '?' . $query;
}
return $url;
}
作者:webchemistr
项目:forms-control
/**
* @return bool
*/
public function validateRecaptcha()
{
$httpData = $this->getForm()->getHttpData();
if (!isset($httpData['g-recaptcha-response'])) {
$this->addError($this->getFilledMessage());
return TRUE;
}
$this->validateKeys();
$url = new Url();
$url->setHost('www.google.com')->setScheme('https')->setPath('recaptcha/api/siteverify')->setQueryParameter('secret', $this->secretKey)->setQueryParameter('response', $httpData['g-recaptcha-response']);
$data = json_decode(file_get_contents((string) $url));
if (!isset($data->success) || $data->success !== TRUE) {
$this->addError($this->getValidMessage());
}
return TRUE;
}
作者:newPOP
项目:web-addons.nette.or
/**
* Calls remote API.
*
* @param string
* @return mixed json-decoded result
* @throws \NetteAddons\IOException
*/
protected function exec($path)
{
try {
$url = new Url($this->baseUrl . '/' . ltrim($path, '/'));
if ($this->clientId && $this->clientSecret) {
$url->appendQuery(array('client_id' => $this->clientId, 'client_secret' => $this->clientSecret));
}
$request = $this->requestFactory->create($url);
$request->addHeader('Accept', "application/vnd.github.{$this->apiVersion}+json");
return \Nette\Utils\Json::decode($request->execute());
} catch (\NetteAddons\Utils\StreamException $e) {
throw new \NetteAddons\IOException('Request execution failed.', NULL, $e);
} catch (\Nette\Utils\JsonException $e) {
throw new \NetteAddons\IOException('GitHub API returned invalid JSON.', NULL, $e);
}
}
作者:vitkutn
项目:versio
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);
}
作者:enuma
项目:WebChemistry-Forms-Control
public function validateRecaptcha()
{
$httpData = $this->getForm()->getHttpData();
if (!isset($httpData['g-recaptcha-response'])) {
$this->addError('Please fill antispam.');
return TRUE;
}
$url = new Url();
$url->setHost('www.google.com')->setScheme('https')->setPath('recaptcha/api/siteverify')->setQueryParameter('secret', $this->secretKey)->setQueryParameter('response', $httpData['g-recaptcha-response']);
$data = json_decode(file_get_contents((string) $url));
if (isset($data->success) && $data->success === TRUE) {
return TRUE;
} else {
$this->addError('Antispam detection wasn\'t success.');
return TRUE;
}
}
作者:kiz
项目:easyminer-easyminercente
/**
* 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");
}
作者:sg3teste
项目:songato
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;
}
作者:nett
项目:routin
/**
* 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;
}
// remove default values; NULL values are retain
foreach ($this->defaults as $key => $value) {
if (isset($params[$key]) && $params[$key] == $value) {
// intentionally ==
unset($params[$key]);
}
}
$url = ($this->flags & self::SECURED ? 'https://' : $refUrl->getScheme() . '://') . $refUrl->getAuthority() . $refUrl->getPath();
$sep = ini_get('arg_separator.input');
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
if ($query != '') {
// intentionally ==
$url .= '?' . $query;
}
return $url;
}
作者:nextra
项目:static-route
/**
* Constructs absolute URL from Request object.
*
* @return string|NULL
*/
public function constructUrl(AppRequest $appRequest, Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return NULL;
}
$params = $appRequest->getParameters();
if (!isset($params['action']) || !is_string($params['action'])) {
return NULL;
}
$key = $appRequest->getPresenterName() . ':' . $params['action'];
if (!isset($this->tableOut[$key])) {
return NULL;
}
if ($this->lastRefUrl !== $refUrl) {
$this->lastBaseUrl = $refUrl->getBaseUrl();
$this->lastRefUrl = $refUrl;
}
unset($params['action']);
$slug = $this->tableOut[$key];
$query = ($tmp = http_build_query($params)) ? '?' . $tmp : '';
$url = $this->lastBaseUrl . $slug . $query;
return $url;
}
作者:kiz
项目:easyminer-easyminercente
/**
* 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);
}
作者:sg3teste
项目:songato
protected function setupCallbackUrl()
{
//Create and setup callback URL
$this->callback_url = new Url();
$this->callback_url->setScheme('http');
$this->callback_url->setHost('ws.audioscrobbler.com');
$this->callback_url->setPath('/2.0/');
//2.0 - API version
$this->callback_url->appendQuery("api_key={$this->key}");
if ($this->data_format == self::DATA_JSON) {
$this->callback_url->appendQuery('format=json');
}
//JSON result
}
作者:pkristia
项目:flickrlick
/**
* Sign current request
*
* @param Signature\SignatureMethod $method
*
* @return $this
*/
public function signRequest(Signature\SignatureMethod $method)
{
$this->url->setQueryParameter('oauth_signature_method', $method->getName());
$signature = $method->buildSignature($this->getSignatureBaseString(), $this->consumer, $this->token);
$this->url->setQueryParameter('oauth_signature', $signature);
$parameters = $this->getParameters();
ksort($parameters, SORT_STRING);
$authHeader = NULL;
foreach ($parameters as $key => $value) {
if (in_array($key, $this->oauthHeader)) {
$authHeader .= ' ' . $key . '="' . OAuth\Utils\Url::urlEncodeRFC3986($value) . '",';
// Remove oauth from query parameter
$this->url->setQueryParameter($key, NULL);
}
}
if ($authHeader !== NULL) {
$this->headers['Authorization'] = 'OAuth ' . trim(rtrim($authHeader, ','));
}
return $this;
}
作者:kysela-pet
项目:generator-kysel
/**
* Pro zadane URL vytvori URL na minimalizacni skript
* @param string $url
* @param int $width [optional]
* @param int $height [optional]
* @return string
*/
public function min($url, $width = NULL, $height = NULL, $topcut = FALSE)
{
$min = new Url($this->scriptUrl);
$min->setQueryParameter('file', $url);
if ($width) {
$min->setQueryParameter('w', $width);
}
if ($height) {
$min->setQueryParameter('h', $height);
}
if ($width && $height) {
$min->setQueryParameter('exact', TRUE);
if ($topcut) {
$min->setQueryParameter('topcut', TRUE);
}
}
$minUrl = "/" . $min->getRelativeUrl();
return $minUrl;
}
作者:pdosta
项目:nette-blo
/**
* Request/URL factory.
* @param PresenterComponent base
* @param string destination in format "[[module:]presenter:]action" or "signal!" or "this"
* @param array array of arguments
* @param string forward|redirect|link
* @return string URL
* @throws InvalidLinkException
* @internal
*/
protected function createRequest($component, $destination, array $args, $mode)
{
// note: createRequest supposes that saveState(), run() & tryCall() behaviour is final
// cached services for better performance
static $presenterFactory, $router, $refUrl;
if ($presenterFactory === NULL) {
$presenterFactory = $this->application->getPresenterFactory();
$router = $this->application->getRouter();
$refUrl = new Http\Url($this->httpRequest->getUrl());
$refUrl->setPath($this->httpRequest->getUrl()->getScriptPath());
}
$this->lastCreatedRequest = $this->lastCreatedRequestFlag = NULL;
// PARSE DESTINATION
// 1) fragment
$a = strpos($destination, '#');
if ($a === FALSE) {
$fragment = '';
} else {
$fragment = substr($destination, $a);
$destination = substr($destination, 0, $a);
}
// 2) ?query syntax
$a = strpos($destination, '?');
if ($a !== FALSE) {
parse_str(substr($destination, $a + 1), $args);
// requires disabled magic quotes
$destination = substr($destination, 0, $a);
}
// 3) URL scheme
$a = strpos($destination, '//');
if ($a === FALSE) {
$scheme = FALSE;
} else {
$scheme = substr($destination, 0, $a);
$destination = substr($destination, $a + 2);
}
// 4) signal or empty
if (!$component instanceof Presenter || substr($destination, -1) === '!') {
$signal = rtrim($destination, '!');
$a = strrpos($signal, ':');
if ($a !== FALSE) {
$component = $component->getComponent(strtr(substr($signal, 0, $a), ':', '-'));
$signal = (string) substr($signal, $a + 1);
}
if ($signal == NULL) {
// intentionally ==
throw new InvalidLinkException("Signal must be non-empty string.");
}
$destination = 'this';
}
if ($destination == NULL) {
// intentionally ==
throw new InvalidLinkException("Destination must be non-empty string.");
}
// 5) presenter: action
$current = FALSE;
$a = strrpos($destination, ':');
if ($a === FALSE) {
$action = $destination === 'this' ? $this->action : $destination;
$presenter = $this->getName();
$presenterClass = get_class($this);
} else {
$action = (string) substr($destination, $a + 1);
if ($destination[0] === ':') {
// absolute
if ($a < 2) {
throw new InvalidLinkException("Missing presenter name in '{$destination}'.");
}
$presenter = substr($destination, 1, $a - 1);
} else {
// relative
$presenter = $this->getName();
$b = strrpos($presenter, ':');
if ($b === FALSE) {
// no module
$presenter = substr($destination, 0, $a);
} else {
// with module
$presenter = substr($presenter, 0, $b + 1) . substr($destination, 0, $a);
}
}
try {
$presenterClass = $presenterFactory->getPresenterClass($presenter);
} catch (Application\InvalidPresenterException $e) {
throw new InvalidLinkException($e->getMessage(), NULL, $e);
}
}
// PROCESS SIGNAL ARGUMENTS
if (isset($signal)) {
// $component must be IStatePersistent
//.........这里部分代码省略.........