示例#1
0
文件: VK.php 项目: romeoz/rock
 public function init()
 {
     if (isset($this->service)) {
         return;
     }
     //$serviceFactory = new ServiceFactory();
     // Session storage
     $storage = new Session();
     // Setup the credentials for the requests
     $credentials = new Credentials($this->clientId, $this->clientSecret, Url::modify([$this->redirectUrl], Url::ABS));
     $this->service = new Vkontakte($credentials, new StreamClient(), $storage, $this->scopes);
 }
示例#2
0
文件: Facebook.php 项目: romeoz/rock
 public function init()
 {
     if (isset($this->service)) {
         return;
     }
     $serviceFactory = new ServiceFactory();
     // Session storage
     $storage = new Session();
     // Setup the credentials for the requests
     $credentials = new Credentials($this->clientId, $this->clientSecret, Url::modify($this->redirectUrl, Url::ABS));
     $this->service = $serviceFactory->createService('facebook', $credentials, $storage, $this->scopes);
 }
示例#3
0
文件: Google.php 项目: romeoz/rock
 public function init()
 {
     if (isset($this->service)) {
         return;
     }
     $serviceFactory = new ServiceFactory();
     // Session storage
     $storage = new Session(false);
     // Setup the credentials for the requests
     $credentials = new Credentials($this->clientId, $this->clientSecret, Url::modify($this->redirectUrl, Url::ABS));
     // Instantiate the Google service using the credentials, http client and storage mechanism for the token
     $this->service = $serviceFactory->createService('google', $credentials, $storage, $this->scopes);
 }
示例#4
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     if ($this->hasModel() && $this->activeField) {
         $this->options = $this->activeField->calculateClientInputOption($this->options);
         $input = ActiveHtml::activeTextInput($this->model, $this->attribute, $this->options);
     } else {
         $input = Html::textInput($this->name, $this->value, $this->options);
     }
     if ($this->output === self::BASE64) {
         $src = $this->captcha->getDataUri();
     } else {
         $src = Url::modify([$this->captchaAction, 'v' => uniqid()], Url::ABS);
     }
     $image = Html::img($src, $this->imageOptions);
     echo strtr($this->template, ['{input}' => $input, '{image}' => $image]);
 }
 /**
  * Creates the URL suitable for pagination with the specified page number.
  * This method is mainly called by pagers when creating URLs used to perform pagination.
  * @param integer $page the zero-based page number that the URL should point to.
  * @param null $limit
  * @return string the created URL
  * @throws \rock\url\UrlException
  */
 public function createUrl($page, $limit = null)
 {
     $params = [$this->pageParam => (int) $page];
     $limit = (int) $limit;
     if ($limit <= 0) {
         $limit = $this->getLimit();
     }
     if ($limit != $this->defaultLimit) {
         $params[$this->limitParam] = $limit;
     } else {
         unset($params[$this->limitParam]);
     }
     if (is_array($this->url)) {
         return Url::modify(array_merge($this->url, $params));
     } elseif ($this->url instanceof Url) {
         return $this->url->setQueryParams($params)->get();
     }
     return Url::modify($params);
 }
示例#6
0
 /**
  * @inheritdoc
  */
 public function get()
 {
     return \rock\url\Url::modify($this->modify, $this->config);
 }
示例#7
0
 /**
  * Modify url.
  *
  * @param string $url
  * @param array $params params:
  *
  * - modify:      modify arguments.
  * - csrf:        adding a CSRF-token.
  * - scheme: adduce URL to: {@see \rock\url\Url::ABS}, {@see \rock\url\Url::HTTP},
  *                  and {@see \rock\url\Url::HTTPS}.
  * @param Template $template
  * @return string
  * @throws \rock\url\UrlException
  */
 public static function modifyUrl($url, array $params = [], Template $template)
 {
     if (empty($url)) {
         return '#';
     }
     if (!isset($params['modify'])) {
         $params['modify'] = [];
     }
     array_unshift($params['modify'], $url);
     $config = isset($params['config']) ? $params['config'] : [];
     if (isset($params['csrf'])) {
         $config['csrf'] = (bool) $params['csrf'];
     }
     if (isset($params['scheme'])) {
         $params['modify']['@scheme'] = $params['scheme'];
     }
     $config['request'] = $template->request;
     return Url::modify($params['modify'], $config);
 }
示例#8
0
文件: User.php 项目: romeoz/rock
 /**
  * Returns the URL that the browser should be redirected to after successful login.
  *
  * This method reads the return URL from the session. It is usually used by the login action which
  * may call this method to redirect the browser to where it goes after successful authentication.
  *
  * @param string|array $defaultUrl the default return URL in case it was not set previously.
  * If this is null and the return URL was not set previously, {@see \rock\request\Request::getHomeUrl()} will be redirected to.
  * @return string the URL that the user should be redirected to after login.
  */
 public function getReturnUrl($defaultUrl = null)
 {
     $url = $this->storage->get($this->returnUrlParam, $defaultUrl);
     return $url === null ? $this->request->getHomeUrl() : Url::modify($url);
 }
示例#9
0
 /**
  * Redirects the browser to the specified URL.
  * This method is a shortcut to {@see \rock\response\Response::redirect()}.
  *
  * You can use it in an action by returning the {@see \rock\response\Response} directly:
  *
  * ```php
  * // stop executing this action and redirect to login page
  * return $this->redirect(['login']);
  * ```
  *
  * @param string|array $url the URL to be redirected to. This can be in one of the following formats:
  *
  * - a string representing a URL (e.g. "http://example.com")
  * - a string representing a URL alias (e.g. "@example.com")
  *
  * Any relative URL will be converted into an absolute one by prepending it with the host info
  * of the current request.
  *
  * @param integer $statusCode the HTTP status code. Defaults to 302.
  * See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>
  * for details about HTTP status code
  * @return Response the current response object
  */
 public function redirect($url, $statusCode = 302)
 {
     return $this->response->redirect(Url::modify($url, Url::ABS), $statusCode);
 }
示例#10
0
文件: Response.php 项目: romeoz/rock
 /**
  * Refreshes the current page.
  *
  * The effect of this method call is the same as the user pressing the refresh button of his browser
  * (without re-posting data).
  *
  * In a controller action you may use this method like this:
  *
  * ``php
  * return Rock::$app->response->refresh();
  * ```
  *
  * @param array $modify
  * @return Response the response object itself
  */
 public function refresh(array $modify = null)
 {
     return $this->redirect(Url::modify($modify, Url::ABS));
 }
示例#11
0
 protected function calculateLastPage(array $data, $pageParam)
 {
     if (!($pageLast = (int) $data['pageLast'])) {
         return null;
     }
     $this->_pageArgs[$pageParam] = $pageLast;
     $placeholders = ['url' => $url = Url::modify($this->url + $this->_pageArgs, ['request' => $this->template->request]), 'pageLastName' => $this->template->replace($this->pageLastName)];
     return $this->template->replaceByPrefix($this->pageLastTpl, $placeholders);
 }
示例#12
0
 /**
  * Generates an image tag.
  *
  * @param array|string $src the image URL. This parameter will be
  *                              processed by {@see \rock\url\Url::getAbsoluteUrl()} .
  * @param array $options the tag options in terms of name-value pairs. These will be rendered as
  *                              the attributes of the resulting tag. The values will be HTML-encoded using {@see \rock\template\Html::encode()} .
  *                              If a value is null, the corresponding attribute will not be rendered.
  *                              See {@see \rock\template\Html::renderTagAttributes()} for details on how attributes are being rendered.
  * @return string the generated image tag
  */
 public static function img($src, $options = [])
 {
     if (!empty($src) && strpos($src, 'data:') !== 0) {
         $src = (array) $src;
         if (!isset($src['@scheme'])) {
             $src['@scheme'] = Url::ABS;
         }
         $src = Url::modify($src);
     }
     $options['src'] = $src;
     if (!isset($options['alt'])) {
         $options['alt'] = '';
     }
     return static::tag('img', '', $options);
 }
示例#13
0
 /**
  * Generates relative URL
  *
  * @param string $url the parameter to be used to generate a valid URL
  * @param array $config
  * @return string the generated relative URL
  */
 public function url($url, $config = [])
 {
     return Url::modify($url, $config);
 }
示例#14
0
 /**
  * Creates a URL for sorting the data by the specified attribute.
  * This method will consider the current sorting status given by {@see \rock\data\Sort::$attributeOrders}.
  * For example, if the current page already sorts the data by the specified attribute in ascending order,
  * then the URL created will lead to a page that sorts the data by the specified attribute in descending order.
  * @param string $attribute the attribute name
  * @return string the URL for sorting. False if the attribute is invalid.
  * @see attributeOrders
  * @see params
  */
 public function createUrl($attribute)
 {
     $params = [$this->sortParam => $this->createSortParam($attribute)];
     if (is_array($this->url)) {
         return Url::modify(array_merge($this->url, $params));
     } elseif ($this->url instanceof Url) {
         return $this->url->setQueryParams($params)->get();
     }
     return Url::modify($params);
 }