url box plugin

Creating and modifying plugins.
Post Reply
Tys
Regular
Posts: 36
Joined: Thu Feb 24, 2005 5:18 am

url box plugin

Post by Tys »

I recently ran into the problem of semi-integrating WebCalendar with s9y. While this isn't perfect (like merging the Blog Calendar with the WebCalendar) it is a decent solution which does have other potiental uses.

Web Calendar has file called upcoming.php (example here: http://tvg.ca/calendar/upcoming.php, note: heavily modified to look good in the blog) that displays upcoming events. I first tried to include this file right in s9y so I wouldn't have to do a url fetch each page load, but ran into dbi problems with WebCalendar.

So I ended up merging the html nugget plugin with the RSS feed plugin to fetch a url and cache it. This solves the dbi problems I was running into and the url fetch each load problem (as the result is now cached). I included the option of also running markup on the fetched url, I haven't tested it and I'm not sure the security issues it might entail.


Here is the code, put it in plugins/serendipity_plugin_urlbox/serendipity_plugin_urlbox.php and an example on my blog, see the "Event Calendar" sidebar.
Last edited by Tys on Sat Mar 05, 2005 9:46 am, edited 1 time in total.
Tys
Regular
Posts: 36
Joined: Thu Feb 24, 2005 5:18 am

Post by Tys »

Guess I can simplify the getting urls with a simple include, but then it gets executed (maybe that is what people want?) security issues though. Instead I found the file_get_contents() function which seems to do the trick.

You can change the following:

Code: Select all

             // grab the url
            $handle = fopen($url, "r");
            $contents = '';
            while (!feof($handle)) {
               $contents .= fread($handle, 8192);
            }
            fclose($handle); 
To:

Code: Select all

             // grab the url
            $contents = file_get_contents($url);
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Even better would be to use the PEAR::HTTP_Request module, which we use for fetching images (and fetching RSS feeds in the latest version of the plugin). So people with a PHP setting of allow_url_fopen = false can still download the files. :)

Security implications are, BTW, not really high. :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Tys
Regular
Posts: 36
Joined: Thu Feb 24, 2005 5:18 am

Post by Tys »

That was the first thing I tried. However it was taking 15 seconds to do a page request, where as this is way was well under a second. Maybe I was doing something wrong, hrm.

I guess it could do a check and see if allow_url_fopen is set, if so use file_get_contents, if not use the soap library.
Tys
Regular
Posts: 36
Joined: Thu Feb 24, 2005 5:18 am

Post by Tys »

Tried the http_request again, seems to be working fine now, not sure what was wrong before. Right now it checks to see if allow_url_fopen is true, if so it uses file_get_contents, other wise it uses the PEAR library.

I have added the option to allow the url to be loaded in an iFrame so if the remote server is slow (as is my case for my gallery) it won't slow down the rest of the blog. I ran into the problem where I needed to get the iframe to resize, so I found some javascript code that will do it, but only for local urls. So I then made an option for s9y to download, then display the url as a local url.

Because the sidebar plugins can't fire their own events and sessions aren't saved until the page load finishes (where the iframe loads concurrently). I had to pull info right from the $serendipity variable. Bad practice but I didn't see any other option (didn't want to send all the info through the url). This might break with mod_rewrite, I am not sure.

Here is the code, let me know if you can think of any improvements.
Post Reply