Пример #1
0
 * @author ErgallM
 *
 * @var    View         $this
 * @param  string       $text
 * @param  string|array $href
 * @param  array        $attributes HTML attributes
 * @return string
 */
return function ($text, $href, array $attributes = []) {
    // if href is settings for url helper
    if (is_array($href)) {
        $href = $this->url(...$href);
    }
    // href can be null, if access is denied
    if (null === $href) {
        return '';
    }
    $current = Request::getUri()->getPath();
    if (Request::getUri()->getQuery()) {
        $current .= sprintf('?%s', Request::getUri()->getQuery());
    }
    if ($href == $current) {
        if (isset($attributes['class'])) {
            $attributes['class'] .= ' active';
        } else {
            $attributes['class'] = 'active';
        }
    }
    $attributes = $this->attributes($attributes);
    return '<a href="' . $href . '" ' . $attributes . '>' . Translator::translate($text) . '</a>';
};
Пример #2
0
 /**
  * Get the request URI without baseUrl
  *
  * @return string
  */
 public function getCleanUri()
 {
     if ($this->cleanUri === null) {
         $uri = Request::getUri()->getPath();
         if ($this->getBaseUrl() && strpos($uri, $this->getBaseUrl()) === 0) {
             $uri = substr($uri, strlen($this->getBaseUrl()));
         }
         $this->cleanUri = $uri;
     }
     return $this->cleanUri;
 }
Пример #3
0
 /**
  * Reload current page please, be careful to avoid loop of reload
  *
  * @return void
  * @throws ReloadException
  */
 public static function reload()
 {
     self::redirect(Request::getUri());
 }
Пример #4
0
 /**
  * Denied access
  * @param ForbiddenException $exception
  * @return \Bluz\Controller\Controller|null
  */
 public function forbidden(ForbiddenException $exception)
 {
     if (AuthProxy::getIdentity()) {
         $message = Translator::translate("You don't have permissions to access this page");
     } else {
         $message = Translator::translate("You don't have permissions, please sign in");
     }
     // for AJAX and API calls (over JSON)
     $jsonOrApi = Request::isXmlHttpRequest() || Request::getAccept([Request::TYPE_HTML, Request::TYPE_JSON]) == Request::TYPE_JSON;
     // for guest, for requests
     if (!AuthProxy::getIdentity() && !$jsonOrApi) {
         // save URL to session and redirect make sense if presentation is null
         Session::set('rollback', Request::getUri()->__toString());
         // add error notice
         Messages::addError($message);
         // redirect to Sign In page
         $url = Router::getUrl('users', 'signin');
         return $this->redirect($url);
     } else {
         return $this->error(new ForbiddenException($message, 403, $exception));
     }
 }