Exemplo n.º 1
0
 /**
  * Update profile picture
  * @todo this class looks like it's not being used
  * @param integer $userid User ID whose profile picture is going to be updated
  * @param bool $delete Whether to delete profile picture of the user
  * @param array $data Picture data. It should be an array contains
  *			  the following items: 'filename', 'width', 'height', 'filedata' or 'tmp_name'
  */
 public function updateProfilePic($userid, $delete, $data = array())
 {
     // We don't need everything but we need at least one of these
     if (!$delete and empty($data['filedata']) and empty($data['tmp_name']) and empty($data[''])) {
         return false;
     }
     $userContext = vB::getUserContext();
     $currentUserId = $userContext->fetchUserId();
     $userid = intval($userid);
     if ($userid <= 0 and $currentUserId) {
         $userid = $currentUserId;
     }
     // Check if current user canadminusers
     try {
         $this->checkHasAdminPermission('canadminusers');
     } catch (Exception $e) {
         // No. Then we need to do something here.
         if ($currentUserId != $userid) {
             // If current user isn't the same as passed $userid
             throw new vB_Exception_Api('no_permission');
         }
     }
     $userinfo = vB_User::fetchUserInfo(intval($userid));
     $bf_ugp_genericpermissions = vB::getDatastore()->getValue('bf_ugp_genericpermissions');
     if (!$userinfo) {
         throw new vB_Exception_Api('invalid_user_specified');
     }
     if (!$delete) {
         $userpic = new vB_DataManager_Userpic(vB_DataManager_Constants::ERRTYPE_ARRAY_UNPROCESSED);
         cache_permissions($userinfo, false);
         // user's group doesn't have permission to use custom avatars so set override
         if (!($userinfo['permissions']['genericpermissions'] & $bf_ugp_genericpermissions['canprofilepic'])) {
             // init user datamanager
             $userdata = new vB_Datamanager_User(vB_DataManager_Constants::ERRTYPE_ARRAY_UNPROCESSED);
             $userdata->set_existing($userinfo);
             $userdata->set_bitfield('adminoptions', 'adminprofilepic', 1);
             $userdata->save();
             if ($userdata->has_errors(false)) {
                 throw $userdata->get_exception();
             }
             unset($userdata);
         }
         $userpic->set('userid', $userinfo['userid']);
         $userpic->set('dateline', vB::getRequest()->getTimeNow());
         $userpic->set('filename', $data['filename']);
         $userpic->set('width', $data['width']);
         $userpic->set('height', $data['height']);
         $userpic->setr('filedata', $data['filedata']);
         $userpic->set_info('avatarrevision', $userinfo['avatarrevision']);
         $userpic->set_info('profilepicrevision', $userinfo['profilepicrevision']);
         $userpic->set_info('sigpicrevision', $userinfo['sigpicrevision']);
         if (!($result = $userpic->save())) {
             throw $userpic->get_exception();
         }
     } else {
         // Delete userpic
         $userpic = new vB_DataManager_Userpic(vB_DataManager_Constants::ERRTYPE_ARRAY_UNPROCESSED);
         $userpic->condition = array('userid' => $userinfo['userid']);
         $userpic->delete();
         if ($userpic->has_errors(false)) {
             throw $userpic->get_exception();
         }
     }
     return true;
 }