Example #1
0
 /**
  * The before() method is called before controller action
  *
  * @throws  HTTP_Exception
  *
  * @uses    Assets::css
  * @uses    User::is_guest
  */
 public function before()
 {
     if (User::is_guest()) {
         throw HTTP_Exception::factory(403, 'Permission denied! You must login!');
     }
     $id = $this->request->param('id', FALSE);
     if ($id and 'index' == $this->request->action()) {
         $this->request->action('view');
     }
     if (!$id and 'index' == $this->request->action()) {
         $this->request->action('inbox');
     }
     Assets::css('user', 'media/css/user.css', array('theme'), array('weight' => 60));
     parent::before();
 }
Example #2
0
 /**
  * Check if current user is admin
  *
  * @return  boolean TRUE if current user is admin
  */
 public static function is_admin()
 {
     if (User::is_guest()) {
         return FALSE;
     }
     $user = Auth::instance()->get_user();
     // To reduce the number of SQL queries, we cache the user's roles in a static variable.
     if (!isset(User::$roles[$user->id])) {
         // @todo fetch and save in session to avoid recursive lookups
         User::$roles[$user->id] = $user->roles();
     }
     if (in_array('admin', User::$roles[$user->id]) or array_key_exists(4, User::$roles[$user->id])) {
         return TRUE;
     }
     return FALSE;
 }
Example #3
0
 public static function form($controller, $item, $_action = FALSE, $captcha = FALSE)
 {
     // Set default comment form action
     $action = Request::current()->uri();
     $view = View::factory('comment/form')->set('use_captcha', $captcha)->set('action', $action)->set('is_edit', FALSE)->set('auth', Auth::instance())->set('destination', array())->set('item', $item)->bind('errors', $errors)->bind('post', $post);
     // Set form action either from model or action param
     if ($item->url) {
         $action = (string) $item->url;
     } elseif ($_action) {
         $action = $_action;
     }
     // Set if captcha necessary
     if ($captcha) {
         $captcha = Captcha::instance();
         $view->set('captcha', $captcha);
     }
     // Load the comment model
     $post = ORM::factory('comment');
     if ($controller->valid_post('comment')) {
         $values = Arr::merge(array('post_id' => $item->id, 'type' => $item->type), $_POST);
         try {
             $post->values($values)->save();
             if ($post->status != 'publish') {
                 Message::success(__('Your comment has been queued for review by site administrators and will be published after approval.'));
             } else {
                 Message::success(__('Your comment has been posted.', array(':title' => $post->title)));
             }
             // Save the anonymous user information to a cookie for reuse.
             if (User::is_guest()) {
                 User::cookie_save(array('name' => $post->guest_name, 'email' => $post->guest_email, 'url' => $post->guest_url));
             }
             Log::info('Comment: :title has posted.', array(':title' => $post->title));
             // Redirect to post page
             $controller->request->redirect(Request::current()->uri());
         } catch (ORM_Validation_Exception $e) {
             // @todo Add messages
             $errors = $e->errors('models', TRUE);
         }
     }
     return $view;
 }
Example #4
0
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<?php 
echo HTML::anchor('/', HTML::image($site_logo, array('alt' => $site_slogan, 'class' => 'logo')), array('class' => 'navbar-brand', 'title' => $site_name));
?>
			</div>
			<nav class="navbar-collapse collapse" role="navigation">
				<?php 
echo $primary_menu;
?>

				<ul class="nav navbar-nav navbar-right">
						<?php 
if (User::is_guest()) {
    ?>
							<?php 
    if (Kohana::$config->load('auth')->get('register')) {
        ?>
								<li><a href="<?php 
        echo URL::site('/user/register');
        ?>
"><?php 
        echo __('Sign Up');
        ?>
</a></li>
							<?php 
    }
    ?>
							<li><a href="<?php 
Example #5
0
					<?php 
echo User::getAvatar($user, array('size' => 210));
?>
				</div>

				<div class="list-group">
					<a href="javascript:;" class="list-group-item">
						<i class="fa fa-fw fa-asterisk"></i> <?php 
echo __('Activity Feed');
?>
						<i class="fa fa-chevron-right list-group-chevron"></i>
					</a>
					<?php 
if ($is_owner) {
    echo HTML::anchor('message/inbox', '<i class="fa fa-fw fa-envelope"></i> ' . __('Messages') . '<i class="fa fa-chevron-right list-group-chevron"></i>', array('class' => 'list-group-item'));
} elseif (!User::is_guest()) {
    echo HTML::anchor('message/compose', '<i class="fa fa-fw fa-envelope"></i> ' . __('Send Message') . '<i class="fa fa-chevron-right list-group-chevron"></i>', array('class' => 'list-group-item'));
}
?>
					<?php 
if ($enable_buddy) {
    ?>
						<?php 
    echo HTML::anchor('buddy', '<i class="fa fa-fw fa-group"></i> ' . __('Friends') . '<i class="fa fa-chevron-right list-group-chevron"></i>', array('class' => 'list-group-item'));
    ?>
					<?php 
}
?>
					<?php 
echo HTML::anchor('user/edit', '<i class="fa fa-fw fa-cog"></i> ' . __('Settings') . '<i class="fa fa-chevron-right list-group-chevron"></i>', array('class' => 'list-group-item'));
?>
Example #6
0
 /**
  * Detect language based on the user language settings.
  *
  *     // Get the language
  *     $lang = I18n::userLocale();
  *
  * @return  string
  */
 public static function userLocale()
 {
     // Can't set guest users locale, default's to site locale
     if (User::is_guest()) {
         // Respect cookie if its set already or use default
         $locale = strtolower(Cookie::get(self::$_cookie, I18n::$default));
     } else {
         $locale = User::active_user()->language;
     }
     if (self::isAvailable($locale)) {
         return $locale;
     }
     return FALSE;
 }