*/ class syntax_plugin_doi_isbn extends \dokuwiki\Extension\SyntaxPlugin { /** @inheritDoc */ public function getType() { return 'substition'; } /** @inheritDoc */ public function getPType() { return 'normal'; } /** @inheritDoc */ public function getSort() { return 155; } /** @inheritDoc */ public function connectTo($mode) { $this->Lexer->addSpecialPattern('\[\[isbn>[^\]]+\]\]', $mode, 'plugin_doi_isbn'); } /** @inheritDoc */ public function handle($match, $state, $pos, Doku_Handler $handler) { $isbn = substr($match, 7, -2); $isbn = preg_replace('/[^0-9X]/i', '', $isbn); return ['isbn' => $isbn]; } /** @inheritDoc */ public function render($mode, Doku_Renderer $renderer, $data) { $publication = $this->fetchInfo($data['isbn']); $title = $publication['details']['title'] ?? $data['isbn']; $url = $publication['details']['info_url'] ?? 'https://www.google.com/search?q=isbn+' . $data['isbn']; if ($mode !== 'xhtml' || !$publication) { $renderer->externallink($url, $title); return true; } /** @var Doku_Renderer_xhtml $renderer */ $this->formatPub($publication, $renderer); return true; } /** * Render the given message * * @param array $message * @param Doku_Renderer_xhtml $renderer * @return void */ protected function formatPub($message, $renderer) { $url = $message['info_url']; $message = $message['details']; $isbn = $message['isbn_13'][0] ?? $message['isbn_10'][0] ?? ''; $title = $message['title'] ?? $isbn; $class = 'book'; $authorList = []; foreach ($message['authors'] ?? [] as $author) { $authorList[] = '' . hsc($author['name']) . ''; } $published = $message['publish_date'] ?? ''; if (preg_match('/\b(\d{4})\b/', $published, $m)) { $published = ' (' . hsc($m[1]) . ')'; } else { $published = ''; } $publisher = hsc($message['publishers'][0] ?? ''); //output $renderer->doc .= '