1 | <?php
|
---|
2 |
|
---|
3 | class ModuleShoutBox extends AppModule
|
---|
4 | {
|
---|
5 | function __construct($System)
|
---|
6 | {
|
---|
7 | parent::__construct($System);
|
---|
8 | $this->Name = 'ShoutBox';
|
---|
9 | $this->Version = '1.0';
|
---|
10 | $this->Creator = 'Chronos';
|
---|
11 | $this->License = 'GNU/GPL';
|
---|
12 | $this->Description = 'Simple user chat system.';
|
---|
13 | $this->Dependencies = array('News');
|
---|
14 | }
|
---|
15 |
|
---|
16 | function Start()
|
---|
17 | {
|
---|
18 | $this->System->RegisterPage('shoutbox', 'PageShoutBox');
|
---|
19 | $this->System->ModuleManager->Modules['News']->RegisterRSS(array(
|
---|
20 | 'Title' => 'Kecátko', 'Channel' => 'shoutbox', 'Callback' => array('PageShoutBox', 'ShowRSS'),
|
---|
21 | 'Permission' => LICENCE_ANONYMOUS));
|
---|
22 | }
|
---|
23 |
|
---|
24 | function ShowBox()
|
---|
25 | {
|
---|
26 | $Output = '<strong><a href="'.$this->System->Link('/shoutbox/').'">'.T('Chatbox').':</a></strong>';
|
---|
27 |
|
---|
28 | if($this->System->User->Licence(LICENCE_USER))
|
---|
29 | $Output .= ' <a href="'.$this->System->Link('/shoutbox/?a=add').'">'.T('Add').'</a>';
|
---|
30 | $Output .= '<div class="box"><table>';
|
---|
31 | $DbResult = $this->Database->query('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 30');
|
---|
32 | while($Line = $DbResult->fetch_assoc())
|
---|
33 | $Output .= '<tr><td><strong>'.$Line['UserName'].'</strong>: '.MakeActiveLinks($Line['Text']).'</td></tr>';
|
---|
34 | $Output .= '</table></div>';
|
---|
35 | return($Output);
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | class PageShoutBox extends Page
|
---|
40 | {
|
---|
41 | function Show()
|
---|
42 | {
|
---|
43 | if(array_key_exists('a', $_POST)) $Action = $_POST['a'];
|
---|
44 | else if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
|
---|
45 | else $Action = '';
|
---|
46 | if($Action == 'add2') $Output = $this->AddFinish();
|
---|
47 | if($Action == 'add') $Output = $this->ShowAddForm();
|
---|
48 | else $Output = $this->ShowList();
|
---|
49 | return($Output);
|
---|
50 | }
|
---|
51 |
|
---|
52 | function ShowList()
|
---|
53 | {
|
---|
54 | $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ShoutBox`');
|
---|
55 | $DbRow = $DbResult->fetch_row();
|
---|
56 | $PageList = GetPageList($DbRow[0]);
|
---|
57 |
|
---|
58 | $Output = '<h3>Kecátko</h3>'.$PageList['Output'];
|
---|
59 | if($this->System->User->Licence(LICENCE_USER))
|
---|
60 | $Output .= ' <a href="'.$this->System->Link('/shoutbox/?a=add').'">'.T('Add').'</a>';
|
---|
61 | $Output .= '<div class="shoutbox">';
|
---|
62 | $DbResult = $this->System->Database->query('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC '.$PageList['SQLLimit']);
|
---|
63 | while($Line = $DbResult->fetch_assoc())
|
---|
64 | $Output .= '<div><strong>'.$Line['UserName'].'</strong>: '.MakeActiveLinks($Line['Text']).'</div>';
|
---|
65 | $Output .= '</div>'.$PageList['Output'];
|
---|
66 | return($Output);
|
---|
67 | }
|
---|
68 |
|
---|
69 | function ShowAddForm()
|
---|
70 | {
|
---|
71 | $Output = '';
|
---|
72 | if($this->System->User->Licence(LICENCE_USER))
|
---|
73 | {
|
---|
74 | $Output .= '<form action="?" method="post">'.
|
---|
75 | '<fieldset><legend>Nová zpráva kecátka</legend>'.
|
---|
76 | 'Uživatel: ';
|
---|
77 | if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />';
|
---|
78 | else $Output .= '<input type="text" name="user" /><br />';
|
---|
79 | $Output .= 'Text zprávy: <br/>'.
|
---|
80 | '<textarea onkeydown="ResizeTextArea(this)" name="text" cols="40"></textarea> <br/>'.
|
---|
81 | '<input type="hidden" name="a" value="add2"/>'.
|
---|
82 | '<input type="submit" value="Odeslat" /><br /></fieldset>'.
|
---|
83 | '</form>';
|
---|
84 | } else $Output .= ShowMessage('Pro vkládaní zpráv musíte byt registrováni.', MESSAGE_CRITICAL);
|
---|
85 | $Output .= $this->ShowList();
|
---|
86 | return($Output);
|
---|
87 | }
|
---|
88 |
|
---|
89 | function AddFinish()
|
---|
90 | {
|
---|
91 | $Output = '';
|
---|
92 | if($this->System->User->Licence(LICENCE_USER))
|
---|
93 | {
|
---|
94 | if(array_key_exists('text', $_POST))
|
---|
95 | {
|
---|
96 | $Text = $_POST['text'];
|
---|
97 | if(trim($Text) == '') $Output .= ShowMessage('Nelze vložit prázdnou zprávu.', MESSAGE_WARNING);
|
---|
98 | else
|
---|
99 | {
|
---|
100 | // Protection against mutiple post of same message
|
---|
101 | $DbResult = $this->System->Database->query('SELECT `Text` FROM `ShoutBox` WHERE (`User` = "'.
|
---|
102 | $this->System->User->Id.'") ORDER BY `Date` DESC LIMIT 1');
|
---|
103 | if($DbResult->num_rows > 0)
|
---|
104 | {
|
---|
105 | $DbRow = $DbResult->fetch_assoc();
|
---|
106 | } else $DbRow['Text'] = '';
|
---|
107 |
|
---|
108 | if($DbRow['Text'] == $Text) $Output .= ShowMessage('Nelze vložit stejnou zprávu vícekrát za sebou.', MESSAGE_WARNING);
|
---|
109 | else
|
---|
110 | {
|
---|
111 | $this->System->Database->query('INSERT INTO `ShoutBox` ( `User`, `UserName` , `Text` , `Date` , `IP` ) '.
|
---|
112 | ' VALUES ('.$this->System->User->Id.', "'.$this->System->User->Name.
|
---|
113 | '", "'.$Text.'", NOW(), "'.$_SERVER['REMOTE_ADDR'].'")');
|
---|
114 | $Output .= ShowMessage('Zpráva vložena.');
|
---|
115 | }
|
---|
116 | }
|
---|
117 | } else $Output .= ShowMessage('Nezadán text pro novou zprávu.', MESSAGE_CRITICAL);
|
---|
118 | $Output .= '<br/>';
|
---|
119 | } else $Output .= ShowMessage('Pro vkládaní zpráv musíte byt registrováni.', MESSAGE_CRITICAL);
|
---|
120 | $Output .= $this->ShowList();
|
---|
121 | return($Output);
|
---|
122 | }
|
---|
123 |
|
---|
124 | function ShowRSS()
|
---|
125 | {
|
---|
126 | $TitleLength = 50;
|
---|
127 | mb_internal_encoding('utf-8');
|
---|
128 | $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`Date`) AS `UnixDate`, `User`, `UserName`, `Text` FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 20');
|
---|
129 | while($DbRow = $DbResult->fetch_assoc())
|
---|
130 | {
|
---|
131 | $Title = mb_substr($DbRow['Text'], 0, $TitleLength);
|
---|
132 | if(mb_strlen($Title) == $TitleLength) $Title .= '...';
|
---|
133 | $Items[] = array
|
---|
134 | (
|
---|
135 | 'Title' => $DbRow['UserName'].': '.$Title,
|
---|
136 | 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'),
|
---|
137 | 'Description' => $DbRow['Text'],
|
---|
138 | 'Time' => $DbRow['UnixDate'],
|
---|
139 | );
|
---|
140 | }
|
---|
141 | $Output = GenerateRSS(array
|
---|
142 | (
|
---|
143 | 'Title' => 'WoW překlad - Shoutbox',
|
---|
144 | 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'),
|
---|
145 | 'Description' => 'Překlad textů WoW',
|
---|
146 | 'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
|
---|
147 | 'Items' => $Items,
|
---|
148 | ));
|
---|
149 | return($Output);
|
---|
150 | }
|
---|
151 | }
|
---|