/**
* translate a string
* @param app the id of the app for which to translate the string
* @param text the string to translate
* @return string
*/
function t(app,text, vars){
if( !( t.cache[app] )){
$.ajax(OC.filePath('core','ajax','translations.php'),{
async:false,//todo a proper sollution for this without sync ajax calls
data:{'app': app},
type:'POST',
success:function(jsondata){
t.cache[app] = jsondata.data;
}
});
// Bad answer ...
if( !( t.cache[app] )){
t.cache[app] = [];
}
}
var _build = function(text, vars) {
return text.replace(/{([^{}]*)}/g,
function (a, b) {
var r = vars[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
);
}
if( typeof( t.cache[app][text] ) !== 'undefined' ){
if(typeof vars === 'object') {
return _build(t.cache[app][text], vars);
} else {
return t.cache[app][text];
}
}
else{
if(typeof vars === 'object') {
return _build(text, vars);
} else {
return text;
}
}
}
t.cache={};
/*
* Sanitizes a HTML string
* @param string
* @return Sanitized string
*/
function escapeHTML(s) {
return s.toString().split('&').join('&').split('<').join('<').split('"').join('"');
}
/**
* Get the path to download a file
* @param file The filename
* @param dir The directory the file is in - e.g. $('#dir').val()
* @return string
*/
function fileDownloadPath(dir, file) {
return OC.filePath('files', 'ajax', 'download.php')+'?files='+encodeURIComponent(file)+'&dir='+encodeURIComponent(dir);
}
var OC={
PERMISSION_CREATE:4,
PERMISSION_READ:1,
PERMISSION_UPDATE:2,
PERMISSION_DELETE:8,
PERMISSION_SHARE:16,
webroot:oc_webroot,
appswebroots:oc_appswebroots,
currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false,
coreApps:['', 'admin','log','search','settings','core','3rdparty'],
/**
* get an absolute url to a file in an appen
* @param app the id of the app the file belongs to
* @param file the file path relative to the app folder
* @return string
*/
linkTo:function(app,file){
return OC.filePath(app,'',file);
},
/**
* get the absolute url for a file in an app
* @param app the id of the app
* @param type the type of the file to link to (e.g. css,img,ajax.template)
* @param file the filename
* @return string
*/
filePath:function(app,type,file){
var isCore=OC.coreApps.indexOf(app)!==-1,
link=OC.webroot;
if((file.substring(file.length-3) === 'php' || file.substring(file.length-3) === 'css') && !isCore){
link+='/index.php/apps/' + app;
if (file != 'index.php') {
link+='/';
if(type){
link+=encodeURI(type + '/');
}
link+= file;
}
}else if(file.substring(file.length-3) !== 'php' && !isCore){
link=OC.appswebroots[app];
if(type){
link+= '/'+type+'/';
}
if(link.substring(link.length-1) !== '/'){
link+='/';
}
link+=file;
}else{
if ((app == 'settings' || app == 'core' || app == 'search') && type == 'ajax') {
link+='/index.php/';
}
else {
link+='/';
}
if(!isCore){
link+='apps/';
}
if (app !== '') {
app+='/';
link+=app;
}
if(type){
link+=type+'/';
}
link+=file;
}
return link;
},
/**
* get the absolute path to an image file
* @param app the app id to which the image belongs
* @param file the name of the image file
* @return string
*
* if no extension is given for the image, it will automatically decide between .png and .svg based on what the browser supports
*/
imagePath:function(app,file){
if(file.indexOf('.')==-1){//if no extension is given, use png or svg depending on browser support
file+=(SVGSupport())?'.svg':'.png';
}
return OC.filePath(app,'img',file);
},
/**
* load a script for the server and load it
* @param app the app id to which the script belongs
* @param script the filename of the script
* @param ready event handeler to be called when the script is loaded
*
* if the script is already loaded, the event handeler will be called directly
*/
addScript:function(app,script,ready){
var deferred, path=OC.filePath(app,'js',script+'.js');
if(!OC.addScript.loaded[path]){
if(ready){
deferred=$.getScript(path,ready);
}else{
deferred=$.getScript(path);
}
OC.addScript.loaded[path]=deferred;
}else{
if(ready){
ready();
}
}
return OC.addScript.loaded[path];
},
/**
* load a css file and load it
* @param app the app id to which the css style belongs
* @param style the filename of the css file
*/
addStyle:function(app,style){
var path=OC.filePath(app,'css',style+'.css');
if(OC.addStyle.loaded.indexOf(path)===-1){
OC.addStyle.loaded.push(path);
style=$('');
$('head').append(style);
}
},
basename: function(path) {
return path.replace(/\\/g,'/').replace( /.*\//, '' );
},
dirname: function(path) {
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
},
/**
* do a search query and display the results
* @param query the search query
*/
search:function(query){
if(query){
OC.addStyle('search','results');
$.getJSON(OC.filePath('search','ajax','search.php')+'?query='+encodeURIComponent(query), function(results){
OC.search.lastResults=results;
OC.search.showResults(results);
});
}
},
dialogs:OCdialogs,
mtime2date:function(mtime) {
mtime = parseInt(mtime,10);
var date = new Date(1000*mtime);
return date.getDate()+'.'+(date.getMonth()+1)+'.'+date.getFullYear()+', '+date.getHours()+':'+date.getMinutes();
},
/**
* Opens a popup with the setting for an app.
* @param appid String. The ID of the app e.g. 'calendar', 'contacts' or 'files'.
* @param loadJS boolean or String. If true 'js/settings.js' is loaded. If it's a string
* it will attempt to load a script by that name in the 'js' directory.
* @param cache boolean. If true the javascript file won't be forced refreshed. Defaults to true.
* @param scriptName String. The name of the PHP file to load. Defaults to 'settings.php' in
* the root of the app directory hierarchy.
*/
appSettings:function(args) {
if(typeof args === 'undefined' || typeof args.appid === 'undefined') {
throw { name: 'MissingParameter', message: 'The parameter appid is missing' };
}
var props = {scriptName:'settings.php', cache:true};
$.extend(props, args);
var settings = $('#appsettings');
if(settings.length == 0) {
throw { name: 'MissingDOMElement', message: 'There has be be an element with id "appsettings" for the popup to show.' };
}
var popup = $('#appsettings_popup');
if(popup.length == 0) {
$('body').prepend('