/** * Gets users online stats. */ public function readStats() { $conditionBuilder = clone $this->getConditionBuilder(); $conditionBuilder->add('session.spiderID IS NULL'); $sql = "SELECT\t\tuser_option_value.userOption" . User::getUserOptionID('canViewOnlineStatus') . " AS canViewOnlineStatus, session.userID\n\t\t\tFROM\t\twcf" . WCF_N . "_session session\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value user_option_value\n\t\t\tON\t\t(user_option_value.userID = session.userID)\n\t\t\t" . $conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); while ($row = $statement->fetchArray()) { $this->stats['total']++; if ($row['userID']) { $this->stats['members']++; if ($row['canViewOnlineStatus'] && !self::isVisible($row['userID'], $row['canViewOnlineStatus'])) { $this->stats['invisible']++; } } else { $this->stats['guests']++; } } }
/** * @see \wcf\system\cache\builder\AbstractCacheBuilder::rebuild() */ protected function rebuild(array $parameters) { $userOptionID = User::getUserOptionID('birthday'); if ($userOptionID === null) { // birthday profile field missing; skip return array(); } $data = array(); $birthday = 'userOption' . $userOptionID; $sql = "SELECT\tuserID, " . $birthday . "\n\t\t\tFROM\twcf" . WCF_N . "_user_option_value\n\t\t\tWHERE\t" . $birthday . " LIKE ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array('%-' . ($parameters['month'] < 10 ? '0' : '') . $parameters['month'] . '-%')); while ($row = $statement->fetchArray()) { list($year, $month, $day) = explode('-', $row[$birthday]); if (!isset($data[$month . '-' . $day])) { $data[$month . '-' . $day] = array(); } $data[$month . '-' . $day][] = $row['userID']; } return $data; }
public function switchContext() { $userAction = new UserAction(array(WCF::getUser()), 'update', array('options' => array(User::getUserOptionID('recentActivitiesFilterByFollowing') => WCF::getUser()->recentActivitiesFilterByFollowing ? 0 : 1))); $userAction->executeAction(); }
/** * @see \wcf\system\option\ISearchableConditionUserOption::addCondition() */ public function addCondition(UserList $userList, Option $option, $value) { $ageFrom = intval($value['ageFrom']); $ageTo = intval($value['ageTo']); if ($ageFrom < 0 || $ageFrom > 120 || $ageTo < 0 || $ageTo > 120) { return false; } $dateFrom = DateUtil::getDateTimeByTimestamp(TIME_NOW)->sub(new \DateInterval('P' . ($ageTo + 1) . 'Y'))->add(new \DateInterval('P1D')); $dateTo = DateUtil::getDateTimeByTimestamp(TIME_NOW)->sub(new \DateInterval('P' . $ageFrom . 'Y')); $userList->getConditionBuilder()->add('user_option_value.userOption' . User::getUserOptionID('birthdayShowYear') . ' = ?', array(1)); if ($ageFrom && $ageTo) { $userList->getConditionBuilder()->add('user_option_value.userOption' . $option->optionID . ' BETWEEN DATE(?) AND DATE(?)', array($dateFrom->format('Y-m-d'), $dateTo->format('Y-m-d'))); } else { if ($ageFrom) { $userList->getConditionBuilder()->add('user_option_value.userOption' . $option->optionID . ' BETWEEN DATE(?) AND DATE(?)', array('1893-01-01', $dateTo->format('Y-m-d'))); } else { $userList->getConditionBuilder()->add('user_option_value.userOption' . $option->optionID . ' BETWEEN DATE(?) AND DATE(?)', array($dateFrom->format('Y-m-d'), DateUtil::getDateTimeByTimestamp(TIME_NOW)->add(new \DateInterval('P1D'))->format('Y-m-d'))); } } }
/** * @see \wcf\form\IForm::save() */ public function save() { AbstractForm::save(); // get options $saveOptions = $this->optionHandler->save(); $registerVia3rdParty = false; $avatarURL = ''; if ($this->isExternalAuthentication) { switch (WCF::getSession()->getVar('__3rdPartyProvider')) { case 'github': // GitHub if (WCF::getSession()->getVar('__githubData')) { $githubData = WCF::getSession()->getVar('__githubData'); $this->additionalFields['authData'] = 'github:' . WCF::getSession()->getVar('__githubToken'); WCF::getSession()->unregister('__githubData'); WCF::getSession()->unregister('__githubToken'); if (WCF::getSession()->getVar('__email') && WCF::getSession()->getVar('__email') == $this->email) { $registerVia3rdParty = true; } if (isset($githubData['bio']) && User::getUserOptionID('aboutMe') !== null) { $saveOptions[User::getUserOptionID('aboutMe')] = $githubData['bio']; } if (isset($githubData['location']) && User::getUserOptionID('location') !== null) { $saveOptions[User::getUserOptionID('location')] = $githubData['location']; } } break; case 'twitter': // Twitter if (WCF::getSession()->getVar('__twitterData')) { $twitterData = WCF::getSession()->getVar('__twitterData'); $this->additionalFields['authData'] = 'twitter:' . $twitterData['user_id']; WCF::getSession()->unregister('__twitterData'); if (isset($twitterData['description']) && User::getUserOptionID('aboutMe') !== null) { $saveOptions[User::getUserOptionID('aboutMe')] = $twitterData['description']; } if (isset($twitterData['location']) && User::getUserOptionID('location') !== null) { $saveOptions[User::getUserOptionID('location')] = $twitterData['location']; } } break; case 'facebook': // Facebook if (WCF::getSession()->getVar('__facebookData')) { $facebookData = WCF::getSession()->getVar('__facebookData'); $this->additionalFields['authData'] = 'facebook:' . $facebookData['id']; WCF::getSession()->unregister('__facebookData'); if (isset($facebookData['email']) && $facebookData['email'] == $this->email) { $registerVia3rdParty = true; } if (isset($facebookData['gender']) && User::getUserOptionID('gender') !== null) { $saveOptions[User::getUserOptionID('gender')] = $facebookData['gender'] == 'male' ? UserProfile::GENDER_MALE : UserProfile::GENDER_FEMALE; } if (isset($facebookData['birthday']) && User::getUserOptionID('birthday') !== null) { list($month, $day, $year) = explode('/', $facebookData['birthday']); $saveOptions[User::getUserOptionID('birthday')] = $year . '-' . $month . '-' . $day; } if (isset($facebookData['bio']) && User::getUserOptionID('bio') !== null) { $saveOptions[User::getUserOptionID('aboutMe')] = $facebookData['bio']; } if (isset($facebookData['location']) && User::getUserOptionID('location') !== null) { $saveOptions[User::getUserOptionID('location')] = $facebookData['location']['name']; } if (isset($facebookData['website']) && User::getUserOptionID('website') !== null) { $urls = preg_split('/[\\s,;]/', $facebookData['website'], -1, PREG_SPLIT_NO_EMPTY); if (!empty($urls)) { if (!Regex::compile('^https?://')->match($urls[0])) { $urls[0] = 'http://' . $urls[0]; } $saveOptions[User::getUserOptionID('homepage')] = $urls[0]; } } // avatar if (isset($facebookData['picture']) && !$facebookData['picture']['data']['is_silhouette']) { $avatarURL = $facebookData['picture']['data']['url']; } } break; case 'google': // Google Plus if (WCF::getSession()->getVar('__googleData')) { $googleData = WCF::getSession()->getVar('__googleData'); $this->additionalFields['authData'] = 'google:' . $googleData['id']; WCF::getSession()->unregister('__googleData'); if (isset($googleData['emails'][0]['value']) && $googleData['emails'][0]['value'] == $this->email) { $registerVia3rdParty = true; } if (isset($googleData['gender']) && User::getUserOptionID('gender') !== null) { switch ($googleData['gender']) { case 'male': $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_MALE; break; case 'female': $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_FEMALE; break; } } if (isset($googleData['birthday']) && User::getUserOptionID('birthday') !== null) { $saveOptions[User::getUserOptionID('birthday')] = $googleData['birthday']; } if (isset($googleData['placesLived']) && User::getUserOptionID('location') !== null) { // save primary location $saveOptions[User::getUserOptionID('location')] = current(array_map(function ($element) { return $element['value']; }, array_filter($googleData['placesLived'], function ($element) { return isset($element['primary']) && $element['primary']; }))); } // avatar if (isset($googleData['image']['url'])) { $avatarURL = $googleData['image']['url']; } } break; } // create fake password $this->password = StringUtil::getRandomID(); } $this->additionalFields['languageID'] = $this->languageID; if (LOG_IP_ADDRESS) { $this->additionalFields['registrationIpAddress'] = WCF::getSession()->ipAddress; } // generate activation code $addDefaultGroups = true; if (REGISTER_ACTIVATION_METHOD == 1 && !$registerVia3rdParty || REGISTER_ACTIVATION_METHOD == 2) { $activationCode = UserRegistrationUtil::getActivationCode(); $this->additionalFields['activationCode'] = $activationCode; $addDefaultGroups = false; $this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::GUESTS)); } // check gravatar support if (MODULE_GRAVATAR && Gravatar::test($this->email)) { $this->additionalFields['enableGravatar'] = 1; } // create user $data = array('data' => array_merge($this->additionalFields, array('username' => $this->username, 'email' => $this->email, 'password' => $this->password)), 'groups' => $this->groupIDs, 'languageIDs' => $this->visibleLanguages, 'options' => $saveOptions, 'addDefaultGroups' => $addDefaultGroups); $this->objectAction = new UserAction(array(), 'create', $data); $result = $this->objectAction->executeAction(); $user = $result['returnValues']; $userEditor = new UserEditor($user); // update session WCF::getSession()->changeUser($user); // set avatar if provided if (!empty($avatarURL)) { $userAvatarAction = new UserAvatarAction(array(), 'fetchRemoteAvatar', array('url' => $avatarURL, 'userEditor' => $userEditor)); $userAvatarAction->executeAction(); } // activation management if (REGISTER_ACTIVATION_METHOD == 0) { $this->message = 'wcf.user.register.success'; } else { if (REGISTER_ACTIVATION_METHOD == 1) { // registering via 3rdParty leads to instant activation if ($registerVia3rdParty) { $this->message = 'wcf.user.register.success'; } else { $mail = new Mail(array($this->username => $this->email), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail.subject'), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail', array('user' => $user))); $mail->send(); $this->message = 'wcf.user.register.needActivation'; } } else { if (REGISTER_ACTIVATION_METHOD == 2) { $this->message = 'wcf.user.register.awaitActivation'; } } } // notify admin if (REGISTER_ADMIN_NOTIFICATION) { // get default language $language = LanguageFactory::getInstance()->getLanguage(LanguageFactory::getInstance()->getDefaultLanguageID()); // send mail $mail = new Mail(MAIL_ADMIN_ADDRESS, $language->getDynamicVariable('wcf.user.register.notification.mail.subject'), $language->getDynamicVariable('wcf.user.register.notification.mail', array('user' => $user))); $mail->setLanguage($language); $mail->send(); } if ($this->captchaObjectType) { $this->captchaObjectType->getProcessor()->reset(); } if (WCF::getSession()->getVar('noRegistrationCaptcha')) { WCF::getSession()->unregister('noRegistrationCaptcha'); } // login user UserAuthenticationFactory::getInstance()->getUserAuthentication()->storeAccessData($user, $this->username, $this->password); WCF::getSession()->unregister('registrationRandomFieldNames'); WCF::getSession()->unregister('registrationStartTime'); $this->saved(); // forward to index page HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink(), WCF::getLanguage()->getDynamicVariable($this->message, array('user' => $user)), 15); exit; }
/** * @see \wcf\system\importer\IImporter::import() */ public function import($oldID, array $data, array $additionalData = array()) { // whether to perform a merge $performMerge = false; // fetch user with same username $conflictingUser = User::getUserByUsername($data['username']); switch (ImportHandler::getInstance()->getUserMergeMode()) { case self::MERGE_MODE_USERNAME_OR_EMAIL: // merge target will be the conflicting user $targetUser = $conflictingUser; // check whether user exists if ($targetUser->userID) { $performMerge = true; break; } case self::MERGE_MODE_EMAIL: // fetch merge target $targetUser = User::getUserByEmail($data['email']); // if it exists: perform a merge if ($targetUser->userID) { $performMerge = true; } break; } // merge should be performed if ($performMerge) { ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user', $oldID, $targetUser->userID); return 0; } // a conflict arose, but no merge was performed, resolve if ($conflictingUser->userID) { // rename user $data['username'] = self::resolveDuplicate($data['username']); } // check existing user id if (is_numeric($oldID)) { $user = new User($oldID); if (!$user->userID) { $data['userID'] = $oldID; } } // handle user options $userOptions = array(); if (isset($additionalData['options'])) { foreach ($additionalData['options'] as $optionName => $optionValue) { if (is_int($optionName)) { $optionID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.option', $optionName); } else { $optionID = User::getUserOptionID($optionName); } if ($optionID) { $userOptions[$optionID] = $optionValue; } } // fix option values foreach ($userOptions as $optionID => &$optionValue) { switch ($this->userOptions[$optionID]->optionType) { case 'boolean': if ($optionValue) { $optionValue = 1; } else { $optionValue = 0; } break; case 'integer': $optionValue = intval($optionValue); if ($optionValue > 2147483647) { $optionValue = 2147483647; } break; case 'float': $optionValue = floatval($optionValue); break; case 'textarea': if (strlen($optionValue) > 16777215) { $optionValue = substr($optionValue, 0, 16777215); } break; case 'birthday': case 'date': if (!preg_match('/^\\d{4}\\-\\d{2}\\-\\d{2}$/', $optionValue)) { $optionValue = '0000-00-00'; } break; default: if (strlen($optionValue) > 65535) { $optionValue = substr($optionValue, 0, 65535); } } } } $languageIDs = array(); if (isset($additionalData['languages'])) { foreach ($additionalData['languages'] as $languageCode) { $language = LanguageFactory::getInstance()->getLanguageByCode($languageCode); if ($language !== null) { $languageIDs[] = $language->languageID; } } } if (empty($languageIDs)) { $languageIDs[] = LanguageFactory::getInstance()->getDefaultLanguageID(); } // assign an interface language $data['languageID'] = reset($languageIDs); // create user $user = UserEditor::create($data); $userEditor = new UserEditor($user); // updates user options $userEditor->updateUserOptions($userOptions); // save user groups $groupIDs = array(); if (isset($additionalData['groupIDs'])) { foreach ($additionalData['groupIDs'] as $oldGroupID) { $newGroupID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.group', $oldGroupID); if ($newGroupID) { $groupIDs[] = $newGroupID; } } } if (!$user->activationCode) { $defaultGroupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::USERS)); } else { $defaultGroupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::GUESTS)); } $groupIDs = array_merge($groupIDs, $defaultGroupIDs); $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_user_to_group\n\t\t\t\t\t\t(userID, groupID)\n\t\t\tVALUES\t\t\t(?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($groupIDs as $groupID) { $statement->execute(array($user->userID, $groupID)); } // save languages $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_user_to_language\n\t\t\t\t\t\t(userID, languageID)\n\t\t\tVALUES\t\t\t(?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($languageIDs as $languageID) { $statement->execute(array($user->userID, $languageID)); } // save default user events $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_user_notification_event_to_user\n\t\t\t\t\t\t(userID, eventID)\n\t\t\tVALUES\t\t\t(?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($this->eventIDs as $eventID) { $statement->execute(array($user->userID, $eventID)); } // save mapping ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user', $oldID, $user->userID); return $user->userID; }
/** * @see \wcf\system\faker\IFaker::fake() */ public function fake() { $username = $tmpName = $this->generator->userName; $username = str_replace(',', '', $username); while (!\wcf\util\UserUtil::isAvailableUsername($tmpName)) { $tmpName = $username . $this->generator->randomNumber(4); } $username = $tmpName; $password = $username; $email = $username . '@' . $this->generator->safeEmailDomain; // shouldn't happen if (!\wcf\util\UserUtil::isValidEmail($email)) { $email = $this->generator->safeEmail; } while (!\wcf\util\UserUtil::isAvailableEmail($email)) { $email = $this->generator->safeEmail; } $registrationDate = $this->generator->dateTimeBetween('2000-01-01 GMT', 'now')->getTimestamp(); $lastActivityTime = $this->generator->optional($weight = 0.7)->numberBetween($registrationDate, TIME_NOW); $parameters = array('data' => array('languageID' => $this->language->languageID, 'username' => $username, 'email' => $email, 'password' => $password, 'registrationDate' => $registrationDate, 'lastActivityTime' => $lastActivityTime === null ? 0 : $lastActivityTime)); if (isset($this->parameters['groupIDs'])) { $parameters['groups'] = $this->parameters['groupIDs']; } // handle old name if (isset($this->parameters['userRandomOldUsername']) && $this->parameters['userRandomOldUsername']) { // 2 percent chance if ($this->generator->boolean(2)) { $parameters['data']['oldUsername'] = $this->generator->userName; } } // handle signature if (isset($this->parameters['userRandomSignature']) && $this->parameters['userRandomSignature']) { $parameters['data']['signature'] = $this->generator->realText($this->generator->numberBetween(10, 500)); } // handle options $options = array(); // handle gender if (isset($this->parameters['userGender'])) { switch ($this->parameters['userGender']) { case 0: case 1: case 2: $options[User::getUserOptionID('gender')] = $this->parameters['userGender']; break; default: $options[User::getUserOptionID('gender')] = $this->generator->numberBetween(0, 2); break; } } // handle aboutMe if (isset($this->parameters['userRandomAboutMe']) && $this->parameters['userRandomAboutMe']) { $options[User::getUserOptionID('aboutMe')] = $this->generator->realText($this->generator->numberBetween(50, 1500)); } // handle birthday if (isset($this->parameters['userRandomBirthday']) && $this->parameters['userRandomBirthday']) { $options[User::getUserOptionID('birthday')] = $this->generator->dateTimeBetween("-90 years", "-14 years")->format('Y-m-d'); } // handle location if (isset($this->parameters['userRandomLocation']) && $this->parameters['userRandomLocation']) { $options[User::getUserOptionID('location')] = $this->generator->address; } // handle homepage if (isset($this->parameters['userRandomHomepage']) && $this->parameters['userRandomHomepage']) { $options[User::getUserOptionID('homepage')] = $this->generator->url; } if (!empty($options)) { $parameters['options'] = $options; } $objectAction = new \wcf\data\user\UserAction(array(), 'create', $parameters); $objectAction->executeAction(); }