Creating a "recent dmBridge comments" block in Drupal

Submitted by user1 on March 10, 2010 - 2:39pm

The dmBridge PHP API includes a lot of methods for accessing your social data, and it mates effortlessly with other PHP applications, including Drupal. If you have Drupal's PHP filter module enabled, creating a "recent dmBridge comments" block is easy and does not require any modification of the Drupal files.

From the main administration menu, click on "Blocks."

Click "Add block."

For the block description, enter "Recent dmBridge comments."

For the block title, enter "Recent object comments" (or whatever you want the public to see).

In the first line of code, we include the PHP API by passing its path to include_once().

From there, we create a <dl> (definition list) element. <dl> is an often-overlooked element that is useful for presenting information in "term-definition" format. You could easily change this to a <ul>, <table>, or whatever.

We instantiate a new dmCollection object representing our "Welcome Home, Howard!" digital collection. You'll need to change the alias to that of one of your own collections.

We then call the getRecentComments() method of our dmCollection, which accepts a parameter of a number of comments to retrieve. It returns an indexed array of dmComment objects. Since this is just a block, we keep the number of returned comments low.

Within the foreach loop, we iterate over all four dmComment objects, using their getters to build HTML tags. Any output gets wrapped inside the htmlspecialchars() function, whcih is standard prevention against XSS.

This is a basic example that should be enough to get you rolling. This method of creating blocks will work for any kind of information you can get from the dmBridge PHP API.