-
Notifications
You must be signed in to change notification settings - Fork 61
/
SSI.php
2175 lines (1885 loc) · 67 KB
/
SSI.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
/**
* Provides ways to add information to your website by linking to and capturing output
* from ElkArte
*
* @package ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
*
* This file contains code covered by:
* copyright: 2011 Simple Machines (http://www.simplemachines.org)
*
* @version 2.0 dev
*
*/
use BBC\ParserWrapper;
use ElkArte\Cache\Cache;
use ElkArte\Controller\Poll;
use ElkArte\EventManager;
use ElkArte\Helper\Util;
use ElkArte\MembersList;
use ElkArte\MessageTopicIcons;
use ElkArte\User;
/**
* Set this to one of three values depending on what you want to happen in the case of a fatal error.
* - false: Default, will just load the error sub template and die - not putting any theme layers around it.
* - true: Will load the error sub template AND put the template layers around it (Not useful if on total custom pages).
* - string: Name of a callback function to call in the event of an error to allow you to define your own methods. Will die after function returns.
*/
$ssi_on_error_method = false;
/**
* Don't do john didley if the forum's been shut down completely.
*/
// $ssi_maintenance_off = false;
/**
* Define a theme for SSI (integer)
*/
// $ssi_theme = 0;
/**
* An array of layers to use.
*/
// $ssi_layers = array();
/**
* Gzip output? (because it must be boolean and true, this can't be hacked.)
*/
// $ssi_gzip = false;
/**
* Should we ban from SSI as well?
*/
// $ssi_ban = false;
/**
* Do we allow guests in here?
*/
// $ssi_guest_access = false;
// We are in Elk, but from the side-entrance.
if (!defined('ELKBOOT'))
{
define('ELK', 'SSI');
require_once(__DIR__ . '/bootstrap.php');
$bootstrap = new Bootstrap(true);
}
// The globals that were created during the bootstrap process
global $time_start, $maintenance, $msubject, $mmessage, $mbname, $language;
global $boardurl, $webmaster_email, $cookiename;
global $db_type, $db_server, $db_name, $db_user, $db_prefix, $db_persist, $db_error_send;
global $modSettings, $context, $user_info, $topic, $board, $txt;
global $ssi_db_user, $scripturl, $ssi_db_passwd, $db_passwd;
global $boarddir, $sourcedir, $db_show_debug, $ssi_error_reporting;
// Have the ability to easily add functions to SSI.
call_integration_hook('integrate_SSI');
// Call a function passed by GET.
if (isset($_GET['ssi_function']) && function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || User::$info->is_guest === false))
{
call_user_func('ssi_' . $_GET['ssi_function']);
exit;
}
if (isset($_GET['ssi_function']))
{
exit;
}
// You shouldn't just access SSI.php directly by URL!!
if (basename($_SERVER['PHP_SELF']) === 'SSI.php')
{
die(sprintf($txt['ssi_not_direct'], User::$info->is_admin ? "'" . addslashes(__FILE__) . "'" : "'SSI.php'"));
}
error_reporting($ssi_error_reporting);
return true;
/**
* This shuts down the SSI and shows the footer.
*/
function ssi_shutdown()
{
if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'shutdown')
{
template_footer();
}
}
/**
* Display a welcome message, like:
* "Hey, User, you have 0 messages, 0 are new."
*
* @param string $output_method The output method. If 'echo', will display
* everything. Otherwise returns an array of user info.
*/
function ssi_welcome($output_method = 'echo')
{
global $context, $txt, $scripturl;
if ($output_method === 'echo')
{
if ($context['user']['is_guest'])
{
echo replaceBasicActionUrl($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest']);
}
else
{
echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
}
}
// Don't echo... then do what?!
else
{
return $context['user'];
}
}
/**
* Display a menu bar, like is displayed at the top of the forum.
*
* @param string $output_method The output method. If 'echo', will display
* everything. Otherwise returns an array of menu data.
*/
function ssi_menubar($output_method = 'echo')
{
global $context;
if ($output_method === 'echo')
{
template_menu();
}
// What else could this do?
else
{
return $context['menu_buttons'];
}
}
/**
* Show a logout link.
*
* @param string $redirect_to A URL to redirect the user to after they log out.
* @param string $output_method = 'echo; The output method. If 'echo', shows a logout link,
* otherwise returns HTML.
*/
function ssi_logout($redirect_to = '', $output_method = 'echo')
{
global $context, $txt, $scripturl;
if ($redirect_to !== '')
{
$_SESSION['logout_url'] = $redirect_to;
}
// Guests can't log out.
if ($context['user']['is_guest'])
{
return false;
}
$link = '<a class="linkbutton" href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>';
if ($output_method === 'echo')
{
echo $link;
}
else
{
return $link;
}
}
/**
* Recent post list:
* [board] Subject by Poster Date
*
* @param int $num_recent How many recent posts to display
* @param int[]|null $exclude_boards If set, doesn't show posts from the specified boards
* @param int[]|null $include_boards If set, only includes posts from the specified boards
* @param string $output_method The output method. If 'echo', displays the posts, otherwise
* returns an array of information about them.
* @param bool $limit_body Whether or not to only show the first 384 characters of each post
* @todo this may use getLastPosts with some modification
*
*/
function ssi_recentPosts($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo', $limit_body = true)
{
global $modSettings;
// Excluding certain boards...
if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
{
$exclude_boards = array($modSettings['recycle_board']);
}
elseif (empty($exclude_boards))
{
$exclude_boards = array();
}
elseif (is_array($exclude_boards))
{
$exclude_boards = $exclude_boards;
}
else
{
$exclude_boards = array($exclude_boards);
}
// What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter.
if (is_array($include_boards) || (int) $include_boards === $include_boards)
{
$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
}
elseif ($include_boards !== null)
{
$include_boards = array();
}
// Let's restrict the query boys (and girls)
$query_where = '
m.id_msg >= {int:min_message_id}
' . (empty($exclude_boards) ? '' : '
AND b.id_board NOT IN ({array_int:exclude_boards})') . '
' . ($include_boards === null ? '' : '
AND b.id_board IN ({array_int:include_boards})') . '
AND {query_wanna_see_board}' . ($modSettings['postmod_active'] ? '
AND m.approved = {int:is_approved}' : '');
$query_where_params = array(
'is_approved' => 1,
'include_boards' => $include_boards ?? '',
'exclude_boards' => empty($exclude_boards) ? '' : $exclude_boards,
'min_message_id' => $modSettings['maxMsgID'] - 25 * min($num_recent, 5),
);
// Past to this simpleton of a function...
return ssi_queryPosts($query_where, $query_where_params, $num_recent, 'm.id_msg DESC', $output_method, $limit_body);
}
/**
* Fetch a post with a particular ID.
*
* - By default will only show if you have permission to the see the board
* in question - this can be overridden.
*
* @param int[] $post_ids An array containing the IDs of the posts to show
* @param bool $override_permissions Whether to ignore permissions. If true, will show posts even
* if the user doesn't have permission to see them.
* @param string $output_method = 'echo; The output method. If 'echo', displays the posts,
* otherwise returns an array of info about them
* @todo this may use getRecentPosts with some modification
*
*/
function ssi_fetchPosts($post_ids = array(), $override_permissions = false, $output_method = 'echo')
{
global $modSettings;
if (empty($post_ids))
{
return '';
}
// Allow the user to request more than one - why not?
$post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
// Restrict the posts required...
$query_where = '
m.id_msg IN ({array_int:message_list})' . ($override_permissions ? '' : '
AND {query_wanna_see_board}') . ($modSettings['postmod_active'] ? '
AND m.approved = {int:is_approved}' : '');
$query_where_params = array(
'message_list' => $post_ids,
'is_approved' => 1,
);
// Then make the query and dump the data.
return ssi_queryPosts($query_where, $query_where_params, '', 'm.id_msg DESC', $output_method, false, $override_permissions);
}
/**
* This handles actually pulling post info
*
* - removes code duplication in other queries
* - don't call it direct unless you really know what you're up to.
*
* @param string $query_where The WHERE clause for the query
* @param mixed[] $query_where_params An array of parameters for the WHERE clause
* @param int $query_limit The maximum number of rows to return
* @param string $query_order The ORDER BY clause for the query
* @param string $output_method = 'echo; The output method. If 'echo', displays the posts,
* otherwise returns an array of info about them.
* @param bool $limit_body If true, will only show the first 384 characters of the post
* rather than all of it
* @param bool $override_permissions Whether or not to ignore permissions. If true, will
* show all posts regardless of whether the user can actually see them
* @todo if ssi_recentPosts and ssi_fetchPosts will use Recent.subs.php this can be removed
*
*/
function ssi_queryPosts($query_where = '', $query_where_params = array(), $query_limit = 10, $query_order = 'm.id_msg DESC', $output_method = 'echo', $limit_body = false, $override_permissions = false)
{
global $scripturl, $txt, $modSettings;
$db = database();
// Find all the posts. Newer ones will have higher IDs.
$request = $db->fetchQuery('
SELECT
m.poster_time, m.subject, m.id_topic, m.id_member, m.id_msg, m.id_board, b.name AS board_name,
COALESCE(mem.real_name, m.poster_name) AS poster_name, ' . (User::$info->is_guest ? '1 AS is_read, 0 AS new_from' : '
COALESCE(lt.id_msg, lmr.id_msg, 0) >= m.id_msg_modified AS is_read,
COALESCE(lt.id_msg, lmr.id_msg, -1) + 1 AS new_from') . ', ' . ($limit_body ? 'SUBSTRING(m.body, 1, 384) AS body' : 'm.body') . ', m.smileys_enabled
FROM {db_prefix}messages AS m
JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (User::$info->is_guest ? '' : '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = m.id_board AND lmr.id_member = {int:current_member})') . '
WHERE 1=1 ' . ($override_permissions ? '' : '
AND {query_wanna_see_board}') . ($modSettings['postmod_active'] ? '
AND m.approved = {int:is_approved}
AND t.approved = {int:is_approved}' : '') . '
' . (empty($query_where) ? '' : 'AND ' . $query_where) . '
ORDER BY ' . $query_order . '
' . (empty($query_limit) ? '' : 'LIMIT {int:query_limit}'),
array_merge($query_where_params, array(
'current_member' => User::$info->id,
'is_approved' => 1,
'query_limit' => $query_limit,
))
);
$bbc_parser = ParserWrapper::instance();
$posts = array();
while ($row = $request->fetch_assoc())
{
$row['body'] = $bbc_parser->parseMessage($row['body'], $row['smileys_enabled']);
// Censor it!
$row['subject'] = censor($row['subject']);
$row['body'] = censor($row['body']);
$preview = strip_tags(strtr($row['body'], array('<br />' => ' ')));
// Build the array.
$posts[] = array(
'id' => $row['id_msg'],
'board' => array(
'id' => $row['id_board'],
'name' => $row['board_name'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
),
'topic' => $row['id_topic'],
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => Util::shorten_text($row['subject'], empty($modSettings['ssi_subject_length']) ? 24 : $modSettings['ssi_subject_length']),
'preview' => Util::shorten_text($preview, empty($modSettings['ssi_preview_length']) ? 128 : $modSettings['ssi_preview_length']),
'body' => $row['body'],
'time' => standardTime($row['poster_time']),
'html_time' => htmlTime($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $row['subject'] . '</a>',
'new' => !empty($row['is_read']),
'is_new' => empty($row['is_read']),
'new_from' => $row['new_from'],
);
}
$request->free_result();
// Just return it.
if ($output_method !== 'echo' || empty($posts))
{
return $posts;
}
echo '
<table class="ssi_table">';
foreach ($posts as $post)
{
echo '
<tr>
<td class="righttext">
[', $post['board']['link'], ']
</td>
<td class="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt['by'], ' ', $post['poster']['link'], '
', $post['is_new'] ? '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow" class="new_posts">' . $txt['new'] . '</a>' : '', '
</td>
<td class="righttext">
', $post['time'], '
</td>
</tr>';
}
echo '
</table>';
}
/**
* Generates a recent topic list
*
* - [board] Subject by Poster Date
*
* @param int $num_recent How many recent topics to show
* @param int[]|null $exclude_boards If set, exclude topics from the specified board(s)
* @param bool|null $include_boards If set, only include topics from the specified board(s)
* @param string $output_method = 'echo' The output method. If 'echo', displays a list of topics,
* otherwise returns an array of info about them
*/
function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo')
{
global $settings, $scripturl, $txt, $modSettings;
$db = database();
if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
{
$exclude_boards = array($modSettings['recycle_board']);
}
else
{
$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
}
// Only some boards?.
if (is_array($include_boards) || (int) $include_boards === $include_boards)
{
$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
}
elseif ($include_boards !== null)
{
$output_method = $include_boards;
$include_boards = array();
}
$icon_sources = new MessageTopicIcons(!empty($modSettings['messageIconChecks_enable']), $settings['theme_dir']);
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$topics = array();
$db->fetchQuery('
SELECT
t.id_topic, b.id_board, b.name AS board_name
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
WHERE t.id_last_msg >= {int:min_message_id}' . (empty($exclude_boards) ? '' : '
AND b.id_board NOT IN ({array_int:exclude_boards})') . (empty($include_boards) ? '' : '
AND b.id_board IN ({array_int:include_boards})') . '
AND {query_wanna_see_board}' . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}
AND ml.approved = {int:is_approved}' : '') . '
ORDER BY t.id_last_msg DESC
LIMIT {int:num_recent}',
array(
'include_boards' => empty($include_boards) ? '' : $include_boards,
'exclude_boards' => empty($exclude_boards) ? '' : $exclude_boards,
'min_message_id' => $modSettings['maxMsgID'] - 35 * min($num_recent, 5),
'is_approved' => 1,
'num_recent' => $num_recent,
)
)->fetch_callback(
static function ($row) use (&$topics) {
$topics[$row['id_topic']] = $row;
}
);
// Did we find anything? If not, bail.
if (empty($topics))
{
return array();
}
$topic_list = array_keys($topics);
// Count number of new posts per topic.
if (User::$info->is_guest === false)
{
$db->fetchQuery('
SELECT
m.id_topic, COALESCE(lt.id_msg, lmr.id_msg, -2) + 1 AS new_from
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = m.id_board AND lmr.id_member = {int:current_member})
WHERE
m.id_topic IN ({array_int:topic_list})
AND (m.id_msg > COALESCE(lt.id_msg, lmr.id_msg, 0))
GROUP BY m.id_topic, lt.id_msg, lmr.id_msg',
array(
'current_member' => User::$info->id,
'topic_list' => $topic_list
)
)->fetch_callback(
static function ($row) use (&$topics) {
$topics[$row['id_topic']] += $row;
}
);
}
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = $db->fetchQuery('
SELECT
ml.poster_time, ml.id_member, ml.id_msg, ml.smileys_enabled, ml.icon,
mf.subject, mf.id_member AS id_op_member,
t.id_topic, t.num_replies, t.num_views, t.id_last_msg, t.id_first_msg,
mg.online_color,
COALESCE(mem.real_name, ml.poster_name) AS poster_name,
COALESCE(memop.real_name, mf.poster_name) AS op_name,
SUBSTRING(ml.body, 1, 384) AS body
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ml.id_member)
LEFT JOIN {db_prefix}members AS memop ON (memop.id_member = mf.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
WHERE t.id_topic IN ({array_int:topic_list})',
array(
'topic_list' => $topic_list
)
);
$bbc_parser = ParserWrapper::instance();
$posts = array();
while (($row = $request->fetch_assoc()))
{
$row['body'] = strip_tags(strtr($bbc_parser->parseMessage($row['body'], $row['smileys_enabled']), array('<br />' => ' ')));
// Censor the subject and body.
$row['subject'] = censor($row['subject']);
$row['body'] = censor($row['body']);
$row['body'] = Util::shorten_text($row['body'], 128);
// Build the array.
$posts[$row['id_last_msg']] = array(
'board' => array(
'id' => $topics[$row['id_topic']]['id_board'],
'name' => $topics[$row['id_topic']]['board_name'],
'href' => $scripturl . '?board=' . $topics[$row['id_topic']]['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $topics[$row['id_topic']]['id_board'] . '.0">' . $topics[$row['id_topic']]['board_name'] . '</a>',
),
'topic' => $row['id_topic'],
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
),
'original_poster' => array(
'id' => $row['id_op_member'],
'name' => $row['op_name'],
'href' => empty($row['id_op_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_op_member'],
'link' => empty($row['id_op_member']) ? $row['op_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_op_member'] . '">' . $row['op_name'] . '</a>'
),
'subject' => $row['subject'],
'replies' => $row['num_replies'],
'views' => $row['num_views'],
'short_subject' => Util::shorten_text($row['subject'], 25),
'preview' => $row['body'],
'time' => standardTime($row['poster_time']),
'html_time' => htmlTime($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#new" rel="nofollow">' . $row['subject'] . '</a>',
'is_new' => !empty($topics[$row['id_topic']]['new_from']),
'new_from' => empty($topics[$row['id_topic']]['new_from']) ? 0 : $topics[$row['id_topic']]['new_from'],
'icon' => '<img src="' . $icon_sources->getIconURL($row['icon']) . '" class="icon-middle" alt="' . $row['icon'] . '" />',
);
}
$request->free_result();
krsort($posts);
// Just return it.
if ($output_method !== 'echo' || empty($posts))
{
return $posts;
}
echo '
<table class="ssi_table">';
foreach ($posts as $post)
{
echo '
<tr>
<td class="righttext top">
[', $post['board']['link'], ']
</td>
<td class="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt['by'], ' ', $post['poster']['link'], '
', $post['is_new'] ? '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow" class="new_posts">' . $txt['new'] . '</a>' : '', '
</td>
<td class="righttext">
', $post['time'], '
</td>
</tr>';
}
echo '
</table>';
}
/**
* Show the top poster's name and profile link.
*
* @param int $topNumber How many top posters to list
* @param string $output_method = 'echo' The output method. If 'echo', will display a list of
* users, otherwise returns an array of info about them.
*/
function ssi_topPoster($topNumber = 1, $output_method = 'echo')
{
require_once(SUBSDIR . '/Stats.subs.php');
$top_posters = topPosters($topNumber);
// Just return all the top posters.
if ($output_method !== 'echo')
{
return $top_posters;
}
// Make a quick array to list the links in.
$temp_array = array();
foreach ($top_posters as $member)
{
$temp_array[] = $member['link'];
}
echo implode(', ', $temp_array);
}
/**
* Show boards by activity.
*
* @param int $num_top How many boards to display
* @param string $output_method = 'echo' The output method. If 'echo', displays a list of
* boards, otherwise returns an array of info about them.
*/
function ssi_topBoards($num_top = 10, $output_method = 'echo')
{
global $txt;
require_once(SUBSDIR . '/Stats.subs.php');
// Find boards with lots of posts.
$boards = topBoards($num_top, true);
foreach ($boards as $id => $board)
{
$boards[$id]['new'] = empty($board['is_read']);
}
// If we shouldn't output or have nothing to output, just jump out.
if ($output_method !== 'echo' || empty($boards))
{
return $boards;
}
echo '
<table class="ssi_table">
<tr>
<th>', $txt['board'], '</th>
<th class="centertext">', $txt['board_topics'], '</th>
<th class="centertext">', $txt['posts'], '</th>
</tr>';
foreach ($boards as $board)
{
echo '
<tr>
<td>', $board['new'] ? ' <a href="' . $board['href'] . '" class="new_posts">' . $txt['new'] . '</a> ' : '', $board['link'], '</td>
<td class="centertext">', $board['num_topics'], '</td>
<td class="centertext">', $board['num_posts'], '</td>
</tr>';
}
echo '
</table>';
}
/**
* Shows the top topics.
*
* @param string $type Can be one of type or replies
* @param int $num_topics = 10, How many topics to display
* @param string $output_method = 'echo' The output method. If 'echo', displays a
* list of topics, otherwise returns an array of info about them.
*/
function ssi_topTopics($type = 'replies', $num_topics = 10, $output_method = 'echo')
{
global $txt, $scripturl;
require_once(SUBSDIR . '/Stats.subs.php');
$function = function_exists('topTopic' . ucfirst($type)) ? 'topTopic' . ucfirst($type) : 'topTopicReplies';
$topics = $function($num_topics);
foreach ($topics as $topic_id => $row)
{
$row['subject'] = censor($row['subject']);
$topics[$topic_id]['href'] = $scripturl . '?topic=' . $row['id'] . '.0';
$topics[$topic_id]['link'] = '<a href="' . $scripturl . '?topic=' . $row['id'] . '.0">' . $row['subject'] . '</a>';
}
if ($output_method !== 'echo' || empty($topics))
{
return $topics;
}
echo '
<table class="top_topic ssi_table">
<tr>
<th class="link"></th>
<th class="centertext views">', $txt['views'], '</th>
<th class="centertext num_replies">', $txt['replies'], '</th>
</tr>';
foreach ($topics as $topic)
{
echo '
<tr>
<td class="link">
', $topic['link'], '
</td>
<td class="centertext views">', $topic['num_views'], '</td>
<td class="centertext num_replies">', $topic['num_replies'], '</td>
</tr>';
}
echo '
</table>';
}
/**
* Shows the top topics, by replies.
*
* @param int $num_topics = 10, How many topics to show
* @param string $output_method = 'echo' The output method. If 'echo', displays a list of topics,
* otherwise returns an array of info about them
*/
function ssi_topTopicsReplies($num_topics = 10, $output_method = 'echo')
{
return ssi_topTopics('replies', $num_topics, $output_method);
}
/**
* Shows the top topics, by views.
*
* @param int $num_topics = 10, How many topics to show
* @param string $output_method = 'echo' The output method. If 'echo', displays a list of topics,
* otherwise returns an array of info about them
*/
function ssi_topTopicsViews($num_topics = 10, $output_method = 'echo')
{
return ssi_topTopics('views', $num_topics, $output_method);
}
/**
* Show a link to the latest member:
*
* - Please welcome, Someone, our latest member.
*
* @param string $output_method = 'echo' The output method. If 'echo', returns a string
* with a link to the latest member's profile, otherwise returns an array of info about them.
*/
function ssi_latestMember($output_method = 'echo')
{
global $txt, $context;
if ($output_method === 'echo')
{
echo '
', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br />';
}
else
{
return $context['common_stats']['latest_member'];
}
}
/**
* Fetch a random member
*
* @param string $random_type = '', if type set to 'day' will only change once a day!
* @param string $output_method = 'echo' The output method. If 'echo', displays a link to the member's
* profile, otherwise returns an array of info about them.
*/
function ssi_randomMember($random_type = '', $output_method = 'echo')
{
global $modSettings;
// If we're looking for something to stay the same each day then seed the generator.
if ($random_type === 'day')
{
// Set the seed to change only once per day.
mt_srand(floor(time() / 86400));
}
// Get the lowest ID we're interested in.
$member_id = mt_rand(1, $modSettings['latestMember']);
$result = ssi_queryMembers('member_greater_equal', $member_id, 1, 'id_member ASC', $output_method);
// If we got nothing do the reverse - in case of unactivated members.
if (empty($result))
{
$result = ssi_queryMembers('member_lesser_equal', $member_id, 1, 'id_member DESC', $output_method);
}
// Just to be sure put the random generator back to something... random.
if ($random_type !== '')
{
mt_srand(time());
}
return $result;
}
/**
* Fetch a specific member.
*
* @param int[] $member_ids = array() The IDs of the members to fetch
* @param string $output_method = 'echo' The output method. If 'echo', displays a
* list of links to the members' profiles, otherwise returns an array of info about them.
*/
function ssi_fetchMember($member_ids = array(), $output_method = 'echo')
{
if (empty($member_ids))
{
return '';
}
// Can have more than one member if you really want...
$member_ids = is_array($member_ids) ? $member_ids : array($member_ids);
// Then make the query and dump the data.
return ssi_queryMembers('members', $member_ids, '', 'id_member', $output_method);
}
/**
* Fetch all members in the specified group
*
* @param int|null $group_id The ID of the group to get members from
* @param string $output_method = 'echo' The output method. If 'echo', returns a list of
* group members, otherwise returns an array of info about them.
*/
function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo')
{
if ($group_id === null)
{
return false;
}
return ssi_queryMembers('group_list', is_array($group_id) ? $group_id : array($group_id), '', 'real_name', $output_method);
}
/**
* Fetch some member data!
*
* - Gathers info about members based on the specified parameters.
* - Used by other functions to eliminate duplication.
*
* @param string|null $query_where The info for the WHERE clause of the query
* @param string|string[] $query_where_params The parameters for the WHERE clause
* @param string|int $query_limit The number of rows to return or an empty string to return all
* @param string $query_order The info for the ORDER BY clause of the query
* @param string $output_method The output method. If 'echo', displays a list of members,
* otherwise returns an array of info about them
*/
function ssi_queryMembers($query_where = null, $query_where_params = array(), $query_limit = '', $query_order = 'id_member DESC', $output_method = 'echo')
{
if ($query_where === null)
{
return false;
}
require_once(SUBSDIR . '/Members.subs.php');
$members_data = retrieveMemberData(array(
$query_where => $query_where_params,
'limit' => empty($query_limit) ? 10 : (int) $query_limit,
'order_by' => $query_order,
'activated_status' => 1,
));
$members = array();
foreach ($members_data['member_info'] as $row)
{
$members[] = $row['id'];
}
if (empty($members))
{
return array();
}
// Load the members.
MembersList::load($members);
// Draw the table!
if ($output_method === 'echo')
{
echo '
<table class="ssi_table">';
}
$query_members = array();
foreach ($members as $id)
{
$member = MembersList::get($id);
// Load their context data.
if ($member->isEmpty())
{
continue;
}
$member->loadContext();
// Store this member's information.
$query_members[$id] = $member;
// Only do something if we're echo'ing.
if ($output_method === 'echo')
{
echo '
<tr>
<td class="centertext">
', $query_members[$id]['link'], '
<br />', $query_members[$id]['avatar']['image'], '
</td>
</tr>';
}
}
// End the table if appropriate.
if ($output_method === 'echo')
{
echo '
</table>';
}
// Send back the data.
return $query_members;
}
/**
* Show some basic stats:
*
* - Total This: XXXX, etc.
*
* @param string $output_method The output method. If 'echo', displays the stats,
* otherwise returns an array of info about them
*/
function ssi_boardStats($output_method = 'echo')
{
global $txt, $scripturl, $modSettings;
if (!allowedTo('view_stats'))
{
return false;
}