Recent Topics

1 Jun 25, 2006 04:44    

[list=1]

  • Introduction

  • Required Files

  • Core hack

  • Save code as rss2.php

  • Edit a few tags

  • Upload rss2.php

  • Credits

  • Update Notes

  • [/list:o]

    1. Introduction

    This hack is designed to allow b2evolution to include files in RSSv2 feeds (podcasts, vidcasts, et-cetera). It has iTunes support but requires manual editing of the iTunes tags once within the rss2.php file.

    Right now this is a very rough hack. I would love help with it as those of you who use the hack experiment with it. Please post your results here and I'll update this post and leave update notes below the credits.

    2. Required Files

    b2evocore/_class_item.php
    rss2.php

    3. Core Hack

    In b2evocore/_class_item.php:
    Look for:

    
    function url_link( $before='', $after='', $format = 'htmlbody' )
    {
       if( !empty( $this->url ) )
       {
          echo $before;
          echo format_to_output( '<a href="'.$this->url.'">'.$this->url.'</a>',
                                  $format );
          echo $after;
       }
    }
    

    It's right at the end of the file.

    After the above function's last brace, add this:

    
    // RSS Enclosure Hack
    function ret_url( )
    {
      if( !empty( $this->url ) )
      {
         return $this->url;
      }
    }
    




    4. Save code as rss2.php

    Copy the following code. Paste it into a text editor (TextEdit, Gedit, Notepad, etc.) and save the file as rss2.php:

    
    <?php
    
    	/**
    
    	 * This template generates an RSS 2.0 feed for the requested blog
    
    	 *
    
    	 * See {@link http://backend.userland.com/rss}
    
    	 *
    
    	 * b2evolution - {@link http://b2evolution.net/}
    
    	 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
    
    	 * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
    
    	 *
    
    	 * @package xmlsrv
    
    	 */
    
    	$skin = '';										// We don't want this do be displayed in a skin !
    
    	$show_statuses = array();			// Restrict to published posts
    
    	$timestamp_min = '';					// Show past
    
    	$timestamp_max = 'now';				// Hide future
    
    	/**
    
    	 * Initialize everything:
    
    	 */
    
    	$resolve_extra_path = false;	// We don't want extra path resolution on this page
    
    	require dirname(__FILE__).'/../b2evocore/_blog_main.php' ;
    
    	header("Content-type: application/xml");
    
    	echo "<?xml version=\"1.0\"?".">";
    
    
    // function needed for enclosure file size
    function remote_filesize($uri)
    {
       $head = ReturnHttpHead($uri);
       
       // see if it was a 302
       if(strpos($head,'302 Found'))
       {	// yup
       	// get the new location
       
       	$pos = strpos($head,'Location: ') + 10;
       	if($pos !== false)
       	{
       		$endpos = strpos($head,chr(13),$pos);
       		$uri = substr($head,$pos,($endpos-$pos));
       		$head = ReturnHttpHead($uri);
       	}
       	
       }
       		
       		
       $regex = '/Content-Length:\s([0-9].+?)\s/';
       $count = preg_match($regex, $head, $matches);
       
       
       // gets you the numeric value from the Content-Length
       // field in the http header
       $regex = '/Content-Length:\s([0-9].+?)\s/';
       $count = preg_match($regex, $head, $matches);
    	
       // if there was a Content-Length field, its value
       // will now be in $matches[1]
       if (isset($matches[1]))
       {
           $size = $matches[1];
       } else {
           $size = 'unknown';
       }
    
       return $size;
    }
    
    function ReturnHttpHead($uri)
    {
    	// start output buffering
       ob_start();
       // initialize curl with given uri
       $ch = curl_init($uri);
       // make sure we get the header
       curl_setopt($ch, CURLOPT_HEADER, 1);
       // make it a http HEAD request
       curl_setopt($ch, CURLOPT_NOBODY, 1);
         
       $okay = curl_exec($ch);
       
       curl_close($ch);
       // get the output buffer
       $head = ob_get_contents();
       // clean the output buffer and return to previous
       // buffer settings
       ob_end_clean();
    	
    	return $head;
    	
    }
    
    function DoEnclosure($testurl)
    {
    	// do the enclosure
    	
    	$url_len = strlen($testurl);
    	if($testurl)
    	{
    		$pos = $url_len - 1;
    		while(substr($testurl,$pos,1) != '.')
    		{	// count backwards until we get a .
    			$pos--;
    			if(!$pos)
    				break;
    		}
    		
    		if(substr($testurl,$pos,1) == '.')
    		{
    			$posres = substr($testurl, $pos, ($url_len - $pos) );	
    			$mimetype ="";
    			switch(strtolower($posres))
    			{
    				case ".mp3":
    					$mimetype = "audio/mpeg";
    				break;
    								
    				case ".wav":
    					$mimetype= "audio/wav";
    				break;
    					
    				case ".wma":
    					$mimetype = "audio/wma";
    				break;
    				
    				case ".m4a":
    					$mimetype = "audio/mp4";
    				break;
    				
    				case ".midi":
    					$mimetype = "audio/midi";
    				break;
    				
    				case ".mp4":
    					$mimetype = "video/mp4";
    				break;
    				
    				case ".wmv":
    					$mimetype = "video/x-ms-wmv";
    				break;
    				
    				case ".mpeg":
    					$mimetype = "video/mpeg";
    				break;
    				
    				case ".avi":
    					$mimetype = "video/msvideo";
    				break;
    			
    				case ".mov":
    					$mimetype = "video/quicktime";
    				break;
    			
    				case ".png":
    					$mimetype = "image/png";
    				break;
    								
    				case ".bmp":
    					$mimetype = "image/bmp";
    				break;
    			
    				case ".jpg":
    				case ".jpeg":
    					$mimetype = "image/jpeg";
    				break;
    							
    				case ".gif":
    					$mimetype = "image/gif";
    				break;
    			
    				case ".ogg":
    					$mimetype = "application/ogg";
    				break;
    				
    				case ".torrent":
    					$mimetype = "application/x-bittorrent";
    				break;
    						
    				// add mime types here
    			}
    			if($mimetype)
    				echo "<enclosure url=\"$testurl\" length=\"". remote_filesize($testurl) ."\" type=\"$mimetype\"/>";
    		}
    	}
    	// end enclosure			
    
    	
    }
    
    ?>
    
    <!-- generator="b2evolution/<?php echo $b2_version ?>" -->
    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
    
    	<channel>
    
    		<title><?php $Blog->disp( 'name', 'htmlbody' ) ?></title>
    
    		<link><?php $Blog->disp( 'blogurl', 'xml' ) ?></link>
    
    		<description><?php $Blog->disp( 'shortdesc', 'xml' ) ?></description>
    
    		<language><?php $Blog->disp( 'locale', 'xml' ) ?></language>
    
    		<docs>http://backend.userland.com/rss</docs>
    
    		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=<?php echo $b2_version ?>"/>
    
    		<ttl>60</ttl>
    
    		<?php while( $Item = $MainList->get_item() ) {	?>
    <copyright><?php echo date("Y"); ?></copyright>
    <managingEditor>nospam@nospam.com (No Spam)</managingEditor>
    <pubDate><?php $Item->issue_date( 'r', true ) ?></pubDate>
    <generator>b2evolution <?php echo $b2_version ?></generator>
    <category><?php $Blog->disp( 'keywords', 'htmlbody' ) ?></category>
    <?php /* Removie this line and edit the url, width, and height tags below to include a picture ?>
    <image>
      <title><?php $Blog->disp( 'name', 'htmlbody' ); ?></title>
      <link><?php $Blog->disp( 'staticurl', 'raw' ) ?></link>
      <url>http://www.yourdomain/path-to-picture</url>
      <width>120</width><height>118</height>
    </image>
    <?php Removie this line and edit the url, width, and height tags above to include a picture */ ?>
    <itunes:subtitle><?php $Blog->disp( 'tagline', 'htmlbody' ); ?></itunes:subtitle>
    <itunes:author><?php $Blog->disp( 'name', 'htmlbody' ); ?></itunes:author>
    <itunes:summary><?php $Blog->disp( 'longdesc', 'htmlbody' ); ?></itunes:summary>
    <itunes:owner>
      <itunes:name><?php $Blog->disp( 'name', 'htmlbody' ); ?></itunes:name>
      <itunes:email>nospam@nospam.com</itunes:email>
    </itunes:owner>
    <?php /* Removie this line and edit the url tag below to include a picture ?>
    <itunes:image href="http://www.yourdomain/path-to-picture" />
    <?php Removie this line and edit the url tag above to include a picture */?>
    <itunes:category text="Main Category"/>
    <itunes:category text="Secondary Category">
      <itunes:category text="Subcategory"/>
    </itunes:category>
    
    <itunes:explicit>no</itunes:explicit>
    		<item>
    
    			<title><?php $Item->title( '', '', false, 'xml' ) ?></title>
    <copyright><?php echo date("Y"); ?></copyright>
    <itunes:subtitle><?php $Item->title( '', '', false, 'xml' ) ?></itunes:subtitle>
    <itunes:author><?php $Blog->disp( 'name', 'htmlbody' ) ?></itunes:author>
    <itunes:summary><?php $Item->permalink( 'single' ) ?></itunes:summary>
    <itunes:owner>
      <itunes:name><?php $Item->Author->prefered_name() ?></itunes:name>
      <itunes:email>nospam@nospam.com</itunes:email>
    </itunes:owner>
    <?php /* Removie this line and edit the url tag below to include a picture ?>
    <itunes:image href="http://www.yourdomain/path-to-picture" />
    <?php Removie this line and edit the url tag above to include a picture */?>
    <itunes:category text="Main Category"/>
    <itunes:category text="Secondary Category">
      <itunes:category text="Subcategory"/>
    </itunes:category>
    <itunes:explicit>no</itunes:explicit>
    <itunes:keywords><?php $Blog->disp( 'keywords', 'htmlbody' ) ?></itunes:keywords>
    
    			<link><?php $Item->permalink( 'single' ) ?></link>
    
    			<pubDate><?php $Item->issue_date( 'r', true ) ?></pubDate>
    
    <dc:creator><?php $Blog->disp( 'keywords', 'htmlbody' ) ?></dc:creator>
    
    			<?php $Item->categories( false, '<category domain="main">', '</category>', '<category domain="alt">', '</category>', '<category domain="external">', '</category>', "\n", 'xml' ) ?>
    
    			<guid isPermaLink="false"><?php the_ID() ?>@<?php echo $baseurl ?></guid>
    
    			<description><?php
    
    				$Item->url_link( '', ' ', 'xml' );
    
    				$Item->content( 1, false, T_('[...] Read more!'), '', '', '', 'xml', $rss_excerpt_length );
    
    			?></description>
    
    			<content:encoded><![CDATA[<?php
    
    				$Item->url_link( '<p>', '</p>' );
    
    				$Item->content()
    
    			?>]]></content:encoded>
    <enclosure><?php DoEnclosure($Item->ret_url()); ?></enclosure>
    
    			<comments><?php comments_link( '', 1, 1 ) ?></comments>
    
    		</item>
    
    		<?php } ?>
    
    	</channel>
    
    </rss>
    
    <?php log_hit(); // log the hit on this page ?>
    


    5. Edit a few tags

    Edit the following tags within the code above to match your blog:

    [list]

  • iTunes:category (two sets, in accordance with [url=http://www.apple.com/itunes/podcasts/techspecs.html#_Toc526931698]Apple's iTunes Technical Specifications[/url]

  • iTunes:explicit

  • image (optional)

  • [list]

  • delete the php comment lines before and after the image tags

  • edit the url to match the url of your podcast's image

  • edit the height to match the image height in number of pixels

  • edit the height to match the image width in number of pixels

  • [/list:u]

  • iTunes:image (two sets, optional)

  • [list]

  • delete the php comment lines before and after each of the two iTunes:image tags

  • edit the url to match the url of your podcast's image

  • [/list:u]

  • iTunes:email (two sets, optional)

  • [/list:u]

    6. Upload rss2.php

    Replace the new RSS2.php with the one on your server within the xmlsrv folder.

    7. Credits

    This hack is a modified rss2.php page from b2evolution 0.9.2 as written by the suave b2evolution develipment team and CVS contributors. This hack also uses a lot of code from [url=http://forums.b2evolution.net/viewtopic.php?t=2542]Mike's (turbo2ltr's) brilliant RSS Enclosure hack[/url].

    8. Update Notes

    24 June, 2006: Added "two sets" to iTunes tags to assure those who use this hack remember to edit both sets

    25 June, 2006: Added Required Files section


    Form is loading...