[20293] | 1 | <?php |
---|
| 2 | /* |
---|
[20301] | 3 | Plugin Name: OAuth |
---|
[20293] | 4 | Version: auto |
---|
[20301] | 5 | Description: Provides various ways to sign in your gallery (Twitter, Facebook, Google, etc.) |
---|
[20293] | 6 | Plugin URI: auto |
---|
| 7 | Author: Mistic |
---|
| 8 | Author URI: http://www.strangeplanet.fr |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
| 12 | |
---|
[26556] | 13 | |
---|
| 14 | define('OAUTH_ID', basename(dirname(__FILE__))); |
---|
[20293] | 15 | define('OAUTH_PATH' , PHPWG_PLUGINS_PATH . OAUTH_ID . '/'); |
---|
| 16 | define('OAUTH_ADMIN', get_root_url() . 'admin.php?page=plugin-' . OAUTH_ID); |
---|
| 17 | define('OAUTH_CONFIG', PWG_LOCAL_DIR . 'config/hybridauth.inc.php'); |
---|
| 18 | define('OAUTH_PUBLIC', get_absolute_root_url() . ltrim(OAUTH_PATH,'./') . 'include/hybridauth/'); |
---|
| 19 | define('OAUTH_VERSION', 'auto'); |
---|
| 20 | |
---|
| 21 | |
---|
[26556] | 22 | // try to load hybridauth config |
---|
| 23 | global $hybridauth_conf; |
---|
[20293] | 24 | |
---|
| 25 | include_once(OAUTH_PATH . 'include/functions.inc.php'); |
---|
| 26 | |
---|
| 27 | if (file_exists(PHPWG_ROOT_PATH.OAUTH_CONFIG)) |
---|
| 28 | { |
---|
| 29 | load_hybridauth_conf(); |
---|
| 30 | } |
---|
| 31 | |
---|
[26556] | 32 | |
---|
| 33 | add_event_handler('init', 'oauth_init'); |
---|
| 34 | |
---|
[20293] | 35 | if (defined('IN_ADMIN')) |
---|
| 36 | { |
---|
| 37 | add_event_handler('get_admin_plugin_menu_links', 'oauth_admin_plugin_menu_links'); |
---|
| 38 | } |
---|
| 39 | else if (!empty($hybridauth_conf) and function_exists('curl_init')) |
---|
| 40 | { |
---|
| 41 | add_event_handler('loc_begin_identification', 'oauth_begin_identification'); |
---|
| 42 | add_event_handler('loc_begin_register', 'oauth_begin_register'); |
---|
| 43 | add_event_handler('loc_begin_profile', 'oauth_begin_profile'); |
---|
| 44 | |
---|
| 45 | add_event_handler('try_log_user', 'oauth_try_log_user', EVENT_HANDLER_PRIORITY_NEUTRAL-30, 2); |
---|
| 46 | add_event_handler('user_logout', 'oauth_logout'); |
---|
| 47 | |
---|
| 48 | add_event_handler('blockmanager_apply', 'oauth_blockmanager'); |
---|
| 49 | |
---|
| 50 | include_once(OAUTH_PATH . 'include/public_events.inc.php'); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | * plugin initialization |
---|
| 56 | */ |
---|
| 57 | function oauth_init() |
---|
| 58 | { |
---|
[26556] | 59 | global $conf, $page, $hybridauth_conf; |
---|
[20293] | 60 | |
---|
[26556] | 61 | include_once(OAUTH_PATH . 'maintain.inc.php'); |
---|
| 62 | $maintain = new oAuth_maintain(OAUTH_ID); |
---|
| 63 | $maintain->autoUpdate(OAUTH_VERSION, 'install'); |
---|
[20293] | 64 | |
---|
| 65 | load_language('plugin.lang', OAUTH_PATH); |
---|
| 66 | |
---|
| 67 | $conf['oauth'] = unserialize($conf['oauth']); |
---|
| 68 | |
---|
| 69 | // check config |
---|
| 70 | if (defined('IN_ADMIN')) |
---|
| 71 | { |
---|
[26556] | 72 | if (empty($hybridauth_conf) and strpos(@$_GET['page'],'plugin-'.OAUTH_ID)===false) |
---|
[20293] | 73 | { |
---|
[26556] | 74 | $page['warnings'][] = '<a href="'.OAUTH_ADMIN.'">'.l10n('OAuth: You need to configure the credentials').'</a>'; |
---|
[20293] | 75 | } |
---|
| 76 | if (!function_exists('curl_init')) |
---|
| 77 | { |
---|
[26556] | 78 | $page['warnings'][] = l10n('OAuth: PHP Curl extension is needed'); |
---|
[20293] | 79 | } |
---|
| 80 | } |
---|
[20323] | 81 | |
---|
| 82 | // in case of registration aborded |
---|
[23815] | 83 | // DON'T WORK, because potentially executed by sub-scripts like Secureimage for Crypto Captcha |
---|
| 84 | // if ( script_basename() != 'register' and ($data=pwg_get_session_var('oauth_new_user')) !== null ) |
---|
| 85 | // { |
---|
| 86 | // pwg_unset_session_var('oauth_new_user'); |
---|
[20369] | 87 | |
---|
[23815] | 88 | // require_once(OAUTH_PATH . 'include/hybridauth/Hybrid/Auth.php'); |
---|
[20369] | 89 | |
---|
[23815] | 90 | // try { |
---|
| 91 | // $hybridauth = new Hybrid_Auth($hybridauth_conf); |
---|
| 92 | // $adapter = $hybridauth->getAdapter($data[0]); |
---|
| 93 | // $adapter->logout(); |
---|
| 94 | // } |
---|
| 95 | // catch (Exception $e) { |
---|
| 96 | // } |
---|
| 97 | // } |
---|
[20293] | 98 | } |
---|
| 99 | |
---|
[26556] | 100 | function oauth_admin_plugin_menu_links($menu) |
---|
| 101 | { |
---|
| 102 | $menu[] = array( |
---|
| 103 | 'NAME' => l10n('OAuth'), |
---|
| 104 | 'URL' => OAUTH_ADMIN, |
---|
| 105 | ); |
---|
| 106 | return $menu; |
---|
| 107 | } |
---|