private function format($topics)
 {
     $_topics = array();
     $i = 0;
     foreach ($topics as $topic) {
         $message = \CODOF\Format::message($topic['message']);
         $_topics[$i] = array("cat_alias" => $topic['cat_alias'], "cat_img" => $topic['cat_img'], "id" => $topic['id'], "avatar" => \CODOF\Util::get_avatar_path($topic['avatar'], $topic['id']), "name" => $topic['name'], "post_created" => \CODOF\Time::get_pretty_time($topic['post_created']), "topic_id" => $topic['topic_id'], "post_id" => $topic['post_id'], "safe_title" => \CODOF\Filter::URL_safe($topic['title']), "title" => \CODOF\Util::mid_cut($topic['title'], 200), "no_replies" => \CODOF\Util::abbrev_no($topic['no_posts'] - 1, 1), "no_views" => \CODOF\Util::abbrev_no($topic['no_views'], 1), "last_post_uid" => $topic['last_post_uid'], "last_post_name" => $topic['last_post_name'], "last_post_time" => \CODOF\Time::get_pretty_time($topic['last_post_time'] != $topic['topic_created'] ? $topic['last_post_time'] : NULL));
         $excerpt = \CODOF\Format::excerpt($message, $topic['topic_id'], $_topics[$i]["safe_title"]);
         $_topics[$i]["message"] = $excerpt['message'];
         $_topics[$i]["overflow"] = $excerpt['overflow'];
         $_topics[$i]["status"] = $topic['topic_status'];
         $_topics[$i]["what"] = 'is_topic';
         $i++;
     }
     return $_topics;
 }
Esempio n. 2
0
 private function gen_posts_arr($posts)
 {
     $_posts = array();
     $i = 0;
     $topics_set = array();
     foreach ($posts as $post) {
         if (isset($topics_set[$post['topic_id']])) {
             $_posts[$topics_set[$post['topic_id']]]['contents'][] = array("post_id" => $post['post_id'], "message" => \CODOF\Format::message($post['message']), "post_created" => \CODOF\Time::get_pretty_time($post['post_created']));
             //$topics_set[$post['topic_id']]++;
             continue;
         }
         $_posts[$i] = array("id" => $post['id'], "avatar" => \CODOF\Util::get_avatar_path($post['avatar'], $post['id']), "name" => $post['name'], "no_replies" => \CODOF\Util::abbrev_no($post['no_posts'] - 1, 1), "no_views" => \CODOF\Util::abbrev_no($post['no_views'], 1), "topic_created" => \CODOF\Time::get_pretty_time($post['topic_created']), "cat_alias" => $post['cat_alias'], "cat_img" => $post['cat_img'], "contents" => array(array("post_id" => $post['post_id'], "message" => \CODOF\Format::message($post['message']), "post_created" => \CODOF\Time::get_pretty_time($post['post_created']))), "topic_id" => $post['topic_id'], "safe_title" => \CODOF\Filter::URL_safe($post['title']), "title" => html_entity_decode(\CODOF\Util::mid_cut($post['title'], 200), ENT_NOQUOTES, "UTF-8"));
         $topics_set[$post['topic_id']] = $i;
         $i++;
     }
     return $_posts;
 }
Esempio n. 3
0
 /**
  * Returns user info from database 
  * @param string $qry
  * @param array $vals
  * @param PDO $db
  * @return object
  */
 protected static function getUserObject($qry, $vals, $db)
 {
     $obj = $db->prepare($qry);
     $obj->execute($vals);
     $userDetails = $obj->fetchAll(PDO::FETCH_OBJ);
     foreach ($userDetails as $u) {
         $rids[] = $u->rid;
         if ($u->is_primary == '1') {
             $primary_rid = $u->rid;
         }
     }
     if (isset($userDetails[0])) {
         $user = $userDetails[0];
         $user->rids = $rids;
         $user->rid = $primary_rid;
         unset($user->is_primary);
         //not required and is wrong
     }
     if (isset($user) && property_exists($user, 'id')) {
         $user->rawAvatar = $user->avatar;
         $user->avatar = \CODOF\Util::get_avatar_path($user->avatar, $user->id);
         return $user;
     }
     \CODOF\Util::log('Unable to fetch user data User.php:39 vals= ' . print_r($vals, true) . ' ' . print_r($_SESSION, true));
     return false;
 }
Esempio n. 4
0
 /** private functions --------------------------------------------------------- */
 public function gen_posts_arr($posts, $search = false)
 {
     $_posts = array();
     $user = \CODOF\User\User::get();
     $uid = $user->id;
     $i = 0;
     foreach ($posts as $post) {
         $message = \CODOF\Format::message($post['message']);
         if ($search) {
             $message = $search->get_matching_str($message);
         }
         $_posts[$i] = array("id" => $post['id'], "avatar" => \CODOF\Util::get_avatar_path($post['avatar'], $post['id']), "name" => $post['name'], "post_created" => \CODOF\Time::get_pretty_time($post['post_created']), "post_modified" => \CODOF\Time::get_pretty_time($post['post_modified']), "post_id" => $post['post_id'], "message" => $message, "imessage" => $post['imessage'], "reputation" => $post['reputation'], "role" => \CODOF\User\User::getRoleName($post['rid']), "no_posts" => \CODOF\Util::abbrev_no($post['no_posts'], 1), "signature" => $post['signature']);
         $_posts[$i]['tid'] = $this->tid;
         $_posts[$i]['page'] = $this->from + 1;
         $_posts[$i]['safe_title'] = $this->safe_title;
         if ($this->topic_post_id == $post['post_id']) {
             //is a topic
             $_posts[$i]['is_topic'] = true;
             if ($post['id'] == $uid) {
                 //this topic belongs to current user
                 $_posts[$i]['can_edit_topic'] = $user->can(array('edit my topics', 'edit all topics'), $this->cat_id);
                 $_posts[$i]['can_delete_topic'] = $user->can(array('delete my topics', 'delete all topics'), $this->cat_id);
             } else {
                 $_posts[$i]['can_edit_topic'] = $user->can('edit all topics', $this->cat_id);
                 $_posts[$i]['can_delete_topic'] = $user->can('delete all topics', $this->cat_id);
             }
             $_posts[$i]['can_manage_topic'] = $_posts[$i]['can_edit_topic'] || $_posts[$i]['can_delete_topic'];
         } else {
             $_posts[$i]['is_topic'] = false;
             if ($post['id'] == $uid) {
                 //this topic belongs to current user
                 $_posts[$i]['can_edit_post'] = $user->can(array('edit my posts', 'edit all posts'), $this->cat_id);
                 $_posts[$i]['can_delete_post'] = $user->can(array('delete my posts', 'delete all posts'), $this->cat_id);
             } else {
                 $_posts[$i]['can_edit_post'] = $user->can('edit all posts', $this->cat_id);
                 $_posts[$i]['can_delete_post'] = $user->can('delete all posts', $this->cat_id);
             }
             $_posts[$i]['can_manage_post'] = $_posts[$i]['can_edit_post'] || $_posts[$i]['can_delete_post'];
         }
         $_posts[$i]['can_see_history'] = $user->can('see history', $this->cat_id);
         if ($this->tuid == $uid) {
             //if my topic
             $_posts[$i]['can_reply'] = true;
             //i can reply to my own topic
         } else {
             $_posts[$i]['can_reply'] = $user->can('reply to all topics', $this->cat_id, $this->tid);
         }
         if ($search) {
             $_posts[$i]['in_search'] = true;
         }
         $i++;
     }
     return $_posts;
 }
Esempio n. 5
0
 public function gen_topic_arr($topics, $cid)
 {
     $_topics = array();
     $user = \CODOF\User\User::get();
     $uid = $user->id;
     $i = 0;
     foreach ($topics as $topic) {
         $message = \CODOF\Format::message($topic['message']);
         $_topics[$i] = array("id" => $topic['id'], "avatar" => \CODOF\Util::get_avatar_path($topic['avatar'], $topic['id']), "name" => $topic['name'], "post_created" => \CODOF\Time::get_pretty_time($topic['post_created']), "topic_created" => $topic['topic_created'], "topic_id" => $topic['topic_id'], "post_id" => $topic['post_id'], "safe_title" => \CODOF\Filter::URL_safe(html_entity_decode($topic['title'])), "title" => $topic['title'], "no_replies" => \CODOF\Util::abbrev_no($topic['no_posts'] - 1, 1), "no_views" => \CODOF\Util::abbrev_no($topic['no_views'], 1), "last_post_name" => $topic['lname'], "last_post_uid" => $topic['luid'], "sticky" => Forum::isSticky($topic['topic_status']), "last_post_id" => $topic['last_post_id'], "last_post_time" => \CODOF\Time::get_pretty_time($topic['lpost_time'] != $topic['topic_created'] ? $topic['lpost_time'] : NULL));
         $excerpt = \CODOF\Format::excerpt($message, $topic['topic_id'], $_topics[$i]["safe_title"]);
         $_topics[$i]["message"] = $excerpt['message'];
         $_topics[$i]["overflow"] = $excerpt['overflow'];
         if ($topic['uid'] == $uid) {
             //this topic belongs to current user
             $_topics[$i]['can_edit_topic'] = $user->can(array('edit my topics', 'edit all topics'), $cid);
             $_topics[$i]['can_delete_topic'] = $user->can(array('delete my topics', 'delete all topics'), $cid);
         } else {
             $_topics[$i]['can_edit_topic'] = $user->can('edit all topics', $cid);
             $_topics[$i]['can_delete_topic'] = $user->can('delete all topics', $cid);
         }
         $_topics[$i]['can_manage_topic'] = $_topics[$i]['can_edit_topic'] || $_topics[$i]['can_delete_topic'];
         if (isset($search)) {
             $_topics[$i]['in_search'] = true;
         }
         if (in_array($topic['topic_id'], $this->new_topic_ids)) {
             $_topics[$i]["new_topic"] = true;
         }
         if (in_array($topic['topic_id'], $this->new_replies)) {
             $_topics[$i]["new_replies"] = $this->new_replies[$topic['topic_id']][0];
             $_topics[$i]["last_reply_id"] = $this->new_replies[$topic['topic_id']][1];
         }
         if (isset($this->tags[$topic['topic_id']])) {
             $_topics[$i]["tags"] = $this->tags[$topic['topic_id']];
         }
         $i++;
     }
     return $_topics;
 }
Esempio n. 6
0
 /**
  * Get matched users with limit 10
  * @param string $qry
  * @return array
  */
 public function find($qry, $catid, $tid)
 {
     $cid = (int) $catid;
     $tid = (int) $tid;
     $selector = '';
     if ($cid) {
         $selector = ', MAX(p.granted) AS allowed';
     }
     $users = \DB::table(PREFIX . 'codo_users AS u');
     $users->select(\DB::raw('u.id, u.username, u.avatar' . $selector))->where('u.username', 'LIKE', "{$qry}%")->where('u.mail', '<>', 'anonymous@localhost');
     if ($cid) {
         $users->leftJoin(PREFIX . 'codo_user_roles AS r', 'r.uid', '=', 'u.id')->leftJoin(PREFIX . 'codo_permissions AS p', function ($join) use($cid) {
             $join->on('p.permission', '=', \DB::raw('\'view all topics\''))->on('p.rid', '=', 'r.rid')->on('p.cid', '=', \DB::raw($cid))->on('p.tid', '=', \DB::raw(0));
         })->groupBy('u.id');
     }
     $users = $users->take(10)->get();
     $type = '';
     if ($cid) {
         $type = 'new_topic';
     }
     if ($tid) {
         $type = 'new_reply';
     }
     $mutedIds = array();
     if ($type != '' && count($users)) {
         $uids = array_column($users, 'id');
         $subscriber = new Subscriber();
         $mutedIds = $subscriber->mutedOf($type, $cid, $tid, $uids);
     }
     $_users = array();
     $i = 0;
     foreach ($users as $user) {
         $_users[$i]["username"] = $user['username'];
         $_users[$i]["avatar"] = \CODOF\Util::get_avatar_path($user['avatar'], $user['id'], false);
         if ($cid) {
             //if $cid is not provided can't say whether user is mentionable or not
             $notMentionable = in_array($user['id'], $mutedIds) || $user['allowed'] === 0;
             $_users[$i]["mentionable"] = !$notMentionable ? 'yes' : 'no';
             //better for js -> y/n
         }
         $i++;
     }
     return $_users;
 }