Plugin dokuwiki xterm2 UPDATED php7.0

< xterm2 >

linux:/home/zabbix$ ls -l | grep
drwxr-xr-x  2 zabbix zabbix   4096 Mar 23  2004 autom4te.cache
drwxr-xr-x  2 zabbix zabbix   4096 Oct  4  2004 bin
drwxr-xr-x  5 zabbix zabbix   4096 Mar 23  2004 create
drwxr-xr-x  2 zabbix zabbix   4096 Mar 23  2004 doc

< xterm2 root >

linux:/home/zabbix$ ls -l | grep
drwxr-xr-x  2 zabbix zabbix   4096 Mar 23  2004 autom4te.cache
drwxr-xr-x  2 zabbix zabbix   4096 Oct  4  2004 bin
drwxr-xr-x  5 zabbix zabbix   4096 Mar 23  2004 create
drwxr-xr-x  2 zabbix zabbix   4096 Mar 23  2004 doc

ls


xterm2 plugin

—- plugin —- description:

UPDATED 2017.06.19 fix php7

Download and install the plugin using the Plugin Manager using the following URL. Refer to Plugins on how to install plugins manually.

<?php
/**
 * Add Note capability to dokuwiki
 *
 * <xterm2>This is a console</xterm2>
 * <xterm2 root>This is a ROOT console</xterm2>
 *
 * Authors of the note plugin
 *----------------------------*
 * by Olivier Cortès <olive@deep-ocean.net>
 * under the terms of the GNU GPL v2.
 *
 * Originaly derived from the work of :
 * Stephane Chamberland <stephane.chamberland@ec.gc.ca> (Side Notes PlugIn)
 * Carl-Christian Salvesen <calle@ioslo.net> (Graphviz plugin)
 *
 * Contributions by Eric Hameleers <alien [at] slackware [dot] com> :
 *   use <div> instead of <table>,
 *   contain the images and stylesheet inside the plugin,
 *   permit nesting of notes,
 *
 * Contributed by Christopher Smith <chris [at] jalakai [dot] co [dot] uk>
 *   fix some parsing problems and a security hole.
 *   make note types case independent
 *   simplify code reading
 *   modernise the plugin for changes/fixes/improvements to the underlying Dokuwiki plugin class,
 *   improve efficiency.
 *
 * Contributed by Aurélien Bompard <aurelien [at] bompard [dot] org>
 *   support for the ODT output format.
 *
 * @license    GNU_GPL_v2
 * @author     Olivier Cortes <olive@deep-ocean.net>
 *
 * UPDATE 2017-06-17 FIX  "Doku_Handler"  error
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
 
class syntax_plugin_xterm2 extends DokuWiki_Syntax_Plugin {
 
    var $notes = array(
                'xterm2user'    => array('', 'user'),
                'xterm2root'    => array('root', 'admin')
      );
 
    var $default = 'xterm2user';
 
    function getInfo(){
        return array(
            'author' => 'Olivier Cortès / Eric Hameleers / Christopher Smith / Aurélien Bompard',
            'email'  => 'olive@deep-ocean.net',
            'date'   => '2006-03-29',
            'name'   => 'Xterm2 Plugin',
            'desc'   => 'Add console root or user Capability <xterm2 root> for root console(DIV+CSS box)\n Adapted by Xarkam',
            'url'    => 'http://wiki.splitbrain.org/plugin:xterm2',
        );
    }
 
 
    function getType(){ return 'container'; }
    function getPType(){ return 'normal'; }
    function getAllowedTypes() {
        return array('container','substition','protected','disabled','formatting','paragraphs');
    }
    function getSort(){ return 195; }
 
    // override default accepts() method to allow nesting
    // - ie, to get the plugin accepts its own entry syntax
    function accepts($mode) {
      if ($mode == substr(get_class($this), 7)) return true;
        return parent::accepts($mode);
      }
 
    function connectTo($mode) {
        $this->Lexer->addEntryPattern('<xterm2.*?>(?=.*?</xterm2>)',$mode,'plugin_xterm2');
    }
    function postConnect() {
        $this->Lexer->addExitPattern('</xterm2>','plugin_xterm2');
    }
 
//    function handle($match, $state, $pos, $handler){
 function handle($match, $state, $pos, Doku_Handler $handler){
        switch ($state) {
 
          case DOKU_LEXER_ENTER :
            $note = strtolower(trim(substr($match,7,-1)));
 
            foreach( $this->notes as $class => $names ) {
              if (in_array($note, $names))
                return array($state, $class);
            }
 
            return array($state, $this->default);
 
          case DOKU_LEXER_UNMATCHED :
            return array($state, $match);
 
          default:
            return array($state);
        }
    }
 
    function render($mode, Doku_Renderer $renderer, $indata) {
 
        if($mode == 'xhtml'){
 
          list($state, $data) = $indata;
 
          switch ($state) {
            case DOKU_LEXER_ENTER :
              $renderer->doc .= '<pre class="'.$data.'">';
              break;
 
            case DOKU_LEXER_UNMATCHED :
              $renderer->doc .= $renderer->_xmlEntities($data);
              break;
 
            case DOKU_LEXER_EXIT :
              $renderer->doc .= "</pre>";
              break;
          }
          return true;
 
        }
        // unsupported $mode
        return false;
    }
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>
 
 
  • This is my first attempt at a DokuWiki plugin, and although it works for fine for my purposes, I'm sure it could be written more cleanly. Please feel free to comment or point out my errors. Tom Trenker
  • Would it be better to allow any formatting within the xterm by instead of matching the whole lot in DOKULEXERUNMATCHED to use the rest of the state cases as normal and have getAllowedTypes return array('formatting') ? I'd like to have italics too for example. – Mike Battersby
  • I tried your suggestion. It seems to work well. See the above code. Tom Trenker
  • I'd strongly suggest to generate valid XHTML code. Not only is the FONT tag deprecated for ages (and not allowed at all in XHTML, see XHTML1 DTD), but also all tag attributes have to be enclosed in quotes (either single or double quotes). Matthias Watermann
I think replacing the //<pre><font size=+0>// with //<pre class="code">//, and dropping the //</font>// will bring the code into XHTML compliance. [[ronaldb64@gmail.com|Ronald Bruintjes]]
  • there seems to be a bug in that formatting markup tries to span %%<xterm>%% blocks. E.g., if you have <code> <xterm>this has two slashes</xterm> some text here <xterm>another two slashes in later block</xterm> </code> then the whole lot will be merged into one xterm block. :( – Mike Battersby
    • You're right, this is a serious bug. I tried a few changes with no success. I'm hoping that I might be able to fix the problem with a different addEntryPattern. Any suggestions would be appreciated. Tom Trenker
    • I think this is a wiki bug in general rather than with xterm. For example, if you put // into one list item and another // into a later list item, the two will be merged. It might be to do with the URL detection code. Perhaps you can lodge this as a wiki bug? – Mike Battersby
    No its not (really) a bug and its not related to URL detection. DokuWiki doesn't verify that your markup makes sense. Markup must be properly nested to work correctly in all circumstances. So the correct markup is <code>

    <

    xterm>this has two slashes</xterm> some text here <xterm>another two slashes in later block</xterm> </code> Now nesting is correctly preserved. In technical terms, when you enter a new formatting mode (e.g. %%) the exit pattern of the earlier mode (e.g. </xterm>%%) is no longer recognised. The exit pattern won't be a recognizable pattern until either that mode is entered again or we exit the new mode. — Christopher Smith 2006-01-05 12:09 * How i can change the background color of box ? Alessandro Celli 2006-06-21 15:20 * You can modify style.css to achieve a number of effects. The following is copied from the file tag: <code> /* code blocks by xterm tag */ div.dokuwiki pre.xterm { font-family:MiscFixed; white-space:pre; padding: 0.5em; border: 1px dashed medium; color: Black; background-color: medium; overflow: auto; } </code> * xterm does not support the embedded HTML? i have try to use this: <html><font color=“blue” size=“+1”>CHOOSE</font></html> Alessandro Celli 2006-06-22 12:08 * I updated the xterm plugin to work with DokuWiki-2006-03-09.tgz, and I also implemented the use of CSS which will hopefully ensure XHTML compliance. Tom Trenker 2006-08-27 * 20060913: I made a minor modification to syntax.php to disable typography substitution by removing 'substition' from the getAllowedTypes() function call. Tom Trenker —- Hi thank you very much for this plugin. Here is a possible design for a real terminal look: /lib/tpl/YOUR_TEMPLATE/layout.css <code> /* code blocks by xterm tag */ div.dokuwiki pre.xterm { font-family:“Lucida Console”,Monospace,“DejaVu Sans Mono”,“Courier New”,MiscFixed; font-size: 12px; white-space:pre; padding: 0.5em; border: 2px solid 000000; color: FFFFFF; background-color:#3F3F3F; overflow: auto; } </code> /lib/plugin/xterm/style.css <code> .xterm { font-family:“Lucida Console”,Monospace,“DejaVu Sans Mono”,“Courier New”,MiscFixed; font-size: 12px; white-space:pre; padding: 0.5em; border: 2px solid 000000; color: FFFFFF; background-color:#3F3F3F; overflow: auto; } </code> Best regards,
    UPDATED PHP7 fix !! (see code file)