Magpie not getting media:thumbnail element

407 Views Asked by At

I'm creating a php script which uses a lot of rss sources. It puts the rss feeds in the database. There are multiple ways a thumbnail/image is put in an xml file. I have a problem with one specific way.

When an xml file contains something like this: Source

...
    <media:content type="image/jpeg" url="http://static3.hln.be/static/photo/2015/1/8/6/20150405151722/crop_7613016.jpg">
    <media:thumbnail url="http://static3.hln.be/static/photo/2015/1/8/6/20150405151722/crop_7613016.jpg"/>
    </media:content>
...

For some reason it looks like MagPie doesn't get that element. If I var_dump that item it looks like this:

...
    ["media"]=> array(1) { ["content"]=> string(1) " " } ["content"]=> string(1) " "
...

Anyone an idea how I can extract the thumbnail element? Thanks in advance.

UPDATE - (some example code):

    $rss = fetch_rss('http://www.hln.be/rss.xml');
    foreach ($rss->items as $item )
    { //loop through rss feed
        var_dump($item); //the var_dump without media elements

        return $array = $arrayName = array(
            'title' => $item['title'],
            'url' => $item['link'],
            ...);

        putDataInDatabase(); //put everything in the database
    }

A more full look at the var_dump

array(10) { ["title"]=> string(62) "Isinbayeva ..."" ["link"]=> string(23) "http://s.hln.be/2276986" ["description"]=> string(141) "Yelena Isinbayeva ..." ["pubdate"]=> string(29) "Sun, 05 Apr 2015 13:06:00 GMT" ["author"]=> string(8) "redactie" ["guid"]=> string(23) "http://s.hln.be/2276986" ["media"]=> array(1) { ["content"]=> string(1) " " } ["content"]=> string(1) " " ["summary"]=> string(141) "Yelena Isinbayeva wil... " ["date_timestamp"]=> int(1428239160) }
1

There are 1 best solutions below

12
hakre On BEST ANSWER

The elements are inside that array, e.g. you can access the URL of the content thumbnail like this:

$item['media']['content_thumbnail@url']

To put that into the perspective of your example:

$rss = fetch_rss('http://www.hln.be/rss.xml');
foreach ($rss->items as $item) { //loop through rss feed
    var_dump($item['media']['content_thumbnail@url']);
}

Gives the following output:

string(79) "http://static3.hln.be/static/photo/2015/2/10/14/20150405204108/crop_7613834.jpg"
string(78) "http://static0.hln.be/static/photo/2015/1/9/13/20150405201321/crop_7613833.jpg"
string(77) "http://static2.hln.be/static/photo/2015/7/0/8/20150405203748/crop_7613858.jpg"
string(77) "http://static2.hln.be/static/photo/2015/0/6/8/20150405200321/crop_7613813.jpg"
string(79) "http://static2.hln.be/static/photo/2015/17/6/10/20150405200509/crop_7613830.jpg"
string(77) "http://static1.hln.be/static/photo/2015/7/9/7/20150405195208/crop_7613782.jpg"
string(78) "http://static2.hln.be/static/photo/2015/0/15/7/20150405193052/crop_7613737.jpg"
...

This is the overall structure of the media element:

Array
(
    [content#] => 1
    [content@] => type,url
    [content@type] => image/jpeg
    [content@url] => http://static3.hln.be/static/photo/2015/2/10/14/20150405204108/crop_7613834.jpg
    [content] => 

    [content_thumbnail#] => 1
    [content_thumbnail@] => url
    [content_thumbnail@url] => http://static3.hln.be/static/photo/2015/2/10/14/20150405204108/crop_7613834.jpg
)