The image.module does not use any filters to display the node's body, which deprecates the use of the weblink,module somewhat.

I patched two functions in the image.module file to remedy this. For this to work the default format must allow the Only local images are allowed. tag.

function image_view(&$node, $main = 0, $page = 0) {
  $rand = "";

  // If random suffix is enabled or we have a new image add random suffix.
  if (variable_get("image_random_suffix", "0") || $node->image_id) {
    $rand = rand();
  }
  node_image_content($node, $rand, $main, $page);
  // added to run through filters
  node_prepare($node);
}

and

function node_image_content(&$node, $rand, $main = 0, $page = 0) {
  global $base_url;

  if ($main) {
    // check if the thumbnail file exists, and create it if it doesn't
    if (!file_exists($node->thumb_path)) {
      _image_make_thumbnail($node->image_path, $node->thumb_path);
    }
    if($rand) {
      $node->teaser = "<img class=\"thumb\" src=\"$base_url/$node->thumb_path?".$rand."\" />" . $node->teaser;
    }
    else {
      $node->teaser = "<img class=\"thumb\" src=\"$base_url/$node->thumb_path\" />" . $node->teaser;
    }
    // filter the teaser
    node_prepare($node,true);
  }
.
.
.

Comments

jhm’s picture

I just posted this a little prematurely and it stripped out some important information. Here is a paragraph with the missing piece:

I patched two functions in the image.module file to remedy this. For this to work the default format must allow the <img> tag, or the actual image provided by the image.module will be filtered out.

slower’s picture

This doesn't seem to work for me. I have both the glossary and contentlinks modules which should apply to a couple of my image descriptions, but neither are being filtered in. I don't think I fully understand when/where/how the filters apply -- for instance, why isn't there a "filter_form" function beneath the Description textarea? If it's missing, does only the default filter apply in those cases? Anyway, node_prepare isn't doing the trick -- any suggestions?

basicmagic.net’s picture

Title: image module does not use any filters » fix image module to allow for filters in descriptions and teasers

hello all-

i am running drupal 4.5.2 with image.module 1.138.

made the following two fixes to image.module (#1 and #2 at bottom)-
and now i have at least the weblink and inline filters working great in all of the teasers / descriptions for images.

please note that the two hacks account for getting input filters to be processed correctly-
in both the image taxonomy / term generated views like:

http://www.ralphdeluca.com/taxonomy/term/12

and also in any of the image module / node generated views like:

http://www.ralphdeluca.com/node/12
http://www.ralphdeluca.com/12?res=640x480
http://www.ralphdeluca.com/node/12?res=800x600

finally- i had to make the following settings in input formats (#3 at bottom).

next up is i am hacking the web link module- with a similar issue- that in the weblink teasers and descriptions (module view) the filters are not working- although they are working in the taxonomy views.

if anybody has any insight or comments on what i am doing right or wrong here... please advise and comment.

i am just a hacker- trying to get something to work like i need / want it to...

#1 find this original code in image.module:

/**
 * Display the image node
 */
function image_view_og(&$node, $main = 0, $page = 0) {
  $rand = "";

  // If random suffix is enabled or we have a new image add random suffix.
  if (variable_get("image_random_suffix", "0") || $node->image_id) {
    $rand = rand();
  }
  node_image_content($node, $rand, $main, $page);
}

change to:

/**
 * Display the image node
 */
function image_view(&$node, $main = 0, $page = 0) {
  $rand = "";

  // If random suffix is enabled or we have a new image add random suffix.
  if (variable_get("image_random_suffix", "0") || $node->image_id) {
    $rand = rand();
  }    
  node_image_content($node, $rand, $main, $page);

// added to run through filters
$node = node_prepare($node,true);

}

#2 find this original code in image.module:

/**
 * Theme function to render image node.
 */
function node_image_content_og(&$node, $rand, $main = 0, $page = 0) {
  global $base_url;

  if ($main) {
    // check if the thumbnail file exists, and create it if it doesn't
    if (!file_exists($node->thumb_path)) {
      _image_make_thumbnail($node->image_path, $node->thumb_path);
    }
    if($rand) {
      $node->teaser = "<img class=\"thumb\" src=\"$base_url/$node->thumb_path?".$rand."\" />" . $node->teaser;
    }
    else {
      $node->teaser = "<img class=\"thumb\" src=\"$base_url/$node->thumb_path\" />" . $node->teaser;
    }
  }
  else {
    if ($_GET["res"]) {
      $res = $_GET["res"];
      if ($res != "original") {
        $valid_res = explode(",", variable_get("image_default_resolutions", "640x480,800x600,1024x768,1600x1200"));
        if (!in_array($res, $valid_res)) {
          $res = variable_get("image_default_resolution", "640x480");
        }
      }
    }
    else {
      $res = variable_get("image_default_resolution", "640x480");
    }
    if ($res == "original") {
      $fname = $node->image_path;
    }
    else {
      // check if the file exists, and create it if it doesnt
      if (!file_exists($node->image_list[$res]["fname"])) {
        unset($node->image_list[$res]);
      }
      // if this image has not been created then create image.
      if (!$node->image_list[$res]) {
        $fname = _image_make_static($node, $res);
        if ($fname) {
          $node->image_list[$res]["fname"] = $fname;
          if (!$_GET["op"]) {
            // we are just displaying the node so we need to save the new
            // resolution
            $node->image_list[$res]["fname"] = _image_add_static($node, $res);
          }
        }
        else {
          $res = array_keys($node->image_list);
          $res = $res[0];
        }
      }

      $fname = $node->image_list[$res][fname];
    }
    if($rand) {
      $node->body = "<img class=\"image\" src=\"$base_url/$fname?".$rand."\" />". $node->body;
    }
    else {
      $node->body = "<img class=\"image\" src=\"$base_url/$fname\" />". $node->body;
    }
  }
}

change to:

/**
 * Theme function to render image node.
 */
function node_image_content(&$node, $rand, $main = 0, $page = 0) {
  global $base_url;

  if ($main) {
    // check if the thumbnail file exists, and create it if it doesn't
    if (!file_exists($node->thumb_path)) {
      _image_make_thumbnail($node->image_path, $node->thumb_path);
    }
    
    if($rand) {
      $node->teaser = "<img class=\"thumb\" src=\"$base_url/$node->thumb_path?".$rand."\" />" . $node->teaser;

    }
    
    else {
      $node->teaser = "<img class=\"thumb\" src=\"$base_url/$node->thumb_path\" />" . $node->teaser;

    }

// added to run through filters
$node->teaser = check_output($node->teaser);
    
  }
  else {
    if ($_GET["res"]) {
      $res = $_GET["res"];
      if ($res != "original") {
        $valid_res = explode(",", variable_get("image_default_resolutions", "640x480,800x600,1024x768,1600x1200"));
        if (!in_array($res, $valid_res)) {
          $res = variable_get("image_default_resolution", "640x480");
        }
      }
    }
    else {
      $res = variable_get("image_default_resolution", "640x480");
    }
    if ($res == "original") {
      $fname = $node->image_path;
    }
    else {
      // check if the file exists, and create it if it doesnt
      if (!file_exists($node->image_list[$res]["fname"])) {
        unset($node->image_list[$res]);
      }
      // if this image has not been created then create image.
      if (!$node->image_list[$res]) {
        $fname = _image_make_static($node, $res);
        if ($fname) {
          $node->image_list[$res]["fname"] = $fname;
          if (!$_GET["op"]) {
            // we are just displaying the node so we need to save the new
            // resolution
            $node->image_list[$res]["fname"] = _image_add_static($node, $res);
          }
        }
        else {
          $res = array_keys($node->image_list);
          $res = $res[0];
        }
      }

      $fname = $node->image_list[$res][fname];
    }
    if($rand) {
      $node->body = "<img class=\"image\" src=\"$base_url/$fname?".$rand."\" />". $node->body;

    }
    
    
else {

$node->body = "<img class=\"image\" src=\"$base_url/$fname\" />". $node->body;

// added to run through filters
$node->body = check_output($node->body);


    }
  }
}

#3 input format settings- (set filtered html as default)

1. default filtered html:

- filter html tags (strip tags)
- add the follwing tags to the allowed html tags:

<br><p><img><class><src>

- html style attributes allowed

- arrange filter order and weights like this:

line break conv -10
inline -9
weblink -8
html 0

2. php:
- arrange filter order and weights like this:

inline -10
weblink -9
php 0

3. full html:
- arrange filter order and weights like this:

line break conv -10
inline -9
weblink -8

walkah’s picture

Component: Code » gd toolkit
Status: Needs review » Closed (won't fix)