Example #1
0
 public function getLeaderboard($limit = 10)
 {
     $widget = $limit == 10;
     // Is there cache
     if ($widget && ($cache = $this->app->cache->get('scoreboard', 1))) {
         return json_decode($cache);
     }
     $sql = 'SELECT users.user_id, username, score, (users_medals.user_id IS NOT NULL) AS donator, profile.gravatar,
                 IF (profile.gravatar = 1, users.email, profile.img) as `image`
                 FROM users
                 LEFT JOIN users_profile profile
                 ON users.user_id = profile.user_id
                 LEFT JOIN users_priv
                 ON users_priv.user_id = users.user_id
                 LEFT JOIN users_medals
                 ON users.user_id = users_medals.user_id AND users_medals.medal_id = (SELECT medal_id FROM medals WHERE label = "Donator")
                 WHERE COALESCE(show_leaderboard, 1) = 1
                 ORDER BY score DESC, user_id ASC
                 LIMIT ' . $limit;
     $st = $this->app->db->prepare($sql);
     $st->execute();
     $board = $st->fetchAll();
     $found = false;
     for ($n = 0; $n < ($widget ? 3 : count($board)); $n++) {
         $user = $board[$n];
         if (isset($user->image)) {
             $gravatar = isset($user->gravatar) && $user->gravatar == 1;
             $user->image = profile::getImg($user->image, $widget ? 18 : 22, $gravatar);
         } else {
             $user->image = profile::getImg(null, $widget ? 18 : 22);
         }
         if ($user->user_id == $this->app->user->uid) {
             $user->highlight = true;
             $found = true;
         }
     }
     if (!$widget && !$found) {
         // find users position
         $sql = 'SELECT COUNT(user_id) AS `position` FROM users WHERE score > :score';
         $st = $this->app->db->prepare($sql);
         $st->execute(array(':score' => $this->app->user->score));
         $result = $st->fetch();
         $result->extra = true;
         $result->highlight = true;
         $result->score = $this->app->user->score;
         $result->username = $this->app->user->username;
         $result->donator = $this->app->user->donator;
         $result->image = $this->app->user->image;
         $board[$limit] = $result;
     }
     // Cache
     if ($widget) {
         $this->app->cache->set('scoreboard', json_encode($board));
     }
     return $board;
 }
Example #2
0
?>
</h1>

<?php 
if (!count($profile->friendsList)) {
    $app->utils->message('You haven\'t added any friends yet', 'info');
} else {
    ?>
        <ul class='users-list'>
<?php 
    foreach ($profile->friendsList as $friend) {
        if (isset($friend->image)) {
            $gravatar = isset($friend->gravatar) && $friend->gravatar == 1;
            $friend->image = profile::getImg($friend->image, 48, $gravatar);
        } else {
            $friend->image = profile::getImg(null, 48);
        }
        ?>
            <li>
                <div>
                    <a href='/user/<?php 
        echo $friend->username;
        ?>
'>
                        <img src='<?php 
        echo $friend->image;
        ?>
' width='100%' alt='<?php 
        echo $friend->username;
        ?>
 profile picture'/>
Example #3
0
 /**
  * Initaite Twig parser
  *
  * @param none
  *
  * @return void
  */
 private function initTwig()
 {
     // Load Twig
     require_once $this->config['path'] . '/files/vendor/Twig/Autoloader.php';
     Twig_Autoloader::register();
     $loader = new Twig_Loader_Filesystem($this->config['path'] . "/files/templates/");
     $this->twig = new Twig_Environment($loader, array('cache' => false, 'autoescape' => false));
     $wysiwyg = new Twig_SimpleFunction('wysiwyg', function ($name = "", $placeholder = "", $text = "") {
         $wysiwyg_name = $name;
         $wysiwyg_placeholder = $placeholder;
         $wysiwyg_text = $text;
         include 'elements/wysiwyg.php';
     });
     $this->twig->addFunction($wysiwyg);
     $csrf = new Twig_SimpleFunction('CSRFKey', function ($name) {
         echo $this->generateCSRFKey($name);
     });
     $this->twig->addFunction($csrf);
     $msg = new Twig_SimpleFunction('msg', function ($text, $type = "error") {
         $this->utils->message($text, $type);
     });
     $this->twig->addFunction($msg);
     $this->twig->addFilter('floor', new Twig_Filter_Function('floor'));
     $this->twig->addFilter('ceil', new Twig_Filter_Function('ceil'));
     $since = new Twig_Filter_Function(function ($time) {
         return $this->utils->timeSince($time);
     });
     $this->twig->addFilter('since', $since);
     $sinceShort = new Twig_Filter_Function(function ($time) {
         return $this->utils->timeSince($time, false, true);
     });
     $this->twig->addFilter('sinceShort', $sinceShort);
     $getImg = new Twig_SimpleFunction('getImg', function ($img, $size = 48, $gravatar = false) {
         echo profile::getImg($img, $size, $gravatar);
     });
     $this->twig->addFunction($getImg);
     $include = new Twig_SimpleFunction('include', function ($file) {
         $app = $this;
         include $file;
     });
     $this->twig->addFunction($include);
     $printForumSection = new Twig_SimpleFunction('printForumSection', function ($section) {
         $this->forum->printSectionsList($section, true);
     });
     $this->twig->addFunction($printForumSection);
 }
Example #4
0
 public function getThread($thread_id, $page = 1, $limit = 10, $admin = false)
 {
     $sql = "SELECT thread.thread_id AS `id`, thread.title, thread.slug, thread.deleted, thread.closed, thread.sticky,\n                    section.slug AS section_slug, replies.count AS replies, COALESCE(forum_users.watching, 0) AS `watching`, IF(section.priv_level,IF(users_levels.level_id > 0, 1, 0),1) AS `access`\n                    FROM forum_threads thread\n                    LEFT JOIN forum_users\n                    ON forum_users.thread_id = thread.thread_id AND forum_users.user_id = :uid\n                    LEFT JOIN forum_sections section\n                    ON section.section_id = thread.section_id\n                    LEFT JOIN (SELECT `thread_id`, count(*)-1 AS `count` FROM forum_posts WHERE deleted = 0 GROUP BY `thread_id`) replies\n                    ON replies.thread_id = thread.thread_id\n                    LEFT JOIN users_levels\n                    ON users_levels.user_id = :uid AND users_levels.completed > 0 AND users_levels.level_id = section.priv_level\n                    WHERE thread.thread_id = :thread_id AND (thread.section_id != 95 && (thread.section_id < 100 || thread.section_id > 233)) AND thread.deleted = 0\n                    LIMIT 1";
     $st = $this->app->db->prepare($sql);
     $st->execute(array(':thread_id' => $thread_id, ':uid' => $this->app->user->uid));
     $thread = $st->fetch();
     if (!$thread) {
         return false;
     }
     // does the user have access
     if (!$thread->access) {
         return false;
     }
     $thread->title = $this->app->parse($thread->title, false);
     if ($thread->closed) {
         $thread->title = '[closed] ' . $thread->title;
     }
     if ($thread->sticky) {
         $thread->title = '[sticky] ' . $thread->title;
     }
     // Get question
     $st = $this->app->db->prepare("SELECT post.post_id, users.user_id, users.username, post.body, post.posted, post.updated AS edited, profile.forum_signature AS signature,\n                profile.gravatar, IF (profile.gravatar = 1, users.email , profile.img) as `image`,\n                forum_posts.posts, users.score, coalesce(users_forum.karma, 0) AS `karma`, coalesce(user_karma.karma, 0) AS `user_karma`, (donate.medal_id IS NOT NULL) AS donator\n                FROM forum_posts post\n                LEFT JOIN users\n                ON users.user_id = post.author\n                LEFT JOIN users_profile profile\n                ON users.user_id = profile.user_id\n                LEFT JOIN users_medals donate\n                ON users.user_id = donate.user_id AND donate.medal_id = 19\n                LEFT JOIN (SELECT author, COUNT(*) AS `posts` FROM forum_posts WHERE deleted = 0 GROUP BY author) forum_posts\n                ON forum_posts.author = post.author\n                LEFT JOIN (SELECT post_id, SUM(karma) AS `karma` FROM users_forum GROUP BY post_id) users_forum\n                ON users_forum.post_id = post.post_id\n                LEFT JOIN (SELECT post_id, user_id, karma FROM users_forum) user_karma\n                ON user_karma.post_id = post.post_id AND user_karma.user_id = :uid\n                WHERE post.thread_id = :thread_id AND post.deleted = 0\n                ORDER BY `posted` ASC\n                LIMIT 1");
     $st->execute(array(':thread_id' => $thread_id, ':uid' => $this->app->user->uid));
     $thread->question = $st->fetch();
     // Get questioners image
     if (isset($thread->question->image)) {
         $gravatar = isset($thread->question->gravatar) && $thread->question->gravatar == 1;
         $thread->question->image = profile::getImg($thread->question->image, 60, $gravatar);
     } else {
         $thread->question->image = profile::getImg(null, 60);
     }
     $thread->p_start = ($page - 1) * $limit + 1;
     // Get replies
     $st = $this->app->db->prepare("SELECT post.post_id, users.user_id, users.username, post.body, post.posted, post.updated AS edited, profile.forum_signature AS signature,\n                profile.gravatar, IF (profile.gravatar = 1, users.email , profile.img) as `image`,\n                forum_posts.posts, users.score, coalesce(users_forum.karma, 0) AS `karma`, coalesce(user_karma.karma, 0) AS `user_karma`, (donate.medal_id IS NOT NULL) AS donator\n                FROM forum_posts post\n                LEFT JOIN users\n                ON users.user_id = post.author\n                LEFT JOIN users_profile profile\n                ON users.user_id = profile.user_id\n                LEFT JOIN users_medals donate\n                ON users.user_id = donate.user_id AND donate.medal_id = 19\n                LEFT JOIN (SELECT author, COUNT(*) AS `posts` FROM forum_posts WHERE deleted = 0 GROUP BY author) forum_posts\n                ON forum_posts.author = post.author\n                LEFT JOIN (SELECT post_id, SUM(karma) AS `karma` FROM users_forum GROUP BY post_id) users_forum\n                ON users_forum.post_id = post.post_id\n                LEFT JOIN (SELECT post_id, user_id, karma FROM users_forum) user_karma\n                ON user_karma.post_id = post.post_id AND user_karma.user_id = :uid\n                WHERE post.thread_id = :thread_id AND post.deleted = 0\n                ORDER BY `posted` ASC\n                LIMIT :l1, :l2");
     $st->bindValue(':thread_id', $thread_id);
     $st->bindValue(':uid', $this->app->user->uid);
     $st->bindValue(':l1', (int) $thread->p_start, PDO::PARAM_INT);
     $st->bindValue(':l2', (int) $limit, PDO::PARAM_INT);
     $st->execute();
     $thread->posts = $st->fetchAll();
     // Get posts images
     foreach ($thread->posts as $post) {
         if (isset($post->image)) {
             $gravatar = isset($post->gravatar) && $post->gravatar == 1;
             $post->image = profile::getImg($post->image, 50, $gravatar);
         } else {
             $post->image = profile::getImg(null, 50);
         }
     }
     $thread->p_end = $thread->p_start + count($thread->posts) - 1;
     // Get section slug
     $thread->section = $this->getSection($thread->section_slug);
     //Update view status
     if ($this->app->user->loggedIn) {
         $st = $this->app->db->prepare("INSERT INTO forum_users (`user_id`, `thread_id`)\n                        VALUES (:uid, :thread_id) ON DUPLICATE KEY UPDATE `viewed` = now()");
         $st->execute(array(':thread_id' => $thread_id, ':uid' => $this->app->user->uid));
         // Mark notifications as seen
         $st = $this->app->db->prepare("update users_notifications SET seen = 1 WHERE notification_id IN (\n                                                    SELECT notifications.id\n                                                    FROM (  select notification_id as `id`\n                                                            from users_notifications\n                                                            inner join forum_posts\n                                                            on users_notifications.item_id = forum_posts.post_id\n                                                            where (type='forum_reply' or type='forum_post') AND user_id = :uid AND thread_id = :thread_id AND seen = 0\n                                                         ) AS `notifications`\n                                                    );");
         $st->execute(array(':thread_id' => $thread_id, ':uid' => $this->app->user->uid));
     }
     return $thread;
 }
Example #5
0
 public function __construct($username, $public = false)
 {
     global $app;
     $this->app = $app;
     if ($public) {
         $st = $this->app->db->prepare("SELECT u.user_id as uid, u.username, u.score, u.email, profile.show_email, profile.about, profile.forum_signature,\n                    friends.status AS friends, profile.gravatar,\n                    IF (profile.gravatar = 1, u.email , profile.img) as `image`,\n                    IF (priv.site_priv = 2, true, false) AS admin, IF(priv.forum_priv = 2, true, false) AS moderator,\n                    coalesce(priv.site_priv, 1) AS `site_priv`, coalesce(priv.pm_priv, 1) AS `pm_priv`, coalesce(priv.forum_priv, 1) AS `forum_priv`, coalesce(priv.pub_priv, 1) AS `pub_priv`\n                    FROM users u\n                    LEFT JOIN users_profile profile\n                    ON u.user_id = profile.user_id\n                    LEFT JOIN users_friends friends\n                    ON (friends.user_id = u.user_id AND friends.friend_id = :user) OR (friends.user_id = :user AND friends.friend_id = u.user_id)\n                    LEFT JOIN users_priv priv\n                    ON u.user_id = priv.user_id\n                    WHERE u.user_id = :profile or u.username = :profile");
         $st->execute(array(':profile' => $username, ':user' => $this->app->user->uid));
         $st->setFetchMode(PDO::FETCH_INTO, $this);
         $res = $st->fetch();
         if (!$res) {
             return false;
         }
         // is this user allowed to see that stuff?
         if (!$this->app->user->admin_site_priv && !$this->show_email) {
             unset($this->email);
         }
         unset($this->show_email);
         if (isset($this->image)) {
             $gravatar = isset($this->gravatar) && $this->gravatar == 1;
             $this->image = profile::getImg($this->image, 198, $gravatar);
         } else {
             $this->image = profile::getImg(null, 198);
         }
         unset($this->gravatar);
         if (!$this->app->admin) {
             unset($this->site_priv);
             unset($this->pm_priv);
             unset($this->forum_priv);
             unset($this->pub_priv);
         }
         if ($this->friends === null) {
             unset($this->friends);
         }
     } else {
         $st = $this->app->db->prepare("SELECT u.user_id as uid, u.username, u.score, u.email, profile.*, activity.joined,\n                    activity.last_active, friends.status AS friends, friends.user_id AS friend, profile.gravatar,\n                    IF (profile.gravatar = 1, u.email , profile.img) as `image`,\n                    IF(priv.site_priv = 2, true, false) AS admin, IF(priv.forum_priv = 2, true, false) AS moderator,\n                    priv.*,\n                    forum_posts.posts, articles.articles, (donated.user_id IS NOT NULL) AS donator, (users_blocks.user_id IS NOT NULL) AS blocked, (users_blocks_me.user_id IS NOT NULL) AS blockedMe, karma.karma\n                    FROM users u\n                    LEFT JOIN users_profile profile\n                    ON u.user_id = profile.user_id\n                    LEFT JOIN users_activity activity\n                    ON u.user_id = activity.user_id\n                    LEFT JOIN users_friends friends\n                    ON (friends.user_id = u.user_id AND friends.friend_id = :user) OR (friends.user_id = :user AND friends.friend_id = u.user_id)\n                    LEFT JOIN users_blocks \n                    ON users_blocks.user_id = :user AND users_blocks.blocked_id = u.user_id\n                    LEFT JOIN users_blocks users_blocks_me\n                    ON users_blocks_me.user_id = u.user_id AND users_blocks_me.blocked_id = :user\n                    LEFT JOIN (SELECT author, COUNT(*) AS `posts` FROM forum_posts WHERE deleted = 0 GROUP BY author) forum_posts\n                    ON forum_posts.author = u.user_id\n                    LEFT JOIN (SELECT user_id, COUNT(*) AS `articles` FROM articles GROUP BY user_id) articles\n                    ON articles.user_id = u.user_id\n                    LEFT JOIN users_priv priv\n                    ON u.user_id = priv.user_id\n                    LEFT JOIN users_medals donated\n                    ON u.user_id = donated.user_id AND donated.medal_id = (SELECT medal_id FROM medals WHERE label = 'Donator')\n                    LEFT JOIN (SELECT SUM(karma) AS karma, forum_posts.author FROM users_forum INNER JOIN forum_posts ON users_forum.post_id = forum_posts.post_id AND forum_posts.deleted = 0 GROUP BY forum_posts.author) karma\n                    ON karma.author = u.user_id\n                    WHERE u.username = :profile");
         $st->execute(array(':profile' => $username, ':user' => $this->app->user->uid));
         $st->setFetchMode(PDO::FETCH_INTO, $this);
         $res = $st->fetch();
     }
     if (!$res) {
         return false;
     }
     if (isset($this->image)) {
         $gravatar = isset($this->gravatar) && $this->gravatar == 1;
         $this->image = profile::getImg($this->image, 198, $gravatar);
     } else {
         $this->image = profile::getImg(null, 198);
     }
     $st = $this->app->db->prepare('SELECT users_medals.medal_id, medals.label, medals.description, medals_colours.colour
                 FROM users_medals
                 INNER JOIN medals
                 ON users_medals.medal_id = medals.medal_id
                 INNER JOIN medals_colours
                 ON medals.colour_id = medals_colours.colour_id
                 WHERE users_medals.user_id = :uid');
     $st->execute(array(':uid' => $this->uid));
     $this->medals = $st->fetchAll();
     if (!$this->app->user->admin) {
         unset($this->site_priv);
         unset($this->pm_priv);
         unset($this->forum_priv);
         unset($this->pub_priv);
     }
     // Limit the amount of information public users can see
     if ($public) {
         return true;
     }
     $st = $this->app->db->prepare('SELECT u.user_id as uid, u.username, users_friends.status, u.score, profile.gravatar, IF (profile.gravatar = 1, u.email , profile.img) as `image`
                 FROM users_friends as friends
                 INNER JOIN users u
                 ON u.user_id = IF(friends.user_id = :uid, friends.friend_id, friends.user_id)
                 LEFT JOIN users_profile profile
                 ON u.user_id = profile.user_id
                 LEFT JOIN users_friends
                 ON (users_friends.user_id = u.user_id AND users_friends.friend_id = :user) OR (users_friends.user_id = :user AND users_friends.friend_id = u.user_id)
                 WHERE friends.status = 1 AND (friends.user_id = :uid OR friends.friend_id = :uid)
                 ORDER BY u.username');
     $st->execute(array(':uid' => $this->uid, ':user' => $this->app->user->uid));
     $this->friendsList = $st->fetchAll();
     // Parse content
     $this->name = $this->app->parse($this->name, false, false);
     if (isset($this->about)) {
         $this->about_plain = $this->app->parse($this->about, false, false);
         $this->about = $this->app->parse($this->about);
     }
     $this->feed = $this->getFeed();
     $this->links = $this->getLinks();
     $this->owner = $this->app->user->uid === $this->uid;
     // Check score and award medal?
     if ($this->score >= $this->app->max_score) {
         $this->score_perc = 100;
     } else {
         $this->score_perc = $this->score / $this->app->max_score * 100;
     }
 }
 public function getFriends()
 {
     // Get items
     $sql = "SELECT notification_id AS id, users.user_id AS uid, item_id, type,\n                               users_notifications.time AS timestamp, seen, username,\n                               profile.gravatar, IF (profile.gravatar = 1, users.email , profile.img) as `image`\n                               FROM users_notifications\n                               LEFT JOIN users\n                               ON users_notifications.from_id = users.user_id\n                               LEFT JOIN users_profile profile\n                               ON profile.user_id = users.user_id\n                               WHERE users_notifications.user_id = :uid\n                               AND `type` = 'friend'\n                               ORDER BY users_notifications.time DESC";
     $st = $this->app->db->prepare($sql);
     $st->bindParam(":uid", $this->app->user->uid);
     $st->execute();
     $result = $st->fetchAll();
     // Loop items, get details and create images
     foreach ($result as $key => &$res) {
         if ($res->type == 'friend') {
             // status
             $st = $this->app->db->prepare("SELECT status\n                        FROM users_friends\n                        WHERE user_id = :friend_id AND friend_id = :uid\n                        LIMIT 1");
             $st->execute(array(':uid' => $this->app->user->uid, ':friend_id' => $res->uid));
             $st->setFetchMode(PDO::FETCH_INTO, $res);
             $st->fetch();
             if ($res->status == true) {
                 unset($result[$key]);
                 continue;
             }
         }
         // Parse title
         if (isset($res->title)) {
             $res->title = $this->app->parse($res->title, false);
         }
         // Profile images
         if (isset($res->image)) {
             $gravatar = isset($res->gravatar) && $res->gravatar == 1;
             $res->img = profile::getImg($res->image, 28, $gravatar);
         } else {
             $res->img = profile::getImg(null, 28);
         }
         unset($res->image);
         unset($res->gravatar);
         unset($res->id);
         unset($res->item_id);
         $res->timestamp = $this->app->utils->fdate($res->timestamp);
     }
     $result = array_values($result);
     return $result;
 }
Example #7
0
 private function searchUsers($term)
 {
     if (strlen($term) <= 3) {
         return false;
     }
     $like = $this->app->utils->escape_like($term, '|');
     $like .= '%';
     $sql = 'SELECT username, users.score, profile.gravatar, IF (profile.gravatar = 1, users.email , profile.img) as `image`, users_friends.status
                 FROM users
                 LEFT JOIN users_profile as profile
                 ON users.user_id = profile.user_id
                 LEFT JOIN users_friends
                 ON (users_friends.user_id = users.user_id AND users_friends.friend_id = :uid) OR (users_friends.user_id = :uid AND users_friends.friend_id = users.user_id)
                 WHERE username LIKE :like ESCAPE \'|\' OR (email = :term AND profile.show_email = 1)
                 ORDER BY username ASC
                 LIMIT 8';
     $st = $this->app->db->prepare($sql);
     $st->execute(array(':like' => $like, ':term' => $term, ':uid' => $this->app->user->uid));
     $result = $st->fetchAll();
     if (!count($result)) {
         return false;
     }
     foreach ($result as $res) {
         if (isset($res->image)) {
             $gravatar = isset($res->gravatar) && $res->gravatar == 1;
             $res->image = profile::getImg($res->image, 48, $gravatar);
         } else {
             $res->image = profile::getImg(null, 48);
         }
     }
     return $result;
 }
Example #8
0
 public function getComment($comment_id, $bbcode = true)
 {
     // Group by required for count
     $st = $this->app->db->prepare('SELECT comments.comment_id as id, comments.comment, DATE_FORMAT(comments.time, \'%Y-%m-%dT%T+01:00\') as `time`, users.username, users.score, users_profile.gravatar,
                 IF (users_profile.gravatar = 1, users.email , users_profile.img) as `image`
                 FROM articles_comments comments
                 LEFT JOIN users
                 ON users.user_id = comments.user_id
                 LEFT JOIN users_profile
                 ON users_profile.user_id = users.user_id
                 WHERE comment_id = :comment_id
                 ORDER BY `time` DESC');
     $st->execute(array(':comment_id' => $comment_id));
     $result = $st->fetchAll();
     foreach ($result as $comment) {
         $comment->comment = $this->app->parse($comment->comment, $bbcode);
         if ($comment->username === $this->app->user->username) {
             $comment->owner = true;
         }
         // Set image
         if (isset($comment->image)) {
             $gravatar = isset($comment->gravatar) && $comment->gravatar == 1;
             $comment->image = profile::getImg($comment->image, 40, $gravatar);
         } else {
             $comment->image = profile::getImg(null, 40);
         }
     }
     return $result;
 }
Example #9
0
 /**
  * Loads all user data into object
  *
  * Also handles checking medals scores/consecutive logins/karma
  *
  * @todo Split functionality into separate functions e.g. medal checks
  */
 public function get_details()
 {
     $this->app->stats->users_activity($this);
     $st = $this->app->db->prepare('SELECT username, score, email, (oauth_id IS NOT NULL) as connected,
                 IFNULL(site_priv, 1) as site_priv, IFNULL(pm_priv, 1) as pm_priv, IFNULL(forum_priv, 1) as forum_priv, IFNULL(pub_priv, 1) as pub_priv, verified, IFNULL(`posts`.posts, 0) AS `posts`,
                 profile.gravatar, profile.img as `image`,
                 activity.consecutive, activity.consecutive_most, activity.joined
                 FROM users u
                 LEFT JOIN users_profile profile
                 ON u.user_id = profile.user_id
                 LEFT JOIN users_priv priv
                 ON u.user_id = priv.user_id
                 LEFT JOIN users_activity activity
                 ON u.user_id = activity.user_id
                 LEFT JOIN (SELECT COUNT(post_id) AS `posts`, author FROM forum_posts WHERE deleted = 0 GROUP BY author) `posts`
                 ON `posts`.author = u.user_id
                 WHERE u.user_id = :user_id');
     $st->execute(array(':user_id' => $this->uid));
     $st->setFetchMode(PDO::FETCH_INTO, $this);
     $st->fetch();
     if ($this->site_priv > 1 || $this->pm_priv > 1 || $this->forum_priv > 1 || $this->pub_priv > 1) {
         $this->admin = true;
     }
     if (isset($this->gravatar) && $this->gravatar == 1) {
         // If user is currently using gravatar but has uploaded an image previously
         if (isset($this->image)) {
             $this->image_old = profile::getImg($this->image, 75, 0);
         }
         $this->image = profile::getImg($this->email, 100, 1);
     } else {
         if (isset($this->image)) {
             $this->image = profile::getImg($this->image, 100, 0);
         } else {
             $this->image = profile::getImg(null, 100);
         }
     }
     // Check score and award medal?
     if ($this->score >= $this->app->max_score) {
         $this->score_perc = 100;
     } else {
         $this->score_perc = $this->score / $this->app->max_score * 100;
     }
     if ($this->score >= 5000) {
         $this->awardMedal('score', 3);
     } else {
         if ($this->score >= 2500) {
             $this->awardMedal('score', 2);
         } else {
             if ($this->score >= 1000) {
                 $this->awardMedal('score');
             }
         }
     }
     // Check consecutive logins
     if ($this->consecutive <= 7) {
         $consecutive_target = 7;
     } elseif ($this->consecutive <= 14) {
         $consecutive_target = 14;
     } else {
         $consecutive_target = 30;
     }
     if ($this->consecutive >= $consecutive_target) {
         $this->consecutive_perc = 100;
     } else {
         $this->consecutive_perc = $this->consecutive / $consecutive_target * 100;
     }
     if ($this->consecutive == 7) {
         $this->awardMedal('visits');
     } else {
         if ($this->consecutive == 14) {
             $this->awardMedal('visits', 2);
         } else {
             if ($this->consecutive == 30) {
                 $this->awardMedal('visits', 3);
             }
         }
     }
     // Veteran medal
     $joined = strtotime($this->joined);
     $target = strtotime('-1 year');
     if ($joined < $target) {
         $this->awardMedal('veteran', 2);
         $this->awardMedal('veteran', 1);
     } else {
         $target = strtotime('-1 month');
         if ($joined < $target) {
             $this->awardMedal('veteran', 1);
         }
     }
     // Is donator / karma priv?
     $this->karma_priv = 0;
     $st = $this->app->db->prepare('SELECT medals.medal_id, medals.colour_id, medals.label FROM medals INNER JOIN users_medals ON medals.medal_id = users_medals.medal_id WHERE (label = :label1 OR label = :label2) AND users_medals.user_id = :uid');
     $st->execute(array(':uid' => $this->uid, ':label1' => 'donator', ':label2' => 'karma'));
     $res = $st->fetchAll();
     foreach ($res as $medal) {
         if (strcasecmp($medal->label, 'donator') === 0) {
             $this->donator = true;
         }
         if (strcasecmp($medal->label, 'karma') === 0) {
             $this->karma_priv++;
         }
     }
     if ($this->karma_priv == 0) {
         if ($this->score >= 500 && $this->posts >= 10) {
             $this->awardMedal('karma', 1);
             $this->karma_priv++;
         }
     }
     if ($this->karma_priv == 1) {
         if ($this->score >= 3000 && $this->posts >= 100) {
             $this->awardMedal('karma', 2);
             $this->karma_priv++;
         }
     }
     // Get or make simple request token
     if (!isset($_SESSION['csrf_basic']) || !$_SESSION['csrf_basic']) {
         $_SESSION['csrf_basic'] = substr(md5(uniqid(rand(), true)), 0, 16);
     }
     $this->csrf_basic = $_SESSION['csrf_basic'];
 }
Example #10
0
 public function getConvo($id, $limit = true)
 {
     $sql = "SELECT message, messages.time as timestamp, IF (messages.time <= seen, 1, 0) AS seen,\n                   username, profile.gravatar, IF (profile.gravatar = 1, users.email , profile.img) as `image`\n                   FROM pm_messages messages\n                   INNER JOIN pm_users\n                   ON messages.pm_id = pm_users.pm_id AND pm_users.user_id = :uid\n                   INNER JOIN users\n                   ON messages.user_id = users.user_id\n                   LEFT JOIN users_profile profile\n                   ON profile.user_id = users.user_id\n                   WHERE messages.pm_id = :pm_id AND (pm_users.deleted IS NULL OR messages.time > pm_users.deleted)\n                   ORDER BY messages.time DESC";
     if ($limit) {
         $sql .= ' LIMIT 5';
     }
     // Get items
     $st = $this->app->db->prepare($sql);
     $st->execute(array(':uid' => $this->app->user->uid, ':pm_id' => $id));
     $result = $st->fetchAll();
     //flip array
     $result = array_reverse($result);
     // Mark thread as seen
     $st = $this->app->db->prepare("UPDATE pm_users SET `seen` = NOW() WHERE user_id = :uid AND pm_id = :pm_id LIMIT 1");
     $st->execute(array(':uid' => $this->app->user->uid, ':pm_id' => $id));
     // Loop items and create images
     foreach ($result as $res) {
         if (isset($res->image)) {
             $gravatar = isset($res->gravatar) && $res->gravatar == 1;
             $res->img = profile::getImg($res->image, 28, $gravatar);
         } else {
             $res->img = profile::getImg(null, 28);
         }
         unset($res->image);
         unset($res->gravatar);
         $res->message = $this->app->parse($res->message);
         //time
         $res->timestamp = $this->app->utils->fdate($res->timestamp);
     }
     return $result;
 }