/var/www/hkosl.com/aga/wp-content/plugins/so-widgets-bundle/widgets/price-table/price-table.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php

/*
Widget Name: Price Table
Description: A powerful yet simple price table widget for your sidebars or Page Builder pages.
Author: SiteOrigin
Author URI: https://siteorigin.com
Documentation: https://siteorigin.com/widgets-bundle/price-table-widget/
*/

class SiteOrigin_Widget_PriceTable_Widget extends SiteOrigin_Widget {
    function 
__construct() {
        
parent::__construct(
            
'sow-price-table',
            
__'SiteOrigin Price Table''so-widgets-bundle' ),
            array(
                
'description' => __'A simple Price Table.''so-widgets-bundle' ),
                
'help'        => 'https://siteorigin.com/widgets-bundle/price-table-widget/'
            
),
            array(),
            
false,
            
plugin_dir_path__FILE__ ) . '../'
        
);
    }

    function 
initialize() {
        
$this->register_frontend_scripts(
            array(
                array(
                    
'siteorigin-pricetable',
                    
plugin_dir_url__FILE__ ) . 'js/pricetable' SOW_BUNDLE_JS_SUFFIX '.js',
                    array( 
'jquery' )
                )
            )
        );
    }

    function 
get_widget_form() {
        return array(
            
'title' => array(
                
'type'  => 'text',
                
'label' => __'Title''so-widgets-bundle' ),
            ),

            
'columns' => array(
                
'type'       => 'repeater',
                
'label'      => __'Columns''so-widgets-bundle' ),
                
'item_name'  => __'Column''so-widgets-bundle' ),
                
'item_label' => array(
                    
'selector'     => "[id*='columns-title']",
                    
'update_event' => 'change',
                    
'value_method' => 'val'
                
),
                
'fields'     => array(
                    
'featured' => array(
                        
'type'  => 'checkbox',
                        
'label' => __'Featured''so-widgets-bundle' ),
                    ),
                    
'title'    => array(
                        
'type'  => 'text',
                        
'label' => __'Title''so-widgets-bundle' ),
                    ),
                    
'subtitle' => array(
                        
'type'  => 'text',
                        
'label' => __'Subtitle''so-widgets-bundle' ),
                    ),

                    
'image' => array(
                        
'type'  => 'media',
                        
'label' => __'Image''so-widgets-bundle' ),
                    ),

                    
'image_title' => array(
                        
'type'  => 'text',
                        
'label' => __'Image title''so-widgets-bundle' ),
                    ),

                    
'image_alt' => array(
                        
'type'  => 'text',
                        
'label' => __'Image alt text''so-widgets-bundle' ),
                    ),

                    
'price'    => array(
                        
'type'  => 'text',
                        
'label' => __'Price''so-widgets-bundle' ),
                    ),
                    
'per'      => array(
                        
'type'  => 'text',
                        
'label' => __'Per''so-widgets-bundle' ),
                    ),
                    
'button'   => array(
                        
'type'  => 'text',
                        
'label' => __'Button text''so-widgets-bundle' ),
                    ),
                    
'url'      => array(
                        
'type'  => 'link',
                        
'label' => __'Button URL''so-widgets-bundle' ),
                    ),
                    
'features' => array(
                        
'type'       => 'repeater',
                        
'label'      => __'Features''so-widgets-bundle' ),
                        
'item_name'  => __'Feature''so-widgets-bundle' ),
                        
'item_label' => array(
                            
'selector'     => "[id*='columns-features-text']",
                            
'update_event' => 'change',
                            
'value_method' => 'val'
                        
),
                        
'fields'     => array(
                            
'text'       => array(
                                
'type'  => 'text',
                                
'label' => __'Text''so-widgets-bundle' ),
                            ),
                            
'hover'      => array(
                                
'type'  => 'text',
                                
'label' => __'Hover text''so-widgets-bundle' ),
                            ),
                            
'icon_new'   => array(
                                
'type'  => 'icon',
                                
'label' => __'Icon''so-widgets-bundle' ),
                            ),
                            
'icon_color' => array(
                                
'type'  => 'color',
                                
'label' => __'Icon color''so-widgets-bundle' ),
                            ),
                        ),
                    ),
                ),
            ),

            
'theme' => array(
                
'type'    => 'select',
                
'label'   => __'Price table theme''so-widgets-bundle' ),
                
'options' => array(
                    
'atom' => __'Atom''so-widgets-bundle' ),
                ),
            ),

            
'header_color' => array(
                
'type'  => 'color',
                
'label' => __'Header color''so-widgets-bundle' ),
            ),

            
'featured_header_color' => array(
                
'type'  => 'color',
                
'label' => __'Featured header color''so-widgets-bundle' ),
            ),

            
'button_color' => array(
                
'type'  => 'color',
                
'label' => __'Button color''so-widgets-bundle' ),
            ),

            
'featured_button_color' => array(
                
'type'  => 'color',
                
'label' => __'Featured button color''so-widgets-bundle' ),
            ),

            
'button_new_window' => array(
                
'type'  => 'checkbox',
                
'label' => __'Open Button URL in a new window''so-widgets-bundle' ),
            ),

            
'equalize_row_heights' => array(
                
'type'  => 'checkbox',
                
'label' => __'Equalize row heights''so-widgets-bundle' ),
            ),
        );
    }

    function 
get_column_classes$column$i$columns ) {
        
$classes = array();
        if ( 
$i == ) {
            
$classes[] = 'ow-pt-first';
        }
        if ( 
$i == count$columns ) - ) {
            
$classes[] = 'ow-pt-last';
        }
        if ( ! empty( 
$column['featured'] ) ) {
            
$classes[] = 'ow-pt-featured';
        }

        if ( 
$i == ) {
            
$classes[] = 'ow-pt-even';
        } else {
            
$classes[] = 'ow-pt-odd';
        }

        return 
implode' '$classes );
    }

    function 
column_image$column ) {
        
$image $column['image'];

        if ( ! empty( 
$image ) ) {
            
$size 'full';
            
$src  wp_get_attachment_image_src$image$size );

            
$img_attrs = array();
            if ( 
function_exists'wp_get_attachment_image_srcset' ) ) {
                
$img_attrs['srcset'] = wp_get_attachment_image_srcset$image$size );
            }
            if ( 
function_exists'wp_get_attachment_image_sizes' ) ) {
                
$img_attrs['sizes'] = wp_get_attachment_image_sizes$image$size );
            }

            if ( ! empty( 
$column['image_title'] ) ) {
                
$img_attrs['title'] = $column['image_title'];
            }
            if ( ! empty( 
$column['image_alt'] ) ) {
                
$img_attrs['alt'] = $column['image_alt'];
            }
            
$attr_string '';
            foreach ( 
$img_attrs as $attr => $val ) {
                
$attr_string .= ' ' $attr '="' esc_attr$val ) . '"';
            }
            
?><img src="<?php echo $src[0?>"<?php echo $attr_string ?>/> <?php
        
}
    }

    function 
get_template_name$instance ) {
        return 
$this->get_style_name$instance );
    }

    function 
get_template_variables$instance$args ) {
        
$columns              = array();
        
$any_column_has_image false;
        if( ! empty( 
$instance'columns' ] ) ) {
            foreach ( 
$instance['columns'] as $column ) {
                
$any_column_has_image $any_column_has_image || ! empty( $column['image'] );
                if ( ! empty( 
$column['features'] ) ) {
                    foreach ( 
$column['features'] as &$feature ) {
                        
$feature['text'] = do_shortcode$feature['text'] );
                    }
                }
                
$columns[] = $column;
            }
        }

        return array(
            
'title'                => $instance['title'],
            
'columns'              => $columns,
            
'before_title'         => $args['before_title'],
            
'after_title'          => $args['after_title'],
            
'button_new_window'    => $instance['button_new_window'],
            
'equalize_row_heights' => ! empty( $instance['equalize_row_heights'] ),
            
'any_column_has_image' => $any_column_has_image,
        );
    }


    function 
get_style_name$instance ) {
        if ( empty( 
$instance['theme'] ) ) {
            return 
'atom';
        }

        return 
$instance['theme'];
    }

    
/**
     * Get the LESS variables for the price table widget.
     *
     * @param $instance
     *
     * @return array
     */
    
function get_less_variables$instance ) {
        
$instance wp_parse_args$instance, array(
            
'header_color'          => '',
            
'featured_header_color' => '',
            
'button_color'          => '',
            
'featured_button_color' => '',
        ) );

        
$colors = array(
            
'header_color'          => $instance['header_color'],
            
'featured_header_color' => $instance['featured_header_color'],
            
'button_color'          => $instance['button_color'],
            
'featured_button_color' => $instance['featured_button_color'],
        );

        if ( ! 
class_exists'SiteOrigin_Widgets_Color_Object' ) ) {
            require 
plugin_dir_pathSOW_BUNDLE_BASE_FILE ) . 'base/inc/color.php';
        }

        if ( ! empty( 
$instance['button_color'] ) ) {
            
$color = new SiteOrigin_Widgets_Color_Object$instance['button_color'] );
            
$color->lum += ( $color->lum 0.75 ? - 0.5 0.8 );
            
$colors['button_text_color'] = $color->hex;
        }

        if ( ! empty( 
$instance['featured_button_color'] ) ) {
            
$color = new SiteOrigin_Widgets_Color_Object$instance['featured_button_color'] );
            
$color->lum += ( $color->lum 0.75 ? - 0.5 0.8 );
            
$colors['featured_button_text_color'] = $color->hex;
        }

        return 
$colors;
    }

    
/**
     * Modify the instance to use the new icon.
     */
    
function modify_instance$instance ) {
        if ( empty( 
$instance['columns'] ) || ! is_array$instance['columns'] ) ) {
            return 
$instance;
        }

        foreach ( 
$instance['columns'] as &$column ) {
            if ( empty( 
$column['features'] ) || ! is_array$column['features'] ) ) {
                continue;
            }

            foreach ( 
$column['features'] as &$feature ) {

                if ( empty( 
$feature['icon_new'] ) && ! empty( $feature['icon'] ) ) {
                    
$feature['icon_new'] = 'fontawesome-' $feature['icon'];
                }

            }
        }

        return 
$instance;
    }
}

siteorigin_widget_register'sow-price-table'__FILE__'SiteOrigin_Widget_PriceTable_Widget' );