1<?php /* vim: set noet ts=4 sw=4 ft=php: : */
2
3define('USERGROUP_JSON_URL', 'http://php.ug/api/rest/listtype.json/1');
4
5function usergroups_update_infos($root)
6{
7    /*
8     * Fetch Usergroup-Informations
9     */
10    $nameOfUgCacheFile = $root . "/backend/usergroups.json";
11    // Get the complete list of usergroups.
12    fetch_into_file(USERGROUP_JSON_URL, $nameOfUgCacheFile);
13
14    $usergroups = json_decode(file_get_contents($nameOfUgCacheFile), true);
15    foreach($usergroups['groups'] as $group) {
16
17        if (! isset($group['icalendar_url'])) {
18            continue;
19        }
20        $url = $group['icalendar_url'];
21        $usergroupIcalFileCache = $root . "/backend/events/" . md5($url);
22        if (strncmp("webcal://", $url, strlen("webcal://")) == 0) {
23            $url = str_replace("webcal://", "http://", $url);
24        }
25        fetch_into_file($url, $usergroupIcalFileCache);
26    }
27}
28