table exist * * @return bool */ public static function isTableExists( $tableName ) { global $wpdb ; $exist = false; $wpdb->hide_errors(); if ( empty($tableName) ) { return false; } $sql = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->prefix . 'dgwt_wcas_%' ); $result = $wpdb->get_col( $sql ); if ( is_array( $result ) && in_array( $tableName, $result ) ) { $exist = true; } return $exist; } /** * Check if the engine can search in variable products * * @return bool */ public static function canSearchInVariableProducts() { global $wpdb ; $allow = false; $el = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product_variation' LIMIT 1" ); if ( !empty($el) && is_numeric( $el ) ) { $allow = true; } if ( DGWT_WCAS()->settings->getOption( 'search_in_product_content' ) !== 'on' ) { $allow = false; } return apply_filters( 'dgwt/wcas/search_in_variable_products', $allow ); } /** * Allow to remove method for an hook when, it's a class method used and class don't have variable, but you know the class name * * @link https://github.com/herewithme/wp-filters-extras * @return bool */ public static function removeFiltersForAnonymousClass( $hook_name = '', $class_name = '', $method_name = '', $priority = 0 ) { global $wp_filter ; // Take only filters on right hook name and priority if ( !isset( $wp_filter[$hook_name][$priority] ) || !is_array( $wp_filter[$hook_name][$priority] ) ) { return false; } // Loop on filters registered foreach ( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) { // Test if filter is an array ! (always for class/method) if ( isset( $filter_array['function'] ) && is_array( $filter_array['function'] ) ) { // Test if object is a class, class and method is equal to param ! if ( is_object( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) == $class_name && $filter_array['function'][1] == $method_name ) { // Test for WordPress >= 4.7 WP_Hook class (https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/) if ( is_a( $wp_filter[$hook_name], 'WP_Hook' ) ) { unset( $wp_filter[$hook_name]->callbacks[$priority][$unique_id] ); } else { unset( $wp_filter[$hook_name][$priority][$unique_id] ); } } } } return false; } /** * Create tooltip * * @param string $id * @param string $content * @param string $template * @param string $placement * @param string $class * * @return string */ public static function createTooltip( $id, $content = '', $template = '', $placement = 'right', $class = '' ) { if ( !empty($template) ) { $file = DGWT_WCAS_DIR . 'partials/admin/tooltips/' . $template . '.php'; if ( file_exists( $file ) ) { ob_start(); require $file; $content = ob_get_contents(); ob_end_clean(); } } $id = 'js-dgwt-wcas-tooltip-id' . sanitize_key( $id ); $html = '
'; $html .= ''; return $html; } /** * Create HTML override option tooltip * * @param string $id * @param string $content * @param string $template * @param string $placement * * @return string */ public static function getOverrideOptionText( $theme ) { $linkToShortcodesDoc = 'https://fibosearch.com/documentation/get-started/how-to-add-fibosearch-to-your-website/#add-fibosearch-with-a-shortcode'; $content = '

' . sprintf( __( 'This option is overridden by the seamless integration with the %s theme. If you want to change the value of this option, disable the integration in
WooCommerce -> FiboSearch -> Starting (tab).', 'ajax-search-for-woocommerce' ), $theme ) . '

'; $content .= '

' . sprintf( __( 'Furthermore, you can override this option for a specific search bar via shortcode params. Learn more about shortcodes parameters.', 'ajax-search-for-woocommerce' ), $linkToShortcodesDoc ) . '

'; return $content; } /** * Create HTML question mark with tooltip * * @param string $id * @param string $content * @param string $template * @param string $placement * * @return string */ public static function createQuestionMark( $id, $content = '', $template = '', $placement = 'right' ) { return self::createTooltip( $id, $content, $template, $placement, 'dashicons dashicons-editor-help dgwt-wcas-questio-mark' ); } /** * Create HTML option override tooltip * * @param string $id * @param string $content * @param string $template * @param string $placement * * @return string */ public static function createOverrideTooltip( $id, $content = '', $template = '', $placement = 'right' ) { return self::createTooltip( $id, $content, $template, $placement, 'dashicons dashicons-lock dgwt-wcas-override-tooltip' ); } /** * Get list of 24 hours */ public static function getHours() { $hours = array(); $cycle12 = ( get_option( 'time_format' ) === 'H:i' ? false : true ); for ( $i = 0 ; $i < 24 ; $i++ ) { $label = ( $cycle12 ? $i . ':00 am' : $i . ':00' ); if ( $cycle12 && $i === 0 ) { $label = 12 . ':00 am'; } if ( $cycle12 && $i > 11 ) { if ( $i === 12 ) { $label = 12 . ':00 pm'; } else { $label = $i - 12 . ':00 pm'; } } $hours[$i] = $label; } return $hours; } /** * Get local date including timezone * * @param $timestamp * @param string $format * * @return string * @throws \Exception */ public static function localDate( $timestamp, $format = '' ) { if ( empty($timestamp) ) { return ''; } if ( empty($format) ) { $format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); } $date = new \WC_DateTime( "@{$timestamp}" ); $date->setTimezone( new \DateTimeZone( wc_timezone_string() ) ); return $date->date_i18n( $format ); } /** * Get labels * * @return array */ public static function getLabels() { return apply_filters( 'dgwt/wcas/labels', array( 'post' => __( 'Post' ), 'page' => __( 'Page' ), 'vendor' => __( 'Vendor', 'ajax-search-for-woocommerce' ), 'product_plu' => __( 'Products', 'woocommerce' ), 'post_plu' => __( 'Posts' ), 'page_plu' => __( 'Pages' ), 'vendor_plu' => __( 'Vendors', 'ajax-search-for-woocommerce' ), 'sku_label' => __( 'SKU', 'woocommerce' ) . ':', 'sale_badge' => __( 'Sale', 'woocommerce' ), 'vendor_sold_by' => __( 'Sold by:', 'ajax-search-for-woocommerce' ), 'featured_badge' => __( 'Featured', 'woocommerce' ), 'in' => _x( 'in', 'in categories fe. in Books > Crime stories', 'ajax-search-for-woocommerce' ), 'read_more' => __( 'continue reading', 'ajax-search-for-woocommerce' ), 'no_results' => DGWT_WCAS()->settings->getOption( 'search_no_results_text', __( 'No results', 'ajax-search-for-woocommerce' ) ), 'show_more' => DGWT_WCAS()->settings->getOption( 'search_see_all_results_text', __( 'See all products...', 'ajax-search-for-woocommerce' ) ), 'show_more_details' => DGWT_WCAS()->settings->getOption( 'search_see_all_results_text', __( 'See all products...', 'ajax-search-for-woocommerce' ) ), 'search_placeholder' => DGWT_WCAS()->settings->getOption( 'search_placeholder', __( 'Search for products...', 'ajax-search-for-woocommerce' ) ), 'submit' => DGWT_WCAS()->settings->getOption( 'search_submit_text', '' ), ) ); } /** * Get labels * * @param string $key * * @return string */ public static function getLabel( $key ) { $label = ''; $labels = self::getLabels(); if ( array_key_exists( $key, $labels ) ) { $label = $labels[$key]; } return $label; } /** * Remove all HTML tags including