1<?php 2/** 3 * Plugin qrcodescanner 4 * author: dodotori @dokuwiki forum 5 * a dokuwiki scanner for bureaucracy form html5-qrcode library 6 */ 7 8// must be run within DokuWiki 9if(!defined('DOKU_INC')) die(); 10 11/** 12 * All DokuWiki plugins to extend the parser/rendering mechanism 13 * need to inherit from this class 14 */ 15 16class syntax_plugin_qrcodescanner extends DokuWiki_Syntax_Plugin { 17 18 19 20 21 public function getType() { return 'substition'; } 22 public function getSort() { return 32; } 23 24 public function connectTo($mode) { 25 $this->Lexer->addSpecialPattern('\{\{QRCODESCANNER\}\}',$mode,'plugin_qrcodescanner'); 26 } 27 28 public function handle($match, $state, $pos, Doku_Handler $handler) { 29 return array($match, $state, $pos); 30 } 31 32 public function render($mode, Doku_Renderer $renderer, $data) { 33 // $data is what the function handle return'ed. 34 if($mode == 'xhtml'){ 35 /** @var Doku_Renderer_xhtml $renderer */ 36 $renderer->doc .= '<div id="reader" style="width:100%"></div>'; 37 $renderer->doc .= '<script src="https://unpkg.com/html5-qrcode"></script>'; 38 $renderer->doc .= '<script> 39 40function onScanSuccess(decodedText, decodedResult) { 41 // handle the scanned code as you like, for example: 42 console.log(`Code matched = ${decodedText}`, decodedResult); 43 document.getElementsByName("bureaucracy[1]")[0].value = `${decodedText}`, decodedResult; 44} 45 46let qrconfig = { 47 fps: 10, 48 qrbox: {width: 300, height: 300}, 49 rememberLastUsedCamera: true, 50 //formatsToSupport: [ Html5QrcodeSupportedFormats.CODE_39 ] 51 // Only support camera scan type. 52}; 53 54let html5QrcodeScanner = new Html5QrcodeScanner( 55 "reader", qrconfig); 56 57html5QrcodeScanner.render(onScanSuccess); 58 59 60</script>'; 61 62 63 return true; 64 } 65 return false; 66 } 67}