Wordpress Digg Widget

April 14th, 2007 by mike

I 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.

 

26 Responses to “Wordpress Digg Widget”

  1. Eric Odom » New Wordpress Plugin: Digg Widget Says:

    […] 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. […]

  2. Eric Says:

    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

  3. mike Says:

    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

  4. Dave Says:

    Here is a flash version: (might not work on hosted wordpress account) http://www.lemieuxster.com/digg/scroller/

  5. Amazon Secret Shopping Says:

    Thanks !! Looking for this …..

  6. Joe Stump Says:

    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.

  7. mike Says:

    @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…

  8. Eric Odom » Ask and ye shall receive Says:

    […] first one to come along was Mike’s version in the form of a Wordpress […]

  9. DD32 Says:

    “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

  10. Earl Grey Says:

    Superb.
    i will be adding this later today.
    Thankyou

  11. writer4webw Says:

    Hi,
    Thanks for the widget. I love those things.

  12. Wordpress Digg Widget » Blog Marketing Videos And Social Marketing Tips To Get Free Targeted Traffic Says:

    […] cool little widget for adding Digg to your sidebar.read more | digg […]

  13. psychic readings Says:

    thanks !

  14. MomLinker Says:

    Something like this was needed

  15. Ben Says:

    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?

  16. mike Says:

    @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.

  17. Ben Says:

    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.

  18. mike Says:

    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.

  19. Cj B Says:

    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/

  20. Wordpress Digg Widget « News Coctail Says:

    […] 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 […]

  21. 和谐,自由 Says:

    把朋友 digg 的文章显示到你的 Blog…

    CoolCode 看来还是有问题, 本来要帖的一段代码都不能显示了。
    这个 Digg Friends 的插件很有用的。 Delicious 应该也有类似的插件吧?

    ……

  22. Devlounge | Friday Focus #27 Says:

    […] - Wordpress Digg Widget The past 7 days in Programming only saw a few items get hot, and I though the most interesting [or […]

  23. Yuzle! Says:

    Thanks man

  24. Motorcycle Guy Says:

    This shows a lot of promise.

  25. I’m Mike » Blog Archive » Digg Widget 2.0 Says:

    […] 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 […]

  26. Javascript, PHP, CGI, Perl, ASP, Vbscript, Ajax articles, resources and programming tutorials Says:

    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…

Leave a Reply