1<?php 2/** 3 * Date: 2015/3/14 4 * Time: 8:14 5 * 6 */ 7 8if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 10require_once(DOKU_PLUGIN . 'syntax.php'); 11 12class syntax_plugin_pagestat_edit extends DokuWiki_Syntax_Plugin { 13 private $pg_count=0; 14 function getType(){ return 'substition';} 15 function getPType(){ return 'block';} 16 public function getSort() { return 321; } 17 public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); } 18 public function connectTo($mode) { $this->Lexer->addEntryPattern('<PT.*?>(?=.*?</PT>)',$mode,'plugin_pagestat_edit'); } 19 public function postConnect() { $this->Lexer->addExitPattern('</PT>','plugin_pagestat_edit'); } 20 21 22 23/* 24 public function connectTo($mode) { $this->Lexer->addEntryPattern($this->entry_pattern,$mode,'plugin_pagestat_'.$this->getPluginComponent());} 25 public function connectTo($mode) { $this->Lexer->addSpecialPattern('<PT.*?>',$mode,'plugin_now');} 26 function connectTo($mode) { $this->Lexer->addEntryPattern('\+\+\+\+.*?\|(?=.*\+\+\+\+)',$mode,'plugin_folded_div'); } 27*/ 28 public function handle($match, $state, $pos, Doku_Handler $handler){ 29 switch ($state) { 30 case DOKU_LEXER_ENTER : 31 $match = trim(substr($match,3,-1)); 32 $arg_list = explode(" ",$match); 33 $this->pg_count=$this->pg_count+1; 34 return array($state, $arg_list,$this->pg_count-1); 35 36 case DOKU_LEXER_UNMATCHED : return array($state, $match); 37 case DOKU_LEXER_EXIT : return array($state, ''); 38 } 39 return array(); 40 } 41 42 public function render($mode, Doku_Renderer $renderer, $data) { 43 // $data is what the function handle() return'ed. 44 if($mode == 'xhtml'){ 45 /** @var Doku_Renderer_xhtml $renderer */ 46 list($state,$match,$count) = $data; 47 switch ($state) { 48 case DOKU_LEXER_ENTER : 49 $arg_list = $match; 50 $length = count($arg_list); 51 if($length<1){ 52 break; 53 } 54 $subname=$arg_list[0]; 55 $arg_count=1; 56// $str = '<div class="xxpg xxpg_'.$match.'" id="xxpg_'.$match+$count.'"></div>'; 57 58 $pt_arg=implode(";",array_slice($arg_list,1)); 59 $str2 =<<<MYSTR2 60<div class="xxpg xxpg_$subname" id="xxpg_$subname$count" pt_arg="$pt_arg" pt_arg_count="$length" > 61MYSTR2; 62 $renderer->doc .= $str2; 63 64 65 break; 66 67 case DOKU_LEXER_UNMATCHED : 68 $renderer->doc .= $renderer->_xmlEntities($match); 69 break; 70 case DOKU_LEXER_EXIT : 71 $renderer->doc .= "</div>"; 72 break; 73 } 74 return true; 75 } 76 return false; 77 } 78 79 80} 81