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

Last change on this file since 24142 was 24142, checked in by mistic100, 11 years ago

fix lightbow conflict

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