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_showpref_info()
9{
10	return [
11		'name' => tra('Show Preference'),
12		'documentation' => 'PluginShowpref',
13		'description' => tra('Display the value of public global preferences'),
14		'prefs' => ['wikiplugin_showpref'],
15		'filter' => 'wikicontent',
16		'iconname' => 'cog',
17		'introduced' => 13,
18		'params' => [
19			'pref' => [
20				'required' => true,
21				'name' => tra('Preference Name'),
22				'description' => tra('Name of preference to be displayed.'),
23				'since' => '13.0',
24				'filter' => 'text',
25			],
26		],
27	];
28}
29
30function wikiplugin_showpref($data, $params)
31{
32	global $prefs;
33	$tikilib = TikiLib::lib('tiki');
34
35	$name = $params['pref'];
36	if (substr($name, 0, 3) == 'tp_') {
37		$midpos = strpos($name, '_', 3);
38		$pos = strpos($name, '_', $midpos + 1);
39		$file = substr($name, 0, $pos);
40	} elseif (false !== $pos = strpos($name, '_')) {
41		$file = substr($name, 0, $pos);
42	} else {
43		$file = 'global';
44	}
45
46	$inc_file = "lib/prefs/{$file}.php";
47	if (substr($file, 0, 3) == "tp_") {
48		$paths = \Tiki\Package\ExtensionManager::getPaths();
49		$package = str_replace('_', '/', substr($file, 3));
50		$inc_file = $paths[$package] . "/prefs/{$file}.php";
51	}
52
53	if (file_exists($inc_file)) {
54		require_once $inc_file;
55		$function = "prefs_{$file}_list";
56		if (function_exists($function)) {
57			$preffile = $function();
58		} else {
59			$preffile = [];
60		}
61	}
62
63	// Security public prefs only, you would not want all prefs to be displayed via wiki syntax
64
65	if (isset($preffile[$name]['public']) && $preffile[$name]['public']) {
66		return $tikilib->get_preference($name);
67	} else {
68		return '';
69	}
70}
71