Title Filtering based on node format

te-brian - August 19, 2009 - 19:54
Project:Wordfilter
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:jaydub
Status:active
Description

Wordfilter was working great for us in terms of node content, but one issue that cropped up was that we wanted to filter the titles of some nodes and not others. In our context, the criteria was whether or not the node body used a format that included the wordfilter filter. We're using Better Input Formats to help control the formatting of a few specific node types, and since wordfilter is a filter, it behaved just fine for the body.

Here is the change that I made to fix our specific issue. This approach may not be generic enough to fit every user case and so I offer this mostly to start the conversation of how, or even if, to conditionally filter node titles based on node format decisions.

function wordfilter_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
      if (variable_get('wordfilter_node_title', TRUE)) {
        if (db_result(db_query("SELECT fid FROM {filters} WHERE module = 'wordfilter' AND delta = 0 AND format = '%s'", $node->format))) {
          $node->title = wordfilter_filter_process($node->title);
        }
      }
      break;
    case 'load':
      if (variable_get('wordfilter_node_title', TRUE)) {
        if (db_result(db_query("SELECT fid FROM {filters} WHERE module = 'wordfilter' AND delta = 0 AND format = '%s'", $node->format))) {
          $node->title = wordfilter_filter_process($node->title);
        }
      }
      break;

#1

te-brian - August 19, 2009 - 19:58

Quick edit: Mixed up the type of `format` in my SQL

function wordfilter_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
      if (variable_get('wordfilter_node_title', TRUE)) {
        if (db_result(db_query("SELECT fid FROM {filters} WHERE module = 'wordfilter' AND delta = 0 AND format = %d", $node->format))) {
          $node->title = wordfilter_filter_process($node->title);
        }
      }
      break;
    case 'load':
      if (variable_get('wordfilter_node_title', TRUE)) {
        if (db_result(db_query("SELECT fid FROM {filters} WHERE module = 'wordfilter' AND delta = 0 AND format = %d", $node->format))) {
          $node->title = wordfilter_filter_process($node->title);
        }
      }
      break;

#2

jaydub - August 28, 2009 - 17:50
Assigned to:Anonymous» jaydub

looks like a good idea. I think I'll look into just setting this as a variable rather than doing a query every time.

 
 

Drupal is a registered trademark of Dries Buytaert.