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