forked from extern/egroupware
allow to share files and directories from filemanager via mail app
This commit is contained in:
parent
e06e8d4c32
commit
75688e8cb8
@ -155,7 +155,7 @@ class filemanager_ui
|
||||
'caption' => lang('Mail files'),
|
||||
'icon' => 'filemanager/mail_post_to',
|
||||
'group' => $group,
|
||||
'onExecute' => 'javaScript:app.filemanager.mail',
|
||||
'children' => array(),
|
||||
),
|
||||
'documents' => filemanager_merge::document_action(
|
||||
$GLOBALS['egw_info']['user']['preferences']['filemanager']['document_dir'],
|
||||
@ -207,6 +207,17 @@ class filemanager_ui
|
||||
{
|
||||
unset($actions['mail']);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach(egw_sharing::$modes as $mode => $data)
|
||||
{
|
||||
$actions['mail']['children']['mail_'.$mode] = array(
|
||||
'caption' => $data['label'],
|
||||
'title' => $data['title'],
|
||||
'onExecute' => 'javaScript:app.filemanager.mail',
|
||||
);
|
||||
}
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
|
@ -149,11 +149,12 @@ app.classes.filemanager = AppJS.extend(
|
||||
* Open compose with already attached files
|
||||
*
|
||||
* @param {(string|string[])} attachments path(s)
|
||||
* @param {object} params
|
||||
*/
|
||||
open_mail: function(attachments)
|
||||
open_mail: function(attachments, params)
|
||||
{
|
||||
if (typeof attachments == 'undefined') attachments = this.get_clipboard_files();
|
||||
var params = {};
|
||||
if (!params || typeof params != 'object') params = {};
|
||||
if (!(attachments instanceof Array)) attachments = [ attachments ];
|
||||
for(var i=0; i < attachments.length; i++)
|
||||
{
|
||||
@ -170,7 +171,9 @@ app.classes.filemanager = AppJS.extend(
|
||||
*/
|
||||
mail: function(_action, _elems)
|
||||
{
|
||||
this.open_mail(this._elems2paths(_elems));
|
||||
this.open_mail(this._elems2paths(_elems), {
|
||||
'preset[filemode]': _action.id.substr(5)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@ -359,7 +362,7 @@ app.classes.filemanager = AppJS.extend(
|
||||
clipboard = {
|
||||
type:[],
|
||||
selected:[]
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// When pasting we need to know the type of data - pull from actions
|
||||
@ -632,7 +635,7 @@ app.classes.filemanager = AppJS.extend(
|
||||
// File(s) were dropped on a row, they want them inside
|
||||
if(_target)
|
||||
{
|
||||
var dst = ''
|
||||
var dst = '';
|
||||
var paths = this._elems2paths([_target]);
|
||||
if(paths[0]) dst = paths[0];
|
||||
|
||||
@ -793,7 +796,7 @@ app.classes.filemanager = AppJS.extend(
|
||||
widget.set_label('Superuser');
|
||||
widget.onclick = function(){
|
||||
jQuery('.superuser').css('display','inline');
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,29 +40,6 @@ class mail_compose
|
||||
"plain"=>"plain",
|
||||
"html"=>"html"
|
||||
);
|
||||
/**
|
||||
* Modes for sending files
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $filemodes = array(
|
||||
'attach' => array(
|
||||
'label' => 'Attachment',
|
||||
'title' => 'Works reliable for total size up to 1-2 MB, might work for 5-10 MB, most likely to fail for >10MB',
|
||||
),
|
||||
'link' => array(
|
||||
'label' => 'Download link',
|
||||
'title' => 'Link is appended to mail allowing recipients to download currently attached version of files',
|
||||
),
|
||||
'share_ro' => array(
|
||||
'label' => 'Share readonly',
|
||||
'title' => 'Link is appended to mail allowing recipients to download up to date version of files',
|
||||
),
|
||||
'share_rw' => array(
|
||||
'label' => 'Share writable',
|
||||
'title' => 'Link is appended to mail allowing recipients to download or modify up to date version of files (EPL only)'
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Instance of mail_bo
|
||||
@ -228,13 +205,19 @@ class mail_compose
|
||||
if (!isset($upload['file'])) $upload['file'] = $upload['tmp_name'];
|
||||
try
|
||||
{
|
||||
$tmp_filename = mail_bo::checkFileBasics($upload,$this->composeID,false);
|
||||
$upload['file'] = $upload['tmp_name'] = mail_bo::checkFileBasics($upload,$this->composeID,false);
|
||||
}
|
||||
catch (egw_exception_wrong_userinput $e)
|
||||
{
|
||||
error_log(__METHOD__.__LINE__." ". $e->getMessage());
|
||||
egw_framework::message($e->getMessage(), 'error');
|
||||
unset($_content['uploadForCompose'][$i]);
|
||||
continue;
|
||||
}
|
||||
if (is_dir($upload['file']) && (!$_content['filemode'] || $_content['filemode'] == egw_sharing::ATTACH))
|
||||
{
|
||||
$_content['filemode'] = egw_sharing::READONLY;
|
||||
egw_framework::message(lang('Directories have to be shared.'), 'info');
|
||||
}
|
||||
$upload['file'] = $upload['tmp_name'] = $tmp_filename;
|
||||
}
|
||||
}
|
||||
// check if someone did hit delete on the attachments list
|
||||
@ -747,6 +730,10 @@ class mail_compose
|
||||
|
||||
if (isset($_REQUEST['preset']['file']))
|
||||
{
|
||||
$content['filemode'] = !empty($_REQUEST['preset']['filemode']) &&
|
||||
isset(egw_sharing::$modes[$_REQUEST['preset']['filemode']]) ?
|
||||
$_REQUEST['preset']['filemode'] : egw_sharing::ATTACH;
|
||||
|
||||
$names = (array)$_REQUEST['preset']['name'];
|
||||
$types = (array)$_REQUEST['preset']['type'];
|
||||
//if (!empty($types) && in_array('text/calendar; method=request',$types))
|
||||
@ -780,7 +767,11 @@ class mail_compose
|
||||
'file' => egw_vfs::decodePath($path),
|
||||
'size' => filesize(egw_vfs::decodePath($path)),
|
||||
);
|
||||
if ($formData['type'] == egw_vfs::DIR_MIME_TYPE) continue; // ignore directories
|
||||
if ($formData['type'] == egw_vfs::DIR_MIME_TYPE && $content['filemode'] == egw_sharing::ATTACH)
|
||||
{
|
||||
$content['filemode'] = egw_sharing::READONLY;
|
||||
egw_framework::message(lang('Directories have to be shared.'), 'info');
|
||||
}
|
||||
}
|
||||
elseif(is_readable($path))
|
||||
{
|
||||
@ -1117,7 +1108,7 @@ class mail_compose
|
||||
if (isset($content['mimeType'])) $preserv['mimeType'] = $content['mimeType'];
|
||||
$sel_options['mimeType'] = self::$mimeTypes;
|
||||
$sel_options['priority'] = self::$priorities;
|
||||
$sel_options['filemode'] = self::$filemodes;
|
||||
$sel_options['filemode'] = egw_sharing::$modes;
|
||||
if (!isset($content['priority']) || empty($content['priority'])) $content['priority']=3;
|
||||
//$GLOBALS['egw_info']['flags']['currentapp'] = 'mail';//should not be needed
|
||||
$etpl = new etemplate_new('mail.compose');
|
||||
@ -1616,6 +1607,7 @@ class mail_compose
|
||||
{
|
||||
$attachfailed = true;
|
||||
$alert_msg = $e->getMessage();
|
||||
egw_framework::message($e->getMessage(), 'error');
|
||||
}
|
||||
//error_log(__METHOD__.__LINE__.array2string($tmpFileName));
|
||||
|
||||
@ -2093,10 +2085,12 @@ class mail_compose
|
||||
{
|
||||
$signature = mail_bo::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
|
||||
}
|
||||
if ($_formData['attachments'] && $_formData['filemode'] != 'attach' && $_send)
|
||||
if ($_formData['attachments'] && $_formData['filemode'] != egw_sharing::ATTACH && $_send)
|
||||
{
|
||||
$attachment_links = $this->getAttachmentLinks($_formData['attachments'], $_formData['filemode'],
|
||||
$_formData['mimeType'] == 'html', array_merge((array)$_formData['to'], (array)$_formData['cc'], (array)$_formData['bcc']));
|
||||
$_formData['mimeType'] == 'html',
|
||||
array_unique(array_merge((array)$_formData['to'], (array)$_formData['cc'], (array)$_formData['bcc'])),
|
||||
$_formData['expiration'], $_formData['password']);
|
||||
}
|
||||
if($_formData['mimeType'] == 'html')
|
||||
{
|
||||
@ -2200,7 +2194,7 @@ class mail_compose
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif ($_formData['filemode'] == 'attach')
|
||||
elseif ($_formData['filemode'] == egw_sharing::ATTACH)
|
||||
{
|
||||
if (isset($attachment['file']) && parse_url($attachment['file'],PHP_URL_SCHEME) == 'vfs')
|
||||
{
|
||||
@ -2230,26 +2224,17 @@ class mail_compose
|
||||
* We only care about file attachments, not forwarded messages or parts
|
||||
*
|
||||
* @param array $attachments
|
||||
* @param string $filemode 'attach', 'link', 'share_ro', 'share_rw'
|
||||
* @param string $filemode egw_sharing::(ATTACH|LINK|READONL|WRITABLE)
|
||||
* @param boolean $html
|
||||
* @param array $recipients =array()
|
||||
* @param string $expiration =null
|
||||
* @param string $password =null
|
||||
* @return string might be empty if no file attachments found
|
||||
*/
|
||||
protected function getAttachmentLinks(array $attachments, $filemode, $html, $recipients=array())
|
||||
protected function getAttachmentLinks(array $attachments, $filemode, $html, $recipients=array(), $expiration=null, $password=null)
|
||||
{
|
||||
switch ($filemode)
|
||||
{
|
||||
case 'attach':
|
||||
return '';
|
||||
if ($filemode == egw_sharing::ATTACH) return '';
|
||||
|
||||
case 'links':
|
||||
case 'share_ro':
|
||||
$func = 'egw_sharing::create';
|
||||
break;
|
||||
|
||||
case 'share_rw':
|
||||
$func = 'stylite_sharing::create';
|
||||
break;
|
||||
}
|
||||
$links = array();
|
||||
foreach($attachments as $attachment)
|
||||
{
|
||||
@ -2259,18 +2244,28 @@ class mail_compose
|
||||
{
|
||||
$path = $GLOBALS['egw_info']['server']['temp_dir'].SEP.basename($path);
|
||||
}
|
||||
$share = call_user_func($func, $path, $attachment['name'], $filemode, $recipients);
|
||||
// create share
|
||||
if ($filemode == egw_sharing::WRITABLE || $expiration || $password)
|
||||
{
|
||||
$share = stylite_sharing::create($path, $filemode, $attachment['name'], $recipients, $expiration, $password);
|
||||
}
|
||||
else
|
||||
{
|
||||
$share = egw_sharing::create($path, $filemode, $attachment['name'], $recipients);
|
||||
}
|
||||
$link = egw_sharing::share2link($share);
|
||||
|
||||
$name = egw_vfs::basename($attachment['name'] ? $attachment['name'] : $attachment['file']);
|
||||
|
||||
if ($html)
|
||||
{
|
||||
$links[] = html::a_href($name, $link).' '.egw_vfs::hsize($attachment['size']);
|
||||
$links[] = html::a_href($name, $link).' '.
|
||||
(is_dir($path) ? lang('Directory') : egw_vfs::hsize($attachment['size']));
|
||||
}
|
||||
else
|
||||
{
|
||||
$links[] = $name.' '.egw_vfs::hsize($attachment['size']).': '.$link;
|
||||
$links[] = $name.' '.egw_vfs::hsize($attachment['size']).': '.
|
||||
(is_dir($path) ? lang('Directory') : $link);
|
||||
}
|
||||
}
|
||||
if (!$links)
|
||||
|
@ -4127,8 +4127,8 @@ app.classes.mail = AppJS.extend(
|
||||
if (!_widget) _widget = this.et2.getWidgetById('filemode');
|
||||
|
||||
var extended_settings = _widget.get_value() != 'attach' && this.egw.app('stylite');
|
||||
this.et2.getWidgetById('share_expiration').set_readonly(!extended_settings);
|
||||
this.et2.getWidgetById('share_password').set_readonly(!extended_settings);
|
||||
this.et2.getWidgetById('expiration').set_readonly(!extended_settings);
|
||||
this.et2.getWidgetById('password').set_readonly(!extended_settings);
|
||||
|
||||
if (_widget.get_value() == 'share_rw' && !this.egw.app('stylite'))
|
||||
{
|
||||
|
@ -382,7 +382,7 @@ div.mailUploadSection > div.et2_hbox > label {
|
||||
#mail-compose_filemode {
|
||||
margin-left: 6px;
|
||||
}
|
||||
#mail-compose_share_expiration > input {
|
||||
#mail-compose_expiration > input {
|
||||
min-width: 15ex;
|
||||
}
|
||||
#mail-compose_selectFromVFSForCompose{
|
||||
|
@ -114,8 +114,8 @@
|
||||
<vbox class="et2_file mailUploadSection" disabled="@no_griddata">
|
||||
<hbox>
|
||||
<select id="filemode" label="Send files as" onchange="app.mail.check_sharing_filemode"/>
|
||||
<date id="share_expiration" label="Expiration"/>
|
||||
<passwd id="share_password" blur="password protect"/>
|
||||
<date id="expiration" label="Expiration" blur="EPL only" data_format="Y-m-d"/>
|
||||
<passwd id="password" blur="password protect" statustext="Only makes sense, if you transport password through a different channel / outside of this mail to recipients!"/>
|
||||
</hbox>
|
||||
<grid id="attachments" width="100%" maxheight="165" class="egwGridView_grid">
|
||||
<columns>
|
||||
|
@ -379,7 +379,7 @@ div.mailUploadSection > div.et2_hbox > label {
|
||||
#mail-compose_filemode {
|
||||
margin-left: 6px;
|
||||
}
|
||||
#mail-compose_share_expiration > input {
|
||||
#mail-compose_expiration > input {
|
||||
min-width: 15ex;
|
||||
}
|
||||
#mail-compose_selectFromVFSForCompose {
|
||||
|
@ -20,7 +20,6 @@
|
||||
* @todo handle existing user sessions eg. by mounting share under it's token into vfs and redirect to regular filemanager
|
||||
* @todo handle mounts inside shared directory (they get currently lost)
|
||||
* @todo handle absolute symlinks (wont work as we use share as root)
|
||||
* @todo use sharing instead of attachments in mail app
|
||||
*/
|
||||
class egw_sharing
|
||||
{
|
||||
@ -48,6 +47,38 @@ class egw_sharing
|
||||
*/
|
||||
protected $share;
|
||||
|
||||
/**
|
||||
* Modes ATTACH is NOT a sharing mode, but it is traditional mode in email
|
||||
*/
|
||||
const ATTACH = 'attach';
|
||||
const LINK = 'link';
|
||||
const READONLY = 'share_ro';
|
||||
const WRITABLE = 'share_rw';
|
||||
|
||||
/**
|
||||
* Modes for sharing files
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $modes = array(
|
||||
self::ATTACH => array(
|
||||
'label' => 'Attachment',
|
||||
'title' => 'Works reliable for total size up to 1-2 MB, might work for 5-10 MB, most likely to fail for >10MB',
|
||||
),
|
||||
self::LINK => array(
|
||||
'label' => 'Download link',
|
||||
'title' => 'Link is appended to mail allowing recipients to download currently attached version of files',
|
||||
),
|
||||
self::READONLY => array(
|
||||
'label' => 'Readonly share',
|
||||
'title' => 'Link is appended to mail allowing recipients to download up to date version of files',
|
||||
),
|
||||
self::WRITABLE => array(
|
||||
'label' => 'Writable share',
|
||||
'title' => 'Link is appended to mail allowing recipients to download or modify up to date version of files (EPL only)'
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Protected constructor called via self::create_session
|
||||
*
|
||||
@ -204,8 +235,9 @@ class egw_sharing
|
||||
* Create a new share
|
||||
*
|
||||
* @param string $path either path in temp_dir or vfs with optional vfs scheme
|
||||
* @param string $mode 'link': copy file in users tmp-dir or 'share_ro' share given vfs file, if no vfs behave as 'link'
|
||||
* @param string $name filename to use for $mode='link', default basename of $path
|
||||
* @param string $mode self::LINK: copy file in users tmp-dir or self::READABLE share given vfs file,
|
||||
* if no vfs behave as self::LINK
|
||||
* @param string $name filename to use for $mode==self::LINK, default basename of $path
|
||||
* @param string|array $recipients one or more recipient email addresses
|
||||
* @param array $extra =array() extra data to store
|
||||
* @throw egw_exception_not_found if $path not found
|
||||
@ -224,7 +256,7 @@ class egw_sharing
|
||||
$temp_dir = $GLOBALS['egw_info']['server']['temp_dir'].'/';
|
||||
if (substr($path, 0, strlen($temp_dir)) == $temp_dir)
|
||||
{
|
||||
$mode = 'link';
|
||||
$mode = self::LINK;
|
||||
}
|
||||
elseif(parse_url($path, PHP_URL_SCHEME) !== 'vfs')
|
||||
{
|
||||
@ -236,28 +268,28 @@ class egw_sharing
|
||||
throw new egw_exception_not_found("'$path' NOT found!");
|
||||
}
|
||||
// check if file has been shared before
|
||||
if (($mode != 'link' || isset($path2tmp[$path])) &&
|
||||
if (($mode != self::LINK || isset($path2tmp[$path])) &&
|
||||
($share = self::$db->select(self::TABLE, '*', array(
|
||||
'share_path' => $mode == 'link' ? $path2tmp[$path] : egw_vfs::parse_url($path, PHP_URL_PATH),
|
||||
'share_owner' => $GLOBALS['egw_info']['user']['account_id'],
|
||||
)+$extra, __LINE__, __FILE__)->fetch()))
|
||||
{
|
||||
// if yes, just add additional recipients
|
||||
$share['share_recipients'] = $share['share_recipients'] ? explode(',', $share['recipients']) : array();
|
||||
$share['share_with'] = $share['share_with'] ? explode(',', $share['share_with']) : array();
|
||||
$need_save = false;
|
||||
foreach((array)$recipients as $recipient)
|
||||
{
|
||||
if (!in_array($recipient, $share['recipients']))
|
||||
if (!in_array($recipient, $share['share_with']))
|
||||
{
|
||||
$share['recipients'][] = $recipient;
|
||||
$share['share_with'][] = $recipient;
|
||||
$need_save = true;
|
||||
}
|
||||
}
|
||||
$share['share_recipients'] = implode(',', $share['recipients']);
|
||||
$share['share_with'] = implode(',', $share['share_with']);
|
||||
if ($need_save)
|
||||
{
|
||||
self::$db->update(self::TABLE, array(
|
||||
'share_recipients' => $share['share_recipients'],
|
||||
'share_with' => $share['share_with'],
|
||||
), array(
|
||||
'share_id' => $share['share_id'],
|
||||
), __LINE__, __FILE__);
|
||||
@ -276,15 +308,18 @@ class egw_sharing
|
||||
$n = 0;
|
||||
do {
|
||||
$tmp_file = egw_vfs::concat($user_tmp, ($n?$n.'.':'').egw_vfs::basename($name));
|
||||
} while(!($fp = egw_vfs::fopen($tmp_file, 'x')) && $n++ < 100);
|
||||
}
|
||||
while(!(is_dir($path) && egw_vfs::mkdir($tmp_file) ||
|
||||
!is_dir($path) && ($fp = egw_vfs::fopen($tmp_file, 'x'))) && $n++ < 100);
|
||||
|
||||
if ($n >= 100)
|
||||
{
|
||||
throw new egw_exception_assertion_failed("Could NOT create temp. file '$tmp_file'!");
|
||||
}
|
||||
fclose($fp);
|
||||
if ($fp) fclose($fp);
|
||||
|
||||
if (!copy($path, egw_vfs::PREFIX.$tmp_file))
|
||||
if (is_dir($path) && !egw_vfs::copy_files(array($path), $tmp_file) ||
|
||||
!is_dir($path) && !copy($path, egw_vfs::PREFIX.$tmp_file))
|
||||
{
|
||||
throw new egw_exception_assertion_failed("Could NOT create temp. file '$tmp_file'!");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user