1edb40cceSAndreas Pazureck<?php 2edb40cceSAndreas Pazureck/** 3edb40cceSAndreas Pazureck * DokuWiki Plugin chordsheets (Syntax Component) 4edb40cceSAndreas Pazureck * 5edb40cceSAndreas Pazureck * @license MIT 6edb40cceSAndreas Pazureck * @author Andreas Pazureck <andreas@pazureck.de> 7edb40cceSAndreas Pazureck */ 8edb40cceSAndreas Pazureck 9edb40cceSAndreas Pazureck// must be run within Dokuwiki 10edb40cceSAndreas Pazureckif (!defined('DOKU_INC')) { 11edb40cceSAndreas Pazureck die(); 12edb40cceSAndreas Pazureck} 13edb40cceSAndreas Pazureck 14edb40cceSAndreas Pazureckclass syntax_plugin_chordsheets extends DokuWiki_Syntax_Plugin 15edb40cceSAndreas Pazureck{ 16edb40cceSAndreas Pazureck public function getType(){ return 'formatting'; } 17edb40cceSAndreas Pazureck public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); } 18edb40cceSAndreas Pazureck public function getSort(){ return 158; } 193d7a1733SAndreas Pazureck public function connectTo($mode) 203d7a1733SAndreas Pazureck { 213d7a1733SAndreas Pazureck $this->Lexer->addEntryPattern('<chordSheet.*?>(?=.*?</chordSheet>)',$mode,'plugin_chordsheets'); 223d7a1733SAndreas Pazureck } 23*729bed97SMatt Perry public function postConnect() 24*729bed97SMatt Perry { 25*729bed97SMatt Perry $this->Lexer->addExitPattern('</chordSheet>','plugin_chordsheets'); 26*729bed97SMatt Perry $this->Lexer->addPattern('%.*?\[\w+\]', $mode,'plugin_chordsheets'); 27*729bed97SMatt Perry } 28edb40cceSAndreas Pazureck 29edb40cceSAndreas Pazureck /** 30edb40cceSAndreas Pazureck * Handle the match 31edb40cceSAndreas Pazureck */ 32edb40cceSAndreas Pazureck public function handle($match, $state, $pos, Doku_Handler $handler){ 33edb40cceSAndreas Pazureck switch ($state) { 34edb40cceSAndreas Pazureck case DOKU_LEXER_ENTER : 35edb40cceSAndreas Pazureck $re = '/^<chordSheet.*?([-+]?\d+)>/'; 36edb40cceSAndreas Pazureck $transpose = 0; 37edb40cceSAndreas Pazureck preg_match($re, $match, $matches, PREG_OFFSET_CAPTURE, 0); 38edb40cceSAndreas Pazureck if(count($matches) > 0) { 39edb40cceSAndreas Pazureck $transpose = $matches[1]; 40edb40cceSAndreas Pazureck } 41edb40cceSAndreas Pazureck return array($state, $transpose); 42edb40cceSAndreas Pazureck 43edb40cceSAndreas Pazureck case DOKU_LEXER_UNMATCHED : return array($state, $match); 44edb40cceSAndreas Pazureck case DOKU_LEXER_EXIT : return array($state, ''); 45*729bed97SMatt Perry case DOKU_LEXER_MATCHED: return array($state, $match); 46edb40cceSAndreas Pazureck } 47edb40cceSAndreas Pazureck return array(); 48edb40cceSAndreas Pazureck } 49edb40cceSAndreas Pazureck 50edb40cceSAndreas Pazureck /** 51edb40cceSAndreas Pazureck * Create output 52edb40cceSAndreas Pazureck */ 53edb40cceSAndreas Pazureck public function render($mode, Doku_Renderer $renderer, $data) { 54edb40cceSAndreas Pazureck // $data is what the function handle() return'ed. 55edb40cceSAndreas Pazureck if($mode == 'xhtml'){ 56edb40cceSAndreas Pazureck /** @var Doku_Renderer_xhtml $renderer */ 57edb40cceSAndreas Pazureck list($state,$match) = $data; 58edb40cceSAndreas Pazureck switch ($state) { 59edb40cceSAndreas Pazureck case DOKU_LEXER_ENTER : 60edb40cceSAndreas Pazureck list($transpose) = $match; 61edb40cceSAndreas Pazureck $id = mt_rand(); 62cad2dd57SAndreas Pazureck $renderer->doc .= '<div class="cSheetButtonBar"><span class=cSheetButtons><button onclick="cSheetExportToWord('.$id.')">Export to Word</button></span></div>'; 63edb40cceSAndreas Pazureck $renderer->doc .= '<div class="song-with-chords" id="'.$id.'" data-transpose="'.$transpose.'">'; 647519296cSMatt Perry break; 65edb40cceSAndreas Pazureck case DOKU_LEXER_UNMATCHED : 66edb40cceSAndreas Pazureck $renderer->doc .= $renderer->_xmlEntities($match); 67edb40cceSAndreas Pazureck break; 68edb40cceSAndreas Pazureck case DOKU_LEXER_EXIT : 69edb40cceSAndreas Pazureck $renderer->doc .= "</div>"; 70edb40cceSAndreas Pazureck break; 71*729bed97SMatt Perry case DOKU_LEXER_MATCHED: 723d7a1733SAndreas Pazureck $renderer->doc .= '<span class="jtab">'.$match.'</span>'; 733d7a1733SAndreas Pazureck break; 74edb40cceSAndreas Pazureck } 75edb40cceSAndreas Pazureck return true; 76edb40cceSAndreas Pazureck } 77edb40cceSAndreas Pazureck return false; 78edb40cceSAndreas Pazureck } 79edb40cceSAndreas Pazureck} 80