PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Framework
/
Helpers
<?php namespace WilokeListingTools\Framework\Helpers; use WilokeThemeOptions; class QueryHelper { protected static $aTaxonomies; private static $oSearchFormSkeleton; private static $aCustomDropdownKeys; protected static $aEventFilterBy = [ 'upcoming_event', 'happening_event', 'ongoing_event', 'starts_from_ongoing_event' ]; public static function getEventOrderBy($isCustomQuery = false) { $orderBy = WilokeThemeOptions::getOptionDetail('event_search_page_order_by'); if (empty($orderBy)) { return 'wilcity_event_starts_on'; } if ($orderBy !== 'menu_order') { return $orderBy; } $orderByFallback = WilokeThemeOptions::getOptionDetail('event_search_page_order_by_fallback'); if (empty($orderByFallback)) { return $orderBy; } return $isCustomQuery ? $orderBy.','.$orderByFallback : $orderBy.' '.$orderByFallback; } public static function convertTermQueryToSearchOption($taxonomy, $val) { if (empty($val)) { return ''; } $aTerms = is_array($val) ? $val : explode(',', $val); $aResults = []; foreach ($aTerms as $term) { $name = TermSetting::getTermField($term, $taxonomy, 'name'); if (!empty($name)) { $aResults[] = [ 'label' => $name, 'id' => abs(TermSetting::getTermField($term, $taxonomy, 'term_id')) ]; } } return $aResults; } public static function buildUrl($url, $aArgs) { $aQuery = []; foreach ($aArgs as $key => $val) { if (is_array($val)) { $val = json_encode($val); } $aQuery[$key] = $val; } return add_query_arg($aQuery, $url); } public static function buildSearchPageURL($aArgs) { $searchPageID = WilokeThemeOptions::getOptionDetail('search_page'); if (empty($searchPageID)) { return ''; } $searchURL = get_permalink($searchPageID); return self::buildUrl($searchURL, $aArgs); } protected static function getTaxQuery($aRequest, $taxonomy, $logic = 'AND') { if (!isset($aRequest[$taxonomy]) || empty($aRequest[$taxonomy]) || $aRequest[$taxonomy] == -1) { return []; } if (Validation::isValidJson($aRequest[$taxonomy])) { $aParseTax = Validation::getJsonDecoded(); if (empty($aParseTax)) { return []; } } else { $aParseTax = $aRequest[$taxonomy]; } $aParseTax = is_array($aParseTax) ? $aParseTax : explode(',', $aParseTax); if (is_array($aParseTax)) { $fieldType = is_numeric($aParseTax[0]) ? 'term_id' : 'slug'; } else { $fieldType = is_numeric($aParseTax) ? 'term_id' : 'slug'; } $aArgs = [ 'taxonomy' => $taxonomy, 'field' => $fieldType, 'terms' => $aParseTax ]; // if (is_array($aParseTax) && count($aParseTax) > 1) { // $aArgs['relation'] = $logic; // } return $aArgs; } protected static function buildTaxQuery($aRequest) { if (isset($aRequest['tax_query']) && !empty($aRequest['tax_query'])) { if (Validation::isValidJson($aRequest['tax_query'])) { return Validation::getJsonDecoded(); } return $aRequest['tax_query']; } if (empty(self::$aTaxonomies)) { $aCustomTerms = TermSetting::getCustomListingTaxonomies(); if (is_array($aCustomTerms)) { self::$aTaxonomies = array_keys($aCustomTerms); self::$aTaxonomies = array_merge(self::$aTaxonomies, ['listing_location', 'listing_cat', 'listing_tag']); } } $aArgs = []; foreach (self::$aTaxonomies as $taxonomy) { $termLogic = apply_filters('wilcity/wiloke-listing-tools/filter/multi-tax-logic', 'AND', $taxonomy, self::$aTaxonomies, $aRequest); $aTaxQuery = self::getTaxQuery($aRequest, $taxonomy, $termLogic); if (!empty($aTaxQuery)) { $aArgs[] = $aTaxQuery; } } if (!empty($aArgs) && count($aArgs) > 1) { $aArgs['relation'] = apply_filters('wilcity/wiloke-listing-tools/filter/tax-query-logic', 'AND'); } return $aArgs; } private static function getCustomDropdownKeys($postType) { if (empty(self::$oSearchFormSkeleton)) { self::$oSearchFormSkeleton = new SearchFormSkeleton($postType); } return self::$oSearchFormSkeleton->getCustomDropdownKeys(); } private static function getCustomTaxonomiesKeys($postType) { if (empty(self::$oSearchFormSkeleton)) { self::$oSearchFormSkeleton = new SearchFormSkeleton($postType); } return self::$oSearchFormSkeleton->getCustomTaxonomiesKeys(); } private static function generateMetaKey($metaKey) { return strpos($metaKey, 'wilcity_custom_') === false ? 'wilcity_custom_'.$metaKey : $metaKey; } public static function buildQueryArgs($aRequest) { if (is_array($aRequest)) { foreach ($aRequest as $key => $val) { unset($aRequest[$key]); $aRequest[str_replace('--', '_', $key)] = $val; } } if (!isset($aRequest['postType'])) { if (isset($aRequest['post_type'])) { $aRequest['postType'] = $aRequest['post_type']; } elseif (isset($aRequest['type'])) { $aRequest['postType'] = $aRequest['type']; } else { $aRequest['postType'] = General::getFirstPostTypeKey(false, false); } } $isMap = !isset($aRequest['is_map']) ? 'no' : $aRequest['is_map']; $aArgs = [ 'post_type' => $aRequest['postType'], 'post_status' => 'publish', 'is_map' => $isMap ]; $search = ''; if (isset($aRequest['s'])) { $search = $aRequest['s']; } else if (isset($aRequest['keyword'])) { $search = $aRequest['keyword']; } else if (isset($aRequest['wp_search'])) { $search = $aRequest['wp_search']; } // if (isset($aRequest['match']) && !empty($aRequest['match'])) { // $aArgs['match'] = $aRequest['match']; // unset($aRequest['match']); // } elseif (!empty($search)) { // $aArgs['match'] = [ // 'relation' => 'OR', // 'params' => [ // [ // 'match' => 'post_title, post_content', // 'against' => $search // ] // ] // ]; // } $aArgs['s'] = $search; if ($aRequest['postType'] == 'event') { if (isset($aRequest['event_filter'])) { if ($aRequest['event_filter'] !== 'pick_a_date_event') { unset($aRequest['date_range']); } } } // resolved old event setting if (isset($aRequest['orderby']) && in_array($aRequest['orderby'], self::$aEventFilterBy)) { $aRequest['orderby'] = 'wilcity_event_starts_on'; $aArgs['event_filter'] = $aRequest['orderby']; } if (!isset($aRequest['orderby']) || empty($aRequest['orderby'])) { if ($aRequest['postType'] === 'event') { $orderBy = self::getEventOrderBy(); if (isset($aRequest['order']) && !empty($aRequest['order'])) { $order = trim($aRequest['order']); } else { $order = WilokeThemeOptions::getOptionDetail('event_search_page_order'); } } else { $aDirectoryTypes = General::getPostTypeKeys(false, true); $isListingPostType = is_string($aRequest['postType']) && in_array($aRequest['postType'], $aDirectoryTypes) || is_array($aRequest['postType']) && empty(array_diff($aRequest['postType'], $aDirectoryTypes)); if ($isListingPostType) { $orderBy = WilokeThemeOptions::getOptionDetail('listing_search_page_order_by'); if (empty($orderBy)) { $orderBy = 'menu_order post_date'; $order = 'DESC'; } else { $orderBy = $orderBy == 'menu_order' ? $orderBy.' '.WilokeThemeOptions::getOptionDetail('listing_search_page_order_by_fallback') : $orderBy; $order = WilokeThemeOptions::getOptionDetail('listing_search_page_order'); } } else { $aArgs['order'] = 'DESC'; $aArgs['orderby'] = 'post_date'; } } $aArgs['order'] = $order; $aArgs['orderby'] = $orderBy; } else { $aArgs['order'] = $aRequest['order']; if ($aRequest['orderby'] === 'newest') { $aArgs['orderby'] = 'post_date'; $aArgs['order'] = 'DESC'; } else { $aArgs['orderby'] = $aRequest['orderby']; } } if ($aArgs['orderby'] == 'rand' && isset($aRequest['postsNotIn']) && is_array($aRequest['postsNotIn'])) { $aArgs['post__not_in'] = $aRequest['postsNotIn']; } if (isset($aRequest['aBounds']) && !empty($aRequest['aBounds'])) { unset($aRequest['oAddress']); $aArgs['map_bounds'] = $aRequest['aBounds']; } else if (isset($aRequest['map_bounds']) && !empty($aRequest['map_bounds'])) { unset($aRequest['oAddress']); $aArgs['map_bounds'] = $aRequest['map_bounds']; } if (isset($aRequest['oAddress']) && !empty($aRequest['oAddress'])) { if (is_string($aRequest['oAddress'])) { $aRequest['oAddress'] = json_decode($aRequest['oAddress'], true); } $aArgs['order'] = 'ASC'; if (isset($aRequest['oAddress']['radius'])) { $radius = abs($aRequest['oAddress']['radius']); } elseif (GetSettings::getSearchFormField($aRequest['postType'], 'defaultRadius')) { $radius = GetSettings::getSearchFormField($aRequest['postType'], 'defaultRadius'); } else { $radius = WilokeThemeOptions::getOptionDetail('default_radius'); } if (isset($aRequest['oAddress']['unit'])) { $unit = $aRequest['oAddress']['unit']; } elseif (GetSettings::getSearchFormField($aRequest['postType'], 'unit')) { $unit = GetSettings::getSearchFormField($aRequest['postType'], 'unit'); } else { $unit = WilokeThemeOptions::getOptionDetail('unit_of_distance'); } $aArgs['geocode'] = [ 'latLng' => $aRequest['oAddress']['lat'].','.$aRequest['oAddress']['lng'], 'radius' => $radius, 'unit' => empty($unit) ? 'km' : $unit ]; } if (isset($aRequest['open_now']) && !empty($aRequest['open_now']) && $aRequest['open_now'] !== 'no') { $aArgs['open_now'] = $aRequest['open_now']; } if (isset($aRequest['date_range'])) { // temporary fix if (strpos($aRequest['date_range'], '[') !== false) { $aRequest['date_range'] = str_replace(['[', ']'], ['', ''], $aRequest['date_range']); $aRequest['date_range'] = explode(',', $aRequest['date_range']); } if (isset($aRequest['date_range']['from'])) { $aArgs['date_range'] = [ 'from' => $aRequest['date_range']['from'], 'to' => $aRequest['date_range']['to'] ]; } else { $aArgs['date_range'] = [ 'from' => $aRequest['date_range'][0], 'to' => $aRequest['date_range'][1] ]; } } $aTaxQuery = self::buildTaxQuery($aRequest); if (!empty($aTaxQuery)) { $aArgs['tax_query'] = $aTaxQuery; } if ( isset($aRequest['price_range']) && !empty($aRequest['price_range']) && $aRequest['price_range'] !== 'nottosay' ) { if (Validation::isValidJson($aRequest['price_range'])) { $aPriceRange = Validation::getJsonDecoded(); if (isset($aPriceRange['min'])) { $aPriceRange = Validation::deepValidation($aPriceRange); $aArgs['price_range'] = $aPriceRange; } } else { $aArgs['meta_query'][] = [ [ 'key' => 'wilcity_price_range', 'value' => $aRequest['price_range'], 'compare' => '=' ] ]; } } if (isset($aRequest['claimed']) && $aRequest['claimed'] === 'yes') { $aArgs['meta_query'][] = [ [ 'key' => 'wilcity_claim_status', 'value' => 'claimed', 'compare' => '=' ] ]; } if ((isset($aRequest['discount']) && $aRequest['discount'] === 'yes') || (isset($aRequest['orderby']) && $aRequest['orderby'] === 'discount')) { $aArgs['meta_query'][] = [ [ 'key' => 'wilcity_coupon_expiry', 'value' => time(), 'compare' => '>=' ] ]; if ($aRequest['orderby'] === 'discount') { $aRequest['orderby'] = 'menu_order post_date'; } } if (!isset($aArgs['posts_per_page']) || empty($aArgs['posts_per_page'])) { $aArgs['posts_per_page'] = isset($aRequest['postsPerPage']) && !empty($aRequest['postsPerPage']) ? absint($aRequest['postsPerPage']) : get_option('posts_per_page'); } $aArgs['posts_per_page'] = $aArgs['posts_per_page'] > 200 ? 200 : $aArgs['posts_per_page']; if (isset($aRequest['page']) && !empty($aRequest['page'])) { $aArgs['paged'] = abs($aRequest['page']); } elseif (isset($aRequest['offset']) && !empty($aRequest['offset'])) { $aArgs['paged'] = abs($aRequest['offset']); } if (isset($aRequest['postStatus']) && !empty($aRequest['postStatus'])) { $aArgs['post_status'] = sanitize_text_field($aRequest['postStatus']); } if (isset($aRequest['parentID']) && !empty($aRequest['parentID'])) { $aArgs['post_parent'] = abs($aRequest['parentID']); } switch ($aArgs['orderby']) { case 'recommended': case 'premium_listings': $aArgs['orderby'] = 'menu_order'; $aArgs['order'] = 'DESC'; if (isset($aRequest['TYPE'])) { if ($aRequest['TYPE'] == 'LISTINGS_SLIDER') { $aMetaKey = GetSettings::getPromotionKeyByPosition('listing_slider_sc', true); } else { $aMetaKey = GetSettings::getPromotionKeyByPosition('listing_grid_sc', true); } if (!empty($aMetaKey)) { $aArgs['meta_key'] = $aMetaKey[0]; $aArgs['orderby'] = 'rand menu_order'; } } break; case 'best_viewed': $aArgs['orderby'] = 'meta_value_num'; $aArgs['meta_key'] = 'wilcity_count_viewed'; break; case 'best_shared': $aArgs['orderby'] = 'meta_value_num'; $aArgs['meta_key'] = 'wilcity_count_shared'; break; case 'rating': case 'lowest_rating': case 'best_rated': case 'highest_rating': if ($aRequest['orderby'] === 'highest_rating' || $aRequest['orderby'] === 'best_rated') { $aArgs['order'] = 'DESC'; } else if ($aRequest['orderby'] === 'lowest_rating') { $aArgs['order'] = 'ASC'; } $aArgs['orderby'] = 'meta_value_num'; $aArgs['meta_key'] = 'wilcity_average_reviews'; break; // case 'discount': //// $aArgs['meta_query'][] = [ //// 'key' => '' //// ]; // break; } if (!is_array($aArgs['post_type'])) { $aDropdownKeys = self::getCustomDropdownKeys($aArgs['post_type']); $aRequestKeys = array_keys($aRequest); $aCustomFields = array_intersect($aDropdownKeys, $aRequestKeys); if (!empty($aCustomFields)) { foreach ($aCustomFields as $metaKey) { if (empty($aRequest[$metaKey])) { continue; } if (Validation::isValidJson($aRequest[$metaKey])) { $aMetaValues = Validation::getJsonDecoded(); if (is_array($aMetaValues)) { $aMetaQuery = []; foreach ($aMetaValues as $val) { $aMetaQuery[] = [ 'key' => self::generateMetaKey($metaKey), 'value' => $val, 'compare' => 'LIKE' ]; } if (!empty($aMetaQuery)) { if (count($aMetaQuery) > 1) { $aMetaQuery['relation'] = apply_filters( 'wilcity/wiloke-listing-tools/filter/multi-field-option-logic', 'AND' ); } $aArgs['meta_query'][] = $aMetaQuery; } } } else { $aArgs['meta_query'][] = [ 'key' => self::generateMetaKey($metaKey), 'compare' => 'LIKE', 'value' => $aRequest[$metaKey] ]; } } } } if (isset($aArgs['meta_query']) && count($aArgs['meta_query']) > 1) { $aArgs['meta_query']['relation'] = apply_filters('wilcity/wiloke-listing-tools/filter/multi-metadata-logic', 'AND'); } if (isset($aArgs['s']) && empty($aArgs['s'])) { unset($aArgs['s']); } return apply_filters('wiloke-listing-tools/search-form-controller/query-args', $aArgs, $aRequest); } }
[+]
..
[-] SearchFieldSkeleton.php
[edit]
[-] FileSystem.php
[edit]
[-] Response.php
[edit]
[-] GetWilokeSubmission.php
[edit]
[-] AbstractSkeleton.php
[edit]
[-] InheritCMB2Styles.php
[edit]
[-] ReviewSkeleton.php
[edit]
[-] RestaurantMenu.php
[edit]
[-] WooCommerce.php
[edit]
[-] MapHelpers.php
[edit]
[-] .DS_Store
[edit]
[-] Message.php
[edit]
[-] GetSettings.php
[edit]
[-] QueryHelper.php
[edit]
[+]
Collection
[-] Inc.php
[edit]
[-] UserSkeleton.php
[edit]
[-] Firebase.php
[edit]
[-] Repository.php
[edit]
[-] DebugStatus.php
[edit]
[-] MapFactory.php
[edit]
[-] SetSettings.php
[edit]
[-] AddListingFieldSkeleton.php
[edit]
[-] VideoHelper.php
[edit]
[-] SearchFormSkeleton.php
[edit]
[-] PostSkeleton.php
[edit]
[-] KCHelpers.php
[edit]
[-] ProductSkeleton.php
[edit]
[-] QRCodeGenerator.php
[edit]
[-] HTML.php
[edit]
[-] Time.php
[edit]
[-] PlanHelper.php
[edit]
[-] SemanticUi.php
[edit]
[-] AjaxMsg.php
[edit]
[-] Logger.php
[edit]
[-] Cookie.php
[edit]
[-] Validation.php
[edit]
[-] GalleryHelper.php
[edit]
[-] AuthorSkeleton.php
[edit]
[-] General.php
[edit]
[-] Submission.php
[edit]
[-] TermSetting.php
[edit]