products-compare-for-woocommerce
Last commit date
berocket
6 years ago
css
6 years ago
includes
6 years ago
js
6 years ago
languages
6 years ago
style_templates
6 years ago
templates
6 years ago
loco.xml
6 years ago
main.php
6 years ago
products-compare.php
6 years ago
readme.txt
6 years ago
wpml-config.xml
6 years ago
main.php
1250 lines
| 1 | <?php |
| 2 | define( "BeRocket_Compare_Products_domain", 'products-compare-for-woocommerce'); |
| 3 | define( "Compare_Products_TEMPLATE_PATH", plugin_dir_path( __FILE__ ) . "templates/" ); |
| 4 | load_plugin_textdomain('products-compare-for-woocommerce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/'); |
| 5 | require_once(plugin_dir_path( __FILE__ ).'berocket/framework.php'); |
| 6 | foreach (glob(__DIR__ . "/includes/*.php") as $filename) |
| 7 | { |
| 8 | include_once($filename); |
| 9 | } |
| 10 | include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 11 | foreach (glob(plugin_dir_path( __FILE__ ) . "includes/compatibility/*.php") as $filename) |
| 12 | { |
| 13 | include_once($filename); |
| 14 | } |
| 15 | |
| 16 | class BeRocket_Compare_Products extends BeRocket_Framework { |
| 17 | public $theme_template; |
| 18 | public static $settings_name = 'br-compare-products-options'; |
| 19 | protected static $instance; |
| 20 | protected $plugin_version_capability = 15; |
| 21 | protected $check_init_array = array( |
| 22 | array( |
| 23 | 'check' => 'woocommerce_version', |
| 24 | 'data' => array( |
| 25 | 'version' => '3.0', |
| 26 | 'operator' => '>=', |
| 27 | 'notice' => 'Plugin Products Compare for WooCommerce required WooCommerce version 3.0 or higher' |
| 28 | ) |
| 29 | ), |
| 30 | array( |
| 31 | 'check' => 'framework_version', |
| 32 | 'data' => array( |
| 33 | 'version' => '2.1', |
| 34 | 'operator' => '>=', |
| 35 | 'notice' => 'Please update all BeRocket plugins to the most recent version. Products Compare for WooCommerce is not working correctly with older versions.' |
| 36 | ) |
| 37 | ), |
| 38 | ); |
| 39 | function __construct () { |
| 40 | $this->info = array( |
| 41 | 'id' => 4, |
| 42 | 'lic_id' => 53, |
| 43 | 'version' => BeRocket_Compare_Products_version, |
| 44 | 'plugin' => '', |
| 45 | 'slug' => '', |
| 46 | 'key' => '', |
| 47 | 'name' => '', |
| 48 | 'plugin_name' => 'compare_products', |
| 49 | 'full_name' => __('Products Compare for WooCommerce', 'products-compare-for-woocommerce'), |
| 50 | 'norm_name' => __('Products Compare', 'products-compare-for-woocommerce'), |
| 51 | 'price' => '', |
| 52 | 'domain' => 'products-compare-for-woocommerce', |
| 53 | 'templates' => Compare_Products_TEMPLATE_PATH, |
| 54 | 'plugin_file' => BeRocket_Compare_Products_file, |
| 55 | 'plugin_dir' => __DIR__, |
| 56 | ); |
| 57 | $this->defaults = array( |
| 58 | 'template' => '', |
| 59 | 'general_settings' => array( |
| 60 | 'fast_compare' => '0', |
| 61 | 'hide_same_button' => '1', |
| 62 | 'hide_same_default' => '0', |
| 63 | 'remove_all_compare' => '', |
| 64 | 'addthisID' => '', |
| 65 | 'compare_page' => '', |
| 66 | 'remove_compare_table' => '', |
| 67 | 'attributes' => array(), |
| 68 | 'use_full_screen' => '', |
| 69 | 'compare_template' => 'new-compare', |
| 70 | 'button_position' => 'after_add_to_cart', |
| 71 | ), |
| 72 | 'style_settings' => array( |
| 73 | 'button' => array( |
| 74 | 'bcolor' => '999999', |
| 75 | 'bwidth' => '0', |
| 76 | 'bradius' => '0', |
| 77 | 'fontsize' => '16', |
| 78 | 'fcolor' => '333333', |
| 79 | 'backcolor' => '9999ff', |
| 80 | ), |
| 81 | 'toolbutton' => array( |
| 82 | 'bcolor' => '999999', |
| 83 | 'bwidth' => '0', |
| 84 | 'bradius' => '0', |
| 85 | 'fontsize' => '16', |
| 86 | 'fcolor' => '333333', |
| 87 | 'backcolor' => '9999ff', |
| 88 | ), |
| 89 | 'table' => array( |
| 90 | 'colwidth' => '200', |
| 91 | 'imgwidth' => '', |
| 92 | 'toppadding' => '0', |
| 93 | 'backcolor' => 'ffffff', |
| 94 | 'backcolorsame' => '', |
| 95 | 'margintop' => '', |
| 96 | 'marginbottom' => '', |
| 97 | 'marginleft' => '', |
| 98 | 'marginright' => '', |
| 99 | 'paddingtop' => '', |
| 100 | 'paddingbottom' => '', |
| 101 | 'paddingleft' => '', |
| 102 | 'paddingright' => '', |
| 103 | 'top' => '', |
| 104 | 'bottom' => '', |
| 105 | 'left' => '', |
| 106 | 'right' => '', |
| 107 | 'bordercolor' => '', |
| 108 | 'samecolor' => '', |
| 109 | 'samecolorhover' => '', |
| 110 | ), |
| 111 | 'fulltable' => array( |
| 112 | 'closesize' => '34', |
| 113 | 'closecolor' => '', |
| 114 | 'closetop' => '0', |
| 115 | 'closebottom' => '', |
| 116 | 'closeleft' => '', |
| 117 | 'closeright' => '0', |
| 118 | 'backcolor' => '000000', |
| 119 | 'backopacity' => '0.5', |
| 120 | ), |
| 121 | 'dif_button' => array( |
| 122 | 'fontsize' => '', |
| 123 | 'top' => '', |
| 124 | 'bottom' => '0', |
| 125 | 'color' => '', |
| 126 | 'backcolor' => '', |
| 127 | ), |
| 128 | 'dif_button_hover' => array( |
| 129 | 'fontsize' => '', |
| 130 | 'color' => '', |
| 131 | 'backcolor' => '', |
| 132 | ), |
| 133 | 'clear_button' => array( |
| 134 | 'fontsize' => '', |
| 135 | 'top' => '', |
| 136 | 'bottom' => '0', |
| 137 | 'color' => '', |
| 138 | 'backcolor' => '', |
| 139 | ), |
| 140 | 'clear_button_hover' => array( |
| 141 | 'fontsize' => '', |
| 142 | 'color' => '', |
| 143 | 'backcolor' => '', |
| 144 | ), |
| 145 | 'comparebutton' => array( |
| 146 | 'fontsize' => '', |
| 147 | 'width' => '', |
| 148 | 'color' => '', |
| 149 | 'backcolor' => '', |
| 150 | ), |
| 151 | 'comparebuttonhover' => array( |
| 152 | 'fontsize' => '', |
| 153 | 'width' => '', |
| 154 | 'color' => '', |
| 155 | 'backcolor' => '', |
| 156 | ), |
| 157 | 'comparebuttonadded' => array( |
| 158 | 'fontsize' => '', |
| 159 | 'width' => '', |
| 160 | 'color' => '', |
| 161 | 'backcolor' => '', |
| 162 | ), |
| 163 | ), |
| 164 | 'text_settings' => array( |
| 165 | 'compare' => 'Compare', |
| 166 | 'add_compare' => 'Compare', |
| 167 | 'added_compare' => 'Added', |
| 168 | 'toolbar' => 'Products For Compare', |
| 169 | 'attribute' => 'Attributes', |
| 170 | 'custom' => 'Other attributes', |
| 171 | 'availability' => 'Availability', |
| 172 | 'description' => 'Description', |
| 173 | 'remove_all_compare_text' => '', |
| 174 | 'hide_same_button_text' => '', |
| 175 | 'show_same_button_text' => '', |
| 176 | ), |
| 177 | 'javascript_settings' => array( |
| 178 | 'before_load' => '', |
| 179 | 'after_load' => '', |
| 180 | 'before_remove' => '', |
| 181 | 'after_remove' => '', |
| 182 | 'custom_css' => '', |
| 183 | ), |
| 184 | 'fontawesome_frontend_disable' => '', |
| 185 | 'fontawesome_frontend_version' => '', |
| 186 | ); |
| 187 | $this->values = array( |
| 188 | 'settings_name' => 'br-compare-products-options', |
| 189 | 'option_page' => 'br-compare-products', |
| 190 | 'premium_slug' => 'woocommerce-products-compare', |
| 191 | 'free_slug' => 'products-compare-for-woocommerce', |
| 192 | ); |
| 193 | $this->feature_list = array(); |
| 194 | $this->framework_data['fontawesome_frontend'] = true; |
| 195 | $this->active_libraries = array('addons', 'popup', 'templates'); |
| 196 | parent::__construct( $this ); |
| 197 | if( $this->check_framework_version() ) { |
| 198 | if ( $this->init_validation() ) { |
| 199 | $options_global = $this->get_option(); |
| 200 | $options = $options_global['general_settings']; |
| 201 | $this->add_compare_actions(); |
| 202 | add_action ( 'berocket_add_compare_actions', array($this, 'add_compare_actions') ); |
| 203 | add_action ( 'berocket_remove_compare_actions', array($this, 'remove_compare_actions') ); |
| 204 | add_action ( "widgets_init", array ( $this, 'widgets_init' ) ); |
| 205 | add_filter('berocket_compare_acf_product_field', array($this, 'acf_product_field'), 10, 3); |
| 206 | add_filter('berocket_compare_acf_product_field_height', array($this, 'acf_product_field_height'), 10, 2); |
| 207 | add_action( "wp_ajax_br_get_compare_products", array ( $this, 'listener_products' ) ); |
| 208 | add_action( "wp_ajax_nopriv_br_get_compare_products", array ( $this, 'listener_products' ) ); |
| 209 | add_action( "wp_ajax_br_get_compare_list", array ( $this, 'compare_list' ) ); |
| 210 | add_action( "wp_ajax_nopriv_br_get_compare_list", array ( $this, 'compare_list' ) ); |
| 211 | add_shortcode( 'br_compare_table', array( $this, 'shortcode' ) ); |
| 212 | if( empty($options['remove_compare_table']) ) { |
| 213 | add_filter ( 'the_content', array( $this, 'compare_page' ) ); |
| 214 | } |
| 215 | if( isset($_GET['compare']) ) { |
| 216 | $_GET['compare'] = urldecode($_GET['compare']); |
| 217 | } |
| 218 | add_filter('BeRocket_popup_open_page_elements', array($this, 'popup_open_page_elements'), 10, 2); |
| 219 | if( ! empty($options_global['template']) ) { |
| 220 | $template_data = $this->libraries->libraries_class['templates']->get_active_template_info($options_global['template']); |
| 221 | $theme_template = $template_data['class']; |
| 222 | do_action('berocket_init_template_'.$this->info['plugin_name'], $options_global['template']); |
| 223 | $this->theme_template = $theme_template; |
| 224 | } |
| 225 | } |
| 226 | } else { |
| 227 | add_filter( 'berocket_display_additional_notices', array( |
| 228 | $this, |
| 229 | 'old_framework_notice' |
| 230 | ) ); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | public function popup_open_page_elements($html_elements, $elements) { |
| 235 | $pattern = '/<div([^<>]+)>popup_compare_fullsize_table<\/div>/i'; |
| 236 | $replacement = ''; |
| 237 | $html_elements['html_content'] = preg_replace($pattern, $replacement, $html_elements['html_content']); |
| 238 | return $html_elements; |
| 239 | } |
| 240 | |
| 241 | public function add_compare_actions() { |
| 242 | $this->add_remove_compare_actions('add'); |
| 243 | } |
| 244 | |
| 245 | public function remove_compare_actions() { |
| 246 | $this->add_remove_compare_actions('remove'); |
| 247 | } |
| 248 | |
| 249 | public function add_remove_compare_actions($add_remove = 'add') { |
| 250 | $options_global = $this->get_option(); |
| 251 | $action = $add_remove.'_action'; |
| 252 | $options = $options_global['general_settings']; |
| 253 | switch($options['button_position']) { |
| 254 | case 'before_all': |
| 255 | $action( 'woocommerce_before_shop_loop_item', array( $this, 'get_compare_button' ), 5 ); |
| 256 | $action( 'lgv_advanced_before', array( $this, 'get_compare_button' ), 38 ); |
| 257 | $action( 'woocommerce_before_single_product_summary', array( $this, 'get_compare_button' ), 5 ); |
| 258 | break; |
| 259 | case 'after_image': |
| 260 | $action( 'woocommerce_before_shop_loop_item_title', array( $this, 'get_compare_button' ), 20 ); |
| 261 | $action( 'lgv_advanced_after_img', array( $this, 'get_compare_button' ), 38 ); |
| 262 | $action( 'woocommerce_before_single_product_summary', array( $this, 'get_compare_button' ), 38 ); |
| 263 | break; |
| 264 | case 'after_title': |
| 265 | $action( 'woocommerce_shop_loop_item_title', array( $this, 'get_compare_button' ), 38 ); |
| 266 | $action( 'lgv_advanced_before_description', array( $this, 'get_compare_button' ), 38 ); |
| 267 | $action( 'woocommerce_single_product_summary', array( $this, 'get_compare_button' ), 8 ); |
| 268 | break; |
| 269 | case 'after_price': |
| 270 | $action( 'woocommerce_after_shop_loop_item_title', array( $this, 'get_compare_button' ), 38 ); |
| 271 | $action( 'lgv_advanced_after_price', array( $this, 'get_compare_button' ), 38 ); |
| 272 | $action( 'woocommerce_single_product_summary', array( $this, 'get_compare_button' ), 15 ); |
| 273 | break; |
| 274 | case 'after_add_to_cart': |
| 275 | $action( 'woocommerce_after_shop_loop_item', array( $this, 'get_compare_button' ), 38 ); |
| 276 | $action( 'lgv_advanced_after_price', array( $this, 'get_compare_button' ), 30 ); |
| 277 | $action( 'woocommerce_single_product_summary', array( $this, 'get_compare_button' ), 38 ); |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | function init_validation() { |
| 282 | return parent::init_validation() && $this->check_framework_version(); |
| 283 | } |
| 284 | function check_framework_version() { |
| 285 | return ( ! empty(BeRocket_Framework::$framework_version) && version_compare(BeRocket_Framework::$framework_version, 2.1, '>=') ); |
| 286 | } |
| 287 | function old_framework_notice($notices) { |
| 288 | $notices[] = array( |
| 289 | 'start' => 0, |
| 290 | 'end' => 0, |
| 291 | 'name' => $this->info[ 'plugin_name' ].'_old_framework', |
| 292 | 'html' => __('<strong>Please update all BeRocket plugins to the most recent version. Products Compare for WooCommerce is not working correctly with older versions.</strong>', 'products-compare-for-woocommerce'), |
| 293 | 'righthtml' => '', |
| 294 | 'rightwidth' => 0, |
| 295 | 'nothankswidth' => 0, |
| 296 | 'contentwidth' => 1600, |
| 297 | 'subscribe' => false, |
| 298 | 'priority' => 10, |
| 299 | 'height' => 50, |
| 300 | 'repeat' => false, |
| 301 | 'repeatcount' => 1, |
| 302 | 'image' => array( |
| 303 | 'local' => '', |
| 304 | 'width' => 0, |
| 305 | 'height' => 0, |
| 306 | 'scale' => 1, |
| 307 | ) |
| 308 | ); |
| 309 | return $notices; |
| 310 | } |
| 311 | public function init () { |
| 312 | parent::init(); |
| 313 | add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_plugin')); |
| 314 | } |
| 315 | public function enqueue_scripts_plugin() { |
| 316 | wp_reset_query(); |
| 317 | $element_i = $this->add_popup('ajax_load'); |
| 318 | |
| 319 | $options_global = $this->get_option(); |
| 320 | wp_register_style( 'berocket_compare_products_style', plugins_url( 'css/products_compare.css', __FILE__ ), "", BeRocket_Compare_Products_version ); |
| 321 | wp_enqueue_style( 'berocket_compare_products_style' ); |
| 322 | wp_enqueue_script( 'berocket_jquery_cookie', plugins_url( 'js/jquery.cookie.js', __FILE__ ), array( 'jquery' ), BeRocket_Compare_Products_version ); |
| 323 | wp_enqueue_script( 'berocket_compare_products_script', plugins_url( 'js/products_compare.js', __FILE__ ), array( 'jquery' ), BeRocket_Compare_Products_version ); |
| 324 | wp_enqueue_script( 'jquery-mousewheel', plugins_url( 'js/jquery.mousewheel.min.js', __FILE__ ), array( 'jquery' ), BeRocket_Compare_Products_version ); |
| 325 | $javascript = $options_global['javascript_settings']; |
| 326 | $options = $options_global['general_settings']; |
| 327 | $style = $options_global['style_settings']; |
| 328 | |
| 329 | global $wp_query; |
| 330 | $page = $options['compare_page']; |
| 331 | $is_compare_page = false; |
| 332 | $page_id = ( isset($wp_query->queried_object->ID) ? $wp_query->queried_object->ID : '' ); |
| 333 | if( ! empty( $page_id ) && $wp_query->is_main_query() ) { |
| 334 | $default_language = apply_filters( 'wpml_default_language', NULL ); |
| 335 | $page_id = apply_filters( 'wpml_object_id', $page_id, 'page', true, $default_language ); |
| 336 | $is_compare_page = $page_id == $page; |
| 337 | } |
| 338 | wp_localize_script( |
| 339 | 'berocket_compare_products_script', |
| 340 | 'the_compare_products_data', |
| 341 | array( |
| 342 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 343 | 'user_func' => $javascript, |
| 344 | 'home_url' => site_url(), |
| 345 | 'hide_same' => (empty($options_global['text_settings']['hide_same_button_text']) ? __( 'Hide attributes with same values', 'products-compare-for-woocommerce' ) : $options_global['text_settings']['hide_same_button_text']), |
| 346 | 'show_same' => (empty($options_global['text_settings']['show_same_button_text']) ? __( 'Show attributes with same values', 'products-compare-for-woocommerce' ) : $options_global['text_settings']['show_same_button_text']), |
| 347 | 'hide_same_default' => ! empty($options['hide_same_default']), |
| 348 | 'compare_selector' => '#br_popup_'.$element_i, |
| 349 | 'toppadding' => (int) $style['table']['toppadding'], |
| 350 | 'is_compare_page' => $is_compare_page, |
| 351 | ) |
| 352 | ); |
| 353 | } |
| 354 | public function widgets_init() { |
| 355 | register_widget("berocket_compare_products_widget"); |
| 356 | } |
| 357 | |
| 358 | public static function get_all_compare_products() { |
| 359 | if ( ! empty($_COOKIE['br_products_compare']) ) { |
| 360 | $cookie = $_COOKIE['br_products_compare']; |
| 361 | $products = explode( ',', $cookie ); |
| 362 | return $products; |
| 363 | } else { |
| 364 | return false; |
| 365 | } |
| 366 | } |
| 367 | public static function is_set_cookie( $id ) { |
| 368 | if ( ! empty($_COOKIE['br_products_compare']) ) { |
| 369 | $cookie = $_COOKIE['br_products_compare']; |
| 370 | if ( preg_match( "/(^".$id.",)|(,".$id."$)|(,".$id.",)|(^".$id."$)/", $cookie ) ) { |
| 371 | return true; |
| 372 | } else { |
| 373 | return false; |
| 374 | } |
| 375 | } else { |
| 376 | return false; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | public function listener_products() { |
| 381 | set_query_var( 'type', 'image' ); |
| 382 | $this->br_get_template_part('selected_products'); |
| 383 | wp_die(); |
| 384 | } |
| 385 | |
| 386 | public function compare_list() { |
| 387 | $options_global = $this->get_option(); |
| 388 | $options = $options_global['general_settings']; |
| 389 | $template_name = ( empty($options['compare_template']) || $options['compare_template'] == 'compare' ? 'new-compare' : $options['compare_template'] ); |
| 390 | set_query_var( 'is_full_screen', true ); |
| 391 | $this->br_get_template_part($template_name); |
| 392 | wp_die(); |
| 393 | } |
| 394 | |
| 395 | public function shortcode($atts = array()) { |
| 396 | $options_global = $this->get_option(); |
| 397 | $options = $options_global['general_settings']; |
| 398 | global $wp; |
| 399 | $default_atts = array( |
| 400 | 'addthis' => '0', |
| 401 | ); |
| 402 | if( ! is_array($atts) ) { |
| 403 | $atts = array(); |
| 404 | } |
| 405 | if( ! empty($options['use_full_screen']) ) { |
| 406 | $element_i = $this->add_popup('page'); |
| 407 | set_query_var( 'berocket_element_i', $element_i ); |
| 408 | } |
| 409 | $atts = array_merge($default_atts, $atts); |
| 410 | $br_compare_uri = add_query_arg('compare', (empty($_COOKIE['br_products_compare']) ? '' : $_COOKIE['br_products_compare']), home_url( $wp->request )); |
| 411 | $template_name = ( empty($options['compare_template']) || $options['compare_template'] == 'compare' ? 'new-compare' : $options['compare_template'] ); |
| 412 | ob_start(); |
| 413 | $this->br_get_template_part($template_name); |
| 414 | $compare_page = ob_get_clean(); |
| 415 | if( empty($compare_page) ) { |
| 416 | return ''; |
| 417 | } |
| 418 | ob_start(); |
| 419 | ?> |
| 420 | <script> |
| 421 | var br_compare_page = "<?php echo remove_query_arg('compare', home_url( $wp->request )); ?>"; |
| 422 | var br_compare_uri = "<?php echo $br_compare_uri; ?>"; |
| 423 | <?php |
| 424 | if( ! isset($_GET['compare']) && ! empty($_COOKIE['br_products_compare']) ) { |
| 425 | ?> |
| 426 | if('history' in window && 'pushState' in history) { |
| 427 | var stateParameters = { BeRocket: "Rules" }; |
| 428 | history.replaceState(stateParameters, "BeRocket Rules", br_compare_uri); |
| 429 | history.pathname = br_compare_uri; |
| 430 | } else { |
| 431 | location.replace(br_compare_uri); |
| 432 | } |
| 433 | <?php } ?> |
| 434 | </script> |
| 435 | <?php if( ! empty($atts['addthis']) ) { ?> |
| 436 | <div class="addthis_sharing_toolbox" data-url="<?php echo $br_compare_uri; ?>"></div> |
| 437 | <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=<?php echo $options['addthisID']; ?>"></script> |
| 438 | <?php |
| 439 | } |
| 440 | echo '<div class="woocommerce">'.$compare_page.'</div>'; |
| 441 | return ob_get_clean(); |
| 442 | } |
| 443 | |
| 444 | public function compare_page ($content) { |
| 445 | global $wp_query; |
| 446 | $options_global = $this->get_option(); |
| 447 | $options = $options_global['general_settings']; |
| 448 | $page = $options['compare_page']; |
| 449 | $page_id = ( isset($wp_query->queried_object->ID) ? $wp_query->queried_object->ID : '' ); |
| 450 | remove_filter ( 'the_content', array( $this, 'compare_page' ) ); |
| 451 | if( ! empty( $page_id ) && $wp_query->is_main_query() ) { |
| 452 | $default_language = apply_filters( 'wpml_default_language', NULL ); |
| 453 | $page_id = apply_filters( 'wpml_object_id', $page_id, 'page', true, $default_language ); |
| 454 | if ( $page == $page_id ) { |
| 455 | ob_start(); |
| 456 | $br_compare_uri = add_query_arg('compare', (empty($_COOKIE['br_products_compare']) ? '' : $_COOKIE['br_products_compare']), get_page_link($page)); |
| 457 | ?> |
| 458 | <script> |
| 459 | var br_compare_page = "<?php echo get_page_link($page); ?>"; |
| 460 | var br_compare_uri = "<?php echo $br_compare_uri; ?>"; |
| 461 | <?php |
| 462 | if( ! isset($_GET['compare']) && ! empty($_COOKIE['br_products_compare']) ) { |
| 463 | ?> |
| 464 | if('history' in window && 'pushState' in history) { |
| 465 | var stateParameters = { BeRocket: "Rules" }; |
| 466 | history.replaceState(stateParameters, "BeRocket Rules", br_compare_uri); |
| 467 | history.pathname = br_compare_uri; |
| 468 | } else { |
| 469 | location.replace(br_compare_uri); |
| 470 | } |
| 471 | <?php } ?> |
| 472 | </script> |
| 473 | <?php if( ! empty($options['addthisID']) ) { ?> |
| 474 | <div class="addthis_sharing_toolbox" data-url="<?php echo $br_compare_uri; ?>"></div> |
| 475 | <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=<?php echo $options['addthisID']; ?>"></script> |
| 476 | <?php |
| 477 | } |
| 478 | if( ! empty($options['use_full_screen']) ) { |
| 479 | $element_i = $this->add_popup('page'); |
| 480 | set_query_var( 'berocket_element_i', $element_i ); |
| 481 | } |
| 482 | $template_name = ( empty($options['compare_template']) || $options['compare_template'] == 'compare' ? 'new-compare' : $options['compare_template'] ); |
| 483 | $this->br_get_template_part($template_name); |
| 484 | $content = ob_get_clean() . $content; |
| 485 | } |
| 486 | } |
| 487 | add_filter ( 'the_content', array( $this, 'compare_page' ) ); |
| 488 | return $content; |
| 489 | } |
| 490 | |
| 491 | public function add_popup($type = 'page') { |
| 492 | $open_type = array(); |
| 493 | $html_content = ''; |
| 494 | if( $type == 'page' ) { |
| 495 | $open_type = array('click' => array('type' => 'click', 'selector' => '.br_new_compare_full_size')); |
| 496 | $html_content = 'popup_compare_fullsize_table'; |
| 497 | } |
| 498 | $popup_options = array( |
| 499 | 'close_delay' => '0', |
| 500 | 'hide_body_scroll' => true, |
| 501 | 'print_button' => false, |
| 502 | 'width' => '90%', |
| 503 | 'height' => '90%', |
| 504 | 'theme' => $this->theme_template, |
| 505 | ); |
| 506 | return BeRocket_popup_display::add_popup($popup_options, $html_content, $open_type); |
| 507 | } |
| 508 | |
| 509 | public function get_compare_button() { |
| 510 | global $product, $wp_query; |
| 511 | $options_global = $this->get_option(); |
| 512 | $product_id = br_wc_get_product_id($product); |
| 513 | $product_id = intval($product_id); |
| 514 | $default_language = apply_filters( 'wpml_default_language', NULL ); |
| 515 | $product_id = apply_filters( 'wpml_object_id', $product_id, 'product', true, $default_language ); |
| 516 | $options = $options_global['general_settings']; |
| 517 | $text = $options_global['text_settings']; |
| 518 | $page_compare = intval($options['compare_page']); |
| 519 | $button_class = array( |
| 520 | 'add_to_cart_button', |
| 521 | 'button', |
| 522 | 'br_compare_button', |
| 523 | 'br_product_'.$product_id |
| 524 | ); |
| 525 | if ( $this->is_set_cookie($product_id) ) { |
| 526 | $button_class[] = 'br_compare_added'; |
| 527 | } |
| 528 | if ( ! empty($options['fast_compare']) ) { |
| 529 | $button_class[] = 'berocket_product_smart_compare'; |
| 530 | } |
| 531 | $button_class = implode(' ', $button_class); |
| 532 | $button_class = esc_html($button_class); |
| 533 | $href_link = '#no_compare_page'; |
| 534 | if( get_post($page_compare) ) { |
| 535 | $href_link = get_page_link($page_compare); |
| 536 | } |
| 537 | echo '<a class="'.$button_class.'" data-id="'.$product_id.'" href="'.$href_link.'"> |
| 538 | <i class="fa fa-square-o"></i> |
| 539 | <i class="fa fa-check-square-o"></i> |
| 540 | <span class="br_compare_button_text" data-added="'.(empty($text['added_compare']) ? __( 'Added', 'products-compare-for-woocommerce' ) : $text['added_compare']).'" data-not_added="'.(empty($text['add_compare']) ? __( 'Compare Product', 'products-compare-for-woocommerce' ) : $text['add_compare']).'"> |
| 541 | '.( $this->is_set_cookie($product_id) ? (empty($text['added_compare']) ? __( 'Added', 'products-compare-for-woocommerce' ) : $text['added_compare']) : (empty($text['add_compare']) ? __( 'Compare Product', 'products-compare-for-woocommerce' ) : $text['add_compare']) ).' |
| 542 | </span> |
| 543 | </a>'; |
| 544 | } |
| 545 | |
| 546 | public function acf_product_field($field_text, $field, $term) { |
| 547 | if( is_array($field) && isset($field['type']) ) { |
| 548 | if( $field['type'] == 'image' ) { |
| 549 | $img = get_field($field['name'], $term['id']); |
| 550 | if( empty($img) ) { |
| 551 | $field_text = ''; |
| 552 | } else { |
| 553 | $field_text = '<img style="display:inline-block;max-height: 90px;max-width:100%;" src="'.$img.'">'; |
| 554 | } |
| 555 | } elseif($field['type'] == 'color_picker') { |
| 556 | $color = get_field($field['name'], $term['id']); |
| 557 | if( empty($color) ) { |
| 558 | $field_text = ''; |
| 559 | } else { |
| 560 | $field_text = '<p><span style="border:2px solid black; display: inline-block; width: 30px;height:30px;background-color: '.$color.';"></span></p>'; |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | return $field_text; |
| 565 | } |
| 566 | public function acf_product_field_height($height, $field) { |
| 567 | if( is_array($field) && isset($field['type']) ) { |
| 568 | if( $field['type'] == 'image' ) { |
| 569 | $height = 'height:100px!important;'; |
| 570 | } |
| 571 | } |
| 572 | return $height; |
| 573 | } |
| 574 | public function admin_init () { |
| 575 | parent::admin_init(); |
| 576 | $options = $this->get_option(); |
| 577 | $this->update_from_not_framework(); |
| 578 | wp_enqueue_script( 'berocket_compare_products_admin_script', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ) ); |
| 579 | wp_register_style( 'berocket_compare_products_admin_style', plugins_url( 'css/admin.css', __FILE__ ), "", BeRocket_Compare_Products_version ); |
| 580 | wp_enqueue_style( 'berocket_compare_products_admin_style' ); |
| 581 | } |
| 582 | |
| 583 | public function activation() { |
| 584 | parent::activation(); |
| 585 | $this->update_from_not_framework(); |
| 586 | $options_global = $this->get_option(); |
| 587 | if ( ! $options_global['general_settings']['compare_page'] ) { |
| 588 | $compare_page = array( |
| 589 | 'post_title' => 'Compare', |
| 590 | 'post_content' => '', |
| 591 | 'post_status' => 'publish', |
| 592 | 'post_type' => 'page', |
| 593 | ); |
| 594 | |
| 595 | $post_id = wp_insert_post($compare_page); |
| 596 | $options_global['general_settings']['compare_page'] = $post_id; |
| 597 | update_option($this->values['settings_name'], $options_global); |
| 598 | } |
| 599 | } |
| 600 | public function update_from_not_framework() { |
| 601 | $update_option = false; |
| 602 | $options = $this->get_option(); |
| 603 | $settings_list = array('general_settings', 'style_settings', 'text_settings', 'javascript_settings'); |
| 604 | foreach($settings_list as $setting_list) { |
| 605 | $settings = get_option('br_compare_products_'.$setting_list); |
| 606 | if( ! empty($settings) && is_array($settings) ) { |
| 607 | $update_option = true; |
| 608 | $options[$setting_list] = $settings; |
| 609 | delete_option('br_compare_products_'.$setting_list); |
| 610 | } |
| 611 | } |
| 612 | if($update_option) { |
| 613 | $options = $this->recursive_array_set( $this->defaults, $options ); |
| 614 | update_option($this->values[ 'settings_name' ], $options); |
| 615 | } |
| 616 | } |
| 617 | public function set_styles () { |
| 618 | $options_global = $this->get_option(); |
| 619 | $general_options = $options_global['general_settings']; |
| 620 | $template_name = ( empty($general_options['compare_template']) || $general_options['compare_template'] == 'compare' ? 'new-compare' : $general_options['compare_template'] ); |
| 621 | $options = $options_global['style_settings']; |
| 622 | //TABLE STYLE |
| 623 | if( $template_name == 'compare' ) { |
| 624 | //OLD TABLE STYLE |
| 625 | echo '<style>'; |
| 626 | echo '.berocket_compare_box .br_moved_attr tr td {'; |
| 627 | echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).';'; |
| 628 | echo '}'; |
| 629 | echo '.berocket_compare_box .berocket_compare_table_hidden {'; |
| 630 | echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).';'; |
| 631 | echo '}'; |
| 632 | echo 'div.berocket_compare_box.berocket_full_screen_box {'; |
| 633 | echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).';'; |
| 634 | echo '}'; |
| 635 | echo 'div.berocket_compare_box .berocket_compare_table td {'; |
| 636 | echo 'min-width: '.$options['table']['colwidth'].'px;'; |
| 637 | echo '}'; |
| 638 | //DIF BUTTON |
| 639 | echo '.berocket_compare_table_hidden .br_product_hidden_first .br_show_compare_dif {'; |
| 640 | if( strlen($options['dif_button']['fontsize']) > 0 ) { |
| 641 | echo 'font-size: '.$options['dif_button']['fontsize'].'px!important;'; |
| 642 | } |
| 643 | if( strlen($options['dif_button']['top']) > 0 ) { |
| 644 | echo 'top: '.$options['dif_button']['top'].'px;'; |
| 645 | } |
| 646 | if( strlen($options['dif_button']['bottom']) > 0 ) { |
| 647 | echo 'bottom: '.$options['dif_button']['bottom'].'px;'; |
| 648 | } |
| 649 | if( strlen($options['dif_button']['color']) > 0 ) { |
| 650 | echo 'color: #'.str_replace( '#', '', $options['dif_button']['color'] ).';'; |
| 651 | } |
| 652 | if( strlen($options['dif_button']['backcolor']) > 0 ) { |
| 653 | echo 'background-color: #'.str_replace( '#', '', $options['dif_button']['backcolor'] ).';'; |
| 654 | } |
| 655 | echo '}'; |
| 656 | echo '.berocket_compare_table_hidden .br_product_hidden_first .br_show_compare_dif:hover {'; |
| 657 | if( strlen($options['dif_button_hover']['fontsize']) > 0 ) { |
| 658 | echo 'font-size: '.$options['dif_button_hover']['fontsize'].'px;'; |
| 659 | } |
| 660 | if( strlen($options['dif_button_hover']['color']) > 0 ) { |
| 661 | echo 'color: #'.str_replace( '#', '', $options['dif_button_hover']['color'] ).';'; |
| 662 | } |
| 663 | if( strlen($options['dif_button_hover']['backcolor']) > 0 ) { |
| 664 | echo 'background-color: #'.str_replace( '#', '', $options['dif_button_hover']['backcolor'] ).';'; |
| 665 | } |
| 666 | echo '}'; |
| 667 | //CLEAR BUTTON |
| 668 | echo '.berocket_compare_table_hidden .br_product_hidden_first .br_remove_all_compare {'; |
| 669 | if( strlen($options['clear_button']['fontsize']) > 0 ) { |
| 670 | echo 'font-size: '.$options['clear_button']['fontsize'].'px!important;'; |
| 671 | } |
| 672 | if( strlen($options['clear_button']['top']) > 0 ) { |
| 673 | echo 'top: '.$options['clear_button']['top'].'px;'; |
| 674 | } |
| 675 | if( strlen($options['clear_button']['bottom']) > 0 ) { |
| 676 | echo 'bottom: '.$options['clear_button']['bottom'].'px;'; |
| 677 | } |
| 678 | if( strlen($options['clear_button']['color']) > 0 ) { |
| 679 | echo 'color: #'.str_replace( '#', '', $options['clear_button']['color'] ).';'; |
| 680 | } |
| 681 | if( strlen($options['clear_button']['backcolor']) > 0 ) { |
| 682 | echo 'background-color: #'.str_replace( '#', '', $options['clear_button']['backcolor'] ).';'; |
| 683 | } |
| 684 | echo '}'; |
| 685 | echo '.berocket_compare_table_hidden .br_product_hidden_first .br_remove_all_compare:hover {'; |
| 686 | if( strlen($options['clear_button_hover']['fontsize']) > 0 ) { |
| 687 | echo 'font-size: '.$options['clear_button_hover']['fontsize'].'px;'; |
| 688 | } |
| 689 | if( strlen($options['clear_button_hover']['color']) > 0 ) { |
| 690 | echo 'color: #'.str_replace( '#', '', $options['clear_button_hover']['color'] ).';'; |
| 691 | } |
| 692 | if( strlen($options['clear_button_hover']['backcolor']) > 0 ) { |
| 693 | echo 'background-color: #'.str_replace( '#', '', $options['clear_button_hover']['backcolor'] ).';'; |
| 694 | } |
| 695 | echo '}'; |
| 696 | echo 'div.berocket_compare_box .br_moved_attr tr td {'; |
| 697 | echo 'min-width: '.$options['table']['colwidth'].'px;'; |
| 698 | echo '}'; |
| 699 | echo '.beroket_compare_box .berocket_compare_table img {'; |
| 700 | echo 'width: '.$options['table']['imgwidth'].'px;'; |
| 701 | echo '}'; |
| 702 | echo '.berocket_compare_box {'; |
| 703 | echo 'margin-top: '.$options['table']['margintop'].'px;'; |
| 704 | echo 'margin-bottom: '.$options['table']['marginbottom'].'px;'; |
| 705 | echo 'margin-left: '.$options['table']['marginleft'].'px;'; |
| 706 | echo 'margin-right: '.$options['table']['marginright'].'px;'; |
| 707 | echo '}'; |
| 708 | echo 'div.berocket_full_screen_box.berocket_compare_box {'; |
| 709 | echo 'top: '.$options['table']['top'].'px;'; |
| 710 | echo 'bottom: '.$options['table']['bottom'].'px;'; |
| 711 | echo 'left: '.$options['table']['left'].'px;'; |
| 712 | echo 'right: '.$options['table']['right'].'px;'; |
| 713 | echo '}'; |
| 714 | echo 'div.berocket_back_full_screen {'; |
| 715 | echo 'background-color: #'.str_replace( '#', '', $options['fulltable']['backcolor'] ).';'; |
| 716 | if( isset($options['fulltable']['backopacity']) && $options['fulltable']['backopacity'] >= 0 && $options['fulltable']['backopacity'] <= 1 ) { |
| 717 | echo 'opacity: '.$options['fulltable']['backopacity'].';'; |
| 718 | } |
| 719 | echo '}'; |
| 720 | echo '.berocket_compare_box a.berocket_normal_size {'; |
| 721 | echo 'font-size: '.$options['fulltable']['closesize'].'px;'; |
| 722 | if( isset($options['fulltable']['closetop']) && strlen($options['fulltable']['closetop']) > 0 ) { |
| 723 | echo 'top: '.$options['fulltable']['closetop'].'px;'; |
| 724 | } |
| 725 | if( isset($options['fulltable']['closebottom']) && strlen($options['fulltable']['closebottom']) > 0 ) { |
| 726 | echo 'bottom: '.$options['fulltable']['closebottom'].'px;'; |
| 727 | } |
| 728 | if( isset($options['fulltable']['closeleft']) && strlen($options['fulltable']['closeleft']) > 0 ) { |
| 729 | echo 'left: '.$options['fulltable']['closeleft'].'px;'; |
| 730 | } |
| 731 | if( isset($options['fulltable']['closeright']) && strlen($options['fulltable']['closeright']) > 0 ) { |
| 732 | echo 'right: '.$options['fulltable']['closeright'].'px;'; |
| 733 | } |
| 734 | echo 'color: #'.str_replace( '#', '', $options['fulltable']['closecolor'] ).';'; |
| 735 | echo '}'; |
| 736 | echo '.berocket_compare_box .br_same_attr td {'; |
| 737 | echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolorsame'] ).';'; |
| 738 | echo '}'; |
| 739 | echo '</style>'; |
| 740 | } else { |
| 741 | //NEW TABLE STYLE |
| 742 | echo '<style>'; |
| 743 | echo '.br_new_compare_block .br_left_table {'; |
| 744 | echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).'!important;'; |
| 745 | echo '}'; |
| 746 | echo '.br_new_compare_block .br_main_top table {'; |
| 747 | echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).'!important;'; |
| 748 | echo '}'; |
| 749 | echo 'div.br_new_compare_block.br_full_size_popup {'; |
| 750 | echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolor'] ).'!important;'; |
| 751 | echo '}'; |
| 752 | echo ' |
| 753 | div.br_new_compare .br_right_table tr td, |
| 754 | div.br_new_compare .br_right_table tr th, |
| 755 | div.br_new_compare .br_left_table, |
| 756 | div.br_new_compare_block .br_top_table table th, |
| 757 | div.br_new_compare_block .br_top_table table td {'; |
| 758 | echo 'width: '.$options['table']['colwidth'].'px!important;'; |
| 759 | echo 'min-width: '.$options['table']['colwidth'].'px!important;'; |
| 760 | echo 'max-width: '.$options['table']['colwidth'].'px!important;'; |
| 761 | echo '}'; |
| 762 | echo ' |
| 763 | div.br_new_compare div.br_right_table, |
| 764 | div.br_top_table div.br_main_top, |
| 765 | div.br_top_table div.br_opacity_top{'; |
| 766 | echo 'margin-left: '.$options['table']['colwidth'].'px!important;'; |
| 767 | echo '}'; |
| 768 | echo 'div.br_new_compare_block .br_top_table .br_show_compare_dif {'; |
| 769 | echo 'max-width: '.$options['table']['colwidth'].'px!important;'; |
| 770 | echo '}'; |
| 771 | //DIF BUTTON |
| 772 | echo 'div.br_new_compare_block .br_show_compare_dif {'; |
| 773 | if( strlen($options['dif_button']['fontsize']) > 0 ) { |
| 774 | echo 'font-size: '.$options['dif_button']['fontsize'].'px!important;'; |
| 775 | } |
| 776 | if( strlen($options['dif_button']['top']) > 0 ) { |
| 777 | echo 'top: '.$options['dif_button']['top'].'px!important;'; |
| 778 | } |
| 779 | if( strlen($options['dif_button']['bottom']) > 0 ) { |
| 780 | echo 'bottom: '.$options['dif_button']['bottom'].'px!important;'; |
| 781 | } |
| 782 | if( strlen($options['dif_button']['color']) > 0 ) { |
| 783 | echo 'color: #'.str_replace( '#', '', $options['dif_button']['color'] ).'!important;'; |
| 784 | } |
| 785 | if( strlen($options['dif_button']['backcolor']) > 0 ) { |
| 786 | echo 'background-color: #'.str_replace( '#', '', $options['dif_button']['backcolor'] ).'!important;'; |
| 787 | } |
| 788 | echo '}'; |
| 789 | echo 'div.br_new_compare_block .br_show_compare_dif:hover {'; |
| 790 | if( strlen($options['dif_button_hover']['fontsize']) > 0 ) { |
| 791 | echo 'font-size: '.$options['dif_button_hover']['fontsize'].'px!important;'; |
| 792 | } |
| 793 | if( strlen($options['dif_button_hover']['color']) > 0 ) { |
| 794 | echo 'color: #'.str_replace( '#', '', $options['dif_button_hover']['color'] ).'!important;'; |
| 795 | } |
| 796 | if( strlen($options['dif_button_hover']['backcolor']) > 0 ) { |
| 797 | echo 'background-color: #'.str_replace( '#', '', $options['dif_button_hover']['backcolor'] ).'!important;'; |
| 798 | } |
| 799 | echo '}'; |
| 800 | //CLEAR BUTTON |
| 801 | echo 'div.br_new_compare_block .br_remove_all_compare {'; |
| 802 | if( strlen($options['clear_button']['fontsize']) > 0 ) { |
| 803 | echo 'font-size: '.$options['clear_button']['fontsize'].'px!important;'; |
| 804 | } |
| 805 | if( strlen($options['clear_button']['top']) > 0 ) { |
| 806 | echo 'top: '.$options['clear_button']['top'].'px!important;'; |
| 807 | } |
| 808 | if( strlen($options['clear_button']['bottom']) > 0 ) { |
| 809 | echo 'bottom: '.$options['clear_button']['bottom'].'px!important;'; |
| 810 | } |
| 811 | if( strlen($options['clear_button']['color']) > 0 ) { |
| 812 | echo 'color: #'.str_replace( '#', '', $options['clear_button']['color'] ).'!important;'; |
| 813 | } |
| 814 | if( strlen($options['clear_button']['backcolor']) > 0 ) { |
| 815 | echo 'background-color: #'.str_replace( '#', '', $options['clear_button']['backcolor'] ).'!important;'; |
| 816 | } |
| 817 | echo '}'; |
| 818 | echo 'div.br_new_compare_block .br_remove_all_compare:hover {'; |
| 819 | if( strlen($options['clear_button_hover']['fontsize']) > 0 ) { |
| 820 | echo 'font-size: '.$options['clear_button_hover']['fontsize'].'px!important;'; |
| 821 | } |
| 822 | if( strlen($options['clear_button_hover']['color']) > 0 ) { |
| 823 | echo 'color: #'.str_replace( '#', '', $options['clear_button_hover']['color'] ).'!important;'; |
| 824 | } |
| 825 | if( strlen($options['clear_button_hover']['backcolor']) > 0 ) { |
| 826 | echo 'background-color: #'.str_replace( '#', '', $options['clear_button_hover']['backcolor'] ).'!important;'; |
| 827 | } |
| 828 | echo '}'; |
| 829 | // ------- |
| 830 | echo '.br_new_compare_block .br_new_compare img {'; |
| 831 | echo 'width: '.$options['table']['imgwidth'].'px!important;'; |
| 832 | echo '}'; |
| 833 | echo '.br_new_compare_block {'; |
| 834 | echo 'margin-top: '.$options['table']['margintop'].'px!important;'; |
| 835 | echo 'margin-bottom: '.$options['table']['marginbottom'].'px!important;'; |
| 836 | echo 'margin-left: '.$options['table']['marginleft'].'px!important;'; |
| 837 | echo 'margin-right: '.$options['table']['marginright'].'px!important;'; |
| 838 | echo '}'; |
| 839 | echo 'div.br_new_compare_block.br_full_size_popup {'; |
| 840 | echo 'top: '.$options['table']['top'].'px!important;'; |
| 841 | echo 'bottom: '.$options['table']['bottom'].'px!important;'; |
| 842 | echo 'left: '.$options['table']['left'].'px!important;'; |
| 843 | echo 'right: '.$options['table']['right'].'px!important;'; |
| 844 | echo '}'; |
| 845 | echo 'div.br_new_compare_black_popup {'; |
| 846 | echo 'background-color: #'.str_replace( '#', '', $options['fulltable']['backcolor'] ).'!important;'; |
| 847 | if( isset($options['fulltable']['backopacity']) && $options['fulltable']['backopacity'] >= 0 && $options['fulltable']['backopacity'] <= 1 ) { |
| 848 | echo 'opacity: '.$options['fulltable']['backopacity'].'!important;'; |
| 849 | } |
| 850 | echo '}'; |
| 851 | echo '.br_full_size_close a {'; |
| 852 | echo 'font-size: '.$options['fulltable']['closesize'].'px!important;'; |
| 853 | if( isset($options['fulltable']['closetop']) && strlen($options['fulltable']['closetop']) > 0 ) { |
| 854 | echo 'top: '.$options['fulltable']['closetop'].'px!important;'; |
| 855 | } |
| 856 | if( isset($options['fulltable']['closebottom']) && strlen($options['fulltable']['closebottom']) > 0 ) { |
| 857 | echo 'bottom: '.$options['fulltable']['closebottom'].'px!important;'; |
| 858 | } |
| 859 | if( isset($options['fulltable']['closeleft']) && strlen($options['fulltable']['closeleft']) > 0 ) { |
| 860 | echo 'left: '.$options['fulltable']['closeleft'].'px!important;'; |
| 861 | } |
| 862 | if( isset($options['fulltable']['closeright']) && strlen($options['fulltable']['closeright']) > 0 ) { |
| 863 | echo 'right: '.$options['fulltable']['closeright'].'px!important;'; |
| 864 | } |
| 865 | echo 'color: #'.str_replace( '#', '', $options['fulltable']['closecolor'] ).'!important;'; |
| 866 | echo '}'; |
| 867 | echo '.br_new_compare_block .br_same_attr {'; |
| 868 | echo 'background-color: #'.str_replace( '#', '', $options['table']['backcolorsame'] ).'!important;'; |
| 869 | echo '}'; |
| 870 | echo '</style>'; |
| 871 | } |
| 872 | //OTHER STYLE |
| 873 | echo '<style>'; |
| 874 | echo '.berocket_compare_widget_start .berocket_compare_widget .berocket_open_compare ,'; |
| 875 | echo '.berocket_compare_widget_toolbar .berocket_compare_widget .berocket_open_compare {'; |
| 876 | echo 'border-color: #'.str_replace( '#', '', $options['button']['bcolor'] ).';'; |
| 877 | echo 'border-width: '.$options['button']['bwidth'].'px;'; |
| 878 | echo 'border-radius: '.$options['button']['bradius'].'px;'; |
| 879 | echo 'font-size: '.$options['button']['fontsize'].'px;'; |
| 880 | echo 'color: #'.str_replace( '#', '', $options['button']['fcolor'] ).';'; |
| 881 | echo 'background-color: #'.str_replace( '#', '', $options['button']['backcolor'] ).';'; |
| 882 | echo '}'; |
| 883 | echo '.berocket_compare_widget_start .berocket_show_compare_toolbar {'; |
| 884 | echo 'border-color: #'.str_replace( '#', '', $options['toolbutton']['bcolor'] ).';'; |
| 885 | echo 'border-width: '.$options['toolbutton']['bwidth'].'px;'; |
| 886 | echo 'border-radius: '.$options['toolbutton']['bradius'].'px;'; |
| 887 | echo 'font-size: '.$options['toolbutton']['fontsize'].'px;'; |
| 888 | echo 'color: #'.str_replace( '#', '', $options['toolbutton']['fcolor'] ).';'; |
| 889 | echo 'background-color: #'.str_replace( '#', '', $options['toolbutton']['backcolor'] ).';'; |
| 890 | echo '}'; |
| 891 | echo '.br_compare_button {'; |
| 892 | echo 'background-color: #'.str_replace( '#', '', $options['comparebutton']['backcolor'] ).'!important;'; |
| 893 | echo 'color: #'.str_replace( '#', '', $options['comparebutton']['color'] ).'!important;'; |
| 894 | if( isset($options['comparebutton']['fontsize']) && strlen($options['comparebutton']['fontsize']) > 0 ) { |
| 895 | echo 'font-size: '.$options['comparebutton']['fontsize'].'px!important;'; |
| 896 | } |
| 897 | if( isset($options['comparebutton']['width']) && strlen($options['comparebutton']['width']) > 0 ) { |
| 898 | echo 'width: '.$options['comparebutton']['width'].'px!important;'; |
| 899 | } |
| 900 | echo '}'; |
| 901 | echo '.button.br_compare_button:hover {'; |
| 902 | echo 'background-color: #'.str_replace( '#', '', $options['comparebuttonhover']['backcolor'] ).'!important;'; |
| 903 | echo 'color: #'.str_replace( '#', '', $options['comparebuttonhover']['color'] ).'!important;'; |
| 904 | if( isset($options['comparebuttonhover']['fontsize']) && strlen($options['comparebuttonhover']['fontsize']) > 0 ) { |
| 905 | echo 'font-size: '.$options['comparebuttonhover']['fontsize'].'px!important;'; |
| 906 | } |
| 907 | if( isset($options['comparebuttonhover']['width']) && strlen($options['comparebuttonhover']['width']) > 0 ) { |
| 908 | echo 'width: '.$options['comparebuttonhover']['width'].'px!important;'; |
| 909 | } |
| 910 | echo '}'; |
| 911 | echo '.br_compare_added {'; |
| 912 | echo 'background-color: #'.str_replace( '#', '', $options['comparebuttonadded']['backcolor'] ).'!important;'; |
| 913 | echo 'color: #'.str_replace( '#', '', $options['comparebuttonadded']['color'] ).'!important;'; |
| 914 | if( isset($options['comparebuttonadded']['fontsize']) && strlen($options['comparebuttonadded']['fontsize']) > 0 ) { |
| 915 | echo 'font-size: '.$options['comparebuttonadded']['fontsize'].'px!important;'; |
| 916 | } |
| 917 | if( isset($options['comparebuttonadded']['width']) && strlen($options['comparebuttonadded']['width']) > 0 ) { |
| 918 | echo 'width: '.$options['comparebuttonadded']['width'].'px!important;'; |
| 919 | } |
| 920 | echo '}'; |
| 921 | echo '</style>'; |
| 922 | $javascript_css = $options_global['javascript_settings']; |
| 923 | if( ! empty($javascript_css['custom_css']) ) { |
| 924 | echo '<style>'.$javascript_css['custom_css'].'</style>'; |
| 925 | } |
| 926 | } |
| 927 | public function admin_settings( $tabs_info = array(), $data = array() ) { |
| 928 | $pages = get_pages(); |
| 929 | $pages_option = array(); |
| 930 | foreach($pages as $page) { |
| 931 | $pages_option[] = array('value' => $page->ID, 'text' => $page->post_title); |
| 932 | } |
| 933 | parent::admin_settings( |
| 934 | array( |
| 935 | 'General' => array( |
| 936 | 'icon' => 'cog', |
| 937 | 'name' => __( 'General', "products-compare-for-woocommerce" ), |
| 938 | ), |
| 939 | 'Popup Templates' => array( |
| 940 | 'icon' => 'files-o', |
| 941 | 'name' => __( 'Popup Templates', "products-compare-for-woocommerce" ), |
| 942 | ), |
| 943 | 'Style' => array( |
| 944 | 'icon' => 'eye', |
| 945 | 'name' => __( 'Style', "products-compare-for-woocommerce" ), |
| 946 | ), |
| 947 | 'Text' => array( |
| 948 | 'icon' => 'align-center', |
| 949 | 'name' => __( 'Text', "products-compare-for-woocommerce" ), |
| 950 | ), |
| 951 | 'Custom CSS/JavaScript' => array( |
| 952 | 'icon' => 'css3', |
| 953 | 'name' => __( 'Custom CSS/JavaScript', "products-compare-for-woocommerce" ), |
| 954 | ), |
| 955 | 'License' => array( |
| 956 | 'icon' => 'unlock-alt', |
| 957 | 'link' => admin_url( 'admin.php?page=berocket_account' ) |
| 958 | ), |
| 959 | ), |
| 960 | array( |
| 961 | 'General' => array( |
| 962 | 'fast_compare' => array( |
| 963 | "label" => __('Fast compare', 'products-compare-for-woocommerce'), |
| 964 | "label_for" => __('Open compare table via AJAX on same page', 'products-compare-for-woocommerce'), |
| 965 | "type" => "checkbox", |
| 966 | "name" => array("general_settings", "fast_compare"), |
| 967 | "value" => '1', |
| 968 | ), |
| 969 | 'hide_same_button' => array( |
| 970 | "label" => __('Hide attributes with same value', 'products-compare-for-woocommerce'), |
| 971 | "items" => array( |
| 972 | "hide_same_button" => array( |
| 973 | "label_for" => __('Display button to hide/show attributes', 'products-compare-for-woocommerce'), |
| 974 | "type" => "checkbox", |
| 975 | "name" => array("general_settings", "hide_same_button"), |
| 976 | "value" => '1', |
| 977 | ), |
| 978 | "hide_same_default" => array( |
| 979 | "label_for" => __('Hide attributes by default', 'products-compare-for-woocommerce'), |
| 980 | "label_be_for"=> '<br>', |
| 981 | "type" => "checkbox", |
| 982 | "name" => array("general_settings", "hide_same_default"), |
| 983 | "value" => '1', |
| 984 | ), |
| 985 | ), |
| 986 | ), |
| 987 | 'remove_all_compare' => array( |
| 988 | "label" => __('Clear compare list', 'products-compare-for-woocommerce'), |
| 989 | "label_for" => __('Display button to remove all products from compare', 'products-compare-for-woocommerce'), |
| 990 | "type" => "checkbox", |
| 991 | "name" => array("general_settings", "remove_all_compare"), |
| 992 | "value" => '1', |
| 993 | ), |
| 994 | 'compare_template' => array( |
| 995 | "tr_class" => "berocket_compare_template_hidden", |
| 996 | "label" => __( 'Compare template', "products-compare-for-woocommerce" ), |
| 997 | "name" => array("general_settings", "compare_template"), |
| 998 | "type" => "selectbox", |
| 999 | "options" => array( |
| 1000 | array('value' => 'new-compare', 'text' => __( 'Static CSS Build', "products-compare-for-woocommerce" )), |
| 1001 | ), |
| 1002 | "value" => '' |
| 1003 | ), |
| 1004 | 'button_position' => array( |
| 1005 | "label" => __( 'Button position', "products-compare-for-woocommerce" ), |
| 1006 | "name" => array("general_settings", "button_position"), |
| 1007 | "type" => "selectbox", |
| 1008 | "options" => array( |
| 1009 | array('value' => 'before_all', 'text' => __( 'Before all', "products-compare-for-woocommerce" )), |
| 1010 | array('value' => 'after_image', 'text' => __( 'After Image', "products-compare-for-woocommerce" )), |
| 1011 | array('value' => 'after_title', 'text' => __( 'After Title', "products-compare-for-woocommerce" )), |
| 1012 | array('value' => 'after_price', 'text' => __( 'After Price', "products-compare-for-woocommerce" )), |
| 1013 | array('value' => 'after_add_to_cart', 'text' => __( 'After Add to cart button', "products-compare-for-woocommerce" )), |
| 1014 | ), |
| 1015 | "value" => '' |
| 1016 | ), |
| 1017 | 'compare_page' => array( |
| 1018 | "label" => __( 'Compare Page', "products-compare-for-woocommerce" ), |
| 1019 | "name" => array("general_settings", "compare_page"), |
| 1020 | "type" => "selectbox", |
| 1021 | "options" => $pages_option, |
| 1022 | "value" => '' |
| 1023 | ), |
| 1024 | 'remove_compare_table' => array( |
| 1025 | "label" => __('Remove compare table', 'products-compare-for-woocommerce'), |
| 1026 | "label_for" => __('Remove compare table on "Compare page"', 'products-compare-for-woocommerce'), |
| 1027 | "type" => "checkbox", |
| 1028 | "name" => array("general_settings", "remove_compare_table"), |
| 1029 | "value" => '1', |
| 1030 | ), |
| 1031 | 'addthisID' => array( |
| 1032 | "label" => __('AddThis ID', 'products-compare-for-woocommerce'), |
| 1033 | "label_for" => ' ' . __('Your ID from AddThis site', 'products-compare-for-woocommerce') . ' <a target="_blank" href="https://www.addthis.com/">https://www.addthis.com/</a>', |
| 1034 | "type" => "text", |
| 1035 | "name" => array("general_settings", "addthisID"), |
| 1036 | "value" => '1', |
| 1037 | ), |
| 1038 | 'use_full_screen' => array( |
| 1039 | "label" => __('Full screen button on compare page', 'products-compare-for-woocommerce'), |
| 1040 | "type" => "checkbox", |
| 1041 | "name" => array("general_settings", "use_full_screen"), |
| 1042 | "value" => '1', |
| 1043 | ), |
| 1044 | 'attribute' => array( |
| 1045 | "label" => "", |
| 1046 | "section" => 'attributes' |
| 1047 | ), |
| 1048 | ), |
| 1049 | 'Style' => array( |
| 1050 | 'all_style' => array( |
| 1051 | "label" => "", |
| 1052 | "section" => 'all_style' |
| 1053 | ), |
| 1054 | ), |
| 1055 | 'Text' => array( |
| 1056 | 'compare' => array( |
| 1057 | "label" => __('Text on compare button', 'products-compare-for-woocommerce'), |
| 1058 | "type" => "text", |
| 1059 | "name" => array("text_settings", "compare"), |
| 1060 | "value" => '', |
| 1061 | ), |
| 1062 | 'add_compare' => array( |
| 1063 | "label" => __('Add to compare button', 'products-compare-for-woocommerce'), |
| 1064 | "type" => "text", |
| 1065 | "name" => array("text_settings", "add_compare"), |
| 1066 | "value" => '', |
| 1067 | ), |
| 1068 | 'added_compare' => array( |
| 1069 | "label" => __('Add to compare button if product added', 'products-compare-for-woocommerce'), |
| 1070 | "type" => "text", |
| 1071 | "name" => array("text_settings", "added_compare"), |
| 1072 | "value" => '', |
| 1073 | ), |
| 1074 | 'toolbar' => array( |
| 1075 | "label" => __('Text on button for toolbar open', 'products-compare-for-woocommerce'), |
| 1076 | "type" => "text", |
| 1077 | "name" => array("text_settings", "toolbar"), |
| 1078 | "value" => '', |
| 1079 | ), |
| 1080 | 'attribute' => array( |
| 1081 | "label" => __('Attribute text', 'products-compare-for-woocommerce'), |
| 1082 | "type" => "text", |
| 1083 | "name" => array("text_settings", "attribute"), |
| 1084 | "value" => '', |
| 1085 | ), |
| 1086 | 'custom' => array( |
| 1087 | "label" => __('Custom taxonomies text', 'products-compare-for-woocommerce'), |
| 1088 | "type" => "text", |
| 1089 | "name" => array("text_settings", "custom"), |
| 1090 | "value" => '', |
| 1091 | ), |
| 1092 | 'availability' => array( |
| 1093 | "label" => __('Availability text', 'products-compare-for-woocommerce'), |
| 1094 | "type" => "text", |
| 1095 | "name" => array("text_settings", "availability"), |
| 1096 | "value" => '', |
| 1097 | ), |
| 1098 | 'description' => array( |
| 1099 | "label" => __('Description text', 'products-compare-for-woocommerce'), |
| 1100 | "type" => "text", |
| 1101 | "name" => array("text_settings", "description"), |
| 1102 | "value" => '', |
| 1103 | ), |
| 1104 | 'remove_all_compare_text' => array( |
| 1105 | "label" => __('Clear compare list Button text', 'products-compare-for-woocommerce'), |
| 1106 | "type" => "text", |
| 1107 | "name" => array("text_settings", "remove_all_compare_text"), |
| 1108 | "extra" => 'placeholder="'.__( 'Clear compare list', 'products-compare-for-woocommerce' ).'"', |
| 1109 | "value" => '', |
| 1110 | ), |
| 1111 | 'hide_same_button_text' => array( |
| 1112 | "label" => __('Hide attributes with same value Button text', 'products-compare-for-woocommerce'), |
| 1113 | "type" => "text", |
| 1114 | "name" => array("text_settings", "hide_same_button_text"), |
| 1115 | "extra" => 'placeholder="'.__( 'Hide attributes with same values', 'products-compare-for-woocommerce' ).'"', |
| 1116 | "value" => '', |
| 1117 | ), |
| 1118 | 'show_same_button_text' => array( |
| 1119 | "label" => __('Show attributes with same value Button text', 'products-compare-for-woocommerce'), |
| 1120 | "type" => "text", |
| 1121 | "name" => array("text_settings", "show_same_button_text"), |
| 1122 | "extra" => 'placeholder="'.__( 'Show attributes with same values', 'products-compare-for-woocommerce' ).'"', |
| 1123 | "value" => '', |
| 1124 | ), |
| 1125 | ), |
| 1126 | 'Custom CSS/JavaScript' => array( |
| 1127 | 'global_font_awesome_disable' => array( |
| 1128 | "label" => __( 'Disable Font Awesome', "products-compare-for-woocommerce" ), |
| 1129 | "type" => "checkbox", |
| 1130 | "name" => "fontawesome_frontend_disable", |
| 1131 | "value" => '1', |
| 1132 | 'label_for' => __('Don\'t load Font Awesome css files on site front end. Use it only if you don\'t use Font Awesome icons in widgets or your theme has Font Awesome.', 'products-compare-for-woocommerce'), |
| 1133 | ), |
| 1134 | 'global_fontawesome_version' => array( |
| 1135 | "label" => __( 'Font Awesome Version', "products-compare-for-woocommerce" ), |
| 1136 | "name" => "fontawesome_frontend_version", |
| 1137 | "type" => "selectbox", |
| 1138 | "options" => array( |
| 1139 | array('value' => '', 'text' => __('Font Awesome 4', 'products-compare-for-woocommerce')), |
| 1140 | array('value' => 'fontawesome5', 'text' => __('Font Awesome 5', 'products-compare-for-woocommerce')), |
| 1141 | ), |
| 1142 | "value" => '', |
| 1143 | "label_for" => __('Version of Font Awesome that will be used on front end. Please select version that you have in your theme', 'products-compare-for-woocommerce'), |
| 1144 | ), |
| 1145 | array( |
| 1146 | "label" => __("Custom CSS", 'products-compare-for-woocommerce'), |
| 1147 | "name" => array("javascript_settings", "custom_css"), |
| 1148 | "type" => "textarea", |
| 1149 | "value" => "", |
| 1150 | ), |
| 1151 | array( |
| 1152 | "label" => __("JavaScript Before products load", 'products-compare-for-woocommerce'), |
| 1153 | "name" => array("javascript_settings", "before_load"), |
| 1154 | "type" => "textarea", |
| 1155 | "value" => "", |
| 1156 | ), |
| 1157 | array( |
| 1158 | "label" => __("JavaScript After products load", 'products-compare-for-woocommerce'), |
| 1159 | "name" => array("javascript_settings", "after_load"), |
| 1160 | "type" => "textarea", |
| 1161 | "value" => "", |
| 1162 | ), |
| 1163 | array( |
| 1164 | "label" => __("JavaScript Before remove product", 'products-compare-for-woocommerce'), |
| 1165 | "name" => array("javascript_settings", "before_remove"), |
| 1166 | "type" => "textarea", |
| 1167 | "value" => "", |
| 1168 | ), |
| 1169 | array( |
| 1170 | "label" => __("JavaScript After remove product", 'products-compare-for-woocommerce'), |
| 1171 | "name" => array("javascript_settings", "after_remove"), |
| 1172 | "type" => "textarea", |
| 1173 | "value" => "", |
| 1174 | ), |
| 1175 | ), |
| 1176 | 'Popup Templates' => array( |
| 1177 | 'templates' => array( |
| 1178 | "label" => "", |
| 1179 | "section" => 'templates' |
| 1180 | ), |
| 1181 | ) |
| 1182 | ) ); |
| 1183 | } |
| 1184 | public function section_attributes($data, $options_global) { |
| 1185 | $options = $options_global['general_settings']; |
| 1186 | $settings_name = $this->values['settings_name']; |
| 1187 | $html = '<th>' . __( 'Uses Attributes', 'products-compare-for-woocommerce' ) . '</th> |
| 1188 | <td>' . __( 'Select attributes that will be displayed on compare table', 'products-compare-for-woocommerce' ) . '</td> |
| 1189 | </tr> |
| 1190 | <tr><th></th><td>'; |
| 1191 | $attributes = get_taxonomies(); |
| 1192 | unset( $attributes['category']); |
| 1193 | unset( $attributes['post_tag']); |
| 1194 | unset( $attributes['nav_menu']); |
| 1195 | unset( $attributes['link_category']); |
| 1196 | unset( $attributes['post_format']); |
| 1197 | unset( $attributes['product_type']); |
| 1198 | unset( $attributes['product_tag']); |
| 1199 | unset( $attributes['product_shipping_class']); |
| 1200 | foreach ( $attributes as $key_attr => $attr ) { |
| 1201 | $tax = get_taxonomy( $attr ); |
| 1202 | $attributes[$key_attr] = $tax->labels->singular_name; |
| 1203 | } |
| 1204 | $attributes = array( |
| 1205 | 'cp_price' => __('Price', 'products-compare-for-woocommerce'), |
| 1206 | 'cp_add_to_cart' => __('Add To Cart Button', 'products-compare-for-woocommerce'), |
| 1207 | 'cp_short_description' => __('Short Description', 'products-compare-for-woocommerce'), |
| 1208 | 'cp_available' => __('Availability', 'products-compare-for-woocommerce'), |
| 1209 | 'cp_image' => __('Image', 'products-compare-for-woocommerce'), |
| 1210 | ) + $attributes; |
| 1211 | foreach ( $attributes as $attr => $attr_label ) { |
| 1212 | $checked = ''; |
| 1213 | if ( ( is_array( $options['attributes'] ) && in_array( $attr, $options['attributes'] ) ) || ! is_array( $options['attributes'] ) || count( $options['attributes'] ) == 0 ) { |
| 1214 | $checked = ' checked'; |
| 1215 | } |
| 1216 | $html .= '<p><label><input name="' . $settings_name . '[general_settings][attributes][]" type="checkbox" value="' . $attr . '"' . $checked . '>' . $attr_label . '</label></p>'; |
| 1217 | } |
| 1218 | $groups = apply_filters( 'acf/get_field_groups', array() ); |
| 1219 | if ( is_array( $groups ) ) { |
| 1220 | foreach ( $groups as $group ) { |
| 1221 | $fields = apply_filters( 'acf/field_group/get_fields', array(), $group['id'] ); |
| 1222 | if( is_array($fields) ) { |
| 1223 | foreach($fields as $field) { |
| 1224 | $checked = ''; |
| 1225 | if ( is_array( $options['attributes'] ) && isset( $options['attributes']['acf_br_fields'] ) && is_array( $options['attributes']['acf_br_fields'] ) && in_array($field['name'], $options['attributes']['acf_br_fields']) ) { |
| 1226 | $checked = ' checked'; |
| 1227 | } |
| 1228 | $html .= '<p><label> |
| 1229 | <input name="' . $settings_name . '[general_settings][attributes][acf_br_fields][]" type="checkbox" value="' . $field['name'] . '"' . $checked . '> |
| 1230 | <strong>ACF </strong><small>[' . $group['title'] . ']</small> ' . $field['label'] . ' |
| 1231 | </label></p>'; |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | $html .= '</td>'; |
| 1237 | return $html; |
| 1238 | } |
| 1239 | public function section_all_style($data, $options_global) { |
| 1240 | $settings_name = $this->values['settings_name']; |
| 1241 | $options = $options_global['style_settings']; |
| 1242 | $defaults = $this->defaults['style_settings']; |
| 1243 | ob_start(); |
| 1244 | include('templates/style_section.php'); |
| 1245 | return ob_get_clean(); |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | new BeRocket_Compare_Products; |
| 1250 |