1 | <?php |
---|
2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | class 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 `' . USERS_TABLE . '` LIKE "oauth_id";'); |
---|
35 | if (!pwg_db_num_rows($result)) |
---|
36 | { |
---|
37 | pwg_query('ALTER TABLE `' . USERS_TABLE . '` ADD `oauth_id` VARCHAR(255) DEFAULT NULL;'); |
---|
38 | } |
---|
39 | |
---|
40 | // add fields in hybridauth conf file |
---|
41 | if (file_exists($this->file)) |
---|
42 | { |
---|
43 | $hybridauth_conf = include($this->file); |
---|
44 | if (!isset($hybridauth_conf['total'])) |
---|
45 | { |
---|
46 | $enabled = array_filter($hybridauth_conf['providers'], create_function('$p', 'return $p["enabled"];')); |
---|
47 | |
---|
48 | $hybridauth_conf['total'] = count($hybridauth_conf['providers']); |
---|
49 | $hybridauth_conf['enabled'] = count($enabled); |
---|
50 | |
---|
51 | $content = "<?php\ndefined('PHPWG_ROOT_PATH') or die('Hacking attempt!');\n\nreturn "; |
---|
52 | $content.= var_export($hybridauth_conf, true); |
---|
53 | $content.= ";\n?>"; |
---|
54 | |
---|
55 | file_put_contents($this->file, $content); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | $this->installed = true; |
---|
60 | } |
---|
61 | |
---|
62 | function activate($plugin_version, &$errors=array()) |
---|
63 | { |
---|
64 | if (!$this->installed) |
---|
65 | { |
---|
66 | $this->install($plugin_version, $errors); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | function deactivate() |
---|
71 | { |
---|
72 | } |
---|
73 | |
---|
74 | function uninstall() |
---|
75 | { |
---|
76 | conf_delete_param('oauth'); |
---|
77 | |
---|
78 | pwg_query('ALTER TABLE `'. USERS_TABLE .'` DROP `oauth_id`;'); |
---|
79 | |
---|
80 | @unlink($this->file); |
---|
81 | } |
---|
82 | } |
---|