forked from kestasjk/webDiplomacy
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.php
executable file
·870 lines (728 loc) · 29.8 KB
/
index.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
<?php
/*
Copyright (C) 2004-2010 Kestas J. Kuliukas
This file is part of webDiplomacy.
webDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
webDiplomacy 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.
You should have received a copy of the GNU Affero General Public License
along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @package Base
*/
require_once('header.php');
require_once(l_r('lib/message.php'));
require_once(l_r('objects/game.php'));
require_once(l_r('gamepanel/gamehome.php'));
/*
* A field
*
* add(field, index)
* compare(field1, field2) -> 1 if aligned, 0 if not
*
*/
libHTML::starthtml(l_t('Home'));
if( !isset($_SESSION['lastSeenHome']) || $_SESSION['lastSeenHome'] < $User->timeLastSessionEnded )
{
$_SESSION['lastSeenHome']=$User->timeLastSessionEnded;
}
global $DB;
$gameToggleID = 0;
if(isset($_POST['submit']))
{
if(isset($_POST['gameToggleName']))
{
$gameToggleID = (int)$_POST['gameToggleName'];
}
if ($User->type['User'] and $gameToggleID > 0)
{
libAuth::formToken_Valid();
$noticesStatus = 5;
list($noticesStatus) = $DB->sql_row("SELECT hideNotifications FROM wD_Members WHERE userID =".$User->id." and gameID =".$gameToggleID);
if ($noticesStatus == 0)
{
$DB->sql_put("UPDATE wD_Members SET hideNotifications = 1 WHERE userID =".$User->id." and gameID =".$gameToggleID);
}
else if ($noticesStatus == 1)
{
$DB->sql_put("UPDATE wD_Members SET hideNotifications = 0 WHERE userID =".$User->id." and gameID =".$gameToggleID);
}
}
}
class libHome
{
static public function getType($type=false, $limit=35)
{
global $DB, $User;
$notices=array();
$tabl=$DB->sql_tabl("SELECT n.*
FROM wD_Notices n
LEFT JOIN wD_Games g on g.name = n.linkName and n.type = 'Game'
LEFT JOIN wD_Members m on m.gameID = g.id and n.type = 'Game' and m.userID = ".$User->id."
WHERE (m.hideNotifications is null or m.hideNotifications = 0) and n.toUserID=".$User->id.($type ? " AND n.type='".$type."'" : '')."
ORDER BY n.timeSent DESC ".($limit?'LIMIT '.$limit:''));
while($hash=$DB->tabl_hash($tabl))
{
$notices[] = new notice($hash);
}
return $notices;
}
public static function PMs()
{
$pms = self::getType('PM', 10);
$buf = '';
foreach($pms as $pm)
{
$buf .= $pm->html();
}
return $buf;
}
public static function Game()
{
global $User;
$pms = self::getType('Game');
if(!count($pms))
{
print '<div class="hr"></div>';
print '<p class="notice">'.l_t('No game notices found.').'</p>';
return;
}
print '<div class="hr"></div>';
foreach($pms as $pm)
{
print $pm->viewedSplitter();
print $pm->html();
}
}
public static function NoticePMs()
{
global $User;
try
{
$message=notice::sendPMs();
}
catch(Exception $e)
{
$message=$e->getMessage();
}
if ( $message )
print '<p class="notice">'.$message.'</p>';
$pms = self::getType('PM', 200);
if(!count($pms))
{
print '<div class="hr"></div>';
print '<p class="notice">'.l_t('No private messages found; you can send them to other people on their profile page.').'</p>';
return;
}
print '<div class="hr"></div>';
foreach($pms as $pm)
{
print $pm->viewedSplitter();
print $pm->html();
}
}
public static function NoticeGame()
{
global $User;
$pms = self::getType('Game');
if(!count($pms))
{
print '<div class="hr"></div>';
print '<p class="notice">'.l_t('No game notices found; try browsing the <a href="gamelistings.php">game listings</a>, '.
'or <a href="gamecreate.php">create your own</a> game.').'</p>';
return;
}
print '<div class="hr"></div>';
foreach($pms as $pm)
{
print $pm->viewedSplitter();
print $pm->html();
}
}
public static function Notice()
{
global $User;
$pms = self::getType();
if(!count($pms))
{
print '<div class="hr"></div>';
print '<p class="notice">'.l_t('No notices found.').'</p>';
return;
}
print '<div class="hr"></div>';
foreach($pms as $pm)
{
print $pm->viewedSplitter();
print $pm->html();
}
}
static function topUsers()
{
global $DB;
$rows=array();
$tabl = $DB->sql_tabl("SELECT id, username, points FROM wD_Users
order BY points DESC LIMIT 10");
$i=1;
while(list($userID,$username,$points)=$DB->tabl_row($tabl))
{
$rows[] = '#'.$i.': <a href="profile.php?userID='.$userID.'">'.$username.'</a> ('.$points.libHTML::points().')';
$i++;
}
return $rows;
}
static function statsGlobalGame()
{
global $Misc;
$stats=array(
'Starting'=>$Misc->GamesNew,
'Joinable'=>$Misc->GamesOpen,
'Active'=>$Misc->GamesActive,
'Finished'=>$Misc->GamesFinished
);
return $stats;
}
static function statsGlobalUser()
{
global $Misc;
$stats=array(
'Logged on'=>$Misc->OnlinePlayers,
'Playing'=>$Misc->ActivePlayers,
'Registered'=>$Misc->TotalPlayers
);
if( $stats['Logged on'] <= 1 ) unset($stats['Logged on']);
if( $stats['Playing'] < 25 ) unset($stats['Playing']);
return $stats;
}
static function globalInfo()
{
$userStats = self::statsGlobalUser();
$gameStats = self::statsGlobalGame();
$buf='<strong>'.l_t('Users:').'</strong> ';
$first=true;
foreach($userStats as $name => $val)
{
if( $first ) $first=false; else $buf .= ' - ';
$buf .= l_t($name).':<strong>'.$val.'</strong>';
}
$buf .= '<br /><strong>'.l_t('Games:').'</strong> ';
$first=true;
foreach($gameStats as $name => $val)
{
if( $first ) $first=false; else $buf .= ' - ';
$buf .= l_t($name).':<strong>'.$val.'</strong>';
}
return $buf;
}
static public function gameWatchBlock ()
{
global $User, $DB;
$tabl=$DB->sql_tabl("SELECT g.* FROM wD_Games g
INNER JOIN wD_WatchedGames w ON ( w.userID = ".$User->id." AND w.gameID = g.id )
WHERE NOT g.phase = 'Finished'
ORDER BY g.processStatus ASC, g.processTime ASC");
$buf = '';
$count=0;
while($game=$DB->tabl_hash($tabl))
{
$count++;
$Variant=libVariant::loadFromVariantID($game['variantID']);
$Game=$Variant->panelGameHome($game);
$buf .= '<div class="hr"></div>';
$buf .= $Game->summary();
}
if($count==0)
{
$buf .= '<div class="hr"></div>';
$buf .= '<div><p class="notice">'.l_t('You\'re not spectating any games.').'<br />
'.l_t('Click the \'spectate\' button on an existing game to add games to your list of spectated games.').
'</p></div>';
}
return $buf;
}
static public function upcomingLiveGames ()
{
global $User, $DB;
if ($User->options->value['displayUpcomingLive'] == 'No') return '';
$tabl=$DB->sql_tabl("SELECT g.* FROM wD_Games g
WHERE (g.phase = 'Pre-game' OR (g.phase in ('Diplomacy','Retreats','Builds') and g.minimumBet is not null and g.gameOver = 'No')) AND g.phaseMinutes < 60 AND g.password IS NULL
ORDER BY g.processStatus ASC, g.processTime ASC LIMIT 3");
$buf = '';
$count=0;
while($game=$DB->tabl_hash($tabl))
{
$count++;
$Variant=libVariant::loadFromVariantID($game['variantID']);
$Game=$Variant->panelGameHome($game);
$buf .= '<div class="hr"></div>';
$buf .= $Game->summary();
}
return $buf;
}
static public function gameNotifyBlock ()
{
global $User, $DB;
// Load all active games
$tabl=$DB->sql_tabl("SELECT g.* FROM wD_Games g
INNER JOIN wD_Members m ON ( (m.userID = ".$User->id." OR g.directorUserID = ".$User->id.") AND m.gameID = g.id )
WHERE NOT g.phase = 'Finished' and m.status <> 'Defeated'
GROUP BY g.id
ORDER BY g.processStatus ASC, g.processTime ASC");
$buf = '';
$bufDef = $bufPause = $bufPregame = '';
$count=0;
while($game=$DB->tabl_hash($tabl))
{
$count++;
$Variant=libVariant::loadFromVariantID($game['variantID']);
$Game=$Variant->panelGameHome($game);
if (isset($Game->Members->ByUserID[$User->id]) && $Game->Members->ByUserID[$User->id]->status == 'Defeated')
$bufDef .= '<div class="hr"></div>'.$Game->summary();
elseif ($Game->processStatus == 'Paused')
$bufPause .= '<div class="hr"></div>'.$Game->summary();
elseif ($Game->phase == 'Pre-game')
$bufPregame .= '<div class="hr"></div>'.$Game->summary();
else
$buf .= '<div class="hr"></div>' . $Game->summary();
}
if ($bufPause != '') $buf .= $bufPause;
if ($bufPregame != '') $buf .= $bufPregame;
if ($bufDef != '') $buf .= '<div class="hr"></div><div><p class="notice"><br />'.l_t('Defeated:').'</p></div>'.$bufDef;
if($count==0)
{
$buf .= '<div class="hr"></div>';
$buf .= '<div class="bottomborder"><p class="notice">'.l_t('You have not joined any games!').'<br />
'.l_t('Access the <a href="gamelistings.php?tab=">Games</a> '.
'link above to find games you can join, or start a '.
'<a href="gamecreate.php">New game</a> yourself.</a>').'</p></div>';
}
elseif ( $count == 1 && $User->points > 5 )
{
$buf .= '<div class="hr"></div>';
$buf .= '<div class="bottomborder"><p class="notice">'.l_t('You can join as many games as you '.
'have the points to join.').' </a></p></div>';
}
return $buf;
}
static public function gameDefeatedNotifyBlock ()
{
global $User, $DB;
$tabl=$DB->sql_tabl("SELECT g.* FROM wD_Games g
INNER JOIN wD_Members m ON ( m.userID = ".$User->id." AND m.gameID = g.id )
WHERE NOT g.phase = 'Finished' and m.status = 'Defeated'
ORDER BY g.processStatus ASC, g.processTime ASC");
$buf = '';
$count=0;
while($game=$DB->tabl_hash($tabl))
{
$count++;
$Variant=libVariant::loadFromVariantID($game['variantID']);
$Game=$Variant->panelGameHome($game);
$buf .= '<div class="hr"></div>';
$buf .= $Game->summary();
}
if($count==0)
{
$buf .= '<div class="hr"></div>';
$buf .= '<div class="bottomborder"><p class="notice"> You are not defeated in any active games, good job!<br />
</p></div>';
}
elseif ( $count == 1 && $User->points > 5 )
{
$buf .= '<div class="hr"></div>';
$buf .= '<div class="bottomborder"><p class="notice">'.l_t('You can join as many games as you '.
'have the points to join.').' </a></p></div>';
}
return $buf;
}
static function forumNew()
{
// Select by id, prints replies and new threads
global $DB, $Misc, $User;
$tabl = $DB->sql_tabl("
SELECT m.id as postID, t.id as threadID, m.type, m.timeSent, IF(t.replies IS NULL,m.replies,t.replies) as replies,
IF(t.subject IS NULL,m.subject,t.subject) as subject,
m.anon,
u.id as userID, u.username, u.vpoints, IF(s.userID IS NULL,0,0) as online, u.type as userType,
SUBSTRING(m.message,1,100) as message, m.latestReplySent, t.fromUserID as threadStarterUserID
FROM wD_ForumMessages m
INNER JOIN wD_Users u ON ( m.fromUserID = u.id )
LEFT JOIN wD_Sessions s ON ( m.fromUserID = s.userID )
LEFT JOIN wD_ForumMessages t ON ( m.toID = t.id AND t.type = 'ThreadStart' AND m.type = 'ThreadReply' )
ORDER BY m.timeSent DESC
LIMIT 50");
$oldThreads=0;
$threadCount=0;
$threadIDs = array();
$threads = array();
while(list(
$postID, $threadID, $type, $timeSent, $replies, $subject,
$anon,
$userID, $username, $points, $online, $userType, $message, $latestReplySent,$threadStarterUserID
) = $DB->tabl_row($tabl))
{
// Anonymize the forum posts on the home-screen too
if ($anon == 'Yes')
{
$username = 'Anon';
$userID = 0;
$points = '??';
$userType = 'User';
}
// End anonymizer
$threadCount++;
if( $threadID )
$iconMessage=libHTML::forumMessage($threadID, $postID);
else
$iconMessage=libHTML::forumMessage($postID, $postID);
if ( $type == 'ThreadStart' ) $threadID = $postID;
if( !isset($threads[$threadID]) )
{
if(strlen($subject)>30) $subject = substr($subject,0,40).'...';
$threadIDs[] = $threadID;
$threads[$threadID] = array('subject'=>$subject, 'replies'=>$replies, 'posts'=>array(),'threadStarterUserID'=>$threadStarterUserID);
}
$message=Message::refilterHTML($message);
if( strlen($message) >= 50 ) $message = substr($message,0,50).'...';
$message = '<div class="message-contents threadID'.$threadID.'" fromUserID="'.$userID.'">'.$message.'</div>';
$threads[$threadID]['posts'][] = array(
'iconMessage'=>$iconMessage,'userID'=>$userID, 'username'=>$username,
'message'=>$message,'points'=>$points, 'online'=>$online, 'userType'=>$userType, 'timeSent'=>$timeSent
);
}
$buf = '';
$threadCount=0;
foreach($threadIDs as $threadID)
{
$data = $threads[$threadID];
$buf .= '<div class="hr userID'.$threads[$threadID]['threadStarterUserID'].' threadID'.$threadID.'"></div>';
$buf .= '<div class="homeForumGroupNew homeForumAlt'.($threadCount%2 + 1).
' userID'.$threads[$threadID]['threadStarterUserID'].' threadID'.$threadID.'">
<div class="homeForumSubject homeForumTopBorder">'.libHTML::forumParticipated($threadID).' '.$data['subject'].'</div> ';
if( count($data['posts']) < $data['replies'])
{
$buf .= '<div class="homeForumPost homeForumMessage homeForumPostAlt'.libHTML::alternate().' ">
...</div>';
}
$data['posts'] = array_reverse($data['posts']);
foreach($data['posts'] as $post)
{
$buf .= '<div class="homeForumPost homeForumPostAlt'.libHTML::alternate().' userID'.$post['userID'].'">
<div class="homeForumPostTime">'.libTime::text($post['timeSent']).' '.$post['iconMessage'].'</div>
<a href="profile.php?userID='.$post['userID'].'" class="light">'.$post['username'].'</a>
'.' ('.$post['points'].libHTML::vpoints().
User::typeIcon($post['userType']).')
<div style="clear:both"></div>
<div class="homeForumMessage">'.$post['message'].'</div>
</div>';
}
$buf .= '<div class="homeForumLink">
<div class="homeForumReplies">'.l_t('%s replies','<strong>'.$data['replies'].'</strong>').'</div>
<a href="forum.php?threadID='.$threadID.'#'.$threadID.'">'.l_t('Open').'</a>
</div>
</div>';
}
if( $buf )
{
// First remove the mod-alerts from the home-forum-view.
$buf = str_replace('<img src="images/icons/alert_minor.png" alt="(!)" title="ModAlert" />','',$buf);
// Than return the buffer.
return $buf;
}
else
{
return '<div class="homeNoActivity">'.l_t('No forum posts found, why not '.
'<a href="forum.php?postboxopen=1#postbox" class="light">start one</a>?');
}
}
static function forumBlock()
{
$buf = '<div class="homeHeader">'.l_t('Forum').'</div>';
$forumNew=libHome::forumNew();
$buf .= '<table><tr><td>'.implode('</td></tr><tr><td>',$forumNew).'</td></tr></table>';
return $buf;
}
static function forumBlockExtern()
{
$buf = '<div class="homeHeader">'.l_t('Forum').'</div>';
$forumNew=libHome::forumNewExtern();
$buf .= '<table><tr><td>'.implode('</td></tr><tr><td>',$forumNew).'</td></tr></table>';
return $buf;
}
static function forumNewExtern()
{
// Select by id, prints replies and new threads
global $DB, $Misc;
$tabl = $DB->sql_tabl("SELECT t.forum_id, f.forum_name, t.topic_id, t.topic_title, t.topic_time, t.topic_views, t.topic_posts_approved,
u1.webdip_user_id as topic_poster_webdip, t.topic_poster, t.topic_first_poster_name, t.topic_first_poster_colour,
t.topic_last_post_id, t.topic_last_post_time,
u2.webdip_user_id as topic_last_poster_webdip, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour,
p.post_id, p.post_text
FROM phpbb_topics t
INNER JOIN phpbb_posts p ON p.post_id = t.topic_last_post_id
INNER JOIN phpbb_forums f ON f.forum_id = t.forum_id
INNER JOIN phpbb_users u1 ON u1.user_id = t.topic_poster
INNER JOIN phpbb_users u2 ON u2.user_id = t.topic_last_poster_id
WHERE t.topic_visibility = 1 and f.forum_name <> 'Politics' and t.topic_title not like '%HIDDEN%'
ORDER BY t.topic_last_post_time DESC
LIMIT 20");
$buf = '';
while($t = $DB->tabl_hash($tabl))
{
$buf .= '<div class="hr"></div>';
$urlForum = '/contrib/phpBB3/viewforum.php?f='.$t['forum_id'];
$urlThread = '/contrib/phpBB3/viewtopic.php?f='.$t['forum_id'].'&t='.$t['topic_id'];
$urlPost = '/contrib/phpBB3/viewtopic.php?f='.$t['forum_id'].'&p='.$t['post_id'].'#p'.$t['post_id'];
//topic_poster_webdip // ID
//topic_last_poster_webdip // ID
$alt = libHTML::alternate();
$buf .= '<div class="homeForumGroupNew homeForumAlt'.$alt.'">';
$buf .= '
<div class="homeForumSubject" >';
//$buf .= '<div style="float:right"><img src="http://127.0.0.1/images/historyicons/external.png" width="10" height="10"></div>';
$buf .= '<span style=\'font-size:90%\'>'.($t['topic_posts_approved']>1?'Re: ':'New: ').'</span>'
.'<a href="'.$urlThread.'" style=\'font-size:110%\'>'.$t['topic_title'].'</a>';
$buf .= '<div style="clear:both"></div>';
$buf .= '<div class="homeForumPostTime" style="float:right"><em>'.libTime::text($t['topic_time']).'</em></div>';
$buf .= '<span style=\'font-size:90%\'>';
$buf .= 'Thread:</span> <a href="profile.php?userID='.$t['topic_poster_webdip'].'" class="light">'.$t['topic_first_poster_name'].'</a> ';
$buf .= '<div style="clear:both"></div></div>';
$buf .= '<div class="homeForumPost homeForumPostAlt'.$alt.'">';
if( $t['topic_posts_approved']>1 )
{
$buf .= '<div class="" style="margin-bottom:5px;margin-left:3px; margin-right:3px;">';
$buf .= '<div class="homeForumPostTime" style="float:right;font-weight:bold"><em>'.libTime::text($t['topic_last_post_time']).'</em></div>';
$buf .= '<span class="home-forum-latest">';
$buf .= 'Latest:</span> <a href="profile.php?userID='.$t['topic_last_poster_webdip'].'" class="light">'.$t['topic_last_poster_name'].'</a> '
.'</div>';
}
$post = $DB->msg_escape(preg_replace("/\[[^\]]+\]/","",preg_replace("/<[^>]+>/","",$t['post_text'])));
$post = str_replace("\\'","'", $post);
$post = substr($post, 0, 75);
if(strlen($post) > 45) $post .= '...';
$buf .= '<div><span style="font-style:italic">"'.$post.'"</span>';
$buf .= '<div style="float:right"><a href="'.$urlPost.'">Open</a></div>';
$buf .= '<div style="clear:both"></div>';
$buf .= '</div>';
$buf .= '</div>';
$buf .= '<div class="" style="margin-bottom:5px;margin-left:3px; margin-right:3px;">';
$buf .= '<div style="margin-left:3px; margin-right:3px; font-size:90%">';
$buf .= '<div style="float:right">';
$buf .= l_t('<span class="forum-preview-span">%s replies, </span>','<strong>'.($t['topic_posts_approved']-1).'</strong>');
$buf .= l_t('<span class="forum-preview-span">%s views</span>','<strong style=\'content: "\f14c"\'>'.($t['topic_views']-1).'</strong>');
$buf .= '</div>';
$buf .= '<span class="forum-preview-span">»
<a href="'.$urlForum.'">'.$t['forum_name'].'</a></span>
</div>';
$buf .= '</div>';
$buf .= '</div>';
}
if( $buf )
{
return $buf;
}
else
{
return '<div class="homeNoActivity">'.l_t('No forum posts found, why not start one?');
}
}
}
if( !$User->type['User'] )
{
print '<div class = "introToDiplomacy"><div class="content-notice" style="text-align:center">'.libHome::globalInfo().'</div></div>';
print libHTML::pageTitle(l_t('Welcome to vDiplomacy!'),l_t('A multiplayer web implementation of the popular turn-based strategy game Diplomacy.'));
//print '<div class="content">';
?>
<p style="text-align: center;"><img
src="<?php print l_s('images/vmap.png'); ?>" alt="<?php print l_t('The map'); ?>"
title="<?php print l_t('A vDiplomacy map'); ?>" /></p>
<div class = "introToDiplomacy_show"><p class="welcome"><?php print l_t('<em> "Luck plays no part in Diplomacy. Cunning and
cleverness, honesty and perfectly-timed betrayal are the tools needed to
outwit your fellow players. The most skillful negotiator will climb to
victory over the backs of both enemies and friends.<br />
<br />
Who do you trust?"<br />
(<a href="https://avalonhill.wizards.com/games/diplomacy">Avalon Hill</a>)</em>'); ?></p>
<?php
print '</div></div>';
require_once(l_r('locales/English/intro.php'));
print '</div>';
}
elseif( isset($_REQUEST['notices']) )
{
$User->clearNotification('PrivateMessage');
print '<div class="content"><a href="index.php" class="light">< '.l_t('Back').'</a></div>';
print '<div class="content-bare content-home-header">';
print '<table class="homeTable"><tr>';
notice::$noticesPage=true;
if( !isset(Config::$customForumURL) )
{
print '<td class="homeNoticesPMs">';
print '<div class="homeHeader">'.l_t('Private messages').'</a></div>';
print libHome::NoticePMs();
print '</td>';
print '<td class="homeSplit"></td>';
}
print '<td class="homeNoticesGame">';
print '<div class="homeHeader">'.l_t('Game messages').'</a></div>';
print libHome::NoticeGame();
print '</td>';
print '</tr></table>';
print '</div>';
print '</div>';
}
else
{
print '<div class="content-bare content-home-header">';// content-follow-on">';
// home page tutorial
if (isset($_COOKIE['wD-Tutorial-Index']))
{
$tutorialMessage = l_t(
'To help you become familiar with webDiplomacy, we prepared a few brief presentations
for you that you will find on different pages of the site. You will only see these once apiece, but if you
ever want to review what you read, you can check out our <a href="faq.php" target="_blank">Frequently Asked Questions</a>.
If you are new to the game of Diplomacy, we also recommend our <a href="intro.php" target="_blank">Intro to Diplomacy</a>
and our <a href="rules.php" target="_blank">site rules</a>.
<br><br>
Even if you are familiar with the game of Diplomacy, webDiplomacy does some things a bit differently than other sites or
face to face Diplomacy communities. We developed our own scoring system, the Ghost Ratings, which you can read about <a
href="https://sites.google.com/view/webdipinfo/ghost-ratings" target="_blank">here</a>, in addition to points that you can
use to cover the bet to enter games. We also developed a reliability rating to gauge how committed and reliable a player
is to entering orders prior to deadlines. Whether you decide to be a casual Diplomacy player or a very dedicated player,
it is important to enter orders prior to the deadlines so that the game is fair and balanced for everyone, and so that
games are not delayed while players are replaced. Some games require a minimum reliability rating, so it is important to
keep it high! You can read more about reliability rating <a href="profile.php?userID='.$User->id.'"
target="_blank">here</a>.
<br><br>
You are currently on the home screen. This is the landing page that you will see when you log into the site. While you can
access any Diplomacy games you are playing from any page on the site when you have orders to submit or a message to read,
you can see all of your games in one place here. When you join games, they will appear on the right side of the screen
under "My Games." Since you are not in any games right now, it will be empty. You can also see games that you "spectate" here,
which are games that you are not playing in but just want to watch, as well as tournaments that you join when you are more experienced.
In the center of the page, you will see if a phase has changed in any of your games, a notice if you were defeated, drew with your opponents,
or won a game you are in, or miss a phase deadline and need to catch up. On the left side of the page, you can see upcoming live games.
Live games are games that finish quickly, with phase lengths ranging between 5 and 30 minutes. Below upcoming live games, you can see the
latest posts on our forum, a place you can go to ask questions, find high quality games with other players, read Diplomacy advice from
some of the best players in the world, join tournaments, and play some forum games.
<br><br>
To reach out to the moderators for help with your account, you can click <a href="contactUsDirect.php" target="_blank">here</a>.
Thank you for joining the site, and have fun!'
);
libHTML::help('Home', $tutorialMessage);
unset($_COOKIE['wD-Tutorial-Index']);
setcookie('wD-Tutorial-Index', '', time()-3600);
}
print '<table class="homeTable"><tr>';
print '<td class="homeMessages">';
$liveGames = libHome::upcomingLiveGames();
if ($liveGames != '')
{
print '<div class="homeHeader">'.l_t('Joinable live games').' <a href="gamelistings.php?gamelistType=Search&phaseLengthMax=30m&messageNorm=Yes&messagePub=Yes&messageNon=Yes&messageRule=Yes&Submit=Search#results">'.libHTML::link().'</a></div>';
print $liveGames;
}
if( isset(Config::$customForumURL) )
{
print '<div class="homeHeader">'.l_t('Forum').' <a href="/contrib/phpBB3/">'.libHTML::link().'</a></div>';
if( file_exists(libCache::dirName('forum').'/home-forum.html') )
{
print file_get_contents(libCache::dirName('forum').'/home-forum.html');
$diff = (time() - filemtime(libCache::dirName('forum').'/home-forum.html'));
if( $diff > 60*5 )
{
unlink(libCache::dirName('forum').'/home-forum.html');
}
}
else
{
$buf_home_forum=libHome::forumNewExtern();
file_put_contents(libCache::dirName('forum').'/home-forum.html', $buf_home_forum);
print $buf_home_forum;
}
}
else
{
print '<div class="homeHeader">'.l_t('Forum').' <a href="forum.php">'.libHTML::link().'</a></div>';
if( file_exists(libCache::dirName('forum').'/home-forum.html') )
print file_get_contents(libCache::dirName('forum').'/home-forum.html');
else
{
$buf_home_forum=libHome::forumNew();
file_put_contents(libCache::dirName('forum').'/home-forum.html', $buf_home_forum);
print $buf_home_forum;
}
}
print '</td>';
print '<td class="homeSplit"></td>';
print '<td class="homeGameNotices">';
print '<div class="homeHeader">'.l_t('Notices').' <a href="index.php?notices=on">'.libHTML::link().'</a></div>';
print libHome::Notice();
print '</td>';
print '<td class="homeSplit"></td>';
print '<td class="homeGamesStats">';
print '<div class="homeHeader">'.l_t('My games').' <a href="gamelistings.php?page=1&gamelistType=My games">'.libHTML::link().'</a></div>';
print libHome::gameNotifyBlock();
print '<div class="homeHeader">'.l_t('Defeated games').'</div>';
print libHome::gameDefeatedNotifyBlock();
print '<div class="homeHeader">'.l_t('Spectated games').'</div>';
print libHome::gameWatchBlock();
$sql = "select distinct t.id, t.name, t.status from wD_Tournaments t inner join wD_TournamentParticipants s on s.tournamentID = t.id
where t.status <> 'Finished' and ( s.userID =".$User->id." or t.directorID = ".$User->id." or t.coDirectorID = ".$User->id.")";
$sqlCounter = "select count(distinct t.id) from wD_Tournaments t inner join wD_TournamentParticipants s on s.tournamentID = t.id
where t.status <> 'Finished' and ( s.userID =".$User->id." or t.directorID = ".$User->id." or t.coDirectorID = ".$User->id.")";
$tablChecked = $DB->sql_tabl($sql);
list($resultsParticipating) = $DB->sql_row($sqlCounter);
if ($resultsParticipating > 0)
{
print '<div class="homeHeader">'.l_t('My Tournaments').' <a href="tournaments.php?tab=Participating">'.libHTML::link().'</a></div>';
while (list($id, $name, $status) = $DB->tabl_row($tablChecked))
{
print '<div class = "gamePanelHome">
<h3 class = "tournamentCenter">'.$name.'</h3><div class = "tournamentCenter">';
if ($status != 'PreStart')
{
print '<a class = "tournamentCenter" href="tournamentScoring.php?tournamentID='.$id.'">Scoring and Participants</a></br>';
if($status != 'Registration')
{
print '</br><a class = "tournamentCenter" href="gamelistings.php?gamelistType=Search&tournamentID='.$id.'">Tournament Games</a></br>';
}
}
print'</br></div></div>';
}
}
$sql = "select t.id, t.name, t.status from wD_Tournaments t inner join wD_TournamentSpectators s on s.tournamentID = t.id where t.status <> 'Finished' and s.userID =".$User->id;
$sqlCounter = "select count(1) from wD_Tournaments t inner join wD_TournamentSpectators s on s.tournamentID = t.id where t.status <> 'Finished' and s.userID =".$User->id;
$tablChecked = $DB->sql_tabl($sql);
list($resultsSpectating) = $DB->sql_row($sqlCounter);
if ($resultsSpectating > 0)
{
print '<div class="homeHeader">'.l_t('Spectated Tournaments').' <a href="tournaments.php?tab=Spectating">'.libHTML::link().'</a></div>';
while (list($id, $name, $status) = $DB->tabl_row($tablChecked))
{
print '<div class = "gamePanelHome">
<h3 class = "tournamentCenter">'.$name.'</h3><div class = "tournamentCenter">';
if ($status != 'PreStart')
{
print '<a class = "tournamentCenter" href="tournamentScoring.php?tournamentID='.$id.'">Scoring and Participants</a></br>';
if($status != 'Registration')
{
print '</br><a class = "tournamentCenter" href="gamelistings.php?gamelistType=Search&tournamentID='.$id.'">Tournament Games</a></br>';
}
}
print'</br></div></div>';
}
}
print '</td>
</tr></table>';
print '</div>';
print '</div>';
}
libHTML::$footerIncludes = [l_j('home.js'), l_j('help.js')];
libHTML::$footerScript[] = l_jf('homeGameHighlighter').'();';
$_SESSION['lastSeenHome']=time();
libHTML::footer();
?>