|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/*************************************************************************** |
|
4
|
|
|
* for license information see LICENSE.md |
|
5
|
|
|
* summarize methods to get new events, caches, ratings, etc. |
|
6
|
|
|
***************************************************************************/ |
|
7
|
|
|
class getNew |
|
8
|
|
|
{ |
|
9
|
|
|
private $userCountry; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @return mixed |
|
13
|
|
|
*/ |
|
14
|
|
|
public function get_userCountry() |
|
15
|
|
|
{ |
|
16
|
|
|
return $this->userCountry; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param $userCountry |
|
21
|
|
|
*/ |
|
22
|
|
|
public function set_userCountry($userCountry): void |
|
23
|
|
|
{ |
|
24
|
|
|
$this->userCountry = $userCountry; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* constructor |
|
29
|
|
|
* creates the object |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $userCountry country of the loggedin user as parameter for the sql statements |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($userCountry) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->set_userCountry($userCountry); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* rsForSmarty creates the result from database to use with smarty assign-rs method |
|
40
|
|
|
* based on $this->type |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $type type of the "new"-information, i.e. cache, event, rating, etc |
|
43
|
|
|
* @param array $args numeric array containing the parameter for "sql_slave" |
|
44
|
|
|
* @return object mysql result used by smarty assign_rs |
|
45
|
|
|
*/ |
|
46
|
|
|
public function rsForSmarty($type, $args = null) |
|
47
|
|
|
{ |
|
48
|
|
|
switch ($type) { |
|
49
|
|
|
case 'cache': |
|
50
|
|
|
return $this->cacheRs($args); |
|
51
|
|
|
break; |
|
|
|
|
|
|
52
|
|
|
case 'event': |
|
53
|
|
|
return $this->eventRs($args); |
|
54
|
|
|
break; |
|
|
|
|
|
|
55
|
|
|
case 'rating': |
|
56
|
|
|
return $this->ratingRs($args); |
|
57
|
|
|
break; |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* feedForSmarty creates a HTML string to use with smarty assign method |
|
63
|
|
|
* based on $this->type by using RSSParser class |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $type type of the "new"-information, i.e. cache, event, rating, etc |
|
66
|
|
|
* @param int $items number of feeditems to parse from feed (RSSParser) |
|
67
|
|
|
* @param string $url url of the feed to parse (RSSParser) |
|
68
|
|
|
* @param int $timeout maximum seconds to wait for the requested page |
|
69
|
|
|
* @param null|mixed $includeText |
|
70
|
|
|
* @return string HTML string used for smarty assign method |
|
71
|
|
|
* @internal param bool $includetext ???following??? add table-tag? |
|
72
|
|
|
*/ |
|
73
|
|
|
public function feedForSmarty($type, $items = null, $url = null, $timeout = null, $includeText = null) |
|
74
|
|
|
{ |
|
75
|
|
|
switch ($type) { |
|
76
|
|
|
case 'forum': |
|
77
|
|
|
return $this->forumFeed($items, $url, $timeout, $includeText); |
|
78
|
|
|
break; |
|
|
|
|
|
|
79
|
|
|
case 'blog': |
|
80
|
|
|
return $this->blogFeed($items, $url, $timeout, $includeText); |
|
81
|
|
|
break; |
|
|
|
|
|
|
82
|
|
|
case 'wiki': |
|
83
|
|
|
return $this->wikiFeed($items, $url, $timeout, $includeText); |
|
84
|
|
|
break; |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* cacheRs executes the database statements for type "cache" |
|
90
|
|
|
* |
|
91
|
|
|
* @param array $args numeric array containing the parameter for "sql_slave" |
|
92
|
|
|
* @return object mysql result used by smarty assign_rs |
|
93
|
|
|
*/ |
|
94
|
|
View Code Duplication |
private function cacheRs($args = null) |
|
|
|
|
|
|
95
|
|
|
{ |
|
96
|
|
|
global $opt; |
|
97
|
|
|
|
|
98
|
|
|
if ($args === null || !is_array($args)) { |
|
99
|
|
|
$args = [ |
|
100
|
|
|
$this->get_userCountry(), |
|
101
|
|
|
$opt['template']['locale'], |
|
102
|
|
|
10, |
|
103
|
|
|
]; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return sql_slave( |
|
|
|
|
|
|
107
|
|
|
"SELECT `user`.`user_id` `user_id`, |
|
108
|
|
|
`user`.`username` `username`, |
|
109
|
|
|
`caches`.`cache_id` `cache_id`, |
|
110
|
|
|
`caches`.`name` `name`, |
|
111
|
|
|
`caches`.`date_created` `date_created`, |
|
112
|
|
|
`caches`.`type`, |
|
113
|
|
|
`caches`.`longitude` `longitude`, |
|
114
|
|
|
`caches`.`latitude` `latitude`, |
|
115
|
|
|
IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`, |
|
116
|
|
|
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm2`,'') `adm2`, |
|
117
|
|
|
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm3`,'') `adm3`, |
|
118
|
|
|
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm4`,'') `adm4`, |
|
119
|
|
|
`ca`.`attrib_id` IS NOT NULL AS `oconly` |
|
120
|
|
|
FROM `caches` |
|
121
|
|
|
INNER JOIN `user` |
|
122
|
|
|
ON `user`.`user_id`=`caches`.`user_id` |
|
123
|
|
|
LEFT JOIN `cache_location` |
|
124
|
|
|
ON `caches`.`cache_id`=`cache_location`.`cache_id` |
|
125
|
|
|
LEFT JOIN `countries` |
|
126
|
|
|
ON `countries`.`short`=`caches`.`country` |
|
127
|
|
|
LEFT JOIN `sys_trans_text` |
|
128
|
|
|
ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` |
|
129
|
|
|
AND `sys_trans_text`.`lang`='&2' |
|
130
|
|
|
LEFT JOIN `caches_attributes` `ca` |
|
131
|
|
|
ON `ca`.`cache_id`=`caches`.`cache_id` |
|
132
|
|
|
AND `ca`.`attrib_id`=6 |
|
133
|
|
|
WHERE `caches`.`country`='&1' |
|
134
|
|
|
AND `caches`.`type` != 6 |
|
135
|
|
|
AND `caches`.`status` = 1 |
|
136
|
|
|
ORDER BY `caches`.`date_created` DESC |
|
137
|
|
|
LIMIT 0, &3", |
|
138
|
|
|
$args |
|
139
|
|
|
); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* eventRs executes the database statements for type "event" |
|
144
|
|
|
* |
|
145
|
|
|
* @param array $args numeric array containing the parameter for "sql_slave" |
|
146
|
|
|
* @return object mysql result used by smarty assign_rs |
|
147
|
|
|
*/ |
|
148
|
|
View Code Duplication |
private function eventRs($args = null) |
|
|
|
|
|
|
149
|
|
|
{ |
|
150
|
|
|
global $opt; |
|
151
|
|
|
|
|
152
|
|
|
if ($args === null || !is_array($args)) { |
|
153
|
|
|
$args = [ |
|
154
|
|
|
$this->get_userCountry(), |
|
155
|
|
|
$opt['template']['locale'], |
|
156
|
|
|
10, |
|
157
|
|
|
]; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
return sql_slave( |
|
|
|
|
|
|
161
|
|
|
"SELECT `user`.`user_id` `user_id`, |
|
162
|
|
|
`user`.`username` `username`, |
|
163
|
|
|
`caches`.`cache_id` `cache_id`, |
|
164
|
|
|
`caches`.`name` `name`, |
|
165
|
|
|
`caches`.`date_hidden`, |
|
166
|
|
|
IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`, |
|
167
|
|
|
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm2`,'') `adm2`, |
|
168
|
|
|
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm3`,'') `adm3`, |
|
169
|
|
|
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm4`,'') `adm4`, |
|
170
|
|
|
`ca`.`attrib_id` IS NOT NULL AS `oconly` |
|
171
|
|
|
FROM `caches` |
|
172
|
|
|
INNER JOIN `user` |
|
173
|
|
|
ON `user`.`user_id`=`caches`.`user_id` |
|
174
|
|
|
LEFT JOIN `cache_location` |
|
175
|
|
|
ON `caches`.`cache_id`=`cache_location`.`cache_id` |
|
176
|
|
|
LEFT JOIN `countries` |
|
177
|
|
|
ON `countries`.`short`=`caches`.`country` |
|
178
|
|
|
LEFT JOIN `sys_trans_text` |
|
179
|
|
|
ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` |
|
180
|
|
|
AND `sys_trans_text`.`lang`='&2' |
|
181
|
|
|
LEFT JOIN `caches_attributes` `ca` |
|
182
|
|
|
ON `ca`.`cache_id`=`caches`.`cache_id` |
|
183
|
|
|
AND `ca`.`attrib_id`=6 |
|
184
|
|
|
WHERE `caches`.`country`='&1' |
|
185
|
|
|
AND `caches`.`date_hidden` >= curdate() |
|
186
|
|
|
AND `caches`.`type` = 6 |
|
187
|
|
|
AND `caches`.`status`=1 |
|
188
|
|
|
ORDER BY `date_hidden` ASC |
|
189
|
|
|
LIMIT 0, &3", |
|
190
|
|
|
$args |
|
191
|
|
|
); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* ratingDays returns the number of days used for top rating calculation |
|
196
|
|
|
* |
|
197
|
|
|
* @return int |
|
198
|
|
|
*/ |
|
199
|
|
|
public function ratingDays() |
|
200
|
|
|
{ |
|
201
|
|
|
global $opt; |
|
202
|
|
|
|
|
203
|
|
|
// Calculate days depending on country selection. |
|
204
|
|
|
// Todo: make default country configurable and use this also for |
|
205
|
|
|
// "except of [Germany]" new caches and logs lists |
|
206
|
|
|
|
|
207
|
|
|
if ($this->get_userCountry() === 'DE') { |
|
208
|
|
|
return $opt['logic']['rating']['topdays_mainCountry']; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
return $opt['logic']['rating']['topdays_otherCountry']; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* ratingRs executes the database statements for type "rating" |
|
216
|
|
|
* |
|
217
|
|
|
* @param array $args numeric array containing the parameter for "sql_slave" |
|
218
|
|
|
* @return object mysql result used by smarty assign_rs |
|
219
|
|
|
*/ |
|
220
|
|
View Code Duplication |
private function ratingRs($args = null) |
|
|
|
|
|
|
221
|
|
|
{ |
|
222
|
|
|
global $opt; |
|
223
|
|
|
|
|
224
|
|
|
// check $args and set defaults |
|
225
|
|
|
if ($args === null || !is_array($args)) { |
|
226
|
|
|
$args = [ |
|
227
|
|
|
$this->get_userCountry(), |
|
228
|
|
|
$opt['template']['locale'], |
|
229
|
|
|
10, |
|
230
|
|
|
$this->ratingDays(), |
|
231
|
|
|
]; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
// execute sql |
|
235
|
|
|
// 2012-08-24 following |
|
236
|
|
|
// optimized by adding rating_date field to cache_rating, so we don't need the log table. |
|
237
|
|
|
return sql_slave( |
|
|
|
|
|
|
238
|
|
|
"SELECT COUNT(`cache_rating`.`user_id`) AS `cRatings`, |
|
239
|
|
|
MAX(`cache_rating`.`rating_date`) AS `dLastLog`, |
|
240
|
|
|
`user`.`user_id` AS `user_id`, |
|
241
|
|
|
`user`.`username` AS `username`, |
|
242
|
|
|
`caches`.`cache_id` AS `cache_id`, |
|
243
|
|
|
`caches`.`name` AS `name`, |
|
244
|
|
|
`caches`.`type`, |
|
245
|
|
|
IFNULL(`sys_trans_text`.`text`,`countries`.`en`) AS `adm1`, |
|
246
|
|
|
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm2`,'') `adm2`, |
|
247
|
|
|
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm3`,'') `adm3`, |
|
248
|
|
|
IF(`caches`.`country`=`cache_location`.`code1`,`cache_location`.`adm4`,'') `adm4`, |
|
249
|
|
|
`ca`.`attrib_id` IS NOT NULL AS `oconly` |
|
250
|
|
|
FROM `cache_rating` |
|
251
|
|
|
INNER JOIN `caches` ON `caches`.`cache_id`=`cache_rating`.`cache_id` |
|
252
|
|
|
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id` |
|
253
|
|
|
LEFT JOIN `cache_location` ON `cache_rating`.`cache_id`=`cache_location`.`cache_id` |
|
254
|
|
|
LEFT JOIN `countries` ON `countries`.`short`=`caches`.`country` |
|
255
|
|
|
LEFT JOIN `sys_trans_text` |
|
256
|
|
|
ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` |
|
257
|
|
|
AND `sys_trans_text`.`lang`='&2' |
|
258
|
|
|
LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6 |
|
259
|
|
|
WHERE `caches`.`country`='&1' AND |
|
260
|
|
|
`cache_rating`.`rating_date`>DATE_SUB(NOW(), INTERVAL &4 DAY) AND |
|
261
|
|
|
`caches`.`type`!=6 AND |
|
262
|
|
|
`caches`.`status`=1 |
|
263
|
|
|
GROUP BY `cache_rating`.`cache_id` |
|
264
|
|
|
ORDER BY `cRatings` DESC, |
|
265
|
|
|
`dLastLog` DESC, |
|
266
|
|
|
`cache_id` DESC |
|
267
|
|
|
LIMIT 0, &3", |
|
268
|
|
|
$args |
|
269
|
|
|
); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* blogFeed executes the RSSParser for type "blog" |
|
274
|
|
|
* |
|
275
|
|
|
* @param int $items number of feeditems to parse from feed (RSSParser) |
|
276
|
|
|
* @param string $url url of the feed to parse (RSSParser) |
|
277
|
|
|
* @param int $timeout maximum seconds to wait for the requested page |
|
278
|
|
|
* @param bool $includeText ???following??? add table-tag? |
|
279
|
|
|
* @return string HTML string used for smarty assign method |
|
280
|
|
|
*/ |
|
281
|
|
View Code Duplication |
private function blogFeed($items = null, $url = null, $timeout = null, $includeText = null) |
|
|
|
|
|
|
282
|
|
|
{ |
|
283
|
|
|
global $opt; |
|
284
|
|
|
|
|
285
|
|
|
if (!is_numeric($items) || $items === null) { |
|
286
|
|
|
$items = $opt['news']['count']; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
if ($url === null || !is_string($url)) { |
|
290
|
|
|
$url = $opt['news']['include']; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
if ($timeout === null || !is_numeric($timeout)) { |
|
294
|
|
|
$timeout = $opt['news']['timeout']; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
if ($includeText === null || !is_bool($includeText)) { |
|
298
|
|
|
$includeText = false; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
return RSSParser::parse($items, $url, $timeout, $includeText); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* forumFeed executes the RSSParser for type "forum" |
|
306
|
|
|
* |
|
307
|
|
|
* @param int $items number of feeditems to parse from feed (RSSParser) |
|
308
|
|
|
* @param string $url url of the feed to parse (RSSParser) |
|
309
|
|
|
* @param int $timeout maximum seconds to wait for the requested page |
|
310
|
|
|
* @param bool $includeText ???following??? add table-tag? |
|
311
|
|
|
* @return string HTML string used for smarty assign method |
|
312
|
|
|
*/ |
|
313
|
|
View Code Duplication |
private function forumFeed($items = null, $url = null, $timeout = null, $includeText = null) |
|
|
|
|
|
|
314
|
|
|
{ |
|
315
|
|
|
global $opt; |
|
316
|
|
|
|
|
317
|
|
|
if (!is_numeric($items) || $items === null) { |
|
318
|
|
|
$items = $opt['forum']['count']; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
if ($url === null || !is_string($url)) { |
|
322
|
|
|
$url = $opt['forum']['url']; |
|
323
|
|
|
} |
|
324
|
|
|
if ($timeout === null || !is_numeric($timeout)) { |
|
325
|
|
|
$timeout = $opt['forum']['timeout']; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
if ($includeText === null || !is_bool($includeText)) { |
|
329
|
|
|
$includeText = false; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
return RSSParser::parse($items, $url, $timeout, $includeText); |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* wikiFeed executes the RSSParser for type "wiki" |
|
337
|
|
|
* |
|
338
|
|
|
* @param int $items number of feeditems to parse from feed (RSSParser) |
|
339
|
|
|
* @param string $url url of the feed to parse (RSSParser) |
|
340
|
|
|
* @param bool $includeText ???following??? add table-tag? |
|
341
|
|
|
* @param int $timeout maximum seconds to wait for the requested page |
|
342
|
|
|
* @return string HTML string used for smarty assign method |
|
343
|
|
|
*/ |
|
344
|
|
View Code Duplication |
private function wikiFeed($items = null, $url = null, $timeout = null, $includeText = null) |
|
|
|
|
|
|
345
|
|
|
{ |
|
346
|
|
|
global $opt; |
|
347
|
|
|
|
|
348
|
|
|
if (!is_numeric($items) || $items === null) { |
|
349
|
|
|
$items = $opt['wikinews']['count']; |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
if (!is_string($url) || $url === null) { |
|
353
|
|
|
$url = $opt['wikinews']['url']; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
if ($timeout === null || !is_numeric($timeout)) { |
|
357
|
|
|
$timeout = $opt['wikinews']['timeout']; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
if ($includeText === null || !is_bool($includeText)) { |
|
361
|
|
|
$includeText = false; |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
// execute RSSParser |
|
365
|
|
|
return RSSParser::parse($items, $url, $timeout, $includeText); |
|
366
|
|
|
} |
|
367
|
|
|
} |
|
368
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.