*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); require_once(DOKU_PLUGIN.'syntax.php'); class syntax_plugin_data_entry extends DokuWiki_Syntax_Plugin { /** * will hold the data helper plugin */ var $dthlp = null; /** * Constructor. Load helper plugin */ function syntax_plugin_data_entry(){ $this->dthlp =& plugin_load('helper', 'data'); if(!$this->dthlp) msg('Loading the data helper failed. Make sure the data plugin is installed.',-1); } /** * Return some info */ function getInfo(){ return $this->dthlp->getInfo(); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } /** * What about paragraphs? */ function getPType(){ return 'block'; } /** * Where to sort in? */ function getSort(){ return 155; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('----+ *dataentry(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+',$mode,'plugin_data_entry'); } /** * Handle the match - parse the data */ function handle($match, $state, $pos, &$handler){ // get lines $lines = explode("\n",$match); array_pop($lines); $class = array_shift($lines); $class = str_replace('datatable','',$class); $class = trim($class,'- '); // parse info $data = array(); $meta = array(); foreach ( $lines as $line ) { // ignore comments $line = preg_replace('/(?dthlp->_column($line[0]); if($multi){ if(!is_array($data[$key])) $data[$key] = array(); // init with empty array $vals = explode(',',$line[1]); foreach($vals as $val){ $val = trim($this->dthlp->_cleanData($val,$type)); if($val == '') continue; if(!in_array($val,$data[$key])) $data[$key][] = $val; } }else{ $data[$key] = $this->dthlp->_cleanData($line[1],$type); } $meta[$key]['multi'] = $multi; $meta[$key]['type'] = $type; $meta[$key]['title'] = $title; } return array('data'=>$data, 'meta'=>$meta, 'classes'=>$class); } /** * Create output or save the data */ function render($format, &$renderer, $data) { global $ID; switch ($format){ case 'xhtml': $renderer->doc .= $this->_showData($data,$renderer); return true; case 'metadata': $this->_saveData($data,$ID,$renderer->meta['title']); return true; default: return false; } } /** * Output the data in a table */ function _showData($data,&$R){ $ret = ''; $ret .= '