@@ -15,119 +15,119 @@ |
||
| 15 | 15 | class Button { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Services available. |
|
| 20 | - * |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - public $services = array( |
|
| 24 | - 'facebook', |
|
| 25 | - 'twitter', |
|
| 26 | - 'pinterest', |
|
| 27 | - ); |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Current service. |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - public $service = ''; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Constructor. |
|
| 38 | - */ |
|
| 39 | - public function __construct( $service, $options, $prefix = 'sharing' ) { |
|
| 40 | - $this->options = $options; |
|
| 41 | - if ( ! in_array($service, $this->services, true) ) { |
|
| 42 | - return; |
|
| 43 | - } |
|
| 44 | - if ( \lsx\sharing\includes\functions\is_button_disabled('global', $service) || \lsx\sharing\includes\functions\is_button_disabled($prefix, $service) ) { |
|
| 45 | - return ''; |
|
| 46 | - } |
|
| 47 | - $this->service = $service; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Get service link to share. |
|
| 52 | - */ |
|
| 53 | - public function get_link( $post ) { |
|
| 54 | - if ( empty($post) ) { |
|
| 55 | - return ''; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if ( 'email' === $this->service ) { |
|
| 59 | - return $this->get_link_email($post); |
|
| 60 | - } elseif ( 'facebook' === $this->service ) { |
|
| 61 | - return $this->get_link_facebook($post); |
|
| 62 | - } elseif ( 'twitter' === $this->service ) { |
|
| 63 | - return $this->get_link_twitter($post); |
|
| 64 | - } elseif ( 'pinterest' === $this->service ) { |
|
| 65 | - return $this->get_link_pinterest($post); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Get Facebook link to share. |
|
| 71 | - */ |
|
| 72 | - public function get_link_facebook( $post ) { |
|
| 73 | - $permalink = get_permalink($post->ID); |
|
| 74 | - $permalink = apply_filters('lsx_sharing_facebook_url', $permalink, $post); |
|
| 75 | - $title = apply_filters('the_title', $post->post_title); |
|
| 76 | - |
|
| 77 | - return 'https://www.facebook.com/sharer.php?display=page&u=' . rawurlencode($permalink) . '&t=' . rawurlencode($title); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Get Twitter link to share. |
|
| 82 | - */ |
|
| 83 | - public function get_link_twitter( $post ) { |
|
| 84 | - $permalink = get_permalink($post->ID); |
|
| 85 | - $permalink = apply_filters('lsx_sharing_twitter_url', $permalink, $post); |
|
| 86 | - $title = apply_filters('the_title', $post->post_title); |
|
| 87 | - |
|
| 88 | - if ( function_exists('mb_stripos') ) { |
|
| 89 | - $strlen = 'mb_strlen'; |
|
| 90 | - $substr = 'mb_substr'; |
|
| 91 | - } else { |
|
| 92 | - $strlen = 'strlen'; |
|
| 93 | - $substr = 'substr'; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $short_url_length = 24; |
|
| 97 | - |
|
| 98 | - if ( ( $strlen($title) + $short_url_length ) > 140 ) { |
|
| 99 | - $text = $substr($title, 0, ( 140 - $short_url_length - 1 )) . "\xE2\x80\xA6"; |
|
| 100 | - } else { |
|
| 101 | - $text = $title; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return 'https://twitter.com/intent/tweet?text=' . rawurlencode($text) . '&url=' . rawurlencode($permalink); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Get Pinterest link to share. |
|
| 109 | - */ |
|
| 110 | - public function get_link_pinterest( $post ) { |
|
| 111 | - $image = ''; |
|
| 112 | - $permalink = get_permalink($post->ID); |
|
| 113 | - $permalink = apply_filters('lsx_sharing_pinterest_url', $permalink, $post); |
|
| 114 | - $title = apply_filters('the_title', $post->post_title); |
|
| 115 | - |
|
| 116 | - if ( ! has_post_thumbnail($post) ) { |
|
| 117 | - if ( class_exists('lsx\legacy\Placeholders') ) { |
|
| 118 | - $image = \lsx\legacy\Placeholders::placeholder_url(null, $post->post_type); |
|
| 119 | - } elseif ( class_exists('LSX_Placeholders') ) { |
|
| 120 | - $image = \LSX_Placeholders::placeholder_url(null, $post->post_type); |
|
| 121 | - } |
|
| 122 | - } else { |
|
| 123 | - $image = get_the_post_thumbnail_url($post->ID, 'large'); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return 'https://www.pinterest.com/pin/create/button/?url=' . rawurlencode($permalink) . '&media=' . rawurlencode($image) . '&description=' . rawurlencode($title); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Get Email Link. |
|
| 131 | - */ |
|
| 132 | - public function get_link_email() { } |
|
| 18 | + /** |
|
| 19 | + * Services available. |
|
| 20 | + * |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + public $services = array( |
|
| 24 | + 'facebook', |
|
| 25 | + 'twitter', |
|
| 26 | + 'pinterest', |
|
| 27 | + ); |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Current service. |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + public $service = ''; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Constructor. |
|
| 38 | + */ |
|
| 39 | + public function __construct( $service, $options, $prefix = 'sharing' ) { |
|
| 40 | + $this->options = $options; |
|
| 41 | + if ( ! in_array($service, $this->services, true) ) { |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | + if ( \lsx\sharing\includes\functions\is_button_disabled('global', $service) || \lsx\sharing\includes\functions\is_button_disabled($prefix, $service) ) { |
|
| 45 | + return ''; |
|
| 46 | + } |
|
| 47 | + $this->service = $service; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Get service link to share. |
|
| 52 | + */ |
|
| 53 | + public function get_link( $post ) { |
|
| 54 | + if ( empty($post) ) { |
|
| 55 | + return ''; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if ( 'email' === $this->service ) { |
|
| 59 | + return $this->get_link_email($post); |
|
| 60 | + } elseif ( 'facebook' === $this->service ) { |
|
| 61 | + return $this->get_link_facebook($post); |
|
| 62 | + } elseif ( 'twitter' === $this->service ) { |
|
| 63 | + return $this->get_link_twitter($post); |
|
| 64 | + } elseif ( 'pinterest' === $this->service ) { |
|
| 65 | + return $this->get_link_pinterest($post); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Get Facebook link to share. |
|
| 71 | + */ |
|
| 72 | + public function get_link_facebook( $post ) { |
|
| 73 | + $permalink = get_permalink($post->ID); |
|
| 74 | + $permalink = apply_filters('lsx_sharing_facebook_url', $permalink, $post); |
|
| 75 | + $title = apply_filters('the_title', $post->post_title); |
|
| 76 | + |
|
| 77 | + return 'https://www.facebook.com/sharer.php?display=page&u=' . rawurlencode($permalink) . '&t=' . rawurlencode($title); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Get Twitter link to share. |
|
| 82 | + */ |
|
| 83 | + public function get_link_twitter( $post ) { |
|
| 84 | + $permalink = get_permalink($post->ID); |
|
| 85 | + $permalink = apply_filters('lsx_sharing_twitter_url', $permalink, $post); |
|
| 86 | + $title = apply_filters('the_title', $post->post_title); |
|
| 87 | + |
|
| 88 | + if ( function_exists('mb_stripos') ) { |
|
| 89 | + $strlen = 'mb_strlen'; |
|
| 90 | + $substr = 'mb_substr'; |
|
| 91 | + } else { |
|
| 92 | + $strlen = 'strlen'; |
|
| 93 | + $substr = 'substr'; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $short_url_length = 24; |
|
| 97 | + |
|
| 98 | + if ( ( $strlen($title) + $short_url_length ) > 140 ) { |
|
| 99 | + $text = $substr($title, 0, ( 140 - $short_url_length - 1 )) . "\xE2\x80\xA6"; |
|
| 100 | + } else { |
|
| 101 | + $text = $title; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return 'https://twitter.com/intent/tweet?text=' . rawurlencode($text) . '&url=' . rawurlencode($permalink); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Get Pinterest link to share. |
|
| 109 | + */ |
|
| 110 | + public function get_link_pinterest( $post ) { |
|
| 111 | + $image = ''; |
|
| 112 | + $permalink = get_permalink($post->ID); |
|
| 113 | + $permalink = apply_filters('lsx_sharing_pinterest_url', $permalink, $post); |
|
| 114 | + $title = apply_filters('the_title', $post->post_title); |
|
| 115 | + |
|
| 116 | + if ( ! has_post_thumbnail($post) ) { |
|
| 117 | + if ( class_exists('lsx\legacy\Placeholders') ) { |
|
| 118 | + $image = \lsx\legacy\Placeholders::placeholder_url(null, $post->post_type); |
|
| 119 | + } elseif ( class_exists('LSX_Placeholders') ) { |
|
| 120 | + $image = \LSX_Placeholders::placeholder_url(null, $post->post_type); |
|
| 121 | + } |
|
| 122 | + } else { |
|
| 123 | + $image = get_the_post_thumbnail_url($post->ID, 'large'); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return 'https://www.pinterest.com/pin/create/button/?url=' . rawurlencode($permalink) . '&media=' . rawurlencode($image) . '&description=' . rawurlencode($title); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Get Email Link. |
|
| 131 | + */ |
|
| 132 | + public function get_link_email() { } |
|
| 133 | 133 | } |