source: extensions/oAuth/admin/config.php @ 20301

Last change on this file since 20301 was 20301, checked in by mistic100, 11 years ago

clean code

File size: 2.3 KB
Line 
1<?php
2defined('OAUTH_PATH') or die('Hacking attempt!');
3
4$PROVIDERS_CONFIG = include(OAUTH_PATH . 'include/providers_stats.inc.php');
5
6if (isset($_POST['save_config']))
7{
8  // providers config
9  array_walk_recursive($_POST, 'trim');
10 
11  $providers = array();
12  foreach ($_POST['providers'] as $id => $data)
13  {
14    $error = false;
15    $data['enabled'] = $data['enabled']=='true';
16   
17    if ($PROVIDERS_CONFIG[$id]['new_app_link'] and $data['enabled'])
18    {
19      if (empty($data['keys']['secret']) or
20        (@$PROVIDERS_CONFIG[$id]['require_client_id'] and empty($data['keys']['id'])) or
21        (!@$PROVIDERS_CONFIG[$id]['require_client_id'] and empty($data['keys']['key']))
22      ) {
23        array_push($page['errors'], sprintf(l10n('%s: invalid keys'), $PROVIDERS_CONFIG[$id]['provider_name']));
24        $error = true;
25      }
26    }
27    else
28    {
29      unset($data['keys']);
30    }
31   
32    if ( ($id=='Wordpress' or $id=='Flickr') and $data['enabled'] and !@$providers['OpenID']['enabled'] )
33    {
34      array_push($page['errors'], sprintf(l10n('OpenID must be enabled in order to use %s authentication'), $id));
35      $error = true;
36    }
37   
38    if (isset($PROVIDERS_CONFIG[$id]['scope']))
39    {
40      $data['scope'] = $PROVIDERS_CONFIG[$id]['scope'];
41    }
42   
43    if (!$error)
44    {
45      $providers[$id] = $data;
46    }
47  }
48 
49  if (!count($page['errors']))
50  {
51    // generate config file
52    $hybridauth_conf['providers'] = $providers;
53    $content = "<?php\ndefined('PHPWG_ROOT_PATH') or die('Hacking attempt!');\n\nreturn ";
54    $content.= var_export(array('providers'=>$providers), true);
55    $content.= ";\n?>";
56    file_put_contents(OAUTH_CONFIG, $content);
57 
58    // plugin config
59    $conf['oauth'] = array(
60      'display_register' => isset($_POST['display_register']),
61      'display_menubar' => isset($_POST['display_menubar']),
62      );
63     
64    conf_update_param('oauth', serialize($conf['oauth']));
65    array_push($page['infos'], l10n('Information data registered in database'));
66  }
67}
68
69
70$template->assign(array(
71  'PROVIDERS' => $PROVIDERS_CONFIG,
72  'CONFIG' => $hybridauth_conf['providers'],
73  'SERVERNAME' => get_absolute_root_url(),
74  'OAUTH_CALLBACK' => OAUTH_PUBLIC . '?hauth.done=',
75  ));
76$template->assign($conf['oauth']);
77
78// define template file
79$template->set_filename('oauth_content', realpath(OAUTH_PATH . 'admin/template/config.tpl'));
80
81?>
Note: See TracBrowser for help on using the repository browser.