modules section of administration to turn on image.module.', array('%modules' => url('admin/modules')))); } $output = ''; switch ($section) { case 'admin/help#image_filter': $output = t('

Sometimes, you want to add an image to another node like a blog entry or a story. You may do this by creating an image node in Drupal for the target image, and then referencing that image in your story, blog, etc. To enable this feature and learn the proper syntax, visit the filters configuration screen.

', array('%filters' => url('admin/filters'))); break; case 'admin/modules#description': $output = t("Allow users to reference images from other nodes."); break; case 'filter#short-tip': return t('You may link to images on this site using a special syntax', array('%explanation-url' => url('filter/tips', NULL, 'image'))); case 'filter#long-tip': return t('

You may quickly link to image nodes using a special syntax. The image code(s) will be replaced by thumbnail linked to full size image node. Syntax: [image:node_id (left|right|top|middle|bottom|absmiddle|texttop|baseline) hspace=n vspace=n border=n width=n height=n]. Every parameter except node_id is optional.

'); } return $output; } /** * Hook which handles filtering. */ function image_filter_filter($op, $delta = 0, $format = -1, $text = '') { switch ($op) { case 'list': return array(0 => t('Image filter')); case 'description': return t('Allow users to reference images from other nodes.'); case 'process': return image_filter_process($text); default: return $text; } } /** * */ function image_filter_filter_tips($delta = 0, $format = -1, $long = false) { if ($long) { return t('

You may quickly link to image nodes using a special syntax. The image code(s) will be replaced by thumbnail linked to full size image node. Syntax: [image:node_id (left|right|top|middle|bottom|absmiddle|texttop|baseline) hspace=n vspace=n border=n width=n height=n]. Every parameter except node_id is optional.

'); } else { return t('You may link to images on this site using a special syntax', array('%explanation-url' => url('filter/tips', NULL, 'image'))); } } /** * Actually execute filter on given text. */ function image_filter_process($text) { if (preg_match_all('/\[image:(\d+)\w?(.*?)?\]/i', $text, $match)) { // Then we make the html. foreach ($match[1] as $key => $value) { $map[$value] = $key; } $result = db_query("SELECT n.nid, n.title, i.thumb_path FROM {image} i, {node} n WHERE n.status = 1 AND i.nid = n.nid AND n.nid IN ('" . implode("','", array_map("check_query", $match[1])) . "')"); while ($img = db_fetch_object($result)) { $n = $map[$img->nid]; preg_match("/(sub|super|top|middle|bottom|text-top|baseline|text-bottom|length|\d+?%)/i", $match[2][$n], $m); $img->vertalign = $m[1]; preg_match("/margin=\"?([\d\s\w]+?)\"?/i", $match[2][$n], $m); $img->margin = $m[1]; preg_match("/border=\"?([\d\s\w]+?)\"?/i", $match[2][$n], $m); $img->border = $m[1]; preg_match("/width=\"?(\d+)\"?/i", $match[2][$n], $m); $img->width = $m[1]; preg_match("/height=\"?(\d+)\"?/i", $match[2][$n], $m); $img->height = $m[1]; preg_match("/float=\"?(left|right)\"/i", $match[2][$n], $m); $img->float = $m[1]; $match[10][$n] = theme("image_inline_img", $img); } // PHP (4.3.2) str_replace appears to use some internal order // rather than array index when finding replace elements // corresponding to search elements. To make sure that the // order of the arrays correspond, we make new copies here. foreach ($match[1] as $key => $value) { $mtch[] = $match[0][$key]; $repl[] = $match[10][$key]; } $text = str_replace($mtch, $repl, $text); } return $text; } /** * Theme function to render image in a node. * Displays a thumbnail with a link to the image. */ function theme_image_inline_img($img) { $style = ""; $style .= (($img->width)? "width: {$img->width}px; " : NULL); $style .= (($img->height)? "height: {$img->height}px; " : NULL); $style .= (($img->border)? "border: $img->border; " : NULL); $style .= (($img->margin)? "margin: $img->margin; " : NULL); $style .= (($img->vertalign)? "vertical-align: $img->vertalign; " : NULL); $style .= (($img->float)? "float: $img->float; " : NULL); $source = (($img->width)? url("image/view/$img->nid", ($img->width || $img->height ? 'res=' . $img->width . "x$img->height" : '')) : "$img->thumb_path"); return l("\"$img-title\" class=\"thumb\"/>","node/$img->nid"); } ?>