[ Index ]

PHP Cross Reference of Jalakai Designs - DokuWiki Plugins & Templates

title

Body

[close]

/dokuwiki/plugins/folded/syntax/ -> div.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_div extends DokuWiki_Syntax_Plugin {
  30  
  31     /**
  32      * return some info
  33      */
  34      function getInfo(){
  35          return array(
  36              'author' => 'Fabian van-de-l_Isle',
  37              'email'  => 'webmaster@lajzar.co.uk',
  38              'date'   => '2006-12-10',
  39              'name'   => 'Folded Plugin - Block',
  40              'desc'   => 'Enable blocks of folded text. 
  41                           Syntax: ++++title|folded content++++',
  42              'url'    => 'http://wiki.splitbrain.org/plugin:folded',
  43          );
  44      }
  45  
  46      function getType(){ return 'container'; }
  47      function getPType() { return 'block'; }
  48      function getAllowedTypes() { return array('container','substition','protected','disabled','formatting'); }
  49      function getSort(){ return 404; }
  50      function connectTo($mode) { $this->Lexer->addEntryPattern('\+\+\+\+.*?\|(?=.*\+\+\+\+)',$mode,'plugin_folded_div'); }
  51      function postConnect() { $this->Lexer->addExitPattern('\+\+\+\+','plugin_folded_div'); }
  52  
  53     /**
  54      * Handle the match
  55      */
  56      function handle($match, $state, $pos, &$handler){
  57          if ($state == DOKU_LEXER_ENTER){
  58              $match = trim(substr($match,4,-1)); // strip markup
  59              $handler->status['plugin_folded'] = true;
  60  
  61              if (!$this->register_hook) {
  62  
  63                global $EVENT_HANDLER;
  64                $EVENT_HANDLER->register_hook('PARSER_HANDLER_DONE','BEFORE', $this, 'add_writestrings');
  65  
  66                $this->register_hook = true;
  67              }
  68          }
  69          return array($state, $match);
  70      }
  71  
  72     /**
  73      * Create output
  74      */
  75      function render($mode, &$renderer, $data) {
  76          global $plugin_folded_count;
  77  
  78          list($state, $cdata) = $data;
  79  
  80          if($mode == 'xhtml') {
  81              switch ($state){
  82                case DOKU_LEXER_ENTER:
  83                  $plugin_folded_count++;
  84                  $renderer->doc .= '<p><a class="folder" href="#folded_'.$plugin_folded_count.'">';
  85  
  86                  if ($cdata)
  87                      $renderer->doc .= ' '.$renderer->_xmlEntities($cdata);
  88  
  89                  $renderer->doc .= '</a></p><div class="folded hidden" id="folded_'.$plugin_folded_count.'">';
  90                  break;
  91  
  92                case DOKU_LEXER_UNMATCHED:
  93                  $renderer->doc .= $renderer->_xmlEntities($cdata);
  94                  break;
  95  
  96                case DOKU_LEXER_EXIT:
  97                  $renderer->doc .= '</div>';
  98                  break;
  99  
 100                case 'WRITE_STRINGS' :
 101                  if (!$plugin_folded_strings_set) {
 102  
 103                    $hide = $this->getConf('hide') ? $this->getConf('hide') : $this->getLang('hide');
 104                    $reveal = $this->getConf('reveal') ? $this->getConf('reveal') : $this->getLang('reveal');
 105  
 106                    $renderer->doc .= '<span id="folded_reveal" style="display:none;"><!-- '.hsc($reveal).' --></span>';
 107                    $renderer->doc .= '<span id="folded_hide" style="display:none;"><!-- '.hsc($hide).' --></span>';
 108  
 109                    $plugin_folded_strings_set = true;
 110                  }
 111              }
 112              return true;
 113          }
 114          return false;
 115      }
 116  
 117      function add_writestrings(&$event, $param) {
 118  
 119        if (isset($event->plugin_folded)) return;
 120  
 121        // make sure the event is being generated for the handler instance we expect
 122        $handler =& $event->data;
 123        if (empty($handler->status['plugin_folded'])) return;
 124  
 125        // add WRITE_STRINGS instruction to the end of the instruction list
 126        $last_call = end($handler->calls);
 127        array_push($handler->calls, array('plugin', array('folded_span', array('WRITE_STRINGS',0), DOKU_LEXER_MATCHED), $last_call[2]));
 128  
 129        // prevent multiple handling of this event by folded plugin components
 130        $event->plugin_folded = true;
 131      }
 132  }


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