| 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 |
'icon-2' => betterdocs()->assets->icon( 'social/facebook-box-line.svg' ), |
| 15 |
'link' => 'https://www.facebook.com/sharer/sharer.php?u=' . $_permalink |
| 16 |
], |
| 17 |
'twitter' => [ |
| 18 |
'alt' => 'X', |
| 19 |
'icon' => betterdocs()->assets->icon( 'social/twitter.svg' ), |
| 20 |
'icon-2' => betterdocs()->assets->icon( 'social/twitter-x-line.svg' ), |
| 21 |
'link' => 'https://twitter.com/intent/tweet?url=' . $_permalink |
| 22 |
], |
| 23 |
'linkedin' => [ |
| 24 |
'alt' => 'LinkedIn', |
| 25 |
'icon' => betterdocs()->assets->icon( 'social/linkedin.svg' ), |
| 26 |
'icon-2' => betterdocs()->assets->icon( 'social/linkedin-box-line.svg' ), |
| 27 |
'link' => 'https://www.linkedin.com/shareArticle?mini=true&url=' . $_permalink |
| 28 |
], |
| 29 |
'pinterest' => [ |
| 30 |
'alt' => 'Pinterest', |
| 31 |
'icon' => betterdocs()->assets->icon( 'social/pinterest.svg' ), |
| 32 |
'icon-2' => betterdocs()->assets->icon( 'social/pinterest-line.svg' ), |
| 33 |
'link' => 'https://pinterest.com/pin/create/button/?url=' . $_permalink |
| 34 |
], |
| 35 |
// 'instagram' => [ |
| 36 |
// 'alt' => 'Instagram', |
| 37 |
// 'icon' => betterdocs()->assets->icon( 'social/instagram.svg' ), |
| 38 |
// 'icon-2' => betterdocs()->assets->icon( 'social/instagram-line.svg' ), |
| 39 |
// 'link' => 'https://pinterest.com/pin/create/button/?url=' . $_permalink |
| 40 |
// ] |
| 41 |
]; |
| 42 |
|
| 43 |
return array_filter( |
| 44 |
$_defaults, |
| 45 |
function ( $key ) { |
| 46 |
return array_key_exists( $key, $this->attributes ) && (bool) filter_var( $this->attributes[ $key ], FILTER_VALIDATE_BOOLEAN ); |
| 47 |
}, |
| 48 |
ARRAY_FILTER_USE_KEY |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
public function view_params() { |
| 53 |
$links = $this->generate_links(); |
| 54 |
$this->attributes['links'] = $links; |
| 55 |
|
| 56 |
if ( isset( $this->attributes['share_title_select_layout_layout'] ) && $this->attributes['share_title_select_layout_layout'] == 'layout-2' ) { // for elementor only |
| 57 |
$this->view_wrapper .= ' layout-2'; |
| 58 |
} |
| 59 |
|
| 60 |
if ( isset( $this->attributes['layout'] ) && $this->attributes['layout'] == 'layout-2' ) { //for blocks |
| 61 |
$this->view_wrapper .= ' layout-2'; |
| 62 |
} |
| 63 |
|
| 64 |
return [ |
| 65 |
'links' => $links |
| 66 |
]; |
| 67 |
} |
| 68 |
} |
| 69 |
|