[20293] | 1 | <?php |
---|
| 2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
| 3 | |
---|
[26556] | 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', |
---|
[26626] | 13 | 'allow_merge_accounts' => true, |
---|
[26556] | 14 | ); |
---|
[26604] | 15 | |
---|
| 16 | private $file; |
---|
| 17 | |
---|
| 18 | function __construct($plugin_id) |
---|
| 19 | { |
---|
| 20 | parent::__construct($plugin_id); |
---|
| 21 | |
---|
| 22 | $this->file = PWG_LOCAL_DIR . 'config/hybridauth.inc.php'; |
---|
| 23 | } |
---|
[20293] | 24 | |
---|
[26556] | 25 | function install($plugin_version, &$errors=array()) |
---|
| 26 | { |
---|
| 27 | global $conf; |
---|
[20293] | 28 | |
---|
[26556] | 29 | if (empty($conf['oauth'])) |
---|
| 30 | { |
---|
| 31 | $conf['oauth'] = serialize($this->default_conf); |
---|
| 32 | conf_update_param('oauth', $conf['oauth']); |
---|
| 33 | } |
---|
[26626] | 34 | else |
---|
| 35 | { |
---|
| 36 | $old_conf = is_string($conf['oauth']) ? unserialize($conf['oauth']) : $conf['oauth']; |
---|
| 37 | |
---|
| 38 | if (!isset($old_conf['allow_merge_accounts'])) |
---|
| 39 | { |
---|
| 40 | $old_conf['allow_merge_accounts'] = true; |
---|
| 41 | |
---|
| 42 | $conf['oauth'] = serialize($old_conf); |
---|
| 43 | conf_update_param('oauth', $conf['oauth']); |
---|
| 44 | } |
---|
| 45 | } |
---|
[26556] | 46 | |
---|
[26619] | 47 | $result = pwg_query('SHOW COLUMNS FROM `' . USER_INFOS_TABLE . '` LIKE "oauth_id";'); |
---|
[26556] | 48 | if (!pwg_db_num_rows($result)) |
---|
[26619] | 49 | { |
---|
| 50 | pwg_query('ALTER TABLE `' . USER_INFOS_TABLE . '` ADD `oauth_id` VARCHAR(255) DEFAULT NULL;'); |
---|
[26556] | 51 | } |
---|
[26604] | 52 | |
---|
[26619] | 53 | // move field from users table to user_infos |
---|
| 54 | $result = pwg_query('SHOW COLUMNS FROM `' . USERS_TABLE . '` LIKE "oauth_id";'); |
---|
| 55 | if (pwg_db_num_rows($result)) |
---|
| 56 | { |
---|
| 57 | $query = ' |
---|
| 58 | UPDATE `' . USER_INFOS_TABLE . '` AS i |
---|
| 59 | SET oauth_id = ( |
---|
| 60 | SELECT oauth_id |
---|
| 61 | FROM `' . USERS_TABLE . '` AS u |
---|
| 62 | WHERE u.'.$conf['user_fields']['id'].' = i.user_id |
---|
| 63 | ) |
---|
| 64 | ;'; |
---|
| 65 | pwg_query($query); |
---|
| 66 | |
---|
| 67 | pwg_query('ALTER TABLE `' . USERS_TABLE . '` DROP `oauth_id`;'); |
---|
| 68 | } |
---|
| 69 | |
---|
[26626] | 70 | // add 'total' and 'enabled' fields in hybridauth conf file |
---|
[26604] | 71 | if (file_exists($this->file)) |
---|
| 72 | { |
---|
| 73 | $hybridauth_conf = include($this->file); |
---|
| 74 | if (!isset($hybridauth_conf['total'])) |
---|
| 75 | { |
---|
| 76 | $enabled = array_filter($hybridauth_conf['providers'], create_function('$p', 'return $p["enabled"];')); |
---|
| 77 | |
---|
| 78 | $hybridauth_conf['total'] = count($hybridauth_conf['providers']); |
---|
| 79 | $hybridauth_conf['enabled'] = count($enabled); |
---|
| 80 | |
---|
| 81 | $content = "<?php\ndefined('PHPWG_ROOT_PATH') or die('Hacking attempt!');\n\nreturn "; |
---|
| 82 | $content.= var_export($hybridauth_conf, true); |
---|
| 83 | $content.= ";\n?>"; |
---|
| 84 | |
---|
| 85 | file_put_contents($this->file, $content); |
---|
| 86 | } |
---|
| 87 | } |
---|
[20293] | 88 | |
---|
[26556] | 89 | $this->installed = true; |
---|
| 90 | } |
---|
[20293] | 91 | |
---|
[26556] | 92 | function activate($plugin_version, &$errors=array()) |
---|
[20293] | 93 | { |
---|
[26556] | 94 | if (!$this->installed) |
---|
| 95 | { |
---|
| 96 | $this->install($plugin_version, $errors); |
---|
| 97 | } |
---|
[20293] | 98 | } |
---|
| 99 | |
---|
[26556] | 100 | function deactivate() |
---|
| 101 | { |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | function uninstall() |
---|
| 105 | { |
---|
| 106 | conf_delete_param('oauth'); |
---|
| 107 | |
---|
[26619] | 108 | pwg_query('ALTER TABLE `'. USER_INFOS_TABLE .'` DROP `oauth_id`;'); |
---|
[26556] | 109 | |
---|
[26604] | 110 | @unlink($this->file); |
---|
[26556] | 111 | } |
---|
[20293] | 112 | } |
---|