From dd8a5cf29e5b7ed5ea913376136fc55ed2a3b8c6 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 8 Mar 2012 18:43:40 +0000 Subject: [PATCH] * 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) --- calendar/inc/class.calendar_hooks.inc.php | 7 ++ calendar/inc/class.calendar_uiforms.inc.php | 39 ++++----- etemplate/inc/class.vfs_widget.inc.php | 9 +- etemplate/js/nextmatch_action.js | 12 +-- phpgwapi/inc/class.egw_link.inc.php | 95 +++++++++++++++++++++ 5 files changed, 128 insertions(+), 34 deletions(-) diff --git a/calendar/inc/class.calendar_hooks.inc.php b/calendar/inc/class.calendar_hooks.inc.php index 412f65c1d1..fd31dd2c08 100644 --- a/calendar/inc/class.calendar_hooks.inc.php +++ b/calendar/inc/class.calendar_hooks.inc.php @@ -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', + ), + ), ); } diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index e9500d5116..7b7e331a0e 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -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('

'.lang('Permission denied')."

\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('

'.lang('Permission denied')."

\n",null,true); + common::egw_exit(); + } + } + $event =& $this->default_add_event(); } else { diff --git a/etemplate/inc/class.vfs_widget.inc.php b/etemplate/inc/class.vfs_widget.inc.php index 7cc5df1f31..9a2fbc1de7 100644 --- a/etemplate/inc/class.vfs_widget.inc.php +++ b/etemplate/inc/class.vfs_widget.inc.php @@ -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', )); diff --git a/etemplate/js/nextmatch_action.js b/etemplate/js/nextmatch_action.js index 9451a3dc7e..43203127e9 100644 --- a/etemplate/js/nextmatch_action.js +++ b/etemplate/js/nextmatch_action.js @@ -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(); } diff --git a/phpgwapi/inc/class.egw_link.inc.php b/phpgwapi/inc/class.egw_link.inc.php index d4063678c3..31be99a5b6 100644 --- a/phpgwapi/inc/class.egw_link.inc.php +++ b/phpgwapi/inc/class.egw_link.inc.php @@ -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 *