<?php
 
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');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_isns extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'iDo',
            'email'  => 'iDo@woow-fr.com',
            'date'   => '18.01.2006',
            'name'   => 'isns Plugin',
            'desc'   => 'If the page doesnt exist, try to open the index. The syntax: {{isns}}',
            'url'    => 'https://www.dokuwiki.org/plugin:isns',
        );
    }
    
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 1;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern("{{isns}}",$mode,'plugin_isns');
    }
      
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        return true;
    }  
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){ 
            $n=$this->_IsNs();
            if (@$n)
                $renderer->doc = $n;
            return true;
        }
        return false;
    }

    function _IsNs() {
        global $conf;
        global $ID;
        $pn=wikiFN($ID);
        if ((!file_exists($pn)) && (is_dir(substr($pn,0,-4)))) {
            ob_start();
            html_index($ID);
            return ob_get_clean();;
        }
        return false;
    }
}

//Setup VIM: ex: et ts=4 enc=utf-8 :