1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/*************************************************************************** |
3
|
|
|
* For license information see doc/license.txt |
4
|
|
|
* |
5
|
|
|
* Unicode Reminder メモ |
6
|
|
|
* |
7
|
|
|
* Publish new geocaches that are marked for timed publish |
8
|
|
|
***************************************************************************/ |
9
|
|
|
|
10
|
|
|
checkJob(new phpbbtopics()); |
11
|
|
|
|
12
|
|
|
class phpbbtopics |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
public $name = 'phpbbtopics'; |
15
|
|
|
public $interval = 600; |
16
|
|
|
public $topiclist = []; |
17
|
|
|
|
18
|
|
|
public function run() |
19
|
|
|
{ |
20
|
|
|
global $opt; |
21
|
|
|
|
22
|
|
|
foreach ($opt['cron']['phpbbtopics']['forumids'] as $id) { |
23
|
|
|
$url = $opt['cron']['phpbbtopics']['url']; |
24
|
|
|
$url = str_replace('{id}', $id, $url); |
25
|
|
|
|
26
|
|
|
if ($this->processUrl($url) == false) { |
|
|
|
|
27
|
|
|
return; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
usort($this->topiclist, 'sort_compare_updated'); |
32
|
|
|
$this->topiclist = array_slice($this->topiclist, 0, $opt['cron']['phpbbtopics']['count']); |
33
|
|
|
|
34
|
|
|
$f = fopen(__DIR__ . '/../../cache2/phpbb.inc.php', 'w'); |
35
|
|
|
fwrite($f, '<?php' . "\n"); |
36
|
|
|
fwrite( |
37
|
|
|
$f, |
38
|
|
|
'$phpbb_topics = unserialize("' . str_replace('"', '\\"', serialize($this->topiclist)) . '");' . "\n" |
39
|
|
|
); |
40
|
|
|
fwrite($f, '?>'); |
41
|
|
|
fclose($f); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function processUrl($url) |
45
|
|
|
{ |
46
|
|
|
global $opt; |
47
|
|
|
|
48
|
|
|
$maxsize = 100 * 1024; // max. 100kB |
49
|
|
|
|
50
|
|
|
$content = @read_file($url, $maxsize); |
|
|
|
|
51
|
|
|
if ($content === false) { |
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$xml = @simplexml_load_string($content); |
56
|
|
|
if ($xml === false) { |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (!isset($xml->entry)) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
foreach ($xml->entry as $item) { |
65
|
|
|
$posting = []; |
66
|
|
|
|
67
|
|
|
$sTitle = $item->title; |
68
|
|
|
if (mb_strpos($sTitle, '•') !== false) { |
69
|
|
|
$sTitle = mb_trim(mb_substr($sTitle, mb_strpos($sTitle, '•') + 1)); |
70
|
|
|
} |
71
|
|
|
$sTitle = strip_tags($sTitle); |
72
|
|
|
$sTitle = htmlspecialchars_decode($sTitle); |
73
|
|
|
$sTitle = preg_replace('/\\&.*\\;/U', '', $sTitle); |
74
|
|
|
|
75
|
|
|
$nTopicId = crc32($item->id); // workaround ... |
76
|
|
|
$tUpdated = strtotime($item->updated); |
77
|
|
|
|
78
|
|
|
$sUsername = (string)$item->author->name; |
79
|
|
|
$sUsername = htmlspecialchars_decode($sUsername); |
80
|
|
|
$sUsername = preg_replace('/\\&.*\\;/U', '', $sUsername); |
81
|
|
|
|
82
|
|
|
foreach ($item->link->Attributes() as $key => $value) { |
83
|
|
|
if ($key == 'href') { |
84
|
|
|
$sLink = (string)$value; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
$posting['id'] = $nTopicId; |
88
|
|
|
$posting['title'] = $sTitle; |
89
|
|
|
$posting['updated'] = $tUpdated; |
90
|
|
|
$posting['username'] = $sUsername; |
91
|
|
|
$posting['link'] = $sLink; |
|
|
|
|
92
|
|
|
|
93
|
|
|
if ($nTopicId != 0) { |
94
|
|
|
if (isset($this->topiclist[$nTopicId]) && $posting['updated'] > $this->topiclist[$nTopicId]['updated']) { |
95
|
|
|
$this->topiclist[$nTopicId] = $posting; |
96
|
|
|
} else { |
97
|
|
|
if (!isset($this->topiclist[$nTopicId])) { |
98
|
|
|
$this->topiclist[$nTopicId] = $posting; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return true; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
function sort_compare_updated($a, $b) |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
return ($b['updated'] - $a['updated']); |
111
|
|
|
} |
112
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.