/** * Populate the user object * @since Version 3.0.1 * @version 3.0.1 * @return boolean * * @param int $userId */ public function load($userId = false) { if (filter_var($userId, FILTER_VALIDATE_INT)) { $this->id = $userId; } // Get out early if (!filter_var($this->id, FILTER_VALIDATE_INT)) { return false; } $timer = Debug::getTimer(); $this->createUrls(); Debug::logEvent(__METHOD__ . " - createUrls() completed", $timer); $this->mckey = sprintf("railpage:user_id=%d", $this->id); $cached = false; $timer = Debug::getTimer(); /** * Load the User data from Redis first */ if ($data = $this->Redis->fetch($this->mckey)) { $cached = true; Debug::logEvent(__METHOD__ . "(" . $this->id . ") loaded via Redis", $timer); } /** * I f****d up before, so validate the redis data before we continue... */ if (!is_array($data) || empty($data) || count($data) === 1) { $timer = Debug::getTimer(); $data = Utility\UserUtility::fetchFromDatabase($this); Debug::logEvent(__METHOD__ . "(" . $this->id . ") loaded via ZendDB", $timer); } /** * Process some of the returned values */ $data = Utility\UserUtility::normaliseAvatarPath($data); $data = Utility\UserUtility::setDefaults($data, $this); /** * Start setting the class vars */ $this->getGroups(); $this->provider = $data['provider']; $this->preferences = json_decode($data['user_opts']); $this->guest = false; $this->theme = $data['theme']; $this->rank_id = $data['user_rank']; $this->rank_text = $data['rank_title']; $this->timezone = $data['timezone']; $this->website = $data['user_website']; $this->hide = $data['user_allow_viewonline']; $this->meta = json_decode($data['meta'], true); if (json_last_error() != JSON_ERROR_NONE || !is_array($this->meta)) { $this->meta = array(); } if (isset($data['password_new'])) { $this->password_new = $data['password_new']; } $this->session_last_nice = date($this->date_format, $this->lastvisit); $this->contact_email_public = (bool) $this->contact_email_public ? $this->contact_email : $data['femail']; $this->reputation = '100% (+' . $this->wheat . '/' . $this->chaff . '-)'; if (intval($this->wheat) > 0) { $this->reputation = number_format($this->chaff / $this->wheat / 2 * 100, 1) . '% (+' . $this->wheat . '/' . $this->chaff . '-)'; } /** * Map database fields to class vars */ $fields = Utility\UserUtility::getColumnMapping(); foreach ($fields as $key => $var) { $this->{$var} = $data[$key]; } /** * Update the user registration date if required */ Utility\UserMaintenance::checkUserRegdate($data); $this->RegistrationDate = new DateTime($data['user_regdate_nice']); /** * Fetch the last IP address from the login logs */ $this->getLogins(1); $this->warning_level_colour = Utility\UserUtility::getWarningBarColour($this->warning_level); if (isset($data['oauth_key']) && isset($data['oauth_secret'])) { $this->oauth_key = $data['oauth_key']; $this->oauth_secret = $data['oauth_secret']; } $this->oauth_id = $data['oauth_consumer_id']; // Bugfix for REALLY old accounts with a NULL user_level if (!filter_var($this->level, FILTER_VALIDATE_INT) && $this->active == 1) { $this->level = 1; } $this->verifyAPI(); /** * Set some default values for $this->preferences */ $this->preferences = json_decode(json_encode($this->getPreferences())); if (!$cached) { $this->Redis->save($this->mckey, $data, strtotime("+6 hours")); } return true; }