PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Controllers
<?php namespace WilokeListingTools\Controllers; use WilokeListingTools\Controllers\Retrieve\AjaxRetrieve; use WilokeListingTools\Controllers\Retrieve\NormalRetrieve; use WilokeListingTools\Framework\Helpers\GetSettings; use WilokeListingTools\Framework\Helpers\GetWilokeSubmission; use WilokeListingTools\Framework\Helpers\SetSettings; use WilokeListingTools\Framework\Helpers\UserSkeleton; use WilokeListingTools\Framework\Routing\Controller; use WilokeListingTools\Frontend\User; use WilokeListingTools\Models\InvoiceModel; use WilokeListingTools\Models\PaymentMetaModel; use WilokeListingTools\Models\PaymentModel; use WilokeListingTools\Models\PlanRelationshipModel; use WilokeListingTools\Models\RemainingItems; use WilokeListingTools\Models\UserModel; use WilokeListingTools\Framework\Helpers\Validation as ValidationHelper; class UserController extends Controller { public $limit = 4; private $oRetrieve; public function __construct() { add_action('wilcity/header/after-menu', [$this, 'printRegisterLoginButton'], 20); add_action('wp_ajax_wilcity_fetch_user_profile', [$this, 'fetchUserProfile']); add_action('admin_init', [$this, 'addCaps']); add_action('ajax_query_attachments_args', [$this, 'mediaAccess']); add_action('wp_ajax_signin_firebase', [$this, 'signinFirebase']); add_filter('manage_users_columns', [$this, 'registerAddlistingLockedColumn']); add_filter('manage_users_custom_column', [$this, 'showUpLockedUserReasonOnUserRow'], 10, 3); add_action('wp_ajax_wilcity_fetch_my_billings', [$this, 'fetchBillings']); add_action('wp_ajax_wilcity_fetch_my_billing_details', [$this, 'fetchBillingDetails']); add_action('wp_ajax_wilcity_fetch_my_plan', [$this, 'fetchMyPlan']); add_action('wp_enqueue_scripts', [$this, 'printLoginConfiguration']); add_action('wp_ajax_nopriv_wilcity_login', [$this, 'handleLogin']); add_action('wp_ajax_nopriv_wilcity_register', [$this, 'handleRegister']); add_action('wp_ajax_nopriv_wilcity_reset_password', [$this, 'ajaxResetPassword']); add_action('wp_ajax_user_short_info', [$this, 'fetchUserShortInfo']); add_action('wp_ajax_wilcity_fetch_profile_fields', [$this, 'fetchProfileFields']); add_action('wp_ajax_wilcity_fetch_delete_account_fields', [$this, 'fetchDeleteAccountFields']); add_action('wp_ajax_wilcity_update_profile', [$this, 'updateProfile']); add_action('wp_ajax_wilcity_delete_account', [$this, 'deleteAccount']); add_action('wp_ajax_wilcity_is_customer_confirmed', [$this, 'checkIsUserConfirmed']); add_action('rest_api_init', function () { $this->registerRestRouters(); }); add_action('wilcity/after/created-account', [$this, 'maybeSetAccountToConfirmed'], 10); } public function maybeSetAccountToConfirmed($userID) { if (\WilokeThemeOptions::isEnable('toggle_confirmation')) { SetSettings::setUserMeta($userID, 'confirmed', 1); } } public function fetchDeleteAccountFields() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); if (!\WilokeThemeOptions::isEnable('toggle_allow_customer_delete_account')) { $oRetrieve->error([]); } $aSections = [ 'heading' => esc_html__('Permanently Delete Account', 'wiloke-listing-tools'), 'translation' => 'permanentlyDeleteAccount', 'icon' => 'la la-user-times', 'warning' => \WilokeThemeOptions::getOptionDetail('customer_delete_account_warning') ]; $oRetrieve->success($aSections); } public function fetchProfileFields() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $userID = get_current_user_id(); $aBasicInfo = []; $oUserData = get_userdata($userID); $aBasicInfo[] = [ 'value' => $oUserData->first_name, 'type' => 'wil-input', 'key' => 'first_name', 'isRequired' => 'yes', 'label' => esc_html__('First Name', 'wiloke-listing-tools') ]; $aBasicInfo[] = [ 'value' => $oUserData->last_name, 'type' => 'wil-input', 'key' => 'last_name', 'isRequired' => 'yes', 'label' => esc_html__('Last Name', 'wiloke-listing-tools') ]; $aBasicInfo[] = [ 'value' => $oUserData->display_name, 'type' => 'wil-input', 'key' => 'display_name', 'isRequired' => 'yes', 'label' => esc_html__('Display Name', 'wiloke-listing-tools') ]; $avatar = GetSettings::getUserMeta($userID, 'avatar'); $avatarID = GetSettings::getUserMeta($userID, 'avatar_id'); $aBasicInfo[] = [ 'value' => !empty($avatar) ? ['src' => $avatar, 'fileName' => esc_html__('Avatar', 'wiloke-listing-tools'), 'id' => $avatarID] : [], 'type' => 'wil-uploader', 'key' => 'avatar', 'maximum' => 1, 'label' => esc_html__('Avatar', 'wiloke-listing-tools') ]; $coverImg = GetSettings::getUserMeta($userID, 'cover_image'); $coverImgID = GetSettings::getUserMeta($userID, 'cover_image_id'); $aBasicInfo[] = [ 'value' => empty($coverImg) ? [] : [ 'src' => $coverImg, 'fileName' => esc_html__('Cover Image', 'wiloke-listing-tools'), 'id' => $coverImgID ], 'type' => 'wil-uploader', 'key' => 'cover_image', 'maximum' => 1, 'label' => esc_html__('Cover Image', 'wiloke-listing-tools') ]; $aBasicInfo[] = [ 'type' => 'wil-input', 'inputChild' => 'email', 'key' => 'email', 'isRequired' => 'yes', 'value' => $oUserData->user_email, 'label' => esc_html__('Email', 'wiloke-listing-tools') ]; $aBasicInfo[] = [ 'type' => 'wil-input', 'key' => 'position', 'value' => GetSettings::getUserMeta($userID, 'position'), 'label' => esc_html__('Position', 'wiloke-listing-tools') ]; $aBasicInfo[] = [ 'value' => get_the_author_meta('user_description', $userID), 'type' => 'wil-textarea', 'key' => 'description', 'label' => esc_html__('Introduce your self', 'wiloke-listing-tools') ]; $aBasicInfo[] = [ 'value' => GetSettings::getUserMeta($userID, 'send_email_if_reply_message'), 'type' => 'wil-checkbox', 'key' => 'send_email_if_reply_message', 'label' => esc_html__('Receive message through email.', 'wiloke-listing-tools') ]; $aBasicInfo = apply_filters('wilcity/wiloke-listing-tools/filter/profile-controllers/basic-info', $aBasicInfo); $aFollowContact = []; $aFollowContact[] = [ 'type' => 'wil-input', 'key' => 'address', 'value' => GetSettings::getUserMeta($userID, 'address'), 'label' => esc_html__('Address', 'wiloke-listing-tools') ]; $aFollowContact[] = [ 'type' => 'wil-input', 'key' => 'phone', 'value' => GetSettings::getUserMeta($userID, 'phone'), 'label' => esc_html__('Phone', 'wiloke-listing-tools') ]; $aFollowContact[] = [ 'type' => 'wil-input', 'key' => 'website', 'value' => User::getWebsite($userID), 'label' => esc_html__('Website', 'wiloke-listing-tools') ]; $aRawSocialNetworks = GetSettings::getUserMeta($userID, 'social_networks'); $aSocialNetworks = []; if (!empty($aRawSocialNetworks)) { foreach ($aRawSocialNetworks as $social => $socialUrl) { if (!empty($socialUrl)) { $aSocialNetworks[] = [ 'icon' => '', 'id' => $social, 'label' => ucfirst($social), 'value' => $socialUrl ]; } } } $aFollowContact[] = [ 'type' => 'wil-pickup-and-set', 'key' => 'social_networks', 'label' => esc_html__('Social Networks', 'wiloke-listing-tools'), 'value' => $aSocialNetworks, 'pickupOptions' => \WilokeSocialNetworks::getPickupSocialOptions() ]; $aFollowContact = apply_filters( 'wilcity/wiloke-listing-tools/filter/profile-controllers/follow-contact', $aFollowContact ); $aChangePassword = [ [ 'type' => 'wil-input', 'key' => 'currentPassword', 'inputType' => 'password', 'label' => esc_html__('Current Password', 'wiloke-listing-tools'), 'translation' => 'currentPassword', 'value' => '' ], [ 'type' => 'wil-input', 'key' => 'newPassword', 'inputType' => 'password', 'label' => esc_html__('New Password', 'wiloke-listing-tools'), 'translation' => 'newPassword', 'value' => '' ], [ 'type' => 'wil-input', 'key' => 'confirmNewPassword', 'inputType' => 'password', 'label' => esc_html__('Confirm New Password', 'wiloke-listing-tools'), 'translation' => 'confirmNewPassword', 'value' => '' ] ]; $aSections = [ [ 'heading' => 'Basic Info', 'translation' => 'basicInfo', 'key' => 'basic-info', 'fields' => $aBasicInfo ], [ 'heading' => 'Follow & Contact', 'translation' => 'followAndContact', 'icon' => 'la la-user-plus', 'key' => 'follow-and-contact', 'fields' => $aFollowContact ], [ 'heading' => 'Change Password', 'translation' => 'changePassword', 'icon' => 'la la-exchange', 'key' => 'change-password', 'fields' => $aChangePassword ] ]; $oRetrieve->success($aSections); } public function registerRestRouters() { // register_rest_route('wiloke/v2', '/users/my-info', [ // 'methods' => 'GET', // 'callback' => [$this, 'fetchMyInfo'] // ]); } public function printRegisterLoginButton() { if (GetWilokeSubmission::isEnable('toggle')) : ?> <div id="wil-login-register-controller"></div> <?php endif; } public function printLoginConfiguration() { if (\WilokeThemeOptions::isEnable('toggle_custom_login_page')) { $mode = 'custom'; $loginPageURL = GetSettings::getCustomLoginPage(); } else { $mode = 'popup'; $loginPageURL = ''; } if (\WilokeThemeOptions::getOptionDetail('login_redirect_type') == 'self_page') { $redirectTo = get_permalink(\WilokeThemeOptions::getOptionDetail('login_redirect_to')); if (empty($redirectTo)) { $redirectTo = home_url('/'); } $redirectTo = apply_filters('wilcity/filter/custom_login_page_url', $redirectTo); } else { global $wp; $redirectTo = add_query_arg($wp->request, home_url('/')); $loginPageURL = add_query_arg( ['redirect_to' => urlencode($redirectTo)], $loginPageURL ); } $aGoogleReCaptcha = []; if ( \WilokeThemeOptions::isEnable('toggle_google_recaptcha') && !empty(\WilokeThemeOptions::getOptionDetail('recaptcha_site_key')) ) { $aGoogleReCaptcha['siteKey'] = \WilokeThemeOptions::getOptionDetail('recaptcha_site_key'); $aGoogleReCaptcha['on'] = \WilokeThemeOptions::getOptionDetail('using_google_recaptcha_on'); } $aRegisterFormFields = wilokeListingToolsRepository()->get('register-login:registerFormFields'); if (\WilokeThemeOptions::isEnable('toggle_privacy_policy')) { $aRegisterFormFields[] = [ 'type' => 'wil-checkbox', 'name' => 'isAgreeToPrivacyPolicy', 'label' => \WilokeThemeOptions::getOptionDetail('privacy_policy_desc'), ]; } if (\WilokeThemeOptions::isEnable('toggle_terms_and_conditionals')) { $aRegisterFormFields[] = [ 'type' => 'wil-checkbox', 'name' => 'isAgreeToTermsAndConditionals', 'label' => \WilokeThemeOptions::getOptionDetail('terms_and_conditionals_desc'), ]; } $aSocialsLogin = []; if (\WilokeThemeOptions::isEnable('fb_toggle_login')) { $_SESSION['fbCSRF'] = wp_create_nonce('fbCSRF'); $aSocialsLogin[] = [ 'social' => 'facebook', 'configs' => [ 'API' => \WilokeThemeOptions::getOptionDetail('fb_api_id'), 'fbState' => $_SESSION['fbCSRF'], 'redirectTo' => home_url('/') ] ]; } wp_localize_script('jquery-migrate', 'WIL_REGISTER_LOGIN', [ 'mode' => $mode, 'allowRegister' => GetSettings::userCanRegister() && \WilokeThemeOptions::isEnable('toggle_register') ? 'yes' : 'no', 'customLoginPageUrl' => $loginPageURL, 'loggedInRedirectTo' => $redirectTo, 'registerFormFields' => $aRegisterFormFields, 'googleReCaptcha' => $aGoogleReCaptcha, 'socialsLogin' => apply_filters( 'wilcity/wiloke-listing-tools/app/Controllers/UserController/printLoginConfiguration', $aSocialsLogin ) ]); } public function fetchUserShortInfo() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); if (!isset($_GET['userId']) || empty($_GET['userId'])) { $userID = get_current_user_id(); } else { $userID = $_GET['userId']; } $userID = abs($userID); $pluck = isset($_GET['pluck']) ? $_GET['pluck'] : 'avatar,displayName'; $oUserSkeleton = new UserSkeleton($userID); $aInfo = $oUserSkeleton->pluck($pluck); $oRetrieve->success($aInfo); } public function fetchMyPlan() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $aRawUserPlans = PaymentModel::getPaymentSessionsOfUser(User::getCurrentUserID(), ['active', 'succeeded']); if (empty($aRawUserPlans)) { $oRetrieve->error([ 'msg' => esc_html__('You do not use any plan yet.', 'wiloke-listing-tools') ]); } $aUserPlans = []; $order = 0; foreach ($aRawUserPlans as $oPayment) { $aPaymentInfo = PaymentMetaModel::getPaymentInfo($oPayment->ID); if (!empty($oPayment->planID)) { $planTitle = get_the_title($oPayment->planID); } if (empty($planTitle) && isset($aPaymentInfo['planName'])) { $planTitle = $aPaymentInfo['planName']; } if (empty($planTitle)) { $planTitle = esc_html__('This plan may have been deleted.', 'wiloke-listing-tools'); } $aUserPlans[$order]['planName'] = $planTitle; $aUserPlans[$order]['planID'] = $oPayment->planID; if (GetWilokeSubmission::isNonRecurringPayment($oPayment->billingType)) { $aUserPlans[$order]['nextBillingDate'] = 'X'; } else { $nextBillingDateGMT = PaymentMetaModel::getNextBillingDateGMT($oPayment->ID); if (empty($nextBillingDateGMT)) { $aUserPlans[$order]['nextBillingDate'] = esc_html__('Updating', 'wiloke-listing-tools'); } else { $aUserPlans[$order]['nextBillingDate'] = date_i18n(get_option('date_format'), $nextBillingDateGMT); } } $aUserPlans[$order]['paymentID'] = $oPayment->ID; $aUserPlans[$order]['gateway'] = $oPayment->gateway; if (in_array($aPaymentInfo['category'], ['addlisting', 'paidClaim'])) { $listingID = PlanRelationshipModel::getLastObjectIDByPaymentID($oPayment->ID); $aUserPlans[$order]['postType'] = get_post_type($listingID); } else { $aUserPlans[$order]['postType'] = $aPaymentInfo['category']; } $aUserPlans[$order]['billingType'] = $oPayment->billingType; $aUserPlans[$order]['isNonRecurringPayment'] = GetWilokeSubmission::isNonRecurringPayment($oPayment->billingType) ? 'yes' : 'no'; $aUserPlans[$order]['status'] = $oPayment->status; $aUserPlans[$order]['category'] = $aPaymentInfo['category']; if (in_array($aPaymentInfo['category'], ['addlisting', 'paidClaim'])) { $oRemainingItems = new RemainingItems(); $oRemainingItems->setUserID($oPayment->userID) ->setGateway($oPayment->gateway) ->setPlanID($oPayment->planID) ->setBillingType($oPayment->billingType) ->setPaymentID($oPayment->ID) ; $aUserPlans[$order]['remainingItems'] = $oRemainingItems->getRemainingItems(); } else { $aUserPlans[$order]['remainingItems'] = 'x'; } $order++; } $oRetrieve->success($aUserPlans); } private function updateBasicInfo($aBasicInfo, $userID) { $aUserInfo = []; foreach ($aBasicInfo as $key => $val) { switch ($key) { case 'first_name': case 'last_name': case 'display_name': case 'description': $aUserInfo[$key] = sanitize_text_field($val); break; case 'email': if (!empty($val)) { $currentEmail = User::getField('user_email', $userID); if ($currentEmail != $val) { if (email_exists($val)) { return [ 'status' => 'error', 'msg' => esc_html__('This email is already registered.', 'wiloke-listing-tools') ]; } $aUserInfo['user_email'] = sanitize_email($val); } } break; case 'send_email_if_reply_message': $aUserMeta['send_email_if_reply_message'] = sanitize_text_field($val); break; case 'position': $aUserMeta['position'] = sanitize_text_field($val); break; case 'avatar': case 'cover_image': if (!empty($val)) { if (is_array($val)) { $aUserMeta[sanitize_text_field($key)] = $val['src']; $aUserMeta[sanitize_text_field($key).'_id'] = $val['id']; } else { $aUserMeta[sanitize_text_field($key)] = ValidationHelper::deepValidation($val); } } break; } } if (!empty($aUserInfo)) { $aUserInfo['ID'] = $userID; if (empty($aUserInfo['display_name'])) { $aUserInfo['display_name'] = $aUserInfo['first_name'].' '.$aUserInfo['last_name']; } $userID = wp_update_user((object)$aUserInfo); /** * @hooked WILCITY_APP\Controllers\Firebase\MessageController:updateUserAvatarToMessageFirebase 10 */ do_action('wilcity/wiloke-listing-tools/save-profile-basic-info', $aBasicInfo, $userID); } if (!empty($aUserMeta)) { foreach ($aUserMeta as $metaKey => $val) { SetSettings::setUserMeta($userID, $metaKey, $val); } } if (is_wp_error($userID)) { return [ 'status' => 'error', 'msg' => esc_html__('ERROR: Something went wrong, We could not update your profile.', 'wiloke-listing-tools') ]; } do_action('wilcity/wiloke-listing-tools/after-save-profile-basic-info', $aBasicInfo, $userID); return true; } private function updateFollowAndContact($aFollowAndContact, $userID) { $aUserMeta = []; $aUserInfo = []; foreach ($aFollowAndContact as $key => $val) { switch ($key) { case 'social_networks': foreach ($val as $socialInfo) { if (!empty($socialInfo['value'])) { $aUserMeta['social_networks'][sanitize_text_field($socialInfo['id'])] = sanitize_text_field ($socialInfo['value']); } } break; case 'address': case 'phone': $aUserMeta[$key] = sanitize_text_field($val); break; case 'website': $aUserInfo['user_url'] = sanitize_text_field($val); break; } } if (!empty($aUserMeta)) { foreach ($aUserMeta as $key => $val) { SetSettings::setUserMeta($userID, $key, $val); } } if (!empty($aUserInfo)) { $aUserInfo['ID'] = $userID; $aUserInfo = (object)$aUserInfo; wp_update_user($aUserInfo); } return true; } private function updatePassword($aPassword, $userID) { $oUserData = new \WP_User($userID); if (empty($aPassword['currentPassword']) || !wp_check_password($aPassword['currentPassword'], $oUserData->data->user_pass, $userID) ) { return [ 'status' => 'error', 'msg' => esc_html__('ERROR: Invalid Password.', 'wiloke-listing-tools') ]; } if ($aPassword['newPassword'] !== $aPassword['confirmNewPassword']) { return [ 'status' => 'error', 'msg' => esc_html__('ERROR: The password confirmation must be matched the new password.', 'wiloke-listing-tools') ]; } reset_password($oUserData, $aPassword['newPassword']); do_action('wilcity/user/after_reset_password', $oUserData); return true; } public function checkIsUserConfirmed() { wp_send_json_success(['isConfirmed' => User::isUserConfirmedAccount() ? 'yes' : 'no']); } public function deleteAccount() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); if (!\WilokeThemeOptions::isEnable('toggle_allow_customer_delete_account')) { $oRetrieve->error([ 'msg' => esc_html__('You do not have permission to access this page', 'wiloke-listing-tools') ]); } $oUser = new \WP_User(User::getCurrentUserID()); if (!isset($_POST['current_password']) || empty($_POST['current_password']) || !wp_check_password($_POST['current_password'], $oUser->data->user_pass, $oUser->ID) ) { $oRetrieve->error([ 'msg' => esc_html__('Invalid confirm password.', 'wiloke-listing-tools') ]); } $aPosts = get_posts([ 'numberposts' => -1, 'post_type' => 'any', 'author' => $oUser->ID ]); if (!empty($aPosts)) { foreach ($aPosts as $oPost) { wp_delete_post($oPost->ID, true); }; } wp_delete_user($oUser->ID); $oRetrieve->success([ 'msg' => esc_html__('Your account was successfully deleted. We are sorry to see you go!', 'wiloke-listing-tools'), 'redirectTo' => home_url('/') ]); } public function updateProfile() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $userID = get_current_user_id(); $aStatus = $this->middleware(['isUserLoggedIn'], [ 'userID' => $userID, 'isBoolean' => true ]); if ($aStatus['status'] === 'error') { $oRetrieve->error($aStatus); } if (!isset($_POST['values']) || empty($_POST['values'])) { $oRetrieve->error([ 'msg' => esc_html__('There is nothing change', 'wiloke-listing-tools') ]); } $isChangedPassword = false; $aData = json_decode(stripslashes($_POST['values']), true); if (empty($aData)) { $oRetrieve->error([ 'msg' => esc_html__('Oops! Something went wrong, so We could not update the profile.', 'wiloke-listing-tools') ]); } if (isset($aData['basic-info']) && !empty($aData['basic-info'])) { $aStatus = $this->updateBasicInfo($aData['basic-info'], $userID); if ($aStatus !== true) { $oRetrieve->error($aStatus); } } if (isset($aData['follow-and-contact'])) { $this->updateFollowAndContact($aData['follow-and-contact'], $userID); } if (isset($aData['change-password'])) { if (!empty($aData['change-password']['newPassword']) && !empty($aData['change-password']['confirmNewPassword'])) { $aStatus = $this->updatePassword($aData['change-password'], $userID); if ($aStatus !== true) { $oRetrieve->error($aStatus); } $isChangedPassword = true; } } $aResponse['msg'] = esc_html__('Congratulations! Your profile have been updated', 'wiloke-listing-tools'); if ($isChangedPassword) { $aResponse['redirectTo'] = home_url('/'); } $oRetrieve->success($aResponse); } public function fetchBillingDetails() { $aResult = InvoiceModel::getInvoiceDetails($_GET['invoiceID']); if (empty($aResult)) { wp_send_json_error([ 'msg' => esc_html__('This plan may have been deleted', 'wiloke-listing-tools') ]); } wp_send_json_success($aResult); } public function fetchBillings() { $offset = (abs($_GET['page']) - 1) * $this->limit; $aInvoices = InvoiceModel::getMyInvoices($this->limit, $offset); if (empty($aInvoices)) { if ($_GET['page'] > 1) { wp_send_json_error([ 'reachedMaximum' => 'yes' ]); } else { wp_send_json_error(['msg' => esc_html__('There are no invoices', 'wiloke-listing-tools')]); } } wp_send_json_success($aInvoices); } public function registerAddlistingLockedColumn($aColumns) { $aColumns['addlisting_locked'] = 'Locked Status'; return $aColumns; } public function showUpLockedUserReasonOnUserRow($val, $columnName, $userID) { switch ($columnName) { case 'addlisting_locked': $val = GetSettings::getUserMeta($userID, 'locked_addlisting'); break; } return $val; } public function signinFirebase() { if (!is_user_logged_in()) { wp_send_json_error(); } wp_send_json_success( [ 'email' => User::getField('user_email', get_current_user_id()), 'password' => User::getField('user_pass', get_current_user_id()) ] ); } public function addCaps() { $oContributor = get_role('contributor'); $oContributor->add_cap('upload_files'); if ( class_exists('\WilokeThemeOptions') && \WilokeThemeOptions::getOptionDetail('addlisting_upload_img_via') == 'wp' ) { $oSubscriber = get_role('subscriber'); if (!empty($oSubscriber)) { if (current_user_can('subscriber')) { $oSubscriber->add_cap('upload_files'); } else { $oSubscriber->remove_cap('upload_files'); } } } } public function mediaAccess($aArgs) { $userID = User::getCurrentUserID(); if (!empty($userID) && class_exists('\WilokeThemeOptions')) { if ( \WilokeThemeOptions::isEnable( 'user_admin_access_all_media', true ) && User::currentUserCan('administrator') ) { return $aArgs; } $aArgs['author'] = User::getCurrentUserID(); } return $aArgs; } public function fetchUserProfile() { $this->middleware(['isUserLoggedIn'], []); $userID = get_current_user_id(); $aThemeOptions = \Wiloke::getThemeOptions(); wp_send_json_success([ 'display_name' => User::getField('display_name', $userID), 'avatar' => User::getAvatar($userID), 'position' => User::getPosition($userID), 'profile_description' => isset($aThemeOptions['dashboard_profile_description']) ? $aThemeOptions['dashboard_profile_description'] : '', 'author_url' => get_author_posts_url($userID) ]); } private function verify($aData, $aMiddleware) { $aData['isBoolean'] = true; return $this->middleware( $aMiddleware, $aData ); } public function handleLogin() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $aData = $_POST; $aStatus = $this->verify($aData, ['verifyNonce', 'validateGoogleReCaptcha']); if ($aStatus['status'] === 'error') { $oRetrieve->error($aStatus); } $aData = [ 'user_login' => $_POST['username'], 'user_password' => $_POST['password'], 'remember' => isset($_POST['isRemember']) && $_POST['isRemember'] == 'yes' ]; do_action('wilcity/before/login', $aData); $oUser = wp_signon($aData, is_ssl()); if (is_wp_error($oUser)) { $oRetrieve->error([ 'msg' => esc_html__('ERROR: Invalid username or password', 'wiloke-listing-tools') ]); } $aThemeOption = \Wiloke::getThemeOptions(); $oRetrieve->success([ 'msg' => sprintf( esc_html__('Hi %s! Nice to see you back.', 'wiloke-listing-tools'), $_POST['username'] ), 'redirectTo' => isset($aThemeOption['login_redirect_type']) && $aThemeOption['login_redirect_type'] == 'specify_page' ? urlencode(get_permalink($aThemeOption['login_redirect_to'])) : 'self' ]); } public function handleRegister() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $aData = $_POST; $aStatus = $this->verify($aData, ['canRegister', 'verifyNonce', 'validateGoogleReCaptcha']); if ($aStatus['status'] === 'error') { $oRetrieve->error($aStatus); } if (\WilokeThemeOptions::isEnable('toggle_privacy_policy')) { if (!isset($aData['isAgreeToPrivacyPolicy']) || $aData['isAgreeToPrivacyPolicy'] == 'no') { $oRetrieve->error([ 'msg' => esc_html__( 'ERROR: Sorry, To create an account on our site, you have to agree to our team conditionals and our privacy policy.', 'wiloke-listing-tools' ) ]); } } if (\WilokeThemeOptions::isEnable('toggle_terms_and_conditionals')) { if (!isset($aData['isAgreeToTermsAndConditionals']) || $aData['isAgreeToTermsAndConditionals'] == 'no') { $oRetrieve->error([ 'msg' => esc_html__( 'ERROR: Sorry, To create an account on our site, you have to agree to our team conditionals and our privacy policy.', 'wiloke-listing-tools' ) ]); } } do_action('wilcity/before/register', $aData); if (empty($aData['username']) || empty($aData['email']) || empty($aData['password'])) { $oRetrieve->error([ 'msg' => esc_html__('ERROR: Please complete all required fields.', 'wiloke-listing-tools') ]); } if (!is_email($aData['email'])) { $oRetrieve->error([ 'msg' => esc_html__('ERROR: Invalid email address.', 'wiloke-listing-tools') ]); } if (email_exists($aData['email'])) { $oRetrieve->error([ 'msg' => esc_html__( 'ERROR: An account with this email already exists on the website.', 'wiloke-listing-tools' ) ]); } if (username_exists($aData['username'])) { $oRetrieve->error([ 'msg' => esc_html__( 'ERROR: Sorry, The username is not available. Please with another username.', 'wiloke-listing-tools' ) ]); } if (preg_match('/\s/', $aData['username'], $aSpace)) { $oRetrieve->error([ 'msg' => esc_html__('Please do not use space in the username.', 'wiloke-listing-tools') ]); } $aStatus = UserModel::createNewAccount($aData); if ($aStatus['status'] == 'error') { $oRetrieve->error([ 'msg' => esc_html__('ERROR: Something went wrong', 'wiloke-listing-tools') ]); } if ($aStatus['status'] == 'success' && !$aStatus['isNeedConfirm']) { $successMsg = esc_html__( 'Congratulations! Your account has been created successfully.', 'wiloke-listing-tools' ); } else { $successMsg = $aStatus['msg']; } $ssl = is_ssl() ? true : false; wp_signon([ 'user_login' => $_POST['email'], 'user_password' => $_POST['password'], 'remember' => false ], $ssl); $redirectTo = \WilokeThemeOptions::getOptionDetail('created_account_redirect_to'); $redirectTo = !empty($redirectTo) ? urlencode(get_permalink($redirectTo)) : 'self'; do_action('wilcity/after/created-account', $aStatus['userID'], $aData['username'], $aStatus['isNeedConfirm']); $oRetrieve->success([ 'redirectTo' => $redirectTo, 'msg' => $successMsg ]); } private function resetPassword($aData) { $oRetrieve = new RetrieveController(new NormalRetrieve()); if (empty($aData['username'])) { return $oRetrieve->error([ 'msg' => esc_html__('Please provide your username or email address.', 'wiloke-listing-tools') ]); } else if (strpos($aData['username'], '@')) { $email = trim($aData['username']); $oUserData = get_user_by('email', $email); if (empty($oUserData)) { return $oRetrieve->error([ 'msg' => esc_html__('Sorry, We found no account matched this email.', 'wiloke-listing-tools') ]); } } else { $login = trim($aData['username']); $oUserData = get_user_by('login', $login); if (empty($oUserData)) { return $oRetrieve->error([ 'msg' => esc_html__('Sorry, We found no account matched this username.', 'wiloke-listing-tools') ]); } } $userEmail = $oUserData->user_email; $userLogin = $oUserData->user_login; $key = get_password_reset_key($oUserData); if (is_wp_error($key)) { return $oRetrieve->error([ 'msg' => $key->get_error_message() ]); } $resetPasswordPageID = \WilokeThemeOptions::getOptionDetail('reset_password_page'); if (!empty($resetPasswordPageID) && get_post_status($resetPasswordPageID) == 'publish') { $resetURL = get_permalink($resetPasswordPageID); $resetURL = add_query_arg( [ 'key' => $key, 'login' => rawurlencode($userLogin), 'action' => 'rp' ], $resetURL ); } else { $resetURL = network_site_url("wp-login.php?action=rp&key=$key&login=".rawurlencode($userLogin), 'login'); } $message = esc_html__( 'Someone has requested a password reset for the following account:', 'wiloke-listing-tools' )."\r\n\r\n"; $message .= network_home_url('/')."\r\n\r\n"; $message .= sprintf(__('Username: %s'), $userLogin)."\r\n\r\n"; $message .= esc_html__( 'If this was a mistake, just ignore this email and nothing will happen.', 'wiloke-listing-tools' )."\r\n\r\n"; $message .= esc_html__( 'To reset your password, visit the following address:', 'wiloke-listing-tools' )."\r\n\r\n"; $message .= '<'.$resetURL.">\r\n"; if (is_multisite()) { $blogname = get_network()->site_name; } else { /* * The blogname option is escaped with esc_html on the way into the database * in sanitize_option we want to reverse this for the plain text arena of emails. */ $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); } /* translators: Password reset email subject. 1: Site name */ $title = sprintf(__('[%s] Password Reset', 'wiloke-listing-tools'), $blogname); if ($message && !wp_mail($userEmail, wp_specialchars_decode($title), $message)) { return $oRetrieve->error( [ 'msg' => __( 'The email could not be sent.', 'wiloke-listing-tools' )."<br />\n". __( 'Possible reason: your host may have disabled the mail() function.', 'wiloke-listing-tools' ) ] ); } $aParseMail = explode('@', $userEmail); $mailDomain = end($aParseMail); $totalLength = count($aParseMail[0]); if ($totalLength > 5) { $truncateIndex = 4; } else { $truncateIndex = $totalLength - 2; } $escapeEmail = substr($aParseMail[0], 0, $truncateIndex).'***'.'@'.$mailDomain; return $oRetrieve->success( [ 'msg' => sprintf(esc_html__( 'We just mailed a reset link to %s. Please check your mail box / spam box and click on that link.', 'wiloke-listing-tools' ), $escapeEmail), 'isFocusHideForm' => true ] ); } public function ajaxResetPassword() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $aData = $_POST; $aStatus = $this->verify($aData, ['verifyNonce']); if ($aStatus['status'] === 'error') { $oRetrieve->error($aStatus); } do_action('wilcity/before/register', $aData); $aStatus = $this->resetPassword($aData); if ($aStatus['status'] === 'error') { $oRetrieve->error($aStatus); } $oRetrieve->success($aStatus); } }
[+]
..
[-] WebhookController.php
[edit]
[-] SetCoupon.php
[edit]
[-] TermController.php
[edit]
[-] PostController.php
[edit]
[-] SetMyPosts.php
[edit]
[-] NotificationsController.php
[edit]
[-] AjaxUploadImgController.php
[edit]
[-] TaxonomiesControllers.php
[edit]
[-] FavoriteStatisticController.php
[edit]
[-] BelongsToCustomTaxonomies.php
[edit]
[-] DashboardController.php
[edit]
[-] ModifyQueryController.php
[edit]
[-] SetCustomGroup.php
[edit]
[+]
Map
[-] TraitHostedBy.php
[edit]
[-] SearchFormController.php
[edit]
[-] InsertFeaturedImg.php
[edit]
[-] PaymentGatewaysController.php
[edit]
[-] PaymentController.php
[edit]
[-] DokanController.php
[edit]
[-] SchemaController.php
[edit]
[-] UserController.php
[edit]
[-] BelongsToLocation.php
[edit]
[-] WooCommerceBookingController.php
[edit]
[-] IsMyPaymentID.php
[edit]
[-] StripeController.php
[edit]
[-] ContactFormController.php
[edit]
[-] AddListingButtonController.php
[edit]
[-] Validation.php
[edit]
[-] GalleryController.php
[edit]
[-] SetListingRelationship.php
[edit]
[-] AddListingController.php
[edit]
[-] MergingSettingValues.php
[edit]
[-] GoogleReCaptchaController.php
[edit]
[-] CouponController.php
[edit]
[-] InvoiceController.php
[edit]
[-] SingleJsonSkeleton.php
[edit]
[-] SingleController.php
[edit]
[-] InsertImg.php
[edit]
[-] EmailController.php
[edit]
[-] BelongsToCategories.php
[edit]
[-] ReviewController.php
[edit]
[-] SetSinglePrice.php
[edit]
[-] PrintSidebarItems.php
[edit]
[-] SetPlanRelationship.php
[edit]
[-] BookingComController.php
[edit]
[-] WooCommerceController.php
[edit]
[-] FacebookLoginController.php
[edit]
[-] EventController.php
[edit]
[-] SetRestaurantMenu.php
[edit]
[-] SetProductsToListing.php
[edit]
[-] UserPlanController.php
[edit]
[-] FollowController.php
[edit]
[+]
Retrieve
[-] SetGeneral.php
[edit]
[-] VerifyPurchaseCode.php
[edit]
[-] PlanRelationshipController.php
[edit]
[-] FreePlanController.php
[edit]
[-] AddBookingComBannerCreator.php
[edit]
[-] ReportController.php
[edit]
[-] RetrieveController.php
[edit]
[-] SetCustomButton.php
[edit]
[-] GetWilokeToolSettings.php
[edit]
[-] PaymentMetaController.php
[edit]
[-] RegisterLoginController.php
[edit]
[-] TermsAndPolicyController.php
[edit]
[-] AppleLoginController.php
[edit]
[-] ChangePlanStatusController.php
[edit]
[-] NextBillingPaymentController.php
[edit]
[-] AddListingPaymentController.php
[edit]
[-] PromotionController.php
[edit]
[-] PrintAddListingSettings.php
[edit]
[-] PayPalExecuteAddListingPayment.php
[edit]
[-] ClaimController.php
[edit]
[-] ViewStatisticController.php
[edit]
[-] SessionController.php
[edit]
[-] SharesStatisticController.php
[edit]
[-] TraitSetEventData.php
[edit]
[-] PrintAddListingFields.php
[edit]
[-] GuardController.php
[edit]
[+]
TransformAddListingData
[-] MessageController.php
[edit]
[-] OptimizeScripts.php
[edit]
[-] InsertLogo.php
[edit]
[-] SetPostDuration.php
[edit]
[-] GridItemController.php
[edit]
[-] SetVideo.php
[edit]
[-] AddMorePhotosVideosController.php
[edit]
[-] TraitAddListingSettings.php
[edit]
[-] InsertGallery.php
[edit]
[-] BillingControllers.php
[edit]
[-] GetSingleImage.php
[edit]
[-] BelongsToTags.php
[edit]
[-] PermalinksController.php
[edit]
[-] RunUpdateDBToLatestVersionController.php
[edit]
[-] SetListingBelongsToPlanID.php
[edit]
[-] NoticeController.php
[edit]
[-] DirectBankTransferController.php
[edit]
[-] SetPriceRange.php
[edit]
[-] TagsBelongsToCatController.php
[edit]
[-] PayPalController.php
[edit]
[-] InsertAddress.php
[edit]
[-] MapListingController.php
[edit]
[-] ListingController.php
[edit]
[-] AuthorPageController.php
[edit]
[-] RestaurantMenuController.php
[edit]
[-] PaymentStatusController.php
[edit]
[-] SetSocialNetworks.php
[edit]
[-] SetCustomSections.php
[edit]
[-] TranslationController.php
[edit]
[-] IconController.php
[edit]
[-] SetGroupData.php
[edit]
[-] SetContactInfo.php
[edit]
[-] ProfileController.php
[edit]
[-] ShareController.php
[edit]
[-] InsertCoverImage.php
[edit]
[-] HandleSubmit.php
[edit]
[-] SetMyRoom.php
[edit]
[-] ModalController.php
[edit]