* Filemanager/FMail/Calendar: allow to open .eml and .ics files from filemanager in fmail or calendar (infrastructure for apps to register which mime-types they can open)

This commit is contained in:
Ralf Becker 2012-03-08 18:43:40 +00:00
parent 96271ea210
commit dd8a5cf29e
5 changed files with 128 additions and 34 deletions

View File

@ -41,6 +41,13 @@ class calendar_hooks
'add_popup' => '750x400',
'file_access' => 'calendar.calendar_bo.file_access',
'file_access_user' => true, // file_access supports 4th parameter $user
'mime' => array(
'text/calendar' => array(
'menuaction' => 'calendar.calendar_uiforms.edit',
'mime_id' => 'ical_vfs',
'mime_popup' => '750x400',
),
),
);
}

View File

@ -1121,27 +1121,11 @@ class calendar_uiforms extends calendar_ui
'template' => isset($_GET['template']) ? $_GET['template'] : (isset($_REQUEST['print']) ? 'calendar.print' : 'calendar.edit'),
);
$cal_id = (int) $_GET['cal_id'];
if (!$cal_id && empty($_GET['ical']) || $cal_id && !($event = $this->bo->read($cal_id)))
{
if ($cal_id)
{
if (!$preserv['no_popup'])
{
$js = "alert('".lang('Permission denied')."'); window.close();";
}
else
{
$GLOBALS['egw']->framework->render('<p class="redItalic" align="center">'.lang('Permission denied')."</p>\n",null,true);
common::egw_exit();
}
}
$event =& $this->default_add_event();
}
elseif (!empty($_GET['ical']))
if (!empty($_GET['ical']) || !empty($_GET['ical_vfs']) && egw_vfs::file_exists($_GET['ical_vfs']))
{
$ical = new calendar_ical();
if (!($events = $ical->icaltoegw($_GET['ical'], '', 'utf-8')) || count($events) != 1)
$ical_string = !empty($_GET['ical']) ? $_GET['ical'] : file_get_contents(egw_vfs::PREFIX.$_GET['ical_vfs']);
if (!($events = $ical->icaltoegw($ical_string, '', 'utf-8')) || count($events) != 1)
{
error_log(__METHOD__."('$_GET[ical]') error parsing iCal!");
$msg = lang('Error: importing the iCal');
@ -1166,6 +1150,23 @@ class calendar_uiforms extends calendar_ui
//error_log(__METHOD__."(...) parsed as ".array2string($event));
}
unset($ical);
unset($ical_string);
}
elseif (!$cal_id || $cal_id && !($event = $this->bo->read($cal_id)))
{
if ($cal_id)
{
if (!$preserv['no_popup'])
{
$js = "alert('".lang('Permission denied')."'); window.close();";
}
else
{
$GLOBALS['egw']->framework->render('<p class="redItalic" align="center">'.lang('Permission denied')."</p>\n",null,true);
common::egw_exit();
}
}
$event =& $this->default_add_event();
}
else
{

View File

@ -228,17 +228,18 @@ class vfs_widget
break;
}
}
$popup = null;
if (egw_vfs::is_readable($path)) // show link only if we have access to the file or dir
{
if ($n < count($comps)-1 || $mime == egw_vfs::DIR_MIME_TYPE || egw_vfs::is_dir($path))
{
$value['l'.$n] = '/index.php?menuaction=filemanager.filemanager_ui.index&path='.urlencode($path);
$value['l'.$n] = egw_link::mime_open($path, egw_vfs::DIR_MIME_TYPE, $popup);
$target = '';
}
else
{
$value['l'.$n] = egw_vfs::download_url($path);
$target = ',,,_blank';
$value['l'.$n] = egw_link::mime_open($path, $mime, $popup);
$target = '_blank';
}
}
@ -255,7 +256,7 @@ class vfs_widget
else
{
$comp = etemplate::empty_cell('label',$cell_name.'[c'.$n.']',array(
'size' => ',@'.$cell_name.'[l'.$n.']'.$target,
'size' => ',@'.$cell_name.'[l'.$n.'],,,'.$target.','.$popup,
'no_lang' => true,
'span' => ',vfsFilename',
));

View File

@ -352,15 +352,5 @@ function nm_activate_link(_action, _senders)
{
// $j(_senders[0].iface.getDOMNode()).find('a:first').trigger('click'); not sure why this is NOT working
var a_href = $j(_senders[0].iface.getDOMNode()).find('a:first');
if (typeof a_href != undefined)
{
var target = a_href.attr('target');
var href = a_href.attr('href');
if (target)
window.open(href,target);
else
window.location = href;
}
$j(_senders[0].iface.getDOMNode()).find('a:first').click();
}

View File

@ -69,6 +69,19 @@
* 'edit_popup' => '400x300',
* 'name' => 'Some name', // Name to use instead of app-name
* 'icon' => 'app/icon', // Optional icon to use instead of app-icon
* 'mime' => array( // Optional register mime-types application can open
* 'text/something' => array(
* 'mime_id' => 'path', // one of id (path) or url is required!
* 'mime_url' => 'url',
* 'menuaction' => 'app.class.method', // method to call
* 'mime_popup' => '400x300', // optional size of popup
* 'mime_name' => 'name', // optional name of get-parameter for name-part of path
* 'mime_type' => 'type', // ... for mime-type
* 'mime_size' => 'size', // ... for size
* // other get-parameters to set in url
* ),
* // further mime types supported ...
* ),
* 'additional' => array( // allow one app to register sub-types,
* 'app-sub' => array( // different from 'types' approach above
* // every value defined above
@ -888,6 +901,88 @@ class egw_link extends solink
return $view;
}
/**
* Get mime-type information from app-registry
*
* @param string $type
* @return array with values for keys 'menuaction', 'mime_id' (path) or 'mime_url' and options 'mime_popup' and other values to pass one
*/
static function get_mime_info($type)
{
foreach(self::$app_register as $app => $registry)
{
if (isset($registry['mime']))
{
foreach($registry['mime'] as $mime => $data)
{
if ($mime == $type) return $data;
}
}
}
return null;
}
/**
* Get handler (link-data) for given path and mime-type
*
* @param string $path vfs path
* @param string $type=null default to egw_vfs::mime_content_type($path)
* @param string &$popup=null on return popup size or null
* @return string|array string with EGw relative link, array with get-parameters for '/index.php' or null (directory and not filemanager access)
*/
static function mime_open($path, $type=null, &$popup=null)
{
if (is_null($type)) $type = egw_vfs::mime_content_type($path);
if (($data = self::get_mime_info($type)))
{
if (isset($data['mime_url']))
{
$data[$data['mime_url']] = egw_vfs::PREFIX.$path;
unset($data['mime_url']);
}
elseif (isset($data['mime_id']))
{
$data[$data['mime_id']] = $path;
unset($data['mime_id']);
}
else
{
throw egw_exception_assertion_failed("Missing 'mime_id' or 'mime_url' for mime-type '$type'!");
}
// some optional values fmail needs ...
foreach(array(
'mime_type' => $type,
'mime_size' => null, // filesize(egw_vfs::PREFIX.$path),
'mime_name' => basename($path),
) as $name => $value)
{
if (isset($data[$name]))
{
$data[$data[$name]] = $name == 'mime_size' ? filesize(egw_vfs::PREFIX.$path) : $value;
unset($data[$name]);
}
}
$popup = $data['mime_popup'];
unset($data['mime_popup']);
}
elseif ($type == egw_vfs::DIR_MIME_TYPE)
{
if (isset($GLOBALS['egw_info']['user']['apps']['filemanager']))
{
$data = array(
'menuaction' => 'filemanager.filemanager_ui.index',
'path' => $path,
);
}
}
else
{
$data = egw_vfs::download_url($path);
}
return $data;
}
/**
* Check if $app uses a popup for $action
*