Exemple #1
0
 public function test_user_allowed()
 {
     $base = Tart::uri();
     $user = Jam::build('user', array('roles' => array(array('name' => 'login'), array('name' => 'admin', 'allowed' => array($base . '/*')))));
     $guest = Jam::build('user', array('roles' => array(array('name' => 'login'), array('name' => 'guest', 'allowed' => array($base . '/stats*')))));
     $this->assertEquals(TRUE, Tart::user_allowed($base . '/stats', NULL));
     $this->assertEquals(TRUE, Tart::user_allowed($base . '/stats', $user));
     $this->assertEquals(TRUE, Tart::user_allowed($base . '/users', $user));
     $this->assertEquals(TRUE, Tart::user_allowed($base . '/stats', $guest));
     $this->assertEquals(FALSE, Tart::user_allowed($base . '/users', $guest));
 }
Exemple #2
0
 public static function anchor($anchor, $title = NULL, array $attributes = array(), $user = NULL)
 {
     if (!$anchor) {
         return NULL;
     }
     $user = $user ?: Auth::instance()->get_user();
     $options = Arr::extract($attributes, array('external', 'limit', 'if', 'unless'));
     $attributes = array_diff_key($attributes, $options);
     if ($title === NULL) {
         $title = $anchor;
     }
     if ($options['limit'] !== NULL) {
         $title = Text::limit_chars($title, $options['limit']);
     }
     if ($options['external'] !== NULL) {
         $title .= ' <i class="icon-share"></i>';
     }
     if (!$options['external'] and !Tart::user_allowed($anchor, $user)) {
         return NULL;
     }
     if ($options['if'] !== NULL and !$options['if'] or $options['unless'] !== NULL and $options['unless']) {
         return "<span" . HTML::attributes($attributes) . ">{$title}</span>";
     }
     return HTML::anchor($anchor, $title, $attributes);
 }