[ Index ]

PHP Cross Reference of Jalakai Designs - DokuWiki Plugins & Templates

title

Body

[close]

/dokuwiki/plugins/folded/syntax/ -> span.php (source)

   1  <?php
   2  /**
   3   * Folded text Plugin: enables folded text font size with syntax ++ text ++
   4   *
   5   * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
   6   * @author     Fabian van-de-l_Isle <webmaster [at] lajzar [dot] co [dot] uk>
   7   * @author     Christopher Smith <chris@jalakai.co.uk>
   8   * @author     Esther Brunner <esther@kaffeehaus.ch>
   9   */
  10  
  11  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
  12  if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
  13  require_once (DOKU_PLUGIN.'syntax.php');
  14  
  15  // maintain a global count of the number of folded elements in the page, 
  16  // this allows each to be uniquely identified
  17  global $plugin_folded_count;
  18  if (!isset($plugin_folded_count)) $plugin_folded_count = 0;
  19  
  20  // global used to indicate that the localised folder link title tooltips 
  21  // strings have been written out
  22  global $plugin_folded_strings_set;
  23  if (!isset($plugin_folded_string_set)) $plugin_folded_string_set = false;
  24  
  25  /**
  26   * All DokuWiki plugins to extend the parser/rendering mechanism
  27   * need to inherit from this class
  28   */
  29  class syntax_plugin_folded_span extends DokuWiki_Syntax_Plugin {
  30  
  31     var $register_hook = false;
  32  
  33     /**
  34      * return some info
  35      */
  36      function getInfo(){
  37          return array(
  38              'author' => 'Fabian van-de-l_Isle',
  39              'email'  => 'webmaster@lajzar.co.uk',
  40              'date'   => '2006-12-10',
  41              'name'   => 'Folded Plugin – Inline',
  42              'desc'   => 'Enable inline folded text. 
  43                           Syntax: ++title|folded content++',
  44              'url'    => 'http://wiki.splitbrain.org/plugin:folded',
  45          );
  46      }
  47  
  48      function getType(){ return 'formatting'; }
  49      function getAllowedTypes() { return array('substition','protected','disabled','formatting'); }
  50      function getSort(){ return 405; }
  51      function connectTo($mode) { $this->Lexer->addEntryPattern('\+\+.*?\|(?=.*\+\+)',$mode,'plugin_folded_span'); }
  52      function postConnect() { $this->Lexer->addExitPattern('\+\+','plugin_folded_span'); }
  53  
  54     /**
  55      * Handle the match
  56      */
  57      function handle($match, $state, $pos, &$handler){
  58          if ($state == DOKU_LEXER_ENTER){
  59              $match = trim(substr($match,2,-1)); // strip markup
  60              $handler->status['plugin_folded'] = true;
  61  
  62              if (!$this->register_hook) {
  63  
  64                global $EVENT_HANDLER;
  65                $EVENT_HANDLER->register_hook('PARSER_HANDLER_DONE','BEFORE', $this, 'add_writestrings');
  66  
  67                $this->register_hook = true;
  68              }
  69          }
  70          return array($state, $match);
  71      }
  72  
  73     /**
  74      * Create output
  75      */
  76      function render($mode, &$renderer, $data) {
  77          global $plugin_folded_count, $plugin_folded_strings_set;
  78  
  79          list($state, $cdata) = $data;
  80  
  81          if($mode == 'xhtml') {
  82              switch ($state){
  83                 case DOKU_LEXER_ENTER:
  84                  $plugin_folded_count++;
  85                  $renderer->doc .= '<a class="folder" href="#folded_'.$plugin_folded_count.'">';
  86  
  87                  if ($cdata)
  88                      $renderer->doc .= ' '.$renderer->_xmlEntities($cdata);
  89  
  90                  $renderer->doc .= '</a><span class="folded hidden" id="folded_'.$plugin_folded_count.'">';
  91                  break;
  92                  
  93                case DOKU_LEXER_UNMATCHED:
  94                  $renderer->doc .= $renderer->_xmlEntities($cdata);
  95                  break;
  96                  
  97                case DOKU_LEXER_EXIT:
  98                  $renderer->doc .= '</span>';
  99                  break;
 100  
 101                case 'WRITE_STRINGS' :
 102                  if (!$plugin_folded_strings_set) {
 103  
 104                    $hide = $this->getConf('hide') ? $this->getConf('hide') : $this->getLang('hide');
 105                    $reveal = $this->getConf('reveal') ? $this->getConf('reveal') : $this->getLang('reveal');
 106  
 107                    $renderer->doc .= '<span id="folded_reveal" style="display:none;"><!-- '.hsc($reveal).' --></span>';
 108                    $renderer->doc .= '<span id="folded_hide" style="display:none;"><!-- '.hsc($hide).' --></span>';
 109  
 110                    $plugin_folded_strings_set = true;
 111                  }
 112              }
 113              return true;
 114          }
 115          return false;
 116      }
 117      
 118      function add_writestrings(&$event, $param) {
 119  
 120        if (isset($event->plugin_folded)) return;
 121  
 122        // make sure the event is being generated for the handler instance we expect
 123        $handler =& $event->data;
 124        if (empty($handler->status['plugin_folded'])) return;
 125  
 126        // add WRITE_STRINGS instruction to the end of the instruction list
 127        $last_call = end($handler->calls);
 128        array_push($handler->calls, array('plugin', array('folded_span', array('WRITE_STRINGS',0), DOKU_LEXER_MATCHED), $last_call[2]));
 129  
 130        // prevent multiple handling of this event by folded plugin components
 131        $event->plugin_folded = true;
 132      }
 133  }


Generated: Sat Dec 16 05:46:24 2006 Cross-referenced by PHPXref 0.6