summaryrefslogtreecommitdiffstats
path: root/modules-available/baseconfig/inc/baseconfigutil.inc.php
blob: ebaefbcf18c06ef066b9738e8f1bac3a5bdc87f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

class BaseConfigUtil
{

	/**
	 * Return all config variables to be handled directly by the baseconfig edit module.
	 * The array will contain a list of mapping of type:
	 * VARNAME => array(
	 *     catid => xx,
	 *     defaultvalue => xx,
	 *     permissions => xx,
	 *     validator => xx,
	 * )
	 *
	 * @return array all known config variables
	 */
	public static function getVariables()
	{
		$settings = array();
		foreach (glob('modules/*/baseconfig/settings.json', GLOB_NOSORT) as $file) {
			$data = json_decode(file_get_contents($file), true);
			if (!is_array($data))
				continue;
			preg_match('#^modules/([^/]+)/#', $file, $out);
			foreach ($data as &$entry) {
				$entry['module'] = $out[1];
			}
			$settings += $data;
		}
		return $settings;
	}

	public static function getCategories()
	{
		$categories = array();
		foreach (glob('modules/*/baseconfig/categories.json', GLOB_NOSORT) as $file) {
			$data = json_decode(file_get_contents($file), true);
			if (!is_array($data))
				continue;
			preg_match('#^modules/([^/]+)/#', $file, $out);
			foreach ($data as &$entry) {
				$entry = array('module' => $out[1], 'sortpos' => $entry);
			}
			$categories += $data;
		}
		return $categories;
	}

}