forked from Nuked-Klan/CMS_Nuked-Klan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnuked.php
1991 lines (1670 loc) · 58.8 KB
/
nuked.php
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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* nuked.php
*
*
*
* @version 1.8
* @link http://www.nuked-klan.org Clan Management System for Gamers
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @copyright 2001-2016 Nuked-Klan (Registred Trademark)
*/
defined('INDEX_CHECK') or die('You can\'t run this file alone.');
nkHandle_siteInstalled();
if (! function_exists('array_column'))
require_once 'Includes/array_column.php';
require_once 'Includes/nkSessions.php';
require_once 'Includes/nkTemplate.php';
// Set default flags used by nkHtmlEntityDecode, nkHtmlSpecialChars & nkHtmlEntities
define('NK_HTML_DEFAULT_FLAGS', (ENT_COMPAT | ENT_HTML401));
// Initialize main language array
$arrayModLang = array();
$defaultHttpHeader = true;
// CONNECT TO DB.
connect();
// QUERY NUKED CONFIG_TABLE.
$nuked = nkLoadConfiguration($db_prefix);
// INCLUDE CONSTANT TABLE
require_once 'Includes/constants.php';
// $GLOBALS['file'] & $GLOBALS['op'] VALUE.
$GLOBALS['file'] = nkHandle_module();
$GLOBALS['op'] = nkHandle_op();
// Pagination
$GLOBALS['p'] = nkHandle_pageNumber();
// $theme & $language VALUE.
$theme = nkHandle_theme();
$language = nkHandle_language();
// FORMAT DATE FR/EN
// if (!isset($nuked_nude))
nkSetLocale();
// DATE FUNCTION WITH FORMAT AND ZONE FOR DATE
$dateZone = getTimeZoneDateTime($nuked['datezone']);
date_default_timezone_set($dateZone);
// CONFIG PHP SESSION
if (ini_get('session.save_handler') == 'files')
session_set_save_handler('session_open', 'session_close', 'session_read', 'session_write', 'session_delete', 'session_gc');
if (ini_get('suhosin.session.encrypt') == '1') {
@ini_set('session.gc_probability', 100);
@ini_set('session.gc_divisor', 100);
@ini_set('session.gc_maxlifetime', (1440));
}
nkSessions_init();
/**
* Checks if site is closed or not installed
*
* @param void
* @return void
*/
function nkHandle_siteInstalled() {
if (! defined('NK_INSTALLED') && file_exists('INSTALL/index.php')) {
header('location: INSTALL/index.php');
exit;
}
if (! defined('NK_OPEN')) {
echo WEBSITE_CLOSED;
exit;
}
}
/**
* Choose which module will be include
*
* @param void
* @return string : Module name to include
*/
function nkHandle_module() {
global $nuked, $admin;
$module = null;
$admin = false;
if (isset($_POST['admin'])) {
$module = $_POST['admin'];
$admin = true;
}
else if (isset($_POST['file'])) {
$module = $_POST['file'];
}
else if (isset($_GET['admin'])) {
$module = $_GET['admin'];
$admin = true;
}
else if (isset($_GET['file'])) {
$module = $_GET['file'];
}
if ($module !== null) {
// On the recommendations of phpSecure.info
if (strpos($module, '..') !== false || stripos($module, 'http://') !== false)
die(WAYTODO);
$module = basename(trim($module));
}
if ($module === null || empty($module))
$module = $nuked['index_site'];
return $module;
}
/**
* Choose which module file will be include
*
* @param void
* @return string : Module file name to include
*/
function nkHandle_page() {
$nukedNude = $page = null;
if (isset($_POST['nuked_nude']))
$nukedNude = $_POST['nuked_nude'];
else if (isset($_GET['nuked_nude']))
$nukedNude = $_GET['nuked_nude'];
if ($nukedNude !== null) {
trigger_error('Superglobal $nuked_nude is deprecated. Please update your module.', E_USER_DEPRECATED);
nkTemplate_setPageDesign('none');
$nukedNude = basename(trim($nukedNude));
$GLOBALS['nuked_nude'] = & $GLOBALS['page'];
if (! empty($nukedNude))
return $nukedNude;
else
return 'index';
}
if (isset($_POST['page']))
$page = $_POST['page'];
else if (isset($_GET['page']))
$page = $_GET['page'];
if ($page !== null)
$page = basename(trim($page));
if (! empty($page))
return $page;
return 'index';
}
/**
* Choose which action will be execute by module file.
*
* @param void
* @return string : Action name to execute by module file.
*/
function nkHandle_op() {
$op = '';
if (isset($_POST['op']))
$op = $_POST['op'];
else if (isset($_GET['op']))
$op = $_GET['op'];
if ($op != '')
return $op;
return 'index';
}
/**
* Get current page number for pagination.
*
* @param void
* @return int : The current page number.
*/
function nkHandle_pageNumber() {
$p = 1;
if (isset($_POST['p']))
$p = max(1, (int) $_POST['p']);
else if (isset($_GET['p']))
$p = max(1, (int) $_GET['p']);
return $p;
}
/**
* Choose which theme will be include
*
* @param void
* @return string : Theme name to include
*/
function nkHandle_theme() {
global $nuked, $cookie_theme;
if (array_key_exists($cookie_theme, $_COOKIE)
&& is_file(dirname(__FILE__) .'/themes/'. $_COOKIE[$cookie_theme] .'/theme.php')
) {
$theme = trim($_COOKIE[$cookie_theme]);
// On the recommendations of phpSecure.info
if (strpos($theme, '..') !== false)
die(WAYTODO);
}
else if (is_file(dirname(__FILE__) .'/themes/'. $nuked['theme'] .'/theme.php')) {
$theme = $nuked['theme'];
}
else {
exit(THEME_NO_FOUND);
}
return $theme;
}
/**
* Choose which nkHandle_language will be include
*
* @param void
* @return string : Language name to include
*/
function nkHandle_language() {
global $nuked, $cookie_langue;
if (array_key_exists($cookie_langue, $_COOKIE)
&& is_file(dirname(__FILE__) .'/lang/'. $_COOKIE[$cookie_langue] .'.lang.php')
) {
$language = trim($_COOKIE[$cookie_langue]);
// On the recommendations of phpSecure.info
if (strpos($language, '..') !== false)
die(WAYTODO);
}
else if (is_file(dirname(__FILE__) .'/lang/'. $nuked['langue'] .'.lang.php')) {
$language = $nuked['langue'];
}
else {
exit(LANGUAGE_NO_FOUND);
}
return $language;
}
/**
* Check and return nkAlert for Website closed, INSTALL directory,
* install.php and update.php file and new private message
*
* @param void
* @return string : HTML code.
*/
function nkHandle_alert() {
global $file, $page, $nuked, $user, $visiteur;
$html = '';
if ($visiteur == 9 && $file != 'Admin' && $page != 'admin') {
if ($nuked['nk_status'] == 'closed')
$html .= applyTemplate('nkAlert/nkSiteClosedLogged');
if (is_dir('INSTALL/'))
$html .= applyTemplate('nkAlert/nkInstallDirTrue');
if (file_exists('install.php') || file_exists('update.php'))
$html .= applyTemplate('nkAlert/nkInstallFileTrue');
}
if ($user && $user['nbNewPM'] > 0 && ! isset($_COOKIE['popup'])
&& ! in_array($file, array('User', 'Userbox', 'Admin'))
&& $page != 'admin'
)
$html .= applyTemplate('nkAlert/nkNewPrivateMsg');
return $html;
}
/**
* Set PHP locale
*
* @param void
* @return void
*/
function nkSetLocale() {
global $language;
if ($language == 'french') {
// On verifie l'os du serveur pour savoir si on est en windows (setlocale : ISO) ou en unix (setlocale : UTF8)
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
setlocale (LC_ALL, 'fr_FR','fra');
else
setlocale(LC_ALL, 'fr_FR.UTF8','fra');
}
else if ($language == 'english')
setlocale(LC_ALL, 'en_US');
/*
PHP_OS :
- Linux
- ?
if ($language == 'french' && strpos('WIN', PHP_OS))
setlocale (LC_TIME, 'french');
else if ($language == 'french' && strpos('BSD', PHP_OS))
setlocale (LC_TIME, 'fr_FR.ISO8859-1');
else if ($language == 'french')
setlocale (LC_TIME, 'fr_FR');
else
setlocale (LC_TIME, $language);
*/
}
function getRequestVars() {
$vars = array();
$request = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : $_GET;
foreach (func_get_args() as $varName)
$vars[] = (array_key_exists($varName, $request)) ? trim($request[$varName]) : '';
return $vars;
}
// FUNCTIONS TO FIX COMPATIBILITY WITH PHP5.4
function nkHtmlEntityDecode($string, $flags = NK_HTML_DEFAULT_FLAGS) {
return html_entity_decode($string, $flags, 'ISO-8859-1');
}
function nkHtmlSpecialChars($string, $flags = NK_HTML_DEFAULT_FLAGS) {
return htmlspecialchars($string, $flags, 'ISO-8859-1');
}
function nkHtmlEntities($string, $flags = NK_HTML_DEFAULT_FLAGS) {
return htmlentities($string, $flags, 'ISO-8859-1');
}
// FUNCTION TO FIX PRINTING TAGS
function printSecuTags($value) {
return nkHtmlEntities(nkHtmlEntityDecode(nkHtmlEntityDecode($value)));
}
function nkDate($timestamp, $block = false) {
global $nuked, $language;
if(array_key_exists('IsBlok', $nuked)){
$isBlock = $nuked['IsBlok'];
}
else{
$isBlock = false;
}
$format = ((($block === false) ? $isBlock : $block) === true) ? ($language == 'french') ? '%d/%m/%Y' : '%m/%d/%Y' : $nuked['dateformat'];
// iconv pour eviter les caracteres speciaux dans la date
return iconv('UTF-8','ISO-8859-1',strftime($format, $timestamp));
//return iconv('UTF-8','ISO-8859-1',utf8_encode(strftime($format, $timestamp))); // For Windows servers
}
// CURRENT ANNUAL DATEZONE TIME TABLE
function getTimeZoneDateTime($GMT) {
$timezones = array(
'-1200'=>'Pacific/Kwajalein',
'-1100'=>'Pacific/Samoa',
'-1000'=>'Pacific/Honolulu',
'-0900'=>'America/Juneau',
'-0800'=>'America/Los_Angeles',
'-0700'=>'America/Denver',
'-0600'=>'America/Mexico_City',
'-0500'=>'America/New_York',
'-0400'=>'America/Caracas',
'-0330'=>'America/St_Johns',
'-0300'=>'America/Argentina/Buenos_Aires',
'-0200'=>'Atlantic/Azores',
'-0100'=>'Atlantic/Azores',
'+0000'=>'Europe/London',
'+0100'=>'Europe/Paris',
'+0200'=>'Europe/Helsinki',
'+0300'=>'Europe/Moscow',
'+0330'=>'Asia/Tehran',
'+0400'=>'Asia/Baku',
'+0430'=>'Asia/Kabul',
'+0500'=>'Asia/Karachi',
'+0530'=>'Asia/Calcutta',
'+0600'=>'Asia/Colombo',
'+0700'=>'Asia/Bangkok',
'+0800'=>'Asia/Singapore',
'+0900'=>'Asia/Tokyo',
'+0930'=>'Australia/Darwin',
'+1000'=>'Pacific/Guam',
'+1100'=>'Asia/Magadan',
'+1200'=>'Asia/Kamchatka'
);
if (isset($timezones[$GMT]))
return $timezones[$GMT];
return false;
}
// OPEN PHP SESSION
function session_open($path, $name) {
return true;
}
// CLOSE PHP SESSION
function session_close() {
return true;
}
// READ PHP SESSION
function session_read($id) {
connect();
$dbsSession = nkDB_selectOne(
'SELECT session_vars
FROM '. TMPSES_TABLE .'
WHERE session_id = '. nkDB_quote($id)
);
if ($dbsSession && array_key_exists('session_vars', $dbsSession))
return $dbsSession['session_vars'];
return '';
}
// WRITE PHP SESSION
function session_write($id, $data) {
connect();
return nkDB_replace(TMPSES_TABLE, array(
'session_id' => $id,
'session_start' => time(),
'session_vars' => $data
));
}
// DELETE PHP SESSION
function session_delete($id) {
connect();
return nkDB_delete(TMPSES_TABLE, 'session_id = '. nkDB_quote($id));
}
// KILL DEAD SESSION
function session_gc($maxlife) {
connect();
nkDB_delete(TMPSES_TABLE, 'session_start < '. time() - $maxlife);
return true;
}
/**
* Open a connection to a database server
*
* @param void
* @return void
*/
function connect() {
global $global;
static $layerLoaded = false;
if (! $layerLoaded) {
if (! is_file($dbLayer = dirname(__FILE__) .'/Includes/nkDb/nkDB_'. $global['db_type'] .'.php'))
exit(ERROR_DB_LAYER);
require_once $dbLayer;
$layerLoaded = true;
}
nkDB_init($global);
if (($db = nkDB_connect()) === false) {
$error = nkDB_getConnectError();
// TODO : More error message ? ( DB_HOST_ERROR, DB_LOGIN_ERROR & DB_CHARSET_ERROR )
if ($error == 'DB_NAME_ERROR')
exit(ERROR_QUERYDB);
else
exit(ERROR_QUERY);
}
}
/**
* Redirect if current user / visitor is banned
*/
function nkHandle_bannedUser() {
global $user_ip, $user;
$userName = ($user) ? $user['name'] : '';
// TODO : On supprime juste le dernier chiffre ou la derniere partie de l'adresse ip ?
// On supprime le dernier chiffre pour les IP's dynamiques
$ip_dyn = substr($user_ip, 0, -1);
// Condition SQL : IP dynamique ou compte
$where_query = '`ip` LIKE \'%'. nkDB_quote($ip_dyn, true) .'%\' OR `pseudo` = '. nkDB_quote($userName);
// Recherche d'un banissement
$ban = nkDB_selectMany(
'SELECT `id`, `pseudo`, `date`, `dure`
FROM '. BANNED_TABLE .'
WHERE '. $where_query
);
$bannedIp = '';
// Si resultat positif a la recherche d'un bannissement
if (nkDB_numRows() > 0) {
// Nouvelle adresse IP
$bannedIp = $user_ip;
}
// Recherche d'un cookie de banissement
else if (isset($_COOKIE['ip_ban']) && $_COOKIE['ip_ban'] != '') {
// TODO : On supprime juste le dernier chiffre ou la derniere partie de l'adresse ip ?
// On supprime le dernier chiffre de l'adresse IP contenu dans le cookie
$ip_dyn2 = substr($_COOKIE['ip_ban'], 0, -1);
// On verifie l'adresse IP du cookie et l'adresse IP actuelle
if($ip_dyn2 == $ip_dyn) {
// On verifie l'existance du bannissement, si resultat positif, on fait un nouveau ban
if (nkDB_totalNumRows('FROM '. BANNED_TABLE .' WHERE `ip` LIKE \'%'. nkDB_quote($ip_dyn2, true) .'%\'') > 0)
$bannedIp = $user_ip;
}
}
// Suppression des banissements depasses ou mise a jour de l'IP
if ($bannedIp != '') {
// Recherche banissement depasse
if ($ban['dure'] != 0 && ($ban['date'] + $ban['dure']) < time()) {
// Suppression bannissement
nkDB_delete(BANNED_TABLE, '`ip` LIKE \'%'. nkDB_quote($ip_dyn, true) .'%\' OR `pseudo` = '. nkDB_quote($userName));
// Notification dans l'administration
saveNotification($userName . __('BAN_FINISHED'), NOTIFICATION_WARNING);
}
// Sinon on met a jour l'IP
else {
$data = array('ip' => $user_ip);
// Redirection vers la page de banissement
$url = 'ban.php?ip_ban='. $bannedIp;
if ($user) {
$data['pseudo'] = $user['name'];
$url .= '&user='. urlencode($user['name']);
}
nkDB_update(BANNED_TABLE, $data, $where_query);
redirect($url);
}
}
}
// QUERY IMAGE, BLOCK ALL IMAGE FILE (PHP, HTML ..)
function checkimg($url){
$url = rtrim($url);
$ext = strrchr($url, '.');
$ext = substr($ext, 1);
if (!preg_match('#\.(([a-z]?)htm|php)#i', $url) && substr($url, -1) != '/' && preg_match('#jpg|jpeg|gif|png|bmp#i', $ext) )
return $url;
else
return 'images/noimagefile.gif';
}
function getSmiliesList() {
static $smiliesList;
if ($smiliesList) return $smiliesList;
$smiliesList = nkDB_selectMany(
'SELECT code, url, name
FROM '. SMILIES_TABLE,
array('id')
);
return $smiliesList;
}
/**
* Replace smilies in text
* @param array $matches : text to parse
* @return string : parsing text
*/
function replaceSmilies($matches) {
return preg_replace('#<img class="nkSmilie" src=\"(.*)\" alt=\"(.*)\" title=\"(.*)\" />#Usi', '$2', $matches[0]);
}
/**
* Display smilies in text
* @param string $texte : text to parse, without smilies
* @return string : text containing smiley images
*/
function icon($text) {
$text = str_replace('mailto:', 'mailto!', $text);
$text = str_replace('http://', '_http_', $text);
$text = str_replace('https://', '_https_', $text);
$text = str_replace('"', '_QUOT_', $text);
$text = str_replace(''', '_SQUOT_', $text);
foreach (getSmiliesList() as $smilie) {
$pattern = '#(?si)<pre[^<]*>.*?<\/pre>(*SKIP)(*F)|' . preg_quote($smilie['code'], '#') . '#';
$replacement = '<img class="nkSmilie" src="images/icones/' . $smilie['url'] . '" alt="' . nkHtmlEntities($smilie['name']) . '" />';
$text = preg_replace($pattern, $replacement, $text);
}
$text = str_replace('mailto!', 'mailto:', $text);
$text = str_replace('_http_', 'http://', $text);
$text = str_replace('_https_', 'https://', $text);
$text = str_replace('_QUOT_', '"', $text);
$text = str_replace('_SQUOT_', ''', $text);
return $text;
}
// SEARCH SMILIES FOR CKEDITOR.
function ConfigSmileyCkeditor() {
$smiliesList = getSmiliesList();
$smiliesCodeList = addslashes(implode('\', \'', array_values(array_column($smiliesList, 'code'))));
$smiliesUrlList = implode('\', \'', array_values(array_column($smiliesList, 'url')));
$smiliesNameList = nkHtmlEntities(implode('\', \'', array_values(array_column($smiliesList, 'name'))));
return 'CKEDITOR.config.smiley_path=\'images/icones/\';'
. 'CKEDITOR.config.smiley_images=[\''. $smiliesUrlList .'\'];'
. 'CKEDITOR.config.smiley_descriptions=[\''. $smiliesCodeList .'\'];'
. 'CKEDITOR.config.smiley_titles=[\''. $smiliesNameList .'\'];';
}
// SECURITY FOR HTTP LINKS.
function secu_url($url){
$info = parse_url(strtolower($url));
if ($info !== false){
return strrchr($info['path'], '.') != '.php'
&& (!isset($info['query']) || $info['query'] == '');
} else{
return false;
}
}
// CSS FILTER
function secu_css($Style){
$AllowedProprieties = array(
'display',
'margin-left',
'margin-right',
'float',
'padding',
'text-decoration',
'text-align',
'color',
'align',
'vertical-align',
'margin',
'border',
'background-color',
'background',
'width',
'height',
'border-color',
'background-image',
'border-width',
'border-style',
'padding-left',
'padding-right',
'font-size',
'font-family',
'page-break-after'
);
$Style = explode(';', $Style);
$Style = array_map('trim', $Style);
foreach ($Style as $id=>$Element){
preg_match('/ *([^ :]+) *: *(( |.)*)/', $Element, $Phased);
if (!in_array($Phased[1], $AllowedProprieties)){
unset($Style[$id]);
} elseif (preg_match('/url *\\( *\'?"? *([^ \'"]+) *"?\'?\\)/', $Element, $Phased) > 0){
if (!secu_url($Phased[1])){
unset($Style[$id]);
}
}
}
return implode(';', $Style);
}
// HTML FILTER
function secu_args($matches){
global $nuked;
$allowedTags = array(
'p' => array(
'style',
'dir'
),
'h1' => array(
'style'
),
'h2' => array(
'style'
),
'h3' => array(
'style'
),
'h4' => array(
'style'
),
'h5' => array(
'style'
),
'h6' => array(
'style'
),
'img' => array(
'alt',
'class',
'dir',
'id',
'lang',
'longdesc',
'src',
'style',
'title',
'width',
'height',
'border'
),
'strong' => array(),
's' => array(),
'em' => array(),
'u' => array(),
'strike' => array(),
'sub' => array(),
'sup' => array(),
'ol' => array(),
'ul' => array(),
'li' => array(),
'blockquote' => array(
'style'
),
'div' => array(
'class',
'id',
'lang',
'style',
'title',
'align'
),
'br' => array(),
'a' => array(
'accesskey',
'charset',
'class',
'dir',
'href',
'id',
'lang',
'name',
'rel',
'style',
'tabindex',
'target',
'title',
'type'
),
'table' => array(
'align',
'border',
'cellpadding',
'cellspacing',
'class',
'dir',
'id',
'style',
'summary'
),
'caption' => array(),
'thead' => array(),
'tr' => array(
'style'
),
'td' => array(
'style',
'colspan',
'rowspan'
),
'th' => array(
'scope'
),
'tbody' => array(),
'hr' => array(),
'span' => array(
'id',
'style',
'dir'
),
'big' => array(),
'small' => array(),
'tt' => array(),
'code' => array(),
'kbd' => array(),
'samp' => array(),
'var' => array(),
'del' => array(),
'ins' => array(),
'cite' => array(),
'q' => array(),
'pre' => array(
'class'
),
'address' => array()
);
// FOR VIDEO PLUGIN -- POUR PLUGIN VIDEO
$TabVideo = array(
'object' => array(
'width',
'height',
'data',
'type'
),
'param' => array(
'name',
'value'
),
'embed' => array(
'allowfullscreen',
'allowscriptaccess',
'height',
'src',
'type',
'width'
),
/*'iframe' => array (
'src',
'width',
'height',
'frameborder',
),*/
);
$allowedTags = ($nuked['video_editeur'] == 'on') ? array_merge($allowedTags, $TabVideo) : $allowedTags;
if (in_array(strtolower($matches[1]), array_keys($allowedTags))) {
preg_match_all('/([^ =]+)=("((.(?<!"))*)|[^ ]+)/', $matches[2], $args);
//Supprime les attributs interdit
foreach ($args[1] as $id=>$attribute){
if (!in_array($attribute, $allowedTags[$matches[1]]))
foreach ($args as $part=>$g)
unset($args[$part][$id]);
}
//Met en forme les attributs restants
foreach ($args[2] as $id=>$val){
$args[1][$id] = trim(strtolower($args[1][$id]));
$val = trim($val);
if (preg_match('/^"/', $val, $g))
$val .= ';';
$args[2][$id] = trim(nkHtmlEntityDecode($val), " \t\n\r\0\"");
if ($args[1][$id] == 'style'){
$args[2][$id] = secu_css($args[2][$id]);
}
elseif ($matches[1] == 'img' && $args[1][$id] == 'src'){
if(!secu_url($args[2][$id]))
$args[2][$id] = 'images/noimagefile.gif';
}
}
$RetStr = '<' . $matches[1];
foreach ($args[1] as $id=>$attribute){
$RetStr .= ' ' . $attribute . '="' . $args[2][$id] . '"';
}
if (array_key_exists(3,$matches) && $matches[3] == '/'){
$RetStr .= ' />';
}
else{
$RetStr .= '>';
}
return $RetStr;
// Balise de fermeture
}
else if (substr($matches[1], 0, 1) == '/' && in_array(strtolower(substr($matches[1], 1)), array_keys($allowedTags))){
return '<' . $matches[1] . '>';
// Balises interdites
}
else{
return $matches[0];
}
}
// DISPLAY CONTENT WITH SECURITY CSS AND HTML ($texte)
function secu_html($texte, $returnError = false){
global $bgcolor3, $nuked, $language;
// Balise HTML interdite
$texte = str_replace(array('<', '>', '"'), array('<', '>', '"'), $texte);
$texte = stripslashes($texte);
$texte = nkHtmlSpecialChars($texte);
$texte = str_replace('&', '&', $texte);
$texte = str_replace('<3', nkHtmlEntities('<3'), $texte);
// Balise autorisee
$texte = preg_replace_callback('/<([^ &]+)[[:blank:]]?((.(?<!>))*)>/', 'secu_args', $texte);
$texte = str_replace('&lt;3', '<3', $texte);
$arrayOnly1Tag = array('img', 'br', 'hr');
if($nuked['video_editeur'] == 'on'){
$arrayOnly1Tag[] = 'param';
}
$allowedTags = array(
'p','h1','h2','h3','h4','h5','h6','img','strong','s','em',
'u','strike','sub','sup','ol','ul','li','blockquote','div',
'br','a','table','caption','thead','tr','td','th','tbody',
'hr','span','big','small','tt','code','kbd','samp','var',
'del','ins','cite','q','pre','address','object','param','embed'
);
if($nuked['video_editeur'] == 'on'){
$allowedTags[] = 'object';
$allowedTags[] = 'param';
$allowedTags[] = 'embed';
}
preg_match_all('`<(/?)([^/ >]+)(| [^>]*([^/]))>`', $texte, $Tags, PREG_SET_ORDER);
$TagList = array();
$bad = false;
$size = count($Tags);
for($i=0; $i<$size; $i++) {
$Tags[$i][4] = (isset($Tags[$i][4])) ? $Tags[$i][4] : '';
$TagName = ($Tags[$i][3] == '') ? $Tags[$i][2] . $Tags[$i][4] : $Tags[$i][2];
if(!in_array($TagName, $arrayOnly1Tag) && in_array($TagName, $allowedTags)){
if ($Tags[$i][1] == '/'){
$bad = $bad | array_pop($TagList) != $TagName;
}
else{
array_push($TagList, $TagName);
}
}
}
$bad = $bad | count($TagList) > 1;
if ($bad){
if ($returnError)
return false;
else
return(nkHtmlSpecialChars($texte));
}
else{
return $texte;
}
}
function editPhpCkeditor($text){
return str_replace('<?php', nkHtmlEntities('<?php'), $text);
}
// REDIRECT AFTER ($delay) SECONDS TO ($url)
function redirect($url, $delay = 0) {
if ($delay == 0) {
nkDB_disconnect();
header('location:'. $url);
exit;
}
echo '<script type="text/javascript">',"\n"
, '<!--',"\n"
, "\n"
, 'function redirect() {',"\n"
, 'window.location=\'' , $url , '\'',"\n"
, "}\n"
, 'setTimeout(\'redirect()\',\'' , ($delay * 1000) ,'\');',"\n"
, "\n"