2012-03-01 17:24:29 +01:00
|
|
|
/**
|
|
|
|
* EGroupware clientside API object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Andreas Stöckel (as AT stylite.de)
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
egw_core;
|
|
|
|
*/
|
2021-06-05 20:39:39 +02:00
|
|
|
import './egw_core.js';
|
2012-03-01 17:24:29 +01:00
|
|
|
|
2016-02-29 16:50:24 +01:00
|
|
|
egw.extend('images', egw.MODULE_GLOBAL, function()
|
|
|
|
{
|
|
|
|
"use strict";
|
2012-03-01 17:24:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map to serverside available images for users template-set
|
2013-11-15 17:28:24 +01:00
|
|
|
*
|
2012-03-01 17:24:29 +01:00
|
|
|
* @access: private, use egw.image(_name, _app)
|
|
|
|
*/
|
|
|
|
var images = {};
|
|
|
|
|
2015-01-11 19:06:13 +01:00
|
|
|
/**
|
|
|
|
* Mapping some old formats to the newer form, or any other aliasing for mime-types
|
|
|
|
*
|
|
|
|
* Should be in sync with ../inc/class.mime_magic.inc.php
|
|
|
|
*/
|
|
|
|
var mime_alias_map = {
|
|
|
|
'text/vcard': 'text/x-vcard',
|
|
|
|
'text/comma-separated-values': 'text/csv',
|
|
|
|
'text/rtf': 'application/rtf',
|
|
|
|
'text/xml': 'application/xml',
|
|
|
|
'text/x-diff': 'text/diff',
|
|
|
|
'application/x-jar': 'application/java-archive',
|
|
|
|
'application/x-javascript': 'application/javascript',
|
|
|
|
'application/x-troff': 'text/troff',
|
|
|
|
'application/x-egroupware-etemplate': 'application/xml'
|
|
|
|
};
|
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
return {
|
|
|
|
/**
|
2016-04-06 21:57:40 +02:00
|
|
|
* Set imagemap, called from /api/images.php
|
2013-11-15 17:28:24 +01:00
|
|
|
*
|
2014-12-11 10:57:31 +01:00
|
|
|
* @param {array|object} _images
|
2015-02-02 20:49:18 +01:00
|
|
|
* @param {boolean} _need_clone _images need to be cloned, as it is from different window context
|
|
|
|
* and therefore will be inaccessible in IE, after that window is closed
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
2015-02-02 20:49:18 +01:00
|
|
|
set_images: function (_images, _need_clone)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
2015-02-02 20:49:18 +01:00
|
|
|
images = _need_clone ? jQuery.extend(true, {}, _images) : _images;
|
2012-03-01 17:24:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get image URL for a given image-name and application
|
2013-11-15 17:28:24 +01:00
|
|
|
*
|
2014-12-11 10:57:31 +01:00
|
|
|
* @param {string} _name image-name without extension
|
|
|
|
* @param {string} _app application name, default current app of window
|
2012-03-01 17:24:29 +01:00
|
|
|
* @return string with URL of image
|
|
|
|
*/
|
|
|
|
image: function (_name, _app)
|
|
|
|
{
|
|
|
|
// For logging all paths tried
|
|
|
|
var tries = {};
|
|
|
|
|
2012-03-07 15:04:25 +01:00
|
|
|
if (typeof _app === 'undefined')
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
2012-03-07 15:04:25 +01:00
|
|
|
// If the application name is not given, set it to the name of
|
|
|
|
// current application
|
|
|
|
_app = this.getAppName();
|
2023-04-19 17:50:57 +02:00
|
|
|
}
|
2012-03-07 15:04:25 +01:00
|
|
|
|
2023-04-19 17:50:57 +02:00
|
|
|
// Handle images in appname/imagename format
|
|
|
|
if(_name.indexOf('/') > 0)
|
|
|
|
{
|
2024-08-28 14:51:54 +02:00
|
|
|
var split = _name.match(/^([^/]+)\/(.*)$/);
|
|
|
|
// e.g. dhtmlxtree and egw_action are subdirs in image dir, not applications
|
|
|
|
if (typeof images[split[1]] !== 'undefined')
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
2024-08-28 14:51:54 +02:00
|
|
|
_app = split[1];
|
|
|
|
_name = split[2];
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
}
|
2013-11-15 17:28:24 +01:00
|
|
|
|
2024-08-07 18:28:28 +02:00
|
|
|
// own instance specific images in vfs have the highest precedence
|
2012-03-01 17:24:29 +01:00
|
|
|
tries['vfs']=_name;
|
2016-05-04 15:57:26 +02:00
|
|
|
if (typeof images['vfs'] != 'undefined' && typeof images['vfs'][_name] == 'string')
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
return this.webserverUrl+images['vfs'][_name];
|
|
|
|
}
|
2024-08-25 11:48:19 +02:00
|
|
|
if (_app !== 'api')
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
2024-08-25 11:48:19 +02:00
|
|
|
tries['global'] = _app+'/'+_name;
|
|
|
|
if (typeof images['global'] !== 'undefined' && typeof images['global'][_app+'/'+_name] === 'string' &&
|
|
|
|
typeof images['bootstrap'] !== 'undefined' && typeof images['bootstrap'][images['global'][_app+'/'+_name]] == 'string')
|
|
|
|
{
|
|
|
|
return this.webserverUrl+images['bootstrap'][images['global'][_app+'/'+_name]];
|
|
|
|
}
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
2024-08-07 18:28:28 +02:00
|
|
|
tries['global'] = _name;
|
2024-08-25 12:15:35 +02:00
|
|
|
if (_name !== 'navbar' && // do NOT overwrite navbar images of all apps with placeholder
|
2024-08-27 11:03:47 +02:00
|
|
|
typeof images['global'] !== 'undefined' && typeof images['global'][_name] === 'string')
|
2024-08-07 18:28:28 +02:00
|
|
|
{
|
2024-08-27 11:03:47 +02:00
|
|
|
if (typeof images['bootstrap'] !== 'undefined' && typeof images['bootstrap'][images['global'][_name]] == 'string')
|
|
|
|
{
|
|
|
|
return this.webserverUrl+images['bootstrap'][images['global'][_name]];
|
|
|
|
}
|
|
|
|
// global replaces image with non-bootstrap image like {"save": "api/save"} to NOT use bootstrap's "save" icon
|
|
|
|
if (images['global'][_name].indexOf('/') !== -1)
|
|
|
|
{
|
|
|
|
const split = images['global'][_name].split('/',2);
|
|
|
|
_app = split[0];
|
|
|
|
_name = split[1];
|
|
|
|
}
|
2024-08-07 18:28:28 +02:00
|
|
|
}
|
2024-08-27 19:15:25 +02:00
|
|
|
// do NOT find old mime128-icons, if not translated to bootstrap
|
|
|
|
if (_name.startsWith('mime128_'))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2024-08-25 11:48:19 +02:00
|
|
|
tries[_app + (_app == 'phpgwapi' ? " (current app)" : "")] = _name;
|
|
|
|
if (typeof images[_app] != 'undefined' && typeof images[_app][_name] == 'string')
|
|
|
|
{
|
|
|
|
return this.webserverUrl+images[_app][_name];
|
|
|
|
}
|
2024-08-07 18:28:28 +02:00
|
|
|
tries['bootstrap'] = _name;
|
|
|
|
if (typeof images['bootstrap'] !== 'undefined' && typeof images['bootstrap'][_name] == 'string')
|
|
|
|
{
|
|
|
|
return this.webserverUrl+images['bootstrap'][_name];
|
|
|
|
}
|
2016-05-05 11:16:27 +02:00
|
|
|
tries['api'] = _name;
|
|
|
|
if (typeof images['api'] != 'undefined' && typeof images['api'][_name] == 'string')
|
|
|
|
{
|
|
|
|
return this.webserverUrl+images['api'][_name];
|
|
|
|
}
|
2012-03-01 17:24:29 +01:00
|
|
|
tries['phpgwapi'] = _name;
|
2016-05-04 15:57:26 +02:00
|
|
|
if (typeof images['phpgwapi'] != 'undefined' && typeof images['phpgwapi'][_name] == 'string')
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
return this.webserverUrl+images['phpgwapi'][_name];
|
|
|
|
}
|
|
|
|
// if no match, check if it might contain an extension
|
2014-12-11 10:57:31 +01:00
|
|
|
var matches = _name.match(/\.(png|gif|jpg)$/i);
|
|
|
|
if (matches)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
return this.image(_name.replace(/.(png|gif|jpg)$/i,''), _app);
|
|
|
|
}
|
|
|
|
if(matches != null) tries[_app + " (matched)"]= matches;
|
2014-01-10 16:57:02 +01:00
|
|
|
egw.debug("log",'egw.image("'+_name+'", "'+_app+'") image NOT found! Tried ', tries);
|
2012-03-01 17:24:29 +01:00
|
|
|
return null;
|
2012-03-28 10:10:57 +02:00
|
|
|
},
|
2013-11-15 17:28:24 +01:00
|
|
|
|
2012-03-28 10:10:57 +02:00
|
|
|
/**
|
|
|
|
* Get image url for a given mime-type and option file
|
2013-11-15 17:28:24 +01:00
|
|
|
*
|
2014-12-11 10:57:31 +01:00
|
|
|
* @param {string} _mime
|
|
|
|
* @param {string} _path vfs path to generate thumbnails for images
|
2015-01-11 19:06:13 +01:00
|
|
|
* @param {number} _size defaults to 128 (only supported size currently)
|
2015-02-13 09:27:08 +01:00
|
|
|
* @param {number} _mtime current modification time of file to allow infinit caching as url changes
|
2012-03-28 10:10:57 +02:00
|
|
|
* @returns url of image
|
|
|
|
*/
|
2015-02-13 09:27:08 +01:00
|
|
|
mime_icon: function(_mime, _path, _size, _mtime)
|
2012-03-28 10:10:57 +02:00
|
|
|
{
|
2015-01-11 19:06:13 +01:00
|
|
|
if (typeof _size == 'undefined') _size = 128;
|
2012-03-28 10:10:57 +02:00
|
|
|
if (!_mime) _mime = 'unknown';
|
|
|
|
if (_mime == 'httpd/unix-directory') _mime = 'directory';
|
2013-11-15 17:28:24 +01:00
|
|
|
|
2012-03-28 10:10:57 +02:00
|
|
|
var type = _mime.toLowerCase().split('/');
|
2014-12-11 10:57:31 +01:00
|
|
|
var image = type[0] == 'egw' ? this.image('navbar',type[1]) : undefined;
|
2013-11-15 17:28:24 +01:00
|
|
|
|
2014-12-11 10:57:31 +01:00
|
|
|
if (image)
|
2012-03-28 10:10:57 +02:00
|
|
|
{
|
2013-11-15 17:28:24 +01:00
|
|
|
|
2012-03-28 10:10:57 +02:00
|
|
|
}
|
2015-01-02 20:43:50 +01:00
|
|
|
else if (typeof _path == 'string' && (type[0] == 'image' && type[1].match(/^(png|jpe?g|gif|bmp)$/) ||
|
2015-02-25 19:07:21 +01:00
|
|
|
type[0] == 'application' && (
|
|
|
|
// Open Document
|
|
|
|
type[1].indexOf('vnd.oasis.opendocument.') === 0 ||
|
|
|
|
// PDF
|
|
|
|
type[1] == 'pdf' ||
|
|
|
|
// Microsoft
|
|
|
|
type[1].indexOf('vnd.openxmlformats-officedocument.') === 0
|
|
|
|
)
|
|
|
|
))
|
2012-03-28 10:10:57 +02:00
|
|
|
{
|
2015-02-13 09:27:08 +01:00
|
|
|
var params = { 'path': _path, 'thsize': this.config('link_list_thumbnail') || 64};
|
|
|
|
if (_mtime) params.mtime = _mtime;
|
2016-04-06 21:39:49 +02:00
|
|
|
image = this.link('/api/thumbnail.php', params);
|
2012-03-28 10:10:57 +02:00
|
|
|
}
|
2016-02-29 14:05:48 +01:00
|
|
|
// for svg return image itself
|
2021-04-28 20:00:02 +02:00
|
|
|
else if (type[0] == 'image' && type[1] == 'svg+xml' && typeof _path == "string")
|
2016-02-29 14:05:48 +01:00
|
|
|
{
|
|
|
|
image = this.webserverUrl+'/webdav.php'+_path;
|
|
|
|
}
|
2012-03-28 10:10:57 +02:00
|
|
|
else
|
|
|
|
{
|
2015-01-11 19:06:13 +01:00
|
|
|
if ((typeof type[1] == 'undefined' || !(image = this.image('mime'+_size+'_'+type[0]+'_'+type[1], 'etemplate')) &&
|
2015-02-13 09:27:08 +01:00
|
|
|
!(typeof mime_alias_map[_mime] != 'undefined' && (image=this.mime_icon(mime_alias_map[_mime], _path, _size, _mtime)))) &&
|
2012-03-28 10:10:57 +02:00
|
|
|
!(image = this.image('mime'+_size+'_'+type[0], 'etemplate')))
|
|
|
|
{
|
|
|
|
image = this.image('mime'+_size+'_unknown', 'etemplate');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return image;
|
2014-01-14 17:07:39 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create DOM img or svn element depending on url
|
|
|
|
*
|
|
|
|
* @param {string} _url source url
|
|
|
|
* @param {string} _alt alt attribute for img tag
|
|
|
|
* @returns DOM node
|
|
|
|
*/
|
|
|
|
image_element: function(_url, _alt)
|
|
|
|
{
|
|
|
|
var icon;
|
2016-02-24 17:47:32 +01:00
|
|
|
icon = document.createElement('img');
|
|
|
|
if (_url) icon.src = _url;
|
|
|
|
if (_alt) icon.alt = _alt;
|
2014-01-14 17:07:39 +01:00
|
|
|
return icon;
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
2014-12-11 10:57:31 +01:00
|
|
|
};
|
2024-08-07 18:28:28 +02:00
|
|
|
});
|