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