Changeset 2336 in subversion


Ignore:
Timestamp:
Mar 6, 2009 4:48:14 PM (4 years ago)
Author:
ziba
Message:

Added an array of required plugins rcube_plugin_api.php. It's got room to grow.
New core plugin: filesystem_attachments - the existing disk based attachment handling now in plugin form (with one garbage collection bug fix)
New plugin: database_attachments - multi-server safe, database backed attachment temp file handling
New plugin hooks: remove_attachment, display_attachment, upload_attachment, save_attachment, cleanup_attachments, get_attachment

Location:
branches/devel-api
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-api/program/include/rcube_plugin_api.php

    r2305 r2336  
    4040  private $template_contents = array(); 
    4141   
     42  private  $required_plugins = array('filesystem_attachments'); 
    4243 
    4344  /** 
     
    9394            $plugin->init(); 
    9495            $this->plugins[] = $plugin; 
     96 
     97            // Remove required plugin class types from the required_plugins 
     98            // list as they are found 
     99            $key = array_search($plugin_name, $this->required_plugins); 
     100            if($key === FALSE){ 
     101                $parents = class_parents($plugin);  
     102                foreach($parents as $parent){ 
     103                    $key = array_search($parent, $this->required_plugins); 
     104                    if($key !== FALSE){ 
     105                        break; 
     106                    } 
     107                } 
     108            } 
     109            if($key !== FALSE){ 
     110                unset($this->required_plugins[$key]);            
     111            } 
    95112          } 
    96113        } 
     
    104121    } 
    105122     
     123    // Instantiate core plugins if not all required plugin types are satisfied 
     124    foreach($this->required_plugins as $plugin_name){ 
     125      $fn = $plugins_dir->path . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . $plugin_name . '.php'; 
     126      if (file_exists($fn)) { 
     127        include($fn); 
     128        if (class_exists($plugin_name, false)) { 
     129          $plugin = new $plugin_name($this); 
     130          // check inheritance and task specification 
     131          if (is_subclass_of($plugin, 'rcube_plugin') && (!$plugin->task || $plugin->task == $rcmail->task)) { 
     132            $plugin->init(); 
     133            $this->plugins[] = $plugin; 
     134          } 
     135        } 
     136      } 
     137    } 
     138 
    106139    // register an internal hook 
    107140    $this->register_hook('template_container', array($this, 'template_container_hook')); 
  • branches/devel-api/program/steps/mail/attachments.inc

    r2121 r2336  
    2929if ($RCMAIL->action=='remove-attachment') 
    3030{ 
    31   if (preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs)) 
     31  $plugin = rcmail::get_instance()->plugins->exec_hook('remove_attachment',array('id'=>substr($_POST['_file'],7))); 
     32  if ($plugin['status']) 
    3233  { 
    33     $id = $regs[1]; 
     34    $id = $plugin['id']; 
    3435    if (is_array($_SESSION['compose']['attachments'][$id])) 
    3536    { 
    36       @unlink($_SESSION['compose']['attachments'][$id]['path']); 
    3737      unset($_SESSION['compose']['attachments'][$id]); 
    3838      $OUTPUT->command('remove_from_attachment_list', "rcmfile$id"); 
     
    4545if ($RCMAIL->action=='display-attachment') 
    4646{ 
    47   if (preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs)) 
     47  $plugin = rcmail::get_instance()->plugins->exec_hook('display_attachment',array('id'=>substr($_GET['_file'],7))); 
     48  if ($plugin['status']) 
    4849  { 
    49     $id = $regs[1]; 
    50     if (is_array($_SESSION['compose']['attachments'][$id])) 
    51     { 
    52       $apath = $_SESSION['compose']['attachments'][$id]['path']; 
    53       header('Content-Type: ' . $_SESSION['compose']['attachments'][$id]['mimetype']); 
    54       header('Content-Length: ' . filesize($apath)); 
    55       readfile($apath); 
     50    $id = $plugin['id']; 
     51    $apath = $_SESSION['compose']['attachments'][$id]['path']; 
     52    header('Content-Type: ' . $_SESSION['compose']['attachments'][$id]['mimetype']); 
     53    header('Content-Length: ' . filesize($apath)); 
     54    readfile($apath); 
     55    // plugins that don't use disk storage will want this temp file removed after use 
     56    if($plugin['erase_after_send']){ 
     57        unlink($apath); 
    5658    } 
    5759  } 
     
    7375if (is_array($_FILES['_attachments']['tmp_name'])) { 
    7476  foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) { 
    75     $tmpfname = tempnam($temp_dir, 'rcmAttmnt'); 
    76     if (move_uploaded_file($filepath, $tmpfname)) { 
    77       $id = count($_SESSION['compose']['attachments']); 
    78       $_SESSION['compose']['attachments'][] = array( 
    79         'name' => $_FILES['_attachments']['name'][$i], 
    80         'mimetype' => rc_mime_content_type($tmpfname, $_FILES['_attachments']['type'][$i]), 
    81         'path' => $tmpfname, 
    82       ); 
    83  
     77    $plugin = rcmail::get_instance()->plugins->exec_hook('upload_attachment',array('filepath'=>$filepath,'index'=>$i)); 
     78    if ($plugin['status']) { 
     79      $id = $plugin['id']; 
    8480      if (is_file($icon = $CONFIG['skin_path'] . '/images/icons/remove-attachment.png')) { 
    8581        $button = html::img(array( 
     
    9591      $content = html::a(array( 
    9692        'href' => "#delete", 
    97         'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id), 
     93        'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this)", JS_OBJECT_NAME, $id), 
    9894        'title' => rcube_label('delete'), 
    9995      ), $button); 
  • branches/devel-api/program/steps/mail/compose.inc

    r2161 r2336  
    589589         || (empty($part->disposition) && $part->filename))) 
    590590    { 
    591       if ($attachment = rcmail_save_attachment($message, $pid)) 
    592         $_SESSION['compose']['attachments'][] = $attachment; 
     591      if ($attachment = rcmail_save_attachment($message, $pid)){ 
     592          $_SESSION['compose']['attachments'][$attachment['id']] = $attachment; 
     593      } 
    593594    } 
    594595  } 
     
    605606    { 
    606607      if ($attachment = rcmail_save_attachment($message, $pid)) 
    607         $_SESSION['compose']['attachments'][] = $attachment; 
     608        $_SESSION['compose']['attachments'][$attachment['id']] = $attachment; 
    608609    } 
    609610  } 
     
    614615  global $RCMAIL; 
    615616 
    616   $temp_dir = unslashify($RCMAIL->config->get('temp_dir')); 
    617   $tmp_path = tempnam($temp_dir, 'rcmAttmnt'); 
    618617  $part = $message->mime_parts[$pid]; 
    619618   
    620   if ($fp = fopen($tmp_path, 'w')) 
    621   { 
    622     $message->get_part_content($pid, $fp); 
    623     fclose($fp); 
    624  
     619  $attachment = $message->get_part_content($pid); 
     620  $plugin = rcmail::get_instance()->plugins->exec_hook('save_attachment',array('attachment'=>$attachment,'filename'=>$part->filename)); 
     621  if ($plugin['status']) 
     622  { 
    625623    return array( 
    626624        'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, 
    627625        'name' => $part->filename, 
    628         'path' => $tmp_path, 
    629         'content_id' => $part->content_id 
     626        'path' => $plugin['tmp_path'], 
     627        'content_id' => $part->content_id, 
     628        'id' => $plugin['id'] 
    630629    ); 
     630  } else { 
     631    return FALSE; 
    631632  } 
    632633} 
  • branches/devel-api/program/steps/mail/func.inc

    r2303 r2336  
    12151215    return; 
    12161216 
    1217   // remove attachment files from temp dir 
    1218   if (is_array($_SESSION['compose']['attachments'])) 
    1219     foreach ($_SESSION['compose']['attachments'] as $attachment) 
    1220       @unlink($attachment['path']); 
     1217  rcmail::get_instance()->plugins->exec_hook('cleanup_attachments',array()); 
    12211218   
    12221219  unset($_SESSION['compose']); 
  • branches/devel-api/program/steps/mail/sendmail.inc

    r2303 r2336  
    299299  foreach ($_SESSION['compose']['attachments'] as $id => $attachment) 
    300300  { 
     301    // This hook gives attachment handlers a chance to place the file on disk 
     302    $plugin = rcmail::get_instance()->plugins->exec_hook('get_attachment', array('id' => $id,'attachment'=>$attachment)); 
     303    $attachment = $plugin['attachment']; 
    301304    $dispurl = '/\ssrc\s*=\s*[\'"]?\S+display-attachment\S+file=rcmfile' . $id . '[\'"]?/'; 
    302305    $match = preg_match($dispurl, $message_body); 
     
    322325        ); 
    323326    } 
     327    if($plugin['erase_after_send']){ 
     328        unlink($plugin['attachment']['path']); 
     329    } 
    324330  } 
    325331 
Note: See TracChangeset for help on using the changeset viewer.