share-factory.php
112 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Social\Lib\Provider; |
| 4 | |
| 5 | use WP_Social\Lib\Provider\Share\Digg_Sharer; |
| 6 | use WP_Social\Lib\Provider\Share\Email_Sharer; |
| 7 | use WP_Social\Lib\Provider\Share\Facebook_Messenger_Sharer; |
| 8 | use WP_Social\Lib\Provider\Share\Facebook_Sharer; |
| 9 | use WP_Social\Lib\Provider\Share\Kik_Sharer; |
| 10 | use WP_Social\Lib\Provider\Share\Linkedin_Sharer; |
| 11 | use WP_Social\Lib\Provider\Share\No_Provider_Share; |
| 12 | use WP_Social\Lib\Provider\Share\Pinterest_Sharer; |
| 13 | use WP_Social\Lib\Provider\Share\Reddit_Sharer; |
| 14 | use WP_Social\Lib\Provider\Share\Skype_Sharer; |
| 15 | use WP_Social\Lib\Provider\Share\Stumbleupon_Sharer; |
| 16 | use WP_Social\Lib\Provider\Share\Telegram_Sharer; |
| 17 | use WP_Social\Lib\Provider\Share\Trello_Sharer; |
| 18 | use WP_Social\Lib\Provider\Share\Twitter_Sharer; |
| 19 | use WP_Social\Lib\Provider\Share\Viber_Sharer; |
| 20 | use WP_Social\Lib\Provider\Share\Whatsapp_Sharer; |
| 21 | |
| 22 | defined('ABSPATH') || exit; |
| 23 | |
| 24 | class Share_Factory { |
| 25 | |
| 26 | private $provider_type; |
| 27 | private $post_id; |
| 28 | |
| 29 | public $factory; |
| 30 | |
| 31 | |
| 32 | public function __construct($post_id) { |
| 33 | |
| 34 | $this->post_id = intval($post_id); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | public function make($type) { |
| 39 | |
| 40 | $this->provider_type = $type; |
| 41 | |
| 42 | switch($type) { |
| 43 | |
| 44 | case 'facebook' : |
| 45 | $this->factory = new Facebook_Sharer($this->post_id, $type); |
| 46 | break; |
| 47 | |
| 48 | case 'twitter' : |
| 49 | $this->factory = new Twitter_Sharer($this->post_id, $type); |
| 50 | break; |
| 51 | |
| 52 | case 'pinterest' : |
| 53 | $this->factory = new Pinterest_Sharer($this->post_id, $type); |
| 54 | break; |
| 55 | |
| 56 | case 'linkedin' : |
| 57 | $this->factory = new Linkedin_Sharer($this->post_id, $type); |
| 58 | break; |
| 59 | |
| 60 | case 'facebook-messenger' : |
| 61 | $this->factory = new Facebook_Messenger_Sharer($this->post_id, $type); |
| 62 | break; |
| 63 | |
| 64 | case 'kik' : |
| 65 | $this->factory = new Kik_Sharer($this->post_id, $type); |
| 66 | break; |
| 67 | |
| 68 | case 'skype' : |
| 69 | $this->factory = new Skype_Sharer($this->post_id, $type); |
| 70 | break; |
| 71 | |
| 72 | case 'trello' : |
| 73 | $this->factory = new Trello_Sharer($this->post_id, $type); |
| 74 | break; |
| 75 | |
| 76 | case 'viber' : |
| 77 | $this->factory = new Viber_Sharer($this->post_id, $type); |
| 78 | break; |
| 79 | |
| 80 | case 'whatsapp' : |
| 81 | $this->factory = new Whatsapp_Sharer($this->post_id, $type); |
| 82 | break; |
| 83 | |
| 84 | case 'telegram' : |
| 85 | $this->factory = new Telegram_Sharer($this->post_id, $type); |
| 86 | break; |
| 87 | |
| 88 | case 'email' : |
| 89 | $this->factory = new Email_Sharer($this->post_id, $type); |
| 90 | break; |
| 91 | |
| 92 | case 'reddit' : |
| 93 | $this->factory = new Reddit_Sharer($this->post_id, $type); |
| 94 | break; |
| 95 | |
| 96 | case 'digg' : |
| 97 | $this->factory = new Digg_Sharer($this->post_id, $type); |
| 98 | break; |
| 99 | |
| 100 | case 'stumbleupon' : |
| 101 | $this->factory = new Stumbleupon_Sharer($this->post_id, $type); |
| 102 | break; |
| 103 | |
| 104 | default: |
| 105 | $this->factory = new No_Provider_Share(); |
| 106 | |
| 107 | } |
| 108 | |
| 109 | return $this->factory; |
| 110 | } |
| 111 | |
| 112 | } |