1 | <?php
|
---|
2 |
|
---|
3 | class ModuleForum extends AppModule
|
---|
4 | {
|
---|
5 | function __construct($System)
|
---|
6 | {
|
---|
7 | parent::__construct($System);
|
---|
8 | $this->Name = 'Forum';
|
---|
9 | $this->Version = '1.0';
|
---|
10 | $this->Creator = 'Maron';
|
---|
11 | $this->License = 'GNU/GPL';
|
---|
12 | $this->Description = '';
|
---|
13 | $this->Dependencies = array();
|
---|
14 | }
|
---|
15 |
|
---|
16 | function Start()
|
---|
17 | {
|
---|
18 | $this->System->RegisterPage('forum', 'PageForum');
|
---|
19 | $this->System->ModuleManager->Modules['News']->RegisterRSS(array(
|
---|
20 | 'Title' => T('Forum'), 'Channel' => 'forum', 'Callback' => array('PageForum', 'ShowRSS'),
|
---|
21 | 'Permission' => LICENCE_ANONYMOUS));
|
---|
22 | $this->System->RegisterMenuItem(array(
|
---|
23 | 'Title' => T('Forum'),
|
---|
24 | 'Hint' => 'Forum na debatování ohledně překladu wow',
|
---|
25 | 'Link' => $this->System->Link('/forum/'),
|
---|
26 | 'Permission' => LICENCE_ANONYMOUS,
|
---|
27 | 'Icon' => '',
|
---|
28 | ), 17);
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | class PageForum extends Page
|
---|
33 | {
|
---|
34 | function Show()
|
---|
35 | {
|
---|
36 | $Output = '';
|
---|
37 | $this->Title = T('Forum');
|
---|
38 | if(array_key_exists('a', $_POST)) $Action = $_POST['a'];
|
---|
39 | else if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
|
---|
40 | else $Action = '';
|
---|
41 | if (array_key_exists('Thread', $_GET)) {
|
---|
42 | $Output .= '<h3>'.T('Forum - Thread').'</h3>';
|
---|
43 | if($Action == 'add2') $Output .= $this->AddFinish();
|
---|
44 | if($this->System->User->Licence(LICENCE_USER)) $Output .= $this->ShowAddForm();
|
---|
45 | $Output .= $this->ShowList();
|
---|
46 | } else {
|
---|
47 | $Output .= '<h3>'.T('Forum - List of Thread').'</h3>';
|
---|
48 | if($Action == 'add2') $Output .= $this->AddFinish('ForumThread');
|
---|
49 | if($this->System->User->Licence(LICENCE_USER)) $Output .= $this->ShowAddFormThread();
|
---|
50 | $Output .= $this->ShowListThread();
|
---|
51 | }
|
---|
52 | return($Output);
|
---|
53 | }
|
---|
54 |
|
---|
55 | function Del() {
|
---|
56 | $Output = '';
|
---|
57 | if (array_key_exists('Del', $_GET)) {
|
---|
58 | $this->System->Database->query('DELETE FROM `ForumThread` WHERE `User` = '.$this->System->User->Id.' AND `ID` = '.$_GET['Del'].' ');
|
---|
59 | $Output .= ShowMessage('Vlákno smazáno!');
|
---|
60 | }
|
---|
61 | return ($Output);
|
---|
62 | }
|
---|
63 |
|
---|
64 | function ShowListThread()
|
---|
65 | {
|
---|
66 | $Output = '';
|
---|
67 |
|
---|
68 | $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ForumThread` WHERE 1');
|
---|
69 | $DbRow = $DbResult->fetch_row();
|
---|
70 | $PageList = GetPageList($DbRow[0]);
|
---|
71 |
|
---|
72 | $Output .= $PageList['Output'];
|
---|
73 | $Output .= '<div class="shoutbox">';
|
---|
74 | $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE 1 ORDER BY `ID` DESC '.$PageList['SQLLimit']);
|
---|
75 | while($Line = $DbResult->fetch_assoc())
|
---|
76 | $Output .= '<div><a href="?Thread='.$Line['ID'].'">'.MakeActiveLinks(str_replace("\n", '',$Line['Text'])).'</a> (<strong>'.$Line['UserName'].'</strong>) - '.HumanDate($Line['Date']).'</div>';
|
---|
77 | $Output .= '</div>'.$PageList['Output'];
|
---|
78 | return($Output);
|
---|
79 | }
|
---|
80 |
|
---|
81 | function ShowList()
|
---|
82 | {
|
---|
83 | $Output = '';
|
---|
84 | if(array_key_exists('search', $_GET)) $_SESSION['search'] = $_GET['search'];
|
---|
85 | else if(!array_key_exists('search', $_SESSION)) $_SESSION['search'] = '';
|
---|
86 | if(array_key_exists('search', $_GET) and ($_GET['search'] == '')) $_SESSION['search'] = '';
|
---|
87 | if($_SESSION['search'] != '')
|
---|
88 | {
|
---|
89 | $SearchQuery = ' AND (`Text` LIKE "%'.$_SESSION['search'].'%")';
|
---|
90 | $Output .= '<div><a href="?search=">'.sprintf(T('Disable filter "%s"'), $_SESSION['search']).'</a></div>';
|
---|
91 | } else $SearchQuery = '';
|
---|
92 |
|
---|
93 | $DbResult = $this->System->Database->query('SELECT * FROM `ForumThread` WHERE ID='.$_GET['Thread'].' LIMIT 1');
|
---|
94 | $Thread = $DbResult->fetch_assoc();
|
---|
95 | $Output .= '<h3>'.$Thread['Text'].'</h3>';
|
---|
96 |
|
---|
97 | $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `ForumText` WHERE `Thread` = '.$_GET['Thread'].' '.$SearchQuery);
|
---|
98 | $DbRow = $DbResult->fetch_row();
|
---|
99 | $PageList = GetPageList($DbRow[0]);
|
---|
100 |
|
---|
101 | $Output .= $PageList['Output'];
|
---|
102 | $Output .= '<div class="shoutbox">';
|
---|
103 | $DbResult = $this->System->Database->query('SELECT * FROM `ForumText` WHERE `Thread` = '.$_GET['Thread'].' '.$SearchQuery.' ORDER BY `ID` DESC '.$PageList['SQLLimit']);
|
---|
104 | while($Line = $DbResult->fetch_assoc())
|
---|
105 | $Output .= '<div><strong>'.$Line['UserName'].'</strong> ('.HumanDate($Line['Date']).'): '.MakeActiveLinks($Line['Text']).'</div> ';
|
---|
106 | $Output .= '</div>'.$PageList['Output'];
|
---|
107 | return($Output);
|
---|
108 | }
|
---|
109 |
|
---|
110 | function ShowAddForm()
|
---|
111 | {
|
---|
112 | $Output = '';
|
---|
113 | if($this->System->User->Licence(LICENCE_USER))
|
---|
114 | {
|
---|
115 | $Output .= '<form action="?Thread='.$_GET['Thread'].'" method="post">'.
|
---|
116 | '<fieldset><legend>'.T('New Forum Message').'</legend>'.
|
---|
117 | 'Uživatel: ';
|
---|
118 | if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />';
|
---|
119 | else $Output .= '<input type="text" name="user" /><br />';
|
---|
120 | $Output .= 'Text zprávy: <br/>'.
|
---|
121 | '<textarea onkeydown="ResizeTextArea(this)" name="text" cols="40" ></textarea> <br/>'.
|
---|
122 | '<input type="hidden" name="a" value="add2"/>'.
|
---|
123 | '<input type="submit" value="Odeslat" /><br /></fieldset>'.
|
---|
124 | '</form>';
|
---|
125 | } else $Output .= ShowMessage('Pro vkládaní zpráv musíte byt registrováni.', MESSAGE_CRITICAL);
|
---|
126 | return($Output);
|
---|
127 | }
|
---|
128 |
|
---|
129 | function ShowAddFormThread()
|
---|
130 | {
|
---|
131 | $Output = '';
|
---|
132 | if($this->System->User->Licence(LICENCE_USER))
|
---|
133 | {
|
---|
134 | $Output .= '<form action="?" method="post">'.
|
---|
135 | '<fieldset><legend>'.T('New thread').'</legend>'.
|
---|
136 | 'Uživatel: ';
|
---|
137 | if($this->System->User->Licence(LICENCE_USER)) $Output .= '<b>'.$this->System->User->Name.'</b><br />';
|
---|
138 | else $Output .= '<input type="text" name="user" /><br />';
|
---|
139 | $Output .= 'Název vlákna: <br />'.
|
---|
140 | '<textarea onkeydown="ResizeTextArea(this)" name="text" rows="1" cols="30"></textarea> <br/>'.
|
---|
141 | '<input type="hidden" name="a" value="add2"/>'.
|
---|
142 | '<input type="submit" value="Odeslat" /><br /></fieldset>'.
|
---|
143 | '</form>';
|
---|
144 | } else $Output .= ShowMessage('Pro vkládaní zpráv musíte byt registrováni.', MESSAGE_CRITICAL);
|
---|
145 | return($Output);
|
---|
146 | }
|
---|
147 |
|
---|
148 | function AddFinish($Table = 'ForumText')
|
---|
149 | {
|
---|
150 | $Output = '';
|
---|
151 | if($this->System->User->Licence(LICENCE_USER))
|
---|
152 | {
|
---|
153 | if(array_key_exists('text', $_POST))
|
---|
154 | {
|
---|
155 | $Text = $_POST['text'];
|
---|
156 | if(trim($Text) == '') $Output .= ShowMessage('Nelze vložit prázdnou zprávu.', MESSAGE_WARNING);
|
---|
157 | else
|
---|
158 | {
|
---|
159 | // Protection against mutiple post of same message
|
---|
160 | $Thread = '';
|
---|
161 | if ($Table == 'ForumText') $Thread = 'AND `Thread` = '.$_GET['Thread'];
|
---|
162 | $DbResult = $this->System->Database->query('SELECT `Text` FROM `'.$Table.'` WHERE 1 '.$Thread.' AND (`User` = "'.
|
---|
163 | $this->System->User->Id.'") ORDER BY `Date` DESC LIMIT 1');
|
---|
164 | if($DbResult->num_rows > 0)
|
---|
165 | {
|
---|
166 | $DbRow = $DbResult->fetch_assoc();
|
---|
167 | } else $DbRow['Text'] = '';
|
---|
168 |
|
---|
169 | if($DbRow['Text'] == $Text) $Output .= ShowMessage('Nelze vložit stejnou zprávu vícekrát za sebou.', MESSAGE_WARNING);
|
---|
170 | else
|
---|
171 | {
|
---|
172 | if ($Table == 'ForumText')
|
---|
173 | $this->System->Database->query('INSERT INTO `'.$Table.'` ( `User`, `UserName` , `Text` , `Date` , `IP` , `Thread` ) '.
|
---|
174 | ' VALUES ('.$this->System->User->Id.', "'.$this->System->User->Name.
|
---|
175 | '", "'.$Text.'", NOW(), "'.$_SERVER['REMOTE_ADDR'].'","'.$_GET['Thread'].'")');
|
---|
176 | else
|
---|
177 | $this->System->Database->query('INSERT INTO `'.$Table.'` ( `User`, `UserName` , `Text` , `Date` , `IP`) '.
|
---|
178 | ' VALUES ('.$this->System->User->Id.', "'.$this->System->User->Name.
|
---|
179 | '", "'.$Text.'", NOW(), "'.$_SERVER['REMOTE_ADDR'].'")');
|
---|
180 | $Output .= ShowMessage('Vloženo.');
|
---|
181 | }
|
---|
182 | }
|
---|
183 | } else $Output .= ShowMessage('Nezadán text pro novou zprávu.', MESSAGE_CRITICAL);
|
---|
184 | $Output .= '<br/>';
|
---|
185 | } else $Output .= ShowMessage('Pro vkládaní zpráv musíte byt registrováni.', MESSAGE_CRITICAL);
|
---|
186 | return($Output);
|
---|
187 | }
|
---|
188 |
|
---|
189 | function ShowRSS()
|
---|
190 | {
|
---|
191 | $TitleLength = 50;
|
---|
192 | mb_internal_encoding('utf-8');
|
---|
193 | $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`Date`) AS `UnixDate`, `User`, `UserName`, `Text`, ( SELECT `Text` FROM `ForumThread` WHERE `ID` = `ForumText`.`Thread`) as `Thread` FROM `ForumText` ORDER BY `ID` DESC LIMIT 20');
|
---|
194 | while($DbRow = $DbResult->fetch_assoc())
|
---|
195 | {
|
---|
196 | $Title = mb_substr($DbRow['Text'], 0, $TitleLength);
|
---|
197 | if(mb_strlen($Title) == $TitleLength) $Title .= '...';
|
---|
198 | $Items[] = array
|
---|
199 | (
|
---|
200 | 'Title' => $DbRow['Thread'].' - '.$DbRow['UserName'].': ',
|
---|
201 | 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'),
|
---|
202 | 'Description' => $DbRow['Text'],
|
---|
203 | 'Time' => $DbRow['UnixDate'],
|
---|
204 | );
|
---|
205 | }
|
---|
206 | $Output = GenerateRSS(array
|
---|
207 | (
|
---|
208 | 'Title' => 'WoW překlad - Fórum',
|
---|
209 | 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'),
|
---|
210 | 'Description' => 'Překlad textů WoW',
|
---|
211 | 'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
|
---|
212 | 'Items' => $Items,
|
---|
213 | ));
|
---|
214 | return($Output);
|
---|
215 | }
|
---|
216 | }
|
---|