Recent Topics

RSS Enclosure hack

Started by on Dec 24, 2004 – Contents updated: Dec 24, 2004

Dec 24, 2004 07:26    

EDIT:

For the sake of everyone looking for this hack, I will put a link in this post.
[url=http://www.mikemontalvo.com/index.php?blog=6&title=enclosures_for_b2evolution&more=1&c=1&tb=1&pb=1]b2e Enclosure Hack[/url]

6/30/05: Update- details [url=http://www.mikemontalvo.com/index.php?blog=6&title=enclosures_for_b2evolution_update&more=1&c=1&tb=1&pb=1]here[/url]

Now back to your regularly scheduled post.
/edit

Hey guys,
I'm pretty new to b2evo (a day to be exact), but I've whipped up a hack that adds enclosures to the RSS 2 feed if you put a url to an MP3 in the
"Link to URL" field when creating a post. I did it this way for ease of making it work.

Just wanted to see what the 'normal' way of adding enclosures. I'm coming from Blogger which didn't support enclosures. Does the feed generator usually just scan the whole post and 'enclose' any mp3 links? I guess what I'm asking is how other blog software does it and/or how would you like to see it work?

Thanks,
-Mike

Dec 28, 2004 00:24

Mike,

I have a quick questions about the code you showed me.. if ya dont mind

i checked your site, and the enclosure is also appearing in your post, with size, etc.. Are you inputting that seperately or is that a result of your hack, ie, its getting picked up via the edited rss file, and automagically through whatever file is responsible for the post content?

Thanks btw, for the quick reply to my pm :)

Dec 28, 2004 01:13

No, the links at the end of the post to the actual mp3 file, I manually type in (with the size and length)

The only thing the hack does is take the "Link to URL" address you typed in when you created the post, and insert the enclosure tag for it into the RSS output, if it's an MP3 file. It does nothing with the posts.

Dec 28, 2004 23:31

could you give me an example of the exact format of the mp3 file name as you type it in. I'm getting errors when I upload and try to post.

Dec 29, 2004 00:23

Cannot post, please correct these errors:

* Supplied URL is invalid: URL not allowed
* Found invalid URL: URL not allowed
* Parser error: mismatched tag: body near </a></body>

Dec 29, 2004 00:33

I don't know man.

Someone else had the same problem. What version b2e are you running?

Is php compiled with CURL enabled?

What if you replace

Code

echo "<enclosure url=\"$testurl\" length=\"". remote_filesize($testurl) ."\" type=\"audio/mpeg\"/>";

with

Code

echo "<enclosure url=\"$testurl\" length=\"1234\" type=\"audio/mpeg\"/>";

in rss2.php. Does the error go away? (It won't generate a correct RSS enclosure)

Dec 29, 2004 00:52

that didn't get it and

I dont know if curl is enabled...

the only info I've got from cpanel is php version 4.3.9

Dec 29, 2004 01:08

I'd restore the two files from your backup. I really can't imagine any part of the hack causing that error.

Dec 29, 2004 02:27

phpinfo

/configure \
--with-apxs=/usr/local/apache/bin/apxs \
--with-xml \
--enable-bcmath \
--enable-calendar \
--with-curl \

so curl is enabled,

I'll restore from backup.

Thanks for the help.

Dec 29, 2004 03:20

the problem seems to be with linking to myself, I think it's because I banned my own domain in antispam by mistake.

yes that's the problem, unban my own domain in antispam blacklist, and it works.

This hack is fine, why don't you post it in the top message of this topic so others can use it too.

Jan 03, 2005 19:48

Mike,

I am an even newer than you to B2Evo. However I also installed B2Evo to create a site for Podcasting therefore I am very interested in adding the 'enclosure' command to the rss feed.
You say you have modified your version to include this, but would you mind telling me how exactly you did that so that I can modify mine?

Thanks.
Simon.

Jan 03, 2005 20:13

Sorry Mike for being thick but can you tell me how I make sure PHP is compiled with the CURL option?

Thanks.
Simon.

Jan 03, 2005 21:45

What you want is this phpinfoscript

Code

<?php
 
   ob_start();
 
   phpinfo(INFO_MODULES);  
  
   $string = ob_get_contents();
   ob_end_clean();  
  
   $pieces = explode("<h2", $string);
  
   $settings = array();
  
   foreach($pieces as $val)
   {
       preg_match("/<a name=\"module_([^<>]*)\">/", $val, $sub_key);
      
       preg_match_all("/<tr[^>]*>
                                           <td[^>]*>(.*)<\/td>
                                           <td[^>]*>(.*)<\/td>/Ux", $val, $sub);
       preg_match_all("/<tr[^>]*>
                                           <td[^>]*>(.*)<\/td>
                                           <td[^>]*>(.*)<\/td>
                                           <td[^>]*>(.*)<\/td>/Ux", $val, $sub_ext);
                              
       foreach($sub[0] as $key => $val)
       {
           $settings[$sub_key[1]][strip_tags($sub[1][$key])] = array(strip_tags($sub[2][$key]));
       }
      
       foreach($sub_ext[0] as $key => $val)
       {
           $settings[$sub_key[1]][strip_tags($sub_ext[1][$key])] = array(strip_tags($sub_ext[2][$key]), strip_tags($sub_ext[3][$key]));
       }              
              
   }
 
  
   echo "<pre>";
   print_r($settings);
 
?>

name it phpinfo.php put it in your http directory of your webserver, then navigate there in your browser and it will display all the goodies in php.

Jan 04, 2005 02:10

Code

<?php
phpinfo();
?>

Jan 04, 2005 04:30

my code is prettier woo hooo!!!

Jan 07, 2005 00:41

Any guesses? This is the error I get:

>>>>>>
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

--------------------------------------------------------------------------------

The following tags were not closed: rss, channel, item. Error processing resource 'http://www.nadig.com/xmlsrv/rss22.php?bl...
>>>>>>

My assumption is that its barfing on the if statement. Here's the enclosure code block, straight from the supplied file, just for reference:

>>>>>

<?php
// do the enclosure
$testurl = $Item->ret_url( );
if($testurl)
{
$posres = strpos($testurl,".mp3");
if($posres != false) // only do an enclosure for MP3s
echo "<enclosure url=\"$testurl\" length=\"". remote_filesize($testurl) ."\" type=\"audio/mpeg\"/>";
}
// end enclosure
?>
<comments><?php comments_link( '', 1, 1 ) ?></comments>
</item>
<?php } ?>
</channel>
</rss>
<?php log_hit(); // log the hit on this page

// function needed for enclosure file size
function remote_filesize($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();

// 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;
}

Jan 07, 2005 00:53

whats the link to the RSS feed it made?

It's not the code that has a problem. Its the XML file it created.

Jan 07, 2005 01:10

That was easy.

You didn't do the whole hack. You need to mod the _class_item.php.

Jan 07, 2005 01:15

BTW, the page you see when you get an error when viewing an XML file isn't necessarily the output. It's an XML file rendered with a style sheet. To see the actual file, "veiw source". You will see there is a PHP error. It's calling the ret_url() function but not finding it. I assume you didn't add it to _class_item.php or it was added in the wrong spot.

Jan 07, 2005 01:27

This is what I added:

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

Right above my last ?> in _class_item.php

So I'm confused. I tripple checked that the fix is in there...

THanks for the braincheck on viewing the XML - PHP I'm ok on, RSS is new to me. I get "XML source unavailable for viewing" in IE when I try and check it out. Probably MSFT's fault.

Jan 07, 2005 01:44

You put the function outside of the php.

As per the instructions you should put it "After the above function's last brace" (}) . By putting after the ?>, you are putting it outside of the code that will be processed by the php processer.

Jan 07, 2005 01:48

I assume you changed the "mp3" to "jpg" for your test as I see it's enclosing a jpg. If you would like to enclose jpgs, you will need to set up if-thens for each mime type.

Jan 07, 2005 02:14

yeah, i got it all figured out now, thanks very much for the support and attention. I'll rewrite it to do switch/case for a dozen or so mime types when I get set with this.

Jan 12, 2005 23:12

Is there any way to work this enclosures hack to ping audio.weblogs.com whenever the link to is an mp3 file?

That would be suh-weet.

Jan 12, 2005 23:14

That would be part of the posting script, not the RSS feed script. It's a great idea, but I'll leave that to someone else.

Jan 24, 2005 19:47

Hello all, I am having problems. Can you help. I am getting

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

--------------------------------------------------------------------------------

The following tags were not closed: rss, channel, item. Error processing resource 'http://www.hopeontheweb.com/blogs/xmlsrv/rss2.php?blog=6'.


I checked to make sure the code is in the right place on the _class_item.php file here is a snipit from it.

========================
/**
* Template function: Display link to item related url
*
* {@internal Item::url_link(-) }}
*
* @param string string to display before the url (if exists)
* @param string string to display after the url (if exists)
* @param string Output format, see {@link format_to_output()}
*/
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;
}
}

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

/**
* Template function: Display the number of words in the post
*
* {@internal Item::wordcount(-) }}
*/
function wordcount()
{
echo $this->wordcount;
}

}
?>
===========================
and i used the rss2.php file from the page of the hack authour. I have tried both files.

If I do not have a link to item the RSS load fine, see
http://www.hopeontheweb.com/blogs/xmlsrv/rss2.php?blog=4

but if I have one it does not see
http://www.hopeontheweb.com/blogs/xmlsrv/rss2.php?blog=6

Any suguestions?

I have a ticket into my hosting co to find out if we support CURL.

:-/

Jan 24, 2005 19:52

If you look at the souce of the bad XML page:

Code

Fatal error:  Call to undefined function:  curl_init() in D:\home\Default\hopeontheweb.com\htdocs\blogs\xmlsrv\rss2.php</b> on line 73

One of the requirements of the hack is that you have curl enabled in php. You will need to contact your webhost to see if they will enable it for you.

Jan 24, 2005 21:42

turbo2ltr wrote:

If you look at the souce of the bad XML page:

Code

Fatal error:  Call to undefined function:  curl_init() in D:\home\Default\hopeontheweb.com\htdocs\blogs\xmlsrv\rss2.php</b> on line 73

One of the requirements of the hack is that you have curl enabled in php. You will need to contact your webhost to see if they will enable it for you.

Thank you, atleast its not somethign I have done wrong. I have asked my host if they can enable curl. We will see. I wonder how big of a deal that would be for them.

Is it posablile for someon to wright this hack without the curl functions? Sorry not a programer. I just chop up other peoples stuff till it works.

Jan 25, 2005 07:08

It could be re-written to not use curl, but it would only work with locally hosted files. If the files you were enclosing were hosted on another server, it wouldn't work as CURL is the only [easy] way to get the file information needed from off-site files.

Jan 25, 2005 14:58

turbo2ltr wrote:

It could be re-written to not use curl, but it would only work with locally hosted files. If the files you were enclosing were hosted on another server, it wouldn't work as CURL is the only [easy] way to get the file information needed from off-site files.

Locally meaning the same site as B2? I have no problem putting my file in the media folder or wherever I would need to.

Still waiting for my hosting co, but my guess is unless its something really simple they are not going to add CURL

Mar 01, 2005 19:54

So, has anyone tried this curl-less?

Jun 13, 2005 03:08

I'm also contemplating hacking up a curl-less version of this (mostly for fun)... I guess it would have to check if the file is local and, if not, download it to a temporary file where it could get the info for the `length` and `type` elements of the enclosure tag.

If anyone out there still wants a curl-less version of this hack, let me know (or I won't think about it further).

Jun 30, 2005 02:41

Hi guys!

I've been using the enclosure hack for a couple of weeks for my podcast. It works great, but I have a problem with the size detector. Somehow when the file is hosted outside of my blog server, the size atribute of the mp3 file reads "unknown". This is causing me trouble with all the Podcasts Directories and Podcatching programs, 'cause they are reporting a size of "0" (since they can't find a meaningful value on my feed).

CURL is enabled on the server.

Anyone has experienced this??. My files are hosted at Libsyn.

The site is at http://radio.planetachat.com (it's in spanish, but the RSS feed link is easily found on the sidebar).

Thanks

Jun 30, 2005 02:45

This typically means either CURL is not working, or the server that the MP3 is on does not support header only http requests.

Could be a DNS issue as well. If the DNS for the server running PHP isn't right, it might only be able to resolve itself.

Jun 30, 2005 22:52

turbo2ltr wrote:

This typically means either CURL is not working, or the server that the MP3 is on does not support header only http requests.

Could be a DNS issue as well. If the DNS for the server running PHP isn't right, it might only be able to resolve itself.

Uhm... Ok ... I'm going to try tonight using the IP instead of the server name of the MP3 hosting service. I'll let you know.

THanks

Jul 03, 2005 17:14

Not sure what you are asking. You wouldn't be able to add those tags without modifying the hack...and then you still need a way to pass the data for the tags to the feed.

Jul 06, 2005 15:53

Where in the hack can I add them. I do not mind if they are static. For example the image and show discrition tags. I don't understand the correct syntax.

Second, is there any way to add another hack that uses the RSS generator to generate a static RSS page. I am constantly having problems with my hosting company with the folder I keep my mp3's in. The PHP can not access the folder quick enough and it timesout. They are working on this, but another solution would be just to have a static RSS page, like the static HTML pages b2e can generate.

Jul 10, 2005 08:12

Ok, help!!! my hosting company has decided not to support CURL due to "Security reasons" I need a no curl verson of this as fast as possiable. I will try to figure out a way to post my rss manualy in the mean time.

Jul 24, 2005 21:45

Hi Turbo and all!

Just an update about me using the Enclosure Hack:

I had to delete the size fetching part for two reasons:

1.- My podcast storage provider (Libsyn) changed again the way they are storing .mp3 files. Now it seems that they are doing load balancing, so the file comes from a different server each time is requested. After that change the latest version of the size function stopped working again.

2.- It seems that Libsyn has been too slow to return the header for the size when my b2evolution goes fetching for it. So I was experiencing lots of timeout errors with my podcatching software and/or newsreader.

So I came back to the previous version of the hack and deleted the use of the size function (writing "uknown" by default).

IHMO I think that since the xml of B2Evo is generated on the fly, there's now way that the size function would work properly, that is unless the .mp3 files are stored on the same server (that way there wouldn't be any timeout and no need for curl).

I believe that the best way to solve this is to allow the user to manually enter (in some way) the file size of the enclosure. You think you could do something like that Turbo ??? (my php knowledge is too basic to do it myself).

Anyway, the hack still works great but without the Size Fetching feature.

Cheers,

RedPlaneta

Sep 10, 2005 19:21

This a very useful hack. Here's a feature request: hack the upload form so that if the file being uploaded is an mp3, then the url of the file gets added to the 'Link to URL' as well as the body of the post. Most basic users forget to copy the mp3 url to the link to url field, so this would take care of that.

Sep 12, 2005 15:56

First of all, that Dvorak... Pricless

Ok this is more of a gripe than a suguestion, With all the other Bloging platforms automaticly supporting podcasts, don't you think its time for B2 to jump in. Apple has embrased podcasting, this thing is not going away, lets add native support for it. We should be able to just have the mp3 link in the file and have the tags added automaticly.

For anyone needeing another solution that does not want to apply this hack, you can run you feed through feedburner.com. its free and it will help with the enclosure tags.

I have my normal linkable feed point to feedburner and then I have made a copy of the rss2 file and renamed it, to point feed burner at it.

Sep 12, 2005 16:03

That's actually a pretty good suggestion. Especially in light of the fact that Apple is making iTunes use some non-standard tagging in the RSS feed to display channel image (and some other things, I think). Feedburner supports this. b2evolution is all about standards and even if the RSS 2.0 standard was fully supported (and I agree that it should be), then the feed still wouldn't take advantage of all of the iTunes features.

Sep 12, 2005 16:09

Personally I was hoping that there would be enough of an uproar about the non standard tags in iTunes that apple would 'unbrand' the tags, but apparently not. Apple can do no wrong. I still think that what apple did is not condusive to open standards and should not be supported.

Sep 12, 2005 16:25

I agree. I don't think b2evolution should support Apple's non-standard feed format. But people who want to take advantage of all the features of it can still use feedburner.

Sep 12, 2005 17:10

I agree that B2 might not support the non standard itunes tags but it woudl be nice to automaticly support normal enclouser tags

Oct 14, 2005 01:39

The enclosures hack appears to not work with the latest b2evo release.

The rss2.php page results in a 404 not found error.

Any idea what causes this? I'm not going to be podcasting for a few days, and it's been eons since I last did one, but it'd be nice to have this back up and running.

Oct 14, 2005 02:58

Ummmm.... I read that, and I understand that the upgrade changed things. But I didn't see a solution anywhere in the content you linked to. Did I miss something? Or were you just pointing out that the upgrade caused the problem? (I kinda already figured that)

Oct 14, 2005 03:02

Did you read the thread?
Do you have a slash at the end of your base URL in the config?

Oct 14, 2005 03:23

Your link went straight to a particular post within the thread, so I didn't realize you wanted me to start from the beginning.

I tried that, and it worked. But... is there a way to fix it without adding the ending slash? Everything else works right for me, except the enclsoures hack.

I get very good search engine ranking, especially with Google, and I'm leary of messing with anything that changes the URL structure. I know the // should not techinically change anything on other pages, but in the world of seo you'd be surprised how one little thing can change your rankings dramatically.

So is there any way to just get this one page working? I mean, the original rss2.php page works without adding the ending slash to the config, why is it that the modified rss2.php page doesn't work?

Oct 20, 2005 02:46

To be honest I haven't looked too much into it. On the surface it looked like a problem with an interaction in outside modules. There were other problems with other areas of b2e that required the slash as well.

Nov 14, 2005 01:37

Okay, adding the backslash to the base url lets the hack work with 9.1, but it causes the page links at the bottom (e.g. "Page 2") of the blog page to break. For me, it only shows the name of the stub file as the base url and then all the extra php stuff.

Anyone gotten this hack to work on 9.1 WITHOUT adding the backslash to the blog's base url?

Nov 25, 2005 18:42

My podcasts don't show the Author or a Description in iTunes. Is there a way to add these tags to the rss2.php?

Mar 22, 2006 16:15

Could someone please tell me if they have this working with 1.6 "Phoenix Alpha"

Are there any plans to include enclosures in a future version of b2evo?

Thanks
Sam

Jun 25, 2006 05:30

No, it's not working in the 1.6 Alpha. RSS enclosures may have been added since though. The news page of b2evolution is now running v1.8 and I haven't seen the code behind it.

*fingers crossed*

In the meantime, I wasn't satisfied with having two // in the urls of my blogs. I took Mike's (turbo2ltr's) code, added iTunes tags, a few other tweaks, and began using it to podcast. I've had few problems so far excapt that some iTunes tags are static and getting shownotes (the text of a post) to show up in iTunes has been difficult. That hack is listed seperately [url=http://forums.b2evolution.net/viewtopic.php?t=8257]here[/url].

I plan to try making a similar hack for Phoenix, as I'll need it. I'm waiting for a stable version though. I don't want to write a hack for the 1.6 Alpha or a CVS snapshot that may well not work anymore when 1.8 is released.


Form is loading...

multiblog engine – This forum is powered by b2evolution CMS, a complete engine for your website.