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
|
|
|
/** @var array */ |
24
|
|
|
protected $params; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $apiEndpoint = 'me/feed'; |
30
|
|
|
|
31
|
4 |
|
public function __construct($postContent) |
32
|
|
|
{ |
33
|
4 |
|
$this->content = $postContent; |
34
|
4 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get Post content. |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
4 |
|
public function getContent() |
42
|
|
|
{ |
43
|
4 |
|
return $this->content; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Set facebook post main link. |
48
|
|
|
* |
49
|
|
|
* @param string $link |
50
|
|
|
* |
51
|
|
|
* @return $this |
52
|
|
|
*/ |
53
|
1 |
|
public function withLink($link) |
54
|
|
|
{ |
55
|
1 |
|
$this->link = new Link($link); |
56
|
|
|
|
57
|
1 |
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Set facebook post image. |
62
|
|
|
* |
63
|
|
|
* @param $imagePath |
64
|
|
|
* @param string $endpoint |
65
|
|
|
* |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
1 |
|
public function withImage($imagePath, $endpoint = 'me/photos') |
69
|
|
|
{ |
70
|
1 |
|
$this->image = new Image($imagePath, $endpoint); |
71
|
|
|
|
72
|
1 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set facebook post image. |
77
|
|
|
* |
78
|
|
|
* @param $videoPath |
79
|
|
|
* @param array $data |
80
|
|
|
* @param string $endpoint |
81
|
|
|
* |
82
|
|
|
* @return $this |
83
|
|
|
*/ |
84
|
1 |
|
public function withVideo($videoPath, $data = [], $endpoint = 'me/videos') |
85
|
|
|
{ |
86
|
1 |
|
$this->video = new video($videoPath, $endpoint); |
87
|
|
|
|
88
|
1 |
|
if (isset($data['title'])) { |
89
|
1 |
|
$this->video->setTitle($data['title']); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
if (isset($data['description'])) { |
93
|
1 |
|
$this->video->setDescription($data['description']); |
94
|
|
|
} |
95
|
|
|
|
96
|
1 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Schedule the post for a date in the future. |
101
|
|
|
* |
102
|
|
|
* @param string $timestamp UNIX timestamp |
103
|
|
|
* |
104
|
|
|
* @return $this |
105
|
|
|
*/ |
106
|
|
|
public function scheduledFor($timestamp) |
107
|
|
|
{ |
108
|
|
|
$this->params['published'] = false; |
109
|
|
|
$this->params['scheduled_publish_time'] = $timestamp; |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Return Facebook Post api endpoint. |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
4 |
|
public function getApiEndpoint() |
120
|
|
|
{ |
121
|
4 |
|
return $this->apiEndpoint; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Build Facebook post request body. |
126
|
|
|
* |
127
|
|
|
* @return array |
128
|
|
|
*/ |
129
|
4 |
|
public function getPostBody() |
130
|
|
|
{ |
131
|
|
|
$body = [ |
132
|
4 |
|
'message' => $this->getContent(), |
133
|
|
|
]; |
134
|
|
|
|
135
|
4 |
|
if ($this->link != null) { |
136
|
1 |
|
$body['link'] = $this->link->getUrl(); |
137
|
|
|
} |
138
|
|
|
|
139
|
4 |
|
if ($this->image != null) { |
140
|
1 |
|
$body['media'] = $this->image; |
141
|
|
|
} |
142
|
|
|
|
143
|
4 |
|
if ($this->video != null) { |
144
|
1 |
|
$body['media'] = $this->video; |
145
|
|
|
} |
146
|
|
|
|
147
|
4 |
|
if ($this->params != null) { |
148
|
|
|
$body = array_merge($body, $this->params); |
149
|
|
|
} |
150
|
|
|
|
151
|
4 |
|
return $body; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|