Creating a "recent dmBridge comments" block in Drupal

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.

  1. From the main administration menu, click on "Blocks."
  2. Click "Add block."
  3. For the block description, enter "Recent dmBridge comments."
  4. For the block title, enter "Recent object comments" (or whatever you want the public to see).
  5. Enter the following in the block body:

    // Include the dmBridge PHP API
    require_once($_SERVER['DOCUMENT_ROOT'] . '/dm/objects/api.php');

    $collection = dmCollection::instantiate('/hughes');
    foreach (
    $collection->getRecentComments(4) as $c) {
    '<dt>On <a href="' . $c->getObject()->getReferenceURL() . '">'
    . htmlspecialchars($c->getObject()->getField('title'))
    '<dd>' . htmlspecialchars(dmString::truncate($c->getText(), 10)) . '</dd>';

  6. Set the input format to "PHP code."

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.