Drupal

The new Drupal profile/social networking module that Dries Buytaert has been working on is now active at Drupal.org. Members enter information about such things as location, interests, etc. and those descriptions are used to display people with shared interests. The module allows administrators to configure the profile fields and use controlled vocabularies for fields. It's a very nice first crack. So maybe it won't be too hard to start up your own social networking site in a few months when this thing gets more solid. Why not, right? SNSs are a dime a dozen now. If people get interested in contributing code to this open source tool, it can only get better.

To view how this works, view users who describe themselves as residing in the U.S. or who describe themselves as male. The module will also show avatars or pictures if your system is configured to allow them. Very nice. I hope to install this on iaslash when the next release is stable.

Awesome. Drupal contributor Matthias has created an ecommerce module for Drupal. Just goes to show that Drupal, though perhaps not for the novice web user, is truly an open source platform for many applications. It's not simply a content management or weblog publishing system. Sure, the contributed modules don't undergo rigorous testing and heavy design scrutiny, so your ease-of-use mileage may vary. But, since it's open source, you can tweak and improve the modules to your liking. Check the demo here. The code is up for grabs for the upcoming 4.4 release. While I haven't been that tuned into the drupal-dev list in recent months -- I'm more of a Drupal user than heavy contributor lately -- I have heard word of some cool things for the next release. Drupal developers rock. I anxiously await 4.4.

Theme modification to produce better "Read more" output in stripped/excerpted node display.

On the drupal.org forum, someone posted a question about getting simple node list displays instead of full node entry displays. I responded by showing how I'm doing this on familytravelog. Here's what I said:

If you want to show node entries as simple lists with partial field displays, e.g. title, author, rather than displaying the entire blog entry, you can try what I've done. Look at the display of nodes on taxonomy pages on one of my familytravelog blog and come back here -- search for "function node". I did this by modifying the theme's node function (a lot). I'm basically checking if Drupal is serving a $main page -- e.g. main blog pages, taxonomy pages vs. individual node pages -- and giving a stripped down display using list tags for that, or else give them the full-blown node display. My node display on that theme includes more complex displays for my "review" type node.

Basically this involved changing function node like this:

// index pages vs. others
  if ($main) {

    echo "<ul><li><b><a href=\"/node/view/$node->nid\">$node->title</a></b><br />";
    print
    t("%a", array("%a" => format_date($node->created, "short"))) ."</a>";
    print " in $node->type entries</li></ul><br />";

// not index pages  
  } else {
    // normal node code goes here
  }

View the source for my theme file here.

I don't if there is something wrong with this method, but it works for me. Why muck around with the core modules when you can just hack the theme?

At various times in the past I've wanted to change Drupal's node display sort order to be n.title ASC rather than created DESC. On the blog I'm testing, I want to modify my weblink display so that category listings show nodes by title in ascending alphabetical order. See this page for example. The nodes are displayed in a-z order rather than in reverse chron by creation date. To do this, I modified function taxonomy_select_nodes as shown below. I can now modify my function call to include a sort field and sort order argument, e.g.

taxonomy_render_nodes(taxonomy_select_nodes($taxonomy, '1', 'n.title', 'ASC'));

I have no idea what "ORDER BY static DESC" refers to in the function. What is the "static" field?

So I'm wondering. Is this a good way to accomplish what I want? I don't know, but it seems to work. I wonder if this is inelegant and can be improved? Is it costly to the system? And finally, if this works, can it be applied to CVS?

Modified taxonomy.module function:

function taxonomy_select_nodes($taxonomy, $pager = 1, $sort_fld = NULL, $sort_dir = NULL) {
  global $user;
 
  if ($sort_fld == NULL) { $sort_fld = 'created'; }
  if ($sort_fld == NULL) { $sort_dir = 'DESC'; }

  if ($taxonomy->str_tids) {
    if ($taxonomy->operator == "or") {
      $sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.created, n.changed, n.uid, n.static, n.created, u.name FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' ORDER BY static DESC, $sort_fld $sort_dir";
      $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1'";
    }
    else {
      $sql = "SELECT n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name HAVING COUNT(n.nid) = ". count($taxonomy->tids) ." ORDER BY static DESC, $sort_fld $sort_dir";

      // Special trick as we could not find anything better:
      $count = db_num_rows(db_query("SELECT n.nid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid HAVING COUNT(n.nid) = ". count($taxonomy->tids)));
      $sql_count = "SELECT $count";
    }

    if ($pager) {
      $result = pager_query($sql, variable_get("default_nodes_main", 10) , 0, $sql_count);
    }
    else {
      $result = db_query_range($sql, 0, 15);
    }
  }

  return $result;
}

I'm finally getting around to learning how to code Drupal modules. Well, maybe I should say how to more effectively hack Drupal modules. I've spent the last few weeks working on familytravelog, a new weblog I'm going to be publishing soon on family travel resources. I think I started this project mainly to learn how Drupal modules work, but I'm actually into the idea of doing a different kind of blog now.


[screenshot of familytravelog.com]

I've been deconstructing the page module to learn how to add a new node type to my blog, review.module. I'm using this module to create forms that input the fields used to generate reviews of resorts. See this first review to get an idea of what I'm trying to do. I have the basic review table functioning (inserting/updating, etc.) with the review.module. The next steps for me are to figure out how to generate a query of reviews based on the ratings fields I'm using -- the rating_overall and rating_overall fields are used to generate the stars. What I'd like there is the ability to click on the stars to view other reviews with an equal number of stars. Then I'd like to be able to sort from high to low -- values are 0 to 5. Am sure this won't be difficult.

I also hacked the article.module code to produce my article_browser.module and weblink_browser.module. I found this module to present results by taxonomy a little more to my liking than taxonomy_html or _dhtml. Would be nice if someone came up with a module that functions like facetmap some day. Maybe I will take that on if I have the chops.

Overall, the experience of figuring out how to create a simple node module was really quite painless for me. I have enough know how of PHP to figure out how things work (esp. functions that are in libraries elsewhere), but for someone afraid to figure out this system, I can see how it might be daunting. If you want a lot of control over every little detail that Drupal puts out, the learning curve might seem steep at first. It is still to a great extent, a developer's platform, rather than a naive blogger's platform, unless as a naive blogger you are happy with just publishing your site as Drupal wants to out of the box. Much of Drupal still needs to be better documented in digestable format. I found it easier to just trace the path lback through functions to figure out how one function is called by another rather than finding it in the documents. For instance, not all the form_ functions are documented, so I had to look inside one of the included libraries to figure out what the parameters are for form_select. But if you have the patience to do all of this, I think it's worth it. In the end, I think it will be much easier for me to produce this new site with Drupal than to use some other package or to code it myself -- ugh, I shudder at the thought of that. The possibilities for my sites just seemed to grow immensely in these few weeks.

Scot Hacker's blog about the increasing amount of time it takes to rebuild his site, which has a large number of entries, points to scalability limitations using a system that builds static pages when compared to a server-side scripted system that builds pages as requested and then caches them. This, I guess, is one of the reasons I prefer PHP/MySQL apps like Drupal for a site that is meant to grow big (most blogs certainly fit that description) and prefer to only consider MT for smaller, brochure-ware type sites (AIfIA fits that description).

I'm wondering if SixApart is considering a solution -- especially for enterprise customers that might come looking -- that uses server side scripting to generate pages along this model rather than building static pages. I can imagine, with their Perl focus, that they would easily be able to modify MT use CGIs that generate and cache entries from the Berkeley DB or MySQL on the fly. Perhaps this is where SixApart will be going with MT Pro. Clearly there is a need for a version of MovableType that will let advanced users gain some advantage in terms of speediness.

UPDATE: Drupal modules and themes are now listed in a notebook page here: http://urlgreyhot.com/drupal/book/view/474

I offer these files for people to deconstruct my installation of Drupal. My theme uses a PHP script and css files to skin the site rather than relying on the built-in Drupal method for swithching themes, which requires you to register. I also use a very rudimentary custom module to do the home page. This is for people who've been asking me to show how this site's themes are set up. I don't think I'll ever get to a full-blown tutorial. Time just won't allow it.

Please, do NOT copy my graphic files and re-use my color scheme. My files are available so you can figure out how to get Drupal to work. I don't think it's cool to just rip my theme without making modifications to the CSS until it looks different -- your own. Be creative. You don't want to just clone this design. If you do, I will likely find it and mock you in public. ;)

A couple of people have been asking how I've done some things on this site, so I'm hoping to describe how this site is put together. People have mainly asked about how I do the home page and how I've integrated my site skinner with Drupal's themes. So I'm hoping with the next release to start a series of short tutorials explaining how I've made my Drupal site work. I'm excited about the idea of doing that, because I recently created my first baby module and am hoping to learn more about Drupal's functions so I can start creating modules that work with Marco's excellent taxonomy module. Those tutorials may come later. To start off with, I'll probably talk a little about my first experience creating a module. More to come...

Wow. Drupal has somehow been getting more people's attention in the past year. Four IAs I know are now using Drupal and the list of Drupal sites seems to have grown exponentially in one year. The benefit to the Drupal community is hopefully that more users will mean more requests for usability enhancements/evolution.