Skip to content
Permalink
Browse files

First working draft.

  • Loading branch information...
samwilson committed Dec 17, 2015
1 parent 7acfae5 commit 8a91e127611c9fe5976669af036b1ece368f443e
Showing with 115 additions and 95 deletions.
  1. +0 −2 .gitignore
  2. +84 −0 action.php
  3. +0 −16 composer.json
  4. +0 −73 composer.lock
  5. +31 −4 syntax.php

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,84 @@
<?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();
// 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(true);
$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>"
." Published ".$item->get_date('j M Y')." "
." 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);
}
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -49,7 +49,8 @@ public function postConnect() {
}
/**
* Handle matches of the feedaggregator syntax
* Handle matches of the <feedaggregator> tag, storing the list of feeds in
* a file in the ~/data/tmp/feedaggregator directory.
*
* @param string $match The match of the syntax
* @param int $state The state of the handler
@@ -58,8 +59,33 @@ public function postConnect() {
* @return array Data for the renderer
*/
public function handle($match, $state, $pos, Doku_Handler &$handler) {
global $conf;
$data = array();
// Are we to handle this match? If not, don't.
if ($state !== DOKU_LEXER_UNMATCHED) {
return $data;
}
// Get the feed URLs.
$matchedFeeds = preg_split('/[\n\r]+/', $match, -1, PREG_SPLIT_NO_EMPTY);
$feeds = array();
foreach ($matchedFeeds as $feed) {
if (filter_var($feed, FILTER_VALIDATE_URL) === false) {
msg("Feed URL not valid: <code>$feed</code>", 2);
continue;
}
$feeds[] = $feed;
}
$feedList = array_unique($feeds);
// Save the feeds to a temporary CSV. It'll be ready by the action script.
$file = fullpath($conf['tmpdir'].'/feedaggregator.csv');
file_put_contents($file, join("\n", $feedList));
// Get the most-recently generated HTML feed aggregation. This won't be
// up to date with the above feeds yet, but that's okay.
$data['html'] = io_readFile(fullpath($conf['cachedir'].'/feedaggregator/output.html'));
return $data;
}
@@ -72,9 +98,10 @@ public function handle($match, $state, $pos, Doku_Handler &$handler) {
* @return bool If rendering was successful.
*/
public function render($mode, Doku_Renderer &$renderer, $data) {
if ($mode != 'xhtml')
if ($mode != 'xhtml') {
return false;
}
$renderer->doc .= $data['html'];
return true;
}

0 comments on commit 8a91e12

Please sign in to comment.
You can’t perform that action at this time.