PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.14
UiCore Elements – Free widgets and templates for Elementor v1.0.14
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.14, at includes/utils/meta-component.php

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