1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Social Connect |
---|
4 | Version: auto |
---|
5 | Description: Provides various ways to sign in your gallery (Twitter, Facebook, Google, etc.) |
---|
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 | |
---|
13 | define('OAUTH_ID', basename(dirname(__FILE__))); |
---|
14 | define('OAUTH_PATH' , PHPWG_PLUGINS_PATH . OAUTH_ID . '/'); |
---|
15 | define('OAUTH_ADMIN', get_root_url() . 'admin.php?page=plugin-' . OAUTH_ID); |
---|
16 | define('OAUTH_CONFIG', PWG_LOCAL_DIR . 'config/hybridauth.inc.php'); |
---|
17 | define('OAUTH_PUBLIC', get_absolute_root_url() . ltrim(OAUTH_PATH,'./') . 'include/hybridauth/'); |
---|
18 | |
---|
19 | include_once(OAUTH_PATH . 'include/functions.inc.php'); |
---|
20 | |
---|
21 | |
---|
22 | // try to load hybridauth config |
---|
23 | global $hybridauth_conf; |
---|
24 | load_hybridauth_conf(); |
---|
25 | |
---|
26 | |
---|
27 | add_event_handler('init', 'oauth_init'); |
---|
28 | |
---|
29 | if (defined('IN_ADMIN')) |
---|
30 | { |
---|
31 | add_event_handler('get_admin_plugin_menu_links', 'oauth_admin_plugin_menu_links'); |
---|
32 | |
---|
33 | add_event_handler('user_list_columns', 'oauth_user_list_columns'); |
---|
34 | add_event_handler('after_render_user_list', 'oauth_user_list_render'); |
---|
35 | |
---|
36 | add_event_handler('loc_begin_admin_page', 'oauth_user_list'); |
---|
37 | |
---|
38 | include_once(OAUTH_PATH . 'include/admin_events.inc.php'); |
---|
39 | } |
---|
40 | else if (!empty($hybridauth_conf) and function_exists('curl_init')) |
---|
41 | { |
---|
42 | add_event_handler('loc_begin_identification', 'oauth_begin_identification'); |
---|
43 | add_event_handler('loc_begin_register', 'oauth_begin_register'); |
---|
44 | add_event_handler('loc_begin_profile', 'oauth_begin_profile'); |
---|
45 | |
---|
46 | add_event_handler('loc_after_page_header', 'oauth_page_header'); |
---|
47 | |
---|
48 | add_event_handler('try_log_user', 'oauth_try_log_user', EVENT_HANDLER_PRIORITY_NEUTRAL-30, 2); |
---|
49 | add_event_handler('user_logout', 'oauth_logout'); |
---|
50 | |
---|
51 | add_event_handler('blockmanager_apply', 'oauth_blockmanager'); |
---|
52 | |
---|
53 | include_once(OAUTH_PATH . 'include/public_events.inc.php'); |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | /** |
---|
58 | * plugin initialization |
---|
59 | */ |
---|
60 | function oauth_init() |
---|
61 | { |
---|
62 | global $conf, $page, $hybridauth_conf, $template; |
---|
63 | |
---|
64 | load_language('plugin.lang', OAUTH_PATH); |
---|
65 | |
---|
66 | $conf['oauth'] = safe_unserialize($conf['oauth']); |
---|
67 | |
---|
68 | // check config |
---|
69 | if (defined('IN_ADMIN')) |
---|
70 | { |
---|
71 | if (empty($hybridauth_conf) and strpos(@$_GET['page'],'plugin-'.OAUTH_ID)===false) |
---|
72 | { |
---|
73 | $page['warnings'][] = '<a href="'.OAUTH_ADMIN.'">'.l10n('Social Connect: You need to configure the credentials').'</a>'; |
---|
74 | } |
---|
75 | if (!function_exists('curl_init')) |
---|
76 | { |
---|
77 | $page['warnings'][] = l10n('Social Connect: PHP Curl extension is needed'); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | // in case of registration aborded |
---|
82 | if ( script_basename() == 'index' and ($oauth_id=pwg_get_session_var('oauth_new_user')) !== null ) |
---|
83 | { |
---|
84 | pwg_unset_session_var('oauth_new_user'); |
---|
85 | |
---|
86 | if ($oauth_id[0] == 'Persona') |
---|
87 | { |
---|
88 | oauth_assign_template_vars(get_gallery_home_url()); |
---|
89 | $template->block_footer_script(null, 'navigator.id.logout();'); |
---|
90 | } |
---|
91 | else |
---|
92 | { |
---|
93 | require_once(OAUTH_PATH . 'include/hybridauth/Hybrid/Auth.php'); |
---|
94 | |
---|
95 | try { |
---|
96 | $hybridauth = new Hybrid_Auth($hybridauth_conf); |
---|
97 | $adapter = $hybridauth->getAdapter($oauth_id[0]); |
---|
98 | $adapter->logout(); |
---|
99 | } |
---|
100 | catch (Exception $e) {} |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|