PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.3
Easy Elements for Elementor – Addons & Website Templates v1.3.3
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 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 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / social-share / social-share.php

social-share.php in Easy Elements for Elementor – Addons & Website Templates 1.3.3, at widgets/social-share/social-share.php

504 lines 17.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Easyel\EasyElements\Widgets;
3 use Elementor\Controls_Manager;
4 use Elementor\Widget_Base;
5 use Elementor\Group_Control_Typography;
6 use Elementor\Group_Control_Border;
7 use Elementor\Group_Control_Box_Shadow;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 class Easyel_Social_Share_Widget extends \Elementor\Widget_Base {
14
15 public function get_name() {
16 return 'eel-social-share';
17 }
18
19 public function get_title() {
20 return __( 'Social Share', 'easy-elements' );
21 }
22
23 public function get_icon() {
24 return 'easyicon easyelIcon-social-share';
25 }
26
27 public function get_categories() {
28 return [ 'easyelements_category' ];
29 }
30
31 public function get_keywords() {
32 return [ 'social', 'icon', 'link', 'click', 'share' ];
33 }
34
35 public function get_style_depends() {
36 return [
37 'eel-social-share',
38 ];
39 }
40
41
42 protected function register_controls() {
43
44 $this->start_controls_section(
45 'content_section',
46 [
47 'label' => esc_html__('Social Share Settings', 'easy-elements'),
48 'tab' => Controls_Manager::TAB_CONTENT,
49 ]
50 );
51
52
53 $this->add_control(
54 'social_platforms',
55 [
56 'label' => esc_html__('Social Platforms', 'easy-elements'),
57 'type' => Controls_Manager::REPEATER,
58 'fields' => [
59 [
60 'name' => 'platform',
61 'label' => esc_html__('Platform', 'easy-elements'),
62 'type' => Controls_Manager::SELECT,
63 'default' => 'facebook',
64 'options' => [
65 'facebook' => esc_html__('Facebook', 'easy-elements'),
66 'twitter' => esc_html__('Twitter/X', 'easy-elements'),
67 'instagram' => esc_html__('Instagram', 'easy-elements'),
68 'linkedin' => esc_html__('LinkedIn', 'easy-elements'),
69 'youtube' => esc_html__('YouTube', 'easy-elements'),
70 'tiktok' => esc_html__('TikTok', 'easy-elements'),
71 'pinterest' => esc_html__('Pinterest', 'easy-elements'),
72 'whatsapp' => esc_html__('WhatsApp', 'easy-elements'),
73 'telegram' => esc_html__('Telegram', 'easy-elements'),
74 'snapchat' => esc_html__('Snapchat', 'easy-elements'),
75 'reddit' => esc_html__('Reddit', 'easy-elements'),
76 'discord' => esc_html__('Discord', 'easy-elements'),
77 'spotify' => esc_html__('Spotify', 'easy-elements'),
78 'email' => esc_html__('Email', 'easy-elements'),
79 'copy' => esc_html__('Copy Link', 'easy-elements'),
80 ],
81 ],
82 [
83 'name' => 'custom_icon',
84 'label' => esc_html__('Custom Icon', 'easy-elements'),
85 'type' => Controls_Manager::ICONS,
86 'default' => [
87 'value' => '',
88 'library' => '',
89 ],
90 ],
91 ],
92 'default' => [
93 [
94 'platform' => 'facebook',
95 ],
96 [
97 'platform' => 'twitter',
98 ],
99 [
100 'platform' => 'instagram',
101 ],
102 [
103 'platform' => 'linkedin',
104 ],
105 [
106 'platform' => 'youtube',
107 ],
108 [
109 'platform' => 'whatsapp',
110 ],
111 [
112 'platform' => 'telegram',
113 ],
114 [
115 'platform' => 'copy',
116 ],
117 ],
118 'title_field' => '{{{ platform }}}',
119 ]
120 );
121
122 $this->add_control(
123 'layout',
124 [
125 'label' => esc_html__('Layout', 'easy-elements'),
126 'type' => Controls_Manager::SELECT,
127 'default' => 'horizontal',
128 'options' => [
129 'horizontal' => esc_html__('Horizontal', 'easy-elements'),
130 'vertical' => esc_html__('Vertical', 'easy-elements'),
131 'grid' => esc_html__('Grid', 'easy-elements'),
132 ],
133 ]
134 );
135
136 $this->add_control(
137 'open_new_tab',
138 [
139 'label' => esc_html__('Open in New Tab', 'easy-elements'),
140 'type' => Controls_Manager::SWITCHER,
141 'label_on' => esc_html__('Yes', 'easy-elements'),
142 'label_off' => esc_html__('No', 'easy-elements'),
143 'return_value' => 'yes',
144 'default' => 'yes',
145 ]
146 );
147
148 $this->end_controls_section();
149
150 // Style Tab - Buttons
151 $this->start_controls_section(
152 'buttons_style_section',
153 [
154 'label' => esc_html__('Buttons Style', 'easy-elements'),
155 'tab' => Controls_Manager::TAB_STYLE,
156 ]
157 );
158
159 $this->add_control(
160 'icon_size',
161 [
162 'label' => esc_html__('Icon Size', 'easy-elements'),
163 'type' => Controls_Manager::SLIDER,
164 'size_units' => ['px', 'em'],
165 'range' => [
166 'px' => [
167 'min' => 10,
168 'max' => 50,
169 'step' => 1,
170 ],
171 'em' => [
172 'min' => 0.5,
173 'max' => 3,
174 'step' => 0.1,
175 ],
176 ],
177 'default' => [
178 'unit' => 'px',
179 'size' => 18,
180 ],
181 'selectors' => [
182 '{{WRAPPER}} .eel-social-button i' => 'font-size: {{SIZE}}{{UNIT}};',
183 '{{WRAPPER}} .eel-social-button svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
184 ],
185 ]
186 );
187
188 $this->add_group_control(
189 \Elementor\Group_Control_Background::get_type(),
190 [
191 'name' => 'icon__bg',
192 'label' => esc_html__( 'Background', 'easy-elements' ),
193 'types' => [ 'classic', 'gradient' ],
194 'selector' => '{{WRAPPER}} .eel-social-share .eel-social-button',
195 'separator' => 'before',
196 ]
197 );
198
199
200 $this->add_control(
201 'icon_color_cutom',
202 [
203 'label' => esc_html__('Color', 'easy-elements'),
204 'type' => Controls_Manager::COLOR,
205 'default' => '',
206 'selectors' => [
207 '{{WRAPPER}} .eel-social-share .eel-social-button i' => 'color: {{VALUE}};',
208 '{{WRAPPER}} .eel-social-share .eel-social-button svg' => 'fill: {{VALUE}};',
209 '{{WRAPPER}} .eel-social-share .eel-social-button svg path' => 'fill: {{VALUE}};',
210 ],
211 ]
212 );
213
214 $this->add_responsive_control(
215 'button_size',
216 [
217 'label' => esc_html__('Button Size', 'easy-elements'),
218 'type' => Controls_Manager::SLIDER,
219 'size_units' => ['px', 'em'],
220 'range' => [
221 'px' => [
222 'min' => 30,
223 'max' => 100,
224 'step' => 1,
225 ],
226 'em' => [
227 'min' => 2,
228 'max' => 6,
229 'step' => 0.1,
230 ],
231 ],
232 'default' => [
233 'unit' => 'px',
234 'size' => 45,
235 ],
236 'selectors' => [
237 '{{WRAPPER}} .eel-social-button' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
238 ],
239 ]
240 );
241
242 $this->add_responsive_control(
243 'button_spacing',
244 [
245 'label' => esc_html__('Button Spacing', 'easy-elements'),
246 'type' => Controls_Manager::SLIDER,
247 'size_units' => ['px', 'em'],
248 'range' => [
249 'px' => [
250 'min' => 0,
251 'max' => 50,
252 'step' => 1,
253 ],
254 'em' => [
255 'min' => 0,
256 'max' => 3,
257 'step' => 0.1,
258 ],
259 ],
260 'default' => [
261 'unit' => 'px',
262 'size' => 0,
263 ],
264 'selectors' => [
265 '{{WRAPPER}} .eel-social-button' => 'margin: 0 {{SIZE}}{{UNIT}};',
266 '{{WRAPPER}} .eel-social-button:first-child' => 'margin-left: 0;',
267 '{{WRAPPER}} .eel-social-button:last-child' => 'margin-right: 0;',
268 ],
269 ]
270 );
271
272 $this->add_control(
273 'button_border_radius',
274 [
275 'label' => esc_html__('Border Radius', 'easy-elements'),
276 'type' => Controls_Manager::DIMENSIONS,
277 'size_units' => ['px', '%'],
278 'default' => [
279 'top' => '50',
280 'right' => '50',
281 'bottom' => '50',
282 'left' => '50',
283 'unit' => '%',
284 'isLinked' => true,
285 ],
286 'selectors' => [
287 '{{WRAPPER}} .eel-social-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
288 ],
289 ]
290 );
291
292 $this->add_group_control(
293 Group_Control_Border::get_type(),
294 [
295 'name' => 'button_border',
296 'selector' => '{{WRAPPER}} .eel-social-button',
297 ]
298 );
299
300 $this->add_group_control(
301 Group_Control_Box_Shadow::get_type(),
302 [
303 'name' => 'button_box_shadow',
304 'selector' => '{{WRAPPER}} .eel-social-button',
305 ]
306 );
307
308 $this->end_controls_section();
309 }
310
311 protected function render() {
312 $settings = $this->get_settings_for_display();
313
314 if (empty($settings['social_platforms'])) {
315 return;
316 }
317
318 $current_url = get_permalink();
319 $current_title = get_the_title();
320 $current_description = get_the_excerpt() ?: get_bloginfo('description');
321
322 // Get featured image if available
323 $featured_image = '';
324 if (has_post_thumbnail()) {
325 $featured_image = get_the_post_thumbnail_url(get_the_ID(), 'full');
326 }
327
328 $layout_class = 'eel-social-layout-' . ($settings['layout'] ?? 'horizontal');
329 $target = ($settings['open_new_tab'] === 'yes') ? '_blank' : '_self';
330
331 // Add Open Graph meta tags for better social sharing
332 if (!empty($featured_image)) {
333 echo '<meta property="og:image" content="' . esc_url($featured_image) . '">';
334 echo '<meta property="og:image:width" content="1200">';
335 echo '<meta property="og:image:height" content="630">';
336 echo '<meta name="twitter:image" content="' . esc_url($featured_image) . '">';
337 echo '<meta name="twitter:card" content="summary_large_image">';
338 }
339 echo '<meta property="og:title" content="' . esc_attr($current_title) . '">';
340 echo '<meta property="og:description" content="' . esc_attr($current_description) . '">';
341 echo '<meta property="og:url" content="' . esc_url($current_url) . '">';
342 echo '<meta name="twitter:title" content="' . esc_attr($current_title) . '">';
343 echo '<meta name="twitter:description" content="' . esc_attr($current_description) . '">';
344
345 ?>
346 <div class="eel-social-share <?php echo esc_attr($layout_class); ?>">
347
348 <div class="eel-social-buttons">
349 <?php foreach ($settings['social_platforms'] as $platform): ?>
350 <?php
351 $platform_name = $platform['platform'] ?? '';
352 $share_url = $current_url;
353 $share_title = $current_title;
354
355 $social_url = $this->get_social_share_url($platform_name, $share_url, $share_title, $current_description, $featured_image);
356 $icon_class = $this->get_social_icon_class($platform_name);
357 $button_class = 'eel-social-button eel-' . $platform_name;
358
359 // Check for custom icon
360 $custom_icon = $platform['custom_icon'] ?? [];
361 $has_custom_icon = !empty($custom_icon['value']);
362
363 if ($platform_name === 'copy') {
364 $button_class .= ' eel-copy-link';
365 $data_attr = 'data-url="' . esc_attr($share_url) . '"';
366 $href = '#';
367 } else {
368 $data_attr = '';
369 $href = $social_url;
370 }
371 ?>
372
373 <a href="<?php echo esc_url($href); ?>"
374 class="<?php echo esc_attr($button_class); ?>"
375 target="<?php echo esc_attr($target); ?>"
376 <?php echo esc_attr($data_attr); ?>
377 title="<?php echo esc_attr(ucfirst($platform_name)); ?>">
378 <?php if ($has_custom_icon): ?>
379 <?php \Elementor\Icons_Manager::render_icon($custom_icon, ['aria-hidden' => 'true']); ?>
380 <?php else: ?>
381 <i class="<?php echo esc_attr($icon_class); ?>"></i>
382 <?php endif; ?>
383 </a>
384 <?php endforeach; ?>
385 </div>
386 </div>
387
388 <?php
389
390 // Enqueue the JS for copy link functionality
391 wp_register_script( 'eel-copy-link', false, [ 'jquery' ], EASYELEMENTS_VER, true );
392 wp_enqueue_script( 'eel-copy-link' );
393
394 $inline_js = "
395 jQuery(document).ready(function($) {
396 $('.eel-copy-link').on('click', function(e) {
397 e.preventDefault();
398 var url = $(this).data('url');
399 var tempInput = $('<input>');
400 $('body').append(tempInput);
401 tempInput.val(url).select();
402 document.execCommand('copy');
403 tempInput.remove();
404
405 var button = $(this);
406 var originalIcon = button.find('i, svg').clone();
407 button.find('i, svg').remove();
408 button.append('<i class=\"fas fa-check\"></i>');
409 button.addClass('eel-copied');
410
411 setTimeout(function() {
412 button.find('i').remove();
413 button.append(originalIcon);
414 button.removeClass('eel-copied');
415 }, 2000);
416 });
417 });
418 ";
419
420 wp_add_inline_script( 'eel-copy-link', $inline_js );
421 }
422
423 private function get_social_share_url($platform, $url, $title, $description, $image = '') {
424 $encoded_url = urlencode($url);
425 $encoded_title = urlencode($title);
426 $encoded_description = urlencode($description);
427 $encoded_image = urlencode($image);
428
429 switch ($platform) {
430 case 'facebook':
431 return "https://www.facebook.com/sharer/sharer.php?u={$encoded_url}";
432 case 'twitter':
433 return "https://twitter.com/intent/tweet?url={$encoded_url}&text={$encoded_title}";
434 case 'linkedin':
435 return "https://www.linkedin.com/sharing/share-offsite/?url={$encoded_url}";
436 case 'pinterest':
437 if (!empty($image)) {
438 return "https://pinterest.com/pin/create/button/?url={$encoded_url}&description={$encoded_title}&media={$encoded_image}";
439 } else {
440 return "https://pinterest.com/pin/create/button/?url={$encoded_url}&description={$encoded_title}";
441 }
442 case 'whatsapp':
443 return "https://api.whatsapp.com/send?text={$encoded_title}%20{$encoded_url}";
444 case 'telegram':
445 return "https://t.me/share/url?url={$encoded_url}&text={$encoded_title}";
446 case 'instagram':
447 return "https://www.instagram.com/";
448 case 'youtube':
449 return "https://www.youtube.com/";
450 case 'tiktok':
451 return "https://www.tiktok.com/";
452 case 'snapchat':
453 return "https://www.snapchat.com/";
454 case 'reddit':
455 return "https://www.reddit.com/submit?url={$encoded_url}&title={$encoded_title}";
456 case 'discord':
457 return "https://discord.com/";
458 case 'spotify':
459 return "https://open.spotify.com/";
460 case 'email':
461 return "mailto:?subject={$encoded_title}&body={$encoded_description}%20{$encoded_url}";
462 default:
463 return $url;
464 }
465 }
466
467 private function get_social_icon_class($platform) {
468 switch ($platform) {
469 case 'facebook':
470 return 'fab fa-facebook-f';
471 case 'twitter':
472 return 'fab fa-twitter';
473 case 'linkedin':
474 return 'fab fa-linkedin-in';
475 case 'pinterest':
476 return 'fab fa-pinterest-p';
477 case 'whatsapp':
478 return 'fab fa-whatsapp';
479 case 'telegram':
480 return 'fab fa-telegram-plane';
481 case 'instagram':
482 return 'fab fa-instagram';
483 case 'youtube':
484 return 'fab fa-youtube';
485 case 'tiktok':
486 return 'fab fa-tiktok';
487 case 'snapchat':
488 return 'fab fa-snapchat-ghost';
489 case 'reddit':
490 return 'fab fa-reddit-alien';
491 case 'discord':
492 return 'fab fa-discord';
493 case 'spotify':
494 return 'fab fa-spotify';
495 case 'email':
496 return 'fas fa-envelope';
497 case 'copy':
498 return 'fas fa-link';
499 default:
500 return 'fas fa-share';
501 }
502 }
503 }
504