public function profile($id, $action) { $this->view = 'user/profile/view'; \CODOF\Store::set('meta:robots', 'noindex, follow'); if ($id == null) { $id = 0; } if ($action == null) { $action = 'view'; } $profile = new \CODOF\User\Profile(); $uid = $profile->get_uid($id); $currUser = \CODOF\User\User::get(); if (!$currUser->can('view user profiles') && $uid != $currUser->id) { //if current user cannot view user profiles and if he is trying //to view a profile that is not his, we need to deny him permission $action = 'deny'; } $user = \CODOF\User\User::getByIdOrUsername($uid, $uid); if ($user) { $user->avatar = $user->getAvatar(); //pass user object to template $this->smarty->assign('user', $user); $this->smarty->assign('rname', \CODOF\User\User::getRoleName($user->rid)); \CODOF\Store::set('sub_title', $user->username); $can_edit = $this->can_edit_profile($uid); if ($action == 'edit' && $can_edit) { $this->view = 'user/profile/edit'; $this->css_files = array('profile_edit'); $this->js_files = array(array(DATA_PATH . 'assets/js/user/profile/edit.js', array('type' => 'defer')), array('bootstrap-slider.js', array('type' => 'defer'))); $subscriber = new \CODOF\Forum\Notification\Subscriber(); $categories = $subscriber->getCategorySubscriptions($uid); $topics = $subscriber->getTopicSubscriptions($uid); $this->smarty->assign('categories', $categories); $this->smarty->assign('topics', $topics); $this->smarty->assign('signature_char_lim', \CODOF\Util::get_opt('signature_char_lim')); } else { if ($action == 'view') { $this->view = 'user/profile/view'; if ($uid != $currUser->id) { $user->incProfileViews(); } $this->smarty->assign('user_not_confirmed', $uid == $currUser->id && !$user->isConfirmed()); $reg_req_admin = \CODOF\Util::get_opt('reg_req_admin') == 'yes'; $this->smarty->assign('user_not_approved', $uid == $currUser->id && (int) $user->rid == ROLE_UNVERIFIED && $reg_req_admin); $this->smarty->assign('can_edit', $can_edit); $this->css_files = array('profile_view'); $this->js_files = array(array(DATA_PATH . 'assets/js/user/profile/view.js', array('type' => 'defer'))); \CODOF\Hook::call('before_profile_view', $user); } else { $this->view = 'access_denied'; } } } else { $this->view = 'not_found'; } }
/** 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; }
/** * * @param array $data * @return bool */ public function queueNotify($type, $data) { if (!isset($data['actor'])) { $user = \CODOF\User\User::get(); $data["actor"] = array("username" => $user->username, "id" => $user->id, "role" => \CODOF\User\User::getRoleName($user->rid), "avatar" => $user->rawAvatar); } //Insert notification data JSON encoded $nid = \DB::table(PREFIX . 'codo_notify_text')->insertGetId(array("data" => json_encode($data))); //queue notification $qry = "INSERT INTO " . PREFIX . "codo_notify_queue (type, nid) " . " VALUES(:type, :nid)"; $stmt = $this->db->prepare($qry); $created = $stmt->execute(array("type" => $type, "nid" => $nid)); $cron = new \CODOF\Cron\Cron(); $cron->setOnce('notify', 0); return $created; }