isset( $_GET['dgwt_wcas'] ) && isset( $_GET['post_type'] ) && $_GET['post_type'] === 'product' && isset( $_GET['s'] ) ) {
return true;
}
return false;
}
/**
* Check if this is a remote search request
*
* @return bool
*/
public static function isRemoteSearchRequest()
{
if ( isset( $_GET['wc-ajax'] ) && $_GET['wc-ajax'] === DGWT_WCAS_SEARCH_ACTION && !empty($_GET['remote']) && isset( $_GET['s'] ) ) {
return true;
}
return false;
}
/**
* Restore the search phrase so that it can be used in the template.
*
* @param \WP_Post[] $posts Array of post objects.
* @param \WP_Query $query The WP_Query instance (passed by reference).
*
* @return mixed
*/
public static function rollbackSearchPhrase( $posts, $query )
{
if ( !$query->get( 'dgwt_wcas', false ) ) {
return $posts;
}
$query->set( 's', wp_unslash( $query->get( 'dgwt_wcas', '' ) ) );
return $posts;
}
/**
* Clear default search query if our engine is active
*
* @param string $search Search SQL for WHERE clause.
* @param \WP_Query $query The current WP_Query object.
*
* @return string
*/
public static function clearSearchQuery( $search, $query )
{
if ( !$query->get( 'dgwt_wcas', false ) ) {
return $search;
}
return '';
}
/**
* Get formatted search layout settings
*
* @return object
*/
public static function getLayoutSettings()
{
$layoutBreakpoint = DGWT_WCAS()->settings->getOption( 'mobile_breakpoint', 992 );
$layoutBreakpoint = apply_filters( 'dgwt/wcas/scripts/mobile_breakpoint', $layoutBreakpoint );
// deprecated
$mobileOverlayBreakpoint = DGWT_WCAS()->settings->getOption( 'mobile_overlay_breakpoint', 992 );
$layout = array(
'style' => DGWT_WCAS()->settings->getOption( 'search_style', 'solaris' ),
'icon' => 'magnifier-thin',
'layout' => DGWT_WCAS()->settings->getOption( 'search_layout', 'classic' ),
'layout_breakpoint' => apply_filters( 'dgwt/wcas/scripts/layout_breakpoint', $layoutBreakpoint ),
'mobile_overlay' => ( DGWT_WCAS()->settings->getOption( 'enable_mobile_overlay' ) === 'on' ? true : false ),
'mobile_overlay_breakpoint' => apply_filters( 'dgwt/wcas/scripts/mobile_overlay_breakpoint', $mobileOverlayBreakpoint ),
'mobile_overlay_wrapper' => apply_filters( 'dgwt/wcas/scripts/mobile_overlay_wrapper', 'body' ),
'darken_background' => ( DGWT_WCAS()->settings->getOption( 'darken_background', 'off' ) === 'on' ? true : false ),
'icon_color' => DGWT_WCAS()->settings->getOption( 'search_icon_color' ),
);
if ( $layout['style'] === 'pirx' ) {
$layout['icon'] = 'magnifier-pirx';
}
return (object) $layout;
}
/**
* Get frontend scripts settings
*
* @return array
*/
public static function getScriptsSettings()
{
$layout = self::getLayoutSettings();
// Localize
$localize = array(
'labels' => self::getLabels(),
'ajax_search_endpoint' => self::getEndpointUrl( 'search' ),
'ajax_details_endpoint' => self::getEndpointUrl( 'details' ),
'ajax_prices_endpoint' => self::getEndpointUrl( 'prices' ),
'action_search' => DGWT_WCAS_SEARCH_ACTION,
'action_result_details' => DGWT_WCAS_RESULT_DETAILS_ACTION,
'action_get_prices' => DGWT_WCAS_GET_PRICES_ACTION,
'min_chars' => 3,
'width' => 'auto',
'show_details_panel' => false,
'show_images' => false,
'show_price' => false,
'show_desc' => false,
'show_sale_badge' => false,
'show_featured_badge' => false,
'dynamic_prices' => false,
'is_rtl' => ( is_rtl() == true ? true : false ),
'show_preloader' => false,
'show_headings' => 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( '' ),
'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,
'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_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' ) ),
);
if ( Multilingual::isMultilingual() ) {
$localize['current_lang'] = Multilingual::getCurrentLanguage();
}
// 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 );
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;
}
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 = array();
$urlPhrase = str_replace( "\\'", "'", $phrase );
$urlPhrase = str_replace( '\\"', '"', $urlPhrase );
$args = array(
's' => urlencode( $urlPhrase ),
'remote' => 1,
);
if ( Multilingual::isMultilingual() ) {
$args['l'] = Multilingual::getCurrentLanguage();
}
$url = add_query_arg( $args, Helpers::getAjaxSearchEndpointUrl() );
$r = wp_remote_retrieve_body( wp_remote_get( $url, array(
'timeout' => 120,
) ) );
$decR = json_decode( $r );
if ( json_last_error() == JSON_ERROR_NONE ) {
if ( is_object( $decR ) && property_exists( $decR, 'suggestions' ) && is_array( $decR->suggestions ) ) {
$postIn = wp_list_pluck( $decR->suggestions, 'ID' );
}
}
return $postIn;
}
/**
* 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 plugin version
*
* @return string
*/
public static function getPluginVersion()
{
global $wpdb ;
$version = $wpdb->get_var( "SELECT option_value FROM {$wpdb->options} WHERE option_name = 'dgwt_wcas_version_pro'" );
return ( empty($version) ? '' : $version );
}
/**
* Get AJAX search endpoint URL
*
* @param null $scheme
*
* @return string
*
* @see \WC_AJAX::get_endpoint() - Almost the same, but you can choose a scheme
*/
public static function getAjaxSearchEndpointUrl( $scheme = null )
{
return esc_url_raw( apply_filters( 'woocommerce_ajax_get_endpoint', add_query_arg( 'wc-ajax', DGWT_WCAS_SEARCH_ACTION, remove_query_arg( array(
'remove_item',
'add-to-cart',
'added-to-cart',
'order_again',
'_wpnonce'
), home_url( '/', $scheme ) ) ), DGWT_WCAS_SEARCH_ACTION ) );
}
/**
* 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();
}
/**
* 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 );
}
/**
* 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 );
}
/**
* 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\n\t\t\t\t\t round( ( data_length / 1024 / 1024 ), 2 ) 'data',\n\t\t\t\t\t round( ( index_length / 1024 / 1024 ), 2 ) 'index'\n\t\t\t\t\tFROM information_schema.TABLES\n\t\t\t\t\tWHERE table_schema = %s\n\t\t\t\t\tAND 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;
}
}
Fatal error: Uncaught Error: Class 'DgoraWcas\Helpers' not found in /home/arasetne/public_html/wp-content/plugins/ajax-search-for-woocommerce/includes/Integrations/Plugins/WooCommerce/WooCommerce.php:23
Stack trace:
#0 /home/arasetne/public_html/wp-content/plugins/ajax-search-for-woocommerce/includes/Integrations/Plugins/PluginsCompatibility.php(37): DgoraWcas\Integrations\Plugins\WooCommerce\WooCommerce->init()
#1 /home/arasetne/public_html/wp-content/plugins/ajax-search-for-woocommerce/includes/Integrations/Plugins/PluginsCompatibility.php(13): DgoraWcas\Integrations\Plugins\PluginsCompatibility->loadCompatibilities()
#2 /home/arasetne/public_html/wp-content/plugins/ajax-search-for-woocommerce/ajax-search-for-woocommerce.php(74): DgoraWcas\Integrations\Plugins\PluginsCompatibility->__construct()
#3 /home/arasetne/public_html/wp-content/plugins/ajax-search-for-woocommerce/ajax-search-for-woocommerce.php(379): DGWT_WC_Ajax_Search::getInstance()
#4 /home/arasetne/public_html/wp-includes/class-wp-hook.php(324): DGWT_WCAS('' in /home/arasetne/public_html/wp-content/plugins/ajax-search-for-woocommerce/includes/Integrations/Plugins/WooCommerce/WooCommerce.php on line 23