| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Core\Base\Providers; |
| 4 |
|
| 5 |
class Social_Network_Provider { |
| 6 |
|
| 7 |
private static array $social_networks = []; |
| 8 |
|
| 9 |
public const FACEBOOK = 'Facebook'; |
| 10 |
public const TWITTER = 'X (Twitter)'; |
| 11 |
public const INSTAGRAM = 'Instagram'; |
| 12 |
public const LINKEDIN = 'LinkedIn'; |
| 13 |
public const PINTEREST = 'Pinterest'; |
| 14 |
public const YOUTUBE = 'YouTube'; |
| 15 |
public const TIKTOK = 'TikTok'; |
| 16 |
public const WHATSAPP = 'WhatsApp'; |
| 17 |
public const APPLEMUSIC = 'Apple Music'; |
| 18 |
public const SPOTIFY = 'Spotify'; |
| 19 |
public const SOUNDCLOUD = 'SoundCloud'; |
| 20 |
public const BEHANCE = 'Behance'; |
| 21 |
public const DRIBBBLE = 'Dribbble'; |
| 22 |
public const VIMEO = 'Vimeo'; |
| 23 |
public const WAZE = 'Waze'; |
| 24 |
public const MESSENGER = 'Messenger'; |
| 25 |
public const TELEPHONE = 'Telephone'; |
| 26 |
public const EMAIL = 'Email'; |
| 27 |
public const URL = 'Url'; |
| 28 |
public const FILE_DOWNLOAD = 'File Download'; |
| 29 |
public const SMS = 'SMS'; |
| 30 |
public const VIBER = 'VIBER'; |
| 31 |
public const SKYPE = 'Skype'; |
| 32 |
public const VCF = 'Save contact (vCard)'; |
| 33 |
|
| 34 |
public static function get_social_networks_icons(): array { |
| 35 |
static::init_social_networks_array_if_empty(); |
| 36 |
|
| 37 |
static $icons = []; |
| 38 |
|
| 39 |
if ( empty( $icons ) ) { |
| 40 |
foreach ( static::$social_networks as $network => $data ) { |
| 41 |
$icons[ $network ] = $data['icon']; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
return $icons; |
| 46 |
} |
| 47 |
|
| 48 |
public static function get_icon_mapping( string $platform ): string { |
| 49 |
static::init_social_networks_array_if_empty(); |
| 50 |
|
| 51 |
if ( isset( self::$social_networks[ $platform ]['icon'] ) ) { |
| 52 |
return self::$social_networks[ $platform ]['icon']; |
| 53 |
} |
| 54 |
|
| 55 |
return ''; |
| 56 |
} |
| 57 |
|
| 58 |
public static function get_name_mapping( string $platform ): string { |
| 59 |
static::init_social_networks_array_if_empty(); |
| 60 |
|
| 61 |
if ( isset( self::$social_networks[ $platform ]['name'] ) ) { |
| 62 |
return self::$social_networks[ $platform ]['name']; |
| 63 |
} |
| 64 |
|
| 65 |
return ''; |
| 66 |
} |
| 67 |
|
| 68 |
public static function get_text_mapping( string $platform ): string { |
| 69 |
static::init_social_networks_array_if_empty(); |
| 70 |
|
| 71 |
if ( isset( self::$social_networks[ $platform ]['text'] ) ) { |
| 72 |
return self::$social_networks[ $platform ]['text']; |
| 73 |
} |
| 74 |
|
| 75 |
return ''; |
| 76 |
} |
| 77 |
|
| 78 |
public static function get_social_networks_text( $providers = [] ): array { |
| 79 |
static::init_social_networks_array_if_empty(); |
| 80 |
|
| 81 |
static $texts = []; |
| 82 |
|
| 83 |
if ( empty( $texts ) ) { |
| 84 |
foreach ( static::$social_networks as $network => $data ) { |
| 85 |
$texts[ $network ] = $data['text']; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
if ( $providers ) { |
| 90 |
return array_intersect_key( $texts, array_flip( $providers ) ); |
| 91 |
} |
| 92 |
|
| 93 |
return $texts; |
| 94 |
} |
| 95 |
|
| 96 |
private static function init_social_networks_array_if_empty(): void { |
| 97 |
if ( ! empty( static::$social_networks ) ) { |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
static::$social_networks[ static::VCF ] = [ |
| 102 |
'text' => esc_html__( 'Save contact (vCard)', 'elementor' ), |
| 103 |
'icon' => 'fab fa-outlook', |
| 104 |
'name' => 'vcf', |
| 105 |
]; |
| 106 |
|
| 107 |
static::$social_networks[ static::FACEBOOK ] = [ |
| 108 |
'text' => esc_html__( 'Facebook', 'elementor' ), |
| 109 |
'icon' => 'fab fa-facebook', |
| 110 |
'name' => 'facebook', |
| 111 |
]; |
| 112 |
|
| 113 |
static::$social_networks[ static::TWITTER ] = [ |
| 114 |
'text' => esc_html__( 'X (Twitter)', 'elementor' ), |
| 115 |
'icon' => 'fab fa-x-twitter', |
| 116 |
'name' => 'x-twitter', |
| 117 |
]; |
| 118 |
|
| 119 |
static::$social_networks[ static::INSTAGRAM ] = [ |
| 120 |
'text' => esc_html__( 'Instagram', 'elementor' ), |
| 121 |
'icon' => 'fab fa-instagram', |
| 122 |
'name' => 'instagram', |
| 123 |
]; |
| 124 |
|
| 125 |
static::$social_networks[ static::LINKEDIN ] = [ |
| 126 |
'text' => esc_html__( 'LinkedIn', 'elementor' ), |
| 127 |
'icon' => 'fab fa-linkedin-in', |
| 128 |
'name' => 'linkedin', |
| 129 |
]; |
| 130 |
|
| 131 |
static::$social_networks[ static::PINTEREST ] = [ |
| 132 |
'text' => esc_html__( 'Pinterest', 'elementor' ), |
| 133 |
'icon' => 'fab fa-pinterest', |
| 134 |
'name' => 'pinterest', |
| 135 |
]; |
| 136 |
|
| 137 |
static::$social_networks[ static::YOUTUBE ] = [ |
| 138 |
'text' => esc_html__( 'YouTube', 'elementor' ), |
| 139 |
'icon' => 'fab fa-youtube', |
| 140 |
'name' => 'youtube', |
| 141 |
]; |
| 142 |
|
| 143 |
static::$social_networks[ static::TIKTOK ] = [ |
| 144 |
'text' => esc_html__( 'TikTok', 'elementor' ), |
| 145 |
'icon' => 'fab fa-tiktok', |
| 146 |
'name' => 'tiktok', |
| 147 |
]; |
| 148 |
|
| 149 |
static::$social_networks[ static::WHATSAPP ] = [ |
| 150 |
'text' => esc_html__( 'WhatsApp', 'elementor' ), |
| 151 |
'icon' => 'fab fa-whatsapp', |
| 152 |
'name' => 'whatsapp', |
| 153 |
]; |
| 154 |
|
| 155 |
static::$social_networks[ static::APPLEMUSIC ] = [ |
| 156 |
'text' => esc_html__( 'Apple Music', 'elementor' ), |
| 157 |
'icon' => 'fa fa-music', |
| 158 |
'name' => 'apple-music', |
| 159 |
]; |
| 160 |
|
| 161 |
static::$social_networks[ static::SPOTIFY ] = [ |
| 162 |
'text' => esc_html__( 'Spotify', 'elementor' ), |
| 163 |
'icon' => 'fab fa-spotify', |
| 164 |
'name' => 'spotify', |
| 165 |
]; |
| 166 |
|
| 167 |
static::$social_networks[ static::SOUNDCLOUD ] = [ |
| 168 |
'text' => esc_html__( 'SoundCloud', 'elementor' ), |
| 169 |
'icon' => 'fab fa-soundcloud', |
| 170 |
'name' => 'soundcloud', |
| 171 |
]; |
| 172 |
|
| 173 |
static::$social_networks[ static::BEHANCE ] = [ |
| 174 |
'text' => esc_html__( 'Behance', 'elementor' ), |
| 175 |
'icon' => 'fab fa-behance', |
| 176 |
'name' => 'behance', |
| 177 |
]; |
| 178 |
|
| 179 |
static::$social_networks[ static::DRIBBBLE ] = [ |
| 180 |
'text' => esc_html__( 'Dribbble', 'elementor' ), |
| 181 |
'icon' => 'fab fa-dribbble', |
| 182 |
'name' => 'dribble', |
| 183 |
]; |
| 184 |
|
| 185 |
static::$social_networks[ static::VIMEO ] = [ |
| 186 |
'text' => esc_html__( 'Vimeo', 'elementor' ), |
| 187 |
'icon' => 'fab fa-vimeo-v', |
| 188 |
'name' => 'vimeo', |
| 189 |
]; |
| 190 |
|
| 191 |
static::$social_networks[ static::WAZE ] = [ |
| 192 |
'text' => esc_html__( 'Waze', 'elementor' ), |
| 193 |
'icon' => 'fab fa-waze', |
| 194 |
'name' => 'waze', |
| 195 |
]; |
| 196 |
|
| 197 |
static::$social_networks[ static::MESSENGER ] = [ |
| 198 |
'text' => esc_html__( 'Messenger', 'elementor' ), |
| 199 |
'icon' => 'fab fa-facebook-messenger', |
| 200 |
'name' => 'messenger', |
| 201 |
]; |
| 202 |
|
| 203 |
static::$social_networks[ static::TELEPHONE ] = [ |
| 204 |
'text' => esc_html__( 'Telephone', 'elementor' ), |
| 205 |
'icon' => 'fas fa-phone-alt', |
| 206 |
'name' => 'phone', |
| 207 |
]; |
| 208 |
|
| 209 |
static::$social_networks[ static::EMAIL ] = [ |
| 210 |
'text' => esc_html__( 'Email', 'elementor' ), |
| 211 |
'icon' => 'fas fa-envelope', |
| 212 |
'name' => 'email', |
| 213 |
]; |
| 214 |
|
| 215 |
static::$social_networks[ static::URL ] = [ |
| 216 |
'text' => esc_html__( 'URL', 'elementor' ), |
| 217 |
'icon' => 'fas fa-globe', |
| 218 |
'name' => 'url', |
| 219 |
]; |
| 220 |
|
| 221 |
static::$social_networks[ static::FILE_DOWNLOAD ] = [ |
| 222 |
'text' => esc_html__( 'File Download', 'elementor' ), |
| 223 |
'icon' => 'fas fa-download', |
| 224 |
'name' => 'download', |
| 225 |
]; |
| 226 |
|
| 227 |
static::$social_networks[ static::SMS ] = [ |
| 228 |
'text' => esc_html__( 'SMS', 'elementor' ), |
| 229 |
'icon' => 'fas fa-sms', |
| 230 |
'name' => 'sms', |
| 231 |
]; |
| 232 |
|
| 233 |
static::$social_networks[ static::VIBER ] = [ |
| 234 |
'text' => esc_html__( 'Viber', 'elementor' ), |
| 235 |
'icon' => 'fab fa-viber', |
| 236 |
'name' => 'viber', |
| 237 |
]; |
| 238 |
|
| 239 |
static::$social_networks[ static::SKYPE ] = [ |
| 240 |
'text' => esc_html__( 'Skype', 'elementor' ), |
| 241 |
'icon' => 'fab fa-skype', |
| 242 |
'name' => 'skype', |
| 243 |
]; |
| 244 |
} |
| 245 |
|
| 246 |
public static function build_messenger_link( string $username ) { |
| 247 |
return 'https://m.me/' . $username; |
| 248 |
} |
| 249 |
|
| 250 |
public static function build_email_link( array $data, string $prefix ) { |
| 251 |
$email = $data[ $prefix . '_mail' ] ?? ''; |
| 252 |
$subject = $data[ $prefix . '_mail_subject' ] ?? ''; |
| 253 |
$body = $data[ $prefix . '_mail_body' ] ?? ''; |
| 254 |
|
| 255 |
if ( ! $email ) { |
| 256 |
return ''; |
| 257 |
} |
| 258 |
|
| 259 |
$link = 'mailto:' . $email; |
| 260 |
|
| 261 |
if ( $subject ) { |
| 262 |
$link .= '?subject=' . $subject; |
| 263 |
} |
| 264 |
|
| 265 |
if ( $body ) { |
| 266 |
$link .= $subject ? '&' : '?'; |
| 267 |
$link .= 'body=' . $body; |
| 268 |
} |
| 269 |
|
| 270 |
return $link; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
public static function build_viber_link( string $action, string $number ) { |
| 275 |
if ( empty( $number ) ) { |
| 276 |
return ''; |
| 277 |
} |
| 278 |
|
| 279 |
return add_query_arg( [ |
| 280 |
'number' => urlencode( $number ), |
| 281 |
], 'viber://' . $action ); |
| 282 |
} |
| 283 |
} |
| 284 |
|