1<?php
2/**
3 * DokuWiki Plugin struct (Helper Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Szymon Olewniczak <dokuwiki@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) {
11    die();
12}
13
14class helper_plugin_ireadit extends DokuWiki_Plugin
15{
16    /**
17     * @param array $users
18     * @param array $groups
19     * @return array
20     */
21    public static function users_set($users=[], $groups=[]) {
22        global $auth;
23
24        $set = [];
25        if (empty($users) && empty($groups)) {
26            $set = $auth->retrieveUsers();
27        } else {
28            $all_users = $auth->retrieveUsers();
29            foreach ($all_users as $user => $info) {
30                if (in_array($user, $users)) {
31                    $set[$user] = $info;
32                } elseif (array_intersect($groups, $info['grps'])) {
33                    $set[$user] = $info;
34                }
35            }
36        }
37        return $set;
38    }
39
40    /**
41     * @param $user
42     * @param $meta
43     * @return bool
44     */
45    public function in_users_set($user, $meta) {
46        $users = $meta['users'];
47        $groups = $meta['groups'];
48        $users_set = self::users_set($users, $groups);
49        if (array_key_exists($user, $users_set)) {
50            return true;
51        }
52        return false;
53    }
54}
55