1<?php 2/** 3 * Plugin xkcd: display xkcs comic 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Carlo Perassi <carlo@perassi.org> 7 * @author Zahno Silvan <zaswiki@gmail.com> 8 */ 9 10// based on http://wiki.splitbrain.org/plugin:tutorial 11 12// must be run within Dokuwiki 13if (!defined('DOKU_INC')) die(); 14 15if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 16require_once(DOKU_PLUGIN . 'syntax.php'); 17 18/** 19 * All DokuWiki plugins to extend the parser/rendering mechanism 20 * need to inherit from this class 21 */ 22class syntax_plugin_xkcd extends DokuWiki_Syntax_Plugin { 23 function getInfo() { 24 return array( 25 'author' => 'Zahno Silvan, Carlo Perassi', 26 'email' => 'zaswiki@gmail.com', 27 'date' => '2020-09-02', 28 'name' => 'xkcd Plugin', 29 'desc' => 'It displays the xkcd three times a week. Using RSS feed', 30 'url' => 'https://xkcd.com/rss.xml' 31 ); 32 } 33 34 private function _listhd() { 35 $url = 'https://xkcd.com/rss.xml'; 36 $ch = new \dokuwiki\HTTP\DokuHTTPClient(); 37 $piece = $ch->get($url); 38 $xml = simplexml_load_string($piece); 39 40 $comicURL = $xml->channel->item->link; 41 42 $description = (string) $xml->channel->item->description; 43 $description = html_entity_decode($description, ENT_NOQUOTES); 44 $feed_contents = $description; 45 // Not used anymore because of new xml format 46 //$dom = new DOMDocument(); 47 //$dom->loadXML($description); 48 //$imgSrc = $dom->childNodes->item(0)->attributes->getNamedItem('src' )->value; 49 //$imgTitle = $dom->childNodes->item(0)->attributes->getNamedItem('title' )->value; 50 //$feed_contents = "<a href=\"$comicURL\"><img src=\"$imgSrc\" title=\"$imgTitle\" /></a>\n"; 51 52 return $feed_contents; 53 } 54 55 56 function connectTo($mode) { 57 $this->Lexer->addSpecialPattern('\[xkcd\]', $mode, 'plugin_xkcd'); 58 } 59 60 function getType() { return 'substition'; } 61 62 function getSort() { return 667; } 63 64 function handle($match, $state, $pos, Doku_Handler $handler) { 65 return array($match, $state, $pos); 66 } 67 68 function render($mode, Doku_Renderer $renderer, $data) { 69 70 if ($mode == 'xhtml') { 71 $renderer->doc .= $this->_listhd(); 72 return true; 73 } 74 return false; 75 } 76} 77