1<?php 2/** 3 * Created by PhpStorm. 4 * User: z97 5 * Date: 15-6-9 6 * Time: 下午2:28 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_block extends DokuWiki_Syntax_Plugin { 13 private $pg_count=0; 14 protected $entry_pattern = '<BK.*?>(?=.*?</BK>)'; 15 protected $exit_pattern = '</BK>'; 16 function getType(){ return 'substition';} 17 function getPType(){ return 'block';} 18 public function getSort() { return 322; } 19 public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); } 20 public function connectTo($mode) { $this->Lexer->addEntryPattern($this->entry_pattern,$mode,'plugin_pagestat_block'); } 21 public function postConnect() { $this->Lexer->addExitPattern($this->exit_pattern,'plugin_pagestat_block'); } 22 23 24 25 /* 26 public function connectTo($mode) { $this->Lexer->addEntryPattern($this->entry_pattern,$mode,'plugin_pagestat_'.$this->getPluginComponent());} 27 public function connectTo($mode) { $this->Lexer->addSpecialPattern('<PT.*?>',$mode,'plugin_now');} 28 function connectTo($mode) { $this->Lexer->addEntryPattern('\+\+\+\+.*?\|(?=.*\+\+\+\+)',$mode,'plugin_folded_div'); } 29 */ 30 public function handle($match, $state, $pos, Doku_Handler $handler){ 31 switch ($state) { 32 case DOKU_LEXER_ENTER : 33 $match = trim(substr($match,3,-1)); 34 $arg_list = explode(" ",$match); 35 $this->pg_count=$this->pg_count+1; 36 return array($state, $arg_list,$this->pg_count-1); 37 38 case DOKU_LEXER_UNMATCHED : return array($state, $match); 39 case DOKU_LEXER_EXIT : return array($state, ''); 40 } 41 return array(); 42 } 43 44 public function render($mode, Doku_Renderer $renderer, $data) { 45 // $data is what the function handle() return'ed. 46 if($mode == 'xhtml'){ 47 /** @var Doku_Renderer_xhtml $renderer */ 48 list($state,$match,$count) = $data; 49 switch ($state) { 50 case DOKU_LEXER_ENTER : 51 $arg_list = $match; 52 $length = count($arg_list); 53 if($length<1){ 54 break; 55 } 56 $subname=$arg_list[0]; 57 $arg_count=1; 58 $type_class=""; 59 for($i=1;$i<$length;$i++){ 60 $tmp_arg=explode("=",$arg_list[$i]); 61 if($tmp_arg[0]=="type"){ 62 $type_class="xxbk_type_$tmp_arg[1]"; 63 } 64 } 65 $xx_arg=implode(";",array_slice($arg_list,1)); 66// $str = '<div class="xxpg xxpg_'.$match.'" id="xxpg_'.$match+$count.'"></div>'; 67 68 $str2 =<<<STRRR 69<div class="xxbk xxbk_$subname $type_class" id="xxbk_$subname$count" command="$subname" xx_arg="$xx_arg" arg_count="$length" init="n" 70STRRR; 71 72 $renderer->doc .= $str2.' >'; 73 break; 74 75 case DOKU_LEXER_UNMATCHED : 76 $renderer->doc .= $renderer->_xmlEntities($match); 77 break; 78 case DOKU_LEXER_EXIT : 79 $renderer->doc .= "</div>"; 80 break; 81 } 82 return true; 83 } 84 return false; 85 } 86 87 88}