FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Architecture & Design
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
January 03, 2006
Netnews Hooked on Drupal

Summer of Code -- Jan Blom.

Name: Jan Blom

Contact: jan.j.blom@gmail.com

School: Dutch Open University

Major: Computer Science

Project: Drupal Netnews Module

Project Page: http://sourceforge.net/projects/drupal-netnews/

Mentor: Karoly Negyesi

Mentoring Organization: Drupal (http://drupal.org/)

My proposal for the Summer of Code was about the integration of netnews with the Drupal open-source content management platform (http://drupal.org/). Messages entered in the netnews group linked to the forum should appear in the forum, and vice versa.

Every piece of independent information in Drupal is stored as a node. Whatever the ultimate type of information--a message, a blog entry, a recipe--all types are derived from the node type. That sounds very object oriented and it is. Yet Drupal does not really use the OO facilities that PHP has to offer (see http://drupaldocs.org/api/head/file/contributions/docs/developer/topics/oop.html). As a web application, Drupal runs whenever a page request is made by users. A page request loads its core code and all modules that have been configured for the site. Whenever a node is added, updated, or accessed, Drupal ensures that certain functions are called in every module that implements them. This allows any module to attach functionality to any node type. A good example of this is the forum module. The core functionality, reading and storing node content, is performed by the module node. The forum module adds the functionality to the node that makes a node appear as a forum topic; it implements the forum node type. It does so by implementing predefined hook functions.

There is a secondary information type--the comment type. It can be attached to any node type.

The naming scheme for the hook functions is straightforward--a unique module name with a standard suffix, such as _nodapi, for functionality that should be called when a node is accessed.

For my netnews module, those hooks had to be implemented to allow netnews to act on two specific sets of events given a defined relationship between a forum and a newsgroup:

    * A new topic or comment in the forum.

    * A new post or reply in the newsgroup.

For new entries in the forum, I implemented two hooks--netnews_nodeapi() for new topics and netnews_comment() for new comments. These hooks are triggered by Drupal whenever a topic or comment is added.

For new entries in the newsgroup, I implemented the netnews_exit() and netnews_cron() hooks. The first one runs after completion of every page request, the latter runs at scheduled intervals. With these hooks, synchronization from the forum to the newsgroup happens instantaneously upon message entry, synchronization from the newsgroup to the forum is triggered on user interaction with the forum (after page generation) and at regular intervals to ensure that the number of messages waiting to be read into the forum does not spiral out of control.

Netnews does not implement a new node type, it extends the functionality of the forum and comment types. In addition, the netnews module implements the hooks netnews_menu(), netnews_help(), netnews_perm(), and netnews_admin(), through which the site administrator can configure relationships between forums and newsgroups. The functionality of these hooks is invisible to normal users of the forum.

RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK