PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.2.8
Ever Compare – Products Compare Plugin for WooCommerce v1.2.8
1.3.7 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 trunk 1.0.0 1.0.1 1.0.2 All 31 releases
ever-compare / includes / classes / Assets.php

Assets.php in Ever Compare – Products Compare Plugin for WooCommerce 1.2.8, at includes/classes/Assets.php

284 lines 11.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace EverCompare;
3 /**
4 * Assets handlers class
5 */
6 class Assets {
7
8 /**
9 * [$_instance]
10 * @var null
11 */
12 private static $_instance = null;
13
14 /**
15 * [$suffix]
16 * @var [string]
17 */
18 public $suffix = '';
19
20 /**
21 * [instance] Initializes a singleton instance
22 * @return [Base]
23 */
24 public static function instance() {
25 if ( is_null( self::$_instance ) ) {
26 self::$_instance = new self();
27 }
28 return self::$_instance;
29 }
30
31 /**
32 * Class constructor
33 */
34 private function __construct() {
35 $this->suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
36 add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
37 add_action( 'admin_enqueue_scripts', [ $this, 'register_assets' ] );
38 }
39
40 /**
41 * All available scripts
42 *
43 * @return array
44 */
45 public function get_scripts() {
46
47 $script_list = [
48 'evercompare-admin' => [
49 'src' => EVERCOMPARE_ASSETS . '/js/admin.js',
50 'version' => EVERCOMPARE_VERSION,
51 'deps' => [ 'jquery' ]
52 ],
53 'evercompare-frontend' => [
54 'src' => EVERCOMPARE_ASSETS . '/js/frontend'.$this->suffix.'.js',
55 'version' => EVERCOMPARE_VERSION,
56 'deps' => [ 'jquery' ]
57 ],
58 ];
59
60 return $script_list;
61
62 }
63
64 /**
65 * All available styles
66 *
67 * @return array
68 */
69 public function get_styles() {
70
71 $style_list = [
72 'evercompare-admin' => [
73 'src' => EVERCOMPARE_ASSETS . '/css/admin.css',
74 'version' => EVERCOMPARE_VERSION,
75 ],
76 'evercompare-frontend' => [
77 'src' => EVERCOMPARE_ASSETS . '/css/frontend'.$this->suffix.'.css',
78 'version' => EVERCOMPARE_VERSION,
79 ],
80 ];
81
82 return $style_list;
83
84 }
85
86 /**
87 * Register scripts and styles
88 *
89 * @return void
90 */
91 public function register_assets() {
92 $scripts = $this->get_scripts();
93 $styles = $this->get_styles();
94
95 foreach ( $scripts as $handle => $script ) {
96 $deps = isset( $script['deps'] ) ? $script['deps'] : false;
97
98 wp_register_script( $handle, $script['src'], $deps, $script['version'], true );
99 }
100
101 foreach ( $styles as $handle => $style ) {
102 $deps = isset( $style['deps'] ) ? $style['deps'] : false;
103
104 wp_register_style( $handle, $style['src'], $deps, $style['version'] );
105 }
106
107 // Inline CSS
108 wp_add_inline_style( 'evercompare-frontend', $this->inline_style() );
109
110 // Frontend Localize data
111 $option_data = array(
112 'remove_on_click' => ever_compare_get_option( 'remove_on_click','ever_compare_settings_tabs', 'off' ),
113 'enable_success_notification' => ever_compare_get_option( 'enable_success_notification', 'ever_compare_settings_general', 'off' ),
114 'success_added_notification_text' => ever_compare_get_option( 'success_added_notification_text', 'ever_compare_settings_general', __( '{product_name} added to wishlist.', 'ever-compare') ),
115 'success_removed_notification_text' => ever_compare_get_option( 'success_removed_notification_text', 'ever_compare_settings_general', __( '{product_name} removed from wishlist.', 'ever-compare') ),
116 'removed_notification_after' => ever_compare_get_option( 'removed_notification_after', 'ever_compare_settings_general', -1 ),
117 );
118 $localize_data = array(
119 'ajaxurl' => admin_url( 'admin-ajax.php' ),
120 'nonce' => wp_create_nonce('ever_compare_nonce'),
121 'popup' => ( ever_compare_get_option( 'open_popup', 'ever_compare_settings_tabs', 'on' ) === 'on' ) ? 'yes' : 'no',
122 'option_data' => $option_data,
123 );
124
125 // Admin Localize data
126 $setting_page = 0;
127 if( isset( $_GET['page'] ) && $_GET['page'] == 'evercompare' ){ //phpcs:ignore WordPress.Security.NonceVerification.Recommended
128 $setting_page = 1;
129 }
130 $admin_option_data = array(
131 'enable_success_notification' => ever_compare_get_option( 'enable_success_notification','ever_compare_settings_general','off' ),
132 'shop_btn_position' => ever_compare_get_option( 'shop_btn_position','ever_compare_settings_tabs','after_cart_btn' ),
133 'product_btn_position' => ever_compare_get_option( 'product_btn_position','ever_compare_settings_tabs','after_cart_btn' ),
134 'remove_on_click' => ever_compare_get_option( 'remove_on_click','ever_compare_settings_tabs', 'off' ),
135 'button_icon_type' => ever_compare_get_option( 'button_icon_type','ever_compare_settings_tabs','none' ),
136 'added_button_icon_type' => ever_compare_get_option( 'added_button_icon_type','ever_compare_settings_tabs','none' ),
137 'enable_shareable_link' => ever_compare_get_option( 'enable_shareable_link','ever_compare_table_settings_tabs','off' ),
138 'button_style' => ever_compare_get_option( 'button_style','ever_compare_style_tabs','theme' ),
139 'table_style' => ever_compare_get_option( 'table_style','ever_compare_style_tabs','default' ),
140 'notification_style' => ever_compare_get_option( 'notification_style','ever_compare_style_tabs','default' ),
141 );
142 $admin_localize_data = array(
143 'is_settings'=> $setting_page,
144 'option_data'=> $admin_option_data,
145 );
146 wp_localize_script( 'evercompare-frontend', 'evercompare', $localize_data );
147 wp_localize_script( 'evercompare-admin', 'evercompare', $admin_localize_data );
148
149 }
150
151 /**
152 * [inline_style]
153 * @return [CSS String]
154 */
155 public function inline_style(){
156
157 $inline_css = '';
158
159 // Button Custom Style
160 if( 'custom' === ever_compare_get_option( 'button_style', 'ever_compare_style_tabs', 'theme' ) ){
161
162 $btn_padding = ever_compare_dimensions( 'button_custom_padding','ever_compare_style_tabs','padding' );
163 $btn_margin = ever_compare_dimensions( 'button_custom_margin','ever_compare_style_tabs','margin' );
164 $btn_border_radius = ever_compare_dimensions( 'button_custom_border_radius','ever_compare_style_tabs','border-radius' );
165 $btn_border_width = ever_compare_dimensions( 'button_custom_border','ever_compare_style_tabs','border-width' );
166 $btn_border_style = !empty( $btn_border_width ) ? 'border-style:solid;' : '';
167
168 $btn_border_color = ever_compare_generate_css('button_custom_border_color','ever_compare_style_tabs','border-color');
169 $btn_color = ever_compare_generate_css('button_color','ever_compare_style_tabs','color');
170 $btn_bg_color = ever_compare_generate_css('background_color','ever_compare_style_tabs','background-color');
171
172 // Hover
173 $btn_hover_color = ever_compare_generate_css('button_hover_color','ever_compare_style_tabs','color');
174 $btn_hover_bg_color = ever_compare_generate_css('hover_background_color','ever_compare_style_tabs','background-color');
175
176 $inline_css .= "
177 .htcompare-btn{
178 {$btn_padding}
179 {$btn_margin}
180 {$btn_color}
181 {$btn_bg_color}
182 {$btn_border_width}
183 {$btn_border_style}
184 {$btn_border_color}
185 {$btn_border_radius}
186 }
187 .htcompare-btn:hover{
188 {$btn_hover_color}
189 {$btn_hover_bg_color}
190 }
191 ";
192
193 }
194
195 // Table style
196 if( 'custom' === ever_compare_get_option( 'table_style', 'ever_compare_style_tabs', 'default' ) ){
197
198 $border_color = ever_compare_generate_css('table_border_color','ever_compare_style_tabs','border-color');
199 $column_padding = ever_compare_dimensions( 'table_column_padding','ever_compare_style_tabs','padding' );
200
201 $event_bg_color = ever_compare_generate_css('table_event_color','ever_compare_style_tabs','background-color');
202 $odd_bg_color = ever_compare_generate_css('table_odd_color','ever_compare_style_tabs','background-color');
203
204 $event_heading_color = ever_compare_generate_css('table_heading_event_color','ever_compare_style_tabs','color');
205 $odd_heading_color = ever_compare_generate_css('table_heading_odd_color','ever_compare_style_tabs','color');
206
207 $event_content_color = ever_compare_generate_css('table_content_event_color','ever_compare_style_tabs','color');
208 $odd_content_color = ever_compare_generate_css('table_content_odd_color','ever_compare_style_tabs','color');
209
210 $link_color = ever_compare_generate_css('table_content_link_color','ever_compare_style_tabs','color');
211 $link_hover_color = ever_compare_generate_css('table_content_link_hover_color','ever_compare_style_tabs','color');
212
213 $inline_css .= "
214 .htcompare-col,.compare-data-primary .htcolumn-value{
215 {$border_color}
216 }
217 .htcompare-col{
218 {$column_padding}
219 }
220
221 .htcompare-row:nth-child(2n) .htcompare-col{
222 {$event_bg_color}
223 }
224 .htcompare-row:nth-child(2n+1) .htcompare-col{
225 {$odd_bg_color}
226 }
227
228 .htcompare-row:nth-child(2n) .htcompare-col.htcolumn-field-name{
229 {$event_heading_color}
230 }
231 .htcompare-row:nth-child(2n+1) .htcompare-col.htcolumn-field-name{
232 {$odd_heading_color}
233 }
234
235 .htcompare-row:nth-child(2n) .htcompare-col.htcolumn-value{
236 {$event_content_color}
237 }
238 .htcompare-row:nth-child(2n+1) .htcompare-col.htcolumn-value{
239 {$odd_content_color}
240 }
241
242 .htcompare-row .htcompare-col.htcolumn-value a{
243 {$link_color}
244 }
245 .htcompare-row .htcompare-col.htcolumn-value a:hover{
246 {$link_hover_color}
247 }
248
249 ";
250
251 }
252
253 // Notification Custom Style
254 if( 'custom' === ever_compare_get_option( 'notification_style', 'ever_compare_style_tabs', 'default' ) ){
255 $notification_color = ever_compare_generate_css('notification_text_color','ever_compare_style_tabs','color');
256 $notification_bg_color = ever_compare_generate_css('notification_bg_color','ever_compare_style_tabs','background-color');
257 $notification_border_color = ever_compare_generate_css('notification_border_color','ever_compare_style_tabs','border-color');
258 $notification_btn_color = ever_compare_generate_css('notification_btn_color','ever_compare_style_tabs','color');
259 $notification_btn_color_hover = ever_compare_generate_css('notification_btn_color_hover','ever_compare_style_tabs','color');
260
261 $inline_css .= "
262 .htcompare-notification{
263 {$notification_bg_color}
264 {$notification_border_color}
265 }
266 .htcompare-notification-text{
267 {$notification_color}
268 }
269 .htcompare-notification-close{
270 {$notification_btn_color}
271 }
272 .htcompare-notification-close:hover{
273 {$notification_btn_color_hover}
274 }
275 ";
276 }
277
278 return $inline_css;
279
280 }
281
282
283 }
284