public function saveUser($User, $BannedValue, $Ban = false)
{
$BannedValue = (bool) $BannedValue;
$Banned = $User['Banned'];
if (static::isBanned($Banned, self::BAN_AUTOMATIC) === $BannedValue) {
return;
}
$NewBanned = static::setBanned($Banned, $BannedValue, self::BAN_AUTOMATIC);
Gdn::userModel()->setField($User['UserID'], 'Banned', $NewBanned);
$BanningUserID = Gdn::session()->UserID;
// This is true when a session is started and the session user has a new ip address and it matches a banning rule ip address
if ($User['UserID'] == $BanningUserID) {
$BanningUserID = val('InsertUserID', $Ban, Gdn::userModel()->GetSystemUserID());
}
// Add the activity.
$ActivityModel = new ActivityModel();
$Activity = array('ActivityType' => 'Ban', 'ActivityUserID' => $User['UserID'], 'RegardingUserID' => $BanningUserID, 'NotifyUserID' => ActivityModel::NOTIFY_MODS);
$BannedString = $BannedValue ? 'banned' : 'unbanned';
if ($Ban) {
$Activity['HeadlineFormat'] = '{ActivityUserID,user} was ' . $BannedString . ' (based on {Data.BanType}: {Data.BanValue}).';
$Activity['Data'] = arrayTranslate($Ban, array('BanType', 'BanValue'));
$Activity['Story'] = $Ban['Notes'];
$Activity['RecordType'] = 'Ban';
if (isset($Ban['BanID'])) {
$Activity['BanID'] = $Ban['BanID'];
}
} else {
$Activity['HeadlineFormat'] = '{ActivityUserID,user} was ' . $BannedString . '.';
}
$ActivityModel->save($Activity);
}
/** * Updates visit level information such as date last active and the user's ip address. * * @param int $UserID * @param string|int|float $ClientHour */ public function updateVisit($UserID, $ClientHour = false) { $UserID = (int) $UserID; if (!$UserID) { throw new Exception('A valid User ID is required.'); } $User = Gdn::userModel()->getID($UserID, DATASET_TYPE_ARRAY); $Fields = []; if (Gdn_Format::toTimestamp($User['DateLastActive']) < strtotime('5 minutes ago')) { // We only update the last active date once every 5 minutes to cut down on DB activity. $Fields['DateLastActive'] = Gdn_Format::toDateTime(); } // Update session level information if necessary. if ($UserID == Gdn::session()->UserID) { $IP = Gdn::request()->ipAddress(); $Fields['LastIPAddress'] = ipEncode($IP); $this->saveIP($UserID, $IP); if (Gdn::session()->newVisit()) { $Fields['CountVisits'] = val('CountVisits', $User, 0) + 1; $this->fireEvent('Visit'); } } // Set the hour offset based on the client's clock. if (is_numeric($ClientHour) && $ClientHour >= 0 && $ClientHour < 24) { $HourOffset = $ClientHour - date('G', time()); $Fields['HourOffset'] = $HourOffset; } // See if the fields have changed. $Set = []; foreach ($Fields as $Name => $Value) { if (val($Name, $User) != $Value) { $Set[$Name] = $Value; } } if (!empty($Set)) { $this->EventArguments['Fields'] =& $Set; $this->fireEvent('UpdateVisit'); $this->setField($UserID, $Set); } if ($User['LastIPAddress'] != $Fields['LastIPAddress']) { $User = $this->getID($UserID, DATASET_TYPE_ARRAY); if (!BanModel::checkUser($User, null, true, $Bans)) { $BanModel = new BanModel(); $Ban = array_pop($Bans); $BanModel->saveUser($User, true, $Ban); $BanModel->setCounts($Ban); } } }