コード例 #1
0
 public static function display()
 {
     if (isset($_POST['submit_user_edit_account'])) {
         if (\PFBC\Form::isValid($_POST['submit_user_edit_account'])) {
             new EditFormProcess();
         }
         Framework\Url\Header::redirect();
     }
     $bAdminLogged = AdminCore::auth() && !User::auth();
     // Check if the admin is logged.
     $oUserModel = new UserModel();
     $oHR = new Http();
     $iProfileId = $bAdminLogged && $oHR->getExists('profile_id') ? $oHR->get('profile_id', 'int') : (new Session())->get('member_id');
     $oUser = $oUserModel->readProfile($iProfileId);
     // Birth Date with the date format for the date picker
     $sBirthDate = (new CDateTime())->get($oUser->birthDate)->date('m/d/Y');
     $oForm = new \PFBC\Form('form_user_edit_account');
     $oForm->configure(array('action' => ''));
     $oForm->addElement(new \PFBC\Element\Hidden('submit_user_edit_account', 'form_user_edit_account'));
     $oForm->addElement(new \PFBC\Element\Token('edit_account'));
     if ($bAdminLogged && $oHR->getExists('profile_id')) {
         $oForm->addElement(new \PFBC\Element\HTMLExternal('<p class="center"><a class="m_button" href="' . Uri::get(PH7_ADMIN_MOD, 'user', 'browse') . '">' . t('Back to Browse Users') . '</a></p>'));
         $oGroupId = (new AdminCoreModel())->getMemberships();
         $aGroupName = array();
         foreach ($oGroupId as $oId) {
             // Retrieve only the activated memberships
             if ($oId->enable == 1) {
                 $aGroupName[$oId->groupId] = $oId->name;
             }
         }
         $oForm->addElement(new \PFBC\Element\Select(t('Membership Group:'), 'group_id', $aGroupName, array('value' => $oUser->groupId, 'required' => 1)));
         unset($aGroupName);
     }
     unset($oHR);
     $oForm->addElement(new \PFBC\Element\Textbox(t('First Name:'), 'first_name', array('id' => 'str_first_name', 'onblur' => 'CValid(this.value,this.id,2,20)', 'value' => $oUser->firstName, 'required' => 1, 'validation' => new \PFBC\Validation\Str(2, 20))));
     $oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error str_first_name"></span>'));
     $oForm->addElement(new \PFBC\Element\Textbox(t('Last Name:'), 'last_name', array('id' => 'str_last_name', 'onblur' => 'CValid(this.value,this.id,2,20)', 'value' => $oUser->lastName, 'validation' => new \PFBC\Validation\Str(2, 20))));
     $oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error str_last_name"></span>'));
     $oForm->addElement(new \PFBC\Element\Textbox(t('Username:'******'username', array('description' => t('For site security, you cannot change your username.'), 'disabled' => 'disabled', 'value' => $oUser->username)));
     $oForm->addElement(new \PFBC\Element\Email(t('Email:'), 'mail', array('description' => t('For site security and to avoid spam, you cannot change your email address.'), 'disabled' => 'disabled', 'value' => $oUser->email)));
     $oForm->addElement(new \PFBC\Element\Radio(t('Gender:'), 'sex', array('female' => t('Female'), 'male' => t('Male'), 'couple' => t('Couple')), array('value' => $oUser->sex, 'required' => 1)));
     $oForm->addElement(new \PFBC\Element\Checkbox(t('Interested in:'), 'match_sex', array('male' => t('Male'), 'female' => t('Female'), 'couple' => t('Couple')), array('value' => Form::getVal($oUser->matchSex), 'required' => 1)));
     $oForm->addElement(new \PFBC\Element\Date(t('Date of birth:'), 'birth_date', array('id' => 'birth_date', 'onblur' => 'CValid(this.value, this.id)', 'value' => $sBirthDate, 'validation' => new \PFBC\Validation\BirthDate(), 'required' => 1)));
     $oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error birth_date"></span>'));
     // Generate dynamic fields
     $oFields = $oUserModel->getInfoFields($iProfileId);
     foreach ($oFields as $sColumn => $sValue) {
         $oForm = (new DynamicFieldCoreForm($oForm, $sColumn, $sValue))->generate();
     }
     $oForm->addElement(new \PFBC\Element\Button());
     $oForm->addElement(new \PFBC\Element\HTMLExternal('<script src="' . PH7_URL_STATIC . PH7_JS . 'validate.js"></script><script src="' . PH7_URL_STATIC . PH7_JS . 'geo/autocompleteCity.js"></script>'));
     $oForm->render();
 }
コード例 #2
0
 public function __construct()
 {
     parent::__construct();
     $oUserModel = new UserModel();
     $iProfileId = AdminCore::auth() && !User::auth() && $this->httpRequest->getExists('profile_id') ? $this->httpRequest->get('profile_id', 'int') : $this->session->get('member_id');
     $oUser = $oUserModel->readProfile($iProfileId);
     // For Admins only!
     if (AdminCore::auth() && !User::auth() && $this->httpRequest->getExists('profile_id')) {
         if (!$this->str->equals($this->httpRequest->post('group_id'), $oUser->groupId)) {
             $oUserModel->updateMembership($this->httpRequest->post('group_id'), $iProfileId);
         }
     }
     if (!$this->str->equals($this->httpRequest->post('first_name'), $oUser->firstName)) {
         $oUserModel->updateProfile('firstName', $this->httpRequest->post('first_name'), $iProfileId);
         $this->session->set('member_first_name', $this->httpRequest->post('first_name'));
         (new Framework\Cache\Cache())->start(UserCoreModel::CACHE_GROUP, 'firstName' . $iProfileId . 'Members', null)->clear();
     }
     if (!$this->str->equals($this->httpRequest->post('last_name'), $oUser->lastName)) {
         $oUserModel->updateProfile('lastName', $this->httpRequest->post('last_name'), $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('sex'), $oUser->sex)) {
         $oUserModel->updateProfile('sex', $this->httpRequest->post('sex'), $iProfileId);
         $this->session->set('member_sex', $this->httpRequest->post('sex'));
         (new Framework\Cache\Cache())->start(UserCoreModel::CACHE_GROUP, 'sex' . $iProfileId . 'Members', null)->clear();
     }
     // WARNING: Be careful, you should use the \PH7\Framework\Mvc\Request\Http::ONLY_XSS_CLEAN constant, otherwise the Request\Http::post() method removes the special tags
     // and damages the SET function SQL for entry into the database.
     if (!$this->str->equals($this->httpRequest->post('match_sex', Http::ONLY_XSS_CLEAN), $oUser->matchSex)) {
         $oUserModel->updateProfile('matchSex', Form::setVal($this->httpRequest->post('match_sex', Http::ONLY_XSS_CLEAN)), $iProfileId);
     }
     if (!$this->str->equals($this->dateTime->get($this->httpRequest->post('birth_date'))->date('Y-m-d'), $oUser->birthDate)) {
         $oUserModel->updateProfile('birthDate', $this->dateTime->get($this->httpRequest->post('birth_date'))->date('Y-m-d'), $iProfileId);
     }
     // Update dynamic fields.
     $oFields = $oUserModel->getInfoFields($iProfileId);
     foreach ($oFields as $sColumn => $sValue) {
         $sHRParam = $sColumn == 'description' ? Http::ONLY_XSS_CLEAN : null;
         if (!$this->str->equals($this->httpRequest->post($sColumn, $sHRParam), $sValue)) {
             $oUserModel->updateProfile($sColumn, $this->httpRequest->post($sColumn, $sHRParam), $iProfileId, 'MembersInfo');
         }
     }
     unset($oFields);
     $oUserModel->setLastEdit($iProfileId);
     /*** Clear caches ***/
     $oUserCache = new User();
     $oUserCache->clearReadProfileCache($iProfileId);
     $oUserCache->clearInfoFieldCache($iProfileId);
     // Destroy objects
     unset($oUserModel, $oUser, $oUserCache);
     \PFBC\Form::setSuccess('form_user_edit_account', t('Your profile has been saved successfully!'));
 }
コード例 #3
0
 public function index()
 {
     $oUserModel = new UserModel();
     // Add the style sheet for the Tabs Menu
     $this->design->addCss(PH7_LAYOUT . PH7_TPL . PH7_TPL_NAME . PH7_SH . PH7_CSS, 'tabs.css');
     // Add the JavaScript file for the Ajax Friend
     $this->design->addJs(PH7_LAYOUT . PH7_SYS . PH7_MOD . $this->registry->module . PH7_SH . PH7_TPL . PH7_TPL_MOD_NAME . PH7_SH . PH7_JS, 'friend.js');
     // Set the Profile username
     $this->sUsername = $this->httpRequest->get('username', 'string');
     // Set the Profile ID and Visitor ID
     $this->iProfileId = $oUserModel->getId(null, $this->sUsername);
     $this->iVisitorId = (int) $this->session->get('member_id');
     // Read the Profile information
     $oUser = $oUserModel->readProfile($this->iProfileId);
     if (!empty($oUser->username) && $this->str->equalsIgnoreCase($this->sUsername, $oUser->username)) {
         // The administrators can view all profiles and profile visits are not saved.
         if (!AdminCore::auth()) {
             $this->_initPrivacy($oUserModel, $this->iProfileId, $this->iVisitorId);
         }
         // Gets the Profile background
         $this->view->img_background = $oUserModel->getBackground($this->iProfileId, 1);
         $oFields = $oUserModel->getInfoFields($this->iProfileId);
         unset($oUserModel);
         $sFirstName = !empty($oUser->firstName) ? $this->str->escape($this->str->upperFirst($oUser->firstName), true) : '';
         $sLastName = !empty($oUser->lastName) ? $this->str->escape($this->str->upperFirst($oUser->lastName), true) : '';
         $sMiddleName = !empty($oFields->middleName) ? $this->str->escape($this->str->upperFirst($oFields->middleName), true) : '';
         $sCountry = !empty($oFields->country) ? $oFields->country : '';
         $sCity = !empty($oFields->city) ? $this->str->escape($this->str->upperFirst($oFields->city), true) : '';
         $sState = !empty($oFields->state) ? $this->str->escape($this->str->upperFirst($oFields->state), true) : '';
         $sDescription = !empty($oFields->description) ? Emoticon::init(Ban::filterWord($oFields->description)) : '';
         // Age
         $this->view->birth_date = $this->dateTime->get($oUser->birthDate)->date();
         $aAge = explode('-', $oUser->birthDate);
         $iAge = (new Framework\Math\Measure\Year($aAge[0], $aAge[1], $aAge[2]))->get();
         // Links of the Menubar
         $iNbFriend = FriendModel::totalFriends($this->iProfileId);
         $sNbFriend = $iNbFriend > 0 ? ' (' . $iNbFriend . ')' : '';
         $sFriendTxt = $iNbFriend <= 1 ? $iNbFriend == 1 ? t('Friend:') : t('No Friends') : t('Friends:');
         if ($this->sUserAuth) {
             $iNbMutFriend = (new FriendModel())->get($this->iVisitorId, $this->iProfileId, null, true, null, null, null, null);
             $sNbMutFriend = $iNbMutFriend > 0 ? ' (' . $iNbMutFriend . ')' : '';
             $sMutFriendTxt = $iNbMutFriend <= 1 ? $iNbMutFriend == 1 ? t('Mutual Friend:') : t('No Mutual Friends') : t('Mutuals Friends:');
         }
         $sMailLink = $this->sUserAuth ? Uri::get('mail', 'main', 'compose', $this->sUsername) : Uri::get('user', 'signup', 'step1', '?' . Url::httpBuildQuery(array('msg' => t('You need to free register for send a message to %0%.', $sFirstName), 'ref' => 'profile', 'a' => 'mail', 'u' => $this->sUsername, 'f_n' => $sFirstName, 's' => $oUser->sex)), false);
         $sMessengerLink = $this->sUserAuth ? 'javascript:void(0)" onclick="Messenger.chatWith(\'' . $this->sUsername . '\')' : Uri::get('user', 'signup', 'step1', '?' . Url::httpBuildQuery(array('msg' => t('You need to free register for talk to %0%.', $sFirstName), 'ref' => 'profile', 'a' => 'messenger', 'u' => $this->sUsername, 'f_n' => $sFirstName, 's' => $oUser->sex)), false);
         $sBefriendLink = $this->sUserAuth ? 'javascript:void(0)" onclick="friend(\'add\',' . $this->iProfileId . ',\'' . (new Framework\Security\CSRF\Token())->generate('friend') . '\')' : Uri::get('user', 'signup', 'step1', '?' . Url::httpBuildQuery(array('msg' => t('Free Sign up for %site_name% to become friend with %0%.', $sFirstName), 'ref' => 'profile', 'a' => 'befriend&', 'u' => $this->sUsername, 'f_n' => $sFirstName, 's' => $oUser->sex)), false);
         $this->view->page_title = t('Meet %0%, A beautiful %1% looking some %2% - %3% years - %4% - %5% %6%', $sFirstName, t($oUser->sex), t($oUser->matchSex), $iAge, t($sCountry), $sCity, $sState);
         $this->view->meta_description = t('Meet %0% %1% | %2% - %3%', $sFirstName, $sLastName, $this->sUsername, substr($sDescription, 0, 100));
         $this->view->h1_title = t('Meet <span class="pH1">%0%</span> on <span class="pH0">%site_name%</span>', $sFirstName);
         $this->view->h2_title = t('A <span class="pH1">%0%</span> of <span class="pH3">%1% years</span>, from <span class="pH2">%2%, %3% %4%</span>', t($oUser->sex), $iAge, t($sCountry), $sCity, $sState);
         $this->view->avatarDesign = new AvatarDesignCore();
         // Avatar Design Class
         // Member Menubar
         $this->view->friend_link = $sFriendTxt . $sNbFriend;
         if ($this->sUserAuth) {
             $this->view->mutual_friend_link = $sMutFriendTxt . $sNbMutFriend;
         }
         $this->view->mail_link = $sMailLink;
         $this->view->messenger_link = $sMessengerLink;
         $this->view->befriend_link = $sBefriendLink;
         // Set parameters Google Map
         $oMap = new Map();
         $oMap->setCenter($sCity . ' ' . $sState . ' ' . t($sCountry));
         $oMap->setSize('600px', '300px');
         $oMap->setDivId('profileMap');
         $oMap->setZoom(12);
         $oMap->addMarkerByAddress($sCity . ' ' . $sState . ' ' . t($sCountry), t('Meet %0% near here!', $this->sUsername));
         $oMap->generate();
         $this->view->map = $oMap->getMap();
         unset($oMap);
         $this->view->id = $this->iProfileId;
         $this->view->username = $this->sUsername;
         $this->view->first_name = $sFirstName;
         $this->view->last_name = $sLastName;
         $this->view->middle_name = $sMiddleName;
         $this->view->sex = $oUser->sex;
         $this->view->match_sex = $oUser->matchSex;
         $this->view->match_sex_search = str_replace(array('[code]', ','), '&amp;sex%5B%5D=', '[code]' . $oUser->matchSex);
         $this->view->age = $iAge;
         $this->view->country = t($sCountry);
         $this->view->country_code = $sCountry;
         $this->view->city = $sCity;
         $this->view->state = $sState;
         $this->view->description = nl2br($sDescription);
         $this->view->join_date = VDate::textTimeStamp($oUser->joinDate);
         $this->view->last_activity = VDate::textTimeStamp($oUser->lastActivity);
         $this->view->fields = $oFields;
         $this->view->is_logged = $this->sUserAuth;
         $this->view->is_himself_profile = $this->str->equals($this->iVisitorId, $this->iProfileId);
         // Stat Profile
         Statistic::setView($this->iProfileId, 'Members');
     } else {
         $this->_notFound();
     }
     $this->output();
 }