source: extensions/oAuth/main.inc.php @ 26653

Last change on this file since 26653 was 26626, checked in by mistic100, 10 years ago

add 'allow_merge_accounts' parameter

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