Отзывы

[exec]

$itemTemplate = ‘

{owner_photo}

{date}

{text}

{owner_name}, {owner_uri}

{attach}

‘;

$ownerPhotoTemplate = ‘label‘;

$response = file_get_contents(«https://api.vk.com/method/board.getComments?v=5.3&group_id=77162252&topic_id=31096827&extended=1&offset=0&count=100»);
$wall = json_decode($response);

foreach ($wall->response->items as $item) {
$itemOwnerType = $item->from_id > 0 ? ‘user’ : ‘group’;
if ($itemOwnerType == ‘user’) {
$itemOwner = findItemByID($wall->response->profiles, $item->from_id);
} else {
$itemOwner = findItemByID($wall->response->groups, $item->from_id * -1);
}

// На случай, если findItemByID вернёт null
if ($itemOwner) {
if ($itemOwnerType == ‘user’) {
$ownerName = $itemOwner->first_name . ‘ ‘ . $itemOwner->last_name;
$ownerPhotoUri = $itemOwner->photo_medium_rec;
} else {
$ownerName = $itemOwner->name;
$ownerPhotoUri = $itemOwner->photo_100;
}
}

$ownerPhoto = renderTemplate($ownerPhotoTemplate, array(
‘uri’ => $ownerPhotoUri,
‘label’=> $ownerName,
));

if ($item->attachments){
foreach ($item->attachments as $key => $value) {
$attachPhotos = array($value->photo->photo_604);
foreach ($attachPhotos as $photo){
$arr .= ‘

'.$ownerName.'

‘;
}
}
}

$data = array(
‘{owner_name}’ => $ownerName,
‘{text}’ => $item->text,
‘{date}’ => date(«Y-m-d H:i:s», $item->date),
‘{owner_photo}’=> $ownerPhoto,
‘{owner_uri}’ => ‘https://vk.com/’ . $itemOwner->screen_name,
‘{attach}’ => $arr
);

//echo renderTemplate($itemTemplate, $data);
//var_dump($item->attachments->photo->photo_604);

if($itemOwnerType == ‘user’){echo renderTemplate($itemTemplate, $data);$arr=»;}
else{
$arr=»;
continue;}

}

function findItemByID($items, $needleID)
{
foreach ($items as $item) {
if ($item->id == $needleID) {
return $item;
}
}
return null;
}

function renderTemplate($template, $data)
{
return str_replace(array_keys($data), array_values($data), $template);
}
[/exec]