-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
93 lines (80 loc) · 3.17 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* DokuWiki Plugin feedaggregator (Action Component)
*
* @license GPL 3 http://www.gnu.org/licenses/gpl-3.0.html
* @author Sam Wilson <sam@samwilson.id.au>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) {
die();
}
class action_plugin_feedaggregator extends DokuWiki_Action_Plugin {
/**
* Registers a callback function for the PREPROCESS event.
*
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle');
}
/**
*
*
* @param Doku_Event $event Not used
* @param mixed $param Not used
* @return void
*/
public function handle(Doku_Event &$event, $param) {
global $conf;
if ($event->data != 'feedaggregator') {
return;
}
$event->preventDefault();
// See if we need a token and whether it matches.
$requiredToken = $this->getConf('token');
$suppliedToken = (isset($_GET['token'])) ? $_GET['token'] : false;
if (!empty($requiredToken) && $suppliedToken !== $requiredToken) {
msg("Token doesn't match for feedaggregator");
return true;
}
// Get the feed list.
$feeds = file(fullpath($conf['tmpdir'].'/feedaggregator.csv'));
// Set up SimplePie and merge all the feeds together.
$simplepie = new FeedParser();
$ua = 'Mozilla/4.0 (compatible; DokuWiki feedaggregator plugin '.wl('', '', true).')';
$simplepie->set_useragent($ua);
$simplepie->force_feed($this->getConf('force_feed'));
$simplepie->force_fsockopen($this->getConf('force_fsockopen'));
$simplepie->set_feed_url($feeds);
// Set up caching.
$cacheDir = fullpath($conf['cachedir'].'/feedaggregator');
io_mkdir_p($cacheDir);
$simplepie->enable_cache();
$simplepie->set_cache_location($cacheDir);
// Run the actual feed aggregation.
$simplepie->init();
// Check for errors.
if ($simplepie->error()) {
header("Content-type:text/plain");
echo join("\n", $simplepie->error());
}
// Create the output HTML and cache it for use by the syntax component.
$html = '';
foreach ($simplepie->get_items() as $item) {
$html .= "<div class='feedaggregator_item'>\n"
."<h2>".$item->get_title()."</h2>\n"
.$item->get_content()."\n"
."<p>"
." <a href='".$item->get_permalink()."'>Published ".$item->get_date('j M Y')."</a> "
." in <a href='".$item->get_feed()->get_permalink()."'>".$item->get_feed()->get_title()."</a>"
."</p>\n"
."</div>\n\n";
}
io_saveFile($cacheDir.'/output.html', $html);
// Output nothing, as this should be run from cron and we don't want to
// flood the logs with success.
exit(0);
}
}