corefwnode 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +40 -40
- package/build.js +266 -266
- package/index.js +240 -240
- package/lib/CfwObject.js +1629 -1626
- package/lib/Decorator.js +322 -322
- package/lib/ErrorCodes.js +111 -111
- package/lib/ErrorControl.js +50 -50
- package/lib/GeneralHandling.js +638 -638
- package/lib/Language.js +139 -139
- package/lib/MySql.js +141 -142
- package/lib/Observer.js +75 -75
- package/lib/Validator.js +536 -536
- package/lib/Wiki.js +409 -409
- package/lib/errors/CoreError.js +11 -11
- package/lib/errors/SQLError.js +125 -125
- package/objects/AclGroups.js +69 -69
- package/objects/AclObjects.js +46 -46
- package/objects/AclPrivilages.js +202 -202
- package/objects/EmailTemplates.js +108 -108
- package/objects/Session.js +317 -317
- package/objects/SiteProps.js +55 -55
- package/objects/TransLang.js +39 -39
- package/objects/Translator.js +345 -345
- package/objects/UserCompanies.js +46 -46
- package/objects/Users.js +409 -409
- package/objects/UsersData.js +85 -85
- package/objects/Wiki.js +425 -425
- package/objects/WikiCategory.js +40 -40
- package/objects/WikiTemplates.js +92 -92
- package/objects/index.js +47 -47
- package/package.json +31 -32
package/lib/Wiki.js
CHANGED
|
@@ -1,409 +1,409 @@
|
|
|
1
|
-
const { CoreError } = require('./errors/CoreError');
|
|
2
|
-
|
|
3
|
-
const WikiTemplates = require('../objects/WikiTemplates.js');
|
|
4
|
-
const GeneralHandling = require('./GeneralHandling.js');
|
|
5
|
-
/**
|
|
6
|
-
* Wiki = class for all static (database) text that site uses, provides parsing functionalities
|
|
7
|
-
*
|
|
8
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
9
|
-
*
|
|
10
|
-
* @since 1.0
|
|
11
|
-
* @todo This all things should go to Wiki Object, not here
|
|
12
|
-
* @package CoreFw
|
|
13
|
-
*/
|
|
14
|
-
module.exports = class Wiki
|
|
15
|
-
{
|
|
16
|
-
/**
|
|
17
|
-
* Constructor setting needed object and fetching wiki
|
|
18
|
-
* Set admin to true if you want to enable inline editing (on-site editing) for super administrators
|
|
19
|
-
*
|
|
20
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
21
|
-
*
|
|
22
|
-
* @since 1.0
|
|
23
|
-
*
|
|
24
|
-
* @package CoreFw
|
|
25
|
-
* @param String wikiName
|
|
26
|
-
* @param boolean admin
|
|
27
|
-
* @return void
|
|
28
|
-
*/
|
|
29
|
-
constructor(session, wikiName, fallback = false)
|
|
30
|
-
{
|
|
31
|
-
const me = this;
|
|
32
|
-
/**
|
|
33
|
-
* Fallback to default language if article in requested language not found
|
|
34
|
-
* @type boolean
|
|
35
|
-
*/
|
|
36
|
-
me.fallback = fallback;
|
|
37
|
-
/**
|
|
38
|
-
* Resulting content Array
|
|
39
|
-
* @type Array
|
|
40
|
-
*/
|
|
41
|
-
me.content = {};
|
|
42
|
-
|
|
43
|
-
me.session = session;
|
|
44
|
-
me.lib = me.session.lib;
|
|
45
|
-
me.db = session.db;
|
|
46
|
-
me.lang = session.lang;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
translate(key)
|
|
50
|
-
{
|
|
51
|
-
const me = this;
|
|
52
|
-
|
|
53
|
-
return me.lang.translate(key, me.session.langId);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Prepare wiki name
|
|
58
|
-
*
|
|
59
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
60
|
-
*
|
|
61
|
-
* @since 1.0
|
|
62
|
-
*
|
|
63
|
-
* @package CoreFw
|
|
64
|
-
* @param String wikiName
|
|
65
|
-
* @return String
|
|
66
|
-
*/
|
|
67
|
-
static prepareWikiName(wikiName)
|
|
68
|
-
{
|
|
69
|
-
if (wikiName === undefined)
|
|
70
|
-
{
|
|
71
|
-
return '';
|
|
72
|
-
}
|
|
73
|
-
return wikiName.replace(/ /g, '-', wikiName).toLowerCase();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Get wiki
|
|
78
|
-
*
|
|
79
|
-
* Returns:
|
|
80
|
-
* <code>
|
|
81
|
-
* return {
|
|
82
|
-
* 'id': '',
|
|
83
|
-
* 'header': '',
|
|
84
|
-
* 'date': '',
|
|
85
|
-
* 'name': '',
|
|
86
|
-
* 'categoryId': '',
|
|
87
|
-
* 'content': ''
|
|
88
|
-
* );
|
|
89
|
-
* </code>
|
|
90
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
91
|
-
*
|
|
92
|
-
* @since 1.0
|
|
93
|
-
*
|
|
94
|
-
* @package CoreFw
|
|
95
|
-
* @return Array
|
|
96
|
-
*/
|
|
97
|
-
async getWiki(wikiName)
|
|
98
|
-
{
|
|
99
|
-
const me = this;
|
|
100
|
-
|
|
101
|
-
me.wikiName = Wiki.prepareWikiName(wikiName);
|
|
102
|
-
let results = await me.db.query(`SELECT
|
|
103
|
-
wc.*, wct.categoryName
|
|
104
|
-
FROM wiki_content wc
|
|
105
|
-
JOIN wiki_category wct ON wct.categoryId=wc.categoryId
|
|
106
|
-
WHERE wc.name=? AND wc.langId=?`, [me.wikiName, me.session.langId]);
|
|
107
|
-
let row = results[0];
|
|
108
|
-
|
|
109
|
-
if (row !== undefined && me.lang.lang !== me.session.langId && me.fallback === true)
|
|
110
|
-
{
|
|
111
|
-
results = await me.db.query(`SELECT
|
|
112
|
-
wc.*, wct.categoryName
|
|
113
|
-
FROM wiki_content wc
|
|
114
|
-
JOIN wiki_category wct ON wct.categoryId=wc.categoryId
|
|
115
|
-
WHERE wc.name=? AND wc.langId=?`, [me.wikiName, me.session.langId]);
|
|
116
|
-
[row] = results;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (row === undefined)
|
|
120
|
-
{
|
|
121
|
-
me.content = {
|
|
122
|
-
header: '', name: '', date: '', content: me.translate('NOWIKIFOUND'),
|
|
123
|
-
};
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
let modularData = {};
|
|
128
|
-
let content;
|
|
129
|
-
|
|
130
|
-
if (row.templateId != null)
|
|
131
|
-
{
|
|
132
|
-
content = await me.returnContentByTemplate(row.templateId, row);
|
|
133
|
-
modularData = JSON.parse(row.modularData);
|
|
134
|
-
}
|
|
135
|
-
else
|
|
136
|
-
if (row.parsedContent !== '' && row.parsedContent != null && me.session.groupId !== 1)
|
|
137
|
-
{
|
|
138
|
-
content = row.parsedContent;
|
|
139
|
-
}
|
|
140
|
-
else
|
|
141
|
-
{
|
|
142
|
-
content = row.content;
|
|
143
|
-
me.cacheContent(content);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
me.content = {
|
|
147
|
-
id: row.wikiId,
|
|
148
|
-
header: row.header,
|
|
149
|
-
date: row.dateTime,
|
|
150
|
-
name: row.name,
|
|
151
|
-
featured: row.featured,
|
|
152
|
-
categoryId: row.categoryId,
|
|
153
|
-
categoryName: row.categoryName,
|
|
154
|
-
templateId: row.templateId,
|
|
155
|
-
content,
|
|
156
|
-
rowdata: row,
|
|
157
|
-
modularData,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async returnContentByTemplate(templateId, wikiData)
|
|
162
|
-
{
|
|
163
|
-
const me = this;
|
|
164
|
-
|
|
165
|
-
const results = await me.db.query('SELECT * FROM wiki_templates WHERE templateId=?', [templateId]);
|
|
166
|
-
const row = results[0];
|
|
167
|
-
|
|
168
|
-
if (row === undefined)
|
|
169
|
-
{
|
|
170
|
-
throw new CoreError({ error: true, notice: 'Wiki template not found' });
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const modularData = JSON.parse(wikiData.modularData);
|
|
174
|
-
|
|
175
|
-
let html = row.content;
|
|
176
|
-
|
|
177
|
-
const vars = [];
|
|
178
|
-
const dats = html.split('{#');
|
|
179
|
-
if (dats[0] !== undefined)
|
|
180
|
-
{
|
|
181
|
-
dats.shift();
|
|
182
|
-
}
|
|
183
|
-
for (const value of dats)
|
|
184
|
-
{
|
|
185
|
-
const dat = value.split('}');
|
|
186
|
-
vars.push(dat[0]);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
for (const value of vars)
|
|
190
|
-
{
|
|
191
|
-
const re = new RegExp(`{#${value}}`, 'g');
|
|
192
|
-
html = html.replace(re, me.translate(value));
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
let re = new RegExp('{mod:header}', 'g');
|
|
196
|
-
html = html.replace(re, wikiData.header);
|
|
197
|
-
|
|
198
|
-
re = new RegExp('{mod:date}', 'g');
|
|
199
|
-
html = html.replace(re, wikiData.dateTime);
|
|
200
|
-
|
|
201
|
-
re = new RegExp('{mod:name}', 'g');
|
|
202
|
-
html = html.replace(re, wikiData.name);
|
|
203
|
-
|
|
204
|
-
re = new RegExp('{mod:category}', 'g');
|
|
205
|
-
html = html.replace(re, wikiData.categoryName);
|
|
206
|
-
|
|
207
|
-
const datOne = html.split('{mod');
|
|
208
|
-
datOne.shift();
|
|
209
|
-
|
|
210
|
-
for (const value of datOne)
|
|
211
|
-
{
|
|
212
|
-
const datSec = value.split('}');
|
|
213
|
-
const datTrd = datSec[0].split(':');
|
|
214
|
-
|
|
215
|
-
re = new RegExp(`{mod${datSec[0]}}`, 'g');
|
|
216
|
-
if (datTrd[1] === 'linkfield' && modularData[`${datTrd[2]}_link`] !== undefined)
|
|
217
|
-
{
|
|
218
|
-
html = html
|
|
219
|
-
.replace(
|
|
220
|
-
re,
|
|
221
|
-
`<a href="${modularData[`${datTrd[2]}_link`]}"`
|
|
222
|
-
+ `alt="${modularData[`${datTrd[2]}_alt`]}" ${(modularData[`${datTrd[2]}_check`] !== undefined)
|
|
223
|
-
? 'checked="checked"'
|
|
224
|
-
: ''}${'>'.modularData[`${datTrd[2]}_text`]}</a>`,
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
else
|
|
228
|
-
{
|
|
229
|
-
const rep = (modularData[datTrd[2]] !== undefined) ? modularData[datTrd[2]] : '';
|
|
230
|
-
html = html.replace(re, rep);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return html;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
async getModules(templateId, initialId = false)
|
|
237
|
-
{
|
|
238
|
-
const me = this;
|
|
239
|
-
|
|
240
|
-
const modules = [];
|
|
241
|
-
let initialValues = {};
|
|
242
|
-
|
|
243
|
-
if (initialId !== false)
|
|
244
|
-
{
|
|
245
|
-
const results = await me.db.query('SELECT * FROM wiki_content WHERE wikiId=?', [initialId]);
|
|
246
|
-
const row = results[0];
|
|
247
|
-
|
|
248
|
-
initialValues = JSON.parse(row.modularData);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (templateId !== '')
|
|
252
|
-
{
|
|
253
|
-
const categories = [];
|
|
254
|
-
const results = await me.db.query('SELECT * FROM images_category ORDER BY categoryId DESC');
|
|
255
|
-
for (const row of results)
|
|
256
|
-
{
|
|
257
|
-
categories.push(row);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const wt = new WikiTemplates(me.session);
|
|
262
|
-
wt.id = templateId;
|
|
263
|
-
await wt.select();
|
|
264
|
-
const datOne = wt.content.split('{mod');
|
|
265
|
-
|
|
266
|
-
datOne.shift();
|
|
267
|
-
|
|
268
|
-
const alreadySetModules = [];
|
|
269
|
-
let n = 1;
|
|
270
|
-
for (const value of datOne)
|
|
271
|
-
{
|
|
272
|
-
const datSec = value.split('}');
|
|
273
|
-
const datTrd = datSec[0].split(':');
|
|
274
|
-
|
|
275
|
-
if (alreadySetModules.indexOf(datTrd[2]) !== -1)
|
|
276
|
-
{
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
alreadySetModules.push(datTrd[2]);
|
|
281
|
-
|
|
282
|
-
switch (datTrd[1])
|
|
283
|
-
{
|
|
284
|
-
case 'textfield':
|
|
285
|
-
modules.push({
|
|
286
|
-
type: 'textfield',
|
|
287
|
-
name: datTrd[2],
|
|
288
|
-
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
289
|
-
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
290
|
-
});
|
|
291
|
-
break;
|
|
292
|
-
case 'linkfield':
|
|
293
|
-
modules.push({
|
|
294
|
-
type: 'linkfield',
|
|
295
|
-
name: datTrd[2],
|
|
296
|
-
namelink: datTrd[2],
|
|
297
|
-
namecheck: datTrd[2],
|
|
298
|
-
namealt: datTrd[2],
|
|
299
|
-
nametext: datTrd[2],
|
|
300
|
-
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
301
|
-
valuetext: (initialValues[`${datTrd[2]}_text`] !== undefined)
|
|
302
|
-
? initialValues[`${datTrd[2]}_text`]
|
|
303
|
-
: '',
|
|
304
|
-
valuelink: (initialValues[`${datTrd[2]}_link`] !== undefined)
|
|
305
|
-
? initialValues[`${datTrd[2]}_link`]
|
|
306
|
-
: '',
|
|
307
|
-
valuealt: (initialValues[`${datTrd[2]}_alt`] !== undefined)
|
|
308
|
-
? initialValues[`${datTrd[2]}_alt`]
|
|
309
|
-
: '',
|
|
310
|
-
checked: (initialValues[`${datTrd[2]}_check`] !== undefined) ? 'checked' : '',
|
|
311
|
-
});
|
|
312
|
-
break;
|
|
313
|
-
case 'imagescat':
|
|
314
|
-
modules.push({
|
|
315
|
-
type: 'imagescat',
|
|
316
|
-
name: datTrd[2],
|
|
317
|
-
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
318
|
-
repeatoptions: (categories !== undefined) ? categories : false,
|
|
319
|
-
});
|
|
320
|
-
break;
|
|
321
|
-
case 'textarea':
|
|
322
|
-
modules.push({
|
|
323
|
-
type: 'textarea',
|
|
324
|
-
name: datTrd[2],
|
|
325
|
-
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
326
|
-
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
327
|
-
});
|
|
328
|
-
break;
|
|
329
|
-
case 'location':
|
|
330
|
-
modules.push({
|
|
331
|
-
type: 'location',
|
|
332
|
-
name: datTrd[2],
|
|
333
|
-
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
334
|
-
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
335
|
-
});
|
|
336
|
-
break;
|
|
337
|
-
case 'wysiwyg':
|
|
338
|
-
modules.push({
|
|
339
|
-
type: 'wysiwyg',
|
|
340
|
-
num: n,
|
|
341
|
-
name: datTrd[2],
|
|
342
|
-
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
343
|
-
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
344
|
-
});
|
|
345
|
-
break;
|
|
346
|
-
case 'fileupload':
|
|
347
|
-
modules.push({
|
|
348
|
-
type: 'fileupload',
|
|
349
|
-
num: n,
|
|
350
|
-
name: datTrd[2],
|
|
351
|
-
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
352
|
-
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
353
|
-
displayhref: 'display: none;',
|
|
354
|
-
displayimg: 'display: none;',
|
|
355
|
-
imagetype: datTrd[3],
|
|
356
|
-
});
|
|
357
|
-
break;
|
|
358
|
-
case 'imgupload':
|
|
359
|
-
modules.push({
|
|
360
|
-
type: 'imgupload',
|
|
361
|
-
num: n,
|
|
362
|
-
name: datTrd[2],
|
|
363
|
-
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
364
|
-
value: (initialValues[datTrd[2]] !== undefined)
|
|
365
|
-
? initialValues[datTrd[2]]
|
|
366
|
-
: '/css/images/ui-bg_diagonals-thick_20_666666_40x40.png',
|
|
367
|
-
});
|
|
368
|
-
break;
|
|
369
|
-
default:
|
|
370
|
-
modules.push({
|
|
371
|
-
type: 'textfield',
|
|
372
|
-
name: datTrd[2],
|
|
373
|
-
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
374
|
-
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
375
|
-
});
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
n += 1;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return modules;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Cache wiki content to database
|
|
387
|
-
*
|
|
388
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
389
|
-
*
|
|
390
|
-
* @since 1.0
|
|
391
|
-
*
|
|
392
|
-
* @package CoreFw
|
|
393
|
-
* @param String content
|
|
394
|
-
* @return Array Array of 'error' boolean 'notice' message
|
|
395
|
-
*/
|
|
396
|
-
async cacheContent(content)
|
|
397
|
-
{
|
|
398
|
-
const me = this;
|
|
399
|
-
|
|
400
|
-
if (me.lib.config.cacheWiki !== undefined && me.lib.config.cacheWiki === false)
|
|
401
|
-
{
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
await me.db.query(
|
|
405
|
-
'UPDATE wiki_content SET parsedContent=? WHERE name=? AND langId=?',
|
|
406
|
-
[content, me.wikiName, me.lang.lang],
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
};
|
|
1
|
+
const { CoreError } = require('./errors/CoreError');
|
|
2
|
+
|
|
3
|
+
const WikiTemplates = require('../objects/WikiTemplates.js');
|
|
4
|
+
const GeneralHandling = require('./GeneralHandling.js');
|
|
5
|
+
/**
|
|
6
|
+
* Wiki = class for all static (database) text that site uses, provides parsing functionalities
|
|
7
|
+
*
|
|
8
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
9
|
+
*
|
|
10
|
+
* @since 1.0
|
|
11
|
+
* @todo This all things should go to Wiki Object, not here
|
|
12
|
+
* @package CoreFw
|
|
13
|
+
*/
|
|
14
|
+
module.exports = class Wiki
|
|
15
|
+
{
|
|
16
|
+
/**
|
|
17
|
+
* Constructor setting needed object and fetching wiki
|
|
18
|
+
* Set admin to true if you want to enable inline editing (on-site editing) for super administrators
|
|
19
|
+
*
|
|
20
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
21
|
+
*
|
|
22
|
+
* @since 1.0
|
|
23
|
+
*
|
|
24
|
+
* @package CoreFw
|
|
25
|
+
* @param String wikiName
|
|
26
|
+
* @param boolean admin
|
|
27
|
+
* @return void
|
|
28
|
+
*/
|
|
29
|
+
constructor(session, wikiName, fallback = false)
|
|
30
|
+
{
|
|
31
|
+
const me = this;
|
|
32
|
+
/**
|
|
33
|
+
* Fallback to default language if article in requested language not found
|
|
34
|
+
* @type boolean
|
|
35
|
+
*/
|
|
36
|
+
me.fallback = fallback;
|
|
37
|
+
/**
|
|
38
|
+
* Resulting content Array
|
|
39
|
+
* @type Array
|
|
40
|
+
*/
|
|
41
|
+
me.content = {};
|
|
42
|
+
|
|
43
|
+
me.session = session;
|
|
44
|
+
me.lib = me.session.lib;
|
|
45
|
+
me.db = session.db;
|
|
46
|
+
me.lang = session.lang;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
translate(key)
|
|
50
|
+
{
|
|
51
|
+
const me = this;
|
|
52
|
+
|
|
53
|
+
return me.lang.translate(key, me.session.langId);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Prepare wiki name
|
|
58
|
+
*
|
|
59
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
60
|
+
*
|
|
61
|
+
* @since 1.0
|
|
62
|
+
*
|
|
63
|
+
* @package CoreFw
|
|
64
|
+
* @param String wikiName
|
|
65
|
+
* @return String
|
|
66
|
+
*/
|
|
67
|
+
static prepareWikiName(wikiName)
|
|
68
|
+
{
|
|
69
|
+
if (wikiName === undefined)
|
|
70
|
+
{
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
return wikiName.replace(/ /g, '-', wikiName).toLowerCase();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get wiki
|
|
78
|
+
*
|
|
79
|
+
* Returns:
|
|
80
|
+
* <code>
|
|
81
|
+
* return {
|
|
82
|
+
* 'id': '',
|
|
83
|
+
* 'header': '',
|
|
84
|
+
* 'date': '',
|
|
85
|
+
* 'name': '',
|
|
86
|
+
* 'categoryId': '',
|
|
87
|
+
* 'content': ''
|
|
88
|
+
* );
|
|
89
|
+
* </code>
|
|
90
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
91
|
+
*
|
|
92
|
+
* @since 1.0
|
|
93
|
+
*
|
|
94
|
+
* @package CoreFw
|
|
95
|
+
* @return Array
|
|
96
|
+
*/
|
|
97
|
+
async getWiki(wikiName)
|
|
98
|
+
{
|
|
99
|
+
const me = this;
|
|
100
|
+
|
|
101
|
+
me.wikiName = Wiki.prepareWikiName(wikiName);
|
|
102
|
+
let results = await me.db.query(`SELECT
|
|
103
|
+
wc.*, wct.categoryName
|
|
104
|
+
FROM wiki_content wc
|
|
105
|
+
JOIN wiki_category wct ON wct.categoryId=wc.categoryId
|
|
106
|
+
WHERE wc.name=? AND wc.langId=?`, [me.wikiName, me.session.langId]);
|
|
107
|
+
let row = results[0];
|
|
108
|
+
|
|
109
|
+
if (row !== undefined && me.lang.lang !== me.session.langId && me.fallback === true)
|
|
110
|
+
{
|
|
111
|
+
results = await me.db.query(`SELECT
|
|
112
|
+
wc.*, wct.categoryName
|
|
113
|
+
FROM wiki_content wc
|
|
114
|
+
JOIN wiki_category wct ON wct.categoryId=wc.categoryId
|
|
115
|
+
WHERE wc.name=? AND wc.langId=?`, [me.wikiName, me.session.langId]);
|
|
116
|
+
[row] = results;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (row === undefined)
|
|
120
|
+
{
|
|
121
|
+
me.content = {
|
|
122
|
+
header: '', name: '', date: '', content: me.translate('NOWIKIFOUND'),
|
|
123
|
+
};
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let modularData = {};
|
|
128
|
+
let content;
|
|
129
|
+
|
|
130
|
+
if (row.templateId != null)
|
|
131
|
+
{
|
|
132
|
+
content = await me.returnContentByTemplate(row.templateId, row);
|
|
133
|
+
modularData = JSON.parse(row.modularData);
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
if (row.parsedContent !== '' && row.parsedContent != null && me.session.groupId !== 1)
|
|
137
|
+
{
|
|
138
|
+
content = row.parsedContent;
|
|
139
|
+
}
|
|
140
|
+
else
|
|
141
|
+
{
|
|
142
|
+
content = row.content;
|
|
143
|
+
me.cacheContent(content);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
me.content = {
|
|
147
|
+
id: row.wikiId,
|
|
148
|
+
header: row.header,
|
|
149
|
+
date: row.dateTime,
|
|
150
|
+
name: row.name,
|
|
151
|
+
featured: row.featured,
|
|
152
|
+
categoryId: row.categoryId,
|
|
153
|
+
categoryName: row.categoryName,
|
|
154
|
+
templateId: row.templateId,
|
|
155
|
+
content,
|
|
156
|
+
rowdata: row,
|
|
157
|
+
modularData,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async returnContentByTemplate(templateId, wikiData)
|
|
162
|
+
{
|
|
163
|
+
const me = this;
|
|
164
|
+
|
|
165
|
+
const results = await me.db.query('SELECT * FROM wiki_templates WHERE templateId=?', [templateId]);
|
|
166
|
+
const row = results[0];
|
|
167
|
+
|
|
168
|
+
if (row === undefined)
|
|
169
|
+
{
|
|
170
|
+
throw new CoreError({ error: true, notice: 'Wiki template not found' });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const modularData = JSON.parse(wikiData.modularData);
|
|
174
|
+
|
|
175
|
+
let html = row.content;
|
|
176
|
+
|
|
177
|
+
const vars = [];
|
|
178
|
+
const dats = html.split('{#');
|
|
179
|
+
if (dats[0] !== undefined)
|
|
180
|
+
{
|
|
181
|
+
dats.shift();
|
|
182
|
+
}
|
|
183
|
+
for (const value of dats)
|
|
184
|
+
{
|
|
185
|
+
const dat = value.split('}');
|
|
186
|
+
vars.push(dat[0]);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for (const value of vars)
|
|
190
|
+
{
|
|
191
|
+
const re = new RegExp(`{#${value}}`, 'g');
|
|
192
|
+
html = html.replace(re, me.translate(value));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
let re = new RegExp('{mod:header}', 'g');
|
|
196
|
+
html = html.replace(re, wikiData.header);
|
|
197
|
+
|
|
198
|
+
re = new RegExp('{mod:date}', 'g');
|
|
199
|
+
html = html.replace(re, wikiData.dateTime);
|
|
200
|
+
|
|
201
|
+
re = new RegExp('{mod:name}', 'g');
|
|
202
|
+
html = html.replace(re, wikiData.name);
|
|
203
|
+
|
|
204
|
+
re = new RegExp('{mod:category}', 'g');
|
|
205
|
+
html = html.replace(re, wikiData.categoryName);
|
|
206
|
+
|
|
207
|
+
const datOne = html.split('{mod');
|
|
208
|
+
datOne.shift();
|
|
209
|
+
|
|
210
|
+
for (const value of datOne)
|
|
211
|
+
{
|
|
212
|
+
const datSec = value.split('}');
|
|
213
|
+
const datTrd = datSec[0].split(':');
|
|
214
|
+
|
|
215
|
+
re = new RegExp(`{mod${datSec[0]}}`, 'g');
|
|
216
|
+
if (datTrd[1] === 'linkfield' && modularData[`${datTrd[2]}_link`] !== undefined)
|
|
217
|
+
{
|
|
218
|
+
html = html
|
|
219
|
+
.replace(
|
|
220
|
+
re,
|
|
221
|
+
`<a href="${modularData[`${datTrd[2]}_link`]}"`
|
|
222
|
+
+ `alt="${modularData[`${datTrd[2]}_alt`]}" ${(modularData[`${datTrd[2]}_check`] !== undefined)
|
|
223
|
+
? 'checked="checked"'
|
|
224
|
+
: ''}${'>'.modularData[`${datTrd[2]}_text`]}</a>`,
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
else
|
|
228
|
+
{
|
|
229
|
+
const rep = (modularData[datTrd[2]] !== undefined) ? modularData[datTrd[2]] : '';
|
|
230
|
+
html = html.replace(re, rep);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return html;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async getModules(templateId, initialId = false)
|
|
237
|
+
{
|
|
238
|
+
const me = this;
|
|
239
|
+
|
|
240
|
+
const modules = [];
|
|
241
|
+
let initialValues = {};
|
|
242
|
+
|
|
243
|
+
if (initialId !== false)
|
|
244
|
+
{
|
|
245
|
+
const results = await me.db.query('SELECT * FROM wiki_content WHERE wikiId=?', [initialId]);
|
|
246
|
+
const row = results[0];
|
|
247
|
+
|
|
248
|
+
initialValues = JSON.parse(row.modularData);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (templateId !== '')
|
|
252
|
+
{
|
|
253
|
+
const categories = [];
|
|
254
|
+
const results = await me.db.query('SELECT * FROM images_category ORDER BY categoryId DESC');
|
|
255
|
+
for (const row of results)
|
|
256
|
+
{
|
|
257
|
+
categories.push(row);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
const wt = new WikiTemplates(me.session);
|
|
262
|
+
wt.id = templateId;
|
|
263
|
+
await wt.select();
|
|
264
|
+
const datOne = wt.content.split('{mod');
|
|
265
|
+
|
|
266
|
+
datOne.shift();
|
|
267
|
+
|
|
268
|
+
const alreadySetModules = [];
|
|
269
|
+
let n = 1;
|
|
270
|
+
for (const value of datOne)
|
|
271
|
+
{
|
|
272
|
+
const datSec = value.split('}');
|
|
273
|
+
const datTrd = datSec[0].split(':');
|
|
274
|
+
|
|
275
|
+
if (alreadySetModules.indexOf(datTrd[2]) !== -1)
|
|
276
|
+
{
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
alreadySetModules.push(datTrd[2]);
|
|
281
|
+
|
|
282
|
+
switch (datTrd[1])
|
|
283
|
+
{
|
|
284
|
+
case 'textfield':
|
|
285
|
+
modules.push({
|
|
286
|
+
type: 'textfield',
|
|
287
|
+
name: datTrd[2],
|
|
288
|
+
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
289
|
+
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
290
|
+
});
|
|
291
|
+
break;
|
|
292
|
+
case 'linkfield':
|
|
293
|
+
modules.push({
|
|
294
|
+
type: 'linkfield',
|
|
295
|
+
name: datTrd[2],
|
|
296
|
+
namelink: datTrd[2],
|
|
297
|
+
namecheck: datTrd[2],
|
|
298
|
+
namealt: datTrd[2],
|
|
299
|
+
nametext: datTrd[2],
|
|
300
|
+
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
301
|
+
valuetext: (initialValues[`${datTrd[2]}_text`] !== undefined)
|
|
302
|
+
? initialValues[`${datTrd[2]}_text`]
|
|
303
|
+
: '',
|
|
304
|
+
valuelink: (initialValues[`${datTrd[2]}_link`] !== undefined)
|
|
305
|
+
? initialValues[`${datTrd[2]}_link`]
|
|
306
|
+
: '',
|
|
307
|
+
valuealt: (initialValues[`${datTrd[2]}_alt`] !== undefined)
|
|
308
|
+
? initialValues[`${datTrd[2]}_alt`]
|
|
309
|
+
: '',
|
|
310
|
+
checked: (initialValues[`${datTrd[2]}_check`] !== undefined) ? 'checked' : '',
|
|
311
|
+
});
|
|
312
|
+
break;
|
|
313
|
+
case 'imagescat':
|
|
314
|
+
modules.push({
|
|
315
|
+
type: 'imagescat',
|
|
316
|
+
name: datTrd[2],
|
|
317
|
+
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
318
|
+
repeatoptions: (categories !== undefined) ? categories : false,
|
|
319
|
+
});
|
|
320
|
+
break;
|
|
321
|
+
case 'textarea':
|
|
322
|
+
modules.push({
|
|
323
|
+
type: 'textarea',
|
|
324
|
+
name: datTrd[2],
|
|
325
|
+
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
326
|
+
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
327
|
+
});
|
|
328
|
+
break;
|
|
329
|
+
case 'location':
|
|
330
|
+
modules.push({
|
|
331
|
+
type: 'location',
|
|
332
|
+
name: datTrd[2],
|
|
333
|
+
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
334
|
+
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
335
|
+
});
|
|
336
|
+
break;
|
|
337
|
+
case 'wysiwyg':
|
|
338
|
+
modules.push({
|
|
339
|
+
type: 'wysiwyg',
|
|
340
|
+
num: n,
|
|
341
|
+
name: datTrd[2],
|
|
342
|
+
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
343
|
+
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
344
|
+
});
|
|
345
|
+
break;
|
|
346
|
+
case 'fileupload':
|
|
347
|
+
modules.push({
|
|
348
|
+
type: 'fileupload',
|
|
349
|
+
num: n,
|
|
350
|
+
name: datTrd[2],
|
|
351
|
+
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
352
|
+
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
353
|
+
displayhref: 'display: none;',
|
|
354
|
+
displayimg: 'display: none;',
|
|
355
|
+
imagetype: datTrd[3],
|
|
356
|
+
});
|
|
357
|
+
break;
|
|
358
|
+
case 'imgupload':
|
|
359
|
+
modules.push({
|
|
360
|
+
type: 'imgupload',
|
|
361
|
+
num: n,
|
|
362
|
+
name: datTrd[2],
|
|
363
|
+
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
364
|
+
value: (initialValues[datTrd[2]] !== undefined)
|
|
365
|
+
? initialValues[datTrd[2]]
|
|
366
|
+
: '/css/images/ui-bg_diagonals-thick_20_666666_40x40.png',
|
|
367
|
+
});
|
|
368
|
+
break;
|
|
369
|
+
default:
|
|
370
|
+
modules.push({
|
|
371
|
+
type: 'textfield',
|
|
372
|
+
name: datTrd[2],
|
|
373
|
+
title: me.translate(GeneralHandling.safeTrans(`INPUT_${datTrd[2]}`)),
|
|
374
|
+
value: (initialValues[datTrd[2]] !== undefined) ? initialValues[datTrd[2]] : '',
|
|
375
|
+
});
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
n += 1;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return modules;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Cache wiki content to database
|
|
387
|
+
*
|
|
388
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
389
|
+
*
|
|
390
|
+
* @since 1.0
|
|
391
|
+
*
|
|
392
|
+
* @package CoreFw
|
|
393
|
+
* @param String content
|
|
394
|
+
* @return Array Array of 'error' boolean 'notice' message
|
|
395
|
+
*/
|
|
396
|
+
async cacheContent(content)
|
|
397
|
+
{
|
|
398
|
+
const me = this;
|
|
399
|
+
|
|
400
|
+
if (me.lib.config.cacheWiki !== undefined && me.lib.config.cacheWiki === false)
|
|
401
|
+
{
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
await me.db.query(
|
|
405
|
+
'UPDATE wiki_content SET parsedContent=? WHERE name=? AND langId=?',
|
|
406
|
+
[content, me.wikiName, me.lang.lang],
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
};
|