Wordpress Digg Widget
April 14th, 2007 by mikeI was taking a break from coding earlier and found a blog post on digg requesting a digg widget that would show your friends digg activity. It seemed like a pretty good idea, so I threw together a quick proof of concept. The styling isn’t great, but it works! Check out the sidebar here (on the homepage) for an example.
You can download the plugin here. Place it in the plugins directory for Wordpress then activate it under plugins (it’s called diggfriends). Once you’ve done that you can place a call to the digg_friends() function anywhere in your theme files and it will create a list of what your friends have dugg! The function takes one argument, your username, passed as a string.
April 14th, 2007 at 7:09 pm
[…] Vino2Vino’s Mike jumped right on the challenge by pumping out a fairly simple Wordpress plugin that will display a user’s friend list of recent Diggs. […]
April 14th, 2007 at 7:11 pm
Mike,
Thanks for the quick action! How hard would it be to add a little style and maybe pull in some extra data such as # of Diggs and a link to the users profile?
Awesome work!
-Eric
April 14th, 2007 at 7:26 pm
It wouldn’t be hard at all. I’ll do some more work on it later, but I have a few things to do tonight to get ready for the Web 2.0 Expo tomorrow!
-Mike
April 14th, 2007 at 9:25 pm
Here is a flash version: (might not work on hosted wordpress account) http://www.lemieuxster.com/digg/scroller/
April 15th, 2007 at 2:20 am
Thanks !! Looking for this …..
April 15th, 2007 at 2:39 am
1.) You use regular expressions instead of an XML parser.
2.) You can get your friends diggs via RSS.
3.) No caching, which makes our operations team sad pandas. Every page request to a blog, at this point, will result in a request to digg.
April 15th, 2007 at 2:46 am
@Joe
All good points, here are my responses…
1. Regular expressions are significantly faster and safer for scraping sites like this, since they don’t throw a hissy fit if you have invalid XML.
2. I thought of the RSS feed after I had written the scraper… I would have used it if I had thought of it before, and I’ll probably do a rewrite to use it in the future (in which case I’ll use an XML parser to parse it).
3. Caching is good, but there’s no simple & portable way (that I know of) to cache from a WP plugin without some sort of user configuration, and this was just a quick proof of concept. The version I’m using on my site is actually using Memcache. It took about 5 additional lines to add caching with Memcache…
April 15th, 2007 at 2:52 am
[…] first one to come along was Mike’s version in the form of a Wordpress […]
April 15th, 2007 at 3:23 am
“3. Caching is good, but there’s no simple & portable way (that I know of) to cache from a WP plugin ”
fetch_rss has a default cache time of 900 seconds, you cant change that timeout on a per-request basis though.
If WP’s builtin Cache functions are enabled(not by default stupidly enough - for reasons) then you can use that to cache the RSS(or any other data) for a period of time, http://codex.wordpress.org/Function_Reference/WP_Cache
April 15th, 2007 at 4:10 am
Superb.
i will be adding this later today.
Thankyou
April 15th, 2007 at 4:14 am
Hi,
Thanks for the widget. I love those things.
April 15th, 2007 at 9:45 am
[…] cool little widget for adding Digg to your sidebar.read more | digg […]
April 15th, 2007 at 3:43 pm
thanks !
April 16th, 2007 at 12:42 am
Something like this was needed
April 16th, 2007 at 2:12 am
1) Regular expressions are slow, especially compared to just digesting an rss feed.
2) How could you overlook rss when your goal is to aggregate content from another site, and you consider yourself some sort of web developer
3) Caching is polite, easy and necessary with content aggregation. How would you like it if some guy released some half-arsed code that redundantly and repeatedly hit your server over and over again?
April 16th, 2007 at 10:08 am
@Ben:
1. Regular expressions are only slow if you don’t know how to use them. And, as I said in my earlier comment, if I had been parsing an RSS feed I would have used an XML parser.
2. Everyone doesn’t offer RSS feeds. I apologize if my 15 minute proof of concept doesn’t utilize all of the industry’s best practices.
3. If you’re running WP Cache the widget will be cached with the page anyways. Outside of WP Cache there is no easy way to portably cache content for a WP plugin. If someone wants to write a plugin for WP that aggregates content from my site and market it for me I don’t think I’d mind them hitting my server over and over again.
Feel free to write something better if you’re so upset.
April 16th, 2007 at 10:42 am
1) With the XML parser vs regular expressions, I’m sure there’s a highly efficient xml parser in php by now that works better than performing string operations on a 35kb string. Maybe there isn’t though, php isn’t my forte.
2) It’s not a best practice, it’s the method with the lightest load. I’m not sure if curl supports gzip or not but the RSS feeds on digg seem to be ~4kb gzipped, 35kb raw. By comparison the page is 11kb gzipped and 44kb uncompressed. When you’re distributing a blog widgit for one of, if not the most popular blogging platforms on the internet you should keep in mind that kind of significant saving for the host site.
3) You always have a very simple caching option available - write the file to disk. For maximum benefit to the blog you’d do so after processing it. Then all you need to do is check the creation time, if it’s more than x minutes old refetch it and overwrite it.
As far as it just being a proof of concept, I don’t think that removes any (purely ethical) obligations a developer has. It’s just rude to write and distribute a script that hits another site as hard as possible for the sake of saving 5 minutes writing a cleaner version, and it sets a poor example that’s likely to be followed in other plugins.
April 16th, 2007 at 11:12 am
There are several efficient XML parsers, but using an XML parser doesn’t avoid string operations… Although I suppose the RSS feed is smaller.
I’m not disagreeing with your point on RSS. I should have used it, my bad. Re: caching to disk - that’s what I would have done except that the Wordpress installation documents recommend that you chmod all of the non-upload directories to be non-writable. Many people follow these directions, which makes it more difficult to cache to disk. I could have cached to /tmp, but that wouldn’t work on Windows… I figured any reasonably highly trafficked blog would have WP Cache installed, and that would mitigate the problem.
April 16th, 2007 at 12:39 pm
Hi. I wrote a digg widget a couple weeks ago that uses the official digg javascript. You can download it here:
http://www.cjbonline.org/index.php/2007/04/01/dugg-widget/
April 19th, 2007 at 10:56 pm
[…] Digg Widget Filed under: Uncategorized — recar @ 4:56 am Wordpress Digg Widget Ask, and ye shall receive! WP digg widget that let’s you put your friends diggs in your […]
April 20th, 2007 at 8:38 pm
把朋友 digg 的文章显示到你的 Blog…
CoolCode 看来还是有问题, 本来要帖的一段代码都不能显示了。
这个 Digg Friends 的插件很有用的。 Delicious 应该也有类似的插件吧?
……
April 21st, 2007 at 5:39 am
[…] - Wordpress Digg Widget The past 7 days in Programming only saw a few items get hot, and I though the most interesting [or […]
April 22nd, 2007 at 4:44 pm
Thanks man
April 27th, 2007 at 12:03 pm
This shows a lot of promise.
April 30th, 2007 at 8:59 am
[…] couple of weeks ago I wrote a post on the Vino2Vino development blog about a digg widget that displayed your friends’ digg activity on your blog. I wrote the widget in response to a […]
May 16th, 2007 at 3:39 pm
Top wordpress tools of the month…
Wordpress is the phenomenon (yeah I do believe it is one) that made a lot of dreams come true. It created a bridge between people without any kind of programming knowledge and the fact of being live and writing for people. The road is so much shorter f…