PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.15
UiCore Elements – Free widgets and templates for Elementor v1.0.15
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / utils / meta-component.php

meta-component.php in UiCore Elements – Free widgets and templates for Elementor 1.0.15, at includes/utils/meta-component.php

422 lines 16.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements\Utils;
3
4 use Elementor\Controls_Manager;
5 use Elementor\Group_Control_Typography;
6 use UiCoreElements\Helper;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly
10 }
11
12 trait Meta_Trait {
13
14 function get_meta_content_controls($product_metas = false)
15 {
16
17 // Meta options
18 $options = [
19 'none' => __( 'None', 'uicore-elements' ),
20 ];
21 $generic_posts = [
22 'author' => __( 'Author', 'uicore-elements' ),
23 'date' => __( 'Posted Date', 'uicore-elements' ),
24 'updated date' => __( 'Updated Date', 'uicore-elements' ),
25 'comment' => __( 'Comments Count', 'uicore-elements' ),
26 'reading time' => __( 'Reading Time', 'uicore-elements' ),
27 'category' => __( 'Category', 'uicore-elements' ),
28 'tag' => __( 'Tag', 'uicore-elements' ),
29 ];
30 $products = [
31 'product price' => __( 'Product Price', 'uicore-elements' ),
32 'product rating' => __( 'Product Rating', 'uicore-elements' ),
33 'product stock' => __( 'Product Stock', 'uicore-elements' ),
34 'product category' => __( 'Product Category', 'uicore-elements' ),
35 'product tag' => __( 'Product Tag', 'uicore-elements' ),
36 'product attribute' => __( 'Product Attribute', 'uicore-elements' ),
37 'product sale' => __( 'Product Sale', 'uicore-elements' ),
38 ];
39 $custom = [
40 'custom meta' => __( 'Custom Meta', 'uicore-elements' ),
41 'custom taxonomy' => __( 'Custom Taxonomy', 'uicore-elements' ),
42 'custom html' => __( 'Custom HTML', 'uicore-elements' ),
43 ];
44 $portfolio = [
45 'portfolio category' => __( 'Portfolio Category', 'uicore-elements' ),
46 ];
47
48 $options = $product_metas ?
49 array_merge($options, $products, $custom) : // specific to product widgets
50 array_merge($options, $generic_posts, $products, $portfolio, $custom); // generic posts widgets
51
52
53 $repeater = new \Elementor\Repeater();
54 $repeater->add_control('type',[
55 'label' => __( 'Meta', 'uicore-elements' ),
56 'type' => Controls_Manager::SELECT,
57 'default' => '',
58 'options' => $options
59 ]
60 );
61 $repeater->add_control('type_custom',[
62 'label' => __( 'Custom Field Name', 'uicore-elements' ),
63 'type' => Controls_Manager::TEXT,
64 'condition' => [
65 'type' => ['custom meta','custom taxonomy']
66 ]
67 ]
68 );
69 $repeater->add_control('html_custom',[
70 'label' => __( 'Custom HTML', 'uicore-elements' ),
71 'type' => Controls_Manager::TEXTAREA,
72 'condition' => [
73 'type' => ['custom html']
74 ]
75 ]
76 );
77 $repeater->add_control('date_format',[
78 'label' => esc_html__( 'Date Format', 'uicore-elements' ),
79 'type' => Controls_Manager::SELECT,
80 'default' => 'default',
81 'options' => [
82 'default' => esc_html__( 'Default', 'uicore-elements' ),
83 'F j, Y' => gmdate( 'F j, Y' ),
84 'Y-m-d' => gmdate( 'Y-m-d' ),
85 'm/d/Y' => gmdate( 'm/d/Y' ),
86 'd/m/Y' => gmdate( 'd/m/Y' ),
87 'custom' => esc_html__( 'Custom', 'uicore-elements' ),
88 ],
89 'condition' => [
90 'type' => ['date','updated date']
91 ]
92 ]
93 );
94 $repeater->add_control('custom_format',[
95 'label' => esc_html__( 'Custom Format', 'uicore-elements' ),
96 'default' => get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
97 'description' => sprintf( '<a href="https://wordpress.org/documentation/article/customize-date-and-time-format/" target="_blank">%s</a>', esc_html__( 'Documentation on date and time formatting', 'uicore-elements' ) ),
98 'condition' => [
99 'date_format' => 'custom',
100 'type' => ['date','updated date']
101 ],
102 ]
103 );
104 $repeater->add_control('before',[
105 'label' => __( 'Text Before', 'uicore-elements' ),
106 'type' => Controls_Manager::TEXT,
107 'condition' => [
108 'type!' => 'none',
109 ]
110 ]
111 );
112 $repeater->add_control('after',[
113 'label' => __( 'Text After', 'uicore-elements' ),
114 'type' => Controls_Manager::TEXT,
115 'condition' => [
116 'type!' => 'none',
117 ]
118 ]
119 );
120 $repeater->add_control('autor_display',[
121 'label' => __( 'Display Type', 'uicore-elements' ),
122 'type' => Controls_Manager::SELECT,
123 'default' => 'name',
124 'options' => [
125 'name' => __( 'Name', 'uicore-elements' ),
126 'full' => __( 'Avatar & Name', 'uicore-elements' ),
127 'avatar' => __( 'Avatar', 'uicore-elements' ),
128 ],
129 'condition' => [
130 'type' => 'author',
131 ],
132 ]
133 );
134 $repeater->add_control('icon',[
135 'label' => __( 'Icon', 'uicore-elements' ),
136 'type' => Controls_Manager::ICONS,
137 'condition' => [
138 'autor_display' => 'name',
139 'type!' => 'none',
140 ],
141 ]
142 );
143 return $repeater->get_controls();
144 }
145
146 function get_meta_style_controls($position = 'tb-meta')
147 {
148 $this->add_group_control(
149 Group_Control_Typography::get_type(),
150 [
151 'name' => $position.'_meta_typography',
152 'selector' => '{{WRAPPER}} .ui-e-'.$position,
153 'separator' => 'before',
154 ]
155 );
156 $this->add_control(
157 $position.'_meta_color',
158 [
159 'label' => __( 'Text Color', 'uicore-elements' ),
160 'type' => Controls_Manager::COLOR,
161 'selectors' => [
162 '{{WRAPPER}} .ui-e-'.$position => 'color: {{VALUE}}',
163 '{{WRAPPER}} .ui-e-'.$position.' svg' => 'fill: {{VALUE}}',
164 ],
165 ]
166 );
167 $this->add_control(
168 $position.'_link_color',
169 [
170 'label' => __( 'Link Color', 'uicore-elements' ),
171 'type' => Controls_Manager::COLOR,
172 'selectors' => [
173 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item a' => 'color: {{VALUE}}',
174 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item svg' => 'fill: {{VALUE}}',
175 ],
176 ]
177 );
178 $this->add_control(
179 $position.'_linkh_color',
180 [
181 'label' => __( 'Link Hover Color', 'uicore-elements' ),
182 'type' => Controls_Manager::COLOR,
183 'selectors' => [
184 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item a:hover' => 'color: {{VALUE}}',
185 ],
186 ]
187 );
188 $this->add_control(
189 $position.'_meta_background',
190 [
191 'label' => __( 'Background Color', 'uicore-elements' ),
192 'type' => Controls_Manager::COLOR,
193 'selectors' => [
194 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item' => 'background-color: {{VALUE}}',
195
196 ],
197 ]
198 );
199 $this->add_control(
200 $position.'_meta_radius',
201 [
202 'label' => esc_html__('Border Radius', 'uicore-elements'),
203 'type' => Controls_Manager::DIMENSIONS,
204 'selectors' => [
205 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item' => 'border-radius: {{TOP}}px {{RIGHT}}px {{BOTTOM}}px {{LEFT}}px;'
206 ],
207 ]
208 );
209 $this->add_group_control(
210 \Elementor\Group_Control_Box_Shadow::get_type(),
211 [
212 'name' => $position.'_meta_shadow',
213 'label' => esc_html__( 'Box Shadow', 'uicore-elements' ),
214 'selector' => '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item',
215 ]
216 );
217 $this->add_responsive_control(
218 $position.'_meta_padding',
219 [
220 'label' => esc_html__('Padding', 'uicore-elements'),
221 'type' => Controls_Manager::DIMENSIONS,
222 'size_units' => [ 'px', 'em', '%' ],
223 'selectors' => [
224 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
225 ]
226 ]
227 );
228 if($position === 'top'){
229 $this->add_responsive_control(
230 $position.'_meta_margin',
231 [
232 'label' => esc_html__('Margin', 'uicore-elements'),
233 'type' => Controls_Manager::DIMENSIONS,
234 'size_units' => [ 'px', 'em', '%' ],
235 'selectors' => [
236 '{{WRAPPER}} .ui-e-'.$position => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
237 ]
238 ]
239 );
240 }else{
241 $this->add_control($position.'_meta_margin',[
242 'label' => __( 'Meta Top Space', 'uicore-elements' ),
243 'type' => Controls_Manager::SLIDER,
244 'size_units' => [ 'em' ],
245 'separator' => 'after',
246 'range' => [
247 'px' => [
248 'min' => 0,
249 'max' => 3,
250 'step' => 0.1,
251 ],
252 ],
253 'default' => [
254 'unit' => 'em',
255 'size' => 1.2,
256 ],
257 'selectors' => [
258 '{{WRAPPER}} .ui-e-'.$position => 'margin-top: {{SIZE}}em;',
259 ],
260 ]
261 );
262 }
263
264 $this->add_responsive_control($position.'_meta_gap',[
265 'label' => __( 'Items Gap', 'uicore-elements' ),
266 'type' => Controls_Manager::SLIDER,
267 'size_units' => [ 'px' ],
268 'range' => [
269 'px' => [
270 'min' => 0,
271 'max' => 30,
272 ],
273 ],
274 'default' => [
275 'unit' => 'px',
276 'size' => 8,
277 ],
278 'selectors' => [
279 '{{WRAPPER}} .ui-e-'.$position.' ' => 'gap: {{SIZE}}px;',
280 ],
281 ]
282 );
283 $this->add_control($position.'_meta_separator',[
284 'label' => __( 'Separator', 'uicore-elements' ),
285 'type' => Controls_Manager::TEXT,
286 ]
287 );
288 if($position === 'top'){
289 $this->add_control($position.'_meta_placement',[
290 'label' => __( 'Items placement', 'uicore-elements' ),
291 'type' => Controls_Manager::SELECT,
292 'default' => '',
293 'options' => [
294 'start left' => __( 'Top Left', 'uicore-elements' ),
295 'start right' => __( 'Top Right', 'uicore-elements' ),
296 'end left' => __( 'Bottom Left', 'uicore-elements' ),
297 'end right' => __( 'Bottom Right', 'uicore-elements' ),
298 ],
299 'selectors' => [
300 '{{WRAPPER}} .ui-e-post-top-meta' => 'place-content: {{VALUE}};',
301 ],
302 ]
303 );
304 }
305 }
306
307 function get_meta_the_author($mode){
308 global $post;
309 $author_id = $post->post_author;
310
311 // name, full, avatar
312 if($mode === 'avatar'){
313 $display = '<img class="ui-e-meta-avatar" src="' . esc_url( get_avatar_url($author_id, array('size' => 100)) ) . '" />';
314 }elseif($mode === 'full'){
315 $display = '<img class="ui-e-meta-avatar" src="' . esc_url( get_avatar_url($author_id, array('size' => 100)) ) . '" /> '.get_the_author_meta('display_name', $author_id);
316 }else{
317 $display = esc_html(\get_the_author_meta('display_name', $author_id));
318 }
319 $link = sprintf(
320 '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
321 esc_url( get_author_posts_url( $author_id) ),
322 /* translators: %s: Author's display name. */
323 esc_attr( sprintf( __( 'View %s&#8217;s posts', 'uicore-elements' ), esc_html($display) ) ),
324 $display
325 );
326 return $link;
327 }
328
329 function get_woo_meta($type) {
330 global $product;
331
332 if (empty($product)) {
333 return 'No product found.';
334 }
335
336 switch ($type) {
337 case 'product price':
338 return $product->get_price_html();
339 case 'product rating':
340 return wc_get_rating_html( $product->get_average_rating() );
341 case 'product category':
342 return get_the_term_list($product->get_id(), 'product_cat', '', ', ', '');
343 case 'product tag':
344 return get_the_term_list($product->get_id(), 'product_tag', '', ', ', '');
345 case 'product stock' :
346 return ( $product->managing_stock() && $product->is_type('simple') && $product->get_stock_quantity() !== null ) ? $product->get_stock_quantity() : '';
347 case 'product attribute':
348 return wc_display_product_attributes($product);
349 case 'product sale' :
350 return $product->is_on_sale() ? esc_html__( 'Sale!', 'uicore-elements' ) : '';
351 default:
352 return 'Invalid meta type.';
353 }
354 }
355
356
357 function display_meta($meta){
358
359 if($meta['type'] === 'none')
360 return;
361
362 $content = '';
363 $wrapper = '<div class="ui-e-meta-item">';
364 $type = $meta['type'];
365 $prefix = $meta['before'] ? '<span>'.esc_html($meta['before']).'</span>' : '';
366 $suffix = $meta['after'] ? '<span class="ui-e-meta-after">'.esc_html($meta['after']).'</span>' : '';
367
368 ob_start();
369 \Elementor\Icons_Manager::render_icon( $meta['icon'], [ 'aria-hidden' => 'true', 'class'=> 'ui-e-meta-icon' ], 'span' );
370 $icon = ob_get_clean();
371
372 // Build content
373 switch ($type) {
374 case 'author':
375 $content .= $this->get_meta_the_author($meta['autor_display']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
376 break;
377 case 'date':
378 $content .= Helper::format_date(get_the_date('U'), $meta['date_format'], $meta['custom_format']); // 'U' param returns the date in timestamp, necessary for format_date()
379 break;
380 case 'updated date':
381 $content .= Helper::format_date(get_the_modified_date('U'), $meta['date_format'], $meta['custom_format']); // 'U' param returns the date in timestamp, necessary for format_date()
382 break;
383 case 'category':
384 $content .= Helper::get_taxonomy('category');
385 break;
386 case 'tag':
387 $content .= Helper::get_taxonomy('post_tag');
388 break;
389 case 'portfolio category':
390 $content .= Helper::get_taxonomy('portfolio_category');
391 break;
392 case 'comment':
393 $content .= esc_html(get_comments_number());
394 break;
395 case 'custom meta':
396 $content .= esc_html(get_post_meta( get_the_ID(), $meta['type_custom'], true ));
397 break;
398 case 'custom taxonomy':
399 $content .= Helper::get_taxonomy($meta['type_custom']);
400 break;
401 case 'custom html':
402 $content .= wp_kses_post($meta['html_custom']);
403 break;
404 case 'reading time':
405 $content .= esc_html(Helper::get_reading_time());
406 break;
407 default:
408 if (strpos($type, 'product') === 0) {
409 if ($this->get_woo_meta($type) === false) return; // Abort if there's no data for this product meta
410 $content .= wp_kses_post($this->get_woo_meta($type));
411 } else {
412 echo \esc_html($type);
413 }
414 break;
415 }
416
417 // Only output if there's content
418 if (!empty($content)) {
419 echo $wrapper . Helper::esc_svg($icon) . $prefix . $content . $suffix . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
420 }
421 }
422 }