Chip's Tips for Developers

Contains coding, but not narcotic.

OPML Browser for WordPress gets a new parser

August 24th, 2009 3:36:49 pm pst by Sterling Camden

I thought of a new use for my OPML Browser plugin, but the OPML file I intended to use with it threw me a couple of curve balls.

First of all, the file contained nested outline elements, with xmlURL attributes on the containing elements.  Until now, I displayed the feed icon if an item had a feed, and only displayed the folder icon if it didn’t (and it had child elements).  Because the only way to expand/collapse the tree is by clicking on the folder icon, I’ve changed this to display both icons in that case.

Second, my file nests the outline tags more than two levels deep.  I was using preg_match to parse the XML, with a non-greedy search for the end tag.  Can you guess what the problem was with that approach?  I’d get the end tag for an internal outline item when I was looking for the end of the outer item.  This only happened, of course, when an inner item was terminated by </outline>.

Rather than trying to get even fancier with my regular expressions, I decided to implement a real XML parser instead.  I took a look at SimpleXML, but it requires PHP5 and allow_fopen_url.  Then I looked at PHP’s built-in XML parser functions, but that’s event-based and I needed to wade through the document on my own terms.  So I implemented my own simple XML DOM parser, and included that with the plugin.

Posted in OPML, PHP, WordPress | No Comments » RSS 2.0 | Sphere it!

OPML Browser 2.0 for WordPress

May 11th, 2009 4:38:37 pm pst by Sterling Camden

Yes, this is such a major upgrade to my OPML Browser plugin for WordPress that it warrants bumping the initial digit in the version number.  Here’s what changed:

  1. The plugin now expects to be installed in its own folder: (siteurl)/wp-content/plugins/opml-browser
  2. JavaScript and CSS have been separated into their own files.
  3. JavaScript events are now hooked on window load instead of in the HTML.
  4. Added “alt” attribute to all “img” tags.
  5. Images are now looked for in (siteurl)/wp-content/plugins/opml-browser/images
  6. If an image cannot be found, it will be replaced by the supplied unknown.png (a question mark).
  7. Added “Sort items?” option.  This sorts within categories, unless the “flatten” option is enabled (see next item).
  8. Added the “Flatten hierarchy?” option.  This combines all items into one level.  If sorting, all items get sorted together.
  9. The OPML description attribute is now displayed as a tooltip (as in the OPML Blogroll widget, but it also works in IE and Opera now!).

As far as I know, the OPML Browser can now do everything that the OPML Blogroll widget could do (items 7 through 9 filled that out), so I am herewith declaring the OPML Blogroll widget retired from further upgrades.  Please use this plugin’s widget instead from now on.  Let me know if I’ve forgotten any functionality that you need.

A big “thank you” to all of my users who requested various features and reported bugs.  This plugin would not be what it is today without your input. 

Posted in AJAX, ATOM, CSS, JavaScript, OPML, PHP, RSS, WordPress | 1 Comment » RSS 2.0 | Sphere it!

More OPML Browser corrections

September 26th, 2007 1:19:04 pm pst by Sterling Camden

Shack Dougall spotted several HTML coding errors in the latest verion of my OPML Browser plugin.  Get the version 1.3 below.

Pingbacks to previous posts.

Posted in OPML, PHP, Web, WordPress | 25 Comments » RSS 2.0 | Sphere it!

OPML browsing just got better

September 22nd, 2007 1:21:03 pm pst by Sterling Camden

Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/camden/public_html/chipstips/wp-content/plugins/opml-browser/opml-browser.php on line 220

 Version 1.2 of the OPML Browser plugin for WordPress has just been released!  This version includes some significant upgrades, including:

  1. You may now have up to 9 opml-browser widgets. When upgrading, the options from your existing opml-browser widget are copied to the first opml-browser widget.  Thanks to Mark Barnes for suggesting this enhancement.
  2. The option to exclude your domain now ignores differences in case when comparing domain names.  Thanks to Tony Lindskog for finding that one.
  3. You can now override the title for the OPML link by entering text into the “OPML title override” field.  I didn’t want mine to read “FeedDemon Subscriptions”, so I added that for myself.
  4. Added the ability to embed the browser within a page or post using a special

    Could not open OPML URL

    element in the text.  See the readme.
  5. Added a “Get this widget” link at the bottom of the widget.  Thanks to TDavid for suggesting that little bit of self-promotion.

Download version 1.2 via the button below.  Pinging back to all previous posts for those following comments.

UPDATE: More corrections here.

Posted in JavaScript, OPML, PHP, Web, Wildly popular, WordPress | 22 Comments » RSS 2.0 | Sphere it!

OPML Browser with class

March 30th, 2007 3:52:28 pm pst by Sterling Camden

Well, the OPML Browser plugin for WordPress has only been released for two days and already we’re up to version 1.1. Hopefully this one will last a while longer.

I added a new feature: start with all folders closed. Selecting this option will display the browser with all categories collapsed initially, unless the browser doesn’t support Javascript (otherwise the user wouldn’t be able to open them!).

I also completely reworked the code, using a class for the rendering engine. That allowed me to eliminate all global variables (almost always a good thing) and reduce the number of parameters being passed around. I still say PHP’s object syntax sucks, but it’s a good bit better than what I had before.

I even added some comments.

Let me know how you like it.

UPDATE: Get the latest version here.

Posted in JavaScript, OPML, PHP, RSS, Web, Wildly popular, WordPress | 16 Comments » RSS 2.0 | Sphere it!

New OPML browser plugin for WordPress

March 28th, 2007 4:39:54 pm pst by Sterling Camden

Since I first released the OPML Blogroll widget, I’ve received numerous suggestions for enhancements. One that keeps coming up is the ability to show the hierarchy within the OPML file — categories, if you will.

Because of the way the original widget parses and displays the outline, this request was incompatible with the existing code. So I developed a new widget/plugin that does keep the hierarchy intact, and you can download it below. It also uses javascript to expand/collapse categories when the associated folder icon is clicked.

The code also includes an API for displaying an OPML browser within PHP code, so you don’t have to use the widget if your theme is not widget-compatible, or you want to display the browser somewhere else.

See the opml-browser-readme.txt file included in the download for full documentation and tips on how you can control the display through CSS styling to achieve some of the other suggested enhancements — such as scrolling within a limited height, bolding the categories, and removing the ability to expand/collapse categories.

There’s still one thing I haven’t figured out how to do, though. If the text of an item wraps, it wraps beneath the feed icon to the left. I’d like to be able to make it line up with the first line of text, but I’m not enough of a CSS wizard to manage that yet. Any suggestions?

UPDATE: Corrected a missing end-quote error in the autodiscovery link at 14:02 3-29-07

UPDATE: Get the latest version here.

Posted in JavaScript, OPML, PHP, RSS, Web, Wildly popular, WordPress | 15 Comments » RSS 2.0 | Sphere it!

Better Tag Cloud