Ejemplo n.º 1
0
 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';
     }
 }