source: trunk/Modules/Meet/MeetPage.php@ 63

Last change on this file since 63 was 63, checked in by chronos, 4 years ago
  • Modified: Used explicit types where possible for better error reporting.
  • Modified: Updated Common packaged to newer version.
  • Modified: Simplified pages title.
  • Added: Simple keyword based spam filter for meet items.
File size: 10.2 KB
Line 
1<?php
2
3class ModuleMeet extends Module
4{
5 function __construct($System)
6 {
7 parent::__construct($System);
8 $this->Name = 'Meet';
9 $this->Version = '1.0';
10 $this->Creator = 'Chronos';
11 $this->License = 'GNU/GPL';
12 $this->Description = 'List of dance meet items';
13 $this->Dependencies = array();
14 $this->RSSChannels = array();
15 }
16
17 function Start(): void
18 {
19 $this->System->RegisterPage(['seznamka'], 'PageMeetList');
20 $this->System->RegisterPage(['seznamka', 'inzerat'], 'PageMeetItem');
21 $this->System->RegisterPage(['seznamka', 'aktualizace'], 'PageMeetUpdate');
22 $this->System->RegisterPage(['seznamka', 'rss'], 'PageMeetRss');
23 Core::Cast($this->System)->RegisterMenuItem('/seznamka', 'Seznamka');
24 }
25}
26
27class PageMeetList extends Page
28{
29 function __construct($System)
30 {
31 parent::__construct($System);
32 $this->Title = 'Seznamka';
33 $this->Description = 'Taneční seznamka';
34 }
35
36 function Show(): string
37 {
38 global $Config;
39
40 $Filter = new Filter();
41 $Filter->Items = array(
42 array('Name' => 'pohlavi', 'Type' => 'Enumeration', 'DbName' => 'Gender', 'Title' => 'Pohlaví',
43 'States' => array(0 => 'Obě', 1 => 'Muži', 2 => 'Ženy')),
44 array('Name' => 'name', 'Type' => 'String', 'DbName' => 'Name', 'Title' => 'Jméno'),
45 array('Name' => 'vek', 'Type' => 'Integer', 'DbName' => 'Age', 'Title' => 'Věk', 'Units' => 'let'),
46 array('Name' => 'vyska', 'Type' => 'Integer', 'DbName' => 'Height', 'Title' => 'Výška', 'Units' => 'cm'),
47 array('Name' => 'vaha', 'Type' => 'Integer', 'DbName' => 'Weight', 'Title' => 'Váha', 'Units' => 'Kg'),
48 array('Name' => 'message', 'Type' => 'String', 'DbName' => 'Message', 'Title' => 'Zpráva'),
49 array('Name' => 'location', 'Type' => 'String', 'DbName' => 'Location', 'Title' => 'Umístění'),
50 array('Name' => 'source', 'Type' => 'String', 'DbName' => 'SourceName', 'Title' => 'Import'),
51 );
52
53 $Output = '';
54 if (array_key_exists('lvm', $_GET) and ($_GET['lvm'] == 'seznam'))
55 $this->RawPage = true;
56 else $Output .= '<div class="title">Inzeráty</div>';
57
58 $Output .= $Filter->GetOutput($this->System->Link('/seznamka/'));
59 $Where = $Filter->GetWhere($this->Database);
60
61 $DbResult = $this->Database->query('SELECT COUNT(*) FROM (SELECT *, '.
62 '(SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName FROM `MeetItem`) AS T '.
63 'WHERE '.GetDefaultMeetFilter('T').' AND '.$Where);
64 $DbRow = $DbResult->fetch_row();
65 $PageList = GetPageList($DbRow[0]);
66
67 $Gender = array('', 'Muž', 'Žena');
68 $Output .= '<div id="list_content">';
69 $Output .= $PageList['Output'];
70 $TableColumns = array(
71 array('Name' => 'Time', 'Title' => 'Čas'),
72 array('Name' => 'Name', 'Title' => 'Jméno'),
73 array('Name' => 'Height', 'Title' => 'Výška'),
74 array('Name' => 'Age', 'Title' => 'Věk'),
75 array('Name' => 'Weight', 'Title' => 'Váha'),
76 array('Name' => 'Location', 'Title' => 'Umístění'),
77 array('Name' => 'Gender', 'Title' => 'Pohlaví'),
78 array('Name' => 'Message', 'Title' => 'Zpráva'),
79 array('Name' => 'Source', 'Title' => 'Import'),
80 array('Name' => '', 'Title' => 'Detail'),
81 );
82 $Order = GetOrderTableHeader($TableColumns, 'Time', 1);
83 $Output .= '<table class="WideTable">';
84 $Output .= $Order['Output'];
85 $DbResult = $this->Database->query('SELECT * FROM (SELECT *, (SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName, '.
86 '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL FROM MeetItem) AS T WHERE '.GetDefaultMeetFilter('T').' AND '.
87 $Where.$Order['SQL'].$PageList['SQLLimit']);
88 while ($MeetItem = $DbResult->fetch_assoc())
89 {
90 $Output .= '<tr>'.
91 '<td>'.HumanDate(MysqlDateToTime($MeetItem['Time'])).'</td>'.
92 '<td>'.$MeetItem['Name'].'</td>'.
93 '<td>'.$MeetItem['Height'].'</td>'.
94 '<td>'.$MeetItem['Age'].'</td>'.
95 '<td>'.$MeetItem['Weight'].'</td>'.
96 '<td>'.$MeetItem['Location'].'</td>'.
97 '<td>'.$Gender[$MeetItem['Gender']].'</td>'.
98 '<td>'.$MeetItem['Message'].'</td>'.
99 '<td><a href="'.$MeetItem['SourceURL'].'">'.$MeetItem['SourceName'].'</a></td>'.
100 '<td><a href="'.$this->System->Link('/seznamka/inzerat/'.$MeetItem['Id']).'">Ukázat</a></td>';
101 $Output .= '</tr>';
102 }
103 $Output .= '</table>';
104 $Output .= $PageList['Output'];
105 $Output .= '</div>';
106 if (array_key_exists('lvm', $_GET) and ($_GET['lvm'] == 'seznam'))
107 {
108 }
109 else
110 {
111 $Output .= '<div><a href="'.$this->System->Link('/seznamka/rss/').'"><img src="'.$this->System->Link('/images/rss20.png').'" alt="rss20"/></a></div>';
112 }
113 return $Output;
114 }
115}
116
117class PageMeetUpdate extends Page
118{
119 function __construct($System)
120 {
121 parent::__construct($System);
122 $this->Title = 'Aktualizace seznamky';
123 $this->Description = 'Aktualizace taneční seznamky';
124 }
125
126 function Show(): string
127 {
128 $MeetSources = new MeetSources();
129 $MeetSources->Database = $this->Database;
130 if (array_key_exists('i', $_GET)) $Output = $MeetSources->Parse($_GET['i']);
131 else $Output = $MeetSources->Parse();
132 return $Output;
133 }
134}
135
136class PageMeetItem extends Page
137{
138 function __construct($System)
139 {
140 parent::__construct($System);
141 $this->Title = 'Inzerát';
142 $this->Description = 'Inzerát taneční seznamky';
143 }
144
145 function Show(): string
146 {
147 $Output = '';
148 if (count($this->System->PathItems) > 2)
149 {
150 $id = $this->System->PathItems[2] * 1;
151 } else return 'Položka nenalezena';
152 if (Core::Cast($this->System)->IsAdmin())
153 {
154 if (array_key_exists('hide', $_GET)) $this->Database->update('MeetItem', 'Id='.$id, array('Hidden' => 1));
155 if (array_key_exists('unhide', $_GET)) $this->Database->update('MeetItem', 'Id='.$id, array('Hidden' => 0));
156 }
157
158 $Output .= '<div class="title">Inzerát</div>';
159 $Gender = array('', 'Muž', 'Žena');
160 $DbResult = $this->Database->select('MeetItem', '*, (SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName, '.
161 '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL, '.GetDefaultMeetFilter().' AS Filter', 'Id='.$id);
162 if ($DbResult->num_rows > 0)
163 {
164 $MeetItem = $DbResult->fetch_assoc();
165 if (($MeetItem['Filter'] == '0') and !Core::Cast($this->System)->IsAdmin())
166 return 'Položka nenalezena';
167 if ($MeetItem['Link'] != '') $Link = '<a href="'.$MeetItem['Link'].'">Odkaz</a>';
168 else $Link = '';
169 $Output .= '<table class="ItemTable">'.
170 '<tr><th>Čas</th><td>'.HumanDate(MysqlDateToTime($MeetItem['Time'])).'</td></tr>'.
171 '<tr><th>Pohlaví</th><td>'.$Gender[$MeetItem['Gender']].'</td></tr>'.
172 '<tr><th>Jméno</th><td>'.$MeetItem['Name'].'</td></tr>'.
173 '<tr><th>Výška</th><td>'.$MeetItem['Height'].'</td></tr>'.
174 '<tr><th>Věk</th><td>'.$MeetItem['Age'].'</td></tr>'.
175 '<tr><th>Váha</th><td>'.$MeetItem['Weight'].'</td></tr>'.
176 '<tr><th>Umístění</th><td>'.$MeetItem['Location'].'</td></tr>'.
177 '<tr><th>Email</th><td>'.$MeetItem['Email'].'</td></tr>'.
178 '<tr><th>Telefón</th><td>'.$MeetItem['Phone'].'</td></tr>'.
179 '<tr><th>Zpráva</th><td>'.$MeetItem['Message'].'</td></tr>'.
180 '<tr><th>Původní web</th><td>'.$Link.'</td></tr>'.
181 '<tr><th>Zdroj importu</th><td><a href="'.$MeetItem['SourceURL'].'">'.$MeetItem['SourceName'].'</a></td></tr>';
182 $Output .= '</table>';
183 if (Core::Cast($this->System)->IsAdmin()) {
184 if ($MeetItem['Hidden'] == '1')
185 $Output .= '<div>Skrytá položka <a href="?unhide">Zviditelnit</a></div>';
186 else $Output .= '<div>Viditelná položka <a href="?hide">Skrýt</a></div>';
187 }
188 } else $Output .= 'Položka nenalezena';
189 return $Output;
190 }
191}
192
193class PageMeetRss extends Page
194{
195 function __construct($System)
196 {
197 parent::__construct($System);
198 $this->Title = 'RSS inzeráty seznamky';
199 $this->Description = 'RSS kanál taneční seznamky';
200 }
201
202 function Show(): string
203 {
204 global $Config;
205
206 $this->RawPage = true;
207 $RSS = new RSS();
208 $RSS->Title = 'Taneční seznamka';
209 $RSS->Description = '';
210 $RSS->Link = $this->System->AbsoluteLink('/seznamka/');
211
212 $DbResult = $this->Database->query('SELECT *, (SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName, '.
213 '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL FROM MeetItem WHERE '.
214 GetDefaultMeetFilter().' ORDER BY `Time` DESC LIMIT 30');
215 while ($MeetItem = $DbResult->fetch_assoc())
216 {
217 $Title = $MeetItem['Name'];
218 if ($MeetItem['Age'] != '') $Title .= ', '.$MeetItem['Age'].' let';
219 if ($MeetItem['Weight'] != '') $Title .= ', '.$MeetItem['Height'].' cm';
220 if ($MeetItem['Location'] != '') $Title .= ', '.$MeetItem['Location'];
221 $Description = $MeetItem['Message']."<br/>\n";
222 if ($MeetItem['Email'] != '') $Description .= '<br/>Email: '.$MeetItem['Email'];
223 if ($MeetItem['Phone'] != '') $Description .= '<br/>Telefon: '.$MeetItem['Phone'];
224 if ($MeetItem['Age'] != '') $Description .= '<br/>Věk: '.$MeetItem['Age'].' let';
225 if ($MeetItem['Height'] != '') $Description .= '<br/>Výška: '.$MeetItem['Height'].' cm';
226 if ($MeetItem['Weight'] != '') $Description .= '<br/>Váha: '.$MeetItem['Weight'].' kg';
227 $Description .= '<br/>Zdroj importu: <a href="'.$MeetItem['SourceURL'].'">'.$MeetItem['SourceName'].'</a>';
228 $Time = MysqlDateTimeToTime($MeetItem['Time']);
229 $TimeImport = MysqlDateTimeToTime($MeetItem['TimeImport']);
230 // Append time part of TimeImport time to item time so new items will appear in correct time order even if item doesn't have time part specified
231 if (TimeToMysqlTime($Time) == '00:00:00')
232 {
233 $Time = MysqlDateTimeToTime(TimeToMysqlDate($Time).' '.TimeToMysqlTime($TimeImport));
234 }
235 $RSS->Items[] = array(
236 'Title' => $Title,
237 'Description' => $Description,
238 'Time' => $Time,
239 'Link' => $this->System->AbsoluteLink('/seznamka/inzerat/'.$MeetItem['Id'].'/'),
240 );
241 }
242
243 return $RSS->Generate();
244 }
245}
Note: See TracBrowser for help on using the repository browser.