PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.3.5
Ever Compare – Products Compare Plugin for WooCommerce v1.3.5
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.3.5, at includes/classes/Assets.php

289 lines 12.0 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 $cookie_name = 'ever_compare_compare_list';
119 if ( is_multisite() ) {
120 $cookie_name .= '_' . get_current_blog_id();
121 }
122 $localize_data = array(
123 'ajaxurl' => admin_url( 'admin-ajax.php' ),
124 'cookie_name' => $cookie_name,
125 'compare_page_url' => esc_url( get_permalink( ever_compare_get_option( 'compare_page', 'ever_compare_table_settings_tabs' ) ) ),
126 'popup' => ( ever_compare_get_option( 'open_popup', 'ever_compare_settings_tabs', 'on' ) === 'on' ) ? 'yes' : 'no',
127 'option_data' => $option_data,
128 );
129
130 // Admin Localize data
131 $setting_page = 0;
132 if( isset( $_GET['page'] ) && $_GET['page'] == 'evercompare' ){ //phpcs:ignore WordPress.Security.NonceVerification.Recommended
133 $setting_page = 1;
134 }
135 $admin_option_data = array(
136 'enable_success_notification' => ever_compare_get_option( 'enable_success_notification','ever_compare_settings_general','off' ),
137 'shop_btn_position' => ever_compare_get_option( 'shop_btn_position','ever_compare_settings_tabs','after_cart_btn' ),
138 'product_btn_position' => ever_compare_get_option( 'product_btn_position','ever_compare_settings_tabs','after_cart_btn' ),
139 'remove_on_click' => ever_compare_get_option( 'remove_on_click','ever_compare_settings_tabs', 'off' ),
140 'button_icon_type' => ever_compare_get_option( 'button_icon_type','ever_compare_settings_tabs','none' ),
141 'added_button_icon_type' => ever_compare_get_option( 'added_button_icon_type','ever_compare_settings_tabs','none' ),
142 'enable_shareable_link' => ever_compare_get_option( 'enable_shareable_link','ever_compare_table_settings_tabs','off' ),
143 'button_style' => ever_compare_get_option( 'button_style','ever_compare_style_tabs','theme' ),
144 'table_style' => ever_compare_get_option( 'table_style','ever_compare_style_tabs','default' ),
145 'notification_style' => ever_compare_get_option( 'notification_style','ever_compare_style_tabs','default' ),
146 );
147 $admin_localize_data = array(
148 'is_settings'=> $setting_page,
149 'option_data'=> $admin_option_data,
150 );
151 wp_localize_script( 'evercompare-frontend', 'evercompare', $localize_data );
152 wp_localize_script( 'evercompare-admin', 'evercompare', $admin_localize_data );
153
154 }
155
156 /**
157 * [inline_style]
158 * @return [CSS String]
159 */
160 public function inline_style(){
161
162 $inline_css = '';
163
164 // Button Custom Style
165 if( 'custom' === ever_compare_get_option( 'button_style', 'ever_compare_style_tabs', 'theme' ) ){
166
167 $btn_padding = ever_compare_dimensions( 'button_custom_padding','ever_compare_style_tabs','padding' );
168 $btn_margin = ever_compare_dimensions( 'button_custom_margin','ever_compare_style_tabs','margin' );
169 $btn_border_radius = ever_compare_dimensions( 'button_custom_border_radius','ever_compare_style_tabs','border-radius' );
170 $btn_border_width = ever_compare_dimensions( 'button_custom_border','ever_compare_style_tabs','border-width' );
171 $btn_border_style = !empty( $btn_border_width ) ? 'border-style:solid;' : '';
172
173 $btn_border_color = ever_compare_generate_css('button_custom_border_color','ever_compare_style_tabs','border-color');
174 $btn_color = ever_compare_generate_css('button_color','ever_compare_style_tabs','color');
175 $btn_bg_color = ever_compare_generate_css('background_color','ever_compare_style_tabs','background-color');
176
177 // Hover
178 $btn_hover_color = ever_compare_generate_css('button_hover_color','ever_compare_style_tabs','color');
179 $btn_hover_bg_color = ever_compare_generate_css('hover_background_color','ever_compare_style_tabs','background-color');
180
181 $inline_css .= "
182 .htcompare-btn{
183 {$btn_padding}
184 {$btn_margin}
185 {$btn_color}
186 {$btn_bg_color}
187 {$btn_border_width}
188 {$btn_border_style}
189 {$btn_border_color}
190 {$btn_border_radius}
191 }
192 .htcompare-btn:hover{
193 {$btn_hover_color}
194 {$btn_hover_bg_color}
195 }
196 ";
197
198 }
199
200 // Table style
201 if( 'custom' === ever_compare_get_option( 'table_style', 'ever_compare_style_tabs', 'default' ) ){
202
203 $border_color = ever_compare_generate_css('table_border_color','ever_compare_style_tabs','border-color');
204 $column_padding = ever_compare_dimensions( 'table_column_padding','ever_compare_style_tabs','padding' );
205
206 $event_bg_color = ever_compare_generate_css('table_event_color','ever_compare_style_tabs','background-color');
207 $odd_bg_color = ever_compare_generate_css('table_odd_color','ever_compare_style_tabs','background-color');
208
209 $event_heading_color = ever_compare_generate_css('table_heading_event_color','ever_compare_style_tabs','color');
210 $odd_heading_color = ever_compare_generate_css('table_heading_odd_color','ever_compare_style_tabs','color');
211
212 $event_content_color = ever_compare_generate_css('table_content_event_color','ever_compare_style_tabs','color');
213 $odd_content_color = ever_compare_generate_css('table_content_odd_color','ever_compare_style_tabs','color');
214
215 $link_color = ever_compare_generate_css('table_content_link_color','ever_compare_style_tabs','color');
216 $link_hover_color = ever_compare_generate_css('table_content_link_hover_color','ever_compare_style_tabs','color');
217
218 $inline_css .= "
219 .htcompare-col,.compare-data-primary .htcolumn-value{
220 {$border_color}
221 }
222 .htcompare-col{
223 {$column_padding}
224 }
225
226 .htcompare-row:nth-child(2n) .htcompare-col{
227 {$event_bg_color}
228 }
229 .htcompare-row:nth-child(2n+1) .htcompare-col{
230 {$odd_bg_color}
231 }
232
233 .htcompare-row:nth-child(2n) .htcompare-col.htcolumn-field-name{
234 {$event_heading_color}
235 }
236 .htcompare-row:nth-child(2n+1) .htcompare-col.htcolumn-field-name{
237 {$odd_heading_color}
238 }
239
240 .htcompare-row:nth-child(2n) .htcompare-col.htcolumn-value{
241 {$event_content_color}
242 }
243 .htcompare-row:nth-child(2n+1) .htcompare-col.htcolumn-value{
244 {$odd_content_color}
245 }
246
247 .htcompare-row .htcompare-col.htcolumn-value a{
248 {$link_color}
249 }
250 .htcompare-row .htcompare-col.htcolumn-value a:hover{
251 {$link_hover_color}
252 }
253
254 ";
255
256 }
257
258 // Notification Custom Style
259 if( 'custom' === ever_compare_get_option( 'notification_style', 'ever_compare_style_tabs', 'default' ) ){
260 $notification_color = ever_compare_generate_css('notification_text_color','ever_compare_style_tabs','color');
261 $notification_bg_color = ever_compare_generate_css('notification_bg_color','ever_compare_style_tabs','background-color');
262 $notification_border_color = ever_compare_generate_css('notification_border_color','ever_compare_style_tabs','border-color');
263 $notification_btn_color = ever_compare_generate_css('notification_btn_color','ever_compare_style_tabs','color');
264 $notification_btn_color_hover = ever_compare_generate_css('notification_btn_color_hover','ever_compare_style_tabs','color');
265
266 $inline_css .= "
267 .htcompare-notification{
268 {$notification_bg_color}
269 {$notification_border_color}
270 }
271 .htcompare-notification-text{
272 {$notification_color}
273 }
274 .htcompare-notification-close{
275 {$notification_btn_color}
276 }
277 .htcompare-notification-close:hover{
278 {$notification_btn_color_hover}
279 }
280 ";
281 }
282
283 return $inline_css;
284
285 }
286
287
288 }
289