SimplePie 1.5 is now available!

SimplePie Documentation.  Learn how to use this thing.  It's way better than going to school.

You are here: Documentation » API Reference » SimplePie » set_enclosure_class()

set_enclosure_class()

Description

class SimplePie {
	set_enclosure_class ( [string $class = 'SimplePie_Enclosure'] )
}

Allows you to add new methods or replace existing methods in the SimplePie_Enclosure class.

Learn more about extending classes in PHP:

Availability

  • Available since SimplePie Beta 3.

Parameters

class

The new class for SimplePie to use.

Examples

Replace a method and add a method

<?php
require_once('../simplepie.inc');
 
// Create a new class that extends an existing class
class SimplePie_Enclosure_Extras extends SimplePie_Enclosure {
 
	/**
	This is an example of adding a new method to an existing class.
	 */
 
	// Return the file's size in GB's.
	function get_size_gb()
	{
		$length = $this->get_length();
		if (!empty($length))
		{
			return round($length/1073741824, 2);
		}
		else
		{
			return null;
		}
	}
}
 
// Let's do our standard SimplePie thing.
$feed = new SimplePie();
$feed->set_feed_url('http://revision3.com/diggnation/feed/quicktime-large');
$feed->set_enclosure_class('SimplePie_Enclosure_Extras');
$feed->init();
$feed->handle_content_type();
?>
 
<html>
<body>
 
<?php foreach ($feed->get_items(0,5) as $item): ?>
 
	<h4><a href="<?php echo $item->get_permalink()?>"><?php echo $item->get_title()?></a></h4>
	<p><small><?php echo $item->get_date('j F Y, g:i a')?></small></p>
	<p><?php echo $item->get_description()?></p>
 
	<div align="center">
	<?php
 
	if ($enclosure = $item->get_enclosure())
	{
		echo $enclosure->native_embed();
		echo '<p><small>Size is ' . $enclosure->get_size_gb() . ' GB</small></p>';
	}
 
	?>
	</div>
 
	<hr />
 
<?php endforeach; ?>
 
</body>
</html>

See Also


reference/simplepie/set_enclosure_class.txt · Last modified: 2011/03/06 03:56 (external edit)