Created
April 12, 2010 09:45
-
-
Save rmccue/363412 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 />'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment