1<?php 2/** 3 * Plugin barcode: 2D-Barcode Implementation 4 * 5 * @author Enrico Croce & Simona Burzio (staff@eiroca.net) 6 * @copyright Copyright (C) 2009-2019 eIrOcA - Enrico Croce & Simona Burzio 7 * @license GPL >=3 (http://www.gnu.org/licenses/) 8 * @version 19.02 9 * @link http://www.eiroca.net/doku_barcode 10 */ 11if (!defined('DOKU_INC')) die(); 12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 13if (!defined('DOKU_PLUGIN_BARCODE')) define('DOKU_PLUGIN_BARCODE', DOKU_PLUGIN . 'barcode/'); 14require_once (DOKU_PLUGIN . 'syntax.php'); 15require_once (DOKU_PLUGIN_BARCODE . 'api/barcode.inc'); 16 17class syntax_plugin_barcode extends DokuWiki_Syntax_Plugin { 18 19 function getType() { 20 return 'substition'; 21 } 22 23 function getPType() { 24 return 'normal'; 25 } 26 27 function getSort() { 28 return 999; 29 } 30 31 function connectTo($mode) { 32 $this->Lexer->addSpecialPattern('~~BARCODE.*?~~', $mode, 'plugin_barcode'); 33 } 34 35 function handle($match, $state, $pos, Doku_Handler $handler) { 36 global $ID; 37 $paramsArr = explode('~', $match); 38 $p = [ ]; 39 $p['mode'] = 0; 40 $p['size'] = 'M'; 41 $p['text'] = wl($ID, '', true); 42 $last = count($paramsArr); 43 for ($i = 3; $i < $last; $i++) { 44 $currentParam = $paramsArr[$i]; 45 $param = explode('=', $currentParam); 46 switch (trim($param[0])) { 47 case '' : 48 break; 49 case 'url' : 50 $p['text'] = substr($currentParam, 4); 51 break; 52 case 'tel' : 53 $p['text'] = 'TEL:' . substr($currentParam, 4); 54 break; 55 case 'sms' : 56 $p['text'] = 'SMSTO:' . $param[1] . ':' . $param[2]; 57 break; 58 case 'contact' : 59 $p['text'] = 'BEGIN:VCARD\nN:' . $param[1] . '\nTEL:' . $param[2] . '\nEMAIL:' . $param[3] . '\nEND:VCARD'; 60 break; 61 case 'text' : 62 $p['text'] = substr($currentParam, 5); 63 break; 64 default : 65 $p[$param[0]] = $param[1]; 66 break; 67 } 68 } 69 $provider = $this->getConf('provider'); 70 $service = QRProvider::getService($provider); 71 $out .= $service->render($p); 72 return $out; 73 } 74 75 function render($mode, Doku_Renderer $renderer, $data) { 76 global $conf; 77 global $ID; 78 if ($mode == 'xhtml') { 79 $renderer->doc .= $data; 80 if ($this->getConf('showfooter')) { 81 if (plugin_isdisabled('translation') || (!$translation = plugin_load('helper', 'translation'))) { 82 $lang = $conf['lang']; 83 } 84 else { 85 $lang = $translation->getLangPart($ID); 86 } 87 $fn = DOKU_PLUGIN_BARCODE . 'footer_' . $lang . '.txt'; 88 if (!file_exists($fn)) $fn = DOKU_PLUGIN_BARCODE . 'footer.txt'; 89 $renderer->doc .= @file_get_contents($fn); 90 } 91 return true; 92 } 93 return false; 94 } 95 96} 97?>