示例#1
0
 /**
  * Verifies the author of a post and fetches the username if necessary.
  *
  * @return boolean True if the author information is valid, false if invalid.
  */
 function verify_author()
 {
     global $mybb;
     $post =& $this->data;
     // Don't have a user ID at all - not good (note, a user id of 0 will still work).
     if (!isset($post['uid'])) {
         $this->set_error("invalid_user_id");
         return false;
     } else {
         if ($post['uid'] > 0 && empty($post['username'])) {
             $user = get_user($post['uid']);
             $post['username'] = $user['username'];
         } else {
             if ($post['uid'] == 0 && $post['username'] != $lang->guest) {
                 // Set up user handler
                 require_once MYBB_ROOT . "inc/datahandlers/user.php";
                 $userhandler = new UserDataHandler();
                 $data_array = array('username' => $post['username']);
                 $userhandler->set_data($data_array);
                 if (!$userhandler->verify_username()) {
                     // invalid username
                     $this->errors = array_merge($this->errors, $userhandler->get_errors());
                     return false;
                 }
                 if ($userhandler->verify_username_exists()) {
                     // username is in use
                     $this->errors = array_merge($this->errors, $userhandler->get_errors());
                     return false;
                 }
             }
         }
     }
     // After all of this, if we still don't have a username, force the username as "Guest" (Note, this is not translatable as it is always a fallback)
     if (!$post['username']) {
         $post['username'] = "******";
     }
     return true;
 }