Repository navigation
Expand file tree
/
Copy pathShare.php
More file actions
204 lines (188 loc) · 7.11 KB
/
Copy pathShare.php
File metadata and controls
204 lines (188 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
namespace BEA\Theme\Framework\Helpers\Formatting\Share;
use function BEA\Theme\Framework\Helpers\Formatting\Link\get_the_link;
use function BEA\Theme\Framework\Helpers\Svg\get_the_icon;
/**
* @usage BEA\Theme\Framework\Helpers\Formatting\Share\get_share_link( 'facebook', "https://......", ['title' => 'My title', 'class' => "...", 'href' => 'http://www.facebook.com/sharer.php' ], ['title' => 'My title', 'class' => "...", 'href' => 'http://www.facebook.com/sharer.php' ], [ 'before' => '', 'after' => ''] );
*
* @param string $name The network name ( example : "facebook", "linkedin", etc....).
* @param string $link_to_share The sharing link.
* @param array $share_attributes {
* Share attribute that can be passed as a parameter in the sharing URL.
*
* @type string $u For the share link (Facebook)
* @type string $url For the share link (Twitter, Linkedin, etc..)
* @type string $text For the share text
* @type string $body For the email body
*
*
* }
* @param array $attributes {
* Attributes for the acf link markup.
*
* @type string $class CSS class name or space-separated list of classes.
* Default is empty.
* @type string $rel The attribute indicates the relationship between the target of the link and the object making the link.
* @type string $href The URL for the link
* @type string $target Optional.Target for the link (example : _blank). By default is _blank
* }
*
* @param array $settings {
* Optional. Settings for the acf link markup.
*
* @type string $before Optional. Markup to prepend to the link. Default empty.
* @type string $after Optional. Markup to append to the link. Default empty.
* @type array $escape Optional. An array where we specify as key the value we want to escape and as value the method to use. Example for the href ['escape' => ['href' => 'esc_url'] ].
* By default is methode to display the icon
*
* }
*
* @return string Return the markup of the share link
*/
function get_share_link( string $name, string $link_to_share, array $share_attributes = [], array $attributes = [], array $settings = [] ): string {
if ( empty( $name ) ) {
return '';
}
$networks = [
'facebook' => [
'accessible_name' => __( 'Share on Facebook', 'beapi-frontend-framework' ),
'attributes' => [
'href' => 'http://www.facebook.com/sharer.php',
'class' => 'share__link',
],
'icon' => 'social/facebook',
'params' => [
'u' => $link_to_share,
],
],
'x' => [
'accessible_name' => __( 'Share on X', 'beapi-frontend-framework' ),
'attributes' => [
'href' => 'https://twitter.com/intent/tweet',
'class' => 'share__link',
],
'icon' => 'social/x',
'params' => [
'url' => $link_to_share,
],
],
'linkedin' => [
'accessible_name' => __( 'Share on Linkedin', 'beapi-frontend-framework' ),
'attributes' => [
'href' => 'https://www.linkedin.com/shareArticle',
'class' => 'share__link',
],
'icon' => 'social/linkedin',
'params' => [
'url' => $link_to_share,
],
],
'instagram' => [
'accessible_name' => __( 'Share on Instagram', 'beapi-frontend-framework' ),
'attributes' => [
'href' => 'https://www.instagram.com/',
'class' => 'share__link',
],
'icon' => 'social/instagram',
'params' => [
'url' => $link_to_share,
],
],
'bluesky' => [
'accessible_name' => __( 'Share on Bluesky', 'beapi-frontend-framework' ),
'attributes' => [
'href' => 'https://bsky.app/intent/compose',
'class' => 'share__link',
],
'icon' => 'social/bluesky',
'params' => [
'text' => $link_to_share,
],
],
'email' => [
'accessible_name' => __( 'Share by email', 'beapi-frontend-framework' ),
'attributes' => [
'href' => 'mailto:',
'class' => 'share__link',
],
'icon' => 'social/email',
'params' => [
'body' => $link_to_share,
],
],
];
// 1 . Le réseau existe ?
$network = $networks[ $name ] ?? [];
if ( empty( $network ) ) {
return '';
}
$network['params'] = wp_parse_args(
$share_attributes,
$network['params'] ?? []
);
$network['attributes']['href'] = add_query_arg( $network['params'], $network['attributes']['href'] ?? '' );
$network['attributes']['target'] = '_blank';
$attributes = wp_parse_args( $attributes, $network['attributes'] );
$attributes = apply_filters( 'bea_theme_framework_share_attributes', $attributes, $name, $link_to_share, $share_attributes, $settings );
// Only allow icons
unset( $settings['content'] );
$icon_html = isset( $network['icon'] ) ? get_the_icon( $network['icon'] ) : '';
$settings = wp_parse_args(
$settings,
[
'content' => sprintf(
'%s<span class="sr-only">%s</span>',
$icon_html,
(string) ( $network['accessible_name'] ?? '' )
),
'mode' => 'button',
'before' => '<li>',
'after' => '</li>',
]
);
$settings = apply_filters( 'bea_theme_framework_share_settings', $settings, $name, $link_to_share, $share_attributes, $attributes );
return get_the_link(
$attributes,
$settings
);
}
/**
* @usage BEA\Theme\Framework\Helpers\Formatting\Share\get_share_link( 'facebook', "https://......", ['title' => 'My title', 'class' => "...", 'href' => 'http://www.facebook.com/sharer.php' ], ['title' => 'My title', 'class' => "...", 'href' => 'http://www.facebook.com/sharer.php' ], [ 'before' => '', 'after' => ''] );
*
* @param string $name The network name ( example : "facebook", "linkedin", etc....).
* @param string $link_to_share The sharing link.
* @param array $share_attributes {
* Share attribute that can be passed as a parameter in the sharing URL.
*
* @type string $u For the share link (Facebook)
* @type string $url For the share link (Twitter, Linkedin, etc..)
* @type string $text For the share text
* @type string $body For the email body
*
*
* }
* @param array $attributes {
* Attributes for the acf link markup.
*
* @type string $class CSS class name or space-separated list of classes.
* Default is empty.
* @type string $rel The attribute indicates the relationship between the target of the link and the object making the link.
* @type string $href The URL for the link
* @type string $target Optional.Target for the link (example : _blank). By default is _blank
* }
*
* @param array $settings {
* Optional. Settings for the acf link markup.
*
* @type string $before Optional. Markup to prepend to the link. Default empty.
* @type string $after Optional. Markup to append to the link. Default empty.
* @type array $escape Optional. An array where we specify as key the value we want to escape and as value the method to use. Example for the href ['escape' => ['href' => 'esc_url'] ].
* By default is methode to display the icon
*
* }
*
* @return void Echo the markup of the share link
*/
function the_share_link( string $name, string $link_to_share, array $share_attributes = [], array $attributes = [], array $settings = [] ): void {
echo get_share_link( $name, $link_to_share, $share_attributes, $attributes, $settings );
}