Drupal Code Snipits

hook_filter() and Finding Context in D6

Drupal's filter system is a pretty nifty thing- you can grab text coming through the system and modify it to your hearts content. This makes for great things like replacing various kinds of tokens, automatically making URLs link, and so on. I've been looking at the wordfilter module to check for "bad words" coming through the text.

One of the things that this module lacks is logging of the users who are using "bad words". Being able to track usage by user creates the possibility of creating specific kinds of actions around the user- settings various flags, demoting permissions, alerting admin, etc.

Formalize the Media Mover hook

I've been working over the weekend to finish up the media mover hook system. I think I've finally finished out the final form of the hook and the different options that are available. Here's a commented version of what I'm using in the media_mover.inc file

/**
 * Implementation of media_mover hook
 */
function media_mover_media_mover($op, $action = null, $config = null, &$file = array() ) {

  switch ($op) {

    // give your driver a name
    case 'name':
      return "Media Mover module";
    break;

    // create a new configuration option set
Sorry, you need to install flash to see this content.

Media Mover prelim announcement

update 12/9/06:

I've done quite a bit of working pulling together and administrative system. It's by no means polished, but the database is storing each set of configurations (for harvest, process, and storage) and can pull each of these out for each run of of the configuration. This means that it's possible to have multiple runs of say a video conversion with different conversion rates.

The media_mover hook is almost stable at this point, the major piece left is the "save" function which keeps track of how files were moved around and created.

----

Sorry, you need to install flash to see this content.

Search Highlight Module

Just put together a Drupal (4.7) module that highlights search term results in nodes. From the readme file:

This module creates a link on search results pages and if highlighting is enabled for the field (check your input types), it will search and replace the search term in that field with an admin defined string

1) activate "search_highlight" module in admin > modules
2) add the filter to input formats admin > input formats
3) customize highlighting admin > settings > search_highlight (optional)

Sorry, you need to install flash to see this content.

Autotaxonomy module

I just whipped up a quick module to do deployments of taxonomies based on years and months. It runs off cron, so it will automatically make the terms become available as time progresses. Admins can choose what vocabulary the module will add terms to. By default it will generate something like:


2006
-- October 2006
-- September 2006
-- August 2006

You can download autotaxonomy here

swfObject module for drupal

updated: Please see the drupal project: http://drupal.org/project/swfobject_api for updates
updated: swfmodule to more recent version
I created a way to use the swfobject library in drupal. This allows a developer to make a call like:

print swfobject_create($url, $params);

To display a swf file. Url is the web accessible address to the file. Params are the flash parameters- not needed, but if they aren't set, height and width are set to 100%

Updated September 1, 2006

Upcoming Events Module

I wrote this module to display a listing of events that are upcoming, largely because the drupal calendar page never really seems to work for anyone, so it seems like it was high time to make it a module.

REQUIRES
* events module
* phptemplate

INSTALL
* place in modules directory
* place event_upcoming.tpl.php in theme directory
* admin > modules, turn on event_upcoming module
* admin > settings > event_upcoming, set number of events to display

USE
* navigate to event_upcoming to see list of upcoming events

Custom Filter

I wanted to be able to give users the ability to create a custom filter of various taxonomy data on the fly. I know that there are modules out there that sort of do this, however, nothing quite met my needs.

So this is two parts:

1) a function that returns lists of the terms under a vocabulary (you can feed it more than one vocabulary) with check boxes that a user can check off for what terms they want to display (in an "and" capacity)

2) a javascript function that checks the form that the above code produces and redirects the user to the page

    

Img_assist and JavaScript Popups

Ah the age old problem of having popup windows on your thumbnails. I figured out a good way to do this with some modifications of the img_assist plugin.

Change line 813:
$img_template = t($img_template, array('%caption' => $vars['caption'], '%node-link' => url("node/$image->nid"), '%img-link' => $image->filepath, '%alt' => check_plain($vars['alt']), '%width' => $width, '%height' => $height, '%src' => $src, '%image-class' => $class));

Syndicate content