public function __construct() { parent::__construct(); $oUser = new UserCore(); $oUserModel = new UserCoreModel(); $oExistsModel = new ExistsCoreModel(); $oValidate = new Validate(); $aUserData = json_decode($this->file->getFile('http://api.randomuser.me/?results=' . $this->httpRequest->post('num')), true); foreach ($aUserData['results'] as $aUser) { $aUser = $aUser['user']; $sEmail = trim($aUser['email']); $sUsername = trim($aUser['username']); if ($oValidate->email($sEmail) && !$oExistsModel->email($sEmail) && $oValidate->username($sUsername)) { $aData['username'] = $sUsername; $aData['email'] = $sEmail; $aData['first_name'] = $aUser['name']['first']; $aData['last_name'] = $aUser['name']['last']; $aData['password'] = $aUser['password']; $aData['sex'] = $aUser['gender']; $aData['match_sex'] = array($oUser->getMatchSex($aData['sex'])); $aData['country'] = 'US'; $aData['city'] = $aUser['location']['city']; $aData['state'] = $aUser['location']['state']; $aData['zip_code'] = $aUser['location']['zip']; $aData['birth_date'] = $this->dateTime->get($aUser['dob'])->date('Y-m-d'); $aData['avatar'] = $aUser['picture']['large']; $aData['ip'] = Ip::get(); $aData['profile_id'] = $oUserModel->add(escape($aData, true)); $this->_addAvatar($aData, $oUser); } } unset($oUser, $oUserModel, $oExistsModel, $oValidate, $aUser, $aData, $aUserData); \PFBC\Form::setSuccess('form_add_fake_profiles', t('Users has been successfully added.')); }
/** * @param array $aProfile * @param object \PH7\UserCoreModel $oUserModel * @return void */ public function add(array $aProfile, UserCoreModel $oUserModel) { $sBirthDate = !empty($aProfile['birthday']) ? $aProfile['birthday'] : date('m/d/Y', strtotime('-30 year')); $sSex = $aProfile['gender'] != 'male' && $aProfile['gender'] != 'female' && $aProfile['gender'] != 'couple' ? 'female' : $aProfile['gender']; // Default 'female' $sMatchSex = $sSex == 'male' ? 'female' : ($sSex == 'female' ? 'male' : 'couple'); $this->_sUsername = (new UserCore())->findUsername($aProfile['given_name'], $aProfile['name'], $aProfile['family_name']); $this->_aUserInfo = ['email' => $aProfile['email'], 'username' => $this->_sUsername, 'password' => Various::genRndWord(8, 30), 'first_name' => !empty($aProfile['given_name']) ? $aProfile['given_name'] : '', 'last_name' => !empty($aProfile['family_name']) ? $aProfile['family_name'] : '', 'sex' => $sSex, 'match_sex' => array($sMatchSex), 'birth_date' => (new CDateTime())->get($sBirthDate)->date('Y-m-d'), 'country' => Geo::getCountryCode(), 'city' => Geo::getCity(), 'state' => Geo::getState(), 'zip_code' => Geo::getZipCode(), 'description' => !empty($aProfile['bio']) ? $aProfile['bio'] : '', 'website' => '', 'social_network_site' => $aProfile['link'], 'ip' => Ip::get(), 'prefix_salt' => Various::genRnd(), 'suffix_salt' => Various::genRnd(), 'hash_validation' => Various::genRnd(), 'is_active' => DbConfig::getSetting('userActivationType')]; $this->_iProfileId = $oUserModel->add($this->_aUserInfo); }
/** * @param object $oProfile * @param object \PH7\UserCoreModel $oUserModel * @return void */ public function add($oProfile, UserCoreModel $oUserModel) { $sBirthDate = isset($oProfile->birth_month, $oProfile->birth_day, $oProfile->birth_year) ? $oProfile->birth_month . '/' . $oProfile->birth_day . '/' . $oProfile->birth_year : date('m/d/Y', strtotime('-30 year')); $sSex = $oProfile->gender != 'male' && $oProfile->gender != 'female' && $oProfile->gender != 'couple' ? 'female' : $oProfile->gender; // Default 'female' $sMatchSex = $sSex == 'male' ? 'female' : ($sSex == 'female' ? 'male' : 'couple'); $this->_sUsername = (new UserCore())->findUsername($oProfile->name, $oProfile->first_name, $oProfile->last_name); $this->_aUserInfo = ['email' => $oProfile->emails->account, 'username' => $this->_sUsername, 'password' => Various::genRndWord(8, 30), 'first_name' => !empty($oProfile->first_name) ? $oProfile->first_name : '', 'last_name' => !empty($oProfile->last_name) ? $oProfile->last_name : '', 'sex' => $sSex, 'match_sex' => array($sMatchSex), 'birth_date' => (new CDateTime())->get($sBirthDate)->date('Y-m-d'), 'country' => Geo::getCountryCode(), 'city' => Geo::getCity(), 'state' => Geo::getState(), 'zip_code' => Geo::getZipCode(), 'description' => '', 'website' => '', 'social_network_site' => '', 'ip' => Ip::get(), 'prefix_salt' => Various::genRnd(), 'suffix_salt' => Various::genRnd(), 'hash_validation' => Various::genRnd(), 'is_active' => DbConfig::getSetting('userActivationType')]; $this->_iProfileId = $oUserModel->add($this->_aUserInfo); }
/** * @param array $aProfile * @param object \PH7\UserCoreModel $oUserModel * @return void */ public function add(array $aProfile, UserCoreModel $oUserModel) { $oUser = new UserCore(); $sBirthDate = !empty($aProfile['birthday']) ? $aProfile['birthday'] : date('m/d/Y', strtotime('-30 year')); $sLocation = !empty($aProfile['location']['name']) ? $aProfile['location']['name'] : (!empty($aProfile['hometown']['name']) ? $aProfile['hometown']['name'] : ''); $aLocation = @explode(',', $sLocation); $sSex = $aProfile['gender'] != 'male' && $aProfile['gender'] != 'female' && $aProfile['gender'] != 'couple' ? 'female' : $aProfile['gender']; // Default 'female' $sMatchSex = $oUser->getMatchSex($sSex); $this->_sUsername = $oUser->findUsername($aProfile['username'], $aProfile['first_name'], $aProfile['last_name']); $sSite = !empty($aProfile['link']) ? explode(' ', $aProfile['link'])[0] : ''; $sSocialNetworkSite = !empty($aProfile['username']) ? 'http://facebook.com/' . $aProfile['username'] : ''; unset($oUser); $this->_aUserInfo = ['email' => $aProfile['email'], 'username' => $this->_sUsername, 'password' => Various::genRndWord(8, 30), 'first_name' => !empty($aProfile['first_name']) ? $aProfile['first_name'] : '', 'last_name' => !empty($aProfile['last_name']) ? $aProfile['last_name'] : '', 'middle_name' => !empty($aProfile['middle_name']) ? $aProfile['middle_name'] : '', 'sex' => $sSex, 'match_sex' => array($sMatchSex), 'birth_date' => (new CDateTime())->get($sBirthDate)->date('Y-m-d'), 'country' => !empty($aLocation[1]) ? trim($aLocation[1]) : Geo::getCountryCode(), 'city' => !empty($aLocation[0]) ? trim($aLocation[0]) : Geo::getCity(), 'state' => !empty($aProfile['locale']) ? $aProfile['locale'] : Geo::getState(), 'zip_code' => !empty($aProfile['hometown_location']['zip']) ? $aProfile['hometown_location']['zip'] : Geo::getZipCode(), 'description' => !empty($aProfile['bio']) ? $aProfile['bio'] : '', 'website' => $sSite, 'social_network_site' => $sSocialNetworkSite, 'ip' => Ip::get(), 'prefix_salt' => Various::genRnd(), 'suffix_salt' => Various::genRnd(), 'hash_validation' => Various::genRnd(), 'is_active' => DbConfig::getSetting('userActivationType')]; $this->_iProfileId = $oUserModel->add($this->_aUserInfo); }
public function __construct() { parent::__construct(); $this->_aFile = $_FILES['csv_file']; $sExtFile = $this->file->getFileExt($this->_aFile['name']); $sDelimiter = $this->httpRequest->post('delimiter'); $sEnDelimiter = $this->httpRequest->post('enclosure'); if ($sExtFile != 'csv' && $sExtFile != 'txt') { $sErrMsg = static::ERR_BAD_FILE; } elseif (!($rHandler = @fopen($this->_aFile['tmp_name'], 'rb'))) { $sErrMsg = static::ERR_BAD_FILE; } elseif (!($aFileData = @fgetcsv($rHandler, 0, $sDelimiter, $sEnDelimiter)) || !is_array($aFileData)) { $sErrMsg = static::ERR_BAD_FILE; } if (!empty($sErrMsg) && $sErrMsg == static::ERR_BAD_FILE) { $this->_removeTmpFile(); \PFBC\Form::setError('form_import_user', t('Wrong file! Please select a valid CSV file containing data members.')); return; // Stop execution of the method. } /** * Default value... */ $aGenderList = ['male', 'female', 'couple']; $sFiveChars = Various::genRnd($this->_aFile['name'], 5); $aTmpData = ['email' => 'pierrehenrysoriasanz' . $sFiveChars . '@hizup' . $sFiveChars . '.com', 'username' => 'Hizup' . $sFiveChars, 'password' => Various::genRnd(), 'first_name' => 'Alex' . $sFiveChars, 'last_name' => 'Rolli' . $sFiveChars, 'sex' => $aGenderList[mt_rand(0, 2)], 'match_sex' => $aGenderList[mt_rand(0, 2)], 'birth_date' => date('Y') - mt_rand(20, 40) . '-' . mt_rand(1, 12) . '-' . mt_rand(1, 28), 'country' => 'US', 'city' => 'Virginia', 'state' => 'Doswell', 'zip_code' => '23047', 'description' => 'Hi all!<br />How are you today?<br /> Bye ;)', 'website' => '', 'social_network_site' => '', 'ip' => Ip::get()]; foreach ($aFileData as $sKey => $sVal) { // Clean the text to make comparisons easier... $sVal = strtolower(trim(str_replace(array('-', '_', ' '), '', $sVal))); // Test comparisons of strings and adding values in an array "$aTmpData" if ($sVal == 'username' || $sVal == 'login' || $sVal == 'user' || $sVal == 'nickname') { $aTmpData['username'] = $sKey; } if ($sVal == 'name' || $sVal == 'firstname') { $aTmpData['first_name'] = $sKey; } if ($sVal == 'lastname' || $sVal == 'surname') { $aTmpData['last_name'] = $sKey; } if ($sVal == 'matchsex' || $sVal == 'looking' || $sVal == 'lookingfor') { $aTmpData['match_sex'] = $sKey; } if ($sVal == 'sex' || $sVal == 'gender') { $aTmpData['sex'] = $sKey; } if ($sVal == 'email' || $sVal == 'mail') { $aTmpData['email'] = $sKey; } if ($sVal == 'desc' || $sVal == 'description' || $sVal == 'descriptionme' || $sVal == 'generaldescription' || $sVal == 'about' || $sVal == 'aboutme' || $sVal == 'bio' || $sVal == 'biography' || $sVal == 'comment') { $aTmpData['description'] = $sKey; } if ($sVal == 'country' || $sVal == 'countryid') { $aTmpData['country'] = $sKey; } if ($sVal == 'city' || $sVal == 'town') { $aTmpData['city'] = $sKey; } if ($sVal == 'state' || $sVal == 'district' || $sVal == 'province' || $sVal == 'region') { $aTmpData['state'] = $sKey; } if ($sVal == 'zip' || $sVal == 'zipcode' || $sVal == 'postal' || $sVal == 'postalcode') { $aTmpData['zip_code'] = $sKey; } if ($sVal == 'website' || $sVal == 'site' || $sVal == 'url') { $aTmpData['website'] = $sKey; } if ($sVal == 'birthday' || $sVal == 'birthdate' || $sVal == 'dateofbirth') { $aTmpData['birth_date'] = $this->dateTime->get($sKey)->date('Y-m-d'); } } $iRow = 0; $oUser = new UserCore(); $oUserModel = new UserCoreModel(); $oExistsModel = new ExistsCoreModel(); $oValidate = new Validate(); while (($aFileData = fgetcsv($rHandler, 0, $sDelimiter, $sEnDelimiter)) !== false) { $aData[$iRow] = $aTmpData; // Set data by the default contents $sEmail = trim($aFileData[$aTmpData['email']]); if ($oValidate->email($sEmail) && !$oExistsModel->email($sEmail)) { $sUsername = trim($aFileData[$aTmpData['username']]); $sFirstName = trim($aFileData[$aTmpData['first_name']]); $sLastName = trim($aFileData[$aTmpData['last_name']]); $aData[$iRow]['username'] = $oUser->findUsername($sUsername, $sFirstName, $sLastName); $aData[$iRow]['first_name'] = $sFirstName; $aData[$iRow]['last_name'] = $sLastName; $aData[$iRow]['sex'] = trim($aFileData[$aTmpData['sex']]); $aData[$iRow]['match_sex'] = array(trim($aFileData[$aTmpData['match_sex']])); $aData[$iRow]['email'] = $sEmail; $aData[$iRow]['description'] = trim($aFileData[$aTmpData['description']]); $aData[$iRow]['country'] = trim($aFileData[$aTmpData['country']]); $aData[$iRow]['city'] = trim($aFileData[$aTmpData['city']]); $aData[$iRow]['state'] = trim($aFileData[$aTmpData['state']]); $aData[$iRow]['zip_code'] = trim($aFileData[$aTmpData['zip_code']]); $aData[$iRow]['website'] = trim($aFileData[$aTmpData['website']]); $aData[$iRow]['birth_date'] = trim($aFileData[$aTmpData['birth_date']]); $oUserModel->add(escape($aData[$iRow], true)); $iRow++; } } $this->_removeTmpFile(); unset($oUser, $oUserModel, $oExistsModel, $oValidate, $aTmpData, $aData); fclose($rHandler); Header::redirect(Uri::get(PH7_ADMIN_MOD, 'user', 'browse'), nt('%n% User has been successfully added.', '%n% Users has been successfully added.', $iRow)); }
/** * @param array $aFiles * @param string $sDelimiter Delimiter Field delimiter (one character). * @param string $sEnclosure Enclosure Field enclosure (one character). * @return void */ public function __construct(array $aFiles, $sDelimiter, $sEnclosure) { parent::__construct(); $this->_aFile = $aFiles; $sExtFile = $this->file->getFileExt($this->_aFile['name']); if ($sExtFile != 'csv' && $sExtFile != 'txt') { $this->_iErrType = static::ERR_BAD_FILE; } elseif ($this->_aFile['error'] == UPLOAD_ERR_INI_SIZE) { $this->_iErrType = static::ERR_TOO_LARGE; } elseif (!($rHandler = @fopen($this->_aFile['tmp_name'], 'rb'))) { $this->_iErrType = static::ERR_INVALID; } elseif (!($this->_aFileData = @fgetcsv($rHandler, 0, $sDelimiter, $sEnclosure)) || !is_array($this->_aFileData)) { $this->_iErrType = static::ERR_INVALID; } if (!empty($this->_iErrType)) { $this->_removeTmpFile(); $this->_aRes = ['status' => false, 'msg' => $this->getErrMsg()]; } else { $this->setDefVals(); foreach ($this->_aFileData as $sKey => $sVal) { // Clean the text to make comparisons easier... $sVal = strtolower(trim(str_replace(['-', '_', ' '], '', $sVal))); // Test comparisons of strings and adding values in an array "ImportUser::$_aTmpData" if ($sVal == 'username' || $sVal == 'login' || $sVal == 'user' || $sVal == 'nickname') { $this->_aTmpData['username'] = $sKey; } if ($sVal == 'name' || $sVal == 'firstname' || $sVal == 'forname') { $this->_aTmpData['first_name'] = $sKey; } if ($sVal == 'lastname' || $sVal == 'surname') { $this->_aTmpData['last_name'] = $sKey; } if ($sVal == 'matchsex' || $sVal == 'looking' || $sVal == 'lookingfor') { $this->_aTmpData['match_sex'] = $sKey; } if ($sVal == 'sex' || $sVal == 'gender') { $this->_aTmpData['sex'] = $sKey; } if ($sVal == 'email' || $sVal == 'mail') { $this->_aTmpData['email'] = $sKey; } if ($sVal == 'desc' || $sVal == 'description' || $sVal == 'descriptionme' || $sVal == 'generaldescription' || $sVal == 'about' || $sVal == 'aboutme' || $sVal == 'bio' || $sVal == 'biography' || $sVal == 'comment') { $this->_aTmpData['description'] = $sKey; } if ($sVal == 'country' || $sVal == 'countryid') { $this->_aTmpData['country'] = $sKey; } if ($sVal == 'city' || $sVal == 'town') { $this->_aTmpData['city'] = $sKey; } if ($sVal == 'state' || $sVal == 'district' || $sVal == 'province' || $sVal == 'region') { $this->_aTmpData['state'] = $sKey; } if ($sVal == 'zip' || $sVal == 'zipcode' || $sVal == 'postal' || $sVal == 'postalcode' || $sVal == 'eircode') { $this->_aTmpData['zip_code'] = $sKey; } if ($sVal == 'website' || $sVal == 'site' || $sVal == 'url') { $this->_aTmpData['website'] = $sKey; } if ($sVal == 'birthday' || $sVal == 'birthdate' || $sVal == 'dateofbirth') { $this->_aTmpData['birth_date'] = $sKey; } } $iRow = 0; $oUserModel = new UserCoreModel(); $oExistsModel = new ExistsCoreModel(); $oValidate = new Validate(); while (($this->_aFileData = fgetcsv($rHandler, 0, $sDelimiter, $sEnclosure)) !== false) { $sEmail = trim($this->_aFileData[$this->_aTmpData['email']]); if ($oValidate->email($sEmail) && !$oExistsModel->email($sEmail)) { $this->setData($iRow); $oUserModel->add(escape($this->_aData[$iRow], true)); $iRow++; } } $this->_removeTmpFile(); fclose($rHandler); unset($rHandler, $oUserModel, $oExistsModel, $oValidate, $this->_aTmpData, $this->_aFileData, $this->_aData); $this->_aRes = ['status' => true, 'msg' => nt('%n% user has been successfully added.', '%n% users has been successfully added.', $iRow)]; } }