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_pref_info()
9{
10	return [
11		'name' => tra('Preference'),
12		'documentation' => 'PluginPref',
13		'description' => tra('Display content based on global preference settings'),
14		'body' => tr('Wiki text to display if conditions are met. The body may contain %0{ELSE}%1. Text after the marker
15			will be displayed if not matching the conditions.', '<code>', '</code>'),
16		'prefs' => ['wikiplugin_pref'],
17		'filter' => 'wikicontent',
18		'extraparams' => true,
19		'iconname' => 'settings',
20		'introduced' => 11,
21		'params' => [
22		],
23	];
24}
25
26function wikiplugin_pref($data, $params)
27{
28	global $prefs, $tikilib;
29	$dataelse = '';
30	if (strpos($data, '{ELSE}')) {
31		$dataelse = substr($data, strpos($data, '{ELSE}') + 6);
32		$data = substr($data, 0, strpos($data, '{ELSE}'));
33	}
34
35	$else = false;
36	foreach ($params as $prefName => $prefValue) {
37		if ($tikilib->get_preference($prefName) != $prefValue) {
38			return $dataelse;
39		}
40	}
41	return $data;
42}
43