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
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12
13class helper_plugin_multilingual extends DokuWiki_Plugin {
14
15    var $trans = array(); // List of enabled translations
16
17    /**
18     * Initialize
19     */
20    function helper_plugin_multilingual(){
21        require_once(DOKU_INC.'inc/pageutils.php');
22        require_once(DOKU_INC.'inc/utf8.php');
23
24        // load wanted translation into array
25        $this->trans = strtolower(str_replace(',',' ',$this->getConf('enabled_langs')));
26        $this->trans = array_unique(array_filter(explode(' ',$this->trans)));
27        sort($this->trans);
28    }
29
30    /**
31     * return some info
32     */
33    function getInfo(){
34        return confToHash(dirname(__FILE__).'/info.txt');
35    }
36
37    /**
38     * Retrun an array of this dokuwiki's supported languages. Note that
39     * this is not the same as conf['enabled_langs']
40     */
41    function getSupportedLanguages() {
42        $supportedLanguages = array();
43	if ($handle = opendir(DOKU_INC.'inc/lang')) {
44	    while (false !== ($file = readdir($handle))) {
45	        if (is_dir(DOKU_INC.'inc/lang/'.$file)) {
46		    array_push($supportedLanguages,$file);
47		}
48	    }
49	    closedir($handle);
50	}
51	return $supportedLanguages;
52    }
53    /**
54     * Builds a link, either text or graphical depending on the configuration.
55     */
56    function buildTransLink($lng,$idpart){
57        global $conf;
58        global $saved_conf;
59	global $ID;
60
61       /***********************
62        * Setup
63        **********************/
64        $link = ':'.$lng.':'.$idpart;
65	$name = $lng;
66        $exists = true;
67
68       /***********************
69	 * Flags
70	 **********************/
71        if(file_exists(DOKU_PLUGIN.'multilingual/flags/langnames.php') && $this->getConf('flags')) {
72          require(DOKU_PLUGIN.'multilingual/flags/langnames.php');
73          if(file_exists(DOKU_PLUGIN.'multilingual/flags/'.$langflag[$name])){
74            $flag['title'] = $langname[$name];
75            $flag['src'] = DOKU_URL.'lib/plugins/multilingual/flags/'.$langflag[$name];
76            resolve_pageid(getNS($ID),$link,$exists);
77
78            return array($link,$flag,$exists);
79          }
80        }
81
82        /***********************
83	 * Default Fallback
84	 **********************/
85        return array($link,$name,$exists);
86    }
87}
88