PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Framework
/
Helpers
<?php namespace WilokeListingTools\Framework\Helpers; use WilokeListingTools\Framework\Store\Session; use WilokeListingTools\Register\WilokeSubmission; class GetWilokeSubmission { public static $aConfiguration = []; public static $isFocusNonRecurring; public static $aGateways; public static function getThankyouPageURL($aArgs = []) { $thankyouURL = GetWilokeSubmission::getField('thankyou', true); if (!empty($aArgs)) { return add_query_arg($aArgs, $thankyouURL); } return $thankyouURL; } public static function getDefaultPlanID($postID) { return GetWilokeSubmission::getField('free_claim_'.get_post_type($postID).'_plan'); } public static function getCancelPageURL($aArgs = []) { $cancelURL = GetWilokeSubmission::getField('cancel', true); if (!empty($aArgs)) { return add_query_arg($aArgs, $cancelURL); } return $cancelURL; } public static function getField($field, $isUrl = false) { self::getAll(); if (isset(self::$aConfiguration[$field])) { return $isUrl ? get_permalink(self::$aConfiguration[$field]) : self::$aConfiguration[$field]; } return ''; } public static function getDashboardUrl($field, $router) { $dashboardURL = self::getField($field, true); return $dashboardURL.'#'.$router; } public static function getFreePlan($postType) { $aPlans = self::getAddListingPlans($postType.'_plans'); return is_array($aPlans) ? $aPlans[0] : ''; } public static function getFreeClaimPlanID($listingID) { $key = 'free_claim_'.get_post_type($listingID).'_plan'; return self::getField($key); } public static function isEnable($field) { $toggle = self::getField($field); return $toggle == 'enable'; } public static function isFreePlan($planID) { $aPlanSettings = GetSettings::getPlanSettings($planID); return empty($aPlanSettings['regular_price']); } public static function isSystemEnable() { return self::isEnable('toggle'); } public static function getAll() { if (empty(self::$aConfiguration)) { self::$aConfiguration = get_option(WilokeSubmission::$optionKey); self::$aConfiguration = maybe_unserialize(self::$aConfiguration); } return self::$aConfiguration; } public static function getBillingType() { return self::getField('billing_type'); } public static function getGatewaysWithName($excludeDirectBank = false) { $aTranslations = [ 'stripe' => esc_html__('Stripe', 'wiloke-listing-tools'), 'banktransfer' => esc_html__('Bank Transfer', 'wiloke-listing-tools'), 'paypal' => esc_html__('PayPal', 'wiloke-listing-tools'), 'woocommerce' => esc_html__('WooCommerce', 'wiloke-listing-tools') ]; $aGateways = self::getAllGateways($excludeDirectBank); if (empty($aGateways)) { return false; } $aWithName = []; foreach ($aGateways as $gateway) { $aWithName[$gateway] = $aTranslations[$gateway]; } return $aWithName; } public static function getAllGateways($excludeDirectBank = false) { if (!empty(self::$aGateways)) { return self::$aGateways; } $gateways = self::getField('payment_gateways'); if (empty($gateways)) { self::$aGateways = false; return self::$aGateways; } self::$aGateways = explode(',', $gateways); if ($excludeDirectBank) { $key = array_search('banktransfer', self::$aGateways); $aGateways = self::$aGateways; if (!empty($key)) { unset($aGateways[$key]); } return $aGateways; } return self::$aGateways; } public static function getPlanKeyByListingID($listingID) { $postType = get_post_type($listingID); if (empty($listingID)) { return false; } return $postType.'_plans'; } public static function getAddListingPlans($planKey = '') { $planKey = empty($planKey) ? 'listing_plans' : $planKey; if (strpos($planKey, '_plans') === false) { $planKey = $planKey.'_plans'; } $planIDs = self::getField($planKey); if (empty($planIDs)) { return false; } $aPlanIDs = explode(',', $planIDs); $aPlanIDs = array_map('trim', $aPlanIDs); return $aPlanIDs; } public static function isGatewaySupported($gateway = '') { self::getAllGateways(); if (!self::$aGateways) { return false; } return in_array($gateway, self::$aGateways); } public static function getPermalink($field) { $val = self::getField($field); return get_permalink($val); } public static function getAddToCardUrl($productID) { $aArgs = [ 'add-to-cart' => $productID, 'quantity' => 1 ]; return add_query_arg( $aArgs, get_permalink(get_option('woocommerce_checkout_page_id')) ); } public static function isNonRecurringPayment($billingType = null) { if (self::$isFocusNonRecurring) { return true; } $billingType = empty($billingType) ? self::getBillingType() : $billingType; if (empty($billingType)) { if (empty($planID)) { try { Message::error(sprintf(esc_html__('Please provide the billing type: %s %s', 'wiloke-listing-tools'), __LINE__, __CLASS__)); } catch (\Exception $e) { } } $billingType = self::getBillingType(); } return $billingType == wilokeListingToolsRepository()->get('payment:billingTypes', true)->sub('nonrecurring'); } public static function convertStripePrice($price) { $zeroDecimal = self::getField('stripe_zero_decimal'); $zeroDecimal = empty($zeroDecimal) ? 1 : $zeroDecimal; return number_format($price / $zeroDecimal, 2); } public static function getSymbol($currency) { return wilokeListingToolsRepository() ->get('wiloke-submission:currencySymbol', true) ->sub(strtoupper($currency)) ; } public static function getPackageType($packageType) { switch ($packageType) { case 'promotion': $packageType = esc_html__('Promotion', 'wiloke-listing-tools'); break; case 'listing_plan': $packageType = esc_html__('Listing Plan', 'wiloke-listing-tools'); break; default: $packageType = str_replace('_', ' ', $packageType); $packageType = ucfirst($packageType); break; } return $packageType; } public static function canUserTrial($planID, $userID = null) { if (DebugStatus::status('WILOKE_ALWAYS_PAY')) { return true; } $userID = empty($userID) ? get_current_user_id() : $userID; $aPlansIDs = GetSettings::getUserMeta($userID, wilokeListingToolsRepository()->get('user:usedTrialPlans')); return empty($aPlansIDs) || !in_array($planID, $aPlansIDs); } public static function renderPrice($price, $currency = '', $isNegative = false, $symbol = '') { if (empty($symbol)) { $currency = empty($currency) ? GetWilokeSubmission::getField('currency_code') : $currency; $symbol = self::getSymbol($currency); } $position = self::getField('currency_position'); if (strpos($price, '-') !== false) { $price = str_replace('-', '', $price); $isNegative = true; } $symbol = apply_filters('wilcity/filter/symbol', $symbol); switch ($position) { case 'left': $priceHTML = $symbol.$price; break; case 'right': $priceHTML = $price.$symbol; break; case 'left_space': $priceHTML = $symbol.' '.$price; break; default: $priceHTML = $price.' '.$symbol; break; } return $isNegative ? '-'.$priceHTML : $priceHTML; } public static function getSubmissionPlanID() { return Session::getSession(wilokeListingToolsRepository()->get('payment:storePlanID')); } public static function isCancelPage() { global $post; $cancelID = self::getField('cancel'); return isset($post->ID) && $cancelID == $post->ID; } public static function isPlanExists($planID) { $planType = get_post_type($planID).'_plan'; $aPlanIDs = self::getAddListingPlans($planType); return !empty($aPlanIDs) && in_array($planID, $aPlanIDs); } public static function isFreeAddListing() { $mode = GetWilokeSubmission::getField('add_listing_mode'); return $mode == 'free_add_listing'; } public static function getPlanTrialDays($planID) { $aPlanSettings = GetSettings::getPlanSettings($planID); return isset($aPlanSettings['trial_period']) && !empty($aPlanSettings['trial_period']) ? abs($aPlanSettings['trial_period']) : 0; } public static function getPlanRegularDays($planID) { $aPlanSettings = GetSettings::getPlanSettings($planID); return isset($aPlanSettings['regular_period']) && !empty($aPlanSettings['regular_period']) ? $aPlanSettings['regular_period'] : 0; } public static function getPlanFrequencyDays($planID) { $trialDays = self::getPlanTrialDays($planID); if (!empty($trialDays)) { return $trialDays; } return self::getPlanRegularDays($planID); } public static function getDefaultPostType() { $aPostTypes = GetSettings::getFrontendPostTypes(); $aTypes = array_keys($aPostTypes); return $aTypes[0]; } public static function getPlanTypeByPlanID($planID) { $aPostTypes = GetSettings::getFrontendPostTypes(true); if (empty($aPostTypes)) { return ''; } foreach ($aPostTypes as $postTypeKey) { $aPlanIDs = self::getAddListingPlans($postTypeKey); if (in_array($planID, $aPlanIDs)) { return $postTypeKey.'_plan'; } } return ''; } public static function getNewPostStatus($postID) { if (get_post_status($postID) == 'publish') { return 'publish'; } if (get_post_status($postID) === 'editing') { $editListingStatusMode = self::getField('published_listing_editable'); switch ($editListingStatusMode) { case 'allow_trust_approved': $postStatus = 'publish'; break; case 'not_allow': $postStatus = 'draft'; break; default: $postStatus = 'pending'; break; } } else { $newListingStatusMode = self::getField('approved_method'); if ($newListingStatusMode == 'auto_approved_after_payment') { $postStatus = 'publish'; } else { $postStatus = 'pending'; } } return $postStatus; } public static function isTax() { return GetWilokeSubmission::isEnable('toggle_tax'); } public static function isTaxOnPricing() { return GetWilokeSubmission::isEnable('toggle_tax_on_pricing'); } public static function getTaxRate() { if (!self::isTax()) { return 0; } $taxRate = GetWilokeSubmission::getField('tax_rate'); $taxRate = abs($taxRate); return $taxRate; } public static function getTaxTitle() { return GetWilokeSubmission::getField('tax_title'); } /** * @param $price * * @return float */ public static function calculateTax($price) { return round($price * self::getTaxRate() / 100, 1); } /** * It's not included coupon */ public static function calculateTotal($price) { if (!self::isTax()) { return $price; } $tax = self::calculateTax($price); return $price + $tax; } }
[+]
..
[-] 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]