154 if(!$adsLayoutResult->isSuccess())
156 return $adsLayoutResult;
159 $ads = $adsLayoutResult->getData();
162 if(isset($ad[
'group_id']))
164 $groupIDs[] = $ad[
'group_id'];
169 if(!$response->isSuccess())
174 $groups = $response->getData();
175 foreach($groups as $page)
177 $result[] =
new Page([
179 'name' => $page[
'name'],
180 'about' => $page[
'description'],
181 'image' => $page[
'photo_200'],
182 'phone' => $page[
'phone'],
185 $response->setData($result);
205 if(!$result->isSuccess() || empty($result->getData()))
211 $ads = $result->getData();
212 $groupIDs = $postIDs = [];
215 if(isset($ad[
'group_id']) && in_array($ad[
'group_id'], $publicPageIds))
217 $groupIDs[] = $ad[
'group_id'];
219 if(isset($ad[
'post_id']))
221 $postIDs[] = $ad[
'post_id'];
223 if(!empty($params[
'url_tags']) && isset($ad[
'link_domain']) && !empty($ad[
'link_domain']) && !empty($ad[
'link_url']))
225 $url =
new Uri($ad[
'link_url']);
226 $url->addParams($params[
'url_tags']);
228 'ad_id' => $ad[
'id'],
229 'link_url' => $url->getUri(),
233 if(count($data) == self::MAX_ADS_EDIT)
235 $editAdsResult = $this->
editAds($accountId, $data);
236 if(!$editAdsResult->isSuccess())
238 $result->addErrors($editAdsResult->getErrors());
246 $editAdsResult = $this->
editAds($accountId, $data);
247 if(!$editAdsResult->isSuccess())
249 $result->addErrors($editAdsResult->getErrors());
254 if(!empty($groupIDs))
257 if(!$result->isSuccess())
335 $result = $this->
getGroups(array_values($groupIDs));
336 if(!$result->isSuccess())
340 $groups = $result->getData();
341 foreach($groups as $group)
344 if(isset($params[
'url_tags']) && !empty($params[
'url_tags']) && isset($group[
'site']))
346 $uri =
new Uri($group[
'site']);
347 $uri->addParams($params[
'url_tags']);
348 $data[
'website'] = $uri->getUri();
350 if(isset($params[
'phone']) && !empty($params[
'phone']) && $group[
'phone'] != $params[
'phone'])
352 $data[
'phone'] = $params[
'phone'];
356 $data[
'id'] = $group[
'id'];
359 'endpoint' =>
'groups.edit',
362 if(!$response->isSuccess())
364 $result->addErrors($response->getErrors());
368 if(isset($params[
'url_tags']) && !empty($params[
'url_tags']) && isset($group[
'links']) && is_array($group[
'links']) && !empty($group[
'links']))
370 foreach($group[
'links'] as $link)
372 $url =
new Uri($link[
'url']);
373 $url->addParams($params[
'url_tags']);
374 if($url->getUri() != $link[
'url'])
378 'emdpoint' =>
'groups.deleteLink',
380 'group_id' => $group[
'id'],
381 'link_id' => $link[
'id'],
384 if($response->isSuccess())
388 'endpoint' =>
'groups.addLink',
390 'group_id' => $group[
'id'],
391 'text' => $link[
'desc'],
392 'link' => $url->getUri(),
396 if(!$response->isSuccess())
398 $result->addErrors($response->getErrors());
452 $result = $this->
getPosts($postIDs);
453 if(!$result->isSuccess())
458 $posts = $result->getData();
459 foreach($posts as $post)
461 if($post[
'post_type'] ==
'post_ads' && isset($post[
'attachments']) && is_array($post[
'attachments']) && count($post[
'attachments']) == 1)
463 $attachment = reset($post[
'attachments']);
464 if($attachment[
'type'] !=
'link' || mb_strpos($attachment[
'link'][
'url'],
'vk.com') !==
false)
469 if(isset($params[
'phone']) && !empty($params[
'phone']) && mb_strpos($attachment[
'link'][
'url'],
'tel:') === 0)
472 'owner_id' => $post[
'owner_id'],
473 'post_id' => $post[
'id'],
474 'attachments' =>
'tel:'.$params[
'phone'],
477 elseif(isset($params[
'url_tags']) && !empty($params[
'url_tags']))
479 $url =
new Uri($attachment[
'link'][
'url']);
480 $url->addParams($params[
'url_tags']);
481 if($url->getUri() != $attachment[
'link'][
'url'])
484 'owner_id' => $post[
'owner_id'],
485 'post_id' => $post[
'id'],
486 'attachments' => $url->getUri(),
494 'endpoint' =>
'wall.editAdsStealth',
497 if(!$response->isSuccess())
499 $result->addErrors($response->getErrors());