PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Framework
/
Helpers
<?php namespace WilokeListingTools\Framework\Helpers; use WILCITY_SC\SCHelpers; use Wiloke; use WilokeHelpers; use WilokeListingTools\Controllers\ReviewController; use WilokeListingTools\Framework\Helpers\Collection\ArrayCollectionFactory; use WilokeListingTools\Frontend\BusinessHours; use WilokeListingTools\Frontend\SingleListing; use WilokeListingTools\Models\Coupon; use WilokeListingTools\Models\ReviewMetaModel; use WilokeListingTools\Models\UserModel; use WilokeThemeOptions; final class PostSkeleton extends AbstractSkeleton { protected $aAddListingFields; protected $planID = null; private function getAddListingFields() { if (empty($this->aAddListingFields)) { $this->aAddListingFields = GetSettings::getOptions( General::getUsedSectionKey($this->postType, true) ); if (!empty($this->aAddListingFields)) { $this->aAddListingFields = ArrayCollectionFactory::set($this->aAddListingFields)->magicKeyGroup('key')->output(); } } return $this->aAddListingFields; } protected function getReviewCategoriesStatistic(): array { if ($aReviewDetails = $this->getCache('review_details_statistic')) { return $aReviewDetails; } $aStatistic = ReviewMetaModel::getAverageReviewCategories($this->postID); $this->setCache('review_details_statistic', $aStatistic); return $aStatistic; } protected function getAverageRating(): float { return floatval(GetSettings::getAverageRating($this->post->ID)); } protected function getQualityRating(): string { return ReviewMetaModel::getReviewQualityString($this->getAverageRating(), $this->post->post_type); } protected function getModeRating(): int { return GetSettings::getOptions(General::getReviewKey('mode', $this->post->post_type)); } private function isPlanAllowed($key) { if ($this->planID !== null) { $this->planID = GetSettings::getListingBelongsToPlan($this->postID); } if (empty($this->planID)) { return true; } return Submission::isPlanSupported($this->planID, 'toggle_'.$key); } public function getLogo() { return GetSettings::getLogo($this->postID); } public function getExcerpt() { $tagLine = GetSettings::getPostMeta($this->postID, 'tagline'); if (empty($tagLine)) { $tagLine = Wiloke::contentLimit( WilokeThemeOptions::getOptionDetail('listing_excerpt_length'), $this->post, true, $this->post->post_content, true ); $tagLine = strip_shortcodes($tagLine); } return $tagLine; } public function getTagLine() { return $this->getExcerpt(); } public function getOReviews() { $aReviews = []; if (ReviewController::isEnableRating()) { $averageReview = GetSettings::getPostMeta($this->postID, 'average_reviews'); if (empty($averageReview)) { $aReviews = false; } else { $aReviews = []; $aReviews['average'] = floatval($averageReview); $aReviews['mode'] = ReviewController::getMode($this->getPostType()); $aReviews['quality'] = ReviewMetaModel::getReviewQualityString($averageReview, $this->getPostType()); } } return $aReviews; } public function getFeaturedImage() { $imgSize = isset($this->aAtts['img_size']) ? $this->aAtts['img_size'] : 'large'; return GetSettings::getFeaturedImg($this->getID(), $imgSize); } public function getCoupon() { $aCoupon = Coupon::getAllCouponInfo($this->postID); return is_array($aCoupon) ? $aCoupon : []; } public function getOAddress() { $aListingAddress = GetSettings::getListingMapInfo($this->postID); if (!empty($aListingAddress) && !empty($aListingAddress['lat'])) { $mapPageUrl = add_query_arg( [ 'title' => get_the_title($this->postID), 'lat' => $aListingAddress['lat'], 'lng' => $aListingAddress['lng'] ], WilokeThemeOptions::getOptionDetail('map_page') ); $aAddress['mapPageUrl'] = $mapPageUrl; $aAddress['address'] = stripslashes($aListingAddress['address']); $aAddress['addressOnGGMap'] = GetSettings::getAddress($this->postID, true); $aAddress['lat'] = $aListingAddress['lat']; $aAddress['lng'] = $aListingAddress['lng']; $aAddress['marker'] = SingleListing::getMapIcon($this->postID); } else { $aAddress = false; } return $aAddress; } public function getGoogleAddress() { return $this->getOAddress(); } public function getPhone() { return GetSettings::getPostMeta($this->postID, 'phone'); } public function getTaxonomy($taxonomy, $isSingular = false) { $aTerms = []; if ($isSingular) { $oTerm = WilokeHelpers::getTermByPostID($this->post->ID, $taxonomy); if ($oTerm) { $aTerms['name'] = $oTerm->name; $aTerms['link'] = add_query_arg(['postType' => $this->postType], get_term_link($oTerm->term_id)); $aTerms['oIcon'] = WilokeHelpers::getTermOriginalIcon($oTerm); } } else { $aRawTerms = GetSettings::getPostTerms($this->post->ID, $taxonomy); if ($aRawTerms) { foreach ($aRawTerms as $oTerm) { $aTerm = []; $aTerm['name'] = $oTerm->name; $aTerm['link'] = add_query_arg(['postType' => $this->postType], get_term_link($oTerm->term_id)); $aTerm['oIcon'] = WilokeHelpers::getTermOriginalIcon($oTerm); $aTerms[] = $aTerm; } } } return $aTerms; } public function getListingLocation($isSingular = false) { return $this->getTaxonomy('listing_location'); } public function getListingCat($isSingular = false) { return $this->getTaxonomy('listing_cat'); } public function getListingTag($isSingular = false) { return $this->getTaxonomy('listing_tag'); } public function getOTermFooter() { $aFooterSettings = GetSettings::getOptions(General::getSingleListingSettingKey('footer_card', $this->postType)); $taxonomy = isset($aFooterSettings['taxonomy']) ? $aFooterSettings['taxonomy'] : 'listing_cat'; $oTermFooter = WilokeHelpers::getTermByPostID($this->postID, $taxonomy); if (!$oTermFooter) { $aTermFooter = false; } else { $aTermFooter['name'] = $oTermFooter->name; $aTermFooter['link'] = get_term_link($oTermFooter->term_id); $aTermFooter['oIcon'] = WilokeHelpers::getTermOriginalIcon($oTermFooter); } return $aTermFooter; } public function getOBusinessHours() { if (BusinessHours::isEnableBusinessHour($this->postID)) { $aBusinessHours = BusinessHours::getCurrentBusinessHourStatus($this->postID); if ($aBusinessHours['status'] == 'day_off') { $aBusinessHours['class'] = ' color-quaternary'; } } else { $aBusinessHours = false; } return $aBusinessHours; } public function getBusinessHours() { return BusinessHours::getAllBusinessHours($this->postID); } public function getIsMyFavorite() { $userID = isset($this->aAtts['userID']) ? $this->aAtts['userID'] : ''; return UserModel::isMyFavorite($this->postID, false, $userID) ? 'yes' : 'no'; } public function getPrice() { $price = GetSettings::getPostMeta($this->postID, 'single_price'); return empty($price) ? $price : GetWilokeSubmission::renderPrice($price); } public function getSinglePrice() { return $this->getPrice(); } public function getPriceRange() { $aPriceRange = GetSettings::getPriceRange($this->postID, false); if ($aPriceRange) { return GetWilokeSubmission::renderPrice($aPriceRange['minimumPrice']).' - '. GetWilokeSubmission::renderPrice($aPriceRange['maximumPrice']); } return ''; } public function getTotalViews() { return GetSettings::getListingTotalViews($this->postID); } public function getEmail() { return GetSettings::getListingEmail($this->postID); } public function getWebsite() { return GetSettings::getPostMeta($this->postID, 'website'); } public function getIsClaimed() { return SingleListing::isClaimedListing($this->postID, true) ? 'yes' : 'no'; } public function getIsAds() { $adsType = ''; if (isset($this->aAtts['adsType']) && !empty($this->aAtts['adsType'])) { $adsType = $this->aAtts['adsType']; } else { if (isset($this->aAtts['style']) && $this->aAtts['style'] == 'grid') { $adsType = 'GRID'; } } return !empty($adsType) && SCHelpers::renderAds($this->postID, $adsType, true) ? 'yes' : 'no'; } public function getBodyCard() { $aBody = GetSettings::getOptions( General::getSingleListingSettingKey('card', $this->postType) ); $aValues = []; if (!empty($aBody)) { foreach ($aBody as $aItem) { if (!$this->isPlanAllowed($aItem['key'])) { continue; } $val = null; switch ($aItem['type']) { case 'custom_taxonomy': $val = $this->getTaxonomy($aItem['key'], false); break; case 'custom_field': if (!empty($aItem['content'])) { $this->getAddListingFields(); $aItem['customFieldType'] = $this->aAddListingFields[$aItem['key']]['type']; $content = str_replace(']', ' post_id="'.$this->postID.'" return_format="json"]', $aItem['content']); $content = str_replace(['{{', '}}'], ['"', '"'], $content); if (!empty($content)) { $val = do_shortcode($content); if (!empty($val)) { $val = isJson($val) ? json_decode($val, true) : $val; } } } break; default: $funcName = 'get'.ucfirst(str_replace('_', '', $aItem['type'])); if (method_exists($this, $funcName)) { $val = $this->$funcName(); } break; } if (!empty($val)) { $aItem['value'] = $val; unset($aItem['content']); $aValues[] = $aItem; } } } return $aValues; } public function getEventData() { $aEventCalendarSettings = GetSettings::getEventSettings($this->post->ID); $aListing['start'] = [ 'day' => date_i18n(get_option('date_format'), strtotime($aEventCalendarSettings['startsOn'])), 'hour' => Time::renderTimeFormat(strtotime($aEventCalendarSettings['startsOn']), $this->post->ID) ]; $aListing['end'] = [ 'day' => date_i18n(get_option('date_format'), strtotime($aEventCalendarSettings['endsOn'])), 'hour' => Time::renderTimeFormat(strtotime($aEventCalendarSettings['endsOn']), $this->post->ID) ]; $aListing['interested'] = SCHelpers::renderInterested($this->post, [], true); $aListing['hosted_by'] = SCHelpers::renderHostedBy($this->post, [], true); $aListing['hostedByName'] = GetSettings::getEventHostedByName($this->post); $aListing['hostedByURL'] = GetSettings::getEventHostedByUrl($this->post); $aListing['hostedByTarget'] = GetSettings::getEventHostedByTarget($aListing['hostedByURL']); $aListing['startAt'] = date_i18n('d', strtotime($aEventCalendarSettings['startsOn'])); $aListing['startsOn'] = date_i18n('M', strtotime($aEventCalendarSettings['startsOn'])); return $aListing; } public function getHeaderCard() { $aHeader = GetSettings::getOptions( General::getSingleListingSettingKey('header_card', $this->postType) ); $headerType = isset($aHeader['btnAction']) ? $aHeader['btnAction'] : 'total_views'; if (!$this->isPlanAllowed($headerType)) { return []; } $aValues = []; switch ($headerType) { case 'call_us': $val = $this->getPhone(); if (!empty($val)) { $aValues[] = [ 'type' => 'phone', 'icon' => 'la la-phone', 'value' => 'tel:'.$val, 'name' => 'Call us', 'i18' => 'callUs' ]; } break; case 'email_us': $val = $this->getEmail(); if (!empty($val)) { $aValues[] = [ 'type' => 'email', 'icon' => 'la la-envelope', 'value' => 'mailto:'.$val, 'name' => 'Email', 'i18' => 'emailUs' ]; } break; default: $val = $this->getTotalViews(); if (!empty($val)) { $aValues[] = [ 'type' => 'totalViews', 'icon' => 'la la-eye', 'name' => sprintf(_n('%s view', '%s views', $val, 'wiloke-listing-tools'), number_format_i18n($val)), 'value' => get_permalink() ]; } break; } $aValues[] = [ 'type' => 'favorite', 'iconType' => $this->postType === 'event' ? 'star' : 'love', 'isMyFavorite' => $this->getIsMyFavorite() ]; return $aValues; } public function getFooterCard() { $aFooter = GetSettings::getOptions(General::getSingleListingSettingKey('footer_card', $this->postType)); if (empty($aFooter)) { return []; } $aValues = []; foreach ($aFooter as $taxonomy) { $val = $this->getTaxonomy($taxonomy, true); if (!empty($val)) { $aValues[] = [ 'value' => $val, 'position' => 'left', 'type' => 'taxonomy' ]; } } if ($this->isPlanAllowed('toggle_business_hours')) { $aValues[] = [ 'type' => 'business-hours', 'icon' => '', 'value' => $this->getBusinessHours(), 'position' => 'left' ]; } if ($this->isPlanAllowed('toggle_gallery')) { $aValues[] = [ 'type' => 'gallery', 'icon' => 'la la-search-plus', 'value' => $this->getGallery(), 'position' => 'right' ]; } $aValues[] = [ 'type' => 'favorite', 'iconType' => $this->postType === 'event' ? 'star' : 'love', 'isMyFavorite' => $this->getIsMyFavorite(), 'position' => 'right' ]; return apply_filters('wilcity/filter/wiloke-listing-tools/footer-card', $aValues, $this->post); } public function getSkeleton($post, $aPluck, $aAtts = []) { if (empty($aPluck)) { $aPluck = [ 'title', 'permalink', 'postType', 'logo', 'excerpt', 'oReviews', 'featuredImage', 'oAddress', 'phone', 'oTermFooter', 'oBusinessHours', 'gallery', 'isMyFavorite', 'price', 'priceRange', 'headerCard', 'bodyCard', 'footerCard' ]; } else { $aPluck = is_array($aPluck) ? $aPluck : explode(',', $aPluck); $aPluck = array_map(function ($key) { return $key; }, $aPluck); } $isIgnoreMenuOrder = isset($aAtts['ignoreMenuOrder']) && $aAtts['ignoreMenuOrder'] === true; if (!$isIgnoreMenuOrder) { $aPluck[] = 'menuOrder'; } if (is_numeric($post)) { $post = get_post($post); } $this->setPost($post); $this->aAtts = $aAtts; /** * @hooked WilcityRedis\Controllers@removeCachingPluckItems */ $aPluck = apply_filters( 'wilcity/filter/wiloke-listing-tools/app/Framework/Helpers/PostSkeleton/aPluck', $aPluck, $post, $this->aAtts ); $aListing = $this->pluck($aPluck); /** * @hooked WilcityRedis\Controllers@getPostSkeleton 5 * @hooked WilcityRedis\Controllers@setPostSkeleton 10 */ $aListing = apply_filters( 'wilcity/filter/wiloke-listing-tools/app/Framework/Helpers/PostSkeleton/aListing', $aListing, $post, $this->aAtts ); if ($isIgnoreMenuOrder) { $aListing['menuOrder'] = 0; } return $aListing; } }
[+]
..
[-] 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]