Subversion Repositories oidplus

Rev

Rev 424 | Rev 450 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 daniel-mar 1
/*
2
 * OIDplus 2.0
3
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
 
9 daniel-mar 18
/*jshint esversion: 6 */
19
 
219 daniel-mar 20
// $('#html').jstree();
21
 
22
var current_node = "";
23
var popstate_running = false;
362 daniel-mar 24
// DEFAULT_LANGUAGE will be set by oidplus.min.js.php
360 daniel-mar 25
// language_messages will be set by oidplus.min.js.php
26
// language_tblprefix will be set by oidplus.min.js.php
424 daniel-mar 27
// csrf_token will be set by oidplus.min.js.php
219 daniel-mar 28
 
399 daniel-mar 29
var pageChangeCallbacks = [];
30
var pageChangeRequestCallbacks = [];
31
 
356 daniel-mar 32
function isInternetExplorer() {
33
        var ua = window.navigator.userAgent;
34
        return ((ua.indexOf("MSIE ") > 0) || (ua.indexOf("Trident/") > 0));
35
}
36
 
2 daniel-mar 37
String.prototype.explode = function (separator, limit) {
38
        // https://stackoverflow.com/questions/4514323/javascript-equivalent-to-php-explode
39
        const array = this.split(separator);
40
        if (limit !== undefined && array.length >= limit) {
41
                array.push(array.splice(limit - 1).join(separator));
42
        }
43
        return array;
44
};
45
 
46
String.prototype.htmlentities = function () {
399 daniel-mar 47
        return this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');//"
9 daniel-mar 48
};
2 daniel-mar 49
 
50
String.prototype.html_entity_decode = function () {
51
        return $('<textarea />').html(this).text();
9 daniel-mar 52
};
2 daniel-mar 53
 
112 daniel-mar 54
function getMeta(metaName) {
55
        const metas = document.getElementsByTagName('meta');
56
 
57
        for (let i = 0; i < metas.length; i++) {
58
                if (metas[i].getAttribute('name') === metaName) {
59
                        return metas[i].getAttribute('content');
60
                }
61
        }
62
 
63
        return '';
64
}
65
 
66
function getOidPlusSystemTitle() {
360 daniel-mar 67
        return getMeta('OIDplus-SystemTitle'); // do not translate
112 daniel-mar 68
}
69
 
5 daniel-mar 70
function combine_systemtitle_and_pagetitle(systemtitle, pagetitle) {
309 daniel-mar 71
        // Please also change the function in index.php
5 daniel-mar 72
        if (systemtitle == pagetitle) {
73
                return systemtitle;
74
        } else {
309 daniel-mar 75
                return pagetitle + ' - ' + systemtitle;
5 daniel-mar 76
        }
77
}
78
 
385 daniel-mar 79
function getSystemUrl(relative) {
80
        var url = new URL(window.location.href);
81
        if (relative) {
82
                return url.pathname;
83
        } else {
84
                return url.href.substr(0, url.href.length-url.search.length);
85
        }
86
}
87
 
2 daniel-mar 88
function getTreeLoadURL() {
89
        var url = new URL(window.location.href);
90
        var goto = url.searchParams.get("goto");
424 daniel-mar 91
        return (goto != null) ? "ajax.php?csrf_token="+csrf_token+"&action=tree_load&goto="+encodeURIComponent(goto)
92
                              : "ajax.php?csrf_token="+csrf_token+"&action=tree_load";
2 daniel-mar 93
}
94
 
95
function reloadContent() {
154 daniel-mar 96
        // window.location.href = "?goto="+encodeURIComponent(current_node);
399 daniel-mar 97
        if (openOidInPanel(current_node, false)) {
98
                $('#oidtree').jstree("refresh");
99
        }
2 daniel-mar 100
}
101
 
107 daniel-mar 102
function x_rec(x_data, i) {
103
        $('#oidtree').jstree('open_node', x_data[i], function(e, data) {
104
                if (i+1 < x_data.length) {
105
                        x_rec(x_data, i+1);
106
                } else {
114 daniel-mar 107
                        popstate_running = true; // don't call openOidInPanel again
108
                        try {
109
                                $('#oidtree').jstree('select_node', x_data[i]);
110
                        } catch (err) {
111
                                popstate_running = false;
112
                        } finally {
113
                                popstate_running = false;
114
                        }
107 daniel-mar 115
                }
116
        });
117
}
2 daniel-mar 118
 
399 daniel-mar 119
function performCloseQueryCB() {
120
        for (var i=0; i<pageChangeRequestCallbacks.length; i++) {
121
                if (!pageChangeRequestCallbacks[i][0](pageChangeRequestCallbacks[i][1])) return false;
122
        }
123
        pageChangeRequestCallbacks = [];
124
        return true; // may close
125
}
126
 
127
function performCloseCB() {
128
        for (var i=0; i<pageChangeCallbacks.length; i++) {
129
                pageChangeCallbacks[i][0](pageChangeCallbacks[i][1]);
130
        }
131
        pageChangeCallbacks = [];
132
}
133
 
134
function openOidInPanel(id, reselect/*=false*/, anchor/*=''*/, force/*=false*/) {
150 daniel-mar 135
        reselect = (typeof reselect === 'undefined') ? false : reselect;
219 daniel-mar 136
        anchor = (typeof anchor === 'undefined') ? '' : anchor;
399 daniel-mar 137
        force = (typeof force === 'undefined') ? false : force;
150 daniel-mar 138
 
399 daniel-mar 139
        var mayClose = performCloseQueryCB();
140
        if (!force && !mayClose) return false;
141
 
142
        performCloseCB();
405 daniel-mar 143
 
107 daniel-mar 144
        if (reselect) {
2 daniel-mar 145
                $('#oidtree').jstree('deselect_all');
107 daniel-mar 146
 
114 daniel-mar 147
                popstate_running = true; // don't call openOidInPanel during tree selection
148
                try {
149
                        // If the node is already loaded in the tree, select it
150
                        if (!$('#oidtree').jstree('select_node', id)) {
151
                                // If the node is not loaded, then we try to search it.
152
                                // If it can be found, then open all parent nodes and select the node
153
                                $.ajax({
154
                                        url:"ajax.php",
155
                                        method:"POST",
156
                                        data:{
424 daniel-mar 157
                                                csrf_token:csrf_token,
114 daniel-mar 158
                                                action:"tree_search",
159
                                                search:id
160
                                        },
161
                                        error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 162
                                                console.error(_L("Error: %1",errorThrown));
114 daniel-mar 163
                                        },
164
                                        success:function(data) {
165
                                                if ("error" in data) {
166
                                                        console.error(data);
167
                                                } else if ((data instanceof Array) && (data.length > 0)) {
168
                                                        x_rec(data, 0);
169
                                                } else {
170
                                                        console.error(data);
171
                                                }
172
                                        }
173
                                });
107 daniel-mar 174
                        }
114 daniel-mar 175
                } catch (err) {
176
                        popstate_running = false;
177
                } finally {
178
                        popstate_running = false;
179
                }
2 daniel-mar 180
        }
181
 
114 daniel-mar 182
        // This loads the actual content
183
 
405 daniel-mar 184
        // document.title = ""; // <-- we may not do this, otherwise Firefox won't
185
        //                            show titles in the browser history (right-click
186
        //                            on back-button), although document.title() is
187
        //                            set inside the AJAX-callback [FirefoxBug?!]
188
 
2 daniel-mar 189
        $('#real_title').html("&nbsp;");
355 daniel-mar 190
        $('#real_content').html(_L("Loading..."));
108 daniel-mar 191
        $('#static_link').attr("href", "index.php?goto="+encodeURIComponent(id));
183 daniel-mar 192
        $("#gotoedit").val(id);
2 daniel-mar 193
 
194
        // Normal opening of a description
424 daniel-mar 195
        fetch("ajax.php?csrf_token="+csrf_token+"&action=get_description&id="+encodeURIComponent(id))
2 daniel-mar 196
        .then(function(response) {
197
                response.json()
198
                .then(function(data) {
107 daniel-mar 199
                        if ("error" in data) {
360 daniel-mar 200
                                alert(_L("Failed to load content: %1",data.error));
107 daniel-mar 201
                                console.error(data.error);
202
                                return;
203
                        }
204
 
2 daniel-mar 205
                        data.id = id;
206
 
207
                        var state = {
107 daniel-mar 208
                                "node_id":id,
108 daniel-mar 209
                                "titleHTML":(data.icon ? '<img src="'+data.icon+'" width="48" height="48" alt="'+data.title.htmlentities()+'"> ' : '') + data.title.htmlentities(),
2 daniel-mar 210
                                "textHTML":data.text,
108 daniel-mar 211
                                "staticlinkHREF":"index.php?goto="+encodeURIComponent(id),
2 daniel-mar 212
                        };
213
                        if (current_node != id) {
104 daniel-mar 214
                                window.history.pushState(state, data.title, "?goto="+encodeURIComponent(id));
2 daniel-mar 215
                        } else {
104 daniel-mar 216
                                window.history.replaceState(state, data.title, "?goto="+encodeURIComponent(id));
2 daniel-mar 217
                        }
218
 
405 daniel-mar 219
                        document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), data.title);
220
 
32 daniel-mar 221
                        if (data.icon) {
222
                                $('#real_title').html('<img src="'+data.icon+'" width="48" height="48" alt="'+data.title.htmlentities()+'"> ' + data.title.htmlentities());
223
                        } else {
224
                                $('#real_title').html(data.title.htmlentities());
225
                        }
2 daniel-mar 226
                        $('#real_content').html(data.text);
112 daniel-mar 227
                        document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), data.title);
2 daniel-mar 228
                        current_node = id;
219 daniel-mar 229
 
230
                        if (anchor != '') {
231
                                jumpToAnchor(anchor);
232
                        }
2 daniel-mar 233
                })
234
                .catch(function(error) {
360 daniel-mar 235
                        alert(_L("Failed to load content: %1",error));
2 daniel-mar 236
                        console.error(error);
237
                });
238
        })
239
        .catch(function(error) {
360 daniel-mar 240
                alert(_L("Failed to load content: %1",error));
2 daniel-mar 241
                console.error(error);
242
        });
399 daniel-mar 243
 
244
        return true;
2 daniel-mar 245
}
246
 
107 daniel-mar 247
// This function opens the "parentID" node, and then selects the "childID" node (which should be beneath the parent node)
2 daniel-mar 248
function openAndSelectNode(childID, parentID) {
249
        if ($('#oidtree').jstree(true).get_node(parentID)) {
107 daniel-mar 250
                $('#oidtree').jstree('open_node', parentID, function(e, data) { // open parent node
2 daniel-mar 251
                        if ($('#oidtree').jstree(true).get_node(childID)) { // is the child there?
107 daniel-mar 252
                                $('#oidtree').jstree('deselect_all').jstree('select_node', childID); // select it
2 daniel-mar 253
                        } else {
254
                                // This can happen if the content page contains brand new items which are not in the treeview yet
183 daniel-mar 255
                                $("#gotoedit").val(childID);
154 daniel-mar 256
                                window.location.href = "?goto="+encodeURIComponent(childID);
2 daniel-mar 257
                        }
258
                }, true);
259
        } else {
260
                // This should usually not happen
183 daniel-mar 261
                $("#gotoedit").val(childID);
154 daniel-mar 262
                window.location.href = "?goto="+encodeURIComponent(childID);
2 daniel-mar 263
        }
264
}
265
 
266
$(window).on("popstate", function(e) {
399 daniel-mar 267
        if (!performCloseQueryCB()) {
268
                // TODO: does not work!!! The "back/forward" action will be cancelled, but the browser still thinks it was successful,
269
                // so if you do it again, you will then jump 2 pages back, etc!
270
                // This does also not help:
271
                //window.history.pushState(e.originalEvent.state, e.originalEvent.title, e.originalEvent.url);
272
                //window.history.forward();
273
                return;
274
        }
275
 
2 daniel-mar 276
        popstate_running = true;
277
        try {
278
                var data = e.originalEvent.state;
279
 
280
                current_node = data.node_id;
327 daniel-mar 281
                $("#gotoedit").val(current_node);
107 daniel-mar 282
                $('#oidtree').jstree('deselect_all').jstree('select_node', data.node_id);
2 daniel-mar 283
                $('#real_title').html(data.titleHTML);
284
                $('#real_content').html(data.textHTML);
285
                $('#static_link').attr("href", data.staticlinkHREF);
112 daniel-mar 286
                document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), data.titleHTML.html_entity_decode());
2 daniel-mar 287
        } catch (err) {
288
                popstate_running = false;
289
        } finally {
290
                popstate_running = false;
291
        }
292
});
293
 
294
$(document).ready(function () {
399 daniel-mar 295
        /*
296
        window.onbeforeunload = function(e) {
297
                // TODO: This won't be called because TinyMCE overrides it??
298
                // TODO: when the user accepted the query in performCloseQueryCB(), then the message will be shown again by the browser!
299
                if (!performCloseQueryCB()) {
300
                        // Cancel the event
301
                        e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always be shown
302
                        // Chrome requires returnValue to be set
303
                        e.returnValue = '';
304
                } else {
305
                        // the absence of a returnValue property on the event will guarantee the browser unload happens
306
                        delete e['returnValue'];
307
                }
308
        };
309
        */
214 daniel-mar 310
 
2 daniel-mar 311
        // --- JsTree
312
 
313
        $('#oidtree')
314
        .jstree({
315
                plugins: ['massload','search','conditionalselect'],
316
                'core' : {
317
                        'data' : {
318
                                "url" : getTreeLoadURL(),
319
                                "data" : function (node) {
320
                                        return { "id" : node.id };
321
                                }
322
                        },
323
                        "multiple": false
324
                },
325
                'conditionalselect' : function (node) {
68 daniel-mar 326
                        if (node.original.conditionalselect !== undefined) {
327
                                return eval(node.original.conditionalselect);
2 daniel-mar 328
                        } else {
399 daniel-mar 329
                                return performCloseQueryCB();
2 daniel-mar 330
                        }
331
                },
332
        })
333
        .on('ready.jstree', function (e, data) {
334
                var url = new URL(window.location.href);
335
                var goto = url.searchParams.get("goto");
336
                if (goto == null) goto = "oidplus:system"; // the page was not called with ?goto=...
183 daniel-mar 337
                $("#gotoedit").val(goto);
2 daniel-mar 338
 
107 daniel-mar 339
                // By setting current_node, select_node() will not cause ajax.php?action=get_description to load (since we already loaded the first static content via PHP, for search engines mainly)
2 daniel-mar 340
                // But then we need to set the history state manually
341
                current_node = goto;
100 daniel-mar 342
                window.history.replaceState({
107 daniel-mar 343
                        "node_id":goto,
100 daniel-mar 344
                        "titleHTML":$('#real_title').html(),
345
                        "textHTML":$('#real_content').html(),
108 daniel-mar 346
                        "staticlinkHREF":"index.php?goto="+encodeURIComponent(goto),
113 daniel-mar 347
                }, $('#real_title').html(), "?goto="+encodeURIComponent(goto));
2 daniel-mar 348
 
349
                if (goto != null) data.instance.select_node([goto]);
128 daniel-mar 350
 
137 daniel-mar 351
                setTimeout(glayoutWorkaroundA, 100);
352
                setTimeout(glayoutWorkaroundB, 100);
2 daniel-mar 353
        })
354
        .on('select_node.jstree', function (node, selected, event) {
120 daniel-mar 355
                mobileNavClose();
95 daniel-mar 356
 
9 daniel-mar 357
                var id = selected.node.id;
114 daniel-mar 358
                if ((!popstate_running) && (current_node != id)) {
399 daniel-mar 359
                        // 4th argument: we force the reload (because in the
360
                        // conditional select above, we already asked if
361
                        // tinyMCE needs to be saved)
362
                        openOidInPanel(id, false, '', true);
2 daniel-mar 363
                }
364
        });
365
 
366
        // --- Layout
367
 
122 daniel-mar 368
        document.getElementById('system_title_menu').style.display = "block";
120 daniel-mar 369
 
355 daniel-mar 370
        var tmpObjectTree = _L("OBJECT TREE").replace(/(.{1})/g,"$1<br>");
371
        tmpObjectTree = tmpObjectTree.substring(0, tmpObjectTree.length-"<br>".length);
372
 
120 daniel-mar 373
        $('#oidtree').addClass('ui-layout-west');
374
        $('#content_window').addClass('ui-layout-center');
375
        $('#system_title_bar').addClass('ui-layout-north');
128 daniel-mar 376
        glayout = $('#frames').layout({
120 daniel-mar 377
                north__size:                  40,
378
                north__slidable:              false,
379
                north__closable:              false,
380
                north__resizable:             false,
381
                west__size:                   450,
382
                west__spacing_closed:         20,
383
                west__togglerLength_closed:   230,
384
                west__togglerAlign_closed:    "top",
355 daniel-mar 385
                west__togglerContent_closed:  tmpObjectTree,
386
                west__togglerTip_closed:      _L("Open & Pin Menu"),
387
                west__sliderTip:              _L("Slide Open Menu"),
120 daniel-mar 388
                west__slideTrigger_open:      "mouseover",
389
                center__maskContents:         true // IMPORTANT - enable iframe masking
390
        });
183 daniel-mar 391
 
185 daniel-mar 392
        $("#gotobox").addClass("mobilehidden");
355 daniel-mar 393
        $("#languageBox").addClass("mobilehidden");
183 daniel-mar 394
        document.getElementById('gotobox').style.display = "block";
395
        $('#gotoedit').keypress(function(event) {
396
                var keycode = (event.keyCode ? event.keyCode : event.which);
397
                if (keycode == '13') {
398
                        gotoButtonClicked();
399
                }
400
        });
376 daniel-mar 401
});
2 daniel-mar 402
 
137 daniel-mar 403
function glayoutWorkaroundA() {
211 daniel-mar 404
        // "Bug A": Sometimes, the design is completely destroyed after reloading the page. It does not help when glayout.resizeAll()
137 daniel-mar 405
        //          is called at the beginning (e.g. during the ready function), and it does not help if we wait 500ms.
406
        //          So we do it all the time. It has probably something to do with slow loading times, since the error
407
        //          does only appear when the page is "blank" for a short while while it is loading.
408
        glayout.resizeAll();
409
        setTimeout(glayoutWorkaroundA, 100);
287 daniel-mar 410
 
411
        // "Bug C": With Firefox (And sometimes with Chrome), there is a gap between the content-window (including scroll bars)
412
        //          and the right corner of the screen. Removing the explicit width solves this problem.
413
        document.getElementById("content_window").style.removeProperty("width");
137 daniel-mar 414
}
415
 
416
function glayoutWorkaroundB() {
417
        // "Bug B": Sometimes, after reload, weird space between oidtree and content window, because oidtree has size of 438px
418
        document.getElementById("oidtree").style.width = "450px";
419
}
420
 
120 daniel-mar 421
function mobileNavClose() {
422
        if ($("#system_title_menu").is(":hidden")) {
423
                return;
424
        }
425
 
426
        $("#oidtree").slideUp("medium").promise().done(function() {
427
                $("#oidtree").addClass("ui-layout-west");
428
                $("#oidtree").show();
185 daniel-mar 429
//              $("#gotobox").hide();
355 daniel-mar 430
//              $("#languageBox").hide();
185 daniel-mar 431
                $("#gotobox").addClass("mobilehidden");
355 daniel-mar 432
                $("#languageBox").addClass("mobilehidden");
120 daniel-mar 433
        });
434
        $("#system_title_menu").removeClass("active");
95 daniel-mar 435
}
436
 
120 daniel-mar 437
function mobileNavOpen() {
438
        $("#oidtree").hide();
439
        $("#oidtree").removeClass("ui-layout-west");
440
        $("#oidtree").slideDown("medium");
185 daniel-mar 441
//      $("#gotobox").show();
355 daniel-mar 442
//      $("#languageBox").show();
185 daniel-mar 443
        $("#gotobox").removeClass("mobilehidden");
355 daniel-mar 444
        $("#languageBox").removeClass("mobilehidden");
120 daniel-mar 445
        $("#system_title_menu").addClass("active");
446
}
447
 
105 daniel-mar 448
function mobileNavButtonClick(sender) {
120 daniel-mar 449
        if ($("#oidtree").hasClass("ui-layout-west")) {
450
                mobileNavOpen();
103 daniel-mar 451
        } else {
120 daniel-mar 452
                mobileNavClose();
103 daniel-mar 453
        }
454
}
105 daniel-mar 455
 
456
function mobileNavButtonHover(sender) {
457
        sender.classList.toggle("hover");
458
}
183 daniel-mar 459
 
460
function gotoButtonClicked() {
461
        openOidInPanel($("#gotoedit").val(), 1);
462
}
199 daniel-mar 463
 
219 daniel-mar 464
function jumpToAnchor(anchor) {
465
        window.location.href = "#" + anchor;
466
}
467
 
355 daniel-mar 468
function getCookie(cname) {
469
        // Source: https://www.w3schools.com/js/js_cookies.asp
470
        var name = cname + "=";
471
        var decodedCookie = decodeURIComponent(document.cookie);
472
        var ca = decodedCookie.split(';');
473
        for(var i = 0; i <ca.length; i++) {
474
                var c = ca[i];
475
                while (c.charAt(0) == ' ') {
476
                        c = c.substring(1);
477
                }
478
                if (c.indexOf(name) == 0) {
479
                        return c.substring(name.length, c.length);
480
                }
481
        }
482
        return undefined;
483
}
484
 
356 daniel-mar 485
function setCookie(cname, cvalue, exdays, path) {
486
        var d = new Date();
487
        d.setTime(d.getTime() + (exdays*24*60*60*1000));
488
        var expires = exdays == 0 ? "" : "; expires="+d.toUTCString();
489
        document.cookie = cname + "=" + cvalue + expires + ";path=" + path;
490
}
491
 
355 daniel-mar 492
function setLanguage(lngid) {
356 daniel-mar 493
        setCookie('LANGUAGE', lngid, 0/*Until browser closes*/, location.pathname);
494
 
495
        $(".lng_flag").each(function(){
496
                $(this).addClass("picture_ghost");
355 daniel-mar 497
        });
356 daniel-mar 498
        $("#lng_flag_"+lngid).removeClass("picture_ghost");
499
 
500
        if (isInternetExplorer()) {
501
                // Internet Explorer has problems with sending new cookies to new AJAX requests, so we reload the page completely
502
                window.location.reload();
503
        } else {
360 daniel-mar 504
                reloadContent();
356 daniel-mar 505
                mobileNavClose();
506
        }
355 daniel-mar 507
}
508
 
509
function getCurrentLang() {
360 daniel-mar 510
        // Note: If the argument "?lang=" is used, PHP will automatically set a Cookie, so it is OK when we only check for the cookie
355 daniel-mar 511
        var lang = getCookie('LANGUAGE');
512
        return (typeof lang != "undefined") ? lang : DEFAULT_LANGUAGE;
513
}
514
 
360 daniel-mar 515
function _L() {
516
        var args = Array.prototype.slice.call(arguments);
517
        var str = args.shift();
518
 
519
        var tmp = "";
520
        if (typeof language_messages[getCurrentLang()] == "undefined") {
521
                tmp = str;
522
        } else {
523
                var msg = language_messages[getCurrentLang()][str];
524
                if (typeof msg != "undefined") {
525
                        tmp = msg;
526
                } else {
527
                        tmp = str;
528
                }
529
        }
530
 
531
        tmp = tmp.replace('###', language_tblprefix);
532
 
533
        var n = 1;
534
        while (args.length > 0) {
535
                var val = args.shift();
536
                tmp = tmp.replace("%"+n, val);
537
                n++;
538
        }
539
 
370 daniel-mar 540
        tmp = tmp.replace("%%", "%");
541
 
360 daniel-mar 542
        return tmp;
355 daniel-mar 543
}