New attachment view, do_hook() with parameters, better attachment hook
authorfidian <fidian@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 9 Oct 2000 12:18:32 +0000 (12:18 +0000)
committerfidian <fidian@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 9 Oct 2000 12:18:32 +0000 (12:18 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@780 7612ce4b-ef26-0410-bec9-ea0150e637f0

ChangeLog
functions/mime.php
functions/plugin.php

index e4722c4..6adba35 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@ Version 0.6pre1 -- DEVELOPMENT
 - Made message index order customizable (from, subject, date) can be (date, from, subject)
 - Fixed some security problems with uploading attachments
 - Added Catalan translation from Josep Sanz <jsanz@fa.upc.es>
+- When reading, attachments look better and have a better plugin interface
 
 
 Version 0.5 -- September 25, 2000 
index a3556f0..82f239e 100644 (file)
          $body .= "<SMALL><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$ent_num&mailbox=$urlmailbox\">". _("Download this as a file") ."</A></CENTER><BR></SMALL>";
    
          /** Display the ATTACHMENTS: message if there's more than one part **/
+         $body .= "</TD></TR></TABLE>";
          if ($message->entities) {
-            $body .= "</TD></TR></TABLE>";
-            $body .= "<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=4 BORDER=0><TR><TD BGCOLOR=\"$color[0]\">";
-            $body .= "<TT><B>ATTACHMENTS:</B></TT>";
-            $body .= "</TD></TR><TR><TD BGCOLOR=\"$color[0]\">";
-            $num = 0;
-   
             $body .= formatAttachments ($message, $ent_num, $message->header->mailbox, $id);
-            $body .= "</TD></TR></TABLE>";
-         } else {
-            $body .= "</TD></TR></TABLE>";
          }
       } else {
-         $body .= "</TD></TR></TABLE>";
-         $body .= "<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=4 BORDER=0><TR><TD BGCOLOR=\"$color[0]\">";
-         $body .= "<TT><B>ATTACHMENTS:</B></TT>";
-         $body .= "</TD></TR><TR><TD BGCOLOR=\"$color[0]\">";
-         $num = 0;
-
-         $body .= formatAttachments ($message, 999999, $message->header->mailbox, $id);
-         $body .= "</TD></TR></TABLE>";
+         $body .= formatAttachments ($message, -1, $message->header->mailbox, $id);
       }
       return $body;
    }
    // to where to download these attachments
    function formatAttachments ($message, $ent_id, $mailbox, $id) {
       global $where, $what;
-      global $startMessage;
+      global $startMessage, $color;
+      static $ShownHTML;
+      
+      if ($ShownHTML == 0)
+      {
+            $ShownHTML = 1;
+            
+            $body .= "<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR=\"$color[0]\"><TR>\n";
+            $body .= "<TH ALIGN=\"left\" BGCOLOR=\"$color[9]\"><B>\n";
+            $body .= _('Attachments') . ':';
+            $body .= "</B></TH></TR><TR><TD>\n";
+            
+            $body .= "<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0>\n";
+            
+            $body .= formatAttachments ($message, $ent_id, $mailbox, $id);
+            
+            $body .= "</TABLE></TD></TR></TABLE>";
+            
+            return $body;
+      }
+      
       if ($message) {
          if (!$message->entities) {
             $type0 = strtolower($message->header->type0);
    
                $urlMailbox = urlencode($mailbox);
                $ent = urlencode($message->header->entity_id);
-               if ($where && $what) {   
-                  // from a search
-                  $body .= "<TT>&nbsp;&nbsp;&nbsp;<A HREF=\"../src/download.php?startMessage=$startMessage&where=".urlencode($where)."&what=".urlencode($what)."&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent\">" . $display_filename . "</A>&nbsp;&nbsp;(TYPE: $type0/$type1)";
-               } else {   
-                  $body .= "<TT>&nbsp;&nbsp;&nbsp;<A HREF=\"../src/download.php?startMessage=$startMessage&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent\">" . $display_filename . "</A>&nbsp;&nbsp;(TYPE: $type0/$type1)";
-               }
+               
+               $DefaultLink = 
+                  "../src/download.php?startMessage=$startMessage&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent";
+               if ($where && $what)
+                  $DefaultLink .= '&where=' . urlencode($where) . '&what=' . urlencode($what);
+               $Links['download link']['text'] = _('download');
+               $Links['download link']['href'] = 
+                   "../src/download.php?absolute_dl=true&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent";
+               $ImageURL = '';
+               
+               $HookResults = do_hook("attachment $type0/$type1", $Links,
+                   $startMessage, $id, $urlMailbox, $ent, $DefaultLink, 
+                   $where, $what);
+
+               $Links = $HookResults[1];
+               $DefaultLink = $HookResults[6];
+
+               $body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><FONT SIZE="-1">';
+               $body .= "<A HREF=\"$DefaultLink\">$display_filename</A>&nbsp;</FONT></TD>";
+               $body .= "<TD><FONT SIZE=\"-1\">($type0/$type1)&nbsp;</FONT></TD>";
+               $body .= '<TD><FONT SIZE="-1">';
                if ($message->header->description)
-                  $body .= "&nbsp;&nbsp;<b>" . htmlspecialchars($message->header->description)."</b>";
-               $body .= "&nbsp;(<a href=\"../src/download.php?absolute_dl=true&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent\">"._("download")."</a>)\n";     
-               do_hook("attachment $type0/$type1");
-               $body .= "</TT><BR>";
-               $num++;
+                  $body .= '<b>' . htmlspecialchars($message->header->description) . '</b>';
+               $body .= '</FONT></TD><TD><FONT SIZE="-1">&nbsp;';
+               
+               
+               $SkipSpaces = 1;
+               foreach ($Links as $Val)
+               {
+                  if ($SkipSpaces)
+                  {
+                     $SkipSpaces = 0;
+                  }
+                  else
+                  {
+                     $body .= '&nbsp;&nbsp;';
+                  }
+                  $body .= '(<a href="' . $Val['href'] . '">' . 
+                     $Val['text'] . '</a>)';
+               }
+               
+               unset($Links);
+               
+               $body .= "</FONT></TD></TR>\n";
             }
             return $body;
          } else {
index cb845ea..e4727f8 100644 (file)
       if (file_exists('../plugins/'.$name.'/setup.php')) {
          include ('../plugins/'.$name.'/setup.php');
          $function = 'squirrelmail_plugin_init_'.$name;
-         $function();
+         if (function_exists($function))
+            $function();
       }
    }
 
    // This function executes a hook
    function do_hook ($name) {
       global $squirrelmail_plugin_hooks;
+      $Data = func_get_args();
       if (is_array($squirrelmail_plugin_hooks[$name])) {
-         reset($squirrelmail_plugin_hooks[$name]);
-         
-         while (list ($id, $function) = 
-                each ($squirrelmail_plugin_hooks[$name])) {
+         foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
             // Add something to set correct gettext domain for plugin
-            $function();
+            if (function_exists($function)) {
+                $function(&$Data);
+            }
          }
       }
-   }
+      
+      // Variable-length argument lists have a slight problem when
+      // passing values by reference.  Pity.  This is a workaround.
+      return $Data;
+  }
 
    // On startup, register all plugins configured for use
    if (is_array($plugins))
-      while (list ($id, $name) = each ($plugins))
+      foreach ($plugins as $id => $name)
          use_plugin($name);
 
 ?>