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

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

first commit of oAuth plugin, still in developpement

File size: 3.3 KB
Line 
1<?php 
2/*
3Plugin Name: oauth
4Version: auto
5Description: This is not a plugin. It's a oauth for future plugins.
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  include_once(OAUTH_PATH . 'include/admin_events.inc.php');
44}
45else if (!empty($hybridauth_conf) and function_exists('curl_init'))
46{
47  add_event_handler('loc_begin_identification', 'oauth_begin_identification');
48  add_event_handler('loc_begin_register', 'oauth_begin_register');
49  add_event_handler('loc_begin_profile', 'oauth_begin_profile');
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, $pwg_loaded_plugins, $page, $hybridauth_conf;
66 
67  // apply upgrade if needed
68  if (
69    OAUTH_VERSION == 'auto' or
70    $pwg_loaded_plugins[OAUTH_ID]['version'] == 'auto' or
71    version_compare($pwg_loaded_plugins[OAUTH_ID]['version'], OAUTH_VERSION, '<')
72  )
73  {
74    include_once(OAUTH_PATH . 'include/install.inc.php');
75    oauth_install();
76   
77    if ( $pwg_loaded_plugins[OAUTH_ID]['version'] != 'auto' and OAUTH_VERSION != 'auto' )
78    {
79      $query = '
80UPDATE '. PLUGINS_TABLE .'
81SET version = "'. OAUTH_VERSION .'"
82WHERE id = "'. OAUTH_ID .'"';
83      pwg_query($query);
84     
85      $pwg_loaded_plugins[OAUTH_ID]['version'] = OAUTH_VERSION;
86     
87      if (defined('IN_ADMIN'))
88      {
89        $_SESSION['page_infos'][] = 'oAuth updated to version '. OAUTH_VERSION;
90      }
91    }
92  }
93 
94  load_language('plugin.lang', OAUTH_PATH);
95 
96  $conf['oauth'] = unserialize($conf['oauth']);
97 
98  // check config
99  if (defined('IN_ADMIN'))
100  {
101    if (empty($hybridauth_conf))
102    {
103      array_push($page['errors'], l10n('oAuth: You need to configure the credentials'));
104    }
105    if (!function_exists('curl_init'))
106    {
107      array_push($page['errors'], l10n('oAuth: cURL extension is needed'));
108    }
109  }
110}
111
112?>
Note: See TracBrowser for help on using the repository browser.