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 / helper-functions.php

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

244 lines 10.0 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 ( ! is_array( $options_data ) ) {
24 $options_data = array();
25 }
26 $options_data[ $option_key ] = $new_value;
27 update_option( $section, $options_data );
28 }
29
30 /**
31 * [ever_compare_woocommerce_installed]
32 * @return [boolean]
33 */
34 function ever_compare_woocommerce_installed() {
35 return class_exists( 'WooCommerce' );
36 }
37
38 /**
39 * Get Post List
40 * return array
41 */
42 function ever_compare_get_post_list( $post_type = 'page' ){
43 $options = array();
44 $options['0'] = __('Select','ever-compare');
45 $perpage = 200;
46 $all_post = array( 'posts_per_page' => $perpage, 'post_type'=> $post_type );
47 $post_terms = get_posts( $all_post );
48 if ( ! empty( $post_terms ) && ! is_wp_error( $post_terms ) ){
49 foreach ( $post_terms as $term ) {
50 $options[ $term->ID ] = $term->post_title;
51 }
52 return $options;
53 }
54 }
55
56 /**
57 * [ever_compare_locate_template]
58 * @param [string] $tmp_name Template name
59 * @return [Template path]
60 */
61 function ever_compare_locate_template( $tmp_name ) {
62
63 $woo_tmp_base = function_exists('WC') ? WC()->template_path() : '';
64
65 $woo_tmp_path = $woo_tmp_base . $tmp_name; //active theme directory/woocommerce/
66 $theme_tmp_path = '/' . $tmp_name; //active theme root directory
67 $plugin_tmp_path = EVERCOMPARE_DIR . 'includes/templates/' . $tmp_name;
68
69 $located = locate_template( [ $woo_tmp_path, $theme_tmp_path ] );
70
71 if ( ! $located && file_exists( $plugin_tmp_path ) ) {
72 return apply_filters( 'evercompare_locate_template', $plugin_tmp_path, $tmp_name );
73 }
74
75 return apply_filters( 'evercompare_locate_template', $located, $tmp_name );
76 }
77
78 /**
79 * [ever_compare_get_template]
80 * @param [string] $tmp_name Template name
81 * @param [array] $args template argument array
82 * @param boolean $echo
83 * @return [void]
84 */
85 function ever_compare_get_template( $tmp_name = '', $args = null, $echo = true ) {
86 $located = ever_compare_locate_template( $tmp_name );
87
88 if ( $args && is_array( $args ) ) {
89 $evercompare_args = $args;
90 // Backward compat: if template is overridden in theme, extract for legacy support
91 $default_path = EVERCOMPARE_PATH . '/includes/templates/' . $tmp_name;
92 if ( $located !== $default_path ) {
93 extract( $args, EXTR_SKIP ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
94 }
95 }
96
97 if ( $echo !== true ) { ob_start(); }
98
99 // include file located.
100 include( $located );
101
102 if ( $echo !== true ) { return ob_get_clean(); }
103
104 }
105
106
107 /**
108 * Get default fields List
109 * return array
110 */
111 function ever_compare_get_default_fields(){
112 $fields = array(
113 'title' => esc_html__( 'Title', 'ever-compare' ),
114 'ratting' => esc_html__( 'Ratting', 'ever-compare' ),
115 'price' => esc_html__( 'Price', 'ever-compare' ),
116 'add_to_cart' => esc_html__( 'Add To Cart', 'ever-compare' ),
117 'description' => esc_html__( 'Description', 'ever-compare' ),
118 'availability' => esc_html__( 'Availability', 'ever-compare' ),
119 'sku' => esc_html__( 'Sku', 'ever-compare' ),
120 'weight' => esc_html__( 'Weight', 'ever-compare' ),
121 'dimensions' => esc_html__( 'Dimensions', 'ever-compare' ),
122 );
123 return apply_filters( 'ever_compare_default_fields', $fields );
124 }
125
126 /**
127 * Get Fields List
128 * return array
129 */
130 function ever_compare_get_available_attributes() {
131 $attribute_list = array();
132
133 if( function_exists( 'wc_get_attribute_taxonomies' ) ) {
134 $attribute_list = wc_get_attribute_taxonomies();
135 }
136
137 $fields = ever_compare_get_default_fields();
138
139 if ( count( $attribute_list ) > 0 ) {
140 foreach ( $attribute_list as $attribute ) {
141 $fields[ 'pa_' . $attribute->attribute_name ] = $attribute->attribute_label;
142 }
143 }
144
145 return $fields;
146 }
147
148 /**
149 * [ever_compare_table_active_heading]
150 * @return [array]
151 */
152 function ever_compare_table_active_heading(){
153 $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();
154 return $active_heading;
155 }
156
157 /**
158 * [ever_compare_table_heading]
159 * @return [array]
160 */
161 function ever_compare_table_heading(){
162 $new_list = array();
163 $field_list = count( ever_compare_table_active_heading() ) > 0 ? ever_compare_table_active_heading() : ever_compare_get_default_fields();
164 foreach ( $field_list as $key => $value ) {
165 $new_list[$key] = \EverCompare\Frontend\Manage_Compare::instance()->field_name( $key );
166 }
167 return $new_list;
168 }
169
170 /**
171 * [ever_compare_dimensions]
172 * @param [string] $key
173 * @param [string] $tab
174 * @return [String | Bool]
175 */
176 function ever_compare_dimensions( $key, $tab, $css_attr ){
177 $dimensions = !empty( ever_compare_get_option( $key, $tab ) ) ? ever_compare_get_option( $key, $tab ) : array();
178 if( !empty( $dimensions['top'] ) || !empty( $dimensions['right'] ) || !empty( $dimensions['bottom'] ) || !empty( $dimensions['left'] ) ){
179
180 $unit = ( empty( $dimensions['unit'] ) ? 'px' : $dimensions['unit'] );
181 $top = ( !empty( $dimensions['top'] ) ? $dimensions['top'] : 0 );
182 $right = ( !empty( $dimensions['right'] ) ? $dimensions['right'] : 0 );
183 $bottom = ( !empty( $dimensions['bottom'] ) ? $dimensions['bottom'] : 0 );
184 $left = ( !empty( $dimensions['left'] ) ? $dimensions['left'] : 0 );
185
186 $css_attr .= ":{$top}{$unit} {$right}{$unit} {$bottom}{$unit} {$left}{$unit}";
187 return $css_attr.';';
188
189 }else{
190 return false;
191 }
192 }
193
194 /**
195 * [ever_compare_generate_css]
196 * @return [String | Bool]
197 */
198 function ever_compare_generate_css( $key, $tab, $css_attr, $unit = '' ){
199 $field_value = !empty( ever_compare_get_option( $key, $tab ) ) ? ever_compare_get_option( $key, $tab ) : '';
200
201 if( !empty( $field_value ) ){
202 $css_attr .= ":{$field_value}{$unit}";
203 return $css_attr.';';
204 }else{
205 return false;
206 }
207
208 }
209
210 /**
211 * [ever_compare_icon_list]
212 * @return [svg]
213 */
214 function ever_compare_icon_list( $key = '' ){
215 $icon_list = [
216 'default' => '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 471.701 471.701">
217 <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>
218 <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>',
219 'loading' => '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 471.701 471.701">
220 <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>'
221 ];
222 return ( $key == '' ) ? $icon_list : $icon_list[$key];
223 }
224
225 function get_allowed_tags_for_svg () {
226 return [
227 'svg' => [
228 'xmlns' => true,
229 'width' => true,
230 'height' => true,
231 'viewbox' => true,
232 'xmlns:xlink' => true,
233 ],
234 'g' => [
235 'class' => true,
236 ],
237 'path' => [
238 'd' => true,
239 ],
240 'span' => [
241 'class' => true,
242 ],
243 ];
244 }