|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Flynt\Components\HeroPostHeader; |
|
4
|
|
|
|
|
5
|
|
|
use Timber\Timber; |
|
6
|
|
|
use Flynt\Features\Components\Component; |
|
7
|
|
|
use Flynt\Utils\Asset; |
|
8
|
|
|
|
|
9
|
|
|
add_action('wp_enqueue_scripts', function () { |
|
10
|
|
|
Component::enqueueAssets('HeroPostHeader', []); |
|
11
|
|
|
}); |
|
12
|
|
|
|
|
13
|
|
|
add_filter('Flynt/addComponentData?name=HeroPostHeader', function ($data) { |
|
14
|
|
|
$data['post'] = Timber::get_post(); |
|
15
|
|
|
$data['providers'] = getShareProviders( |
|
16
|
|
|
$data['post']->post_title, |
|
17
|
|
|
$data['post']->link, |
|
18
|
|
|
$data['post']->post_excerpt |
|
19
|
|
|
); |
|
20
|
|
|
return $data; |
|
21
|
|
|
}); |
|
22
|
|
|
|
|
23
|
|
|
function getShareProviders($postTitle, $postUrl, $postExcerpt) |
|
24
|
|
|
{ |
|
25
|
|
|
$providers = [ |
|
26
|
|
|
[ |
|
27
|
|
|
'title' => 'Facebook', |
|
28
|
|
|
'class' => 'share-facebook', |
|
29
|
|
|
'url' => 'https://www.facebook.com/sharer/sharer.php?u=$url' |
|
30
|
|
|
], |
|
31
|
|
|
[ |
|
32
|
|
|
'title' => 'Twitter', |
|
33
|
|
|
'class' => 'share-twitter', |
|
34
|
|
|
'url' => 'https://twitter.com/home?status=$url' |
|
35
|
|
|
], |
|
36
|
|
|
[ |
|
37
|
|
|
'title' => 'Google+', |
|
38
|
|
|
'class' => 'share-google', |
|
39
|
|
|
'url' => 'https://plus.google.com/share?url=$url' |
|
40
|
|
|
], |
|
41
|
|
|
[ |
|
42
|
|
|
'title' => 'Linkedin', |
|
43
|
|
|
'class' => 'share-linkedin', |
|
44
|
|
|
'url' => 'https://www.linkedin.com/shareArticle?mini=true&url=$url&title=$title&summary=$summary' |
|
45
|
|
|
] |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$providers = array_map(function ($provider) use ($postTitle, $postUrl, $postExcerpt) { |
|
49
|
|
|
$shareUrl = str_replace('$url', $postUrl, $provider['url']); |
|
50
|
|
|
$shareUrl = str_replace('$title', $postTitle, $shareUrl); |
|
51
|
|
|
$shareUrl = str_replace('$summary', $postExcerpt, $shareUrl); |
|
52
|
|
|
$provider['shareUrl'] = $shareUrl; |
|
53
|
|
|
return $provider; |
|
54
|
|
|
}, $providers); |
|
55
|
|
|
return $providers; |
|
56
|
|
|
} |
|
57
|
|
|
|