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

Last change on this file since 27153 was 26667, checked in by mistic100, 10 years ago

fix display of icon on users list

File size: 3.3 KB
Line 
1<?php 
2/*
3Plugin Name: Social Connect (OAuth)
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
27load_hybridauth_conf();
28
29
30add_event_handler('init', 'oauth_init');
31
32if (defined('IN_ADMIN'))
33{
34  add_event_handler('get_admin_plugin_menu_links', 'oauth_admin_plugin_menu_links');
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');
42}
43else 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 
49  add_event_handler('loc_after_page_header', 'oauth_page_header');
50 
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 */
63function oauth_init()
64{
65  global $conf, $page, $hybridauth_conf, $template;
66 
67  include_once(OAUTH_PATH . 'maintain.inc.php');
68  $maintain = new oAuth_maintain(OAUTH_ID);
69  $maintain->autoUpdate(OAUTH_VERSION, 'install');
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  {
78    if (empty($hybridauth_conf) and strpos(@$_GET['page'],'plugin-'.OAUTH_ID)===false)
79    {
80      $page['warnings'][] = '<a href="'.OAUTH_ADMIN.'">'.l10n('Social Connect: You need to configure the credentials').'</a>';
81    }
82    if (!function_exists('curl_init'))
83    {
84      $page['warnings'][] = l10n('Social Connect: PHP Curl extension is needed');
85    }
86  }
87 
88  // in case of registration aborded
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');
92   
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  }
110}
Note: See TracBrowser for help on using the repository browser.