| 1 |
<?php |
| 2 |
namespace WPDeveloper\BetterDocs\Traits; |
| 3 |
|
| 4 |
trait SocialShare { |
| 5 |
public $view_wrapper = 'betterdocs-social-share'; |
| 6 |
|
| 7 |
public function generate_links() { |
| 8 |
$_permalink = get_the_permalink(); |
| 9 |
|
| 10 |
$_defaults = [ |
| 11 |
'facebook' => [ |
| 12 |
'alt' => 'Facebook', |
| 13 |
'icon' => betterdocs()->assets->icon( 'social/facebook.svg' ), |
| 14 |
'link' => 'https://www.facebook.com/sharer/sharer.php?u=' . $_permalink |
| 15 |
], |
| 16 |
'twitter' => [ |
| 17 |
'alt' => 'Twitter', |
| 18 |
'icon' => betterdocs()->assets->icon( 'social/twitter.svg' ), |
| 19 |
'link' => 'https://twitter.com/intent/tweet?url=' . $_permalink |
| 20 |
], |
| 21 |
'linkedin' => [ |
| 22 |
'alt' => 'LinkedIn', |
| 23 |
'icon' => betterdocs()->assets->icon( 'social/linkedin.svg' ), |
| 24 |
'link' => 'https://www.linkedin.com/shareArticle?mini=true&url=' . $_permalink |
| 25 |
], |
| 26 |
'pinterest' => [ |
| 27 |
'alt' => 'Pinterest', |
| 28 |
'icon' => betterdocs()->assets->icon( 'social/pinterest.svg' ), |
| 29 |
'link' => 'https://pinterest.com/pin/create/button/?url=' . $_permalink |
| 30 |
] |
| 31 |
]; |
| 32 |
|
| 33 |
return array_filter( $_defaults, function ( $key ) { |
| 34 |
return array_key_exists( $key, $this->attributes ) && (bool) filter_var( $this->attributes[$key], FILTER_VALIDATE_BOOLEAN ); |
| 35 |
}, ARRAY_FILTER_USE_KEY ); |
| 36 |
} |
| 37 |
|
| 38 |
public function view_params() { |
| 39 |
$links = $this->generate_links(); |
| 40 |
$this->attributes['links'] = $links; |
| 41 |
|
| 42 |
return [ |
| 43 |
'links' => $links |
| 44 |
]; |
| 45 |
} |
| 46 |
} |
| 47 |
|