Index: contributions/modules/inline/inline.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/inline/inline.module,v
retrieving revision 1.14
diff -u -F^function -r1.14 inline.module
--- contributions/modules/inline/inline.module	3 May 2006 23:16:52 -0000	1.14
+++ contributions/modules/inline/inline.module	30 May 2006 19:21:36 -0000
@@ -11,7 +11,7 @@ function inline_help($section = 'admin/h
     case 'filter#short-tip':
       return t('You may add links to files uploaded with this node <a href="%explanation-url">using special tags</a>', array('%explanation-url' => url('filter/tips', NULL, 'image')));
     case 'filter#long-tip':
-      return t('<p>You may link to files uploaded with the current node using special tags. The tags will be replaced by the corresponding files. Syntax: <code>[inline:file_id]</code>. 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.</p>
+      return t('<p>You may link to files uploaded with the current node using special tags. The tags will be replaced by the corresponding files. Syntax: <code>[attachment:file_id]</code>. 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.</p>
     <p>If the file is an image, it will be displayed inline, otherwise a link to the file will be inserted.</p> ');
   }
 }
@@ -29,6 +29,15 @@ function inline_settings() {
     '#description' => t('This setting will affect the dimensions of displayed images. They will not be resized. Images larger than these dimensions will not be shown automatically.'),
   );
 
+  $form['inline_img_space_dim'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default image spacing (horizontal, vertical)'),
+    '#default_value' => variable_get('inline_img_space_dim', '5,5'),
+    '#size' => 10,
+    '#maxlength' => 10,
+    '#description' => t('This setting will affect the white space around the images. Use <em>hspace=n</em> or <em>vspace=n</em> to override default for specific images.'),
+  );
+
   $form['inline_link_img'] = array(
     '#type' => 'radios',
     '#title' => t('Print link to images'),
@@ -76,32 +85,18 @@ function inline_filter($op, $delta = 0, 
 }
 
 function inline_filter_tips($delta, $format, $long = false) {
-  if ($long) {
-    return t('
-    <p>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):
-    <ul>
-    <li>imag1.png (referred as file #1)
-    <li>file1.pdf (referred as file #2)
-    <li>imag2.png (referred as file #3)
-    </ul>
-
-    <pre>[inline:1=test]  or  [inline:imag1.png=test]</pre>
-
-    will be replaced by <em><code>&lt;img src=imag1.png alt=test&gt;</code></em>
-
-
-    <pre>[file:1=test]  or  [file:imag1.png=test]</pre>
-
-    will be replaced by <em><code>&lt;a href=imag1.png&gt;test&lt;/a&gt;</code></em>
-
-
-    <pre>[attachment:2=test]  or  [attachment:file1.pdf=test]</pre>
-
-    will be replaced by <em><code>&lt;a href=file1.pdf.png&gt;test&lt;/a&gt;</code></em>
+  if (!user_access('upload files')) {
+    return '';
+  }
 
-    ');
+  if ($long) {
+	  return t('<p>You may quickly link to attachments using a special syntax. Each attachment code will be replaced by an image or link to the attachment. Syntax:</p>
+		  	    <blockquote><code>[attachment:<em>attachment_ref</em> link align=<em>alignment</em> hspace=<em>n</em> vspace=<em>n</em> border=<em>n</em> width=<em>n</em> height=<em>n</em> title=<em>name</em> class=<em>name</em> style=<em>style-data</em>]</code></blockquote>
+				<p>Every parameter except <em>attachment_ref</em> is optional.</p>
+				<p><em>attachment_ref</em> can be the filename or the index of the attachment. When using filename be sure to put it between quotes (") when the name contains spaces .</p>
+				<p>Typically, you will specify one of <code>width</code>, or <code>height</code>, or none of them. If you use <code>width=<em>n</em></code> or <code>height=<em>n</em></code>, the image will be scaled to fit the specified width or height. If you use none of them, the attached image size will be used.</p>
+				<p>The <code>align</code>, <code>hspace</code>, <code>vspace</code>, <code>border</code>, <code>class</code>, and <code>style</code> parameters set the corresponding attributes in the generated <code>img</code> tag.</p>
+				<p>By default an attached image is displayed as an image not as a link. However if you specify <code>link</code> a link to the image is created.</p>');
   }
   else {
     return t('You may use <a href="%inline_help">[inline:xx] tags</a> to display uploaded files or images inline.', array("%inline_help" => url("filter/tips/$format", NULL, 'filter-inline')));
@@ -119,6 +114,28 @@ function inline_nodeapi(&$node, $op, $ar
   }
 }
 
+define("INLINE_WORD",    1);
+define("INLINE_INTEGER", 2);
+define("INLINE_STRING",  3);
+
+function inline_attr_value($text, $value_type = INLINE_WORD) {
+  // Strip off initial and final quotes.
+  $first = substr($text, 0, 1);
+  if ($first == "\"" || $first == "\'") {
+    if (substr($text, -1, 1) == $first) {
+      $text = substr($text, 1, -1);
+    }
+  }
+  switch ($value_type) {
+  case INLINE_WORD:
+    return preg_replace("/\W/", '', $text);
+  case INLINE_INTEGER:
+    return preg_replace("/\D/", '', $text);
+  default:
+    return check_plain($text);
+  }
+}
+
 function _inline_fileobj(&$node, $id) {
   if (is_numeric($id)) {
     $n=1;
@@ -142,21 +159,21 @@ function _inline_fileobj(&$node, $id) {
   }
 }
 
-function theme_inline_as_link($file) {
-  return l(($file->description ? $file->description : $file->name),
-    file_create_url($file->filepath),
+function theme_inline_as_link($param) {
+  return l(($param->file->description ? $param->file->description : $param->file->name),
+    file_create_url($param->file->filepath),
     array('title' => t('Download: %name (%size)',
-      array('%name' => $file->filename, '%size' => format_size($file->filesize)))));
+      array('%name' => $param->file->filename, '%size' => format_size($param->file->filesize)))));
 }
 
-function theme_inline_img($file) {
+function theme_inline_img($param) {
   if (variable_get('inline_link_img', '1') == '1') {
-    $html .= '<a href="'. file_create_url($file->filepath) . '" title="'.t("View").': '. $file->name .'">';
+    $html .= '<a href="'. file_create_url($param->file->filepath) . '" title="'.t("View").': '. $param->file->name .'">';
   }
 
-  $title = ( $file->description ? $file->description : $file->name );
+  $title = ( $param->file->description ? $param->file->description : $param->file->name );
 
-  $html .= '<img style="width: '.$file->width.'px; height:'.$file->height.'px;" src="'. file_create_url($file->filepath). '" class="inline" alt="'. $title .'" title="'. $title.'" />';
+  $html .= '<img style="width:'.$param->file->width.'px; height:'.$param->file->height.'px;" src="'. file_create_url($param->file->filepath). '" class="inline" alt="'. $title .'" title="'. $title.'" />';
 
   if (variable_get('inline_link_img', '1') == '1') {
     $html .= '</a>';
@@ -164,12 +181,12 @@ function theme_inline_img($file) {
   return $html;
 }
 
-function theme_inline_add_to_teaser($node, $file) {
-   return theme('inline_img', $file) . $node->teaser;
+function theme_inline_add_to_teaser($node, $param) {
+   return theme('inline_img', $param) . $node->teaser;
 }
 
-function theme_inline_add_to_body($node, $file) {
-   return theme('inline_img', $file) . $node->body;
+function theme_inline_add_to_body($node, $param) {
+   return theme('inline_img', $param) . $node->body;
 }
 
 function _inline_auto_add($node) {
@@ -183,7 +200,8 @@ function _inline_auto_add($node) {
       foreach ($node->files as $fid => $file) {
         if (_inline_decide_img_tag($file)) {
           $node->files[$fid]->inline = TRUE;
-          $node->teaser = theme('inline_add_to_teaser', $node, $file);
+          $param->file = $file;
+          $node->teaser = theme('inline_add_to_teaser', $node, $param->file);
         }
         else {
           $node->files[$fid]->inline = FALSE;
@@ -194,7 +212,8 @@ function _inline_auto_add($node) {
       foreach ($node->files as $fid => $file) {
         if (_inline_decide_img_tag($file)) {
           $node->files[$fid]->inline = TRUE;
-          $node->body = theme('inline_add_to_body', $node, $file);
+          $param->file = $file;
+          $node->body = theme('inline_add_to_body', $node, $param->file);
         }
         else {
           $node->files[$fid]->inline = FALSE;
@@ -205,8 +224,9 @@ function _inline_auto_add($node) {
       foreach ($node->files as $fid => $file) {
         if (_inline_decide_img_tag($file)) {
           $node->files[$fid]->inline = TRUE;
-          $node->teaser = theme('inline_add_to_teaser', $node, $file);
-          $node->body = theme('inline_add_to_body', $node, $file);
+          $param->file = $file;
+          $node->teaser = theme('inline_add_to_teaser', $node, $param->file);
+          $node->body = theme('inline_add_to_body', $node, $param->file);
         }
         else {
           $node->files[$fid]->inline = FALSE;
@@ -218,27 +238,60 @@ function _inline_auto_add($node) {
 }
 
 function _inline_substitute_tags(&$node, $field) {
-  if (preg_match_all("/\[(inline|file|attachment):([^=\\]]+)=?([^\\]]*)?\]/i", $node->$field, $match)) {
-    foreach ($match[2] as $key => $value) {
-      $map[$value] = $key;
-      $titl = $match[3][$key];
-      $ytype = $match[1][$key];
-      $file = _inline_fileobj($node, $value);
-      $replace = "";
-      if ($file->fid != NULL) {
-        //decide if we should show a link or an img tag
-        if (_inline_decide_img_tag($file)) {
-          $replace = theme('inline_img', $file);
-        }
-        else {
-          $replace = theme('inline_as_link', $file);
-        }
-      }
-      else {
-        $replace = "<span style=\"color:red; font-weight:bold\">NOT FOUND: $value</span>";
-      }
-      $mtch[] = $match[0][$key];
-      $repl[] = $replace;
+  //
+  // check for \= in [^\s\]\=] is only for compatibility reasons with previous module -> causes filenames including an = to fail!
+  //
+  if (preg_match_all("/\[(inline|file|attachment):(\"[^\"]*\"|[^\s\]\=]*)(\s*,)?\s*(.*?)\]/i", $node->$field, $matches, PREG_SET_ORDER)) {
+    foreach ($matches as $match) {
+	  $args = array();
+	  // Convert bare alignment 'X' to 'align="X"'.
+	  $match[4] = preg_replace("/^(left|right|top|middle|bottom|absmiddle|texttop|baseline)\b/i", "align=\"$1\"", $match[4]);
+
+	  // any keywords ?
+	  preg_match_all("/(\w+)\=(\"[^\"]*\"|\S*)|(\w+)\s/", $match[4], $a, PREG_SET_ORDER);
+	  foreach ($a as $arg) {
+	    if (isset($arg[3])) {
+		  // keyword only
+		  $args[strtolower($arg[3])] = 1;
+	    }
+	    else {
+		  // keyword and value
+		  $args[strtolower($arg[1])] = $arg[2];
+	    }
+	  }
+	
+      $param->file = (object)_inline_fileobj($node,inline_attr_value($match[2], INLINE_STRING));
+	  $param->width =  inline_attr_value($args['width'],   INLINE_INTEGER);
+	  $param->height = inline_attr_value($args['height'],  INLINE_INTEGER);
+	  $param->align =  inline_attr_value($args['align'],   INLINE_WORD);
+	  $param->hspace = inline_attr_value($args['hspace'],  INLINE_INTEGER);
+	  $param->vspace = inline_attr_value($args['vspace'],  INLINE_INTEGER);
+	  $param->border = inline_attr_value($args['border'],  INLINE_INTEGER);
+	  $param->class =  inline_attr_value($args['class'],   INLINE_WORD);
+	  $param->style =  inline_attr_value($args['style'],   INLINE_STRING);
+	  $param->title =  inline_attr_value($args['title'],   INLINE_STRING);
+	  if (isset($args['link'])) {
+		$param->inline = false;
+	  }
+	  else {
+        if (_inline_decide_img_tag($param->file)) {
+		  $param->inline = true;
+		}
+	  }
+	  $replace = ""; 
+      if ($param->file->fid != NULL) {
+	    if ($param->inline) {
+	      $replace = theme('inline_img', $param);
+		}
+	    else {
+	      $replace = theme('inline_as_link', $param);
+	    }
+	  }
+	  else {
+	    $replace = "<span style=\"color:red; font-weight:bold\">NOT FOUND: $value</span>";
+	  }
+	  $mtch[] = $match[0];
+	  $repl[] = $replace;
     }
     return str_replace($mtch, $repl, $node->$field);
   }
@@ -250,13 +303,15 @@ function _inline_substitute_tags(&$node,
  * @param $file a file object
  * @return TRUE in case an img tag should be generated
  */
-function _inline_decide_img_tag($file) {
+function _inline_decide_img_tag(&$file) {
   $inlined = array('jpg', 'jpeg', 'pjpeg', 'gif', 'png');
   $mime = array_pop(explode('/', $file->filemime));
   if (in_array($mime, $inlined)) {
     // read settings
     list($maxwidth, $maxheight) = explode(',',variable_get('inline_img_dim', '150,150'));
     list($width, $height) = getimagesize($file->filepath);
+    $file->width = $width;
+    $file->height = $height;
     if (($width && $height) && ($width < $maxwidth && $height < $maxheight)) {
       return TRUE;
     }
