1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: OAuth |
---|
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 | // +-----------------------------------------------------------------------+ |
---|
14 | // | Define plugin constants | |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | defined('OAUTH_ID') or define('OAUTH_ID', basename(dirname(__FILE__))); |
---|
17 | define('OAUTH_PATH' , PHPWG_PLUGINS_PATH . OAUTH_ID . '/'); |
---|
18 | define('OAUTH_ADMIN', get_root_url() . 'admin.php?page=plugin-' . OAUTH_ID); |
---|
19 | define('OAUTH_CONFIG', PWG_LOCAL_DIR . 'config/hybridauth.inc.php'); |
---|
20 | define('OAUTH_PUBLIC', get_absolute_root_url() . ltrim(OAUTH_PATH,'./') . 'include/hybridauth/'); |
---|
21 | define('OAUTH_VERSION', 'auto'); |
---|
22 | |
---|
23 | |
---|
24 | // +-----------------------------------------------------------------------+ |
---|
25 | // | Event handlers | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | global $conf, $hybridauth_conf; |
---|
28 | |
---|
29 | add_event_handler('init', 'oauth_init'); |
---|
30 | |
---|
31 | include_once(OAUTH_PATH . 'include/functions.inc.php'); |
---|
32 | |
---|
33 | // try to load hybridauth config |
---|
34 | if (file_exists(PHPWG_ROOT_PATH.OAUTH_CONFIG)) |
---|
35 | { |
---|
36 | load_hybridauth_conf(); |
---|
37 | } |
---|
38 | |
---|
39 | if (defined('IN_ADMIN')) |
---|
40 | { |
---|
41 | add_event_handler('get_admin_plugin_menu_links', 'oauth_admin_plugin_menu_links'); |
---|
42 | |
---|
43 | function oauth_admin_plugin_menu_links($menu) |
---|
44 | { |
---|
45 | array_push($menu, array( |
---|
46 | 'NAME' => l10n('OAuth'), |
---|
47 | 'URL' => OAUTH_ADMIN, |
---|
48 | )); |
---|
49 | return $menu; |
---|
50 | } |
---|
51 | } |
---|
52 | else if (!empty($hybridauth_conf) and function_exists('curl_init')) |
---|
53 | { |
---|
54 | add_event_handler('loc_begin_identification', 'oauth_begin_identification'); |
---|
55 | add_event_handler('loc_begin_register', 'oauth_begin_register'); |
---|
56 | add_event_handler('loc_begin_profile', 'oauth_begin_profile'); |
---|
57 | |
---|
58 | add_event_handler('try_log_user', 'oauth_try_log_user', EVENT_HANDLER_PRIORITY_NEUTRAL-30, 2); |
---|
59 | add_event_handler('user_logout', 'oauth_logout'); |
---|
60 | |
---|
61 | add_event_handler('blockmanager_apply', 'oauth_blockmanager'); |
---|
62 | |
---|
63 | include_once(OAUTH_PATH . 'include/public_events.inc.php'); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | /** |
---|
68 | * plugin initialization |
---|
69 | */ |
---|
70 | function oauth_init() |
---|
71 | { |
---|
72 | global $conf, $pwg_loaded_plugins, $page, $hybridauth_conf; |
---|
73 | |
---|
74 | // apply upgrade if needed |
---|
75 | if ( |
---|
76 | OAUTH_VERSION == 'auto' or |
---|
77 | $pwg_loaded_plugins[OAUTH_ID]['version'] == 'auto' or |
---|
78 | version_compare($pwg_loaded_plugins[OAUTH_ID]['version'], OAUTH_VERSION, '<') |
---|
79 | ) |
---|
80 | { |
---|
81 | include_once(OAUTH_PATH . 'include/install.inc.php'); |
---|
82 | oauth_install(); |
---|
83 | |
---|
84 | if ( $pwg_loaded_plugins[OAUTH_ID]['version'] != 'auto' and OAUTH_VERSION != 'auto' ) |
---|
85 | { |
---|
86 | $query = ' |
---|
87 | UPDATE '. PLUGINS_TABLE .' |
---|
88 | SET version = "'. OAUTH_VERSION .'" |
---|
89 | WHERE id = "'. OAUTH_ID .'"'; |
---|
90 | pwg_query($query); |
---|
91 | |
---|
92 | $pwg_loaded_plugins[OAUTH_ID]['version'] = OAUTH_VERSION; |
---|
93 | |
---|
94 | if (defined('IN_ADMIN')) |
---|
95 | { |
---|
96 | $_SESSION['page_infos'][] = 'OAuth updated to version '. OAUTH_VERSION; |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | load_language('plugin.lang', OAUTH_PATH); |
---|
102 | |
---|
103 | $conf['oauth'] = unserialize($conf['oauth']); |
---|
104 | |
---|
105 | // check config |
---|
106 | if (defined('IN_ADMIN')) |
---|
107 | { |
---|
108 | if ( empty($hybridauth_conf) and strpos(@$_GET['page'],'plugin-'.OAUTH_ID)===false ) |
---|
109 | { |
---|
110 | array_push($page['warnings'], '<a href="'.OAUTH_ADMIN.'">'.l10n('OAuth: You need to configure the credentials').'</a>'); |
---|
111 | } |
---|
112 | if (!function_exists('curl_init')) |
---|
113 | { |
---|
114 | array_push($page['warnings'], l10n('OAuth: PHP Curl extension is needed')); |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | // in case of registration aborded |
---|
119 | // DON'T WORK, because potentially executed by sub-scripts like Secureimage for Crypto Captcha |
---|
120 | // if ( script_basename() != 'register' and ($data=pwg_get_session_var('oauth_new_user')) !== null ) |
---|
121 | // { |
---|
122 | // pwg_unset_session_var('oauth_new_user'); |
---|
123 | |
---|
124 | // require_once(OAUTH_PATH . 'include/hybridauth/Hybrid/Auth.php'); |
---|
125 | |
---|
126 | // try { |
---|
127 | // $hybridauth = new Hybrid_Auth($hybridauth_conf); |
---|
128 | // $adapter = $hybridauth->getAdapter($data[0]); |
---|
129 | // $adapter->logout(); |
---|
130 | // } |
---|
131 | // catch (Exception $e) { |
---|
132 | // } |
---|
133 | // } |
---|
134 | } |
---|
135 | |
---|
136 | ?> |
---|