PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Controllers
<?php namespace WilokeListingTools\Controllers; use WilokeListingTools\Controllers\Retrieve\AjaxRetrieve; use WilokeListingTools\Framework\Helpers\GetSettings; use WilokeListingTools\Framework\Helpers\HTML; use WilokeListingTools\Framework\Helpers\SetSettings; use WilokeListingTools\Framework\Helpers\Time; use WilokeListingTools\Framework\Routing\Controller; use WilokeListingTools\Models\FavoriteStatistic; use WilokeListingTools\Models\ReviewModel; use WilokeListingTools\Models\UserModel; class FavoriteStatisticController extends Controller { public function __construct() { add_action('wp_ajax_wilcity_favorite_statistics', [$this, 'listenAjaxUpdate']); add_action('wp_ajax_nopriv_wilcity_favorite_statistics', [$this, 'listenAjaxUpdate']); add_action('wp_ajax_wilcity_is_my_favorited', [$this, 'checkIsMyFavorite']); add_action('wp_ajax_wilcity_favorites_latest_week', [$this, 'getFavoritesOfLatestWeek']); add_action('wp_ajax_wilcity_fetch_favorites_general', [$this, 'fetchFavoritesGeneral']); add_action('wp_ajax_wilcity_fetch_my_favorites', [$this, 'fetchMyFavorites']); add_action('wp_ajax_wilcity_remove_favorite_from_my_list', [$this, 'removeFavoritesFromMyList']); // add_action('wp_ajax_wilcity_fetch_compare_favorites', array($this, 'fetchComparison')); // add_action('wp_ajax_wilcity_fetch_user_liked', array($this, 'fetchUserLiked')); add_action('rest_api_init', function () { register_rest_route(WILOKE_PREFIX.'/v2', '/users/(?P<userID>\d+)/liked', [ 'methods' => 'GET', 'callback' => [$this, 'getUserLiked'] ]); register_rest_route(WILOKE_PREFIX.'/v2', '/dashboard/(?P<postID>\d+)/compare-favorites', [ 'methods' => 'GET', 'callback' => [$this, 'getCompareFavorites'] ]); }); } public function checkIsMyFavorite() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $aStatus = $this->middleware(['isUserLoggedIn'], [ 'isBoolean' => true ]); if ($aStatus['status'] === 'error') { $oRetrieve->error($aStatus); } $status = UserModel::isMyFavorite($_GET['postID'], false, get_current_user_id()) ? 'yes' : 'no'; $oRetrieve->success(['status' => $status]); } public function getCompareFavorites(\WP_REST_Request $oRequest) { $postID = $oRequest->get_param('postID'); $aComparison = FavoriteStatistic::compare(get_post_field('post_author', $postID), $postID); if ($aComparison['number'] > 1) { $aComparison['text'] = esc_html__('Favorites', 'wiloke-listing-tools'); } else { $aComparison['text'] = esc_html__('Favorite', 'wiloke-listing-tools'); } return ['data' => $aComparison]; } public function removeFavoritesFromMyList() { $aRawFavorites = GetSettings::getUserMeta(get_current_user_id(), 'my_favorites'); array_splice($aRawFavorites, $_POST['id'], 1); SetSettings::setUserMeta(get_current_user_id(), 'my_favorites', $aRawFavorites); } public static function getFavoritesByPage($aRawFavorites, $page) { $limit = 20; $offset = $limit * $page; $total = count($aRawFavorites); $aRawFavorites = array_reverse($aRawFavorites); $aFavorites = array_splice($aRawFavorites, $offset, $limit); if (empty($aFavorites)) { return [ 'reachedMaximum' => 'yes' ]; } $aListings = []; foreach ($aFavorites as $id => $postID) { if (get_post_status($postID) != 'publish') { unset($aFavorites[$id]); continue; } $aData = [ 'postID' => abs($postID), 'order' => $id, 'permalink' => get_permalink($postID), 'title' => get_the_title($postID), 'tagLine' => GetSettings::getTagLine($postID, true), 'featuredImage' => GetSettings::getFeaturedImg($postID, 'thumbnail'), 'address' => GetSettings::getAddress($postID, false), 'mapPage' => GetSettings::getAddress($postID, true) ]; if (get_post_type($postID) == 'post') { $oRawCat = GetSettings::getLastPostTerm($postID, 'category'); if ($oRawCat) { $aData['oCategory'] = [ 'link' => get_term_link($oRawCat->term_id), 'name' => $oRawCat->name, 'oIcon' => 'no' ]; } } else { $oRawCat = GetSettings::getLastPostTerm($postID, 'listing_cat'); if ($oRawCat) { $aData['oCategory'] = [ 'link' => get_term_link($oRawCat->term_id), 'name' => $oRawCat->name, 'oIcon' => \WilokeHelpers::getTermOriginalIcon($oRawCat) ]; } } if (!isset($aData['oCategory'])) { $aData['oCategory'] = 'no'; } $aListings[] = $aData; } return [ 'aInfo' => $aListings, 'total' => $total, 'maxPages' => ceil($total / $limit) ]; } public function fetchMyFavorites() { $aRawFavorites = GetSettings::getUserMeta(get_current_user_id(), 'my_favorites'); if (empty($aRawFavorites)) { wp_send_json_error([ 'msg' => esc_html__('There are no favorites', 'wiloke-listing-tools') ]); } $page = isset($_POST['page']) ? abs($_POST['page']) - 1 : 0; $aResult = self::getFavoritesByPage($aRawFavorites, $page); if (isset($aResult['reachedMaximum'])) { wp_send_json_error($aResult); } wp_send_json_success($aResult); } public function fetchFavoritesGeneral() { $this->middleware(['isUserLoggedIn'], []); $userID = get_current_user_id(); $aCompareFavorites = FavoriteStatistic::compare($userID); wp_send_json_success( [ 'totalFavorites' => $aCompareFavorites['total'], 'oChanging' => [ 'number' => $aCompareFavorites['number'], 'description' => esc_html__('Compared to the last week', 'wiloke-listing-tools'), 'title' => esc_html__('Favorites', 'wiloke-listing-tools'), 'status' => $aCompareFavorites['status'], 'is' => $aCompareFavorites['is'] ] ] ); } public function getFavoritesOfLatestWeek() { $this->middleware(['isUserLoggedIn'], []); $aDateInThisWeek = Time::getAllDaysInThis(); $aCountViewsOfWeek = []; $userID = get_current_user_id(); foreach ($aDateInThisWeek as $date) { $aCountViewsOfWeek[] = FavoriteStatistic::getTotalFavoritesOfAuthorInDay($userID, $date); } $aCompare = FavoriteStatistic::compare($userID); wp_send_json_success([ 'data' => $aCountViewsOfWeek, 'total' => $aCompare['total'], 'compare' => [ 'diff' => $aCompare['diff'], 'tooltip' => esc_html__('Compare with the last week', 'wiloke-listing-tools'), 'label' => esc_html__('Favorites Statistic', 'wiloke-listing-tools'), 'status' => $aCompare['status'], 'representColor' => $aCompare['representColor'] ] ]); } public static function getFavorites($postID, $isRestyleText = false) { $today = Time::mysqlDate(\time()); $countViewsToday = FavoriteStatistic::getTotalFavoritesOfAuthorInDay(get_current_user_id(), $today); $countViews = FavoriteStatistic::countFavorites($postID); if (empty($countViews)) { return !$isRestyleText ? $countViewsToday : HTML::reStyleText($countViews); } $totalViewed = $countViewsToday + abs($countViews); return !$isRestyleText ? $totalViewed : HTML::reStyleText($totalViewed); } public function fetchUserLiked() { $userID = get_current_user_id(); $aLiked = GetSettings::getUserMeta($userID, 'my_favorites'); if (empty($aLiked)) { wp_send_json_error(); } else { wp_send_json_success($aLiked); } } public function getUserLiked($oInfo) { $aError = [ 'error' => [ 'internalMessage' => 'User does not exist', 'status' => 404 ] ]; $userID = $oInfo->get_param('userID'); if (empty($userID)) { return $aError; } $aLiked = GetSettings::getUserMeta($userID, 'my_favorites'); if (empty($aLiked)) { $aError['error']['internalMessage'] = 'No Like'; return $aError; } return ['data' => $aLiked]; } public static function update($postID, $userID = '') { $countFavorites = GetSettings::getPostMeta($postID, 'count_favorites'); $countFavorites = empty($countFavorites) ? 0 : abs($countFavorites); $userID = empty($userID) ? get_current_user_id() : $userID; if (empty($userID)) { return false; } $aFavorites = GetSettings::getUserMeta($userID, 'my_favorites'); if (empty($aFavorites)) { SetSettings::setUserMeta($userID, 'my_favorites', [$postID]); $countFavorites++; $is = 'added'; $isPlus = true; } else { if (in_array($postID, $aFavorites)) { $key = array_search($postID, $aFavorites); unset($aFavorites[$key]); if (empty($aFavorites)) { SetSettings::deleteUserMeta($userID, 'my_favorites'); } else { SetSettings::setUserMeta($userID, 'my_favorites', $aFavorites); } $countFavorites--; $is = 'removed'; $isPlus = false; } else { $countFavorites++; $aFavorites[] = $postID; SetSettings::setUserMeta($userID, 'my_favorites', $aFavorites); $is = 'added'; $isPlus = true; } } FavoriteStatistic::update($postID, $isPlus); SetSettings::setPostMeta($postID, 'count_favorites', $countFavorites); return $is; } public function listenAjaxUpdate() { $this->middleware(['isUserLoggedIn', 'isPublishedPost', 'isThemeOptionSupport'], [ 'postID' => $_POST['postID'], 'feature' => 'listing_toggle_favorite' ]); $postID = abs($_POST['postID']); $is = self::update($postID); wp_send_json_success($is); } }
[+]
..
[-] 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]