1 | <?php
|
---|
2 |
|
---|
3 | class PageChatHistory extends Page
|
---|
4 | {
|
---|
5 | function __construct(System $System)
|
---|
6 | {
|
---|
7 | parent::__construct($System);
|
---|
8 | $this->Title = 'Historie chatu';
|
---|
9 | $this->Description = 'Výpis historie chatu';
|
---|
10 | $this->ParentClass = 'PagePortal';
|
---|
11 | }
|
---|
12 |
|
---|
13 | function dechexr($Num)
|
---|
14 | {
|
---|
15 | $Num = dechex($Num);
|
---|
16 | return substr($Num, 4, 2).substr($Num, 2, 2).substr($Num, 0, 2);
|
---|
17 | }
|
---|
18 |
|
---|
19 | function Show(): string
|
---|
20 | {
|
---|
21 | global $MonthNames;
|
---|
22 |
|
---|
23 | if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Chat', 'Display')) return 'Nemáte oprávnění';
|
---|
24 |
|
---|
25 | if (array_key_exists('date', $_GET)) $Date = $_GET['date'];
|
---|
26 | else $Date = date('Y-m-d');
|
---|
27 | $DateParts = explode('-', $Date);
|
---|
28 |
|
---|
29 | $DbResult = $this->Database->select('ChatHistory', 'MAX(Time), MIN(Time)');
|
---|
30 | $RowTotal = $DbResult->fetch_array();
|
---|
31 |
|
---|
32 | $StartDateTimeParts = explode(' ', $RowTotal['MIN(Time)']);
|
---|
33 | $StartDateParts = explode('-', $StartDateTimeParts[0]);
|
---|
34 | $EndDateTimeParts = explode(' ', $RowTotal['MAX(Time)']);
|
---|
35 | $EndDateParts = explode('-', $EndDateTimeParts[0]);
|
---|
36 |
|
---|
37 | if (!array_key_exists('year', $_SESSION)) $_SESSION['year'] = date('Y', time());
|
---|
38 | if (array_key_exists('year', $_GET)) $_SESSION['year'] = addslashes($_GET['year']);
|
---|
39 |
|
---|
40 | if (!array_key_exists('month', $_SESSION)) $_SESSION['month'] = date('n', time());
|
---|
41 | if (array_key_exists('month', $_GET)) $_SESSION['month'] = addslashes($_GET['month']);
|
---|
42 |
|
---|
43 | $Output = '<div class="ChatHistory">';
|
---|
44 | for ($Year = $EndDateParts[0]; $Year >= $StartDateParts[0]; $Year--)
|
---|
45 | {
|
---|
46 | if ($_SESSION['year'] == $Year)
|
---|
47 | {
|
---|
48 | $Output .= '<div class="Year">'.$Year.'<div class="YearContent">';
|
---|
49 | if ($Year == $StartDateParts[0]) $StartMonth = ($StartDateParts[1] + 0); else $StartMonth = 1;
|
---|
50 | if ($Year == $EndDateParts[0]) $EndMonth = ($EndDateParts[1] + 0); else $EndMonth = 12;
|
---|
51 | for ($Month = $EndMonth; $Month >= $StartMonth; $Month--)
|
---|
52 | {
|
---|
53 | if ($_SESSION['month'] == $Month)
|
---|
54 | {
|
---|
55 | $Output .= '<div class="Months">'.$MonthNames[$Month].'<span>';
|
---|
56 | if (($Year == $StartDateParts[0]) and ($Month == $StartDateParts[1])) $StartDay = ($StartDateParts[2]+0); else $StartDay = 1;
|
---|
57 | if (($Year == $EndDateParts[0]) and ($Month == $EndDateParts[1])) $EndDay = ($EndDateParts[2]+0); else $EndDay = date('t',mktime(0,0,0,$Month,0,$Year));
|
---|
58 | for ($Day = $StartDay; $Day <= $EndDay; $Day++)
|
---|
59 | {
|
---|
60 | $Text = '<a href="?date='.$Year.'-'.$Month.'-'.$Day.'">'.$Day.'</a> ';
|
---|
61 | if (($DateParts[0] == $Year) and ($DateParts[1] == $Month) and ($DateParts[2] == $Day)) $Text = '<strong>'.$Text.'</strong>';
|
---|
62 | $Output .= $Text;
|
---|
63 | }
|
---|
64 | $Output .= '</span></div>';
|
---|
65 | } else $Output .= '<span><a href="?month='.$Month.'">'.$MonthNames[$Month].'</a></span> ';
|
---|
66 | }
|
---|
67 | $Output .='</div></div>';
|
---|
68 | } else $Output .= '<div class="Year"><a href="?year='.$Year.'">'.$Year.'</a></div>';
|
---|
69 | }
|
---|
70 | $Output .= '</div><div></div>';
|
---|
71 |
|
---|
72 | $DbResult = $this->Database->select('ChatHistory', 'Nick, Color, Text, UNIX_TIMESTAMP(Time)', "RoomType = 0 AND Time > '".$Date." 00:00:00' AND Time < '".$Date." 23:59:59' ORDER BY Time DESC");
|
---|
73 | $Output .= '<div class="ChatHistoryText">';
|
---|
74 | if ($DbResult->num_rows > 0)
|
---|
75 | while ($Row = $DbResult->fetch_array())
|
---|
76 | {
|
---|
77 | $Text = $Row['Text'];;
|
---|
78 | // StrTr($Row['text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
|
---|
79 | $Output .= '['.date('d.m.Y H:i:s',$Row['UNIX_TIMESTAMP(Time)']).'] <span style="color: #'.$this->dechexr($Row['Color']).'"><strong><'.$Row['Nick'].'></strong> '.(htmlspecialchars($Text)).'</span><br>';
|
---|
80 | }
|
---|
81 | else $Output .= 'V daném dni nebyly zaznamenány žádné zprávy.';
|
---|
82 | $Output .= '</div>';
|
---|
83 | return $Output;
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | class ModuleChat extends Module
|
---|
88 | {
|
---|
89 | function __construct(System $System)
|
---|
90 | {
|
---|
91 | parent::__construct($System);
|
---|
92 | $this->Name = 'Chat';
|
---|
93 | $this->Version = '1.0';
|
---|
94 | $this->Creator = 'Chronos';
|
---|
95 | $this->License = 'GNU/GPLv3';
|
---|
96 | $this->Description = 'Show history of IRC chat and previous SunriseChat';
|
---|
97 | $this->Models = array(ChatHistory::GetClassName());
|
---|
98 | }
|
---|
99 |
|
---|
100 | function DoStart(): void
|
---|
101 | {
|
---|
102 | $this->System->Pages['chat'] = 'PageChatHistory';
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | class ChatHistory extends Model
|
---|
107 | {
|
---|
108 | static function GetModelDesc(): ModelDesc
|
---|
109 | {
|
---|
110 | $Desc = new ModelDesc(self::GetClassName());
|
---|
111 | $Desc->AddString('Nick');
|
---|
112 | $Desc->AddText('Text');
|
---|
113 | $Desc->AddDateTime('Time');
|
---|
114 | $Desc->AddInteger('Color');
|
---|
115 | $Desc->AddString('RoomName');
|
---|
116 | $Desc->AddInteger('RoomType');
|
---|
117 | $Desc->AddString('Host');
|
---|
118 | return $Desc;
|
---|
119 | }
|
---|
120 | }
|
---|