コード例 #1
0
ファイル: list.php プロジェクト: anqh/anqh
 /**
  * Render view.
  *
  * @return  string
  */
 public function content()
 {
     // Build short (friends) and long (others) user list
     $short = $long = array();
     $total = count($this->users);
     foreach ($this->users as $user) {
         $user = is_array($user) ? $user : Model_User::find_user_light($user);
         if ($total < 11 || Visitor::$user && Visitor::$user->is_friend($user)) {
             $short[mb_strtoupper($user['username'])] = HTML::user($user);
         } else {
             $long[mb_strtoupper($user['username'])] = HTML::user($user);
         }
     }
     ksort($long);
     // If no friends, pick random from long
     if (empty($short) && !empty($long)) {
         $shorts = (array) array_rand($long, min(10, count($long)));
         foreach ($shorts as $move) {
             $short[$move] = $long[$move];
             unset($long[$move]);
         }
     }
     ksort($short);
     ob_start();
     if (count($short)) {
         echo implode(', ', $short);
     }
     if (count($long)) {
         echo ' ', __('and'), ' ', HTML::anchor('#long', __(count($long) == 1 ? ':count other &#9662;' : ':count others &#9662;', array(':count' => count($long))), array('title' => __('Show all'), 'data-toggle' => 'collapse', 'data-target' => '#long', 'onclick' => 'return false;'));
         echo '<div id="long" class="collapse">', implode(', ', $long), '</div>';
     }
     return ob_get_clean();
 }
コード例 #2
0
ファイル: friendsuggestions.php プロジェクト: anqh/anqh
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        $friends = array();
        $suggestions = $this->user->find_friend_suggestions();
        if ($suggestions) {
            $randoms = array_rand($suggestions, min($this->limit, count($suggestions)));
            foreach ($randoms as $friend_id) {
                $friend = Model_User::find_user_light($friend_id);
                $friends[$friend['username']] = array('user' => $friend, 'score' => $suggestions[$friend_id]);
            }
            ?>

<ul class="media-list">
	<?php 
            foreach ($friends as $friend) {
                ?>

	<?php 
                echo new View_Users_Friend($friend['user'], $friend['score']);
                ?>

	<?php 
            }
            ?>
</ul>

<?php 
        } else {
            echo __('Darn, no friend suggestions available. You might want to consider adding some friends first?');
        }
        return ob_get_clean();
    }
コード例 #3
0
ファイル: friends.php プロジェクト: anqh/anqh
 /**
  * Create new view.
  *
  * @param  Model_User  $user
  * @param  boolean     $friended
  */
 public function __construct($user = null, $friended = false)
 {
     parent::__construct();
     $this->user = $user;
     $this->friended = $friended;
     foreach ($this->user->find_friends($this->friended) as $friend_id) {
         $friend = Model_User::find_user_light($friend_id);
         $this->friends[$friend['username']] = $friend;
     }
     ksort($this->friends, SORT_LOCALE_STRING);
     $this->title = $friended ? __('Friending me') : __('Friends');
     $this->title .= ' <small class="muted">(' . count($this->friends) . ')</small>';
 }
コード例 #4
0
ファイル: newsfeed.php プロジェクト: anqh/core
 /**
  * Get news feed as array
  *
  * @return  array
  */
 public function as_array()
 {
     $feed = array();
     foreach ($this->get_items() as $item) {
         // Ignore
         if ($this->_user && $this->_user->is_ignored($item->user_id)) {
             continue;
         }
         $class = 'Newsfeeditem_' . $item->class;
         if (method_exists($class, 'get') && ($text = call_user_func(array($class, 'get'), $item))) {
             $feed[] = array('user' => Model_User::find_user_light((int) $item->user_id), 'stamp' => $item->stamp, 'text' => $text);
         }
     }
     return $feed;
 }
コード例 #5
0
ファイル: online.php プロジェクト: anqh/core
 /**
  * Create new shouts view.
  */
 public function __construct()
 {
     parent::__construct();
     $this->_guest_count = Model_User_Online::get_guest_count();
     $users = Model_User_Online::find_online_users();
     $this->title = __('Online');
     // Build user lists
     $friends = (bool) self::$_user ? self::$_user->find_friends() : array();
     foreach ($users as $user_id) {
         $user = Model_User::find_user_light($user_id);
         if (in_array($user_id, $friends)) {
             $this->_friends[mb_strtoupper($user['username'])] = HTML::user($user);
         } else {
             $this->_users[mb_strtoupper($user['username'])] = HTML::user($user);
         }
     }
 }
コード例 #6
0
ファイル: topic.php プロジェクト: anqh/anqh
 /**
  * Get message recipient usernames
  *
  * @return  array
  */
 public function find_recipient_names()
 {
     static $recipients;
     if (!is_array($recipients)) {
         $recipients = array();
     }
     if ($this->loaded()) {
         if (!isset($recipients[$this->id])) {
             $recipients[$this->id] = array();
             foreach ($this->recipients() as $recipient) {
                 $recipients[$this->id][$recipient] = Arr::get(Model_User::find_user_light($recipient), 'username');
             }
             natcasesort($recipients[$this->id]);
         }
         return $recipients[$this->id];
     }
     return array();
 }
コード例 #7
0
ファイル: bb.php プロジェクト: anqh/core
 /**
  * Handle forum quotations
  *
  * @param   BBCode  $bbcode
  * @param   string  $action
  * @param   string  $name
  * @param   string  $default
  * @param   array   $params
  * @param   string  $content
  * @return  string
  */
 public function bbcode_quote($bbcode, $action, $name, $default, $params, $content)
 {
     // Pass all to 2nd phase
     if ($action == BBCODE_CHECK) {
         return true;
     }
     // Parse parameters
     foreach ($params['_params'] as $param) {
         switch ($param['key']) {
             // Parent post id
             case 'post':
                 $post = Model_Forum_Post::factory((int) $param['value']);
                 break;
                 // Parent post author
             // Parent post author
             case 'author':
                 $author_name = $param['value'];
                 $author = Model_User::find_user_light($author_name);
                 break;
         }
     }
     // Add parent post
     if (isset($post) && $post->loaded()) {
         $quote = '<blockquote cite="' . URL::site(Route::model($post->topic())) . '?post=' . $post->id . '#post-' . $post->id . '">';
         // Override author
         $author = Model_User::find_user_light($post->author_id);
     } else {
         $quote = '<blockquote>';
     }
     $quote .= '<p>' . trim($content) . '</p>';
     // Post author
     if (isset($author) && $author) {
         $quote .= '<cite>' . __('-- :author', array(':author' => HTML::user($author))) . '</cite>';
     } else {
         if (isset($author_name)) {
             $quote .= '<cite>' . __('-- :author', array(':author' => HTML::chars($author_name))) . '</cite>';
         }
     }
     $quote .= '</blockquote>';
     return $quote;
 }
コード例 #8
0
ファイル: ignores.php プロジェクト: anqh/anqh
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        $ignores = array();
        foreach ($this->user->find_ignores() as $ignore_id) {
            $ignore = Model_User::find_user_light($ignore_id);
            $ignores[$ignores['username']] = $ignore;
        }
        ksort($ignores, SORT_LOCALE_STRING);
        ?>

<ul class="media-list">
	<?php 
        foreach ($ignores as $ignore) {
            ?>

	<li class="media">
		<div class="pull-left">
			<?php 
            echo HTML::avatar($ignore['avatar'], $ignore['username']);
            ?>
		</div>
		<div class="media-body">
			<?php 
            echo HTML::user($ignore);
            ?>
<br />
			<?php 
            echo HTML::anchor(URL::user($ignore, 'unignore') . '?token=' . Security::csrf(), '<i class="fa fa-ban"></i> ' . __('Unignore'), array('class' => 'btn btn-default btn-sm ignore-delete'));
            ?>
		</div>
	</li>
	<?php 
        }
        ?>

</ul>

<?php 
        return ob_get_clean();
    }
コード例 #9
0
ファイル: friends.php プロジェクト: anqh/core
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        $friends = array();
        foreach ($this->user->find_friends() as $friend_id) {
            $friend = Model_User::find_user_light($friend_id);
            $friends[$friend['username']] = $friend;
        }
        ksort($friends, SORT_LOCALE_STRING);
        ?>

<ul class="unstyled">
	<?php 
        foreach ($friends as $friend) {
            ?>

	<li class="row-fluid">
		<?php 
            echo HTML::avatar($friend['avatar'], $friend['username']);
            ?>
		<?php 
            echo HTML::user($friend);
            ?>
		<?php 
            if ($friend['last_login']) {
                echo '<small class="ago">' . HTML::time(Date::short_span($friend['last_login'], true, true), $friend['last_login']) . '</small>';
            }
            ?>
	</li>
	<?php 
        }
        ?>

</ul>


<?php 
        return ob_get_clean();
    }
コード例 #10
0
ファイル: new.php プロジェクト: anqh/core
    /**
     * Render content.
     *
     * @return  string
     */
    public function content()
    {
        $dates = array();
        foreach (Model_User::find_new_users($this->limit) as $user_id => $stamp) {
            $user = Model_User::find_user_light($user_id);
            $dates[Date::format(Date::DMY_SHORT, $stamp)][] = array('user' => $user, 'stamp' => $stamp);
        }
        ob_start();
        foreach ($dates as $date => $users) {
            ?>

<h4><?php 
            echo $date;
            ?>
</h4>
<ul class="block-grid three-up">
	<?php 
            foreach ($users as $user) {
                ?>
	<li>
		<?php 
                echo HTML::avatar($user['user']['avatar'], $user['user']['username']), ' ', HTML::user($user['user']);
                ?>
<br />
		<time class="muted"><?php 
                echo Date::format(Date::TIME, $user['stamp']);
                ?>
</time>
	</li>
	<?php 
            }
            ?>
</ul>

<?php 
        }
        return ob_get_clean();
    }
コード例 #11
0
ファイル: ignores.php プロジェクト: anqh/core
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        $ignores = array();
        foreach ($this->user->find_ignores() as $ignore_id) {
            $ignore = Model_User::find_user_light($ignore_id);
            $ignores[$ignores['username']] = $ignore;
        }
        ksort($ignores, SORT_LOCALE_STRING);
        ?>

<ul class="unstyled">
	<?php 
        foreach ($ignores as $ignore) {
            ?>

	<li class="row-fluid">
		<?php 
            echo HTML::avatar($ignore['avatar'], $ignore['username']);
            ?>
		<?php 
            echo HTML::user($ignore);
            ?>
<br />
		<?php 
            echo HTML::anchor(URL::user($ignore, 'unignore') . '?token=' . Security::csrf(), '<i class="icon-ban-circle icon-white"></i> ' . __('Unignore'), array('class' => 'btn btn-inverse btn-small ignore-delete'));
            ?>
	</li>
	<?php 
        }
        ?>

</ul>


<?php 
        return ob_get_clean();
    }
コード例 #12
0
ファイル: html.php プロジェクト: anqh/anqh
 /**
  * Returns user link
  *
  * @param   mixed   $user
  * @param   string  $nick
  * @param   array   $attributes
  * @param   string  $url         override url
  * @return  string
  */
 public static function user($user, $nick = null, array $attributes = null, $url = null)
 {
     static $viewer = true;
     // Load current user for friend styling
     if ($viewer === true) {
         $viewer = Visitor::instance()->get_user();
     }
     $class = array('user', 'hoverable');
     if (is_array($user) || $user && ($user = Model_User::find_user_light($user))) {
         if ($user) {
             $nick = $user['username'];
             if ($viewer && $viewer->is_friend($user)) {
                 $class[] = 'friend ';
             }
             switch ($user['gender']) {
                 case 'f':
                     $class[] = 'female';
                     break;
                 case 'm':
                     $class[] = 'male';
                     break;
             }
         }
     }
     $class[] = Arr::get($attributes, 'class');
     $attributes['class'] = trim(implode(' ', $class));
     return empty($nick) ? __('Unknown') : HTML::anchor($url ? $url : URL::user($nick), $nick, $attributes);
 }
コード例 #13
0
ファイル: note.php プロジェクト: anqh/core
 /**
  * Get note target user light array
  *
  * @return  array
  */
 public function user()
 {
     try {
         return $this->user_id ? Model_User::find_user_light($this->user_id) : null;
     } catch (AutoModeler_Exception $e) {
         return null;
     }
 }
コード例 #14
0
ファイル: topic.php プロジェクト: anqh/forum
 /**
  * Edit forum topic
  *
  * @param  integer  $area_id
  * @param  integer  $topic_id
  *
  * @throws  Model_Exception           invalid area, invalid topic
  * @throws  InvalidArgumentException  missing area and topic
  */
 protected function _edit_topic($area_id = null, $topic_id = null)
 {
     $this->history = false;
     $this->view = new View_Page();
     if ($area_id && !$topic_id) {
         // Start new topic
         $mode = View_Forum_PostEdit::NEW_TOPIC;
         /** @var  Model_Forum_Private_Area|Model_Forum_Area  $area */
         $area = $this->private ? Model_Forum_Private_Area::factory($area_id) : Model_Forum_Area::factory($area_id);
         if (!$area->loaded()) {
             throw new Model_Exception($area, $area_id);
         }
         Permission::required($area, Model_Forum_Area::PERMISSION_POST, self::$user);
         $this->view->title = HTML::chars($area->name);
         if ($this->private) {
             $topic = new Model_Forum_Private_Topic();
             $post = new Model_Forum_Private_Post();
             $cancel = Route::url('forum_area', array('id' => 'private', 'action' => ''));
             $recipients = array();
         } else {
             $topic = new Model_Forum_Topic();
             $post = new Model_Forum_Post();
             $cancel = Route::model($area);
         }
     } else {
         if ($topic_id) {
             // Edit old topic
             $mode = View_Forum_PostEdit::EDIT_TOPIC;
             /** @var  Model_Forum_Private_Topic|Model_Forum_Topic  $topic */
             $topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id);
             if (!$topic->loaded()) {
                 throw new Model_Exception($topic, $topic_id);
             }
             Permission::required($topic, Model_Forum_Topic::PERMISSION_UPDATE, self::$user);
             // Build recipients list
             if ($this->private) {
                 $recipients = $topic->find_recipient_names();
             }
             $this->view->title_html = Forum::topic($topic);
             $cancel = Route::model($topic);
             // Set actions
             if (Permission::has($topic, Model_Forum_Topic::PERMISSION_DELETE, self::$user)) {
                 $this->view->actions[] = array('link' => Route::model($topic, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete topic'), 'class' => 'btn btn-danger topic-delete');
             }
         } else {
             throw new InvalidArgumentException('Topic and area missing');
         }
     }
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         // Get recipients
         if ($this->private) {
             $post_recipients = array();
             foreach (explode(',', Arr::get_once($_POST, 'recipients')) as $recipient) {
                 if ($user = Model_User::find_user_light(trim($recipient))) {
                     $post_recipients[$user['id']] = $user['username'];
                 }
             }
             // Make sure author is included
             $post_recipients[self::$user->id] = self::$user->username;
         }
         if (isset($post)) {
             // New topic
             $post->post = $_POST['post'];
             $post->forum_area_id = $area->id;
             $post->author_id = self::$user->id;
             $post->author_name = self::$user->username;
             $post->author_ip = Request::$client_ip;
             $post->author_host = Request::host_name();
             $post->created = time();
             try {
                 $post->is_valid();
             } catch (Validation_Exception $e) {
                 $errors += $e->array->errors('validate');
             }
             $topic->author_id = self::$user->id;
             $topic->author_name = self::$user->username;
             $topic->name = $_POST['name'];
             $topic->forum_area_id = $area->id;
             $topic->created = time();
             try {
                 $topic->is_valid();
             } catch (Validation_Exception $e) {
                 $errors += $e->array->errors('validate');
             }
             // If no errors found, save models
             if (empty($errors)) {
                 $topic->save();
                 // Recipients
                 if ($this->private) {
                     $topic->set_recipients($post_recipients);
                 }
                 // Post
                 $post->forum_topic_id = $topic->id;
                 $post->save();
                 // Topic
                 $topic->first_post_id = $topic->last_post_id = $post->id;
                 $topic->last_poster = self::$user->username;
                 $topic->last_posted = time();
                 $topic->post_count = 1;
                 $topic->save();
                 // Area, only public forums
                 if (!$this->private) {
                     $area->last_topic_id = $topic->id;
                     $area->post_count++;
                     $area->topic_count++;
                     $area->save();
                 }
                 // User
                 self::$user->post_count++;
                 self::$user->save();
                 // News feed
                 if (!$this->private) {
                     NewsfeedItem_Forum::topic(self::$user, $topic);
                 }
                 $this->request->redirect(Route::model($topic));
             }
             isset($post_recipients) and $recipients = $post_recipients;
         } else {
             // Old topic
             $topic->set_fields(Arr::intersect($_POST, array('name', 'status', 'sticky')));
             try {
                 $topic->save();
                 // Recipients
                 if ($this->private) {
                     $topic->set_recipients($post_recipients);
                 }
                 $this->request->redirect(Route::model($topic));
             } catch (Validation_Exception $e) {
                 $errors = $e->array->errors('validate');
             }
         }
     }
     $form['errors'] = $errors;
     $section = $this->section_post_edit($mode, isset($post) ? $post : null);
     $section->forum_topic = $topic;
     $section->errors = $errors;
     $section->cancel = $cancel;
     $section->recipients = isset($recipients) ? implode(', ', $recipients) : null;
     $this->view->add(View_Page::COLUMN_MAIN, $section);
 }
コード例 #15
0
ファイル: user.php プロジェクト: anqh/core
 /**
  * Action: hover card
  */
 public function action_hover()
 {
     $this->history = false;
     // Hover card works only with ajax
     if ($this->_request_type !== Controller::REQUEST_AJAX) {
         return $this->action_index();
     }
     if ($user = Model_User::find_user_light(urldecode((string) $this->request->param('username')))) {
         $this->response->body(new View_User_HoverCard($user));
     } else {
         $this->response->body(__('Member not found o_O'));
     }
 }
コード例 #16
0
ファイル: users.php プロジェクト: anqh/core
 *
 * @package    Anqh
 * @author     Antti Qvickström
 * @copyright  (c) 2010 Antti Qvickström
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 */
?>


<div class="users">
	<?php 
// Build short (friends) and long (others) user list
$short = $long = array();
$total = count($users);
foreach ($users as $user) {
    $user = is_array($user) ? $user : Model_User::find_user_light($user);
    if ($total < 11 || $viewer && $viewer->is_friend($user)) {
        $short[mb_strtoupper($user['username'])] = HTML::user($user);
    } else {
        $long[mb_strtoupper($user['username'])] = HTML::user($user);
    }
}
ksort($long);
// If no friends, pick random from long
if (empty($short) && !empty($long)) {
    $shorts = (array) array_rand($long, min(10, count($long)));
    foreach ($shorts as $move) {
        $short[$move] = $long[$move];
        unset($long[$move]);
    }
}
コード例 #17
0
ファイル: automodeler.php プロジェクト: anqh/core
 /**
  * Get model author light array
  *
  * @return  array
  */
 public function author()
 {
     return !empty($this->_data['author_id']) ? Model_User::find_user_light($this->_data['author_id']) : null;
 }
コード例 #18
0
ファイル: post.php プロジェクト: anqh/forum
<?php

defined('SYSPATH') or die('No direct access allowed.');
/**
 * Forum post
 *
 * @package    Forum
 * @author     Antti Qvickström
 * @copyright  (c) 2010 Antti Qvickström
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 */
// Post author
// @todo Fix this idiocracy
if ($author = Model_User::find_user_light($post->author_id)) {
    $author_full = Model_User::find_user($author['id']);
}
// Viewer's post
$my = $user && $author && $author['id'] == $user->id;
// Topic author's post
$owners = $author ? $author['id'] == $topic->author_id : $post->author_name == $topic->author_name;
?>

	<article id="post-<?php 
echo $post->id;
?>
" class="post <?php 
echo $owners ? 'owner ' : '', $my ? 'my ' : '', Text::alternate('', 'alt');
?>
">

		<section class="author grid2 first">