Sometimes a user may want to add an image or a file inside the body of a node. This can be done with special tags that are replaced by links to the corresponding uploaded file. If the file is an image, it will be displayed inline, otherwise a link to the file will be inserted. To enable this feature and learn the proper syntax, visit the filters configuration screen.
', array('%filters' => url('admin/filters'))); case 'admin/modules#description': return t('Allows users to insert uploaded files inline. Requires upload.module to work'); case 'filter#short-tip': return t('You may add links to files uploaded with this node using special tags', array('%explanation-url' => url('filter/tips', NULL, 'image'))); case 'filter#long-tip': return t('You may link to files uploaded with the current node using special tags. The tags will be replaced by the corresponding files. Syntax: [inline:file_id]. Parameter: file_id represents the file uploaded with the node in which to link, assuming that the first uploaded file is labeled as 1 and so on.
If the file is an image, it will be displayed inline, otherwise a link to the file will be inserted.
'); } } function inline_settings() { return form_textfield(t('Maximum width and height for the displayed inline images (format: XXX,YYY)'), 'inline_img_dim', variable_get('inline_img_dim', '150,150'), 10, 10, t('This setting will affect the dimensions of displayed images. They will not be resized.')); } function inline_filter($op, $delta = 0, $format = -1, $text = '') { // The "list" operation provides the module an opportunity to declare both how // many filters it defines and a human-readable name for each filter. Note that // the returned name should be passed through t() for translation. if ($op == 'list') { return array( 0 => t('Inline file filter')); } // All operations besides "list" provide a $delta argument so we know which // filter they refer to. We'll switch on that argument now so that we can // discuss each filter in turn. switch ($op) { case 'description': return t('Substitutes [inline:xx] tags with the xxth file uploaded with the node.'); case 'prepare': return $text; case 'process': return $text; } } function inline_filter_tips($delta, $format, $long = false) { if ($long) { return t('You may link to files uploaded with the current node using special tags. The tags will be replaced by the corresponding files. For example: Suppose you uploaded three files (in this order):
[inline:1=test] or [inline:imag1.png=test]will be replaced by
<img src=imag1.png alt=test>
[file:1=test] or [file:imag1.png=test]will be replaced by
<a href=imag1.png>test</a>
[attachment:2=test] or [attachment:file1.pdf=test]will be replaced by
<a href=file1.pdf.png>test</a>
');
}
else {
return t('You may use [inline:xx=left|right|none] tags to display uploaded files or images inline. For an SWF file, use [inline:xx=left|right|none=WIDTHxHEIGHT] [this version of Inline modified by David]', array("%inline_help" => url("filter/tips/$format", NULL, 'filter-inline')));
}
}
function inline_nodeapi(&$node, $op, $arg) {
if(is_array($node->files) && $op == 'view') {
if (preg_match_all("/\[(inline|file|attachment):(\d+)=?(\w*)=?(\d+x\d+)?\]/i", $node->body, $match)) {
foreach ($match[2] as $key => $value) {
$map[$value] = $key;
$align = $match[3][$key];
$dimensions = $match[4][$key];
$mytype = $match[1][$key];
$inline_file = _inline_filename($node, $value);
$replace = "";
$notattachment = ($mytype == "inline" | $mytype == "swf");
if ($inline_file != NULL) {
$replace = theme('inline_html', $inline_file[0], $inline_file[1], $titl, $notattachment, $align, $dimensions);
}
else {
$replace = "NOT FOUND: $value";
}
$mtch[] = $match[0][$key];
$repl[] = $replace;
}
$text_b = str_replace($mtch, $repl, $node->body);
$node->body = $text_b;
$text_t = str_replace($mtch, $repl, $node->teaser);
$node->teaser = $text_t;
}
}
}
function _inline_filename(&$node, $id) {
if (is_numeric($id)) {
$n=1;
foreach ($node->files as $file) {
if ($n == $id) {
//return array($file->filename, file_create_url($file->filepath));
return array($file->filename, $file->filepath);
}
++$n;
}
return NULL;
}
else
{
foreach ($node->files as $file) {
if ($file->filename == $id) {
return array($file->filename, file_create_url($file->filepath));
}
}
return NULL;
}
}
function theme_inline_html($filename, $filepath, $title, $allow_inline_image, $float="", $dimensions, $border=true) {
//make a list with allowed image-tags
$extensions = 'jpg jpeg gif png swf';
$regex = '/\.('. ereg_replace(' +', '|', preg_quote($extensions)) .')$/i';
if (preg_match($regex, $filepath) && $allow_inline_image) {
$opposite = "left";
$float==$opposite && $opposite = "right";
if ($float) {
$float = "float:$float;clear:$float;";
} else {
$float = "float:none;clear:both;";
}
if (preg_match ('/\.(swf)$/', $filepath)) {
// SWF files - get size, etc.
$type = "swf";
list ($f_width, $f_height) = split ("x", $dimensions);
$style = "style=\"$float\"";
$object = '';
$html = $object;
$float || $html = "