1 | <?php |
---|
2 | defined('OAUTH_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | load_language('help.lang', OAUTH_PATH); |
---|
5 | |
---|
6 | $PROVIDERS_CONFIG = include(OAUTH_PATH . 'include/providers_stats.inc.php'); |
---|
7 | |
---|
8 | if (isset($_POST['save_config'])) |
---|
9 | { |
---|
10 | $providers = array(); $count_enabled = 0; |
---|
11 | foreach ($_POST['providers'] as $id => $data) |
---|
12 | { |
---|
13 | $data['enabled'] = $data['enabled']=='true'; |
---|
14 | if ($data['enabled']) $count_enabled++; |
---|
15 | |
---|
16 | if ($PROVIDERS_CONFIG[$id]['new_app_link'] and $data['enabled']) |
---|
17 | { |
---|
18 | if (empty($data['keys']['secret']) or |
---|
19 | (@$PROVIDERS_CONFIG[$id]['require_client_id'] and empty($data['keys']['id'])) or |
---|
20 | (!@$PROVIDERS_CONFIG[$id]['require_client_id'] and empty($data['keys']['key'])) |
---|
21 | ) { |
---|
22 | $page['errors'][] = l10n('%s: invalid keys', $PROVIDERS_CONFIG[$id]['name']); |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | if (isset($PROVIDERS_CONFIG[$id]['scope'])) |
---|
27 | { |
---|
28 | $data['scope'] = $PROVIDERS_CONFIG[$id]['scope']; |
---|
29 | } |
---|
30 | |
---|
31 | if (is_array(@$data['keys'])) |
---|
32 | { |
---|
33 | $data['keys'] = array_map('trim', $data['keys']); |
---|
34 | } |
---|
35 | |
---|
36 | $data['name'] = $PROVIDERS_CONFIG[$id]['name']; |
---|
37 | $providers[$id] = $data; |
---|
38 | } |
---|
39 | |
---|
40 | $hybridauth_conf['providers'] = $providers; |
---|
41 | $hybridauth_conf['total'] = count($hybridauth_conf['providers']); |
---|
42 | $hybridauth_conf['enabled'] = $count_enabled; |
---|
43 | |
---|
44 | if (!count($page['errors'])) |
---|
45 | { |
---|
46 | // generate config file |
---|
47 | $content = "<?php\ndefined('PHPWG_ROOT_PATH') or die('Hacking attempt!');\n\nreturn "; |
---|
48 | $content.= var_export(array_intersect_key($hybridauth_conf, array_flip(array('providers','total','enabled'))), true); |
---|
49 | $content.= ";\n?>"; |
---|
50 | |
---|
51 | file_put_contents(OAUTH_CONFIG, $content); |
---|
52 | $page['infos'][] = l10n('Information data registered in database'); |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | $template->assign(array( |
---|
58 | 'PROVIDERS' => $PROVIDERS_CONFIG, |
---|
59 | 'CONFIG' => $hybridauth_conf['providers'], |
---|
60 | 'SERVERNAME' => get_servername(), |
---|
61 | 'WEBSITE' => get_absolute_root_url(), |
---|
62 | 'OAUTH_CALLBACK' => OAUTH_PUBLIC . '?hauth.done=', |
---|
63 | )); |
---|
64 | |
---|
65 | // define template file |
---|
66 | $template->set_filename('oauth_content', realpath(OAUTH_PATH . 'admin/template/providers.tpl')); |
---|