-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.php
1688 lines (1451 loc) · 44.4 KB
/
global.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
/**
* MercuryBoard
* Copyright (c) 2001-2005 The Mercury Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* $Id: global.php,v 1.206 2006/07/08 20:22:44 jon Exp $
**/
/**
* The MercuryBoard Core
*
* @author Jason Warner <[email protected]>
* @since Beta 2.0
**/
class mercuryboard
{
var $version = 'v1.1.5'; // MercuryBoard's version @var string
var $server = array(); // Alias for $_SERVER @var array
var $get = array(); // Alias for $_GET @var array
var $post = array(); // Alias for $_POST @var array
var $cookie = array(); // Alias for $_COOKIE @var array
var $files = array(); // Alias for $_FILES @var array
var $user = array(); // Information about the user @var array
var $sets = array(); // Settings @var array
var $temps = array(); // Loaded templates @var array
var $censor = array(); // Curse words to filter @var array
var $emotes = array( // Text strings to be replaced with images @var array
'replacement' => array(),
'replacement_clickable' => array()
);
var $tree = null; // The navigational tree @var string
var $nohtml = false; // To display no board wrapper @var bool
var $replaces_loaded = false; // Replacements have been loaded @var bool
var $time; // The current Unix time @var int
var $ip; // The user's IP address @var string
var $agent; // The browser's user agent @var string
var $self; // Alias for $PHP_SELF @var string
var $db; // Database object @var object
var $perms; // Permissions object @var object
var $pre; // Database table prefix @var string
var $skin; // The user's selected skin @var string
var $table; // Start to an HTML table @var string
var $etable; // End to an HTML table @var string
var $lang; // Loaded words @var object
var $query; // The query string @var string
/**
* Constructor; sets up variables
*
* @author Jason Warner <[email protected]>
* @since Beta 2.0
* @return void
**/
function mercuryboard()
{
$this->time = time();
$this->query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null;
$this->ip = $_SERVER['REMOTE_ADDR'];
$this->agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$this->self = $_SERVER['PHP_SELF'];
$this->server = $_SERVER;
$this->get = $_GET;
$this->post = $_POST;
$this->cookie = $_COOKIE;
$this->files = $_FILES;
$this->session = &$_SESSION;
$this->query = htmlspecialchars($this->query);
}
/**
* Extends the existing templates array - see get_templates()
*
* @param string $section Template group
* @author Jason Warner <[email protected]>
* @since Beta 2.0
* @return void
**/
function add_templates($section)
{
$this->temps = array_merge($this->temps, $this->get_templates($section, 0));
}
/**
* Attempts to CHMOD a directory or file
*
* @param string $path Path to CHMOD
* @param int $mode New CHMOD value
* @param bool $recursive True for recursive
* @author Jason Warner <[email protected]>
* @since 1.1.5
* @return void
**/
function chmod($path, $mode, $recursive = false)
{
if (!$recursive || !is_dir($path)) {
@chmod($path, $mode);
return;
}
$dir = opendir($path);
while (($file = readdir($dir)) !== false)
{
if(($file == '.') || ($file == '..')) {
continue;
}
$fullpath = $path . '/' . $file;
if(!is_dir($fullpath)) {
@chmod($fullpath, $mode);
} else {
$this->chmod_r($fullpath, $mode);
}
}
closedir($dir);
@chmod($path, $mode);
}
/**
* Formats a string
*
* @param string $in Input
* @param int $options Options
* @author Jason Warner <[email protected]>
* @since Beta 3.0
* @return string Formatted string
**/
function format($in, $options = 0)
{
if (!$options) {
$options = FORMAT_BREAKS | FORMAT_HTMLCHARS | FORMAT_CENSOR;
}
if ($options & FORMAT_CENSOR) {
if (!$this->replaces_loaded) {
$this->get_replaces();
}
if ($this->censor) {
$in = preg_replace($this->censor, '####', $in);
}
}
if ($options & FORMAT_MBCODE) {
$search = array(
'~(^|\s)([a-z0-9-_.]+@[a-z0-9-.]+\.[a-z0-9-_.]+)~i',
'~(^|\s)(http|https|ftp)://(\w+[^\s\[\]]+)~ise'
);
$replace = array(
'\\1[email]\\2[/email]',
'\'\\1[url]\' . wordwrap(\'\\2://\\3\', 1, \' \', 1) . \'[/url]\''
);
$brackets = (strpos($in, '[') !== false) && (strpos($in, ']') !== false);
if ($brackets) {
$b_search = array(
'~\[code](.*?)\[/code]~ise',
'~\[php](.*?)\[/php]~ise',
'~\[php=([0-9]+?)](.*?)\[/php]~ise',
'~\[img](http|https|ftp)://(.*?)\[/img]~ise',
'~\[url](.*?)\[/url]~ise',
'~\[url=(http|https|ftp)://(.+?)](.+?)\[/url]~ise'
);
$b_replace = array(
'\'[code]\' . base64_encode(\'\\1\') . \'[/code]\'',
'\'[php]\' . base64_encode(\'\\1\') . \'[/php]\'',
'\'[php=\\1]\' . base64_encode(\'\\2\') . \'[/php]\'',
'\'[img]\' . wordwrap(\'\\1://\\2\', 1, \' \', 1) . \'[/img]\'',
'\'[url]\' . wordwrap(\'\\1\\2\', 1, \' \', 1) . \'[/url]\'',
'\'[url=\' . wordwrap(\'\\1://\\2\', 1, \' \', 1) . \']\\3[/url]\''
);
$search = array_merge($search, $b_search);
$replace = array_merge($replace, $b_replace);
}
$in = preg_replace($search, $replace, $in);
$brackets = (strpos($in, '[') !== false) && (strpos($in, ']') !== false); //We may have auto-parsed a URL, adding a bracket
}
$strtr = array();
if ($options & FORMAT_HTMLCHARS) {
$strtr['&'] = '&';
$strtr['"'] = '"';
$strtr['\''] = ''';
$strtr['<'] = '<';
$strtr['>'] = '>';
}
if ($options & FORMAT_BREAKS) {
$strtr["\n"] = "<br />\n";
}
if ($this->user['user_view_emoticons'] && ($options & FORMAT_EMOTICONS)) {
if (!$this->replaces_loaded) {
$this->get_replaces();
}
$strtr = array_merge($strtr, $this->emotes['replacement']);
}
$in = strtr($in, $strtr);
if (($options & FORMAT_MBCODE) && $brackets) {
$search = array(
'~\[(/)?([bi])]~i',
'~\[u]~i',
'~\[s]~i',
'~\[/[us]]~i',
'~\[url](h t t p|h t t p s|f t p) : / /(.+?)\[/url]~ise',
'~\[url=(h t t p|h t t p s|f t p) : / /(.+?)](.+?)\[/url]~ise',
'~\[email]([a-z0-9-_.]+@[a-z0-9-.]+\.[a-z0-9-_.]+)?\[/email]~i',
'~\[email=([^<]+?)](.*?)\[/email]~i',
'~\[img](h t t p|h t t p s|f t p) : / /(.*?)\[/img]~ise',
'~\[(right|center)](.*?)\[/\1]~is',
'~\[code](.*?)\[/code]~ise',
'~\[php](.*?)\[/php]~ise',
'~\[php=([0-9]+?)](.*?)\[/php]~ise',
'~\[color=([A-Za-z ]+?)](.*?)\[/color]~is',
'~\[font=([A-Za-z ]+?)](.*?)\[/font]~is',
'~\[size=([0-9]+?)](.*?)\[/size]~is'
);
$replace = array(
'<\\1\\2>',
'<span style=\'text-decoration:underline\'>',
'<span style=\'text-decoration:line-through\'>',
'</span>',
'\'<a href="\' . str_replace(\' \', \'\', \'\\1://\\2\') . \'" onclick="window.open(this.href,\\\'' . $this->sets['link_target'] . '\\\');return false;">\' . str_replace(\' \', \'\', \'\\1://\\2\') . \'</a>\'',
'\'<a href="\' . str_replace(\' \', \'\', \'\\1://\\2\') . \'" onclick="window.open(this.href,\\\'' . $this->sets['link_target'] . '\\\');return false;">\' . str_replace(\'\\"\', \'"\', \'\\3\') . \'</a>\'',
'<a href="mailto:\\1">\\1</a>',
'<a href="mailto:\\1">\\2</a>',
'\'<img src="\' . str_replace(\' \', \'\', \'\\1://\\2\') . \'" alt="\' . str_replace(\' \', \'\', \'\\1://\\2\') . \'" />\'',
'<div align="\\1">\\2</div>',
'$this->format_code(\'\\1\', 0)',
'$this->format_code(\'\\1\', 1)',
'$this->format_code(\'\\2\', 1, \'\\1\')',
'<span style=\'color:\\1\'>\\2</span>',
'<span style=\'font-family:\\1\'>\\2</span>',
'<span style=\'font-size:\\1ex\'>\\2</span>'
);
if ((substr_count($in, '[quote]') + substr_count($in, '[quote=')) == substr_count($in, '[/quote]')) {
$search[] = '~\[quote=(.+?)]~i';
$search[] = '~\[quote]~i';
$search[] = '~\[/quote]~i';
$replace[] = '<table style="width:90%; margin-left:5%; margin-right:5%;" border="0" cellpadding="3" cellspacing="0"><tr><td><b>\\1 ' . $this->lang->main_said . ':</b></td></tr><tr><td class="quote">';
$replace[] = '<table style="width:90%; margin-left:5%; margin-right:5%;" border="0" cellpadding="3" cellspacing="0"><tr><td><b>' . $this->lang->main_quote . ':</b></td></tr><tr><td class="quote">';
$replace[] = '</td></tr></table>';
}
$in = preg_replace($search, $replace, $in);
$in = str_replace(array(' ', "\t", '&#'), array(' ', ' ', '&#'), $in);
}
return $in;
}
/**
* Makes IE-generated HTML safe
*
* @param string $in Input
* @author Jason Warner <[email protected]>
* @since Beta 4.0
* @return string Corrected input
**/
function format_html_mbcode($in)
{
// Remove JavaScript, etc
}
/**
* Formats code with line numbers and optionally syntax highlighting
*
* @param string $input Code to be formatted
* @param bool $php True to format as PHP
* @param int $start Starting line to count from
* @author Jason Warner <[email protected]>
* @since Beta 2.1
* @return string PHP-highlighted string
**/
function format_code($input, $php, $start = 1)
{
$input = base64_decode($input);
if (substr($input, 0, 1) != "\r") {
$input = "\r\n" . $input;
}
if (substr($input, -1) != "\n") {
$input .= "\r\n";
}
if ($php) {
$title = 'PHP';
if (strpos($input, '<' . '?') === false) {
$input = '<' . "?php $input ?" . '>';
$tagged = true;
}
$input = str_replace(array('\"', '\\'), array('"', '\'), $input);
ob_start();
@highlight_string($input);
$input = ob_get_contents();
ob_end_clean();
} else {
$input = htmlspecialchars(str_replace(array('\'', '\"'), array(''', '"'), $input));
$input = nl2br($input);
$title = $this->lang->main_code;
}
if (isset($tagged)) {
$input = str_replace(array('<?php', '?>'), '', $input);
}
$lines = explode('<br />', $input);
$count = count($lines) - 1;
if (isset($tagged)) {
$lines[1] = $lines[0] . $lines[1];
}
$lines[$count - 1] = $lines[$count - 1] . $lines[$count];
$col1 = '';
$col2 = '';
for ($i = 1; $i < $count; $i++)
{
$col1 .= $start . '<br />';
$col2 .= rtrim($lines[$i]) . '<br />';
$start++;
}
$col2 = substr($col2, 0, -6);
$return = "<div class='code'>";
$return .= "<div class='codetitle'>$title:</div>";
$return .= "<div class='codelines'>$col1</div>";
$return .= "<div class='codedata'>$col2</div></div>";
return $return;
}
/**
* Finds all subforums of $parent in $array
*
* @param array $array Array of forums from forum_grab()
* @param int $parent forum_id of a parent forum
* @author Mark Elliot <[email protected]>
* @since Beta 4.0
* @return array Array of subforums
**/
function forum_array($array, $parent)
{
$arr = array();
for ($i = 0; $i < count($array); $i++)
{
if ($array[$i]['forum_parent'] == $parent) {
$arr[] = $array[$i];
}
}
return $arr;
}
/**
* Gets all forums and puts them in an array
*
* @param string $sort Field to sort by
* @author Mark Elliot <[email protected]>
* @since Beta 4.0
* @return array Array of all existing forums to be passed to select_forums()
**/
function forum_grab($sort = 'forum_position')
{
$forums = array();
$q = $this->db->query('SELECT forum_id, forum_parent, forum_tree, forum_name, forum_position FROM ' . $this->pre . 'forums ORDER BY ' . $sort);
while ($f = $this->db->nqfetch($q))
{
$forums[] = $f;
}
return $forums;
}
/**
* Generates a random pronounceable password
*
* @param int $length Length of password
* @author http://www.zend.com/codex.php?id=215&single=1
* @since 1.1.0
*/
function generate_pass($length)
{
$vowels = array('a', 'e', 'i', 'o', 'u');
$cons = array('b', 'c', 'd', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'u', 'v', 'w', 'tr',
'cr', 'br', 'fr', 'th', 'dr', 'ch', 'ph', 'wr', 'st', 'sp', 'sw', 'pr', 'sl', 'cl');
$num_vowels = count($vowels);
$num_cons = count($cons);
$password = '';
for ($i = 0; $i < $length; $i++)
{
$password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
}
return substr($password, 0, $length);
}
/**
* Retrieves message icons and puts them into a table as radio buttons
*
* @param string $select Icon to select
* @author Jason Warner <[email protected]>
* @since Beta 2.0
* @return string HTML-formatted message icons
**/
function get_icons($select = -1)
{
$i = 0;
$icons = array();
$dir = opendir("./skins/$this->skin/mbicons");
while (($file = readdir($dir)) !== false)
{
$ext = substr($file, -4);
if ((($ext == '.gif') || ($ext == '.jpg') || ($ext == '.png')) && !is_dir("./skins/$this->skin/mbicons/$file")) {
$icons[$i] = $file;
$i++;
}
}
closedir($dir);
natsort($icons);
$msgicons = null;
$i = 0;
foreach ($icons as $icon)
{
if (($i % 8 == 0) && ($i != 0)) {
$msgicons .= "\n</tr><tr>\n\n";
}
$msgicons .= "\n<td><input type='radio' name='icon' id='icon$i' value='$icon'" . (($select == $icon) ? ' checked=\'checked\'' : null) . " /><label for='icon$i'><img src='./skins/$this->skin/mbicons/$icon' alt='Message Icon' /></label> </td>";
$i++;
}
return $msgicons;
}
/**
* Loads a user_language. Bet you couldn't figure that out...
*
* @param string $lang Language to load
* @param string $a Word set to load
* @param string $path Path to the user_languages directory
* @param bool $main Load main universal strings
* @author Jason Warner <[email protected]>
* @since Beta 3.0
* @return object Language
**/
function get_lang($lang, $a = null, $path = './', $main = true)
{
if (isset($this->get['lang'])) {
$lang = $this->get['lang'];
}
if (strstr($lang, '/') || !file_exists($path . 'languages/' . $lang . '.php')) {
$lang = 'en';
}
include $path . 'languages/' . $lang . '.php';
$obj = new $lang();
if ($a) {
$obj->$a();
}
if ($main) {
$obj->main();
}
return $obj;
}
function get_lang_name($code)
{
$code = strtolower($code);
switch($code)
{
case 'bg': return 'Bulgarian'; break;
case 'zh': return 'Chinese'; break;
case 'cs': return 'Czech'; break;
case 'nl': return 'Dutch'; break;
case 'en': return 'English'; break;
case 'fi': return 'Finnish'; break;
case 'fr': return 'French'; break;
case 'de': return 'German'; break;
case 'he': return 'Hebrew'; break;
case 'hu': return 'Hungarian'; break;
case 'id': return 'Indonesian'; break;
case 'it': return 'Italian'; break;
case 'no': return 'Norwegian'; break;
case 'pt': return 'Portuguese'; break;
case 'ru': return 'Russian'; break;
case 'sk': return 'Slovak'; break;
case 'es': return 'Spanish'; break;
case 'sv': return 'Swedish'; break;
default: return $code; break;
}
}
/**
* Gets information about a member's level and title
*
* @param int $posts Member's post count
* @author Jason Warner <[email protected]>
* @since Beta 2.1
* @return array Array of information about the member:<br /><i>string user_title</i> - default member title for that post count<br /><i>int user_level</i> - default member level for that post count
**/
function get_level($posts)
{
$memtitle = array(
'user_title' => '',
'user_level' => '0'
);
$titles = $this->db->query("SELECT * FROM {$this->pre}membertitles WHERE membertitle_posts <= $posts ORDER BY membertitle_posts");
while ($title = $this->db->nqfetch($titles))
{
if ($posts >= $title['membertitle_posts']) {
$memtitle['user_title'] = $title['membertitle_title'];
$memtitle['user_level'] = $title['membertitle_id'];
} else {
break;
}
}
return $memtitle;
}
/**
* Retrieves the current server load
*
* @author Jason Warner <[email protected]>
* @since Beta 2.0
* @return int Server load
**/
function get_load()
{
if (get_cfg_var('safe_mode') || stristr(PHP_OS, 'WIN')) {
return 0;
}
if (@file_exists('/proc/loadavg')) {
$file = @fopen('/proc/loadavg', 'r');
if (!$file) {
return 0;
}
$load = explode(' ', fread($file, 6));
fclose($file);
} else {
$load = @exec('uptime');
if (!$load) {
return 0;
}
$load = split('load averages?: ', $load);
$load = explode(',', $load[1]);
}
return trim($load[0]);
}
/**
* Retrieves the number of personal messages the user has received
*
* @param bool $seen True to retreive all messages, false to retrieve only unread messages
* @param int $folder The folder to check user_pms for
* @author Jason Warner <[email protected]>
* @since Beta 2.0
* @return int Count of personal messages
**/
function get_messages($seen = false, $folder = 0)
{
$count = $this->db->fetch("SELECT COUNT(pm_id) AS messages FROM {$this->pre}pmsystem WHERE pm_to={$this->user['user_id']} AND pm_folder=$folder" . (!$seen ? " AND pm_read=0" : null));
return $count['messages'];
}
/**
* Creates HTML-formatted page numbers
*
* @param mixed $rows Can be either a resource, query, or number; number of total entries for pagination
* @param string $link Query string to attach to link
* @param int $min First entry to display
* @param int $num Number of entries per page
* @author Mark Elliot <[email protected]>
* @since Beta 1.0
* @return string HTML-formatted page numbers
**/
function get_pages($rows, $link, $min = 0, $num = 10)
{
if (!$num) {
$num = 10;
}
// preliminary row handling
if (!is_resource($rows)) {
if (!is_numeric($rows)) {
$rows = $this->db->num_rows($this->db->query($rows));
}
} else {
$rows = $this->db->num_rows($records);
}
// some base variables
$current = ceil($min / $num);
$string = null;
$pages = ceil($rows / $num);
$end = ($pages - 1) * $num;
// check if there's previous articles
if ($min == 0) {
$startlink = '<<';
$previouslink = $this->lang->main_prev;
} else {
$startlink = "<a class='pagelinks' href='$this->self?$link&min=0&num=$num'><<</a>";
$prev = $min - $num;
$previouslink = "<a class='pagelinks' href='$this->self?$link&min=$prev&num=$num'>{$this->lang->main_prev}</a> ";
}
// check for next/end
if (($min + $num) < $rows) {
$next = $min + $num;
$nextlink = "<a class='pagelinks' href='$this->self?$link&min=$next&num=$num'>{$this->lang->main_next}</a>";
$endlink = "<a class='pagelinks' href='$this->self?$link&min=$end&num=$num'>>></a>";
} else {
$nextlink = $this->lang->main_next;
$endlink = '>>';
}
// setup references
$b = $current - 2;
$e = $current + 2;
// set end and beginning of loop
if ($b < 0) {
$e = $e - $b;
$b = 0;
}
// check that end coheres to the issues
if ($e > $pages - 1) {
$b = $b - ($e - $pages + 1);
$e = ($pages - 1 < $current) ? $pages : $pages - 1;
// b may need adjusting again
if ($b < 0) {
$b = 0;
}
}
// ellipses
if ($b != 0) {
$badd = '...';
} else {
$badd = '';
}
if (($e != $pages - 1) && $rows) {
$eadd = '...';
} else {
$eadd = '';
}
// run loop for numbers to the page
for ($i = $b; $i < $current; $i++)
{
$where = $num * $i;
$string .= ", <a class='bodylinktype' href='$this->self?$link&min=$where&num=$num'>" . ($i + 1) . '</a>';
}
// add in page
$string .= ', <b>' . ($current + 1) . '</b>';
// run to the end
for ($i = $current + 1; $i <= $e; $i++)
{
$where = $num * $i;
$string .= ", <a class='bodylinktype' href='$this->self?$link&min=$where&num=$num'>" . ($i + 1) . '</a>';
}
// get rid of preliminary comma. (optimized by jason: mark uses preg_replace() like candy)
if (substr($string, 0, 1) == ',') {
$string = substr($string, 1);
}
return "<span class='pagelinks'>$startlink $previouslink $badd $string $eadd $nextlink $endlink</span>";
}
/**
* Creates HTML-formatted page numbers for topics - see get_pages()
*
* @param int $records Number of replies in the topic
* @param int $link Query string to attach to link
* @param string $sep Separator for pages
* @param int $min First entry to display
* @param int $n Number of entries to display
* @author Mark Elliot <[email protected]>
* @since Beta 2.0
* @return
**/
function get_pages_topic($records, $link, $sep, $min = 0, $n = 10)
{
$records++;
$pages = ceil($records / $n);
$max_page = ($pages - 1) * $n;
if ($pages == 1) {
return null;
}
$pagelinks = null;
if ($pages > 3) {
$countfor = 3;
} else {
$countfor = $pages;
}
for ($i = 0; $i < $countfor; $i++)
{
$minpag = $i * $n;
$page = $i + 1;
$pagelinks .= "<a href='$this->self?$link&min=$minpag&num=$n' class='pages'>$page</a>{$sep}";
}
if (substr($pagelinks, -(strlen($sep))) == $sep) {
$pagelinks = substr($pagelinks, 0, -(strlen($sep)));
}
if ($pages > 3) {
$ellipsis = ($pages == 4) ? '' : '..';
$pagelinks .= "$sep<a href='$this->self?$link&min=$max_page&num=$n' class='pages'>{$ellipsis}{$pages}</a>";
}
$pagelinks = "( $pagelinks )";
return $pagelinks;
}
/**
* Loads emoticon and censor information from the replacements table
*
* @author Jason Warner <[email protected]>
* @since Beta 2.1
* @return void
**/
function get_replaces()
{
$this->replaces_loaded = true;
$replace = $this->db->query("SELECT * FROM {$this->pre}replacements ORDER BY LENGTH(replacement_search) DESC");
while ($r = $this->db->nqfetch($replace))
{
if ($r['replacement_type'] == 'emoticon') {
$this->emotes['replacement'][$r['replacement_search']] = "<img src='./skins/$this->skin/emoticons/{$r['replacement_replace']}' alt='{$r['replacement_search']}' />";
if ($r['replacement_clickable']) {
$this->emotes['replacement_clickable'][$r['replacement_search']] = "<img src='./skins/$this->skin/emoticons/{$r['replacement_replace']}' alt='{$r['replacement_search']}' />";
}
} elseif ($r['replacement_type'] == 'censor') {
$this->censor[] = '/' . $r['replacement_search'] . '/i';
}
}
}
/**
* Loads settings
*
* @author Jason Warner <[email protected]>
* @since 1.1.0
* @return array Settings
**/
function get_settings($sets)
{
$settings = $this->db->fetch("SELECT settings_data FROM {$this->pre}settings LIMIT 1");
return array_merge($sets, unserialize($settings['settings_data']));
}
/**
* Loads templates into an array, replacing {{var}} with $var
*
* @param string $a Template group
* @param bool $getMain Load the standard set of templates
* @author Jason Warner <[email protected]>
* @since Beta 2.0
* @return mixed Array of templates on success, error message on failure
**/
function get_templates($a, $getMain = true)
{
if (!$this->perms->auth('is_admin')) {
$admin_replace = '';
} else {
$admin_replace = '\\1';
}
if ($getMain) {
$temp_query = $this->db->query("SELECT template_name, template_html FROM {$this->pre}templates WHERE template_skin='$this->skin' AND (template_set='Main' OR template_set='$a')");
} else {
$temp_query = $this->db->query("SELECT template_name, template_html FROM {$this->pre}templates WHERE template_skin='$this->skin' AND template_set='$a'");
}
while ($template = $this->db->nqfetch($temp_query))
{
$template['template_html'] = preg_replace('~<IF (.*?)(?<!\-)>(.*?)</IF>~se', '$this->get_templates_callback(\'\\1\', \'\\2\', $template[\'template_name\'])', $template['template_html']);
$templates[$template['template_name']] = $template['template_html'];
}
$dir = file_exists('./skins/' . $this->skin) && is_dir('./skins/' . $this->skin);
if (isset($templates) && $dir) {
// $templates = preg_replace('~<ADMIN>(.*)</ADMIN>~', $admin_replace, $templates);
$templates = str_replace(array('\\', '"', '\\$'), array('\\\\', '\\"', '\\\\$'), $templates);
return $templates;
} else {
if ($dir) {
error(MERCURY_ERROR, "Template set not found in database: $a", __FILE__, __LINE__);
} else {
error(MERCURY_ERROR, "Template set not found in database: $a<br />Skin not found in the skins directory: $this->skin", __FILE__, __LINE__);
}
}
}
/**
* Stores if statements into an array (performance speed-up)
*
* @param string if statements
* @param string string to use if condition is true
* @param string template
* @author Inverno
* @return string replace if statements with a var
**/
function get_templates_callback($condition, $code, $piece)
{
$macro_id = isset($this->macro[$piece]) ? count($this->macro[$piece]) : 0;
$this->macro[$piece][$macro_id] = '$macro_replace[' . $macro_id . '] = ((' . $condition . ') ? "' . $code . '" : ""); ';
return '{' . chr(36) . 'macro_replace[' . $macro_id . ']}';
}
/**
* Determines if a user has been banned
*
* @return bool True if the user is banned, false if the user is not
**/
function is_banned()
{
//Ban by user group
if (!$this->perms->auth('do_anything')) {
return true;
}
//Ban by IP
if ($this->sets['banned_ips']) {
foreach ($this->sets['banned_ips'] as $ip)
{
if (preg_match("/$ip/", $this->ip)) {
return true;
}
}
}
return false;
}
/**
* Generates clickable emoticon HTML
*
* @param int $per_row Smilies to show per row
* @author Jason Warner <[email protected]>
* @since Beta 3.0
* @return string HTML
**/
function make_clickable($per_row)
{
$return = null;
$x = 0;
if (!$this->replaces_loaded) {
$this->get_replaces();
}
foreach ($this->emotes['replacement_clickable'] as $search => $replace)
{
if (!$x) {
$return .= "\n<tr>";
}
$return .= "\n<td align='center' class='tablelight'><a href='#' onclick=\"return insertSmiley('{$search}')\">{$replace}</a></td>";
if ($x == $per_row - 1) {
$return .= "\n</tr>";
$x = 0;
} else {
$x++;
}
}
if ($x && ($x < $per_row)) {
while ($x < $per_row)
{
$return .= "\n<td class='tablelight'> </td>";
$x++;
}
$return .= "\n</tr>";
}
return $return;
}
/**
* Used as a replacement for date() which deals with time zones
*
* @param mixed $format Date format using date() keywords. Either a date constant or a string.
* @param int $time Timestamp. If left out, uses current time
* @author Jason Warner <[email protected]>
* @since Beta 2.1
* @return string Human-readable, formatted Unix timestamp
**/
function mbdate($format, $time = 0)
{
if (!$time) {
$time = $this->time;
}
$adjust = ($this->user['user_timezone'] - $this->sets['servertime']) * 3600;
$time += $adjust;
if (is_int($format)) {
switch($format)
{
case DATE_LONG:
$date_format = 'M j, Y';
$time_format = ', g:i a';
break;
case DATE_SHORT:
$date_format = 'n/j/y';
$time_format = ', g:i a';
break;
case DATE_ONLY_LONG:
$date_format = 'M j, Y';
$time_format = '';
break;
case DATE_TIME:
$date_format = '';
$time_format = 'g:i a';
break;
default: // DATE_ONLY_SHORT
$date_format = 'n/j/y';
$time_format = '';
break;
}
if ($date_format) {