| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * Quick View Module Class. | |
| 4 | + * | |
| 5 | + * @package RadiusTheme\SB | |
| 6 | + */ | |
| 2 | 7 | |
| 3 | 8 | namespace RadiusTheme\SB\Modules\QuickView; |
| 4 | 9 | |
| 5 | 10 | // Do not allow directly accessing this file. |
| @@ -6,34 +11,114 @@ | ||
| 6 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | 12 | exit( 'This script cannot be accessed directly.' ); |
| 8 | 13 | } |
| 9 | 14 | |
| 10 | -use RadiusTheme\SB\Modules\Compare\CompareInstaller; | |
| 15 | +use RadiusTheme\SB\Helpers\Fns; | |
| 11 | 16 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 12 | 17 | |
| 18 | +/** | |
| 19 | + * Quick View Module Class. | |
| 20 | + */ | |
| 13 | 21 | final class QuickView { |
| 22 | + /** | |
| 23 | + * @var array | |
| 24 | + */ | |
| 25 | + private $cache = []; | |
| 14 | 26 | |
| 15 | 27 | /** |
| 16 | 28 | * @var array |
| 17 | 29 | */ |
| 18 | 30 | public $settings = []; |
| 19 | - | |
| 20 | - //protected $module_id = 'quick_view'; | |
| 21 | - | |
| 31 | + /** | |
| 32 | + * @var array|mixed | |
| 33 | + */ | |
| 34 | + private array $options; | |
| 35 | + /** | |
| 36 | + * Options | |
| 37 | + */ | |
| 22 | 38 | use SingletonTrait; |
| 23 | 39 | |
| 24 | - function __construct() { | |
| 25 | - | |
| 40 | + /** | |
| 41 | + * Class constructor. | |
| 42 | + * | |
| 43 | + * @return void | |
| 44 | + */ | |
| 45 | + private function __construct() { | |
| 26 | 46 | QuickViewFrontEnd::instance(); |
| 27 | - | |
| 47 | + $this->options = Fns::get_options( 'modules', 'quick_view' ); | |
| 48 | + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_public_scripts' ], 99 ); | |
| 28 | 49 | do_action( 'rtsb/module/quick_view/loaded' ); |
| 29 | 50 | } |
| 30 | 51 | |
| 31 | 52 | /** |
| 32 | - * Do stuff upon plugin activation | |
| 33 | - * | |
| 34 | 53 | * @return void |
| 35 | 54 | */ |
| 36 | - public function activate() { | |
| 37 | - ( new CompareInstaller() )->run(); | |
| 55 | + public function enqueue_public_scripts() { | |
| 56 | + $cache_key = 'quick_view_style_cache'; | |
| 57 | + $width = ! empty( $this->options['modal_width'] ) ? $this->options['modal_width'] : '950'; | |
| 58 | + $handle = Fns::optimized_handle( 'rtsb-public' ); | |
| 59 | + | |
| 60 | + wp_localize_script( | |
| 61 | + $handle, | |
| 62 | + 'QvModalParams', | |
| 63 | + [ | |
| 64 | + 'modal_width' => absint( $width ), | |
| 65 | + ] | |
| 66 | + ); | |
| 67 | + | |
| 68 | + if ( isset( $this->cache[ $cache_key ] ) && ! empty( $this->cache[ $cache_key ] ) ) { | |
| 69 | + wp_add_inline_style( Fns::optimized_handle( 'rtsb-frontend' ), $this->cache[ $cache_key ] ); | |
| 70 | + return; | |
| 71 | + } | |
| 72 | + | |
| 73 | + $height = $this->options['modal_height'] ?? false; | |
| 74 | + $wrapper_padding = $this->options['modal_wrapper_padding'] ?? '0'; | |
| 75 | + $bg_color = $this->options['modal_bg_color'] ?? false; | |
| 76 | + $box_shadow = $this->options['modal_box_shadow_color'] ?? false; | |
| 77 | + $overly_color = $this->options['modal_overly_color'] ?? false; | |
| 78 | + | |
| 79 | + ob_start(); | |
| 80 | + | |
| 81 | + if ( $height ) { ?> | |
| 82 | + .rtsb-ui-modal .rtsb-modal-content{ | |
| 83 | + height: <?php echo esc_attr( $height ); ?>; | |
| 84 | + } | |
| 85 | + <?php | |
| 86 | + } | |
| 87 | + | |
| 88 | + if ( '' !== $wrapper_padding ) { | |
| 89 | + ?> | |
| 90 | + .rtsb-ui-modal .rtsb-modal-wrapper.quick-view-modal .rtsb-modal-content .rtsb-modal-body{ | |
| 91 | + padding: <?php echo esc_attr( $wrapper_padding ); ?>; | |
| 92 | + } | |
| 93 | + <?php | |
| 94 | + } | |
| 95 | + if ( $bg_color ) { | |
| 96 | + ?> | |
| 97 | + .rtsb-ui-modal .rtsb-modal-wrapper .rtsb-modal-content{ | |
| 98 | + background-color: <?php echo esc_attr( $bg_color ); ?>; | |
| 99 | + } | |
| 100 | + <?php | |
| 101 | + } | |
| 102 | + if ( $box_shadow ) { | |
| 103 | + ?> | |
| 104 | + .rtsb-ui-modal .rtsb-modal-content{ | |
| 105 | + box-shadow: 0 0 10px <?php echo esc_attr( $box_shadow ); ?>; | |
| 106 | + } | |
| 107 | + <?php | |
| 108 | + } | |
| 109 | + | |
| 110 | + if ( $overly_color ) { | |
| 111 | + ?> | |
| 112 | + .rtsb-ui-modal .rtsb-mask-wrapper{ | |
| 113 | + background-color: <?php echo esc_attr( $overly_color ); ?>; | |
| 114 | + } | |
| 115 | + <?php | |
| 116 | + } | |
| 117 | + | |
| 118 | + $dynamic_css = ob_get_clean(); | |
| 119 | + $this->cache[ $cache_key ] = $dynamic_css; | |
| 120 | + if ( ! empty( $dynamic_css ) ) { | |
| 121 | + wp_add_inline_style( Fns::optimized_handle( 'rtsb-frontend' ), $dynamic_css ); | |
| 122 | + } | |
| 38 | 123 | } |
| 39 | -} | |
| 124 | +} | |