? inline.info
? inline.install
? inline_as_link.tpl.php
? inline_img.tpl.php
? patchfile.patch
? template.php
Index: inline.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/inline/inline.module,v
retrieving revision 1.18
diff -u -F^f -r1.18 inline.module
--- inline.module	19 Aug 2006 16:09:54 -0000	1.18
+++ inline.module	6 Jan 2007 16:06:31 -0000
@@ -11,12 +11,26 @@ 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> ');
   }
 }
+function inline_menu($may_cache) {
+  if ($may_cache) {
+    $items[] = array(
+        'path' => 'admin/settings/inline',
+        'title' => t('inline'),
+        'description' => t('Display attachments inline automatically.'),
+        'callback' => 'drupal_get_form',
+        'callback arguments' => array('inline_admin_settings'),
+        'access' => user_access('administer site configuration'),
+        'type' => MENU_NORMAL_ITEM, // optional
+     );
+  }
+  return $items;
+}
 
-function inline_settings() {
+function inline_admin_settings() {
   $form = array();
 
   $form['inline_img_dim'] = array(
@@ -29,6 +43,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'),
@@ -36,20 +59,18 @@ function inline_settings() {
     '#options' => array('0' => t('Print only &lt;img&gt; tag'),'1' => t('Print &lt;img&gt; tag and the link to the image')),
   );
 
-  return $form;
+  return system_settings_form($form);
 }
 
 function inline_form_alter($form_id, &$form) {
-  if (isset($form['type'])) {
-    if ($form['type']['#value'] .'_node_settings' == $form_id) {
-      $form['workflow']['upload_inline_'. $form['type']['#value']] = array(
-          '#type' => 'radios',
-          '#title' => t('Display attachments inline automatically'),
-          '#default_value' => variable_get('upload_inline_'. $form['type']['#value'], 0),
-          '#options' => array(t('Disabled'), t('Only in teaser'), t('Only in body'), t('In teaser and body')),
-          '#description' => t('Whether or not uploaded images should be shown inline. Make sure you set the dimensions at %settings_url', array('%settings_url' => l(t('inline settings'), 'admin/settings/inline'))),
-      );
-    }
+  if ('node_type_form' == $form_id) {
+    $form['workflow']['upload_inline'] = array(
+        '#type' => 'radios',
+        '#title' => t('Display attachments inline automatically'),
+        '#default_value' => variable_get('upload_inline_'. $form['#node_type']->type, 0),
+        '#options' => array(t('Disabled'), t('Only in teaser'), t('Only in body'), t('In teaser and body')),
+        '#description' => t('Whether or not uploaded images should be shown inline. Make sure you set the dimensions at %settings_url', array('%settings_url' => l(t('inline settings'), 'admin/settings/inline'))),
+    );
   }
 }
 
@@ -67,7 +88,7 @@ function inline_filter($op, $delta = 0, 
   // discuss each filter in turn.
   switch ($op) {
     case 'description':
-       return t('Substitutes [inline:xx] tags with the xxth file uploaded with the node.');
+       return t('Substitutes [attachment:xx] tags with the xxth file uploaded with the node.');
     case 'prepare':
        return $text;
     case 'process':
@@ -76,40 +97,26 @@ 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')));
   }
 }
 
-function inline_nodeapi(&$node, $op, $arg) {
-  if(is_array($node->files) && $op == 'view') {
+function inline_nodeapi(&$node, $op) {
+  if(is_array($node->files) && ($op == 'alter')) {
     //only nodes with our inline filter in the format may be altered
     foreach (filter_list_format($node->format) as $filter) {
       if ($filter->module == 'inline') {
@@ -124,6 +131,33 @@ 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);
+    }
+  }
+  if ($text != "") {
+    switch ($value_type) {
+    case INLINE_WORD:
+      return preg_replace("/\W/", '', $text);
+    case INLINE_INTEGER:
+      return preg_replace("/\D/", '', $text);
+    default:
+      return check_plain($text);
+    }
+  }
+  else {
+    return NULL;
+  }
+}
+
 function _inline_fileobj(&$node, $id) {
   if (is_numeric($id)) {
     $n=1;
@@ -159,22 +193,20 @@ function inline_prepare_file_object($fil
   return $file;
 }
 
-
-function theme_inline_as_link($file) {
-  // prepare link text with title or filename
-  $linktext = ($file->title ? $file->title : $file->name);
-
-  return l($linktext, file_create_url($file->filepath), array('title' => t('Download: %name (%size)', array('%name' => $file->filename, '%size' => format_size($file->filesize)))));
+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' => $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->title ? $file->title : $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>';
@@ -182,12 +214,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) {
@@ -238,30 +270,64 @@ 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) {
-      // fetch file object
-      $file = inline_prepare_file_object(_inline_fileobj($node, $value));
-      // deal file title
-      $title = $match[3][$key];
-      if (!empty( $title )) {
-        $file->title = $title;
-      }
-      $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)) {
+		  $param->inline = true;
+		}
+		else {
+		  $param->inline = false;
+		}
+	  }
+	  $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);
   }
@@ -273,19 +339,31 @@ 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, $param) {
   $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'));
-
     if ($file->preview) {
       list($width, $height) = getimagesize($file->real_path);
     }
     else {
       list($width, $height) = getimagesize($file->filepath);
     }
+    $file->width = $width;
+    $file->height = $height;
+
+    if (isset($param)) {
+      if ($param->width && ! $param->height) {
+	    $height = round($height * $param->width / $width);
+	    $width = $param->width;
+      }
+      if ($param->height && ! $param->width) {
+	    $width = round($width * $param->height / $param->file->height);
+	    $height = $param->height;
+      }
+    }
 
     if (($width && $height) && ($width <= $maxwidth && $height <= $maxheight)) {
       return TRUE;
