1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8function wikiplugin_translated_info()
9{
10	return [
11		'name' => tra('Translated'),
12		'documentation' => 'PluginTranslated',
13		'description' => tra('Create multilingual links'),
14		'prefs' => [ 'feature_multilingual', 'wikiplugin_translated' ],
15		'body' => tra('[url] or ((wikiname)) or ((inter:interwiki)) (use wiki syntax)'),
16		'iconname' => 'language',
17		'introduced' => 1,
18		'params' => [
19			'lang' => [
20				'required' => true,
21				'name' => tra('Language'),
22				'description' => tra('Two letter language code of the language, example:') . ' <code>fr</code>',
23				'since' => '1',
24				'filter' => 'alpha',
25				'default' => '',
26			],
27			'flag' => [
28				'required' => false,
29				'name' => tra('Flag'),
30				'description' => tr('Country name, example:') . ' <code>France</code>',
31				'since' => '1',
32				'filter' => 'alpha',
33				'default' => '',
34			],
35		],
36	];
37}
38
39function wikiplugin_translated($data, $params)
40{
41	extract($params, EXTR_SKIP);
42	$img = '';
43
44	$h = opendir("img/flags/");
45	while ($file = readdir($h)) {
46		if (substr($file, 0, 1) != '.' and substr($file, -4, 4) == '.png') {
47			$avflags[] = substr($file, 0, strlen($file) - 4);
48		}
49	}
50	if (isset($flag)) {
51		if (in_array($flag, $avflags)) {
52			$img = "<img src='img/flags/$flag.png' width='18' height='13' vspace='0' hspace='3' alt='$lang' align='baseline' /> ";
53		}
54	}
55
56	if (! $img) {
57		$img = "( $lang ) ";
58	}
59
60	if (isset($data)) {
61		$back = $img . $data;
62	} else {
63		$back = "''no data''";
64	}
65
66	return $back;
67}
68