-
Notifications
You must be signed in to change notification settings - Fork 258
/
Copy pathadmin.js
623 lines (524 loc) · 19.8 KB
/
admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
/*
smf_AdminIndex(oOptions)
{
public init()
public loadAdminIndex()
public setAnnouncements()
public showCurrentVersion()
public checkUpdateAvailable()
}
smf_ViewVersions(oOptions)
{
public init()
public loadViewVersions
public swapOption(oSendingElement, sName)
public compareVersions(sCurrent, sTarget)
public determineVersions()
}
*/
// Handle the JavaScript surrounding the admin and moderation center.
function smf_AdminIndex(oOptions)
{
this.opt = oOptions;
this.init();
}
smf_AdminIndex.prototype.init = function ()
{
window.adminIndexInstanceRef = this;
var fHandlePageLoaded = function () {
window.adminIndexInstanceRef.loadAdminIndex();
}
addLoadEvent(fHandlePageLoaded);
}
smf_AdminIndex.prototype.loadAdminIndex = function ()
{
// Load the text box containing the latest news items.
if (this.opt.bLoadAnnouncements)
this.setAnnouncements();
// Load the current SMF and your SMF version numbers.
if (this.opt.bLoadVersions)
this.showCurrentVersion();
// Load the text box that sais there's a new version available.
if (this.opt.bLoadUpdateNotification)
this.checkUpdateAvailable();
}
smf_AdminIndex.prototype.setAnnouncements = function ()
{
if (!('smfAnnouncements' in window) || !('length' in window.smfAnnouncements))
return;
var sMessages = '';
for (var i = 0; i < window.smfAnnouncements.length; i++)
sMessages += this.opt.sAnnouncementMessageTemplate.replace('%href%', window.smfAnnouncements[i].href).replace('%subject%', window.smfAnnouncements[i].subject).replace('%time%', window.smfAnnouncements[i].time).replace('%message%', window.smfAnnouncements[i].message);
setInnerHTML(document.getElementById(this.opt.sAnnouncementContainerId), this.opt.sAnnouncementTemplate.replace('%content%', sMessages));
}
smf_AdminIndex.prototype.showCurrentVersion = function ()
{
if (!('smfVersion' in window))
return;
var oSmfVersionContainer = document.getElementById(this.opt.sSmfVersionContainerId);
var oYourVersionContainer = document.getElementById(this.opt.sYourVersionContainerId);
setInnerHTML(oSmfVersionContainer, window.smfVersion);
var sCurrentVersion = getInnerHTML(oYourVersionContainer);
if (sCurrentVersion != window.smfVersion)
setInnerHTML(oYourVersionContainer, this.opt.sVersionOutdatedTemplate.replace('%currentVersion%', sCurrentVersion));
}
smf_AdminIndex.prototype.checkUpdateAvailable = function ()
{
if (!('smfUpdatePackage' in window))
return;
var oContainer = document.getElementById(this.opt.sUpdateNotificationContainerId);
// Are we setting a custom title and message?
var sTitle = 'smfUpdateTitle' in window ? window.smfUpdateTitle : this.opt.sUpdateNotificationDefaultTitle;
var sMessage = 'smfUpdateNotice' in window ? window.smfUpdateNotice : this.opt.sUpdateNotificationDefaultMessage;
setInnerHTML(oContainer, this.opt.sUpdateNotificationTemplate.replace('%title%', sTitle).replace('%message%', sMessage));
// Parse in the package download URL if it exists in the string.
document.getElementById('update-link').href = this.opt.sUpdateNotificationLink.replace('%package%', window.smfUpdatePackage);
oContainer.className = ('smfUpdateCritical' in window) ? 'errorbox' : 'noticebox';
}
function smf_ViewVersions (oOptions)
{
this.opt = oOptions;
this.oSwaps = {};
this.init();
}
smf_ViewVersions.prototype.init = function ()
{
// Load this on loading of the page.
window.viewVersionsInstanceRef = this;
var fHandlePageLoaded = function () {
window.viewVersionsInstanceRef.loadViewVersions();
}
addLoadEvent(fHandlePageLoaded);
}
smf_ViewVersions.prototype.loadViewVersions = function ()
{
this.determineVersions();
}
smf_ViewVersions.prototype.swapOption = function (oSendingElement, sName)
{
// If it is undefined, or currently off, turn it on - otherwise off.
this.oSwaps[sName] = !(sName in this.oSwaps) || !this.oSwaps[sName];
if (this.oSwaps[sName])
$("#" + sName).show(300);
else
$("#" + sName).hide(300);
// Unselect the link and return false.
oSendingElement.blur();
return false;
}
smf_ViewVersions.prototype.compareVersions = function (sCurrent, sTarget)
{
var aVersions = aParts = new Array();
var aCompare = new Array(sCurrent, sTarget);
for (var i = 0; i < 2; i++)
{
// Clean the version and extract the version parts.
var sClean = aCompare[i].toLowerCase().replace(/ /g, '').replace(/2.0rc1-1/, '2.0rc1.1');
aParts = sClean.match(/(\d+)(?:\.(\d+|))?(?:\.)?(\d+|)(?:(alpha|beta|rc)(\d+|)(?:\.)?(\d+|))?(?:(dev))?(\d+|)/);
// No matches?
if (aParts == null)
return false;
// Build an array of parts.
aVersions[i] = [
aParts[1] > 0 ? parseInt(aParts[1]) : 0,
aParts[2] > 0 ? parseInt(aParts[2]) : 0,
aParts[3] > 0 ? parseInt(aParts[3]) : 0,
typeof(aParts[4]) == 'undefined' ? 'stable' : aParts[4],
aParts[5] > 0 ? parseInt(aParts[5]) : 0,
aParts[6] > 0 ? parseInt(aParts[6]) : 0,
typeof(aParts[7]) != 'undefined',
];
}
// Loop through each category.
for (i = 0; i < 7; i++)
{
// Is there something for us to calculate?
if (aVersions[0][i] != aVersions[1][i])
{
// Dev builds are a problematic exception.
// (stable) dev < (stable) but (unstable) dev = (unstable)
if (i == 3)
return aVersions[0][i] < aVersions[1][i] ? !aVersions[1][6] : aVersions[0][6];
else if (i == 6)
return aVersions[0][6] ? aVersions[1][3] == 'stable' : false;
// Otherwise a simple comparison.
else
return aVersions[0][i] < aVersions[1][i];
}
}
// They are the same!
return false;
}
smf_ViewVersions.prototype.determineVersions = function ()
{
var oHighYour = {
Sources: '??',
Default: '??',
Languages: '??',
Templates: '??',
Tasks: '??'
};
var oHighCurrent = {
Sources: '??',
Default: '??',
Languages: '??',
Templates: '??',
Tasks: '??'
};
var oLowVersion = {
Sources: false,
Default: false,
Languages: false,
Templates: false,
Tasks: false
};
var sSections = [
'Sources',
'Default',
'Languages',
'Templates',
'Tasks'
];
for (var i = 0, n = sSections.length; i < n; i++)
{
// Collapse all sections.
var oSection = document.getElementById(sSections[i]);
if (typeof(oSection) == 'object' && oSection != null)
oSection.style.display = 'none';
// Make all section links clickable.
var oSectionLink = document.getElementById(sSections[i] + '-link');
if (typeof(oSectionLink) == 'object' && oSectionLink != null)
{
oSectionLink.instanceRef = this;
oSectionLink.sSection = sSections[i];
oSectionLink.onclick = function () {
this.instanceRef.swapOption(this, this.sSection);
return false;
};
}
}
if (!('smfVersions' in window))
window.smfVersions = {};
for (var sFilename in window.smfVersions)
{
if (!document.getElementById('current' + sFilename))
continue;
var sYourVersion = getInnerHTML(document.getElementById('your' + sFilename));
var sCurVersionType;
for (var sVersionType in oLowVersion)
if (sFilename.substr(0, sVersionType.length) == sVersionType)
{
sCurVersionType = sVersionType;
break;
}
if (typeof(sCurVersionType) != 'undefined')
{
if ((this.compareVersions(oHighYour[sCurVersionType], sYourVersion) || oHighYour[sCurVersionType] == '??') && !oLowVersion[sCurVersionType])
oHighYour[sCurVersionType] = sYourVersion;
if (this.compareVersions(oHighCurrent[sCurVersionType], smfVersions[sFilename]) || oHighCurrent[sCurVersionType] == '??')
oHighCurrent[sCurVersionType] = smfVersions[sFilename];
if (this.compareVersions(sYourVersion, smfVersions[sFilename]))
{
oLowVersion[sCurVersionType] = sYourVersion;
document.getElementById('your' + sFilename).className = 'alert';
}
}
else if (this.compareVersions(sYourVersion, smfVersions[sFilename]))
oLowVersion[sCurVersionType] = sYourVersion;
setInnerHTML(document.getElementById('current' + sFilename), smfVersions[sFilename]);
setInnerHTML(document.getElementById('your' + sFilename), sYourVersion);
}
if (!('smfLanguageVersions' in window))
window.smfLanguageVersions = {};
for (sFilename in window.smfLanguageVersions)
{
for (var i = 0; i < this.opt.aKnownLanguages.length; i++)
{
if (!document.getElementById('current' + sFilename + this.opt.aKnownLanguages[i]))
continue;
setInnerHTML(document.getElementById('current' + sFilename + this.opt.aKnownLanguages[i]), smfLanguageVersions[sFilename]);
sYourVersion = getInnerHTML(document.getElementById('your' + sFilename + this.opt.aKnownLanguages[i]));
setInnerHTML(document.getElementById('your' + sFilename + this.opt.aKnownLanguages[i]), sYourVersion);
if ((this.compareVersions(oHighYour.Languages, sYourVersion) || oHighYour.Languages == '??') && !oLowVersion.Languages)
oHighYour.Languages = sYourVersion;
if (this.compareVersions(oHighCurrent.Languages, smfLanguageVersions[sFilename]) || oHighCurrent.Languages == '??')
oHighCurrent.Languages = smfLanguageVersions[sFilename];
if (this.compareVersions(sYourVersion, smfLanguageVersions[sFilename]))
{
oLowVersion.Languages = sYourVersion;
document.getElementById('your' + sFilename + this.opt.aKnownLanguages[i]).style.color = 'red';
}
}
}
setInnerHTML(document.getElementById('yourSources'), oLowVersion.Sources ? oLowVersion.Sources : oHighYour.Sources);
setInnerHTML(document.getElementById('currentSources'), oHighCurrent.Sources);
if (oLowVersion.Sources)
document.getElementById('yourSources').className = 'alert';
setInnerHTML(document.getElementById('yourDefault'), oLowVersion.Default ? oLowVersion.Default : oHighYour.Default);
setInnerHTML(document.getElementById('currentDefault'), oHighCurrent.Default);
if (oLowVersion.Default)
document.getElementById('yourDefault').className = 'alert';
if (document.getElementById('Templates'))
{
setInnerHTML(document.getElementById('yourTemplates'), oLowVersion.Templates ? oLowVersion.Templates : oHighYour.Templates);
setInnerHTML(document.getElementById('currentTemplates'), oHighCurrent.Templates);
if (oLowVersion.Templates)
document.getElementById('yourTemplates').className = 'alert';
}
setInnerHTML(document.getElementById('yourLanguages'), oLowVersion.Languages ? oLowVersion.Languages : oHighYour.Languages);
setInnerHTML(document.getElementById('currentLanguages'), oHighCurrent.Languages);
if (oLowVersion.Languages)
document.getElementById('yourLanguages').className = 'alert';
setInnerHTML(document.getElementById('yourTasks'), oLowVersion.Tasks ? oLowVersion.Tasks : oHighYour.Tasks);
setInnerHTML(document.getElementById('currentTasks'), oHighCurrent.Tasks);
if (oLowVersion.Tasks)
document.getElementById('yourTasks').className = 'alert';
}
function addNewWord()
{
setOuterHTML(document.getElementById('moreCensoredWords'), '<div style="margin-top: 1ex;"><input type="text" name="censor_vulgar[]" size="30"> => <input type="text" name="censor_proper[]" size="30"><' + '/div><div id="moreCensoredWords"><' + '/div>');
}
function toggleBBCDisabled(section, disable)
{
elems = document.getElementById(section).getElementsByTagName('*');
for (var i = 0; i < elems.length; i++)
{
if (typeof(elems[i].name) == "undefined" || (elems[i].name.substr((section.length + 1), (elems[i].name.length - 2 - (section.length + 1))) != "enabledTags") || (elems[i].name.indexOf(section) != 0))
continue;
elems[i].disabled = disable;
}
document.getElementById("bbc_" + section + "_select_all").disabled = disable;
}
function updateInputBoxes()
{
curType = document.getElementById("field_type").value;
privStatus = document.getElementById("private").value;
document.getElementById("max_length_dt").style.display = curType == "text" || curType == "textarea" ? "" : "none";
document.getElementById("max_length_dd").style.display = curType == "text" || curType == "textarea" ? "" : "none";
document.getElementById("dimension_dt").style.display = curType == "textarea" ? "" : "none";
document.getElementById("dimension_dd").style.display = curType == "textarea" ? "" : "none";
document.getElementById("bbc_dt").style.display = curType == "text" || curType == "textarea" ? "" : "none";
document.getElementById("bbc_dd").style.display = curType == "text" || curType == "textarea" ? "" : "none";
document.getElementById("options_dt").style.display = curType == "select" || curType == "radio" ? "" : "none";
document.getElementById("options_dd").style.display = curType == "select" || curType == "radio" ? "" : "none";
document.getElementById("default_dt").style.display = curType == "check" ? "" : "none";
document.getElementById("default_dd").style.display = curType == "check" ? "" : "none";
document.getElementById("mask_dt").style.display = curType == "text" ? "" : "none";
document.getElementById("mask").style.display = curType == "text" ? "" : "none";
document.getElementById("can_search_dt").style.display = curType == "text" || curType == "textarea" || curType == "select" ? "" : "none";
document.getElementById("can_search_dd").style.display = curType == "text" || curType == "textarea" || curType == "select" ? "" : "none";
document.getElementById("regex_div").style.display = curType == "text" && document.getElementById("mask").value == "regex" ? "" : "none";
document.getElementById("display").disabled = false;
// Cannot show this on the topic
if (curType == "textarea" || privStatus >= 2)
{
document.getElementById("display").checked = false;
document.getElementById("display").disabled = true;
}
}
function addOption()
{
setOuterHTML(document.getElementById("addopt"), '<br><input type="radio" name="default_select" value="' + startOptID + '" id="' + startOptID + '"><input type="text" name="select_option[' + startOptID + ']" value=""><span id="addopt"></span>');
startOptID++;
}
//Create a named element dynamically - thanks to: https://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/
function createNamedElement(type, name, customFields)
{
var element = null;
if (!customFields)
customFields = "";
// Try the IE way; this fails on standards-compliant browsers
try
{
element = document.createElement("<" + type + ' name="' + name + '" ' + customFields + ">");
}
catch (e)
{
}
if (!element || element.nodeName != type.toUpperCase())
{
// Non-IE browser; use canonical method to create named element
element = document.createElement(type);
element.name = name;
}
return element;
}
function smfSetLatestThemes()
{
if (typeof(window.smfLatestThemes) != "undefined")
setInnerHTML(document.getElementById("themeLatest"), window.smfLatestThemes);
if (tempOldOnload)
tempOldOnload();
}
function changeVariant(sVariant)
{
document.getElementById('variant_preview').src = oThumbnails[sVariant];
}
// The idea here is simple: don't refresh the preview on every keypress, but do refresh after they type.
function setPreviewTimeout()
{
if (previewTimeout)
{
window.clearTimeout(previewTimeout);
previewTimeout = null;
}
previewTimeout = window.setTimeout("refreshPreview(true); previewTimeout = null;", 500);
}
function toggleDuration(toChange)
{
if (toChange == 'fixed')
{
document.getElementById("fixed_area").style.display = "inline";
document.getElementById("flexible_area").style.display = "none";
}
else
{
document.getElementById("fixed_area").style.display = "none";
document.getElementById("flexible_area").style.display = "inline";
}
}
function calculateNewValues()
{
var total = 0;
for (var i = 1; i <= 6; i++)
{
total += parseInt(document.getElementById('weight' + i + '_val').value);
}
setInnerHTML(document.getElementById('weighttotal'), total);
for (var i = 1; i <= 6; i++)
{
setInnerHTML(document.getElementById('weight' + i), (Math.round(1000 * parseInt(document.getElementById('weight' + i + '_val').value) / total) / 10) + '%');
}
}
function switchType()
{
document.getElementById("ul_settings").style.display = document.getElementById("method-existing").checked ? "none" : "";
document.getElementById("ex_settings").style.display = document.getElementById("method-upload").checked ? "none" : "";
}
function swapUploads()
{
$('.upload_more').toggle();
$('.upload_more input').prop('disabled', function(i, v) { return !v; });
$('.upload_sameall').toggle();
$('.upload_sameall input').prop('disabled', function(i, v) { return !v; });
}
function selectMethod(element)
{
document.getElementById("method-existing").checked = element != "upload";
document.getElementById("method-upload").checked = element == "upload";
}
function updatePreview(filename, filepath)
{
var currentImage = document.getElementById("preview");
var relative_url;
if (typeof filepath == 'undefined' || filepath == null || filepath == '')
relative_url = "/" + filename;
else
relative_url = "/" + filepath + "/" + filename;
// Make sure no sneaky people are trying to be sneaky
var regex = new RegExp("^/(" + smf_smiley_sets.split(",").join("|") + ")/[^.]+\.(gif|png|jpg|jpeg|tiff|svg)$");
var is_valid = relative_url.match(regex);
if (is_valid !== null)
currentImage.src = smf_smileys_url + relative_url;
}
function testFTP()
{
ajax_indicator(true);
// What we need to post.
var oPostData = {
0: "ftp_server",
1: "ftp_port",
2: "ftp_username",
3: "ftp_password",
4: "ftp_path"
}
var sPostData = "";
for (i = 0; i < 5; i++)
sPostData = sPostData + (sPostData.length == 0 ? "" : "&") + oPostData[i] + "=" + escape(document.getElementById(oPostData[i]).value);
// Post the data out.
sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + 'action=admin;area=packages;sa=ftptest;xml;' + smf_session_var + '=' + smf_session_id, sPostData, testFTPResults);
}
function expandFolder(folderIdent, folderReal)
{
// See if it already exists.
var possibleTags = document.getElementsByTagName("tr");
var foundOne = false;
for (var i = 0; i < possibleTags.length; i++)
{
if (possibleTags[i].id.indexOf("content_" + folderIdent + ":-:") == 0)
{
possibleTags[i].style.display = possibleTags[i].style.display == "none" ? "" : "none";
foundOne = true;
}
}
// Got something then we're done.
if (foundOne)
{
return false;
}
// Otherwise we need to get the wicked thing.
else if (window.XMLHttpRequest)
{
ajax_indicator(true);
getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + 'action=admin;area=packages;onlyfind=' + escape(folderReal) + ';sa=perms;xml;' + smf_session_var + '=' + smf_session_id, onNewFolderReceived);
}
// Otherwise reload.
else
return true;
return false;
}
function dynamicExpandFolder()
{
expandFolder(this.ident, this.path);
return false;
}
function repeatString(sString, iTime)
{
if (iTime < 1)
return '';
else
return sString + repeatString(sString, iTime - 1);
}
function select_in_category(cat_id, elem, brd_list)
{
for (var brd in brd_list)
document.getElementById(elem.value + '_brd' + brd_list[brd]).checked = true;
elem.selectedIndex = 0;
}
/*
* Attachments Settings
*/
function toggleSubDir ()
{
var auto_attach = document.getElementById('automanage_attachments');
var use_sub_dir = document.getElementById('use_subdirectories_for_attachments');
var dir_elem = document.getElementById('basedirectory_for_attachments');
use_sub_dir.disabled = !Boolean(auto_attach.selectedIndex);
if (use_sub_dir.disabled)
{
use_sub_dir.style.display = "none";
document.getElementById('setting_use_subdirectories_for_attachments').parentNode.style.display = "none";
dir_elem.style.display = "none";
document.getElementById('setting_basedirectory_for_attachments').parentNode.style.display = "none";
}
else
{
use_sub_dir.style.display = "";
document.getElementById('setting_use_subdirectories_for_attachments').parentNode.style.display = "";
dir_elem.style.display = "";
document.getElementById('setting_basedirectory_for_attachments').parentNode.style.display = "";
}
toggleBaseDir();
}
function toggleBaseDir ()
{
var auto_attach = document.getElementById('automanage_attachments');
var sub_dir = document.getElementById('use_subdirectories_for_attachments');
var dir_elem = document.getElementById('basedirectory_for_attachments');
if (auto_attach.selectedIndex == 0)
{
dir_elem.disabled = 1;
}
else
dir_elem.disabled = !sub_dir.checked;
}