digg-sharer.php
5 years ago
email-sharer.php
5 years ago
facebook-messenger-sharer.php
5 years ago
facebook-sharer.php
5 years ago
kik-sharer.php
5 years ago
linkedin-sharer.php
5 years ago
no-provider-share.php
5 years ago
pinterest-sharer.php
5 years ago
reddit-sharer.php
5 years ago
share-interface.php
5 years ago
sharer.php
5 years ago
skype-sharer.php
5 years ago
stumbleupon-sharer.php
5 years ago
telegram-sharer.php
5 years ago
trello-sharer.php
5 years ago
twitter-sharer.php
5 years ago
viber-sharer.php
5 years ago
whatsapp-sharer.php
5 years ago
sharer.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Social\Lib\Provider\Share; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | abstract class Sharer implements Share_Interface { |
| 8 | |
| 9 | protected $global_options; |
| 10 | protected $key; |
| 11 | protected $post_id; |
| 12 | protected $tracking_url; |
| 13 | protected $option_key; |
| 14 | protected $url_hash; |
| 15 | |
| 16 | public function __construct($post_id = 0, $key = '') { |
| 17 | |
| 18 | $this->key = $key; |
| 19 | |
| 20 | $this->post_id = $post_id; |
| 21 | |
| 22 | $this->tracking_url = get_permalink($this->post_id); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | protected function get_transient_key() { |
| 27 | |
| 28 | $md5 = md5($this->tracking_url . $this->post_id); |
| 29 | |
| 30 | return 'xs_sharer_' . $this->post_id . '_' . $this->key . '_' . $md5; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | public function need_to_call_legacy_function() { |
| 35 | |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | public function set_config_data($conf_array = []) { |
| 41 | |
| 42 | $this->global_options = $conf_array; |
| 43 | |
| 44 | return $this; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | public function set_uri_hash($hash) { |
| 49 | |
| 50 | $this->url_hash = $hash; |
| 51 | |
| 52 | return $this; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | protected function get_option_key() { |
| 57 | |
| 58 | return 'xs_shared_count__' . $this->key . '_' . $this->url_hash; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | protected function get_meta_key() { |
| 63 | |
| 64 | return 'xs_shared_count_' . intval($this->post_id) . '_' . $this->key; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | public function increase_share_count_by_one() { |
| 69 | |
| 70 | $opt_key = $this->get_meta_key(); |
| 71 | |
| 72 | $old = get_post_meta($this->post_id, $opt_key, true); |
| 73 | |
| 74 | $count = intval($old) + 1; |
| 75 | |
| 76 | return update_post_meta($this->post_id, $opt_key, $count); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | public function get_url_share_count() { |
| 81 | |
| 82 | $opt_key = $this->get_meta_key(); |
| 83 | |
| 84 | $old = get_post_meta($this->post_id, $opt_key, true); |
| 85 | |
| 86 | return intval($old); |
| 87 | } |
| 88 | } |
| 89 |