settings['result_count_redraw']) AND $this->settings['result_count_redraw']) {
ob_start();
woocommerce_result_count();
WOOF_REQUEST::push('woof_redraw_elements', ob_get_contents(), $this->settings['result_count_redraw']);
ob_end_clean();
}
if (isset($this->settings['order_dropdown_redraw']) AND $this->settings['order_dropdown_redraw']) {
ob_start();
woocommerce_catalog_ordering();
WOOF_REQUEST::push('woof_redraw_elements', ob_get_contents(), $this->settings['order_dropdown_redraw']);
ob_end_clean();
}
if (isset($this->settings['per_page_redraw']) AND $this->settings['per_page_redraw']) {
ob_start();
woocommerce_pagination();
WOOF_REQUEST::push('woof_redraw_elements', ob_get_contents(), $this->settings['per_page_redraw']);
ob_end_clean();
}
WOOF_REQUEST::set('woof_redraw_elements', apply_filters('woof_redraw_elements_after_ajax', WOOF_REQUEST::get('woof_redraw_elements'), $products));
//+++
?>
have_posts()) :
add_filter('post_class', array($this, 'woo_post_class'));
WOOF_REQUEST::set('woof_before_shop_loop_done', true);
?>
have_posts()) : $products->the_post();
wc_get_template_part('content', $template_part);
endwhile; // end of the loop.
} else {
if (!empty($tpl_index)) {
//template extension drawing
if (isset(WOOF_EXT::$includes['applications'][$tpl_index])) {
WOOF_EXT::$includes['applications'][$tpl_index]->draw($products);
}
} else {
$custom_tpl = str_replace('.' . pathinfo($custom_tpl, PATHINFO_EXTENSION), '', str_replace("..", "", $custom_tpl));
$this->render_html_e(get_theme_file_path($custom_tpl . ".php"), array(
'the_products' => $products
));
}
}
?>
=')) {
wc_reset_loop();
}
//+++
WOOF_REQUEST::del('woof_products_doing');
return ob_get_clean();
}
//for shortcode woof_products
public function woo_post_class($classes) {
global $post;
$classes[] = 'product';
$classes[] = 'type-product';
$classes[] = 'status-publish';
$classes[] = 'has-post-thumbnail';
$classes[] = 'post-' . $post->ID;
return $classes;
}
//shortcode, works when ajax mode only for shop/category page
public function woof_draw_products() {
if (WOOF_REQUEST::isset('link')) {
$link = parse_url(WOOF_REQUEST::get('link'), PHP_URL_QUERY);
$query_array = WOOF_HELPER::safe_parse_str($link);
$_GET = apply_filters('woof_draw_products_get_args', wc_clean(array_merge($query_array, wc_clean($_GET))), WOOF_REQUEST::get('link'));
}
$product_ids = "";
if (WOOF_REQUEST::isset('turbo_mode_ids')) {
$product_ids = " product_ids='" . sanitize_text_field(WOOF_REQUEST::get('turbo_mode_ids')) . "' ";
}
$shortcode_str = $this->check_shortcode("woof_products", "[" . WOOF_REQUEST::get('shortcode') . " page=" . WOOF_REQUEST::get('page') . $product_ids . "]");
$products = do_shortcode($shortcode_str);
$additional_fields = array();
if (WOOF_REQUEST::get('woof_redraw_elements')) {
$additional_fields = WOOF_HELPER::sanitize_html_fields_array(WOOF_REQUEST::get('woof_redraw_elements'));
}
if (isset($_GET["woof_redraw_elements"]) AND $_GET["woof_redraw_elements"]) {
$additional_fields = array_merge($additional_fields, WOOF_HELPER::sanitize_html_fields_array($_GET['woof_redraw_elements']));
}
//+++
$form = '';
if (WOOF_REQUEST::isset('woof_shortcode')) {//if search form on the page exists
$text = "";
$shortcode_str = "";
$woof_shortcode_str = wp_kses_post(wp_unslash(WOOF_REQUEST::get('woof_shortcode')));
if (empty(WOOF_REQUEST::get('woof_additional_taxonomies_string'))) {
$text = "[" . stripslashes($woof_shortcode_str) . "]";
} else {
$taxonomies_str = sanitize_text_field(WOOF_REQUEST::get('woof_additional_taxonomies_string'));
$text = "[" . stripslashes($woof_shortcode_str . " taxonomies={$taxonomies_str}]");
}
$shortcode_str = $this->check_shortcode("woof", $text);
//for data-shortcode in woof.php in ajax mode
if (!empty($shortcode_str)) {
WOOF_REQUEST::set('woof_shortcode_txt', $woof_shortcode_str);
}
//***
$form = trim(do_shortcode($shortcode_str));
}
wp_die(json_encode(compact('products', 'form', 'additional_fields')));
}
public function show_btn($atts) {
return $this->render_html(WOOF_PATH . 'views/shortcodes/woof_show_btn.php', $atts);
}
public function show_mobile_btn($atts) {
if (wp_is_mobile()) {
return $this->render_html(WOOF_PATH . 'views/shortcodes/woof_mobile_btn.php', $atts);
}
return "";
}
//shortcode
public function woof_shortcode($atts) {
$args = array();
//this for synhronizating shortcode woof_products if its has attribute taxonomies
if (isset($atts['taxonomies'])) {
$args['additional_taxes'] = apply_filters('woof_set_shortcode_taxonomyattr_behaviour', $atts['taxonomies']);
} else {
$args['additional_taxes'] = '';
}
//by hands excluded terms directly in [woof] shortcode
WOOF_REQUEST::del('woof_shortcode_excluded_terms');
if (isset($atts['excluded_terms'])) {
WOOF_REQUEST::set('woof_shortcode_excluded_terms', $atts['excluded_terms']);
}
if (isset($atts['mobile_mode'])) {
$args['mobile_mode'] = $atts['mobile_mode'];
}
//+++
$taxonomies = $this->get_taxonomies();
$allow_taxonomies = (array) (isset($this->settings['tax']) ? $this->settings['tax'] : array());
if (isset($atts['tax_only'])) {
$args['tax_only'] = explode(',', $atts['tax_only']);
$args['tax_only'] = array_map('trim', $args['tax_only']);
} else {
$args['tax_only'] = array();
}
$args['woof_settings'] = get_option('woof_settings', array());
//overrides taxonomy display with shortcode attributes
foreach ($args['tax_only'] as $tax_filter_key) {
if (!isset($allow_taxonomies[$tax_filter_key])) {
$allow_taxonomies[$tax_filter_key] = 1;
$this->settings['tax'][$tax_filter_key] = 1;
$args['woof_settings']['tax'][$tax_filter_key] = 1;
}
}
//+++
$args['taxonomies'] = array();
$hide_empty = (bool) get_option('woof_hide_dynamic_empty_pos', 0);
if (!empty($taxonomies)) {
foreach ($taxonomies as $tax_key => $tax) {
if (!in_array($tax_key, array_keys($allow_taxonomies))) {
continue;
}
//+++
$args['taxonomies_info'][$tax_key] = $tax;
$args['taxonomies'][$tax_key] = WOOF_HELPER::get_terms($tax_key, $hide_empty);
//show only subcategories if is_really_current_term_exists
if ($this->is_really_current_term_exists()) {
$t = $this->get_really_current_term();
if ($tax_key == $t->taxonomy) {
if (isset($args['taxonomies'][$tax_key][$t->term_id]) && !empty($args['taxonomies'][$tax_key][$t->term_id]['childs'])) {
$args['taxonomies'][$tax_key] = $args['taxonomies'][$tax_key][$t->term_id]['childs'];
} else {
if ($t->parent != 0) {
$parent = get_term($t->parent, $tax_key);
$parents_ids = array();
$parents_ids[] = $parent->term_id;
while ($parent->parent != 0) {
$parent = get_term_by('id', $parent->parent, $tax_key);
$parents_ids[] = $parent->term_id;
}
$parents_ids = array_reverse($parents_ids);
//***
$tmp = $args['taxonomies'][$tax_key];
foreach ($parents_ids as $id) {
$tmp = $tmp[$id]['childs'];
}
if (isset($tmp[$t->term_id])) {
$args['taxonomies'][$tax_key] = $tmp[$t->term_id]['childs'];
}
}
}
}
}
}
} else {
$args['taxonomies'] = array();
}
//***
if (isset($atts['skin'])) {
wp_enqueue_style('woof_skin_' . $atts['skin'], WOOF_LINK . 'css/shortcode_skins/' . $atts['skin'] . '.css', array(), WOOF_VERSION);
}
//***
if (isset($atts['sid'])) {
$args['sid'] = $atts['sid'];
wp_enqueue_script('woof_sid', WOOF_LINK . 'js/woof_sid.js', array('jquery'), WOOF_VERSION);
}
if (isset($atts['autohide'])) {
$args['autohide'] = $atts['autohide'];
} else {
$args['autohide'] = 0;
}
if (isset($atts['redirect'])) {
$args['redirect'] = $atts['redirect'];
} else {
$args['redirect'] = '';
}
if (isset($atts['start_filtering_btn'])) {
$args['start_filtering_btn'] = intval($atts['start_filtering_btn']);
} else {
$args['start_filtering_btn'] = 0;
}
if (isset($atts['start_filtering_btn_txt'])) {
$args['woof_start_filtering_btn_txt'] = $atts['start_filtering_btn_txt'];
} else {
$args['woof_start_filtering_btn_txt'] = apply_filters('woof_start_filtering_btn_txt', esc_html__('Show products filter form', 'woocommerce-products-filter'));
}
if (isset($atts['tax_exclude'])) {
$args['tax_exclude'] = explode(',', $atts['tax_exclude']);
$args['tax_exclude'] = array_map('trim', $args['tax_exclude']);
} else {
$args['tax_exclude'] = array();
}
if (isset($atts['by_only'])) {
$args['by_only'] = explode(',', $atts['by_only']);
$args['by_only'] = array_map('trim', $args['by_only']);
} else {
$args['by_only'] = array();
}
if (isset($atts['autosubmit']) AND $atts['autosubmit'] != -1) {
$args['autosubmit'] = $atts['autosubmit'];
} else {
$args['autosubmit'] = get_option('woof_autosubmit', 0);
}
WOOF_REQUEST::set('hide_terms_count_txt_short', -1);
if (isset($atts['hide_terms_count'])) {
WOOF_REQUEST::set('hide_terms_count_txt_short', intval($atts['hide_terms_count']));
}
if (isset($atts['ajax_redraw'])) {
$args['ajax_redraw'] = $atts['ajax_redraw'];
} else {
$args['ajax_redraw'] = 0;
}
if (isset($atts['btn_position'])) {
$args['btn_position'] = $atts['btn_position'];
} else {
$args['btn_position'] = 'b';
}
if (isset($atts['dynamic_recount'])) {
$args['dynamic_recount'] = $atts['dynamic_recount'];
} else {
$args['dynamic_recount'] = -1;
}
$args['price_filter'] = 0;
if (isset($this->settings['by_price']['show'])) {
$args['price_filter'] = (int) $this->settings['by_price']['show'];
}
if (isset($atts['by_step'])) {
$args['by_step'] = $atts['by_step'];
}
//for front builder
if (isset($atts['swoof_slug']) AND !empty($atts['swoof_slug'])) {
$args['swoof_slug'] = $atts['swoof_slug'];
}
//***
$args['show_woof_edit_view'] = 0;
if (current_user_can('create_users')) {
$args['show_woof_edit_view'] = isset($this->settings['show_woof_edit_view']) ? (int) $this->settings['show_woof_edit_view'] : 0;
}
//lets assemble shortcode txt for ajax mode for data-shortcode in woof.php
WOOF_REQUEST::set('woof_shortcode_txt', 'woof ');
if (!empty($atts)) {
foreach ($atts as $key => $value) {
if (($key == 'tax_only' OR $key == 'by_only' OR $key == 'tax_exclude') AND empty($value)) {
continue;
}
WOOF_REQUEST::set('woof_shortcode_txt', WOOF_REQUEST::get('woof_shortcode_txt') . $key . "='" . (is_array($value) ? explode(',', $value) : $value) . "' ");
}
}
//+++
if (isset($atts['items_order'])) {
$items_order = explode(',', $atts['items_order']);
add_filter('woof_custom_filter_items_order', function ($order)use ($items_order) {
return $items_order;
});
}
//+++
$args['shortcode_atts'] = $atts;
//+++
$genuine_settings = woof()->settings; //do manipulations on the fly for this filter instance only
if (isset($atts['viewtypes'])) {
$viewtypes = explode(',', $atts['viewtypes']);
foreach ($viewtypes as $pair) {
$val = explode(':', $pair);
if (isset(woof()->settings['tax_type'][$val[0]])) {
woof()->settings['tax_type'][$val[0]] = $val[1];
}
}
}
//use with great care, #1 for filter sections options
$args['woof_settings'] = woof()->settings = apply_filters('woof_modify_settings_before_action', woof()->settings, $atts);
//in this place can be overloaded all settings personally for the current filter instance
if (isset($atts['by_only']) AND !empty($atts['by_only'])) {
$by_only = explode(',', $atts['by_only']);
if (is_array($by_only)) {
foreach ($by_only as $by_only_key) {
$val = 1;
//exclusive exception for price
if ($by_only_key === 'by_price') {
$val = intval(woof()->settings[$by_only_key]['show']);
}
//hook woof_regulate_by_only_show is need here only for price filter because its view depends of this value: 1,2,3,4,5
woof()->settings[$by_only_key]['show'] = apply_filters('woof_regulate_by_only_show', $val, $by_only_key);
}
}
}
$html = $this->render_html(WOOF_PATH . 'views/woof.php', apply_filters('woof_filter_shortcode_args', $args));
woof()->settings = $genuine_settings;
return $html;
}
//shortcode
public function woof_price_filter($args = array()) {
if (!is_array($args)) {
$args = array();
}
$type = 'slider';
if (isset($args['type']) AND $args['type'] == 'select') {
$type = 'select';
}
if (isset($args['type']) AND $args['type'] == 'text') {
$type = 'text';
}
if (isset($args['type']) AND $args['type'] == 'radio') {
$type = 'radio';
}
if (!isset($args['range_min'])) {
$args['range_min'] = null;
}
if (!isset($args['range_max'])) {
$args['range_max'] = null;
}
return $this->render_html(WOOF_PATH . 'views/shortcodes/woof_price_filter_' . $type . '.php', $args);
}
//shortcode
public function woof_search_options($args = array()) {
return $this->render_html(WOOF_PATH . 'views/shortcodes/woof_search_options.php', array());
}
//shortcode
public function woof_found_count($args = array()) {
return $this->render_html(WOOF_PATH . 'views/shortcodes/woof_found_count.php', array());
}
//redraw search form
public function woof_redraw_woof() {
$shortcode = sanitize_text_field(WOOF_REQUEST::get('shortcode'));
WOOF_REQUEST::set('woof_shortcode_txt', $shortcode);
$shortcode_str = $this->check_shortcode("woof", "[" . $shortcode . "]");
wp_die(do_shortcode($shortcode_str));
}
public function woocommerce_pagination_args($args) {
return $args;
}
//if we are on the category products page, or any another product taxonomy page
public function get_really_current_term() {
if (wc_current_theme_is_fse_theme()) {
if (!defined('DOING_AJAX') && !is_page()) {
global $wp_query;
$queried_obj = get_queried_object();
if (isset($wp_query->query_vars['taxonomy']) and is_object($queried_obj) and get_class(get_queried_object()) == 'WP_Term' and !isset($request_data['really_curr_tax'])) {
if (is_object($queried_obj)) {
$this->set_really_current_term($queried_obj);
}
} elseif (isset($request_data['really_curr_tax'])) {
$tmp = explode('-', $request_data['really_curr_tax'], 2);
$res = get_term($tmp[0], $tmp[1]);
$this->set_really_current_term($res);
} else {
$this->set_really_current_term();
}
}
}
$res = NULL;
$key = $this->session_rct_key;
$request = $this->get_request_data(FALSE);
if ($this->storage->is_isset($key)) {
$res = $this->storage->get_val($key);
}
if (!$res) {
if (isset($request['really_curr_tax'])) {
$tmp = explode('-', $request['really_curr_tax']);
if (isset($tmp[1])) {
$res = get_term($tmp[0], $tmp[1]);
}
}
}
return $res;
}
public function is_really_current_term_exists() {
return (bool) $this->get_really_current_term();
}
//we need it when making search on the category page == any taxonomy term page
private function set_really_current_term($queried_obj = NULL) {
if (defined('DOING_AJAX')) {
return false;
}
$request = $this->get_request_data();
if (!$queried_obj) {
if (isset($request['really_curr_tax'])) {
return false;
}
}
$key = $this->session_rct_key;
if ($queried_obj === NULL) {
$this->storage->unset_val($key);
} else {
$this->storage->set_val($key, $queried_obj);
}
return $queried_obj;
}
//ajax + wp_cron
public function cache_count_data_clear() {
global $wpdb;
$wpdb->query("TRUNCATE TABLE " . self::$query_cache_table);
}
//ajax only
public function woof_cache_terms_clear() {
global $wpdb;
$res = $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name LIKE '_transient_woof_terms_cache_%'");
if (!empty($res)) {
foreach ($res as $transient) {
delete_transient(str_replace('_transient_', '', $transient->option_name));
}
}
//wp_die('done');
}
public function woof_price_transient_clear() {
delete_transient('woof_min_max_prices');
}
//Display Product for WooCommerce compatibility
public function woof_modify_query_args($query_args) {
if (WOOF_REQUEST::isset($this->get_swoof_search_slug())) {
if (WOOF_REQUEST::isset('woof_wp_query_args')) {
$WP_Meta_Query = new WP_Meta_Query();
$query_args['meta_query'] = $WP_Meta_Query->sanitize_query(WOOF_REQUEST::get('woof_wp_query_args', 'meta_query'));
$WP_Tax_Query = new WP_Tax_Query();
$query_args['tax_query'] = $WP_Tax_Query->sanitize_query(WOOF_REQUEST::get('woof_wp_query_args', 'tax_query'));
$query_args['paged'] = intval(WOOF_REQUEST::get('woof_wp_query_args', 'paged'));
}
}
return $query_args;
}
public function get_custom_ext_path($relative = '') {
if (!isset($this->settings['custom_extensions_path'])) {
return '';
}
//***
if (!empty($relative)) {
$relative = trim($relative, DIRECTORY_SEPARATOR);
$relative .= DIRECTORY_SEPARATOR;
}
return WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $this->settings['custom_extensions_path'] . DIRECTORY_SEPARATOR . $relative;
}
public function get_custom_ext_link($relative = '') {
if (!empty($relative)) {
$relative = trim($relative, DIRECTORY_SEPARATOR);
$relative .= DIRECTORY_SEPARATOR;
}
return WP_CONTENT_URL . DIRECTORY_SEPARATOR . $this->settings['custom_extensions_path'] . DIRECTORY_SEPARATOR . $relative;
}
public function get_ext_directories() {
$directories = array();
$directories['default'] = glob(WOOF_EXT_PATH . '*', GLOB_ONLYDIR);
$directories['custom'] = array();
if (isset($this->settings['custom_extensions_path']) AND !empty($this->settings['custom_extensions_path'])) {
if ($this->get_custom_ext_path()) {
$directories['custom'] = glob($this->get_custom_ext_path() . '*', GLOB_ONLYDIR);
}
}
return $directories;
}
public function control_extension_by_key($key, $activate) {
$directories = $this->get_ext_directories();
if (isset($this->settings['activated_extensions'])) {
$activated = (array) $this->settings['activated_extensions'];
} else {
$activated = [];
}
//*** default exts
if (!empty($directories['default']) AND is_array($directories['default'])) {
foreach ($directories['default'] as $path) {
if (strrpos($path . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR) !== false) {
$idx = WOOF_EXT::get_ext_idx_new($path);
$key = array_search($idx, $activated);
if ($activate && $key === false) {
//add
$activated[] = $idx;
$this->settings['activated_extensions'] = $activated;
update_option('woof_settings', $this->settings);
}
if (!$activate && $key !== false) {
//delete
unset($activated[$key]);
$this->settings['activated_extensions'] = $activated;
update_option('woof_settings', $this->settings);
}
}
}
}
}
//initialization of extensions
public function init_extensions() {
$directories = $this->get_ext_directories();
if (isset($this->settings['activated_extensions'])) {
$activated = $this->settings['activated_extensions'];
} else {
$activated = array();
}
//for extensions defined by user (custom ext)
if (!empty($directories['custom']) AND is_array($directories['custom'])) {
if (!is_array($activated)) {
$activated = array();
}
foreach ($directories['custom'] as $path) {
//if (in_array(md5($path), $activated))
if (WOOF_EXT::is_ext_activated($path)) {
include_once $path . DIRECTORY_SEPARATOR . 'index.php';
}
}
}
//*** default exts
if (!empty($directories['default']) AND is_array($directories['default'])) {
if (!is_array($activated)) {
$activated = array();
}
foreach ($directories['default'] as $path) {
//if (in_array(md5($path), $activated))
if (WOOF_EXT::is_ext_activated($path)) {
include_once $path . DIRECTORY_SEPARATOR . 'index.php';
}
}
}
//hooked feature for extensions
$this->html_types = apply_filters('woof_add_html_types', $this->html_types);
//hooked feature for extensions
$this->items_keys = apply_filters('woof_add_items_keys', $this->items_keys);
}
//ajax
public function woof_remove_ext() {
if (!current_user_can('manage_woocommerce') OR !current_user_can('activate_plugins')) {
return;
}
check_ajax_referer('rm-ext-nonce', 'rm_ext_nonce');
if (!wp_verify_nonce(WOOF_REQUEST::get('rm_ext_nonce'), 'rm-ext-nonce')) {
die('Stop!');
}
//***
$idx = WOOF_REQUEST::get('idx');
$directories = array();
if ($this->get_custom_ext_path()) {
$directories = glob($this->get_custom_ext_path() . '*', GLOB_ONLYDIR);
}
if (!empty($directories)) {
foreach ($directories as $dir) {
if (WOOF_EXT::get_ext_idx_new($dir) == $idx) {
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $file) {
if ($file->isDir()) {
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
rmdir($dir);
}
}
die('done');
}
die('fail');
}
function generator_get_taxonomy_terms() {
if (WOOF_REQUEST::get('taxonomy') == null || WOOF_REQUEST::get('taxonomy') == -1 || !WOOF_REQUEST::get('taxonomy')) {
wp_send_json(array());
}
$terms = WOOF_HELPER::get_terms(WOOF_REQUEST::get('taxonomy'), false);
wp_send_json($terms);
}
function woof_upload_ext() {
if (!current_user_can('manage_woocommerce') OR !current_user_can('activate_plugins')) {
return;
}
check_ajax_referer('add-ext-nonce', 'extnonce');
if (!wp_verify_nonce(WOOF_REQUEST::get('extnonce'), 'add-ext-nonce')) {
die('Stop!');
}
//require(WOOF_PATH . 'lib/simple-ajax-uploader/extras/Uploader.php');
$upload_dir = WOOF_HELPER::get_server_var('HTTP_LOCATION');
$valid_extensions = array('zip');
$Upload = new FileUpload('uploadfile');
$result = $Upload->handleUpload($upload_dir, $valid_extensions);
//***
$zipArchive = new ZipArchive();
$zip_result = $zipArchive->open($Upload->getSavedFile());
$ext_info = array();
if ($zip_result === TRUE) {
$zipArchive->extractTo($upload_dir);
$zipArchive->close();
$dir = $upload_dir . str_replace('.zip', '', $Upload->getFileName());
$ext_info = WOOF_HELPER::parse_ext_data($dir . '/info.dat');
$ext_info['idx'] = md5($dir);
unlink($Upload->getSavedFile());
}
if (!$result) {
die(json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg())));
} else {
die(json_encode(array('success' => true, 'ext_info' => $ext_info)));
}
}
public function is_permalink_activated() {
return get_option('permalink_structure', '');
}
public function get_option($key, $default = 0) {
$res = $default;
if (isset($this->settings[$key])) {
$res = $this->settings[$key];
}
return $res;
}
private function is_should_init() {
if (is_admin() || apply_filters('woof_disable_filter', false)) {
return true;
}
//do not exclude in widget page
if (isset($_SERVER['SCRIPT_URI'])) {
$uri = parse_url(trim(WOOF_HELPER::get_server_var('SCRIPT_URI')));
$uri = explode('/', trim($uri['path'], ' /'));
if ($uri[0] === 'wp-json') {
$show_legacy = array('widget-types', 'sidebars', 'widgets', 'batch');
$match = array_intersect($show_legacy, $uri);
if (count($match) != 0) {
$this->is_activated = true;
return true;
}
}
}
//stop loading the plugins filters and its another functionality on all pages of the site
if (isset($this->settings['init_only_on']) AND !empty($this->settings['init_only_on'])) {
$links = explode(PHP_EOL, trim($this->settings['init_only_on']));
$server_link = '';
if (isset($_SERVER['SCRIPT_URI'])) {
$server_link = WOOF_HELPER::get_server_var('SCRIPT_URI');
} else {
if (isset($_SERVER['REQUEST_URI'])) {
$server_link = site_url() . WOOF_HELPER::get_server_var('REQUEST_URI');
}
}
//***
$removeChar = ["https://", "http://", "/"];
$init = true;
if (!empty($server_link)) {
if (stripos($server_link, '/' . $this->get_swoof_search_slug() . '/') !== false) {
$this->is_activated = true;
return true;
}
$server_link_mask = str_replace($removeChar, '', trim(stripcslashes($server_link), " /"));
if (isset($this->settings['init_only_on_reverse']) AND $this->settings['init_only_on_reverse']) {
$init = true;
} else {
$init = false;
}
foreach ($links as $key => $pattern_url) {
$pattern_url = str_replace($removeChar, '', trim(stripcslashes($pattern_url), " /"));
$use_mask = true;
if (stripos($pattern_url, '#') === 0) {
$pattern_url = trim(ltrim($pattern_url, "#"));
$use_mask = false;
}
if ($use_mask) {
preg_match('/(.+)?' . trim($pattern_url) . '(.+)?/', $server_link_mask, $matches);
$init_tmp = !empty($matches);
} else {
$init_tmp = ($pattern_url == $server_link_mask);
}
if (isset($this->settings['init_only_on_reverse']) AND $this->settings['init_only_on_reverse']) {
if ($init_tmp) {
$init = false;
break;
}
} else {
if ($init_tmp) {
$init = true;
break;
}
}
}
if ($init) {
$this->is_activated = true;
return true;
}
}
} else {
return true;
}
return false;
}
public function render_html_e($pagepath, $data = array()) {
if (isset($data['pagepath'])) {
unset($data['pagepath']);
}
if (is_array($data) AND !empty($data)) {
extract($data);
}
$pagepath = realpath(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $pagepath));
if (!$pagepath) {
return;
}
include($pagepath);
}
public function render_html($pagepath, $data = array()) {
if (isset($data['pagepath'])) {
unset($data['pagepath']);
}
if (is_array($data) AND !empty($data)) {
extract($data);
}
$pagepath = realpath(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $pagepath));
if (!$pagepath) {
return '';
}
ob_start();
include($pagepath);
return ob_get_clean();
}
//******************************************* FEATURES SUGGESTIONS ***************************************************
public function woof_sort_terms_is_checked($terms = [], $type = 'checkbox') {
if (!is_array($terms)) {
$terms = [];
}
$not_sort_terms = apply_filters('woof_not_sort_checked_terms', array('slider'));
if (in_array($type, $not_sort_terms)) {
return $terms;
}
$request = $this->get_request_data();
$temp_term = current($terms);
if (!is_array($temp_term)) {
return $terms;
}
//if selected logic NOT IN
if (isset($this->settings["comparison_logic"][$temp_term['taxonomy']]) && $this->settings["comparison_logic"][$temp_term['taxonomy']] == 'NOT IN') {
$temp_term['taxonomy'] = 'rev_' . $temp_term['taxonomy'];
}
if ($this->is_isset_in_request_data($temp_term['taxonomy'])) {
$current_request = explode(',', urldecode($request[$temp_term['taxonomy']]));
} else {
return $terms;
}
$temp_array = array();
foreach ($terms as $key => $val) {
if (in_array($val['slug'], $current_request)) {
$temp_array[$key] = $val;
}
}
foreach ($temp_array as $key => $val) {
unset($terms[$key]);
}
return array_merge($temp_array, $terms);
}
//***
// woo3.3
public function set_loop_properties($query, $columns) {
wc_set_loop_prop('is_paginated', true);
wc_set_loop_prop('total_pages', $query->max_num_pages);
wc_set_loop_prop('current_page', (int) max(1, $query->get('paged', 1)));
wc_set_loop_prop('per_page', (int) $query->get('posts_per_page'));
wc_set_loop_prop('total', (int) $query->found_posts);
wc_set_loop_prop('columns', $columns);
wc_set_loop_prop('is_filtered', true);
}
public function product_visibility_not_in($tax_query, $keys) {
$arr_ads = wc_get_product_visibility_term_ids();
$product_not_in = array();
if (!is_array($keys)) {
$keys = array($keys);
}
foreach ($keys as $key) {
if (isset($arr_ads[$key]) OR !empty($arr_ads[$key])) {
$product_not_in[] = $arr_ads[$key];
}
}
if (!empty($product_not_in)) {
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => $product_not_in,
'operator' => 'NOT IN',
);
}
return $tax_query;
}
public function woof_overide_template($template, $template_name, $template_path) {
if ($template_name == 'loop/no-products-found.php') {
if (isset($this->settings['override_no_products']) AND !empty($this->settings['override_no_products'])) {
WOOF_REQUEST::set('override_no_products', 1);
$template = WOOF_PATH . 'views/no-products-found.php';
}
}
return $template;
}
public function generate_visibility_keys($search = false) {
$keys = array();
if ('yes' === get_option('woocommerce_hide_out_of_stock_items')) {
$keys[] = 'outofstock';
}
if ($this->get_option('listen_catalog_visibility')) {
$keys[] = 'exclude-from-search';
if (!$search) {
$keys[] = 'exclude-from-catalog';
}
}
return $keys;
}
public function product_visibility_for_parse_query() {
add_filter('woocommerce_product_query_tax_query', function ($tax_query, $_this) {
foreach ($tax_query as $key => $tax) {
if (isset($tax['taxonomy']) AND $tax['taxonomy'] == 'product_visibility') {
unset($tax_query[$key]);
}
}
return $this->product_visibility_not_in($tax_query, $this->generate_visibility_keys(true));
}, 10, 2);
add_filter('woocommerce_product_is_visible', function ($visible, $id) {
return true;
}, 10, 2);
}
//+++
public function check_shortcode($tag = "", $text = "") {
$tags = array(
'products_woof',
'recent_products_woof',
'sale_products_woof',
'best_selling_products_woof',
'top_rated_products_woof',
'featured_products_woof',
$tag
);
$pattern = get_shortcode_regex($tags);
preg_match_all("/$pattern/", $text, $matches);
if (isset($matches[0][0]) AND !empty($matches[0][0])) {
return $matches[0][0];
} else {
return "";
}
}
public function get_wppp_per_page() {
$per_page = 12;
if (WOOF_REQUEST::isset('wppp_ppp')) {
$per_page = intval(WOOF_REQUEST::get('wppp_ppp'));
} elseif (WOOF_REQUEST::isset('ppp')) {
$per_page = intval(WOOF_REQUEST::get('ppp'));
} elseif (isset($_COOKIE['woocommerce_products_per_page'])) {
$per_page = intval($_COOKIE['woocommerce_products_per_page']);
} else {
$per_page = intval(get_option('wppp_default_ppp', '12'));
}
return $per_page;
}
public function activate_woo_shortcodes() {
$shortcodes = array(
'products',
'recent_products',
'sale_products',
'best_selling_products',
'top_rated_products',
'featured_products',
);
foreach ($shortcodes as $tag) {
add_shortcode(esc_attr($tag) . "_woof", array($this, 'woof_ajax_shortcode'));
add_action('woocommerce_shortcode_' . $tag . '_loop_no_results', function () {
do_action('woocommerce_no_products_found');
}, 10, 1);
}
}
public function woof_ajax_shortcode($atts, $content, $tag) {
$attr_str = "";
if (is_array($atts)) {
foreach ($atts as $key => $val) {
if (is_int($key)) {
$attr_str .= " " . $val;
} else {
$attr_str .= sprintf(" %s='%s'", $key, $val);
}
}
}
$shortcode = str_replace("_woof", "", $tag);
ob_start();
?>
settings['orderby'][$tax])) {
$orberby = $this->settings['orderby'][$tax];
}
if (isset($this->settings['order'][$tax])) {
$orber = $this->settings['order'][$tax];
}
if ($orberby != -1) {
switch ($orberby) {
case'id':
if ($orber == 'ASC') {
uasort($terms, function ($a, $b) {
if ((int) $a['term_id'] == (int) $b['term_id']) {
return 0;
}
return ((int) $a['term_id'] < (int) $b['term_id']) ? -1 : 1;
});
} else {
uasort($terms, function ($a, $b) {
if ((int) $a['term_id'] == (int) $b['term_id']) {
return 0;
}
return ((int) $a['term_id'] > (int) $b['term_id']) ? -1 : 1;
});
}
break;
case'name':
if ($orber == 'ASC') {
uasort($terms, function ($a, $b) {
return strnatcasecmp($a['name'], $b['name']);
});
} else {
uasort($terms, function ($a, $b) {
return strnatcasecmp($b['name'], $a['name']);
});
}
break;
case'numeric':
if ($orber == 'ASC') {
uasort($terms, function ($a, $b) {
if ((int) $a['slug'] == (int) $b['slug']) {
return 0;
}
return ((int) $a['slug'] < (int) $b['slug']) ? -1 : 1;
});
} else {
uasort($terms, function ($a, $b) {
if ((int) $a['slug'] == (int) $b['slug']) {
return 0;
}
return ((int) $a['slug'] > (int) $b['slug']) ? -1 : 1;
});
}
break;
}
}
return $terms;
}
public function change_query_tax_relations($logic_array) {
$logic_arr = array();
if (isset($this->settings['comparison_logic'])) {
$logic_arr = $this->settings['comparison_logic'];
}
foreach ($logic_arr as $cat => $logic) {
if ($logic == 'AND' OR $logic == 'NOT IN') {
$logic_array[$cat] = $logic;
}
}
return $logic_array;
}
public function replacing_template_loop_product_thumbnail() {
$show = 0;
if (isset($this->settings['show_images_by_attr_show'])) {
$show = $this->settings['show_images_by_attr_show'];
}
if ($show) {
//for another wp themes add compatibility in the current function
if (class_exists('Flatsome_Default')) {
//flatsome theme compatibility
remove_action('flatsome_woocommerce_shop_loop_images', 'woocommerce_template_loop_product_thumbnail', 10);
add_action('flatsome_woocommerce_shop_loop_images', array($this, 'wc_template_loop_product_replaced_thumb'), 10);
} else {
// Remove product images from the shop loop
remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
// Adding something instead
add_action('woocommerce_before_shop_loop_item_title', array($this, 'wc_template_loop_product_replaced_thumb'), 10);
}
}
}
public function wc_template_loop_product_replaced_thumb() {
global $product;
$needed = array();
if (isset($this->settings['show_images_by_attr'])) {
$needed = $this->settings['show_images_by_attr'];
}
if (is_array($needed) AND count($needed)) {
if ($this->is_isset_in_request_data($this->get_swoof_search_slug()) AND $product->is_type("variable")) {
$need_array = array();
$request = $this->get_request_data();
$need_array = array_intersect_key($request, array_flip($needed));
$rate = array();
if (count($need_array)) {
$variations = $product->get_available_variations();
foreach ($variations as $key => $variant) {
if (isset($variant['attributes'])) {
$rate[$key] = 0;
foreach ($need_array as $attr_name => $values) {
if (isset($variant['attributes']["attribute_" . $attr_name]) AND in_array($variant['attributes']["attribute_" . $attr_name], explode(",", $values))) {
$rate[$key]++;
}
}
}
}
arsort($rate);
$attr_key = array_key_first($rate);
if (array_shift($rate)) {
if (isset($variations[$attr_key]["image_id"]) AND $variations[$attr_key]["image_id"]) {
$image_size = apply_filters('single_product_archive_thumbnail_size', 'woocommerce_thumbnail');
$image = wp_get_attachment_image($variations[$attr_key]["image_id"], $image_size, false, array());
if ($image) {
echo wp_kses_post(wp_unslash($image));
return;
}
}
}
}
}
}
echo woocommerce_get_product_thumbnail();
}
public function woopt_set_query_args($query_args) {
if ($this->is_isset_in_request_data($this->get_swoof_search_slug())) {
WOOF_REQUEST::set('woof_products_doing', 1);
$query_args['tax_query'] = array_merge($query_args['tax_query'], $this->get_tax_query(''));
$query_args['meta_query'] = array_merge($query_args['meta_query'], $this->get_meta_query());
$query_args = apply_filters('woof_products_query', $query_args);
if (isset($_GET['paged'])) {
$query_args['paged'] = intval($_GET['paged']);
}
}
return $query_args;
}
function sync_on_product_save($product_id, $prod) {
if (isset($this->settings['price_transient']) AND $this->settings['price_transient']) {
woof_price_transient_clear();
}
}
public function parse_tax_query($tax_query) {
$request = $this->get_request_data();
$array_logic = $this->change_query_tax_relations(array());
foreach ($array_logic as $key => $logic) {
if ($logic == "NOT IN" AND isset($request[$this->check_slug($key)])) {
$terms = explode(",", $request[$this->check_slug($key)]);
$tax_query[] = array(
"taxonomy" => $key,
"terms" => $terms,
"field" => "slug",
"operator" => "NOT IN"
);
}
}
return $tax_query;
}
public function check_slug($slug) {
$array_logic = $this->change_query_tax_relations(array());
if (isset($array_logic[$slug]) AND $array_logic[$slug] == 'NOT IN') {
$slug = 'rev_' . $slug;
}
return $slug;
}
public function uncheck_slug($slug) {
$slug = preg_replace("@^rev_@", '', $slug);
return $slug;
}
public function add_shortcode_generator() {
if (isset($_GET['tab']) AND $_GET['tab'] == 'woof') {
$args = array();
$this->render_html_e(WOOF_PATH . 'views/shortcode_generator.php', $args);
}
}
public function get_price_filter_types() {
return [
0 => esc_html__('No', 'woocommerce-products-filter'),
1 => esc_html__('As woo range-slider', 'woocommerce-products-filter'),
2 => esc_html__('As drop-down', 'woocommerce-products-filter'),
3 => esc_html__('As ion range-slider', 'woocommerce-products-filter'),
4 => esc_html__('As textinputs', 'woocommerce-products-filter'),
5 => esc_html__('As radio button', 'woocommerce-products-filter'),
];
}
public function get_icheck_skins() {
return array(
'none' => array('none'),
'flat' => array(
'flat_aero',
'flat_blue',
'flat_flat',
'flat_green',
'flat_grey',
'flat_orange',
'flat_pink',
'flat_purple',
'flat_red',
'flat_yellow'
),
'minimal' => array(
'minimal_aero',
'minimal_blue',
'minimal_green',
'minimal_grey',
'minimal_minimal',
'minimal_orange',
'minimal_pink',
'minimal_purple',
'minimal_red',
'minimal_yellow'
),
'square' => array(
'square_aero',
'square_blue',
'square_green',
'square_grey',
'square_orange',
'square_pink',
'square_purple',
'square_red',
'square_yellow',
'square_square'
)
);
}
}
//***
if (isset($_GET['P3_NOCACHE'])) {
//stupid trick for that who believes in P3
return;
}
//***
$init_the_plugin = true;
//there is no reason to activate the plugin in wp-admin area, exept of the plugin settings page
if (is_admin()) {
$init_the_plugin = false;
}
// //compatybility with elementor
if (isset($_GET['action']) AND $_GET['action'] == 'elementor') {
$init_the_plugin = true;
}
if (defined('DOING_AJAX')) {
$init_the_plugin = true;
}
if (isset($_GET['page']) AND $_GET['page'] == 'wc-settings') {
$init_the_plugin = true;
}
//***
if (isset($_SERVER['SCRIPT_URI']) AND function_exists('basename')) {
$init_pages = array('plugins.php', 'widgets.php', 'term.php', 'edit-tags.php');
//http://stackoverflow.com/questions/7395049/get-last-part-of-url-php
$lastSegment = basename(parse_url(WOOF_HELPER::get_server_var('SCRIPT_URI'), PHP_URL_PATH));
if (in_array($lastSegment, $init_pages)) {
$init_the_plugin = true;
}
} else {
$init_the_plugin = true;
}
//***
if ($init_the_plugin OR isset($_GET['woof_cron_key'])) {
$WOOF = new WOOF();
if ($WOOF->is_activated) {
$GLOBALS['WOOF'] = $WOOF;
add_action('init', array($WOOF, 'init'), 1);
}
}
//clear price transient
add_action('woocommerce_update_product', function ($prod_id, $product = null) {
delete_transient('woof_min_max_prices');
}, 10, 2);
function woof() {
global $WOOF;
return $WOOF;
}