nodisp Plugin

Compatible with DokuWiki

  • 2012-01-25 "Angua" unknown
  • 2011-05-25 "Rincewind" yes
  • 2010-11-07 "Anteater" yes

plugin Hide text from view except from admin or manager

Last updated on
2011-05-23
Provides
Syntax
Repository
Source

Similar to ifauth

Tagged with hide

Installation

Download syntax.php from the source code below and install it in the folder: plugins/nodisp

Refer to Plugins on how to install plugins manually.

Examples/Usage

This plugin will conceal text from all viewers except users who are logged in and belong to either the admin or manager group.

You should include ~~NOCACHE~~ in files which use this plugin. See Caching.

Syntax

<nodisp> your text here </nodisp>
<nodisp>
your text here
and your text here
and here
etc
</nodisp>

Configuration and Settings

Recommended: should use ~~NOCACHE~~

Development

Source Code

To download, click on syntax.php at the top of the code block below.

syntax.php
  <?php
 
    // must be run within DokuWiki
    if(!defined('DOKU_INC')) die();
 
    if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
    require_once(DOKU_PLUGIN.'syntax.php');
 
    /**
     * All DokuWiki plugins to extend the parser/rendering mechanism
     * need to inherit from this class
     */
    class syntax_plugin_nodisp extends DokuWiki_Syntax_Plugin {
 
        /**
         * return some info
         */
        function getInfo(){
            return array(
                'author' => 'Myron Turner',
                'email'  => 'turnermm02 AT shaw DOT ca',
                'date'   => '2010-03-19',
                'name'   => 'nodisp Plugin',
                'desc'   => 'hides display of enclosed text',
                'url'    => 'http://www.mturner.org',
            );
        }
 
        function getType(){ return 'formatting'; }
        function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }   
        function getSort(){ return 168; }
        function connectTo($mode) { $this->Lexer->addEntryPattern('<nodisp.*?>(?=.*?</nodisp>)',$mode,'plugin_nodisp'); }
        function postConnect() { $this->Lexer->addExitPattern('</nodisp>','plugin_nodisp'); }
 
 
        /**
         * Handle the match
         */
        function handle($match, $state, $pos, &$handler){
 
 
            switch ($state) {
              case DOKU_LEXER_ENTER : 
               return array($state, false);
 
              case DOKU_LEXER_UNMATCHED :  return array($state, $match);
              case DOKU_LEXER_EXIT :       return array($state, '');
            }
 
            return array();
        }
 
        /**
         * Create output
         */
        function render($mode, &$renderer, $data) {
            global $INFO;
            if($mode == 'xhtml'){
                list($state, $match) = $data;
                switch ($state) {
                  case DOKU_LEXER_ENTER :  
                    if($INFO['isadmin'] || $INFO['ismanager'] ) break;   
                    $renderer->doc .= "<span style='display:none'>"; 
                    break;
 
                  case DOKU_LEXER_UNMATCHED :  $renderer->doc .= $renderer->_xmlEntities($match); break;
                  case DOKU_LEXER_EXIT : 
                    if($INFO['isadmin'] || $INFO['ismanager'] ) break;   
                    $renderer->doc .= "</span>"; break;
                }
                return true;
            }
            return false;
        }
 
 
 
}

Change Log

Known Bugs and Issues

Discussion

plugin/nodisp.txt · Last modified: 2012/03/20 12:29 by 124.170.15.6
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate