var theXoborVarVal = {}; if (!xobor) { var xobor = new function() { self = this; main = this; }; xobor['start'] = null; xobor['exec'] = null; xobor['plugin'] = null; xobor['helper'] = {}; xobor['updateDataVarStore'] = {}; xobor['global'] = {}; xobor['localCache'] = {}; xobor['config'] = {}; } xobor.start = function(require, callbackfn) { var defaultlibs = [ { name: 'jqueryui', test: function() {$( "#draggable" ).draggable();}, url: xobor_plugin_default_configs.libjs.jqueryui } ]; if (require && typeof require !== 'undefined' && require instanceof Array && require.length > 0) { var somethingfound = false; var toload = { require: {} }; for (var i = 0; i < require.length; i++) { for (var j = 0; j < defaultlibs.length; j++) { if (require[i] == defaultlibs[j]['name']) { somethingfound = true; toload.require[require[i]] = { test: defaultlibs[j]['test'], url: defaultlibs[j]['url'] } } } } if (somethingfound) { self.exec(toload, callbackfn); } else { callbackfn(); } } }; xobor.exec = function(config, callbackfn) { if(typeof config === 'undefined' || typeof callbackfn !== 'function') {main.log.add(1,'xobor.exec','Param error'); return false;} var eself = this; eself.need2LoadUrls = []; eself.loadlib = function(url, cbfn) { var script = document.createElement('script'); script.src = url; var head = document.getElementsByTagName('head')[0]; var done = false; head.appendChild(script); script.onload = script.onreadystatechange = function() { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { done = true; if (eself.need2LoadUrls.length === 0) { $(document).ready(function(){ cbfn(); }); } script.onload = script.onreadystatechange = null; head.removeChild(script); var nexturl = eself.need2LoadUrls.pop(); if (typeof nexturl !== 'undefined') { eself.loadlib(nexturl, cbfn); } } }; }; /* config['require'] = { jqueryui: { test: function() {$( "#draggable" ).draggable();}, url: '//code.jquery.com/ui/1.11.2/jquery-ui.js' } }; */ if (typeof config['require'] !== 'undefined' && config['require'] instanceof Object) { $.each(config['require'], function(key, val){ if (typeof val.test !== 'undefined' && typeof val.test === 'function') { try{ val.test(); } catch(e) { eself.need2LoadUrls.push(val.url); // eself.loadlib(val.url, callbackfn); } } }); if (eself.need2LoadUrls.length > 0) { eself.loadlib(eself.need2LoadUrls.pop(), callbackfn); } else { $(document).ready(function(){ callbackfn(); }); } } else { main.log.add(1,'xobor.exec','config[\'require\'] not found'); } }; xobor.plugin = function(pid, async) { var pself = this; pself.pluginID = (typeof pid !== 'undefined') ? pid : 'null'; pself.ajaxSync = (typeof async !== 'undefined') ? async : main.config.ajaxAsync; pself.ajaxUrl = '//' + window.location.hostname + '/ajax/pluginapi.php?pid='+ ((typeof pid !== 'undefined') ? pid : 'null'); pself.staticContent = (typeof xoborPluginData !== 'undefined') ? xoborPluginData : {}; pself.dynamicContent= (typeof theXoborVarVal !== 'undefined') ? theXoborVarVal : {}; return { localstorage: { localstorageprefix: 'xobor_plugin_'+pid+'_', get: function(key) { if(typeof(Storage) !== "undefined" && this.localstorageprefix) { var data = localStorage.getItem(this.localstorageprefix + key); try { var returnval = JSON.parse(data); if (returnval) { main.log.add(0, 'xobor.plugin.localstorage.get', 'get key ', key); return returnval; } else { main.log.add(2, 'xobor.plugin.localstorage.get', 'returnval is not a valid JSON-String: ', returnval); return false; } } catch (e) { var returnval = data; if (returnval) { main.log.add(1, 'xobor.plugin.localstorage.get', 'something goes wrong by parsing key: ', key); return returnval; } else { return false; } } } }, set: function(key, val) { if(typeof(Storage) !== "undefined" && this.localstorageprefix) { localStorage.setItem(this.localstorageprefix + key, JSON.stringify(val)); main.log.add(0, 'xobor.plugin.localstorage.set', 'save key: "'+key+'"'); return true; } main.log.add(3, 'xobor.plugin.localstorage.set', 'localStore is not defined or localstorageprefix is not set'); return false; }, del: function(key) { if(typeof(Storage) !== "undefined" && this.localstorageprefix) { localStorage.removeItem(this.localstorageprefix + key); main.log.add(0, 'xobor.plugin.localstorage.del', 'delete key: "'+key+'"'); return true; } main.log.add(3, 'xobor.plugin.localstorage.del', 'localStore is not defined or localstorageprefix is not set'); return false; } }, sessionstorage: { sessionstorageprefix: 'xobor_plugin_'+pid+'_', get: function(key) { if(typeof(Storage) !== "undefined" && this.sessionstorageprefix) { var data = sessionStorage.getItem(this.sessionstorageprefix + key); try { var returnval = JSON.parse(data); if (returnval) { main.log.add(0, 'xobor.plugin.sessionstorage.get', 'get key ', key); return returnval; } else { main.log.add(2, 'xobor.plugin.sessionstorage.get', 'returnval is not a valid JSON-String: ', returnval); return false; } } catch (e) { var returnval = data; if (returnval) { main.log.add(1, 'xobor.plugin.sessionstorage.get', 'something goes wrong by parsing key: ', key); return returnval; } else { return false; } } } }, set: function(key, val) { if(typeof(Storage) !== "undefined" && this.sessionstorageprefix) { sessionStorage.setItem(this.sessionstorageprefix + key, JSON.stringify(val)); main.log.add(0, 'xobor.plugin.sessionstorage.set', 'save key: "'+key+'"'); return true; } main.log.add(3, 'xobor.plugin.sessionstorage.set', 'localStore is not defined or sessionstorageprefix is not set'); return false; }, del: function(key) { if(typeof(Storage) !== "undefined" && this.sessionstorageprefix) { sessionStorage.removeItem(this.sessionstorageprefix + key); main.log.add(0, 'xobor.plugin.sessionstorage.del', 'delete key: "'+key+'"'); return true; } main.log.add(3, 'xobor.plugin.sessionstorage.del', 'localStore is not defined or localstorageprefix is not set'); return false; } }, cookie: { cookieprefix: 'xobor_plugin_'+pid+'_', rpid: pid, get: function(key) { main.log.add(0, 'xobor.plugin.cookie.get', 'get cookie key: ', key); return xobor.plugin(this.rpid).getIntVal(xGetCookie(this.cookieprefix+key)); }, set: function(key, val, days) { var cregex = new RegExp("xobor_plugin_"+this.rpid+"_\\w+", 'gi'); var cookieC = document.cookie.match(cregex); var access = false; if (!cookieC) {cookieC = []} for(var i = 0; i < cookieC.length; i++) { cookieC[i] = cookieC[i].replace(this.cookieprefix, ''); } if (cookieC.indexOf(key) > -1) { access = true; } else { if (cookieC.length < 5) { access = true; } } if (access) { main.log.add(0, 'xobor.plugin.cookie.set', 'save cookie key: ', key); xSetCookie(this.cookieprefix+key, val, days); return true; } else { main.log.add(3, 'xobor.plugin.cookie.set', 'cann not save '+key+' cookie limit reached'); return false; } }, del: function(key) { xSetCookie(this.cookieprefix+key, '', -1); main.log.add(0, 'xobor.plugin.cookie.del', 'del cookie key: ', key); return true; } }, connect: function(url, type, data, callbackfn, options, errorCbFn) { var ajaxAsync = pself.ajaxSync; var _tempPluginId = pself.pluginID; var cache_ttl = 60; main.log.add(0,'xobor.plugin.connect', "Request-URL: "+pself.ajaxUrl+url+ " Type: "+type+ " data: ",data); // dataObj length Check if (JSON.stringify(data).length > 63000) { if (typeof errorCbFn === 'function') { errorCbFn(); } main.log.add("connect payload char-limit reached"); return false; } // gibt es options? if (typeof options !== 'undefined') { // cache-ttl if (typeof options['cachettl'] !== 'undefined') { cache_ttl = options['cachettl']; } } // caching var keypart1 = url; var keypart2 = JSON.stringify(data); var keypart3 = type; var cacheKey = md5(keypart1+keypart2+keypart3); var cacheval = xobor.localCache.get(cacheKey); var returnVal; if (cacheval) { if (!ajaxAsync) { return cacheval; } else { callbackfn(cacheval); } } else { $.ajax({ url: pself.ajaxUrl+url, type: type, cache: xobor.config.ajaxCache, async: false, data: data, success: function(response) { main.log.add(0,'xobor.plugin.connect', url + " Result: ", response); if(response.status === 'success') { xobor.localCache.set(cacheKey, response.message, cache_ttl); returnVal = response.message; } else { returnVal = null; } if (typeof callbackfn === 'function') { callbackfn(returnVal); } } }); if(!ajaxAsync) { return returnVal; } } }, getDeep: function(idata, callbackfn) { idata['get_type'] = 'deepdata'; idata['ttype'] = idata['target_type'] ? idata['target_type'] : idata['ttype']; idata['tid'] = idata['target_id'] ? idata['target_id'] : idata['tid']; return this.connect('&function=getDeep', 'POST', JSON.stringify(idata), callbackfn); }, getDeepList: function(idata, callbackfn) { idata['get_type'] = 'deeplist'; return this.connect('&function=getDeepList', 'POST', JSON.stringify(idata), callbackfn); }, getGlob: function(varname, editable, callbackfn) { if (varname instanceof Object) { var tempObj = varname; if (typeof tempObj['varname'] !== 'undefined') {varname = tempObj['varname'];} else {return false;} if (typeof tempObj['editable'] !== 'undefined') {editable = tempObj['editable'];} else {editable = null;} if (typeof tempObj['callbackfn']!== 'undefined') {callbackfn= tempObj['callbackfn'];} else {callbackfn = null;} } if (typeof editable === 'function' && typeof callbackfn === 'undefined') {callbackfn = editable;} var ajaxAsync = pself.ajaxSync; if (typeof callbackfn === 'function') { return xobor.plugin(pself.pluginID).getaGlob(varname, editable, callbackfn); } else { if(!ajaxAsync){return xobor.plugin(pself.pluginID).getaGlob(varname, editable);} try{ if (typeof pself.staticContent[pself.pluginID] !== 'undefined') { if (typeof pself.staticContent[pself.pluginID]['globVars'][varname] !== 'undefined') { val = xobor.plugin(pself.pluginID).getIntVal(pself.staticContent[pself.pluginID]['globVars'][varname]); if(val){ if(!editable){return val;} editableval = xobor.plugin(pself.pluginID).getIntVal(pself.staticContent[pself.pluginID]['globVars'][[varname]+'_editable']); return {'value':val,'editable':editableval}; } else { return false; } } } } catch(e) { return 'v404_2'; } } //variable nicht gefunden: return ''; }, getaGlob: function (vname, editable, callbackfn) { if (typeof editable === 'undefined') { var editable = false; } return this.connect('&function=getaGlob', 'POST', JSON.stringify({get_type: 'global', varname: vname, edit: editable}), callbackfn); }, getConf: function(varname, callbackfn) { if (varname instanceof Object && typeof varname['varname'] !== 'undefined') { var tempObj = varname; if (typeof tempObj['varname'] !== 'undefined') {varname = tempObj['varname'];} else {return false;} if (typeof tempObj['callbackfn']!== 'undefined') {callbackfn= tempObj['callbackfn'];} else {callbackfn = null;} } if (typeof pself.staticContent[pself.pluginID] !== 'undefined') { if (varname instanceof Array) { var retArr = {}; for (var i = 0; i < varname.length; i++) { if (typeof pself.staticContent[pself.pluginID]['confVars'][varname[i]] !== 'undefined') { retArr[varname[i]] = xobor.plugin(pself.pluginID).getIntVal(pself.staticContent[pself.pluginID]['confVars'][varname[i]]); } } if (Object.keys(retArr).length > 0) { return retArr; } else { if (typeof callbackfn === 'undefined') { return false; } } } else { if (typeof pself.staticContent[pself.pluginID]['confVars'][varname] !== 'undefined') { return xobor.plugin(pself.pluginID).getIntVal(pself.staticContent[pself.pluginID]['confVars'][varname]); } } } if (typeof callbackfn !== 'undefined') { if (typeof window.callbackfn !== 'function') { return this.connect('&function=getConf', 'POST', JSON.stringify({get_type: "configVar", vname: varname}), callbackfn); } } }, setGlob: function(vname, val, callbackfn, errorCbFn) { if (vname instanceof Object) { var tempObj = vname; if (typeof tempObj['varname'] !== 'undefined') {vname = tempObj['varname'];} else {return false;} if (typeof tempObj['val'] !== 'undefined') {val = tempObj['val'];} else {val = null;} if (typeof tempObj['callbackfn']!== 'undefined') {callbackfn= tempObj['callbackfn'];} else {callbackfn = null;} } if (val instanceof Array || val instanceof Object) { _val = JSON.stringify(val); _val = _val.replace(/\n/g, '
'); } else { _val = val; } return this.connect('&function=setGlob', 'POST', xconvert2entity({submit_type: "global", varname: vname, value: _val}), callbackfn, errorCbFn); }, getIntVal: function (val) { return val; if(typeof val === 'undefined'){return val;} if(typeof val === null){return val;} if (typeof val === 'array') { for (var i = 0; i < val.length; i++) { if (typeof val[i] === 'array') { val[i] = xobor.plugin(pself.pluginID).getIntVal(val[i]); } else if (typeof val[i] === 'object') { val[i] = xobor.plugin(pself.pluginID).getIntVal(val[i]); } else { if(parseInt(val[i]).toString().length == val[i].toString().length) { val[i] = parseInt(val[i]); } else { val[i] = val[i]; } } } return val } else if (typeof val === 'object') { for( var k in val ) { if (typeof val[k] === 'array') { val[k] = xobor.plugin(pself.pluginID).getIntVal(val[k]); } else if (typeof val[k] === 'object') { val[k] = xobor.plugin(pself.pluginID).getIntVal(val[k]); } else { if(parseInt(val[k]).toString().length == val[k].toString().length) { val[k] = parseInt(val[k]); } else { val[k] = val[k]; } } } return val } else { if(parseInt(val).toString().length == val.toString().length){ if (parseInt(val).toString() == 'NaN' || val.toString().length == 'NaN') { return val; } else { return parseInt(val); } } else { return val; } } }, updateLocalStaticStorage: function(varname, val) { try { if (typeof pself.staticContent[pself.pluginID]['globVars'] !== 'undefined') { pself.staticContent[pself.pluginID]['globVars'][varname] = val; } } catch (e){} }, addNewLocalDynamicStorageItem: function(varname, value, origin_id, origin_type, userseperatedID) { var mergeObj = {}; var originIdObj = {}; var originTypeObj = {}; var varnameObj = {}; var userSeperatedObj = {}; originIdObj[origin_id] = value if (userseperatedID != '' && userseperatedID != null) { userSeperatedObj[userseperatedID] = originIdObj; originTypeObj[origin_type] = userSeperatedObj; } else { originTypeObj[origin_type] = originIdObj; } varnameObj[varname] = originTypeObj; mergeObj[pself.pluginID] = varnameObj; $.extend(true, pself.dynamicContent, mergeObj); }, updateLocalDynamicStorageItem: function(varname, value, origin_id, origin_type, userseperatedID) { var errorHandler = false; if (typeof pself.dynamicContent[pself.pluginID] !== 'undefined') { if (typeof pself.dynamicContent[pself.pluginID][varname] !== 'undefined') { if (typeof pself.dynamicContent[pself.pluginID][varname][origin_type] !== 'undefined') { if (typeof pself.dynamicContent[pself.pluginID][varname][origin_type][userseperatedID] !== 'undefined') { if (typeof pself.dynamicContent[pself.pluginID][varname][origin_type][userseperatedID][origin_id] !== 'undefined') { pself.dynamicContent[pself.pluginID][varname][origin_type][userseperatedID][origin_id] = value; } } else if (typeof pself.dynamicContent[pself.pluginID][varname][origin_type][origin_id] !== 'undefined') { pself.dynamicContent[pself.pluginID][varname][origin_type][origin_id] = value; } else { errorHandler = true; } } else { rrorHandler = true; } } else { errorHandler = true; } } else { errorHandler = true; } if (errorHandler) { this.addNewLocalDynamicStorageItem(varname, value, origin_id, origin_type, userseperatedID); } }, getDataVarAjax: function(vname, origin_id, origin_type, callbackfn, userseperatedID) { var _userID = (typeof userseperatedID !== 'undefined') ? userseperatedID : 'null'; return this.connect('&function=getDataVarAjax', 'POST', JSON.stringify({get_type: "dataVar", varname: vname, origin_id: origin_id, _userID: _userID, origin_type: origin_type}), callbackfn); }, getDataVarByObjectAjax: function(tempObj) { console.log("Object call"); tempObj['get_type'] = "dataVar"; var callbackfn = null; if (typeof tempObj['callbackfn']!== 'undefined') {callbackfn = tempObj['callbackfn'];} return this.connect('&function=getDataVarAjax', 'POST', JSON.stringify(tempObj), callbackfn); }, getDataVar: function (varname, originType, originid, callbackfn, userseperatedID) { var doobjectcall = false; if (varname instanceof Object) { var tempObj = varname; if (typeof tempObj['varname'] == 'undefined') {return false /*Kein call ohne varname*/} if (typeof tempObj['originType'] == 'undefined') {tempObj['originType']=null;} if (typeof tempObj['originid'] == 'undefined') {tempObj['originid']=null;} if (typeof tempObj['callbackfn'] == 'undefined') {tempObj['callbackfn']=null;} if (typeof tempObj['userseperatedID'] == 'undefined') {tempObj['userseperatedID']=null;} if (typeof tempObj['offset'] == 'undefined') {tempObj['offset']=null;} if (typeof tempObj['varname'] !== 'undefined') {varname = tempObj['varname'];} else {return false;} if (typeof tempObj['originType'] !== 'undefined') {originType = tempObj['originType'];} else {originType = null;} if (typeof tempObj['originid'] !== 'undefined') {originid = tempObj['originid'];} else {originid = null;} if (typeof tempObj['callbackfn'] !== 'undefined') {callbackfn = tempObj['callbackfn'];} else {callbackfn = null;} if (typeof tempObj['userseperatedID'] !== 'undefined') {userseperatedID = tempObj['userseperatedID'];} else {userseperatedID = null;} if (typeof tempObj['offset'] !== 'undefined') {offset = tempObj['offset'];} else {offset = null;} doobjectcall = true; } var errorHandler = false; var ajaxAsync = pself.ajaxSync; if (typeof pself.dynamicContent !== 'undefined') { if (typeof pself.dynamicContent[pself.pluginID] !== 'undefined') { if (typeof pself.dynamicContent[pself.pluginID][varname] !== 'undefined') { if (typeof pself.dynamicContent[pself.pluginID][varname][originType][userseperatedID] !== 'undefined') { if (typeof pself.dynamicContent[pself.pluginID][varname][originType][userseperatedID][originid] !== 'undefined') { callbackfn(xobor.plugin(pself.pluginID).getIntVal(pself.dynamicContent[pself.pluginID][varname][originType][userseperatedID][originid])); } else { errorHandler = true; } } else { if (typeof pself.dynamicContent[pself.pluginID][varname][originType][originid] !== 'undefined' && pself.dynamicContent[pself.pluginID][varname][originid] != '') { callbackfn(xobor.plugin(pself.pluginID).getIntVal(pself.dynamicContent[pself.pluginID][varname][originType][originid])); } else { errorHandler = true; } } } else { errorHandler = true; } } else { errorHandler = true; } } else { errorHandler = true; } if (errorHandler && (typeof callbackfn === 'function')) { if(doobjectcall){return this.getDataVarByObjectAjax(tempObj);} else{return this.getDataVarAjax(varname, originid, originType, callbackfn, userseperatedID);} } else { return null; } }, getDataVarList: function () { if (typeof pself.dynamicContent[pself.pluginID] !== 'undefined') { return pself.dynamicContent[pself.pluginID]; } else { return 'p404'; } }, setDataVar: function(vname, origin_type, origin_id, val, callbackfn, userseperatedID, errorCbFn) { if (vname instanceof Object) { var tempObj = vname; if (typeof tempObj['varname'] !== 'undefined') {vname = tempObj['varname'];} else {return false;} if (typeof tempObj['originType'] !== 'undefined') {origin_type = tempObj['originType'];} else {origin_type = null;} if (typeof tempObj['originid'] !== 'undefined') {origin_id = tempObj['originid'];} else {origin_id = null;} if (typeof tempObj['val'] !== 'undefined') {val = tempObj['val'];} else {val = null;} if (typeof tempObj['callbackfn'] !== 'undefined') {callbackfn = tempObj['callbackfn'];} else {callbackfn = null;} if (typeof tempObj['userseperatedID'] !== 'undefined') {userseperatedID = tempObj['userseperatedID'];} else {userseperatedID = null;} if (typeof tempObj['errorCbFn'] !== 'undefined') {errorCbFn = tempObj['errorCbFn'];} else {errorCbFn = null;} } var _userID = (typeof userseperatedID !== 'undefined') ? userseperatedID : 'null'; var _delVar = false; return this.connect('&function=setDataVar', 'POST', xconvert2entity({submit_type: "dataVar", varname: vname, value: val, originID: origin_id, sepID: _userID, originType: origin_type, del: _delVar}), callbackfn, errorCbFn); }, editDataVar: function(vname, origin_type, origin_id, val, callbackfn, userseperatedID, dataseperatedID, errorCbFn) { if (vname instanceof Object) { var tempObj = vname; if (typeof tempObj['varname'] !== 'undefined') {vname = tempObj['varname'];} else {return false;} if (typeof tempObj['originType'] !== 'undefined') {origin_type = tempObj['originType'];} else {origin_type = null;} if (typeof tempObj['originid'] !== 'undefined') {origin_id = tempObj['originid'];} else {origin_id = null;} if (typeof tempObj['val'] !== 'undefined') {val = tempObj['val'];} else {val = null;} if (typeof tempObj['callbackfn'] !== 'undefined') {callbackfn = tempObj['callbackfn'];} else {callbackfn = null;} if (typeof tempObj['userseperatedID'] !== 'undefined') {userseperatedID = tempObj['userseperatedID'];} else {userseperatedID = null;} if (typeof tempObj['dataseperatedID'] !== 'undefined') {dataseperatedID = tempObj['dataseperatedID'];} else {dataseperatedID = null;} if (typeof tempObj['errorCbFn'] !== 'undefined') {errorCbFn = tempObj['errorCbFn'];} else {errorCbFn = null;} } var _editID = (typeof dataseperatedID!== 'undefined') ? dataseperatedID: 'null'; var _userID = (typeof userseperatedID !== 'undefined') ? userseperatedID : 'null'; var _delVar = false; return this.connect('&function=editDataVar', 'POST', xconvert2entity({submit_type: "dataVar", varname: vname, value: val, originID: origin_id, editID: _editID, sepID: _userID, originType: origin_type, del: _delVar}), callbackfn, errorCbFn); }, delDataVar: function(vname, origin_type, origin_id,callbackfn, userseperatedID, dataseperatedID) { if (vname instanceof Object) { var tempObj = vname; if (typeof tempObj['varname'] !== 'undefined') {vname = tempObj['varname'];} else {return false;} if (typeof tempObj['originType'] !== 'undefined') {origin_type = tempObj['originType'];} else {origin_type = null;} if (typeof tempObj['originid'] !== 'undefined') {origin_id = tempObj['originid'];} else {origin_id = null;} if (typeof tempObj['val'] !== 'undefined') {val = tempObj['val'];} else {val = null;} if (typeof tempObj['callbackfn'] !== 'undefined') {callbackfn = tempObj['callbackfn'];} else {callbackfn = null;} if (typeof tempObj['userseperatedID'] !== 'undefined') {userseperatedID = tempObj['userseperatedID'];} else {userseperatedID = null;} if (typeof tempObj['dataseperatedID'] !== 'undefined') {dataseperatedID = tempObj['dataseperatedID'];} else {dataseperatedID = null;} } var _editID = (typeof dataseperatedID!== 'undefined') ? dataseperatedID: 'null'; var _userID = (typeof userseperatedID !== 'undefined') ? userseperatedID : 'null'; var _delVar = true; return this.connect('&function=setDataVar', 'POST', xconvert2entity({submit_type: "dataVar", varname: vname, value: "", origin_id: origin_id, sepID: _userID, editID: _editID, originType: origin_type, del: _delVar}), callbackfn); }, addPluginAction: function(idata, callbackfn) { //mögliche Felder: // 'userid','content','origin','html','feedimg','read_permission'; return this.connect('&function=pluginaction', 'POST', JSON.stringify(idata), callbackfn); }, call: function(fnName, values, callbackfn, options) { if (fnName instanceof Object) { var tempObj = fnName; if (typeof tempObj['fnName'] !== 'undefined') {fnName = tempObj['fnName'];} else {return false;} if (typeof tempObj['values'] !== 'undefined') {values = tempObj['values'];} else {values = null;} if (typeof tempObj['callbackfn'] !== 'undefined') {callbackfn = tempObj['callbackfn'];} else {callbackfn = null;} if (typeof tempObj['options'] !== 'undefined') {options = tempObj['options'];} else {options = null;} } return this.connect('&function=call&internal='+fnName, 'POST', xconvert2entity({submit_type: "call", value: values, functionname: fnName}), callbackfn, options); }, log: function(val) { main.log.add(val); }, } }; xobor.updateDataVarStore = function() { if (typeof xoborDynamic !== 'undefined') { for (var i = 0; i < xoborDynamic.length; i++) { theXoborVarVal = $.extend(theXoborVarVal, xoborDynamic[i]); } } }; xobor.global = $.extend(xobor.global, { internalpluginid : "1337", userid: function () { if (typeof tuserID !== 'undefined') { return tuserID; } else { return 'null'; } }, }); xobor.localCache = { cacheDB: false, getCacheDb: function() { if(typeof(Storage) !== "undefined") { if (xobor.localCache.cacheDB === false) { var fromStorage = JSON.parse(localStorage.getItem('xobor_api_ajax_cache_db')); if (fromStorage) { xobor.localCache.cacheDB = fromStorage; } else { xobor.localCache.cacheDB = {}; } } return xobor.localCache.cacheDB; } else { return false; } }, saveCacheDb: function() { if(typeof(Storage) !== "undefined") { localStorage.setItem('xobor_api_ajax_cache_db', JSON.stringify(xobor.localCache.cacheDB)); return true; } return false; }, get: function(key) { if (!xobor.config.ajaxLocalCache) {return false;} var cacheDb = xobor.localCache.getCacheDb(); if (cacheDb && typeof cacheDb[key] !== 'undefined') { var date = new Date(); var timestamp = Math.round(date.getTime() / 1000); if (cacheDb[key]['ttl'] >= timestamp) { return cacheDb[key]['value']; } else { xobor.localCache.del(key); return false; } } else { return false; } }, set: function(key, val, ttl) { if (!xobor.config.ajaxLocalCache) {return false;} var cacheDb = xobor.localCache.getCacheDb(); if(typeof(Storage) !== "undefined") { if (typeof ttl === 'undefined') { ttl = 60; } var date = new Date(); var timestamp = Math.round(date.getTime() / 1000); ttl = ttl + timestamp; if (typeof ttl === 'undefined' || ttl <= timestamp) { ttl = timestamp + 60; } cacheDb[key] = {value: val, ttl: ttl}; xobor.localCache.cacheDB = cacheDb; xobor.localCache.saveCacheDb(); return true; } return false; }, del: function(key) { if(typeof(Storage) !== "undefined") { var cacheDb = xobor.localCache.getCacheDb(); if (typeof cacheDb[key] !== 'undefined') { delete cacheDb[key]; xobor.localCache.cacheDB = cacheDb; xobor.localCache.saveCacheDb(); return true; } } return false; } }; xobor.config = $.extend(xobor.config, { ajaxAsync: true, ajaxCache: false, ajaxLocalCache: false, debug: false }); xobor.helper = $.extend(xobor.helper, { add: function(ctype,idata){ var _tempPluginId = xobor.global.internalpluginid; idata = xconvert2entity(idata); idata['get_type'] = 'add'; return xobor.plugin(_tempPluginId,false).connect('&function=add&ctype='+ctype, 'POST', JSON.stringify(idata), function(res){console.log(res)}); }, getBoxHeader: function(data){ /*Params: template || t : id des templates id : id der Box header : Überschrift der Box add : Selector für ein Element, was dem Header hinzugefügt wird (z.B. ein Linkl) classes: zusätzliche klassen, die der Box zugewiesen werden. */ var headers = []; headers['t1'] = '
%header%
'; headers['t110'] = '

%header%

'; headers['t111'] = '

%header%

'; headers['t144'] = '
%header%
'; var head_header = data.header ? data.header : false; var head_id = data.id ? 'id="'+data.id+'"' : ""; var head_classes = data.classes ? data.classes : ""; var skeleton = headers["t"+data.template]; skeleton = skeleton.replace("%id%",head_id); skeleton = skeleton.replace("%classes%",head_classes); skeleton = skeleton.replace("%header%",head_header); return skeleton; }, getBoxFooter: function(data){ /*Params: data : entweder ein objeect mit template oder t parameter, oder direkt die template ID. */ var template =""; if(isInt(data)){template = data;} else{template = data.template ? data.template : data.t} var footers = []; footers['t1'] = '
'; footers['t110'] = ''; footers['t111'] = '
'; footers['t144'] = ''; var skeleton = footers["t"+template]; return skeleton; }, getBox: function(data){ /*Params: template || t : id des templates content : HTML-String oder Element id : id der Box header : Überschrift der Box add : Selector für ein Element, was dem Header hinzugefügt wird (z.B. ein Linkl) classes: zusätzliche klassen, die der Box zugewiesen werden. */ var header_str = xobor.helper.getBoxHeader(data); var content_str = data.content ? (typeof(data.content)==='string' ? data.content : data.content.html()) : "" ; var footer_str = xobor.helper.getBoxFooter(data); var boxstring = header_str + content_str + footer_str; $box = $(boxstring); if(data.add){ if(typeof(data.add)==='string'){ data.add = $(data.add); } data.add.appendTo($box.find('.addmarker')); } return $box; }, getUserById: function (data) { /*Params: user : UserId oder Object spanonly: Ist spanonlyy auf true, wird nur die span (ohne link) zurückgegeben classes: zusätzliche klassen, die dem Link (bzw. der span) zugewiesen werden. */ var u = isInt(data) ? data : data.user; var spanonly = data.spanonly ? 1 :0; var added_classes = data.classes ? data.classes : 0; var _tempPluginId = xobor.global.internalpluginid; if(isInt(u)){ var userdata = {"target_type":3, "target_id":u} u = xobor.plugin(_tempPluginId,false).getDeep(userdata); } if(!u){ xobor.plugin("Helper").log("Invalid User Data "); return false; } var userlink = "/u" + u.user_id + "_" + u.uname + ".html"; var user_pm_link = "/private_new.php?sendto=" + u.user_id + ".html"; var span_classes = "xuser xuser_"+u.user_id; if(spanonly){span_classes += added_classes;} var span_color = u.usercolor ? "style='color:"+u.usercolor+";'" : ""; var user_span = ""+u.uname+""; if(spanonly){return user_span;} var user_link_classes = "xuser_link xuser_"+u.user_id+"_link"; if(!spanonly && added_classes){user_link_classes += added_classes;} var user_link = ""+user_span+""; return user_link; }, });