source: extensions/oAuth/maintain.inc.php @ 26619

Last change on this file since 26619 was 26619, checked in by mistic100, 10 years ago

move "oauth_id" field to user + display 16px icon on users list

File size: 2.5 KB
Line 
1<?php
2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
3
4class oAuth_maintain extends PluginMaintain
5{
6  private $installed = false;
7 
8  private $default_conf = array(
9    'display_menubar' => true,
10    'display_register' => true,
11    'identification_icon' => '38px',
12    'menubar_icon' => '26px',
13    );
14   
15  private $file;
16 
17  function __construct($plugin_id)
18  {
19    parent::__construct($plugin_id);
20   
21    $this->file = PWG_LOCAL_DIR . 'config/hybridauth.inc.php';
22  }
23
24  function install($plugin_version, &$errors=array())
25  {
26    global $conf;
27
28    if (empty($conf['oauth']))
29    {
30      $conf['oauth'] = serialize($this->default_conf);
31      conf_update_param('oauth', $conf['oauth']);
32    }
33   
34    $result = pwg_query('SHOW COLUMNS FROM `' . USER_INFOS_TABLE . '` LIKE "oauth_id";');
35    if (!pwg_db_num_rows($result))
36    {
37      pwg_query('ALTER TABLE `' . USER_INFOS_TABLE . '` ADD `oauth_id` VARCHAR(255) DEFAULT NULL;');
38    }
39   
40    // move field from users table to user_infos
41    $result = pwg_query('SHOW COLUMNS FROM `' . USERS_TABLE . '` LIKE "oauth_id";');
42    if (pwg_db_num_rows($result))
43    {
44      $query = '
45UPDATE `' . USER_INFOS_TABLE . '` AS i
46  SET oauth_id = (
47    SELECT oauth_id
48      FROM `' . USERS_TABLE . '` AS u
49      WHERE u.'.$conf['user_fields']['id'].' = i.user_id
50    )
51;';
52      pwg_query($query);
53     
54      pwg_query('ALTER TABLE `' . USERS_TABLE . '` DROP `oauth_id`;');
55    }
56   
57    // add fields in hybridauth conf file
58    if (file_exists($this->file))
59    {
60      $hybridauth_conf = include($this->file);
61      if (!isset($hybridauth_conf['total']))
62      {
63        $enabled = array_filter($hybridauth_conf['providers'], create_function('$p', 'return $p["enabled"];'));
64       
65        $hybridauth_conf['total'] = count($hybridauth_conf['providers']);
66        $hybridauth_conf['enabled'] = count($enabled);
67       
68        $content = "<?php\ndefined('PHPWG_ROOT_PATH') or die('Hacking attempt!');\n\nreturn ";
69        $content.= var_export($hybridauth_conf, true);
70        $content.= ";\n?>";
71       
72        file_put_contents($this->file, $content);
73      }
74    }
75
76    $this->installed = true;
77  }
78
79  function activate($plugin_version, &$errors=array())
80  {
81    if (!$this->installed)
82    {
83      $this->install($plugin_version, $errors);
84    }
85  }
86
87  function deactivate()
88  {
89  }
90
91  function uninstall()
92  {
93    conf_delete_param('oauth');
94
95    pwg_query('ALTER TABLE `'. USER_INFOS_TABLE .'` DROP `oauth_id`;');
96   
97    @unlink($this->file);
98  }
99}
Note: See TracBrowser for help on using the repository browser.