[20293] | 1 | <?php |
---|
| 2 | /* |
---|
[26666] | 3 | Plugin Name: Social Connect (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 | |
---|
[26605] | 22 | global $hybridauth_conf, $conf; |
---|
| 23 | |
---|
[26556] | 24 | // try to load hybridauth config |
---|
[20293] | 25 | include_once(OAUTH_PATH . 'include/functions.inc.php'); |
---|
| 26 | |
---|
[26667] | 27 | load_hybridauth_conf(); |
---|
[20293] | 28 | |
---|
[26556] | 29 | |
---|
| 30 | add_event_handler('init', 'oauth_init'); |
---|
| 31 | |
---|
[20293] | 32 | if (defined('IN_ADMIN')) |
---|
| 33 | { |
---|
| 34 | add_event_handler('get_admin_plugin_menu_links', 'oauth_admin_plugin_menu_links'); |
---|
[26619] | 35 | |
---|
| 36 | add_event_handler('user_list_columns', 'oauth_user_list_columns'); |
---|
| 37 | add_event_handler('after_render_user_list', 'oauth_user_list_render'); |
---|
| 38 | |
---|
| 39 | add_event_handler('loc_begin_admin_page', 'oauth_user_list'); |
---|
| 40 | |
---|
| 41 | include_once(OAUTH_PATH . 'include/admin_events.inc.php'); |
---|
[20293] | 42 | } |
---|
| 43 | else if (!empty($hybridauth_conf) and function_exists('curl_init')) |
---|
| 44 | { |
---|
| 45 | add_event_handler('loc_begin_identification', 'oauth_begin_identification'); |
---|
| 46 | add_event_handler('loc_begin_register', 'oauth_begin_register'); |
---|
| 47 | add_event_handler('loc_begin_profile', 'oauth_begin_profile'); |
---|
| 48 | |
---|
[26605] | 49 | add_event_handler('loc_after_page_header', 'oauth_page_header'); |
---|
[26604] | 50 | |
---|
[20293] | 51 | add_event_handler('try_log_user', 'oauth_try_log_user', EVENT_HANDLER_PRIORITY_NEUTRAL-30, 2); |
---|
| 52 | add_event_handler('user_logout', 'oauth_logout'); |
---|
| 53 | |
---|
| 54 | add_event_handler('blockmanager_apply', 'oauth_blockmanager'); |
---|
| 55 | |
---|
| 56 | include_once(OAUTH_PATH . 'include/public_events.inc.php'); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * plugin initialization |
---|
| 62 | */ |
---|
| 63 | function oauth_init() |
---|
| 64 | { |
---|
[26626] | 65 | global $conf, $page, $hybridauth_conf, $template; |
---|
[20293] | 66 | |
---|
[26556] | 67 | include_once(OAUTH_PATH . 'maintain.inc.php'); |
---|
| 68 | $maintain = new oAuth_maintain(OAUTH_ID); |
---|
| 69 | $maintain->autoUpdate(OAUTH_VERSION, 'install'); |
---|
[20293] | 70 | |
---|
| 71 | load_language('plugin.lang', OAUTH_PATH); |
---|
| 72 | |
---|
| 73 | $conf['oauth'] = unserialize($conf['oauth']); |
---|
| 74 | |
---|
| 75 | // check config |
---|
| 76 | if (defined('IN_ADMIN')) |
---|
| 77 | { |
---|
[26556] | 78 | if (empty($hybridauth_conf) and strpos(@$_GET['page'],'plugin-'.OAUTH_ID)===false) |
---|
[20293] | 79 | { |
---|
[26558] | 80 | $page['warnings'][] = '<a href="'.OAUTH_ADMIN.'">'.l10n('Social Connect: You need to configure the credentials').'</a>'; |
---|
[20293] | 81 | } |
---|
| 82 | if (!function_exists('curl_init')) |
---|
| 83 | { |
---|
[26558] | 84 | $page['warnings'][] = l10n('Social Connect: PHP Curl extension is needed'); |
---|
[20293] | 85 | } |
---|
| 86 | } |
---|
[20323] | 87 | |
---|
| 88 | // in case of registration aborded |
---|
[26626] | 89 | if ( script_basename() == 'index' and ($oauth_id=pwg_get_session_var('oauth_new_user')) !== null ) |
---|
| 90 | { |
---|
| 91 | pwg_unset_session_var('oauth_new_user'); |
---|
[20369] | 92 | |
---|
[26626] | 93 | if ($oauth_id[0] == 'Persona') |
---|
| 94 | { |
---|
| 95 | oauth_assign_template_vars(get_gallery_home_url()); |
---|
| 96 | $template->block_footer_script(null, 'navigator.id.logout();'); |
---|
| 97 | } |
---|
| 98 | else |
---|
| 99 | { |
---|
| 100 | require_once(OAUTH_PATH . 'include/hybridauth/Hybrid/Auth.php'); |
---|
| 101 | |
---|
| 102 | try { |
---|
| 103 | $hybridauth = new Hybrid_Auth($hybridauth_conf); |
---|
| 104 | $adapter = $hybridauth->getAdapter($oauth_id[0]); |
---|
| 105 | $adapter->logout(); |
---|
| 106 | } |
---|
| 107 | catch (Exception $e) {} |
---|
| 108 | } |
---|
| 109 | } |
---|
[20293] | 110 | } |
---|