public
Created

  • Download Gist
simplepie-gametrailers.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
<?php
// Extend SimplePie to retrieve the embed data from a GameTrailers.com feed
 
// Load SimplePie
include('simplepie.class.php');
 
// Define the GameTrailers namespace
define("SIMPLE_NAMESPACE_GAMETRAILERS", "http://www.gametrailers.com/rssexplained.php");
 
// Extend SimplePie_Item with our own class
class SimplePie_Item_Gametrailers extends SimplePie_Item
{
// Make sure we pass everything through
function __construct($feed, $data) {
parent::__construct($feed, $data);
}
 
// Use SimplePie_Item's API to get the embed code
function get_embed_id()
{
$data = $this->get_item_tags(SIMPLE_NAMESPACE_GAMETRAILERS, 'fileType');
return $data[0]['child']['']['embedcode'][0]['data'];
}
}
 
// ...
 
// Example of how to use.
 
$sp = new SimplePie();
$sp->set_item_class('SimplePie_Item_Gametrailers');
$sp->set_feed_url('http://www.gametrailers.com/rssgenerate.php?s1=&favplats[pc]=pc&vidformat[flv]=on&type[gameplay]=on&embed=on&quality[sd]=on&agegate[no]=on&orderby=newest&limit=20');
$sp->init();
 
foreach($sp->get_items() as $item) {
echo $item->get_title() . ' - ';
var_dump($item->get_embed_id());
echo '<br />';
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.