PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.1.9
Ever Compare – Products Compare Plugin for WooCommerce v1.1.9
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 / helper-functions.php

helper-functions.php in Ever Compare – Products Compare Plugin for WooCommerce 1.1.9, at includes/helper-functions.php

219 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugisn Options value
4 * return on/off
5 */
6 function ever_compare_get_option( $option, $section, $default = '' ){
7 $options = get_option( $section );
8 if ( isset( $options[$option] ) ) {
9 return $options[$option];
10 }
11 return $default;
12 }
13
14 /**
15 * [ever_compare_update_option]
16 * @param [string] $option
17 * @param [string] $section
18 * @param string $new_value
19 * @return [string]
20 */
21 function ever_compare_update_option( $section, $option_key, $new_value ){
22 $options_data = get_option( $section );
23 if( isset( $options_data[$option_key] ) ){
24 $options_data[$option_key] = $new_value;
25 }else{
26 $options_data = array( $option_key => $new_value );
27 }
28 update_option( $section, $options_data );
29 }
30
31 /**
32 * [ever_compare_woocommerce_installed]
33 * @return [boolean]
34 */
35 function ever_compare_woocommerce_installed() {
36 return class_exists( 'WooCommerce' );
37 }
38
39 /**
40 * Get Post List
41 * return array
42 */
43 function ever_compare_get_post_list( $post_type = 'page' ){
44 $options = array();
45 $options['0'] = __('Select','ever-compare');
46 $perpage = -1;
47 $all_post = array( 'posts_per_page' => $perpage, 'post_type'=> $post_type );
48 $post_terms = get_posts( $all_post );
49 if ( ! empty( $post_terms ) && ! is_wp_error( $post_terms ) ){
50 foreach ( $post_terms as $term ) {
51 $options[ $term->ID ] = $term->post_title;
52 }
53 return $options;
54 }
55 }
56
57 /**
58 * [ever_compare_locate_template]
59 * @param [string] $tmp_name Template name
60 * @return [Template path]
61 */
62 function ever_compare_locate_template( $tmp_name ) {
63
64 $woo_tmp_base = function_exists('WC') ? WC()->template_path() : '';
65
66 $woo_tmp_path = $woo_tmp_base . $tmp_name; //active theme directory/woocommerce/
67 $theme_tmp_path = '/' . $tmp_name; //active theme root directory
68 $plugin_tmp_path = EVERCOMPARE_DIR . 'includes/templates/' . $tmp_name;
69
70 $located = locate_template( [ $woo_tmp_path, $theme_tmp_path ] );
71
72 if ( ! $located && file_exists( $plugin_tmp_path ) ) {
73 return apply_filters( 'evercompare_locate_template', $plugin_tmp_path, $tmp_name );
74 }
75
76 return apply_filters( 'evercompare_locate_template', $located, $tmp_name );
77 }
78
79 /**
80 * [ever_compare_get_template]
81 * @param [string] $tmp_name Template name
82 * @param [array] $args template argument array
83 * @param boolean $echo
84 * @return [void]
85 */
86 function ever_compare_get_template( $tmp_name = '', $args = null, $echo = true ) {
87 $located = ever_compare_locate_template( $tmp_name );
88
89 if ( $args && is_array( $args ) ) {
90 extract( $args );
91 }
92
93 if ( $echo !== true ) { ob_start(); }
94
95 // include file located.
96 include( $located );
97
98 if ( $echo !== true ) { return ob_get_clean(); }
99
100 }
101
102
103 /**
104 * Get default fields List
105 * return array
106 */
107 function ever_compare_get_default_fields(){
108 $fields = array(
109 'title' => esc_html__( 'Title', 'ever-compare' ),
110 'ratting' => esc_html__( 'Ratting', 'ever-compare' ),
111 'price' => esc_html__( 'Price', 'ever-compare' ),
112 'add_to_cart' => esc_html__( 'Add To Cart', 'ever-compare' ),
113 'description' => esc_html__( 'Description', 'ever-compare' ),
114 'availability' => esc_html__( 'Availability', 'ever-compare' ),
115 'sku' => esc_html__( 'Sku', 'ever-compare' ),
116 'weight' => esc_html__( 'Weight', 'ever-compare' ),
117 'dimensions' => esc_html__( 'Dimensions', 'ever-compare' ),
118 );
119 return apply_filters( 'ever_compare_default_fields', $fields );
120 }
121
122 /**
123 * Get Fields List
124 * return array
125 */
126 function ever_compare_get_available_attributes() {
127 $attribute_list = array();
128
129 if( function_exists( 'wc_get_attribute_taxonomies' ) ) {
130 $attribute_list = wc_get_attribute_taxonomies();
131 }
132
133 $fields = ever_compare_get_default_fields();
134
135 if ( count( $attribute_list ) > 0 ) {
136 foreach ( $attribute_list as $attribute ) {
137 $fields[ 'pa_' . $attribute->attribute_name ] = $attribute->attribute_label;
138 }
139 }
140
141 return $fields;
142 }
143
144 /**
145 * [ever_compare_table_active_heading]
146 * @return [array]
147 */
148 function ever_compare_table_active_heading(){
149 $active_heading = !empty( ever_compare_get_option( 'show_fields', 'ever_compare_table_settings_tabs' ) ) ? ever_compare_get_option( 'show_fields', 'ever_compare_table_settings_tabs' ) : array();
150 return $active_heading;
151 }
152
153 /**
154 * [ever_compare_table_heading]
155 * @return [array]
156 */
157 function ever_compare_table_heading(){
158 $new_list = array();
159 $field_list = count( ever_compare_table_active_heading() ) > 0 ? ever_compare_table_active_heading() : ever_compare_get_default_fields();
160 foreach ( $field_list as $key => $value ) {
161 $new_list[$key] = \EverCompare\Frontend\Manage_Compare::instance()->field_name( $key );
162 }
163 return $new_list;
164 }
165
166 /**
167 * [ever_compare_dimensions]
168 * @param [string] $key
169 * @param [string] $tab
170 * @return [String | Bool]
171 */
172 function ever_compare_dimensions( $key, $tab, $css_attr ){
173 $dimensions = !empty( ever_compare_get_option( $key, $tab ) ) ? ever_compare_get_option( $key, $tab ) : array();
174 if( !empty( $dimensions['top'] ) || !empty( $dimensions['right'] ) || !empty( $dimensions['bottom'] ) || !empty( $dimensions['left'] ) ){
175
176 $unit = ( empty( $dimensions['unit'] ) ? 'px' : $dimensions['unit'] );
177 $top = ( !empty( $dimensions['top'] ) ? $dimensions['top'] : 0 );
178 $right = ( !empty( $dimensions['right'] ) ? $dimensions['right'] : 0 );
179 $bottom = ( !empty( $dimensions['bottom'] ) ? $dimensions['bottom'] : 0 );
180 $left = ( !empty( $dimensions['left'] ) ? $dimensions['left'] : 0 );
181
182 $css_attr .= ":{$top}{$unit} {$right}{$unit} {$bottom}{$unit} {$left}{$unit}";
183 return $css_attr.';';
184
185 }else{
186 return false;
187 }
188 }
189
190 /**
191 * [ever_compare_generate_css]
192 * @return [String | Bool]
193 */
194 function ever_compare_generate_css( $key, $tab, $css_attr, $unit = '' ){
195 $field_value = !empty( ever_compare_get_option( $key, $tab ) ) ? ever_compare_get_option( $key, $tab ) : '';
196
197 if( !empty( $field_value ) ){
198 $css_attr .= ":{$field_value}{$unit}";
199 return $css_attr.';';
200 }else{
201 return false;
202 }
203
204 }
205
206 /**
207 * [ever_compare_icon_list]
208 * @return [svg]
209 */
210 function ever_compare_icon_list( $key = '' ){
211 $icon_list = [
212 'default' => '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 471.701 471.701">
213 <g class="ever-compare-refresh"><path d="M409.6,0c-9.426,0-17.067,7.641-17.067,17.067v62.344C304.667-5.656,164.478-3.386,79.411,84.479 c-40.09,41.409-62.455,96.818-62.344,154.454c0,9.426,7.641,17.067,17.067,17.067S51.2,248.359,51.2,238.933 c0.021-103.682,84.088-187.717,187.771-187.696c52.657,0.01,102.888,22.135,138.442,60.976l-75.605,25.207 c-8.954,2.979-13.799,12.652-10.82,21.606s12.652,13.799,21.606,10.82l102.4-34.133c6.99-2.328,11.697-8.88,11.674-16.247v-102.4 C426.667,7.641,419.026,0,409.6,0z"/><path d="M443.733,221.867c-9.426,0-17.067,7.641-17.067,17.067c-0.021,103.682-84.088,187.717-187.771,187.696 c-52.657-0.01-102.888-22.135-138.442-60.976l75.605-25.207c8.954-2.979,13.799-12.652,10.82-21.606 c-2.979-8.954-12.652-13.799-21.606-10.82l-102.4,34.133c-6.99,2.328-11.697,8.88-11.674,16.247v102.4 c0,9.426,7.641,17.067,17.067,17.067s17.067-7.641,17.067-17.067v-62.345c87.866,85.067,228.056,82.798,313.122-5.068 c40.09-41.409,62.455-96.818,62.344-154.454C460.8,229.508,453.159,221.867,443.733,221.867z"/></g>
214 <g class="ever-compare-check"><path d="M238.933,0C106.974,0,0,106.974,0,238.933s106.974,238.933,238.933,238.933s238.933-106.974,238.933-238.933 C477.726,107.033,370.834,0.141,238.933,0z M238.933,443.733c-113.108,0-204.8-91.692-204.8-204.8s91.692-204.8,204.8-204.8 s204.8,91.692,204.8,204.8C443.611,351.991,351.991,443.611,238.933,443.733z"/><path d="M370.046,141.534c-6.614-6.388-17.099-6.388-23.712,0v0L187.733,300.134l-56.201-56.201 c-6.548-6.78-17.353-6.967-24.132-0.419c-6.78,6.548-6.967,17.353-0.419,24.132c0.137,0.142,0.277,0.282,0.419,0.419 l68.267,68.267c6.664,6.663,17.468,6.663,24.132,0l170.667-170.667C377.014,158.886,376.826,148.082,370.046,141.534z"/></g></svg>',
215 'loading' => '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 471.701 471.701">
216 <g class="ever-compare-refresh"><path d="M409.6,0c-9.426,0-17.067,7.641-17.067,17.067v62.344C304.667-5.656,164.478-3.386,79.411,84.479 c-40.09,41.409-62.455,96.818-62.344,154.454c0,9.426,7.641,17.067,17.067,17.067S51.2,248.359,51.2,238.933 c0.021-103.682,84.088-187.717,187.771-187.696c52.657,0.01,102.888,22.135,138.442,60.976l-75.605,25.207 c-8.954,2.979-13.799,12.652-10.82,21.606s12.652,13.799,21.606,10.82l102.4-34.133c6.99-2.328,11.697-8.88,11.674-16.247v-102.4 C426.667,7.641,419.026,0,409.6,0z"/><path d="M443.733,221.867c-9.426,0-17.067,7.641-17.067,17.067c-0.021,103.682-84.088,187.717-187.771,187.696 c-52.657-0.01-102.888-22.135-138.442-60.976l75.605-25.207c8.954-2.979,13.799-12.652,10.82-21.606 c-2.979-8.954-12.652-13.799-21.606-10.82l-102.4,34.133c-6.99,2.328-11.697,8.88-11.674,16.247v102.4 c0,9.426,7.641,17.067,17.067,17.067s17.067-7.641,17.067-17.067v-62.345c87.866,85.067,228.056,82.798,313.122-5.068 c40.09-41.409,62.455-96.818,62.344-154.454C460.8,229.508,453.159,221.867,443.733,221.867z"/></g></svg>'
217 ];
218 return ( $key == '' ) ? $icon_list : $icon_list[$key];
219 }