=> false, 'preloader_url' => '', 'taxonomy_brands' => '', 'img_url' => DGWT_WCAS_URL . 'assets/img/', 'is_premium' => dgoraAsfwFs()->is_premium(), 'layout_breakpoint' => $layout->layout_breakpoint, 'mobile_overlay_breakpoint' => $layout->mobile_overlay_breakpoint, 'mobile_overlay_wrapper' => $layout->mobile_overlay_wrapper, 'mobile_overlay_delay' => apply_filters( 'dgwt/wcas/scripts/overlay_delay_ms', 0 ), 'debounce_wait_ms' => apply_filters( 'dgwt/wcas/scripts/debounce_wait_ms', 400 ), 'send_ga_events' => apply_filters( 'dgwt/wcas/scripts/send_ga_events', true ), 'enable_ga_site_search_module' => apply_filters( 'dgwt/wcas/scripts/enable_ga_site_search_module', false ), 'magnifier_icon' => self::getMagnifierIco( '' ), 'magnifier_icon_pirx' => self::getMagnifierIco( '', 'magnifier-pirx' ), 'history_icon' => self::getIcon( 'history' ), 'close_icon' => self::getIcon( 'close' ), 'back_icon' => self::getIcon( 'arrow-left' ), 'preloader_icon' => self::getIcon( 'preloader' ), 'voice_search_inactive_icon' => self::getIcon( $layout->style === 'pirx' ? 'voice-search-inactive-pirx' : 'voice-search-inactive', 'dgwt-wcas-voice-search-mic-inactive' ), 'voice_search_active_icon' => self::getIcon( $layout->style === 'pirx' ? 'voice-search-active-pirx' : 'voice-search-active', 'dgwt-wcas-voice-search-mic-active' ), 'voice_search_disabled_icon' => self::getIcon( $layout->style === 'pirx' ? 'voice-search-disabled-pirx' : 'voice-search-disabled', 'dgwt-wcas-voice-search-mic-disabled' ), 'custom_params' => (object) apply_filters( 'dgwt/wcas/scripts/custom_params', array() ), 'convert_html' => true, // Todo remove it in v1.27.0, because it's not used anymore. 'suggestions_wrapper' => apply_filters( 'dgwt/wcas/scripts/suggestions_wrapper', 'body' ), 'show_product_vendor' => dgoraAsfwFs()->is_premium() && class_exists( 'DgoraWcas\Integrations\Marketplace\Marketplace' ) && DGWT_WCAS()->marketplace->showProductVendor(), 'disable_hits' => apply_filters( 'dgwt/wcas/scripts/disable_hits', false ), 'disable_submit' => apply_filters( 'dgwt/wcas/scripts/disable_submit', false ), 'fixer' => apply_filters( 'dgwt/wcas/scripts/fixer', array( 'broken_search_ui' => true, 'broken_search_ui_ajax' => true, 'broken_search_ui_hard' => false, 'broken_search_elementor_popups' => true, 'broken_search_jet_mobile_menu' => true, 'broken_search_browsers_back_arrow' => true, 'force_refresh_checkout' => true ) ), 'voice_search_enabled' => defined( 'DGWT_WCAS_VOICE_SEARCH_ENABLE' ) && DGWT_WCAS_VOICE_SEARCH_ENABLE, 'voice_search_lang' => apply_filters( 'dgwt/wcas/scripts/voice_search_lang', get_bloginfo( 'language' ) ), 'show_recently_searched_products' => false, 'show_recently_searched_phrases' => false, ); // User search history if ( DGWT_WCAS()->settings->getOption( 'show_user_history' ) === 'on' ) { $localize['show_recently_searched_products'] = apply_filters( 'dgwt/wcas/scripts/show_recently_searched_products', true ); $localize['show_recently_searched_phrases'] = apply_filters( 'dgwt/wcas/scripts/show_recently_searched_phrases', true ); } if ( Multilingual::isMultilingual() ) { $localize['current_lang'] = Multilingual::getCurrentLanguage(); } if ( dgoraAsfwFs()->is__premium_only() ) { $localize['dynamic_prices'] = Solver::shouldLoadPriceDynamically__premium_only(); $localize['debounce_wait_ms'] = apply_filters( 'dgwt/wcas/scripts/debounce_wait_ms', 100 ); if ( DGWT_WCAS()->brands->hasBrands() && DGWT_WCAS()->settings->getOption( 'show_product_tax_' . DGWT_WCAS()->brands->getBrandTaxonomy() ) === 'on' ) { $localize['taxonomy_brands'] = DGWT_WCAS()->brands->getBrandTaxonomy(); } } // Min characters $min_chars = DGWT_WCAS()->settings->getOption( 'min_chars' ); if ( ! empty( $min_chars ) && is_numeric( $min_chars ) ) { $localize['min_chars'] = absint( $min_chars ); } $sug_width = DGWT_WCAS()->settings->getOption( 'sug_width' ); if ( ! empty( $sug_width ) && is_numeric( $sug_width ) && $sug_width > 100 ) { $localize['sug_width'] = absint( $sug_width ); } // Show/hide Details panel if ( DGWT_WCAS()->settings->getOption( 'show_details_box' ) === 'on' ) { $localize['show_details_panel'] = true; } // Show/hide images if ( DGWT_WCAS()->settings->getOption( 'show_product_image' ) === 'on' ) { $localize['show_images'] = true; } // Show/hide price if ( DGWT_WCAS()->settings->getOption( 'show_product_price' ) === 'on' ) { $localize['show_price'] = true; } // Show/hide description if ( DGWT_WCAS()->settings->getOption( 'show_product_desc' ) === 'on' ) { $localize['show_desc'] = true; } // Show/hide description if ( DGWT_WCAS()->settings->getOption( 'show_product_sku' ) === 'on' ) { $localize['show_sku'] = true; } // Show/hide sale badge if ( DGWT_WCAS()->settings->getOption( 'show_sale_badge' ) === 'on' ) { $localize['show_sale_badge'] = true; } // Show/hide featured badge if ( DGWT_WCAS()->settings->getOption( 'show_featured_badge' ) === 'on' ) { $localize['show_featured_badge'] = true; } // Set preloader if ( DGWT_WCAS()->settings->getOption( 'show_preloader' ) === 'on' ) { $localize['show_preloader'] = true; $localize['preloader_url'] = esc_url( trim( DGWT_WCAS()->settings->getOption( 'preloader_url' ) ) ); } // Show/hide autocomplete headings if ( DGWT_WCAS()->settings->getOption( 'show_grouped_results' ) === 'on' ) { $localize['show_headings'] = true; } return apply_filters( 'dgwt/wcas/scripts/localize', $localize ); } /** * Get endpoint URL * * @param string $type * * @return string */ public static function getEndpointUrl( $type = '' ) { $url = ''; if ( ! in_array( $type, array( 'search', 'details', 'prices' ) ) ) { return $url; } switch ( $type ) { case 'search': $url = \WC_AJAX::get_endpoint( DGWT_WCAS_SEARCH_ACTION ); if ( dgoraAsfwFs()->is__premium_only() ) { $url = DGWT_WCAS_URL . 'includes/Engines/TNTSearchMySQL/Endpoints/search.php'; if ( ( get_option( 'dgwt_wcas_alternative_endpoint_enabled' ) === '1' && defined( 'DGWT_WCAS_SEARCH_PRO_ACTION' ) ) || ( defined( 'DGWT_WCAS_ALTERNATIVE_SEARCH_ENDPOINT' ) && DGWT_WCAS_ALTERNATIVE_SEARCH_ENDPOINT ) ) { $url = \WC_AJAX::get_endpoint( DGWT_WCAS_SEARCH_PRO_ACTION ); } } break; case 'details': $url = \WC_AJAX::get_endpoint( DGWT_WCAS_RESULT_DETAILS_ACTION ); break; case 'prices': $url = \WC_AJAX::get_endpoint( DGWT_WCAS_GET_PRICES_ACTION ); break; default: break; } return apply_filters( "dgwt/wcas/endpoint/{$type}", $url ); } /** * Checking the current code is run by the object of the given class * * @param string $class_name Class name * @param int $backtrace_limit The number of stack frames that is tested backwards. * * @return bool */ public static function is_running_inside_class( $class_name, $backtrace_limit = 10 ) { if ( empty( $class_name ) ) { return false; } if ( intval( $backtrace_limit ) <= 0 ) { $backtrace_limit = 10; } $result = false; $backtrace = self::debugBacktrace( 0, $backtrace_limit ); if ( ! empty( $backtrace ) ) { foreach ( $backtrace as $item ) { if ( isset( $item['class'] ) && $item['class'] === $class_name ) { $result = true; break; } } } return $result; } /** * Checking the current code is run inside specified function * * @param string $function_name Function name * @param int $backtrace_limit The number of stack frames that is tested backwards. * * @return bool */ public static function isRunningInsideFunction( $function_name, $backtrace_limit = 10 ) { if ( empty( $function_name ) ) { return false; } if ( intval( $backtrace_limit ) <= 0 ) { $backtrace_limit = 10; } $result = false; $backtrace = self::debugBacktrace( 0, $backtrace_limit ); if ( ! empty( $backtrace ) ) { foreach ( $backtrace as $item ) { if ( isset( $item['function'] ) && $item['function'] === $function_name ) { $result = true; break; } } } return $result; } private static function debugBacktrace( $options, $limit ) { return debug_backtrace( $options, $limit ); } /** * Search products with native engine * * @param $phrase * * @return int[] */ public static function searchProducts( $phrase ) { $postIn = []; $results = DGWT_WCAS()->nativeSearch->getSearchResults( $phrase, true, 'product-ids' ); if ( isset( $results['suggestions'] ) && is_array( $results['suggestions'] ) ) { $postIn = wp_list_pluck( $results['suggestions'], 'ID' ); } return $postIn; } /** * Search products with TNT engine * * @param $phrase * @param $orderby * @param $order * * @return int[] */ public static function searchProducts__premium_only( $phrase, $orderby = 'relevance', $order = '' ) { $search = new SearchResultsPageQuery(); $search->setPhrase( $phrase ); if ( Multilingual::isMultilingual() ) { $search->setLang( Multilingual::getCurrentLanguage() ); } $search->searchProducts(); $results = $search->getProducts( $orderby, $order ); return array_map( 'intval', wp_list_pluck( $results, 'post_id' ) ); } /** * Get all post types used in search * * @param string $filter 'no-products' returns post types not related to products * 'only-products' returns post types related to products * * @return array */ public static function getAllowedPostTypes( $filter = '' ) { $types = array(); if ( $filter !== 'no-products' ) { $types[] = 'product'; $types[] = 'product-variation'; } if ( $filter !== 'only-products' ) { if ( DGWT_WCAS()->settings->getOption( 'show_matching_posts' ) === 'on' ) { $types[] = 'post'; } if ( DGWT_WCAS()->settings->getOption( 'show_matching_pages' ) === 'on' ) { $types[] = 'page'; } } return apply_filters( 'dgwt/wcas/allowed_post_types', $types, $filter ); } /** * Get Basic Auth header from dedicated constants or from current request * * @return string */ public static function getBasicAuthHeader() { $authorization = ''; if ( defined( 'DGWT_WCAS_BA_USERNAME' ) && defined( 'DGWT_WCAS_BA_PASSWORD' ) ) { $authorization = 'Basic ' . base64_encode( wp_unslash( DGWT_WCAS_BA_USERNAME ) . ':' . wp_unslash( DGWT_WCAS_BA_PASSWORD ) );; } elseif ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) { $authorization = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); } return $authorization; } /** * Get terms from filter group * * @param string $group * @param array $values * * @return \WP_Term[] */ public static function getFilterGroupTerms__premium_only( $group, $values ) { $taxonomy = self::getTaxonomyFromFilterGroup__premium_only( $group ); if ( empty( $taxonomy ) ) { return array(); } if ( Multilingual::isMultilingual() ) { // Get terms in default language $terms = Multilingual::getTermsInLang( array( 'taxonomy' => $taxonomy, 'include' => $values, 'hide_empty' => false ) ); } else { $terms_args = array( 'taxonomy' => $taxonomy, 'hide_empty' => false, 'include' => $values, ); $terms = get_terms( $terms_args ); } if ( is_wp_error( $terms ) ) { return array(); } return $terms; } /** * Get taxonomy name from filter group * * @param $group * * @return string */ public static function getTaxonomyFromFilterGroup__premium_only( $group ) { if ( strpos( $group, 'pa:' ) !== false ) { $group = wc_attribute_taxonomy_name_by_id( (int) str_replace( 'pa:', '', $group ) ); } return $group; } /** * Get filter products rules * * @return array */ public static function getFilterProductsRules__premium_only() { $rules = array(); $savedRules = DGWT_WCAS()->settings->getOption( 'filter_products_rules' ); if ( ! is_string( $savedRules ) ) { return $rules; } $rulesRaw = json_decode( $savedRules ); if ( empty( $rulesRaw ) ) { return $rules; } // Merge rules from same group foreach ( $rulesRaw as $rule ) { if ( empty( $rule->group ) || empty( $rule->values ) ) { continue; } if ( ! isset( $rules[ $rule->group ] ) ) { $rules[ $rule->group ] = array(); } $rules[ $rule->group ] = array_merge( $rules[ $rule->group ], $rule->values ); $rules[ $rule->group ] = array_unique( $rules[ $rule->group ] ); } return $rules; } /** * Check status of DB support for JSON format */ public static function doesDbSupportJson__premium_only() { global $wpdb; if ( defined( 'SHORTINIT' ) && SHORTINIT ) { $result = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'dgwt_wcas_db_json_support'" ); } else { $result = get_option( 'dgwt_wcas_db_json_support' ); } return $result === 'yes'; } /** * Check if cache is enabled * * @return bool */ public static function isCacheEnabled__premium_only() { $enabled = true; if ( defined( 'DGWT_WCAS_SEARCH_CACHE' ) ) { $enabled = (bool) DGWT_WCAS_SEARCH_CACHE; } return apply_filters( 'dgwt/wcas/tnt/search_cache', $enabled ); } /** * Get version of the FiboSearch Pro. Skips the cache. * * @return string */ public static function getPluginVersion__premium_only() { global $wpdb; $version = $wpdb->get_var( "SELECT SQL_NO_CACHE option_value FROM $wpdb->options WHERE option_name = 'dgwt_wcas_version_pro'" ); return empty( $version ) ? '' : $version; } /** * Check that the AMP version of the page is displayed * * @return bool */ public static function isAMPEndpoint() { return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint(); } /** * Set lock * * @param string $key Lock key * * @return bool */ public static function setLock__premium_only( $key ) { global $wpdb; if ( empty( $key ) ) { return false; } $id = $wpdb->get_var( $wpdb->prepare( "SELECT SQL_NO_CACHE option_id FROM $wpdb->options WHERE option_name = %s", $key ) ); if ( empty( $id ) ) { $result = $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no')", $key, (string) microtime( true ) ) ); } else { $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options SET `option_value` = %s WHERE `option_id` = %d", (string) microtime( true ), $id ) ); } return $result > 0; } /** * Test if lock is locked * * The lock is locked until its expiry time has elapsed. * * @param string $key Lock key * @param int $expiration Expiration time (seconds) * * @return false */ public static function isLockLocked__premium_only( $key, $expiration ) { global $wpdb; $timestamp = $wpdb->get_var( $wpdb->prepare( "SELECT SQL_NO_CACHE option_value FROM $wpdb->options WHERE option_name = %s", $key ) ); if ( empty( $timestamp ) ) { return false; } return microtime( true ) - (float) $expiration < (float) $timestamp; } /** * Unlock lock * * @param string $key Lock key * * @return bool */ public static function unlockLock__premium_only( $key ) { global $wpdb; if ( empty( $key ) ) { return false; } $result = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name = %s", $key ) ); return $result > 0; } /** * Get the path to the fibo directory in the theme or child theme * * @param string $path * @param array $vars * * @return void */ public static function loadTemplate( $template = '', $vars = array() ) { $path = ''; // Load default partials from the plugin $file = DGWT_WCAS_DIR . 'partials/' . $template; if ( file_exists( $file ) ) { $path = $file; } // Load a partial if it is localized in the child-theme $file = get_stylesheet_directory() . '/fibosearch/' . $template; if ( file_exists( $file ) ) { $path = $file; } $path = apply_filters( 'dgwt/wcas/template', $path, $template, $vars ); if ( file_exists( $path ) ) { include $path; } } /** * Add "No results" if suggestions are empty * * @param array $output * * @return array */ public static function noResultsSuggestion( $output ) { if ( empty( $output['suggestions'] ) ) { $output['suggestions'][] = array( 'value' => '', 'type' => 'no-results' ); } return $output; } /** * Get default collate * * @param string $context * * @return string */ public static function getCollate( $context = '' ) { global $wpdb; $sql = ''; $collate = ''; $charset = ''; if ( $wpdb->has_cap( 'collation' ) ) { if ( ! empty( $wpdb->charset ) ) { $charset = $wpdb->charset; } if ( ! empty( $wpdb->collate ) ) { $collate = $wpdb->collate; } } $charset = apply_filters( 'dgwt/wcas/db/charset', $charset, $context ); $collate = apply_filters( 'dgwt/wcas/db/collation', $collate, $context ); if ( ! empty( $charset ) ) { $sql .= " DEFAULT CHARACTER SET " . $charset; } if ( ! empty( $collate ) ) { $sql .= " COLLATE " . $collate; } return apply_filters( 'dgwt/wcas/db/collation/sql', $sql, $context ); } /** * Get plugin info if it's not active * * @param string $name * @param string[] $paths * * @return array|false */ public static function getFolderRenameInfo__premium_only( $name, $paths ) { $valid_plugin_name = false; $result = false; foreach ( $paths as $path ) { if ( \DgoraWcas\Engines\TNTSearchMySQL\Config::isPluginActive( $path ) ) { $valid_plugin_name = true; break; } } if ( ! $valid_plugin_name ) { $result = array( 'name' => $name, 'folder' => dirname( $paths[0] ) ); } return $result; } /** * Check if string ends with another string * * @param string $haystack * @param string $needle * * @return bool */ public static function endsWith( $haystack, $needle ) { $length = strlen( $needle ); return $length > 0 ? substr( $haystack, - $length ) === $needle : true; } /** * Check if index is being built * * @return bool */ public static function isIndexing__premium_only() { if ( ( defined( 'DGWT_WCAS_PREPARE_BUILD_INDEX' ) && DGWT_WCAS_PREPARE_BUILD_INDEX ) || ( defined( 'DGWT_WCAS_BUILD_INDEX_PROCESS' ) && DGWT_WCAS_BUILD_INDEX_PROCESS ) || ( defined( 'DGWT_WCAS_SEARCHABLE_INDEX_TASK' ) && DGWT_WCAS_SEARCHABLE_INDEX_TASK ) || ( defined( 'DGWT_WCAS_READABLE_INDEX_TASK' ) && DGWT_WCAS_READABLE_INDEX_TASK ) || ( defined( 'DGWT_WCAS_TAXONOMY_INDEX_TASK' ) && DGWT_WCAS_TAXONOMY_INDEX_TASK ) || ( defined( 'DGWT_WCAS_VARIATIONS_INDEX_TASK' ) && DGWT_WCAS_VARIATIONS_INDEX_TASK ) || ( defined( 'DGWT_WCAS_VENDOR_INDEX_TASK' ) && DGWT_WCAS_VENDOR_INDEX_TASK ) ) { return true; } return false; } /** * Get table info * * @return float[] */ public static function getTableInfo( $table = '' ) { global $wpdb; if ( ! defined( 'DB_NAME' ) || empty( $table ) ) { return array( 'data' => 0.0, 'index' => 0.0, ); } $info = $wpdb->get_row( $wpdb->prepare( "SELECT round( ( data_length / 1024 / 1024 ), 2 ) 'data', round( ( index_length / 1024 / 1024 ), 2 ) 'index' FROM information_schema.TABLES WHERE table_schema = %s AND table_name = %s;", DB_NAME, $table ) , ARRAY_A ); if ( ! isset( $info['data'] ) || ! isset( $info['index'] ) ) { return array( 'data' => 0.0, 'index' => 0.0, ); } $info['data'] = floatval( $info['data'] ); $info['index'] = floatval( $info['index'] ); return $info; } /** * Get names of all FiboSearch options * * @return array */ public static function getAllOptionNames() { global $wpdb; $options = array(); $res = $wpdb->get_col( "SELECT SQL_NO_CACHE option_name FROM $wpdb->options WHERE option_name LIKE 'dgwt_wcas_%'" ); if ( ! empty( $res ) && is_array( $res ) ) { $options = $res; } return $options; } /** * Load necessary user files to handle current_user_can() in SHORTINIT mode * * @return void */ public static function loadUserFiles__premium_only() { require_once ABSPATH . WPINC . '/default-constants.php'; wp_plugin_directory_constants(); wp_cookie_constants(); require_once ABSPATH . WPINC . '/rest-api.php'; require_once ABSPATH . WPINC . '/kses.php'; require_once ABSPATH . WPINC . '/class-wp-user.php'; require_once ABSPATH . WPINC . '/class-wp-roles.php'; require_once ABSPATH . WPINC . '/class-wp-role.php'; require_once ABSPATH . WPINC . '/class-wp-session-tokens.php'; require_once ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php'; require_once ABSPATH . WPINC . '/user.php'; require_once ABSPATH . WPINC . '/pluggable.php'; require_once ABSPATH . WPINC . '/capabilities.php'; } /** * Does the "Shop manager" role have access to the plugin settings? * * @return bool */ public static function shopManagerHasAccess() { return defined( 'DGWT_WCAS_ALLOW_SHOP_MANAGER_ACCESS' ) && DGWT_WCAS_ALLOW_SHOP_MANAGER_ACCESS; } /** * Clear phrase before processing regex expression. * Some user inputs might contain special characters which should be escaped. * * @return string */ public static function escPhraseForRegex( $phrase ) { $phrase = preg_replace_callback( "/([!@#$&()\-\[\]{}\\`.+,\/\"\\'])/", function ( $matches ) { return '\\' . $matches[0]; }, $phrase ); return $phrase; } /** * Esc not allowed HTML tags for No Results text * * @return string */ public static function ksesNoResults( $content ) { $content = wp_kses( $content, array( 'div' => array( 'class' => array(), ), 'span' => array( 'class' => array(), ), 'a' => array( 'href' => array(), ), 'br' => array(), 'p' => array(), 'em' => array(), 'b' => array(), 'ol' => array(), 'ul' => array(), 'li' => array(), 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array() ) ); return $content; } /** * Convert text to Greeklish * * @param string $text * * @return string */ public static function convertToGreeklish__premium_only( $text ) { $greekLatinMap = array( 'ευα' => 'eva', 'ευη' => 'evi', 'ευε' => 'eve', 'ευκ' => 'efk', 'ευμ' => 'evm', 'χτ' => 'kt', 'ντ' => 'nt', 'ευ' => 'ef', 'ά' => 'a', 'ώ' => 'o', 'έ' => 'e', 'ό' => 'o', 'ί' => 'i', 'ή' => 'i', 'ϊ' => 'i', 'ϋ' => 'i', 'ύ' => 'i', 'λλ' => 'l', 'σσ' => 's', 'τζ' => 'g', 'γγ' => 'g', 'γκ' => 'g', 'κκ' => 'k', 'μμ' => 'm', 'νν' => 'n', 'φφ' => 'f', 'ρρ' => 'r', 'ττ' => 't', 'αι' => 'e', 'οι' => 'i', 'ει' => 'i', 'υι' => 'i', 'ου' => 'ou', 'σ' => 's', 'τ' => 't', 'υ' => 'i', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'o', 'α' => 'a', 'β' => 'v', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'i', 'θ' => '', 'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => 'ks', 'ο' => 'o', 'ρ' => 'r', 'π' => 'p', 'oi' => 'i', 'mb' => 'mp', 'ei' => 'i', 'll' => 'l', 'gk' => 'g', 'kk' => 'k', 'ff' => 'f', 'mm' => 'm', 'nn' => 'n', 'rr' => 'r', 'tt' => 't', 'ph' => 'f', 'oy' => 'ou', 'ai' => 'e', 'ss' => 's', 'th' => '', 'w' => 'o', 'h' => 'i', 'd' => 'nt', 'b' => 'mp', 'c' => 'k', 'y' => 'i', ); return strtr( mb_strtolower( $text ), $greekLatinMap ); } /** * Check if the text contains Greek characters * * @param string $text * * @return bool */ public static function isGreekText__premium_only( $text ) { preg_match_all( '/[\p{Greek}]+/u', $text, $matches, PREG_SET_ORDER, 0 ); return ! empty( $matches ); } /** * Remove Greek accents * * @param string $text The text to process. * * @return string */ public static function removeGreekAccents( $text ) { $chars = array( 'Ά' => 'Α', 'ά' => 'α', 'Έ' => 'Ε', 'έ' => 'α', 'Ί' => 'Ι', 'ί' => 'ι', 'ΐ' => 'ϊ', 'Ύ' => 'Υ', 'ύ' => 'υ', 'ΰ' => 'ϋ', 'Ή' => 'Η', 'ή' => 'η', 'Ό' => 'Ο', 'ό' => 'ο', 'Ώ' => 'Ω', 'ώ' => 'ω', ); return strtr( $text, $chars ); } /** * Test if phrase contains blacklisted term * * @param string $phrase Search phrase. * * @return bool */ public static function phraseContainsBlacklistedTerm( $phrase ) { $blacklistedTerms = apply_filters( 'dgwt/wcas/blacklisted_terms', array() ); if ( is_array( $blacklistedTerms ) ) { foreach ( $blacklistedTerms as $term ) { if ( mb_stripos( $phrase, $term ) !== false ) { return true; } } } if ( apply_filters( 'dgwt/wcas/blacklisted_terms/check_js', true ) && self::containsJsScript( $phrase ) ) { return true; } return false; } /** * Get specific label of the post type * * @param string|\WP_Post_Type $postType * @param string $label * * @return string */ public static function getPostTypeLabel( $postType, $label ) { $text = ''; $obj = null; $label = sanitize_key( $label ); if ( is_string( $postType ) ) { $obj = get_post_type_object( $postType ); } if ( is_object( $postType ) && is_a( $postType, 'WP_Post_Type' ) ) { $obj = $postType; } if ( ! empty( $obj->labels ) && ! empty( $obj->labels->$label ) ) { $text = $obj->labels->$label; } return $text; } /** * Check if the string contains JS script * * @param string $text * * @return bool */ public static function containsJsScript( $text ) { return ! empty( $text ) && preg_match( '/]*?>/', $text ); } /** * Remove content of