1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\FacebookPoster; |
4
|
|
|
|
5
|
|
|
use NotificationChannels\FacebookPoster\Attachments\Link; |
6
|
|
|
use NotificationChannels\FacebookPoster\Attachments\Image; |
7
|
|
|
use NotificationChannels\FacebookPoster\Attachments\Video; |
8
|
|
|
|
9
|
|
|
class FacebookPosterPost |
10
|
|
|
{ |
11
|
|
|
/** @var string */ |
12
|
|
|
protected $content; |
13
|
|
|
|
14
|
|
|
/** @object FacebookPosterLink */ |
15
|
|
|
protected $link; |
16
|
|
|
|
17
|
|
|
/** @object FacebookPosterImage */ |
18
|
|
|
protected $image; |
19
|
|
|
|
20
|
|
|
/** @object FacebookPosterVideo */ |
21
|
|
|
protected $video; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $apiEndpoint = 'me/feed'; |
27
|
|
|
|
28
|
4 |
|
public function __construct($postContent) |
29
|
|
|
{ |
30
|
4 |
|
$this->content = $postContent; |
31
|
4 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get Post content. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
4 |
|
public function getContent() |
39
|
|
|
{ |
40
|
4 |
|
return $this->content; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Set facebook post main link. |
45
|
|
|
* |
46
|
|
|
* @param string $link |
47
|
|
|
* |
48
|
|
|
* @return $this |
49
|
|
|
*/ |
50
|
1 |
|
public function withLink($link) |
51
|
|
|
{ |
52
|
1 |
|
$this->link = new Link($link); |
53
|
|
|
|
54
|
1 |
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Set facebook post image. |
59
|
|
|
* |
60
|
|
|
* @param $imagePath |
61
|
|
|
* @param string $endpoint |
62
|
|
|
* |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
1 |
|
public function withImage($imagePath, $endpoint = 'me/photos') |
66
|
|
|
{ |
67
|
1 |
|
$this->image = new Image($imagePath, $endpoint); |
68
|
|
|
|
69
|
1 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set facebook post image. |
74
|
|
|
* |
75
|
|
|
* @param $videoPath |
76
|
|
|
* @param array $data |
77
|
|
|
* @param string $endpoint |
78
|
|
|
* |
79
|
|
|
* @return $this |
80
|
|
|
*/ |
81
|
1 |
|
public function withVideo($videoPath, $data = [], $endpoint = 'me/videos') |
82
|
|
|
{ |
83
|
1 |
|
$this->video = new video($videoPath, $endpoint); |
84
|
|
|
|
85
|
1 |
|
if (isset($data['title'])) { |
86
|
1 |
|
$this->video->setTitle($data['title']); |
87
|
1 |
|
} |
88
|
|
|
|
89
|
1 |
|
if (isset($data['description'])) { |
90
|
1 |
|
$this->video->setDescription($data['description']); |
91
|
1 |
|
} |
92
|
|
|
|
93
|
1 |
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Return Facebook Post api endpoint. |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
4 |
|
public function getApiEndpoint() |
102
|
|
|
{ |
103
|
4 |
|
return $this->apiEndpoint; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Build Facebook post request body. |
108
|
|
|
* |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
4 |
|
public function getPostBody() |
112
|
|
|
{ |
113
|
|
|
$body = [ |
114
|
4 |
|
'message' => $this->getContent(), |
115
|
4 |
|
]; |
116
|
|
|
|
117
|
4 |
|
if ($this->link != null) { |
118
|
1 |
|
$body['link'] = $this->link->getUrl(); |
119
|
1 |
|
} |
120
|
|
|
|
121
|
4 |
|
if ($this->image != null) { |
122
|
1 |
|
$body['media'] = $this->image; |
123
|
1 |
|
} |
124
|
|
|
|
125
|
4 |
|
if ($this->video != null) { |
126
|
1 |
|
$body['media'] = $this->video; |
127
|
1 |
|
} |
128
|
|
|
|
129
|
4 |
|
return $body; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|