Example #1
0
 public function __construct()
 {
     parent::__construct();
     // Thumbnail
     $oImg = new Image($_FILES['thumb']['tmp_name']);
     if (!$oImg->validate()) {
         \PFBC\Form::setError('form_game', Form::wrongImgFileTypeMsg());
         return;
         // Stop execution of the method.
     }
     $sThumbFile = Various::genRnd($oImg->getFileName(), 30) . $oImg->getExt();
     $sThumbDir = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'game/img/thumb/';
     $oImg->square(60);
     $oImg->save($sThumbDir . $sThumbFile);
     unset($oImg);
     // Game
     $sGameFile = Various::genRnd($_FILES['file']['name'], 30) . PH7_DOT . $this->file->getFileExt($_FILES['file']['name']);
     $sGameDir = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'game/file/';
     // If the folders is not created (games not installed), yet we will create.
     $this->file->createDir(array($sThumbDir, $sGameDir));
     if (!@move_uploaded_file($_FILES['file']['tmp_name'], $sGameDir . $sGameFile)) {
         \PFBC\Form::setError('form_game', t('Impossible to upload the game. If you are the administrator, please check if the folder of games data has the write permission (CHMOD 755).'));
     } else {
         $aData = ['category_id' => $this->httpRequest->post('category_id', 'int'), 'name' => $this->httpRequest->post('name'), 'title' => $this->httpRequest->post('title'), 'description' => $this->httpRequest->post('description'), 'keywords' => $this->httpRequest->post('keywords'), 'thumb' => $sThumbFile, 'file' => $sGameFile];
         (new GameModel())->add($aData);
         /* Clean GameModel Cache */
         (new Framework\Cache\Cache())->start(GameModel::CACHE_GROUP, null, null)->clear();
         HeaderUrl::redirect(Uri::get('game', 'main', 'game', $aData['title'] . ',' . Db::getInstance()->lastInsertId()), t('The game was added successfully!'));
     }
 }
 public function __construct()
 {
     parent::__construct();
     // PH7\UserCoreModel::login() method of the UserCoreModel Class works only for "user" and "affiliate" module.
     $oPasswordModel = $this->registry->module == PH7_ADMIN_MOD ? new AdminModel() : new UserCoreModel();
     $sEmail = $this->registry->module == PH7_ADMIN_MOD ? $this->session->get('admin_email') : ($this->registry->module == 'user' ? $this->session->get('member_email') : $this->session->get('affiliate_email'));
     $sTable = $this->registry->module == PH7_ADMIN_MOD ? 'Admins' : ($this->registry->module == 'user' ? 'Members' : 'Affiliates');
     $sMod = $this->registry->module == PH7_ADMIN_MOD ? PH7_ADMIN_MOD : ($this->registry->module == 'user' ? 'user' : 'affiliate');
     $sAction = $this->registry->module == 'affiliate' ? 'home' : 'main';
     // Login
     if ($this->registry->module == PH7_ADMIN_MOD) {
         $mLogin = $oPasswordModel->adminLogin($sEmail, $this->session->get('admin_username'), $this->httpRequest->post('old_password'));
     } else {
         $mLogin = $oPasswordModel->login($sEmail, $this->httpRequest->post('old_password'), $sTable);
     }
     // Check
     if ($this->httpRequest->post('new_password') !== $this->httpRequest->post('new_password2')) {
         \PFBC\Form::setError('form_change_password', t('The passwords do not match.'));
     } elseif ($this->httpRequest->post('old_password') === $this->httpRequest->post('new_password')) {
         \PFBC\Form::setError('form_change_password', t('The old and new passwords are identical. So why do you change your password?'));
     } elseif ($mLogin !== true) {
         \PFBC\Form::setError('form_change_password', t('The old password is not correct.'));
     } else {
         // Update
         $oPasswordModel->changePassword($sEmail, $this->httpRequest->post('new_password'), Various::genRnd(), Various::genRnd(), $sTable);
         \PFBC\Form::setSuccess('form_change_password', t('Your password has been correctly updated.'));
     }
 }
Example #3
0
 public function __construct()
 {
     parent::__construct();
     /**
      * This can cause minor errors (eg if a user sent a file that is not a video).
      * So we hide the errors if we are not in development mode.
      */
     if (!isDebug()) {
         error_reporting(0);
     }
     // Resizing and saving the video album thumbnail
     $oPicture = new Image($_FILES['album']['tmp_name']);
     if (!$oPicture->validate()) {
         \PFBC\Form::setError('form_video_album', Form::wrongImgFileTypeMsg());
     } else {
         $iApproved = DbConfig::getSetting('videoManualApproval') == 0 ? '1' : '0';
         $sFileName = Various::genRnd($oPicture->getFileName(), 1) . '-thumb.' . $oPicture->getExt();
         (new VideoModel())->addAlbum($this->session->get('member_id'), $this->httpRequest->post('name'), $this->httpRequest->post('description'), $sFileName, $this->dateTime->get()->dateTime('Y-m-d H:i:s'), $iApproved);
         $iLastAlbumId = (int) Db::getInstance()->lastInsertId();
         $oPicture->square(200);
         /* Set watermark text on thumbnail */
         $sWatermarkText = DbConfig::getSetting('watermarkTextImage');
         $iSizeWatermarkText = DbConfig::getSetting('sizeWatermarkTextImage');
         $oPicture->watermarkText($sWatermarkText, $iSizeWatermarkText);
         $sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'video/file/' . $this->session->get('member_username') . PH7_DS . $iLastAlbumId . PH7_DS;
         $this->file->createDir($sPath);
         $oPicture->save($sPath . $sFileName);
         /* Clean VideoModel Cache */
         (new Framework\Cache\Cache())->start(VideoModel::CACHE_GROUP, null, null)->clear();
         HeaderUrl::redirect(Uri::get('video', 'main', 'addvideo', $iLastAlbumId));
     }
 }
 /**
  * Show the captcha image.
  *
  * @param integer $iRandom
  * @return void
  */
 public function show($iRandom = null)
 {
     if (!empty($iRandom)) {
         $this->_sStr = Various::genRnd($iRandom, 5);
     } else {
         $this->_sStr = Various::genRnd('pH7_Pierre-Henry_Soria_Sanz_González_captcha', 5);
     }
     $this->_oSession->set('rand_code', $this->_sStr);
     $this->_sFont = $this->_getFont();
     //$sBackground = PH7_PATH_DATA . 'background/' . mt_rand(1, 5) . '.png';
     $this->_aBox = imagettfbbox($this->_iSize, 0, $this->_sFont, $this->_sStr);
     $this->_iWidth = $this->_aBox[2] - $this->_aBox[0];
     $this->_iHeight = $this->_aBox[1] - $this->_aBox[7];
     unset($this->_aBox);
     $this->_iStringWidth = round($this->_iWidth / strlen($this->_sStr));
     //$this->_rImg = imagecreatefrompng($sBackground);
     $this->_rImg = imagecreate($this->_iWidth + $this->_iMargin, $this->_iHeight + $this->_iMargin);
     $this->_aColor = array(imagecolorallocate($this->_rImg, 0x99, 0x0, 0x66), imagecolorallocate($this->_rImg, 0xcc, 0x0, 0x0), imagecolorallocate($this->_rImg, 0x0, 0x0, 0xcc), imagecolorallocate($this->_rImg, 0x0, 0x0, 0xcc), imagecolorallocate($this->_rImg, 0xbb, 0x88, 0x77));
     $this->_rBlack = imagecolorallocate($this->_rImg, 0, 0, 0);
     $this->_rRed = imagecolorallocate($this->_rImg, 200, 100, 90);
     $this->_rWhite = imagecolorallocate($this->_rImg, 255, 255, 255);
     imagefilledrectangle($this->_rImg, 0, 0, 399, 99, $this->_rWhite);
     $this->_mixing();
     imageline($this->_rImg, mt_rand(2, $this->_iWidth + $this->_iMargin), mt_rand(1, $this->_iWidth + $this->_iMargin), mt_rand(1, $this->_iHeight + $this->_iMargin), mt_rand(2, $this->_iWidth + $this->_iMargin), $this->_rBlack);
     imageline($this->_rImg, mt_rand(2, $this->_iHeight + $this->_iMargin), mt_rand(1, $this->_iHeight + $this->_iMargin), mt_rand(1, $this->_iWidth + $this->_iMargin), mt_rand(2, $this->_iHeight + $this->_iMargin), $this->_rRed);
     imageline($this->_rImg, mt_rand(2, $this->_iHeight + $this->_iMargin), mt_rand(1, $this->_iWidth + $this->_iMargin), mt_rand(1, $this->_iWidth + $this->_iMargin), mt_rand(2, $this->_iHeight + $this->_iMargin), $this->_aColor[array_rand($this->_aColor)]);
     unset($this->_rBlack, $this->_rRed, $this->_rWhite);
     imageconvolution($this->_rImg, $this->_aMatrixBlur, 9, 0);
     imageconvolution($this->_rImg, $this->_aMatrixBlur, 9, 0);
     unset($this->_aMatrixBlur);
     (new Browser())->noCache();
     header('Content-type: image/png');
     imagepng($this->_rImg);
     imagedestroy($this->_rImg);
 }
 public function __construct()
 {
     parent::__construct();
     $oAffModel = new AffiliateModel();
     $oSecurityModel = new SecurityModel();
     $sEmail = $this->httpRequest->post('mail');
     $sPassword = $this->httpRequest->post('password');
     /** Check if the connection is not locked **/
     $bIsLoginAttempt = (bool) DbConfig::getSetting('isAffiliateLoginAttempt');
     $iMaxAttempts = (int) DbConfig::getSetting('maxAffiliateLoginAttempts');
     $iTimeDelay = (int) DbConfig::getSetting('loginAffiliateAttemptTime');
     if ($bIsLoginAttempt && !$oSecurityModel->checkLoginAttempt($iMaxAttempts, $iTimeDelay, $sEmail, $this->view, 'Affiliates')) {
         \PFBC\Form::setError('form_login_aff', Form::loginAttemptsExceededMsg($iTimeDelay));
         return;
         // Stop execution of the method.
     }
     // Check Login
     $sLogin = $oAffModel->login($sEmail, $sPassword, 'Affiliates');
     if ($sLogin === 'email_does_not_exist' || $sLogin === 'password_does_not_exist') {
         sleep(1);
         // Security against brute-force attack to avoid drowning the server and the database
         if ($sLogin === 'email_does_not_exist') {
             $this->session->set('captcha_enabled', 1);
             // Enable Captcha
             \PFBC\Form::setError('form_login_aff', t('Oops! "%0%" is not associated with any %site_name% account.', escape(substr($sEmail, 0, PH7_MAX_EMAIL_LENGTH))));
             $oSecurityModel->addLoginLog($sEmail, 'Guest', 'No Password', 'Failed! Incorrect Username', 'Affiliates');
         } elseif ($sLogin === 'password_does_not_exist') {
             $oSecurityModel->addLoginLog($sEmail, 'Guest', $sPassword, 'Failed! Incorrect Password', 'Affiliates');
             if ($bIsLoginAttempt) {
                 $oSecurityModel->addLoginAttempt('Affiliates');
             }
             $this->session->set('captcha_enabled', 1);
             // Enable Captcha
             $sWrongPwdTxt = t('Oops! This password you entered is incorrect.') . '<br />';
             $sWrongPwdTxt .= t('Please try again (make sure your caps lock is off).') . '<br />';
             $sWrongPwdTxt .= t('Forgot your password? <a href="%0%">Request a new one</a>.', Uri::get('lost-password', 'main', 'forgot', 'affiliate'));
             \PFBC\Form::setError('form_login_aff', $sWrongPwdTxt);
         }
     } else {
         $oSecurityModel->clearLoginAttempts('Affiliates');
         $this->session->remove('captcha_enabled');
         $iId = $oAffModel->getId($sEmail, null, 'Affiliates');
         $oAffData = $oAffModel->readProfile($iId, 'Affiliates');
         if (true !== ($mStatus = (new AffiliateCore())->checkAccountStatus($oAffData))) {
             \PFBC\Form::setError('form_login_aff', $mStatus);
         } else {
             // Is disconnected if the user is logged on as "user" or "administrator".
             if (UserCore::auth() || AdminCore::auth()) {
                 $this->session->destroy();
             }
             // Regenerate the session ID to prevent the session fixation
             $this->session->regenerateId();
             $aSessionData = ['affiliate_id' => $oAffData->profileId, 'affiliate_email' => $oAffData->email, 'affiliate_username' => $oAffData->username, 'affiliate_first_name' => $oAffData->firstName, 'affiliate_sex' => $oAffData->sex, 'affiliate_ip' => Ip::get(), 'affiliate_http_user_agent' => $this->browser->getUserAgent(), 'affiliate_token' => Various::genRnd($oAffData->email)];
             $this->session->set($aSessionData);
             $oSecurityModel->addLoginLog($oAffData->email, $oAffData->username, '*****', 'Logged in!', 'Affiliates');
             $oAffModel->setLastActivity($oAffData->profileId, 'Affiliates');
             Header::redirect(Uri::get('affiliate', 'account', 'index'), t('You are successfully logged!'));
         }
     }
 }
 public function __construct($sTable)
 {
     parent::__construct();
     $oUserModel = new UserCoreModel();
     $sMail = $this->httpRequest->post('mail');
     if (!($iProfileId = $oUserModel->getId($sMail, null, $sTable))) {
         sleep(1);
         // Security against brute-force attack to avoid drowning the server and the database
         \PFBC\Form::setError('form_forgot_password', t('Oops, this "%0%" is not associated with any %site_name% account. Please, make sure that you entered the e-mail address used in creating your account.', escape(substr($sMail, 0, PH7_MAX_EMAIL_LENGTH))));
     } else {
         $oUserModel->setNewHashValidation($iProfileId, Various::genRnd(), $sTable);
         (new UserCore())->clearReadProfileCache($iProfileId, $sTable);
         // Clean the profile data (for the new hash)
         $oData = $oUserModel->readProfile($iProfileId, $sTable);
         /** We place the text outside of Uri::get() otherwise special characters will be deleted and the parameters passed in the url will be unusable thereafter. **/
         $sResetUrl = Uri::get('lost-password', 'main', 'reset', $this->httpRequest->get('mod')) . PH7_SH . $oData->email . PH7_SH . $oData->hashValidation;
         $this->view->content = t('Hello %0%!<br />Somebody (from the IP address %1%) has requested a new password for their account.', $oData->username, Ip::get()) . '<br />' . t('If you requested for this, click on the link below, otherwise ignore this email and your password will remain unchanged.') . '<br /><a href="' . $sResetUrl . '">' . $sResetUrl . '</a>';
         $sMessageHtml = $this->view->parseMail(PH7_PATH_SYS . 'global/' . PH7_VIEWS . PH7_TPL_NAME . '/mail/sys/mod/lost-password/confirm-lost-password.tpl', $oData->email);
         $aInfo = ['to' => $oData->email, 'subject' => t('Request for new password - %site_name%')];
         unset($oData);
         if (!(new Mail())->send($aInfo, $sMessageHtml)) {
             \PFBC\Form::setError('form_forgot_password', Form::errorSendingEmail());
         } else {
             \PFBC\Form::setSuccess('form_forgot_password', t('Successfully requested a new password, email sent!'));
         }
     }
     unset($oUserModel);
 }
Example #7
0
 public function step1()
 {
     $iAffId = (int) (new Cookie())->get(AffiliateCore::COOKIE_NAME);
     $sRef = $this->session->exists('joinRef') ? $this->session->get('joinRef') : t('No reference');
     // Statistics
     $this->session->remove('joinRef');
     $aData = ['email' => $this->httpRequest->post('mail'), 'username' => $this->httpRequest->post('username'), 'first_name' => $this->httpRequest->post('first_name'), 'reference' => $sRef, 'ip' => Ip::get(), 'hash_validation' => Various::genRnd(), 'current_date' => (new CDateTime())->get()->dateTime('Y-m-d H:i:s'), 'is_active' => $this->iActiveType, 'group_id' => (int) DbConfig::getSetting('defaultMembershipGroupId'), 'affiliated_id' => $iAffId];
     $aData += ['password' => Security::hashPwd($this->httpRequest->post('password'))];
     $iTimeDelay = (int) DbConfig::getSetting('timeDelayUserRegistration');
     if (!$this->oUserModel->checkWaitJoin($aData['ip'], $iTimeDelay, $aData['current_date'])) {
         \PFBC\Form::setError('form_join_user', Form::waitRegistrationMsg($iTimeDelay));
     } elseif (!$this->oUserModel->join($aData)) {
         \PFBC\Form::setError('form_join_user', t('An error occurred during registration!<br />
         Please try again with other information in the form fields or come back later.'));
     } else {
         // Successful registration in the database for step 1!
         /** Update the Affiliate Commission **/
         if ($this->iActiveType == 0) {
             // Only if the user's account is already activated.
             AffiliateCore::updateJoinCom($iAffId, $this->config, $this->registry);
         }
         // Send email
         $this->oRegistration->sendMail($aData);
         $this->session->set('mail_step1', $this->httpRequest->post('mail'));
         HeaderUrl::redirect(Uri::get('user', 'signup', 'step2'));
     }
 }
Example #8
0
 public function __construct()
 {
     parent::__construct();
     $sIp = Ip::get();
     $oAdminModel = new AdminModel();
     $oSecurityModel = new SecurityModel();
     $sEmail = $this->httpRequest->post('mail');
     $sUsername = $this->httpRequest->post('username');
     $sPassword = $this->httpRequest->post('password');
     /*** Security IP Login ***/
     $sIpLogin = DbConfig::getSetting('ipLogin');
     /*** Check if the connection is not locked ***/
     $bIsLoginAttempt = (bool) DbConfig::getSetting('isAdminLoginAttempt');
     $iMaxAttempts = (int) DbConfig::getSetting('maxAdminLoginAttempts');
     $iTimeDelay = (int) DbConfig::getSetting('loginAdminAttemptTime');
     if ($bIsLoginAttempt && !$oSecurityModel->checkLoginAttempt($iMaxAttempts, $iTimeDelay, $sEmail, $this->view, 'Admins')) {
         \PFBC\Form::setError('form_admin_login', Form::loginAttemptsExceededMsg($iTimeDelay));
         return;
         // Stop execution of the method.
     }
     /*** Check Login ***/
     $bIsLogged = $oAdminModel->adminLogin($sEmail, $sUsername, $sPassword);
     $bIsIpBanned = !empty($sIpLogin) && $sIpLogin !== $sIp;
     if (!$bIsLogged || $bIsIpBanned) {
         sleep(2);
         // Security against brute-force attack to avoid drowning the server and the database
         if (!$bIsLogged) {
             $oSecurityModel->addLoginLog($sEmail, $sUsername, $sPassword, 'Failed! Incorrect Email, Username or Password', 'Admins');
             if ($bIsLoginAttempt) {
                 $oSecurityModel->addLoginAttempt('Admins');
             }
             $this->session->set('captcha_admin_enabled', 1);
             // Enable Captcha
             \PFBC\Form::setError('form_admin_login', t('"Email", "Username" or "Password" is Incorrect'));
         } elseif ($bIsIpBanned) {
             $this->session->set('captcha_admin_enabled', 1);
             // Enable Captcha
             \PFBC\Form::setError('form_admin_login', t('Incorrect Login!'));
             $oSecurityModel->addLoginLog($sEmail, $sUsername, $sPassword, 'Failed! Bad Ip adress', 'Admins');
         }
     } else {
         $oSecurityModel->clearLoginAttempts('Admins');
         $this->session->remove('captcha_admin_enabled');
         // Is disconnected if the user is logged on as "user" or "affiliate".
         if (UserCore::auth() || AffiliateCore::auth()) {
             $this->session->destroy();
         }
         $iId = $oAdminModel->getId($sEmail, null, 'Admins');
         $oAdminData = $oAdminModel->readProfile($iId, 'Admins');
         // Regenerate the session ID to prevent the session fixation
         $this->session->regenerateId();
         $aSessionData = array('admin_id' => $oAdminData->profileId, 'admin_email' => $oAdminData->email, 'admin_username' => $oAdminData->username, 'admin_first_name' => $oAdminData->firstName, 'admin_ip' => $sIp, 'admin_http_user_agent' => $this->browser->getUserAgent(), 'admin_token' => Various::genRnd($oAdminData->email));
         $this->session->set($aSessionData);
         $oSecurityModel->addLoginLog($sEmail, $sUsername, '*****', 'Logged in!', 'Admins');
         $oAdminModel->setLastActivity($oAdminData->profileId, 'Admins');
         HeaderUrl::redirect(Uri::get(PH7_ADMIN_MOD, 'main', 'index'), t('You signup is successfully!'));
     }
 }
 public function generatePath()
 {
     $this->sIsManualApproval = DbConfig::getSetting('webcamPictureManualApproval') == 1 ? 'pending' : 'img';
     $this->sFile = Various::genRnd() . '.jpg';
     $this->sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'webcam/picture/';
     $this->sTmpPathFile = $this->sPath . 'tmp/' . $this->sFile;
     $this->sOriginalPathFile = $this->sPath . $this->sIsManualApproval . '/original/' . $this->sFile;
     $this->sThumbPathFile = $this->sPath . $this->sIsManualApproval . '/thumb/' . $this->sFile;
     return $this;
 }
Example #10
0
 /**
  * @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)
 {
     $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);
 }
 /**
  * Generate a random token.
  *
  * @param string $sName
  * @return string The Token generated random.
  */
 public function generate($sName)
 {
     // If the token is still valid, it returns the correct token
     if ($this->_oSession->exists('security_token_' . $sName)) {
         return $this->_oSession->get('security_token_' . $sName);
     } else {
         $sToken = Various::genRnd($sName);
         $aSessionData = ['security_token_' . $sName => $sToken, 'security_token_time_' . $sName => time(), 'security_token_ip_' . $sName => Ip::get(), 'security_token_http_user_agent_' . $sName => $this->_sUserAgent];
         $this->_oSession->set($aSessionData);
         return $sToken;
     }
 }
 /**
  * @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 reset($sMod = '', $sMail = '', $sHash = '')
 {
     $this->checkMod($sMod);
     $sTable = VariousModel::convertModToTable($sMod);
     if (!(new UserCoreModel())->checkHashValidation($sMail, $sHash, $sTable)) {
         Header::redirect($this->registry->site_url, t('Oops! Email or hash is invalid.'), 'error');
     } else {
         $sNewPassword = Various::genRndWord(8, 40);
         (new UserCoreModel())->changePassword($sMail, $sNewPassword, $sTable);
         $this->view->content = t('Hello!<br />Your password has been changed to <em>"%0%"</em>.<br />Please change it next time you login.', $sNewPassword);
         $sMessageHtml = $this->view->parseMail(PH7_PATH_SYS . 'global/' . PH7_VIEWS . PH7_TPL_NAME . '/mail/sys/mod/lost-password/recover_password.tpl', $sMail);
         $aInfo = ['to' => $sMail, 'subject' => t('Your new password - %site_name%')];
         if (!(new Mail())->send($aInfo, $sMessageHtml)) {
             Header::redirect($this->registry->site_url, Form::errorSendingEmail(), 'error');
         } else {
             Header::redirect($this->registry->site_url, t('Your new password has been emailed to you.'));
         }
     }
 }
 public function __construct()
 {
     parent::__construct();
     $oSubscriptionModel = new SubscriptionModel();
     $sEmail = $this->httpRequest->post('email');
     $sName = $this->httpRequest->post('name');
     $bIsSubscriber = (new ExistsCoreModel())->email($sEmail, 'Subscribers');
     switch ($this->httpRequest->post('direction')) {
         case 'subscrire':
             if (!$bIsSubscriber) {
                 $aData = ['name' => $sName, 'email' => $sEmail, 'current_date' => (new CDateTime())->get()->dateTime('Y-m-d H:i:s'), 'ip' => Ip::get(), 'hash_validation' => Various::genRnd(), 'active' => '0', 'affiliated_id' => (int) (new Cookie())->get(AffiliateCore::COOKIE_NAME)];
                 $sActivateLink = Uri::get('newsletter', 'home', 'activate') . PH7_SH . $aData['email'] . PH7_SH . $aData['hash_validation'];
                 $this->view->content = t('Hi %0%!', $aData['name']) . '<br />' . t("Welcome to %site_name%'s Subscription!") . '<br />' . t('Activation link: %0%.', '<a href="' . $sActivateLink . '">' . $sActivateLink . '</a>');
                 $this->view->footer = t('You are receiving this mail because we received an application for registration with the email "%0%" has been provided in the form of %site_name% (%site_url%).', $aData['email']) . '<br />' . t('If you think someone has used your email address without your knowledge to create an account on %site_name%, please contact us using our contact form available on our website.');
                 $sMessageHtml = $this->view->parseMail(PH7_PATH_SYS . 'global/' . PH7_VIEWS . PH7_TPL_NAME . '/mail/sys/mod/newsletter/registration.tpl', $sEmail);
                 $aInfo = ['subject' => t('Confirm you email address!'), 'to' => $sEmail];
                 if ((new Mail())->send($aInfo, $sMessageHtml)) {
                     \PFBC\Form::setSuccess('form_subscription', t('Please activate your subscription by clicking the activation link you received by email. If you can not find the email, please look in your SPAM FOLDER and mark as not spam.'));
                     $oSubscriptionModel->add($aData);
                 } else {
                     \PFBC\Form::setError('form_subscription', Form::errorSendingEmail());
                 }
             } else {
                 \PFBC\Form::setError('form_subscription', t('Oops! You are already subscribed to our newsletter.'));
             }
             break;
         case 'unsubscribe':
             if ($bIsSubscriber) {
                 $oSubscriptionModel->unsubscribe($sEmail);
                 \PFBC\Form::setSuccess('form_subscription', t('Your subscription was successfully canceled.'));
             } else {
                 \PFBC\Form::setError('form_subscription', t('We have not found any subscriber with the email address.'));
             }
             break;
         default:
             Framework\Http\Http::setHeadersByCode(400);
             exit('Bad Request Error!');
     }
     unset($oSubscriptionModel);
 }
Example #16
0
 /**
  * Sets the Note Thumbnail.
  *
  * @param object $oPost
  * @param \PH7\NoteModel $oNoteModel
  * @param \PH7\Framework\File\File $oFile
  * @return void
  */
 public function setThumb($oPost, NoteModel $oNoteModel, Framework\File\File $oFile)
 {
     if (!empty($_FILES['thumb']['tmp_name'])) {
         $oImage = new Framework\Image\Image($_FILES['thumb']['tmp_name']);
         if (!$oImage->validate()) {
             \PFBC\Form::setError('form_note', Form::wrongImgFileTypeMsg());
         } else {
             /**
              * The method deleteFile first test if the file exists, if so it delete the file.
              */
             $sPathName = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'note/' . PH7_IMG . $oPost->username . PH7_SH;
             $oFile->deleteFile($sPathName);
             // It erases the old thumbnail
             $oFile->createDir($sPathName);
             $sFileName = Various::genRnd($oImage->getFileName(), 20) . PH7_DOT . $oImage->getExt();
             $oImage->square(100);
             $oImage->save($sPathName . $sFileName);
             $oNoteModel->updatePost('thumb', $sFileName, $oPost->noteId, $oPost->profileId);
         }
         unset($oImage);
     }
 }
Example #17
0
 public function step1()
 {
     $sBirthDate = $this->dateTime->get($this->httpRequest->post('birth_date'))->date('Y-m-d');
     $iAffId = (int) (new Cookie())->get(AffiliateCore::COOKIE_NAME);
     $aData = ['email' => $this->httpRequest->post('mail'), 'username' => $this->httpRequest->post('username'), 'password' => $this->httpRequest->post('password'), 'first_name' => $this->httpRequest->post('first_name'), 'last_name' => $this->httpRequest->post('last_name'), 'sex' => $this->httpRequest->post('sex'), 'birth_date' => $sBirthDate, 'country' => $this->httpRequest->post('country'), 'city' => $this->httpRequest->post('city'), 'state' => $this->httpRequest->post('state'), 'zip_code' => $this->httpRequest->post('zip_code'), 'ip' => Ip::get(), 'hash_validation' => Various::genRnd(), 'current_date' => (new CDateTime())->get()->dateTime('Y-m-d H:i:s'), 'is_active' => $this->iActiveType, 'affiliated_id' => $iAffId];
     $oAffModel = new AffiliateModel();
     $iTimeDelay = (int) DbConfig::getSetting('timeDelayUserRegistration');
     if (!$oAffModel->checkWaitJoin($aData['ip'], $iTimeDelay, $aData['current_date'], 'Affiliates')) {
         \PFBC\Form::setError('form_join_aff', Form::waitRegistrationMsg($iTimeDelay));
     } elseif (!$oAffModel->join($aData)) {
         \PFBC\Form::setError('form_join_aff', t('An error occurred during registration!<br /> Please try again with other information in the form fields or come back later.'));
     } else {
         // Successful registration in the database!
         /** Update the Affiliate Commission **/
         if ($this->iActiveType == 0) {
             // Only if the user's account is already activated.
             AffiliateCore::updateJoinCom($iAffId, $this->config, $this->registry);
         }
         // Send an email and sets the welcome message.
         \PFBC\Form::setSuccess('form_join_aff', t('Your affiliate account has been created! %0%', (new Registration())->sendMail($aData)->getMsg()));
     }
     unset($oAffModel);
 }
Example #18
0
 /**
  * Get and saves the Avatar in the temporary directory.
  *
  * @param string $sUrl
  * @return string The path of the Avatar
  */
 public function getAvatar($sUrl)
 {
     $sTmpDest = PH7_PATH_TMP . Various::genRnd() . '.jpg';
     @copy($sUrl, $sTmpDest);
     return $sTmpDest;
 }
 /**
  * Finds a free username in our database to use for Facebook connect.
  *
  * @param string $sNickname
  * @param string $sFirstName
  * @param string $sLastName
  * @return string Username
  */
 public function findUsername($sNickname, $sFirstName, $sLastName)
 {
     $sRnd = Various::genRnd('pH_Pierre-Henry_Soria_Sanz_González', 4);
     // Random String
     $iMinLen = DbConfig::getSetting('minUsernameLength');
     // Minimum Length
     $iMaxLen = DbConfig::getSetting('maxUsernameLength');
     // Maximum Length
     $aUsernameList = [$sNickname, $sFirstName, $sLastName, $sNickname . $sRnd, $sFirstName . $sRnd, $sLastName . $sRnd, Various::genRndWord($iMinLen, $iMaxLen), $sFirstName . '-' . $sLastName, $sLastName . '-' . $sFirstName, $sFirstName . '-' . $sLastName . $sRnd, $sLastName . '-' . $sFirstName . $sRnd];
     foreach ($aUsernameList as $sUsername) {
         $sUsername = substr($sUsername, 0, $iMaxLen);
         if ((new Framework\Security\Validate\Validate())->username($sUsername)) {
             break;
         } else {
             $sUsername = Various::genRnd('pOH_Pierre-Henry_Soria_Béghin_Rollier', $iMaxLen);
         }
         // Default value
     }
     return $sUsername;
 }
Example #20
0
 public function loginUserAs($iId)
 {
     $aSessionData = ['login_user_as' => 1, 'member_id' => $iId, 'member_email' => $this->oAdminModel->getEmail($iId), 'member_username' => $this->oAdminModel->getUsername($iId), 'member_first_name' => $this->oAdminModel->getFirstName($iId), 'member_sex' => $this->oAdminModel->getSex($iId), 'member_group_id' => $this->oAdminModel->getGroupId($iId), 'member_ip' => Framework\Ip\Ip::get(), 'member_http_user_agent' => $this->browser->getUserAgent(), 'member_token' => Framework\Util\Various::genRnd()];
     $this->session->set($aSessionData);
     HeaderUrl::redirect($this->registry->site_url, t('You are now logged in as member: %0%!', $this->session->get('member_username')));
 }
 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));
 }
 /**
  * Set default values for the "ImportUser::$_aTmpData" array.
  *
  * @return void
  */
 protected function setDefVals()
 {
     $sFiveChars = Various::genRnd($this->_aFile['name'], 5);
     $this->_aTmpData = ['email' => 'pierrehenrysoriasanz' . $sFiveChars . '@hizup' . $sFiveChars . '.com', 'username' => 'Hizup' . $sFiveChars, 'password' => Various::genRnd(), 'first_name' => 'Alex' . $sFiveChars, 'last_name' => 'Rolli' . $sFiveChars, 'sex' => $this->_aGenderList[mt_rand(0, 2)], 'match_sex' => $this->_aGenderList[mt_rand(0, 2)], 'birth_date' => date('Y') - mt_rand(20, 50) . '-' . 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()];
 }
 public function __construct()
 {
     parent::__construct();
     /**
      * @desc This can cause minor errors (eg if a user sent a file that is not a photo).
      * So we hide the errors if we are not in development mode.
      */
     if (!isDebug()) {
         error_reporting(0);
     }
     /**
      * @desc
      * Check if the photo album ID is valid. The value must be numeric.
      * This test is necessary because when the selection exists but that no option is available (this can when a user wants to add photos but he has no album)
      * the return value is of type "string" and the value is "1".
      */
     if (!is_numeric($this->httpRequest->post('album_id'))) {
         \PFBC\Form::setError('form_picture', t('Please add a category before you add some photos.'));
         return;
         // Stop execution of the method.
     }
     /**
      * @desc Resizing and saving some photos
      */
     $aPhotos = $_FILES['photos']['tmp_name'];
     for ($i = 0, $iNumPhotos = count($aPhotos); $i < $iNumPhotos; $i++) {
         $oPicture1 = new Image($aPhotos[$i], 2500, 2500);
         if (!$oPicture1->validate()) {
             \PFBC\Form::setError('form_picture', Form::wrongImgFileTypeMsg());
             return;
             // Stop execution of the method.
         }
         $sAlbumTitle = $this->httpRequest->post('album_title');
         $iAlbumId = (int) $this->httpRequest->post('album_id');
         $oPicture2 = clone $oPicture1;
         $oPicture3 = clone $oPicture1;
         $oPicture4 = clone $oPicture1;
         $oPicture5 = clone $oPicture1;
         $oPicture6 = clone $oPicture1;
         $oPicture2->square(400);
         $oPicture3->square(600);
         $oPicture4->square(800);
         $oPicture5->square(1000);
         $oPicture6->square(1200);
         /* Set watermark text on images */
         $sWatermarkText = DbConfig::getSetting('watermarkTextImage');
         $iSizeWatermarkText = DbConfig::getSetting('sizeWatermarkTextImage');
         $oPicture1->watermarkText($sWatermarkText, $iSizeWatermarkText);
         $oPicture2->watermarkText($sWatermarkText, $iSizeWatermarkText);
         $oPicture3->watermarkText($sWatermarkText, $iSizeWatermarkText);
         $oPicture4->watermarkText($sWatermarkText, $iSizeWatermarkText);
         $oPicture5->watermarkText($sWatermarkText, $iSizeWatermarkText);
         $oPicture6->watermarkText($sWatermarkText, $iSizeWatermarkText);
         $sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'picture/img/' . $this->session->get('member_username') . PH7_DS . $iAlbumId . PH7_DS;
         $sFileName = Various::genRnd($oPicture1->getFileName(), 20);
         $sFile1 = $sFileName . '-original.' . $oPicture1->getExt();
         // Original
         $sFile2 = $sFileName . '-400.' . $oPicture2->getExt();
         $sFile3 = $sFileName . '-600.' . $oPicture3->getExt();
         $sFile4 = $sFileName . '-800.' . $oPicture4->getExt();
         $sFile5 = $sFileName . '-1000.' . $oPicture5->getExt();
         $sFile6 = $sFileName . '-1200.' . $oPicture6->getExt();
         $oPicture1->save($sPath . $sFile1);
         $oPicture2->save($sPath . $sFile2);
         $oPicture3->save($sPath . $sFile3);
         $oPicture4->save($sPath . $sFile4);
         $oPicture5->save($sPath . $sFile5);
         $oPicture6->save($sPath . $sFile6);
         $iApproved = DbConfig::getSetting('pictureManualApproval') == 0 ? '1' : '0';
         // It creates a nice title if no title is specified.
         $sTitle = $this->httpRequest->postExists('title') && $this->str->length($this->str->trim($this->httpRequest->post('title'))) > 2 ? $this->httpRequest->post('title') : $this->str->upperFirst(str_replace(array('-', '_'), ' ', str_ireplace(PH7_DOT . $oPicture1->getExt(), '', escape($_FILES['photos']['name'][$i], true))));
         (new PictureModel())->addPhoto($this->session->get('member_id'), $iAlbumId, $sTitle, $this->httpRequest->post('description'), $sFile1, $this->dateTime->get()->dateTime('Y-m-d H:i:s'), $iApproved);
     }
     /* Clean PictureModel Cache */
     (new Framework\Cache\Cache())->start(PictureModel::CACHE_GROUP, null, null)->clear();
     $sModerationText = t('Your photo(s) has been received! But it will be visible once approved by our moderators. Please do not send a new photo(s) because this is useless!');
     $sText = t('Your photo(s) has been added successfully!');
     $sMsg = $iApproved == '0' ? $sModerationText : $sText;
     Header::redirect(Uri::get('picture', 'main', 'album', $this->session->get('member_username') . ',' . $sAlbumTitle . ',' . $iAlbumId), $sMsg);
 }
Example #24
0
 public function loginUserAs($iId)
 {
     $aSessionData = ['login_affiliate_as' => 1, 'affiliate_id' => $iId, 'affiliate_email' => $this->oAffModel->getEmail($iId, 'Affiliates'), 'affiliate_username' => $this->oAffModel->getUsername($iId, 'Affiliates'), 'affiliate_first_name' => $this->oAffModel->getFirstName($iId, 'Affiliates'), 'affiliate_sex' => $this->oAffModel->getSex($iId, null, 'Affiliates'), 'affiliate_ip' => Framework\Ip\Ip::get(), 'affiliate_http_user_agent' => $this->browser->getUserAgent(), 'affiliate_token' => Framework\Util\Various::genRnd()];
     $this->session->set($aSessionData);
     HeaderUrl::redirect(Uri::get('affiliate', 'account', 'index'), t('You are now logged in as affiliate: %0%!', $this->session->get('affiliate_username')));
 }
Example #25
0
 /**
  * Generate a hash.
  *
  * @param string $sVal
  * @param integer $iLength Default 80
  * @return string
  */
 public static function hash($sVal, $iLength = 80)
 {
     return Various::padStr(hash('whirlpool', hash('sha512', self::PREFIX_SALT . hash('whirlpool', self::PREFIX_SALT)) . hash('whirlpool', $sVal) . hash('sha512', hash('whirlpool', self::SUFFIX_SALT) . self::SUFFIX_SALT)), $iLength);
 }
 public function __construct()
 {
     parent::__construct();
     /**
      * This can cause minor errors (eg if a user sent a file that is not a video).
      * So we hide the errors if we are not in development mode.
      */
     if (!isDebug()) {
         error_reporting(0);
     }
     /**
      * Check if the video album ID is valid. The value must be numeric.
      * This test is necessary because when the selection exists but that no option is available (this can when a user wants to add a video but he has no album)
      * the return value is of type "string" and the value is "1".
      */
     if (!is_numeric($this->httpRequest->post('album_id'))) {
         \PFBC\Form::setError('form_video', t('Please add a category before you add a video.'));
         return;
         // Stop execution of the method.
     }
     $sAlbumTitle = $this->httpRequest->post('album_title');
     $iAlbumId = (int) $this->httpRequest->post('album_id');
     /** Default URL Thumbnail **/
     $sThumb = '';
     if ($this->httpRequest->postExists('embed_code')) {
         $sEmbedUrl = $this->httpRequest->post('embed_code');
         if (!($sFile = (new V\Api())->getVideo($sEmbedUrl))) {
             \PFBC\Form::setError('form_video', t('Oops, the link of the video looks bad? Check that the link is correct.'));
             return;
         }
         if (!($oInfo = (new V\Api())->getInfo($sEmbedUrl))) {
             \PFBC\Form::setError('form_video', t('Unable to retrieve information from the video. Are you sure that the URL of the video is correct?'));
             return;
         }
         $sTitle = $this->httpRequest->postExists('title') && $this->str->length($this->str->trim($this->httpRequest->post('title'))) > 2 ? $this->httpRequest->post('title') : ($oInfo->getTitle() ? $oInfo->getTitle() : t('Untitled'));
         $sDescription = $this->httpRequest->postExists('description') ? $this->httpRequest->post('description') : ($oInfo->getDescription() ? $oInfo->getDescription() : '');
         $sDuration = $oInfo->getDuration() ? $oInfo->getDuration() : '0';
         // Time in seconds
         if (!$sFile) {
             \PFBC\Form::setError('form_video', t('Invalid Api Video Type! Choose from Youtube, Vimeo, Dailymotion and Metacafe.'));
             return;
         }
     } elseif (!empty($_FILES['video']['tmp_name'])) {
         $oVideo = new V\Video($_FILES['video'], 2500, 2500);
         if (!$oVideo->validate()) {
             \PFBC\Form::setError('form_video', Form::wrongVideoFileTypeMsg());
             return;
         } elseif (!$oVideo->check()) {
             \PFBC\Form::setError('form_video', t('File exceeds maximum allowed video filesize of %0%!', F\Various::bytesToSize($oVideo->getMaxSize())));
             return;
         } else {
             // It creates a nice title if no title is specified.
             $sTitle = $this->httpRequest->postExists('title') && $this->str->length($this->str->trim($this->httpRequest->post('title'))) > 2 ? $this->httpRequest->post('title') : $this->str->upperFirst(str_replace(array('-', '_'), ' ', str_ireplace(PH7_DOT . $oVideo->getExt(), '', escape($_FILES['video']['name'], true))));
             $sDescription = $this->httpRequest->post('description');
             $sDuration = $oVideo->getDuration();
             $sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'video/file/' . $this->session->get('member_username') . PH7_DS . $iAlbumId . PH7_DS;
             $sFileName = Various::genRnd($oVideo->getFileName(), 20);
             $sThumb = $sFileName . '.jpg';
             $sThumb1 = $sFileName . '-1.jpg';
             $sThumb2 = $sFileName . '-2.jpg';
             $sThumb3 = $sFileName . '-3.jpg';
             $sThumb4 = $sFileName . '-4.jpg';
             $sFile = $sFileName;
             $oVideo->thumbnail($sPath . $sThumb, 1, 320, 240);
             $oVideo->thumbnail($sPath . $sThumb1, 4, 320, 240);
             $oVideo->thumbnail($sPath . $sThumb2, 6, 320, 240);
             $oVideo->thumbnail($sPath . $sThumb3, 8, 320, 240);
             $oVideo->thumbnail($sPath . $sThumb4, 10, 320, 240);
             $oVideo->rename($sPath . $sFile . '.webm');
             $oVideo->rename($sPath . $sFile . '.mp4');
             //$oVideo->save($sPath . $sFile); // Original file type
         }
     } else {
         \PFBC\Form::setError('form_video', t('You must choose a type of video!'));
         return;
     }
     $iApproved = DbConfig::getSetting('videoManualApproval') == 0 ? '1' : '0';
     (new VideoModel())->addVideo($this->session->get('member_id'), $iAlbumId, $sTitle, $sDescription, $sFile, $sThumb, $sDuration, $this->dateTime->get()->dateTime('Y-m-d H:i:s'), $iApproved);
     /* Clean VideoModel Cache */
     (new Framework\Cache\Cache())->start(VideoModel::CACHE_GROUP, null, null)->clear();
     $sModerationText = t('Your video has been received! But it will be visible once approved by our moderators. Please do not send a new video because this is useless!');
     $sText = t('Your video has been added successfully!');
     $sMsg = $iApproved == '0' ? $sModerationText : $sText;
     Header::redirect(Uri::get('video', 'main', 'album', $this->session->get('member_username') . ',' . $sAlbumTitle . ',' . $iAlbumId), $sMsg);
 }