1<?php
2/**
3 * Translation Plugin: Simple multilanguage plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8// must be run within Dokuwiki
9if(!defined('DOKU_INC')) die();
10
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13
14class syntax_plugin_multilingual extends DokuWiki_Syntax_Plugin {
15
16    /**
17     * for th helper plugin
18     */
19    var $hlp = null;
20
21    /**
22     * Constructor. Load helper plugin
23     */
24    function syntax_plugin_multilingual(){
25        $this->hlp =& plugin_load('helper', 'multilingual');
26    }
27
28    /**
29     * return some info
30     */
31    function getInfo(){
32        return confToHash(dirname(__FILE__).'/info.txt');
33    }
34
35    /**
36     * What kind of syntax are we?
37     */
38    function getType(){
39        return 'substition';
40    }
41
42    /**
43     * Where to sort in?
44     */
45    function getSort(){
46        return 155;
47    }
48
49
50    /**
51     * Connect pattern to lexer
52     */
53    function connectTo($mode) {
54        $this->Lexer->addSpecialPattern('~~NOTRANS~~',$mode,'plugin_multilingual');
55    }
56
57
58    /**
59     * Handle the match
60     */
61    function handle($match, $state, $pos, Doku_Handler $handler){
62        return array('notrans');
63    }
64
65    /**
66     * Create output
67     */
68    function render($format, Doku_Renderer $renderer, $data) {
69        // store info in metadata
70        if($format == 'metadata'){
71            $renderer->meta['plugin']['multilingual']['notrans'] = true;
72        }
73        return false;
74    }
75
76    /**
77     * Displays the available and configured translations. Needs to be placed in the template.
78     */
79    function _showTranslations(){
80        global $ACT;
81        global $ID;
82        global $conf;
83
84        if($ACT != 'show') return;
85        if($this->hlp->tns && strpos($ID,$this->hlp->tns) !== 0) return;
86        $skiptrans = trim($this->getConf('skiptrans'));
87        if($skiptrans &&  preg_match('/'.$skiptrans.'/ui',':'.$ID)) return;
88        $meta = p_get_metadata($ID);
89        if($meta['plugin']['multilingual']['notrans']) return;
90
91        $rx = '/^'.$this->hlp->tns.'(('.join('|',$this->hlp->trans).'):)?/';
92        $idpart = preg_replace($rx,'',$ID);
93
94        $out  = '<div class="plugin_multilingual">'.NL;
95        $out .= '        <ul>'.NL;
96	/*
97        $out .= '          <li>'.NL;
98	$out .= '            <div class="li">'.NL;
99	$out .= '              <span class="curid"><a href="/doku/doku.php/en:doku_doodles" class="media" title="en:doku_doodles"><img src="/doku/lib/exe/fetch.php?w=&amp;h=&amp;cache=&amp;media=http%3A%2F%2Fsnorriheim.dnsdojo.com%2Fdoku%2Flib%2Fplugins%2Fmultilingual%2Fflags%2Fgb.gif" class="media" title="English" alt="English" /></a></span>'.NL;
100	$out .= '            </div>'.NL;
101	$out .= '          </li>'.NL;
102        $out .= '          <li>'.NL;
103	$out .= '            <div class="li">'.NL;
104	$out .= '              <a href="/doku/doku.php/ko:doku_doodles" class="media" title="ko:doku_doodles"><img src="/doku/lib/exe/fetch.php?w=&amp;h=&amp;cache=&amp;media=http%3A%2F%2Fsnorriheim.dnsdojo.com%2Fdoku%2Flib%2Fplugins%2Fmultilingual%2Fflags%2Fkr.gif" class="media" title="한국말 (Korean)" alt="한국말 (Korean)" /></a>'.NL;
105	$out .= '            </div>'.NL;
106	$out .= '          </li>'.NL;
107	*/
108	//*
109        foreach($this->hlp->trans as $t){
110	    list($link,$name,$exists) = $this->hlp->buildTransLink($t,$idpart);
111	    if ( $exists ) {
112                $out .= '          <li>'.NL;
113	 	$out .= '            <div class="li">'.NL;
114		$out .= '              '.html_wikilink($link,$name).NL;
115		$out .= '            </div>'.NL;
116		$out .= '          </li>'.NL;
117     	    } else {
118                $out .= '          <li>'.NL;
119		$out .= '            <div class="li">'.NL;
120		$out .= '              <div class="flag_not_exists">'.NL;
121		$out .= '                '.html_wikilink($link,$name).NL;
122		$out .= '              </div>'.NL;
123		$out .= '            </div>'.NL;
124		$out .= '          </li>'.NL;
125	    }
126        }
127	//*/
128	/*
129        $link = 'link';
130	$name = 'name';
131                $out .= '          <li>'.NL;
132	 	$out .= '            <div class="li">'.NL;
133		$out .= '              '.html_wikilink($link,$name).NL;
134		$out .= '            </div>'.NL;
135		$out .= '          </li>'.NL;
136	*/
137        $out .= '        </ul>'.NL;
138        $out .= '      </div>'.NL;
139
140        return $out;
141    }
142
143}
144
145//Setup VIM: ex: et ts=4 enc=utf-8 :
146