1 | <?php |
||
12 | class Pins extends Provider |
||
13 | { |
||
14 | use Searchable, CanBeDeleted, UploadsImages; |
||
15 | |||
16 | protected $loginRequiredFor = [ |
||
17 | 'like', |
||
18 | 'unLike', |
||
19 | 'comment', |
||
20 | 'deleteComment', |
||
21 | 'create', |
||
22 | 'repin', |
||
23 | 'delete', |
||
24 | 'activity' |
||
25 | ]; |
||
26 | |||
27 | protected $searchScope = 'pins'; |
||
28 | protected $entityIdName = 'id'; |
||
29 | |||
30 | protected $deleteUrl = UrlHelper::RESOURCE_DELETE_PIN; |
||
31 | |||
32 | /** |
||
33 | * Likes pin with current ID. |
||
34 | * |
||
35 | * @param int $pinId |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | public function like($pinId) |
||
40 | { |
||
41 | return $this->likePinMethodCall($pinId, UrlHelper::RESOURCE_LIKE_PIN); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Removes your like from pin with current ID. |
||
46 | * |
||
47 | * @param int $pinId |
||
48 | * |
||
49 | * @return bool |
||
50 | */ |
||
51 | public function unLike($pinId) |
||
52 | { |
||
53 | return $this->likePinMethodCall($pinId, UrlHelper::RESOURCE_UNLIKE_PIN); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Write a comment for a pin with current id. |
||
58 | * |
||
59 | * @param int $pinId |
||
60 | * @param string $text Comment |
||
61 | * |
||
62 | * @return array|bool |
||
63 | */ |
||
64 | public function comment($pinId, $text) |
||
65 | { |
||
66 | $requestOptions = ['pin_id' => $pinId, 'test' => $text]; |
||
67 | |||
68 | return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_COMMENT_PIN, true); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Delete a comment for a pin with current id. |
||
73 | * |
||
74 | * @param int $pinId |
||
75 | * @param int $commentId |
||
76 | * |
||
77 | * @return bool |
||
78 | */ |
||
79 | public function deleteComment($pinId, $commentId) |
||
80 | { |
||
81 | $requestOptions = ['pin_id' => $pinId, 'comment_id' => $commentId]; |
||
82 | |||
83 | return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_COMMENT_DELETE_PIN); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Create a pin. Returns created pin ID. |
||
88 | * |
||
89 | * @param string $imageUrl |
||
90 | * @param int $boardId |
||
91 | * @param string $description |
||
92 | * @param string $link |
||
93 | * |
||
94 | * @return bool|int |
||
95 | */ |
||
96 | public function create($imageUrl, $boardId, $description = '', $link = '') |
||
97 | { |
||
98 | // Upload image if first argument is not url |
||
99 | if (!filter_var($imageUrl, FILTER_VALIDATE_URL)) { |
||
100 | $imageUrl = $this->upload($imageUrl); |
||
101 | } |
||
102 | |||
103 | $requestOptions = [ |
||
104 | 'method' => 'scraped', |
||
105 | 'description' => $description, |
||
106 | 'link' => empty($link) ? $imageUrl : $link, |
||
107 | 'image_url' => $imageUrl, |
||
108 | 'board_id' => $boardId, |
||
109 | ]; |
||
110 | |||
111 | return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_CREATE_PIN, true); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Edit pin by ID. You can move pin to a new board by setting this board id. |
||
116 | * |
||
117 | * @param int $pindId |
||
118 | * @param string $description |
||
119 | * @param string $link |
||
120 | * @param int|null $boardId |
||
121 | * @return bool |
||
122 | */ |
||
123 | public function edit($pindId, $description = '', $link = '', $boardId = null) |
||
134 | |||
135 | /** |
||
136 | * Moves pin to a new board |
||
137 | * |
||
138 | * @param int $pindId |
||
139 | * @param int $boardId |
||
140 | * @return bool |
||
141 | */ |
||
142 | public function moveToBoard($pindId, $boardId) |
||
146 | |||
147 | /** |
||
148 | * Make a repin. |
||
149 | * |
||
150 | * @param int $repinId |
||
151 | * @param int $boardId |
||
152 | * @param string $description |
||
153 | * |
||
154 | * @return bool|int |
||
155 | */ |
||
156 | public function repin($repinId, $boardId, $description = '') |
||
157 | { |
||
158 | $requestOptions = [ |
||
159 | 'board_id' => $boardId, |
||
160 | 'description' => stripslashes($description), |
||
161 | 'link' => stripslashes($repinId), |
||
162 | 'is_video' => null, |
||
163 | 'pin_id' => $repinId, |
||
164 | ]; |
||
165 | |||
166 | return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_REPIN, true); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * Get information of a pin by PinID. |
||
171 | * |
||
172 | * @param int $pinId |
||
173 | * |
||
174 | * @return array|bool |
||
175 | */ |
||
176 | public function info($pinId) |
||
177 | { |
||
178 | $requestOptions = [ |
||
179 | 'id' => $pinId, |
||
180 | 'field_set_key' => 'detailed', |
||
181 | ]; |
||
182 | |||
183 | return $this->execGetRequest($requestOptions, UrlHelper::RESOURCE_PIN_INFO); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Get pins from a specific url. For example: https://pinterest.com/source/flickr.com/ will return |
||
188 | * recent Pins from flickr.com |
||
189 | * |
||
190 | * @param string $source |
||
191 | * @param int $limit |
||
192 | * @return Iterator |
||
193 | */ |
||
194 | public function fromSource($source, $limit = 0) |
||
203 | |||
204 | /** |
||
205 | * Get the latest pin activity with pagination. |
||
206 | * |
||
207 | * @param int $pinId |
||
208 | * @param int $limit |
||
209 | * @return Iterator|null |
||
210 | */ |
||
211 | public function activity($pinId, $limit = 0) |
||
224 | |||
225 | /** |
||
226 | * Calls Pinterest API to like or unlike Pin by ID. |
||
227 | * |
||
228 | * @param int $pinId |
||
229 | * @param string $resourceUrl |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | protected function likePinMethodCall($pinId, $resourceUrl) |
||
237 | |||
238 | /** |
||
239 | * @param int $pinId |
||
240 | * @return int|null |
||
241 | */ |
||
242 | protected function getAggregatedPinId($pinId) |
||
250 | } |
||
251 |