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

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