2 thegreenman Dec 24, 2004 15:27

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 :)
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.
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.
What kind of errors?
I typed:
http://www.mikemontalvo.com/podcasts/MLC_2004_12_24.mp3
in the "Link to URL" field for [url=http://www.mikemontalvo.com/index.php?blog=2&title=mike_s_lifecast_3&more=1&c=1&tb=1&pb=1] this[/url] post
I had previously uploaded the file.
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>
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
echo "<enclosure url=\"$testurl\" length=\"". remote_filesize($testurl) ."\" type=\"audio/mpeg\"/>";
with
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)
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
I'd restore the two files from your backup. I really can't imagine any part of the hack causing that error.
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.
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.
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.
Sorry Mike for being thick but can you tell me how I make sure PHP is compiled with the CURL option?
Thanks.
Simon.
There are several ways. The easiest would probably be to make a php script that calls phpinfo().
http://us4.php.net/manual/en/function.phpinfo.php
What you want is this phpinfoscript
<?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.
<?php
phpinfo();
?>
my code is prettier woo hooo!!!
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;
}
http://www.nadig.com/xmlsrv/rss22.php?blog=2
Sorry, thought I'd posted it.
I renamed it so I could compare the output with rss2.php
That was easy.
You didn't do the whole hack. You need to mod the _class_item.php.
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.
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.
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.
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.
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.
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.
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.
Hey everyone. I updated the rss2.php to handle a bunch of MIME types, a la the MT hack.
Download here:
http://www.mikemontalvo.com/index.php?blog=6&title=enclosures_for_b2evolution&more=1&c=1&tb=1&pb=1
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.
:-/
If you look at the souce of the bad XML page:
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.
turbo2ltr wrote:
If you look at the souce of the bad XML page:
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.
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.
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
So, has anyone tried this curl-less?
I am postign this link to my other post because I think it might have something to do with the Hack. I had gotten everything working but now have this problem. Any help woudl be Great!
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).
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
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.
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
Hey guys,
I tracked down the problem RedPlaneta was having to the way some servers were handling media links.
See the details and get the latest version [url=http://www.mikemontalvo.com/index.php?blog=6&title=enclosures_for_b2evolution_update&more=1&c=1&tb=1&pb=1]here[/url]
Please leave a quick comment on my site if you are using the hack.
Thanks,
Mike
Hey, I love this hack.
I need help. I tried to add some of the tags listed on this PDF from Apple. For Itunes 4.9.
http://phobos.apple.com/static/podcast_specifications.pdf
I don't have an example of what I ahve done up, as I have taken it down. Some general advice would be awsome. I am intrested in the Summary and Owner tags.
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.
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.
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.
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
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.
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.
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.
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.
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.
I agree that B2 might not support the non standard itunes tags but it woudl be nice to automaticly support normal enclouser tags
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.
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)
Did you read the thread?
Do you have a slash at the end of your base URL in the config?
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?
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.
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?
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
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.
http://brandon.fuller.name/archives/hacks/mtenclosures/
this is the MT plugin, which you could reverse engineer