I am attempting to parse an RSS feed which uses media enclosures. I am using SimplePie and I have been able to parse it, and make all the needed elements appear on the page.
But I am writing a plugin for a CMS and I need to put those elements into an array. All are working fine, except the $item->get_enclosure().
I should say, that in the array, what is returned is a string of gibberish. I need it to return the url to the file.
Here is the relevant code:
// Get Enclosure
$enclosures = array();
$item_enclosures = $item->get_enclosures();
if ( ! empty($item_enclosures))
{
foreach ($item_enclosures as $enclosure)
{
if ($enclosure = $item->get_enclosure())
{
$enclosure->get_link();
} else {
$enclosure->get_title();
}
}
}
$items[] = array(
'item_title' => $item->get_title(),
'item_link' => $item->get_permalink(),
'item_date' => $item->get_date('U'),
'item_content' => $item->get_content(),
'item_img' => $item->get_enclosure(),
'item_description' => $item->get_description(),
'item_categories' => $categories,
'item_authors' => $authors
);
}
return $items;
Does anyone know how to make the 'item_img' return a link to the file, rather than what seems to be some kind of encoded string of characters.
From http://simplepie.org/wiki/reference/simplepie_enclosure/get_link
$link = $item->get_enclosure()->get_link();
would seem to do what you want.