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

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