if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
$arResult['res'] = [];
$wall_id = '-' . $arParams['group_id'];
$count = $arParams['count'] ? $arParams['count'] : 20; // Количество записей, которое необходимо получить. Максимальное значение: 100.
$key = '';
if(isset($arParams['key']))
$key = '&access_token=' . $arParams['key'];
$api = file_get_contents("https://api.vk.com/method/wall.get?owner_id=-141299426&count=20&v=4.104&access_token={$wall_id}&count={$count}" . $key);
$res = json_decode($api, true);
if(isset($res["response"]))
{
$all = $res["response"];
foreach($all as $r)
{
if(!isset($r["text"]))
continue;
$text = $r["text"];
$text = preg_replace("#(https?|ftp)://\S+[^\s.,> )\];'\"!?]#",'\\0', $text);
$text = preg_replace("%(^|\s|\A|\b|>)#(\S+)%",'$1#$2', $text);
$img = '';
if(isset($r["attachment"]) && $r["attachment"]['type'] == 'photo')
$img = $r["attachment"]['photo']["src_big"];
else if(isset($r["attachment"]) && $r["attachment"]['type'] == 'link')
$img = $r["attachment"]['link']["image_src"];
else if(isset($r["attachments"]) && $r["attachments"][0]['type'] == 'link')
{
$img = $r["attachments"][0]['link']["image_src"];
if(!$text)
$text = $r["attachments"][0]['link']["title"];
}
else if(isset($r["attachment"]) && $r["attachment"]['type'] == 'video')
$img = $r["attachment"]['video']["image"];
else if(isset($r["attachments"]))
{
foreach($r["attachments"] as $a)
if($a['type'] == 'photo')
{
$img = $a['photo']["src_big"];
if($img)
break;
}
}
$arResult['res'][] = ['id' => $r["id"], 'img' => $img, 'text' => $text, 'date' => ($r['date'] + 60*60*2), 'url' => 'https://vk.com/ttepla45?w=wall-' . $arParams['group_id'] . '_' . $r["id"]];
}
if(isset($arParams['save']) && $arParams['save'] && count($arResult['res']))
{
$all = array_reverse($arResult['res']);
foreach($all as $r)
{
$row = CIBlockElement::GetList(['SORT' => 'ASC'], ['IBLOCK_ID' => 14, 'NAME' => $r['url']], false)->GetNext();
if(!$row)
{
$el = new CIBlockElement;
$arLoadProductArray = Array(
"IBLOCK_ID" => 14,
"PROPERTY_VALUES"=> [1092 => $r['url']],
"NAME" => $r['url'],
"CODE" => $r['url'],
"ACTIVE" => "Y",
"DETAIL_TEXT" => $r['text'],
"DETAIL_PICTURE" => CFile::MakeFileArray($r['img'])
);
if($PRODUCT_ID = $el->Add($arLoadProductArray))
echo "New ID: ".$PRODUCT_ID . '
';
else
echo "Error: ".$el->LAST_ERROR . '
';
}
}
}
}
$this->IncludeComponentTemplate();