/** * * * @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); }
/** * Renders an RSS feed * * @author Andreas Gohr <*****@*****.**> */ function rss($url, $params) { global $lang; global $conf; require_once DOKU_INC . 'inc/FeedParser.php'; $feed = new FeedParser(); $feed->set_feed_url($url); //disable warning while fetching if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } $rc = $feed->init(); if (isset($elvl)) { error_reporting($elvl); } if ($params['nosort']) { $feed->enable_order_by_date(false); } //decide on start and end if ($params['reverse']) { $mod = -1; $start = $feed->get_item_quantity() - 1; $end = $start - $params['max']; $end = $end < -1 ? -1 : $end; } else { $mod = 1; $start = 0; $end = $feed->get_item_quantity(); $end = $end > $params['max'] ? $params['max'] : $end; } $this->doc .= '<ul class="rss">'; if ($rc) { for ($x = $start; $x != $end; $x += $mod) { $item = $feed->get_item($x); $this->doc .= '<li><div class="li">'; // support feeds without links $lnkurl = $item->get_permalink(); if ($lnkurl) { // title is escaped by SimplePie, we unescape here because it // is escaped again in externallink() FS#1705 $this->externallink($item->get_permalink(), html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8')); } else { $this->doc .= ' ' . $item->get_title(); } if ($params['author']) { $author = $item->get_author(0); if ($author) { $name = $author->get_name(); if (!$name) { $name = $author->get_email(); } if ($name) { $this->doc .= ' ' . $lang['by'] . ' ' . $name; } } } if ($params['date']) { $this->doc .= ' (' . $item->get_local_date($conf['dformat']) . ')'; } if ($params['details']) { $this->doc .= '<div class="detail">'; if ($conf['htmlok']) { $this->doc .= $item->get_description(); } else { $this->doc .= strip_tags($item->get_description()); } $this->doc .= '</div>'; } $this->doc .= '</div></li>'; } } else { $this->doc .= '<li><div class="li">'; $this->doc .= '<em>' . $lang['rssfailed'] . '</em>'; $this->externallink($url); if ($conf['allowdebug']) { $this->doc .= '<!--' . hsc($feed->error) . '-->'; } $this->doc .= '</div></li>'; } $this->doc .= '</ul>'; }
/** * Loads images from a MediaRSS or ATOM feed */ function _loadRSS($url) { require_once DOKU_INC . 'inc/FeedParser.php'; $feed = new FeedParser(); $feed->set_feed_url($url); $feed->init(); $files = array(); // base url to use for broken feeds with non-absolute links $main = parse_url($url); $host = $main['scheme'] . '://' . $main['host'] . ($main['port'] ? ':' . $main['port'] : ''); $path = dirname($main['path']) . '/'; foreach ($feed->get_items() as $item) { if ($enclosure = $item->get_enclosure()) { // skip non-image enclosures if ($enclosure->get_type()) { if (substr($enclosure->get_type(), 0, 5) != 'image') { continue; } } else { if (!preg_match('/\\.(jpe?g|png|gif)(\\?|$)/i', $enclosure->get_link())) { continue; } } // non absolute links $ilink = $enclosure->get_link(); if (!preg_match('/^https?:\\/\\//i', $ilink)) { if ($ilink[0] == '/') { $ilink = $host . $ilink; } else { $ilink = $host . $path . $ilink; } } $link = $item->link; if (!preg_match('/^https?:\\/\\//i', $link)) { if ($link[0] == '/') { $link = $host . $link; } else { $link = $host . $path . $link; } } $files[] = array('id' => $ilink, 'isimg' => true, 'file' => basename($ilink), 'title' => SimplePie_Misc::htmlspecialchars_decode($enclosure->get_title(), ENT_COMPAT), 'desc' => strip_tags(SimplePie_Misc::htmlspecialchars_decode($enclosure->get_description(), ENT_COMPAT)), 'width' => $enclosure->get_width(), 'height' => $enclosure->get_height(), 'mtime' => $item->get_date('U'), 'ctime' => $item->get_date('U'), 'detail' => $link); } } return $files; }
/** * Renders an RSS feed * * @author Andreas Gohr <*****@*****.**> */ public function rss($url, $params) { global $lang; global $conf; require_once DOKU_INC . 'inc/FeedParser.php'; $feed = new FeedParser(); $feed->set_feed_url($url); //disable warning while fetching if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } $rc = $feed->init(); if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } //decide on start and end if ($params['reverse']) { $mod = -1; $start = $feed->get_item_quantity() - 1; $end = $start - $params['max']; $end = $end < -1 ? -1 : $end; } else { $mod = 1; $start = 0; $end = $feed->get_item_quantity(); $end = $end > $params['max'] ? $params['max'] : $end; } $this->doc .= '<ul class="rss">'; if ($rc) { for ($x = $start; $x != $end; $x += $mod) { $item = $feed->get_item($x); $this->doc .= '<li><div class="li">'; $this->externallink($item->get_permalink(), $item->get_title()); if ($params['author']) { $author = $item->get_author(0); if ($author) { $name = $author->get_name(); if (!$name) { $name = $author->get_email(); } if ($name) { $this->doc .= ' ' . $lang['by'] . ' ' . $name; } } } if ($params['date']) { $this->doc .= ' (' . $item->get_local_date($conf['dformat']) . ')'; } if ($params['details']) { $this->doc .= '<div class="detail">'; if ($conf['htmlok']) { $this->doc .= $item->get_description(); } else { $this->doc .= strip_tags($item->get_description()); } $this->doc .= '</div>'; } $this->doc .= '</div></li>'; } } else { $this->doc .= '<li><div class="li">'; $this->doc .= '<em>' . $lang['rssfailed'] . '</em>'; $this->externallink($url); if ($conf['allowdebug']) { $this->doc .= '<!--' . hsc($feed->error) . '-->'; } $this->doc .= '</div></li>'; } $this->doc .= '</ul>'; }