forked from elkarte/Elkarte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSI.php
1816 lines (1558 loc) · 60.6 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
*
* @name ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause
*
* This software is a derived product, based on:
*
* Simple Machines Forum (SMF)
* copyright: 2011 Simple Machines (http://www.simplemachines.org)
* license: BSD, See included LICENSE.TXT for terms and conditions.
*
* @version 1.1 dev
*
*/
/**
* 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 competely.
*/
// $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;
require_once(dirname(__FILE__) . '/bootstrap.php');
// 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']))
{
call_user_func('ssi_' . $_GET['ssi_function']);
exit;
}
if (isset($_GET['ssi_function']))
exit;
// You shouldn't just access SSI.php directly by URL!!
elseif (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);
if (function_exists('set_magic_quotes_runtime'))
@set_magic_quotes_runtime($ssi_magic_quotes_runtime);
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
*/
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
*/
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
* @param string $output_method = 'echo'
*/
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 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
*
* @todo this may use getLastPosts with some modification
*
* @param int $num_recent
* @param int[]|null $exclude_boards
* @param int[]|null $include_boards
* @param string $output_method
* @param bool $limit_body
*/
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']);
else
$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $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 === null ? '' : $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 overriden.
*
* @todo this may use getRecentPosts with some modification
*
* @param int[] $post_ids
* @param bool $override_permissions
* @param string $output_method = 'echo'
*/
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 removes code duplication in other queries
* - don't call it direct unless you really know what you're up to.
*
* @todo if ssi_recentPosts and ssi_fetchPosts will use Recent.subs.php this can be removed
*
* @param string $query_where
* @param mixed[] $query_where_params
* @param int $query_limit
* @param string $query_order
* @param string $output_method = 'echo'
* @param bool $limit_body
* @param bool $override_permissions
*/
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, $user_info, $modSettings;
$db = database();
// Find all the posts. Newer ones will have higher IDs.
$request = $db->query('substring', '
SELECT
m.poster_time, m.subject, m.id_topic, m.id_member, m.id_msg, m.id_board, b.name AS board_name,
IFNULL(mem.real_name, m.poster_name) AS poster_name, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(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
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
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}' : '') . '
' . (empty($query_where) ? '' : 'AND ' . $query_where) . '
ORDER BY ' . $query_order . '
' . ($query_limit == '' ? '' : 'LIMIT ' . $query_limit),
array_merge($query_where_params, array(
'current_member' => $user_info['id'],
'is_approved' => 1,
))
);
$posts = array();
while ($row = $db->fetch_assoc($request))
{
$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
// Censor it!
censorText($row['subject']);
censorText($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']) ? $modSettings['ssi_subject_length'] : 24),
'preview' => Util::shorten_text($preview, !empty($modSettings['ssi_preview_length']) ? $modSettings['ssi_preview_length'] : 128),
'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'],
);
}
$db->free_result($request);
// 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"><span class="new_posts">' . $txt['new'] . '</span></a>' : '', '
</td>
<td class="righttext">
', $post['time'], '
</td>
</tr>';
echo '
</table>';
}
/**
* Recent topic list:
* [board] Subject by Poster Date
*
* @param int $num_recent
* @param int[]|null $exclude_boards
* @param bool|null $include_boards
* @param string $output_method = 'echo'
*/
function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo')
{
global $settings, $scripturl, $txt, $user_info, $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();
}
require_once(SUBSDIR . '/MessageIndex.subs.php');
$icon_sources = MessageTopicIcons();
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = $db->query('', '
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 ' . $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,
)
);
$topics = array();
while ($row = $db->fetch_assoc($request))
$topics[$row['id_topic']] = $row;
$db->free_result($request);
// Did we find anything? If not, bail.
if (empty($topics))
return array();
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = $db->query('substring', '
SELECT
ml.poster_time, mf.subject, ml.id_member, ml.id_msg, t.id_topic, t.num_replies, t.num_views, mg.online_color,
IFNULL(mem.real_name, ml.poster_name) AS poster_name, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= ml.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . ', SUBSTRING(ml.body, 1, 384) AS body, ml.smileys_enabled, ml.icon
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)' . (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})' : '') . '
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
WHERE t.id_topic IN ({array_int:topic_list})
ORDER BY t.id_last_msg DESC',
array(
'current_member' => $user_info['id'],
'topic_list' => array_keys($topics),
)
);
$posts = array();
while ($row = $db->fetch_assoc($request))
{
$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br />' => ' ')));
if (Util::strlen($row['body']) > 128)
$row['body'] = Util::substr($row['body'], 0, 128) . '...';
// Censor the subject.
censorText($row['subject']);
censorText($row['body']);
if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
// Build the array.
$posts[] = 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>'
),
'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>',
// Retained for compatibility - is technically incorrect!
'new' => !empty($row['is_read']),
'is_new' => empty($row['is_read']),
'new_from' => $row['new_from'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.png" style="vertical-align: middle;" alt="' . $row['icon'] . '" />',
);
}
$db->free_result($request);
// 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"><span class="new_posts">' . $txt['new'] . '</span></a>', '
</td>
<td class="righttext">
', $post['time'], '
</td>
</tr>';
echo '
</table>';
}
/**
* Show the top poster's name and profile link.
*
* @param int $topNumber
* @param string $output_method = 'echo'
*/
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
* @param string $output_method = 'echo'
*/
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 class="lefttext">', $txt['board'], '</th>
<th class="righttext">', $txt['board_topics'], '</th>
<th class="righttext">', $txt['posts'], '</th>
</tr>';
foreach ($boards as $board)
echo '
<tr>
<td>', $board['new'] ? ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a> ' : '', $board['link'], '</td>
<td class="righttext">', $board['num_topics'], '</td>
<td class="righttext">', $board['num_posts'], '</td>
</tr>';
echo '
</table>';
}
/**
* Shows the top topics.
*
* @param string $type
* @param 10 $num_topics
* @param string $output_method = 'echo'
*/
function ssi_topTopics($type = 'replies', $num_topics = 10, $output_method = 'echo')
{
global $txt, $scripturl;
require_once(SUBSDIR . '/Stats.subs.php');
if (function_exists('topTopic' . ucfirst($type)))
$function = 'topTopic' . ucfirst($type);
else
$function = 'topTopicReplies';
$topics = $function($num_topics);
foreach ($topics as $topic_id => $row)
{
censorText($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="views">', $txt['views'], '</th>
<th class="num_replies">', $txt['replies'], '</th>
</tr>';
foreach ($topics as $topic)
echo '
<tr>
<td class="link">
', $topic['link'], '
</td>
<td class="views">', $topic['num_views'], '</td>
<td class="num_replies">', $topic['num_replies'], '</td>
</tr>';
echo '
</table>';
}
/**
* Shows the top topics, by replies.
*
* @param int $num_topics = 10
* @param string $output_method = 'echo'
*/
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
* @param string $output_method = 'echo'
*/
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, out latest member.
*
* @param string $output_method = 'echo'
*/
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 - if type set to 'day' will only change once a day!
*
* @param string $random_type = ''
* @param string $output_method = 'echo'
*/
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()
* @param string $output_method = 'echo'
*/
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 a specific member.
*
* @param null $group_id
* @param string $output_method = 'echo'
*/
function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo')
{
if ($group_id === null)
return;
return ssi_queryMembers('group_list', is_array($group_id) ? $group_id : array($group_id), '', 'real_name', $output_method);
}
/**
* Fetch some member data!
*
* @param string|null $query_where
* @param string|string[] $query_where_params
* @param string $query_limit
* @param string $query_order
* @param string $output_method
*/
function ssi_queryMembers($query_where = null, $query_where_params = array(), $query_limit = '', $query_order = 'id_member DESC', $output_method = 'echo')
{
global $memberContext;
if ($query_where === null)
return;
require_once(SUBSDIR . '/Members.subs.php');
$members_data = retrieveMemberData(array(
$query_where => $query_where_params,
'limit' => !empty($query_limit) ? (int) $query_limit : 10,
'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.
loadMemberData($members);
// Draw the table!
if ($output_method == 'echo')
echo '
<table class="ssi_table">';
$query_members = array();
foreach ($members as $member)
{
// Load their context data.
if (!loadMemberContext($member))
continue;
// Store this member's information.
$query_members[$member] = $memberContext[$member];
// Only do something if we're echo'ing.
if ($output_method == 'echo')
echo '
<tr>
<td class="centertext">
', $query_members[$member]['link'], '
<br />', $query_members[$member]['blurb'], '
<br />', $query_members[$member]['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
*/
function ssi_boardStats($output_method = 'echo')
{
global $txt, $scripturl, $modSettings;
if (!allowedTo('view_stats'))
return;
require_once(SUBSDIR . '/Boards.subs.php');
require_once(SUBSDIR . '/Stats.subs.php');
$totals = array(
'members' => $modSettings['totalMembers'],
'posts' => $modSettings['totalMessages'],
'topics' => $modSettings['totalTopics'],
'boards' => countBoards(),
'categories' => numCategories(),
);
if ($output_method != 'echo')
return $totals;
echo '
', $txt['total_members'], ': <a href="', $scripturl . '?action=memberlist">', comma_format($totals['members']), '</a><br />
', $txt['total_posts'], ': ', comma_format($totals['posts']), '<br />
', $txt['total_topics'], ': ', comma_format($totals['topics']), ' <br />
', $txt['total_cats'], ': ', comma_format($totals['categories']), '<br />
', $txt['total_boards'], ': ', comma_format($totals['boards']);
}
/**
* Shows a list of online users:
* YY Guests, ZZ Users and then a list...
*
* @param string $output_method
*/
function ssi_whosOnline($output_method = 'echo')
{
global $user_info, $txt, $settings;
require_once(SUBSDIR . '/MembersOnline.subs.php');
$membersOnlineOptions = array(
'show_hidden' => allowedTo('moderate_forum'),
);
$return = getMembersOnlineStats($membersOnlineOptions);
// Add some redundancy for backwards compatibility reasons.
if ($output_method != 'echo')
return $return + array(
'users' => $return['users_online'],
'guests' => $return['num_guests'],
'hidden' => $return['num_users_hidden'],
'buddies' => $return['num_buddies'],
'num_users' => $return['num_users_online'],
'total_users' => $return['num_users_online'] + $return['num_guests'] + $return['num_spiders'],
);
echo '
', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
$bracketList = array();
if (!empty($user_info['buddies']))
$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
if (!empty($return['num_spiders']))
$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
if (!empty($return['num_users_hidden']))
$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
if (!empty($bracketList))
echo ' (' . implode(', ', $bracketList) . ')';
echo '<br />
', implode(', ', $return['list_users_online']);
// Showing membergroups?
if (!empty($settings['show_group_key']) && !empty($return['membergroups']))
echo '<br />
[' . implode('] [', $return['membergroups']) . ']';
}
/**
* Just like whosOnline except it also logs the online presence.
*
* @param string $output_method
*/
function ssi_logOnline($output_method = 'echo')
{
writeLog();
if ($output_method != 'echo')
return ssi_whosOnline($output_method);
else
ssi_whosOnline($output_method);
}
/**
* Shows a login box.
*
* @param string $redirect_to = ''
* @param string $output_method = 'echo'
*/
function ssi_login($redirect_to = '', $output_method = 'echo')
{
global $scripturl, $txt, $user_info, $modSettings, $context, $settings;
if ($redirect_to != '')
$_SESSION['login_url'] = $redirect_to;
if ($output_method != 'echo' || !$user_info['is_guest'])
return $user_info['is_guest'];
$context['default_username'] = isset($_POST['user']) ? preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($_POST['user'], ENT_COMPAT, 'UTF-8')) : '';
echo '
<script src="', $settings['default_theme_url'], '/scripts/sha256.js"></script>
<form action="', $scripturl, '?action=login2" name="frmLogin" id="frmLogin" method="post" accept-charset="UTF-8" ', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
<div class="login">
<div class="roundframe">';
// Did they make a mistake last time?
if (!empty($context['login_errors']))
echo '
<p class="errorbox">', implode('<br />', $context['login_errors']), '</p><br />';
// Or perhaps there's some special description for this time?
if (isset($context['description']))
echo '
<p class="description">', $context['description'], '</p>';
// Now just get the basic information - username, password, etc.
echo '
<dl>
<dt>', $txt['username'], ':</dt>
<dd><input type="text" name="user" size="20" value="', $context['default_username'], '" class="input_text" autofocus="autofocus" placeholder="', $txt['username'], '" /></dd>
<dt>', $txt['password'], ':</dt>
<dd><input type="password" name="passwrd" value="" size="20" class="input_password" placeholder="', $txt['password'], '" /></dd>
</dl>';
if (!empty($modSettings['enableOpenID']))
echo '<p><strong>—', $txt['or'], '—</strong></p>
<dl>
<dt>', $txt['openid'], ':</dt>
<dd><input type="text" name="openid_identifier" class="input_text openid_login" size="17" /> <a href="', $scripturl, '?action=quickhelp;help=register_openid" onclick="return reqOverlayDiv(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" class="centericon" /></a></dd>
</dl>';
echo '
<p><input type="submit" value="', $txt['login'], '" class="button_submit" /></p>
<p class="smalltext"><a href="', $scripturl, '?action=reminder">', $txt['forgot_your_password'], '</a></p>
<input type="hidden" name="hash_passwrd" value="" />
<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
</div>
</div>
</form>';
// Focus on the correct input - username or password.
echo '
<script><!-- // --><![CDATA[
document.forms.frmLogin.', isset($context['default_username']) && $context['default_username'] != '' ? 'passwrd' : 'user', '.focus();
// ]]></script>';
}
/**
* Show the most-voted-in poll.
*
* @param string $output_method = 'echo'
*/
function ssi_topPoll($output_method = 'echo')
{
// Just use recentPoll, no need to duplicate code...
return ssi_recentPoll(true, $output_method);
}
/**
* Show the most recently posted poll.
*
* @param bool $topPollInstead = false
* @param string $output_method = string
*/
function ssi_recentPoll($topPollInstead = false, $output_method = 'echo')
{
global $txt, $settings, $boardurl, $user_info, $context, $modSettings;
$boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote'));
if (empty($boardsAllowed))
return array();
$db = database();
$request = $db->query('', '
SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time
FROM {db_prefix}polls AS p
INNER JOIN {db_prefix}topics AS t ON (t.id_poll = p.id_poll' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ')
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)' . ($topPollInstead ? '
INNER JOIN {db_prefix}poll_choices AS pc ON (pc.id_poll = p.id_poll)' : '') . '