source: extensions/Register_PhpBB/main.inc.php @ 20639

Last change on this file since 20639 was 8046, checked in by Eric, 14 years ago

author email fixed in head comment

  • Property svn:eol-style set to LF
File size: 5.9 KB
Line 
1<?php
2/*
3Plugin Name: Register PhpBB
4Version: 2.1.a
5Description: Link user registration from Piwigo to PhpBB forum (registration, password changing, deletion) - Original Eric's Register_FluxBB plugin adapted to PhpBB. / Liez l'inscription des utilisateurs de Piwigo avec votre forum PhpBB - Adaptation du plugin Register_FluxBB d'Eric.
6Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=129
7Author: Pierric, Eric
8Author URI: http://www.infernoweb.net
9*/
10
11/*
12--------------------------------------------------------------------------------
13  Author     : Pierric, Eric
14    email    : pierrot007@gmail.com, eric@piwigo.org
15    website  : http://www.infernoweb.net
16    PWG user : http://fr.piwigo.org/forum/profile.php?id=5784, http://forum.phpwebgallery.net/profile.php?id=1106
17--------------------------------------------------------------------------------
18
19:: HISTORY
20
212.1.a           - 15/11/2010 - Initial release.
22--------------------------------------------------------------------------------
23*/
24
25// pour faciliter le debug - make debug easier :o)
26//ini_set('error_reporting', E_ALL);
27//ini_set('display_errors', true);
28
29if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
30
31if (!defined('REGPHPBB_DIR')) define('REGPHPBB_DIR' , basename(dirname(__FILE__)));
32if (!defined('REGPHPBB_PATH')) define('REGPHPBB_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
33
34include_once (REGPHPBB_PATH.'include/constants.php');
35include_once (REGPHPBB_PATH.'include/functions.inc.php');
36
37
38/* plugin administration */
39add_event_handler('get_admin_plugin_menu_links', 'Register_PhpBB_admin_menu');
40
41function Register_PhpBB_admin_menu($menu)
42{
43  array_push($menu, array(
44    'NAME' => 'Register PhpBB',
45    'URL'  => get_admin_plugin_menu_link(REGPHPBB_PATH.'admin/admin.php')));
46  return $menu;
47}
48
49
50/* user creation*/
51add_event_handler('register_user', 'Register_PhpBB_Adduser');
52
53function Register_PhpBB_Adduser($register_user)
54{
55  global $conf;
56
57  // Exclusion of Adult_Content users
58  if ($register_user['username'] != "16" and $register_user['username'] != "18")
59  {
60    include_once (REGPHPBB_PATH.'include/functions.inc.php');
61
62    // Warning : PhpBB uses md5 hash like Piwigo, but not like PhpBB !
63    PhpBB_Adduser($register_user['id'], $register_user['username'], md5($_POST['password']), $register_user['email']);
64  }
65}
66
67
68/* user deletion */
69add_event_handler('delete_user', 'Register_PhpBB_Deluser');
70
71function Register_PhpBB_Deluser($user_id)
72{
73  include_once (REGPHPBB_PATH.'include/functions.inc.php');
74
75  PhpBB_Deluser( PhpBB_Searchuser($user_id), true );
76}
77
78
79/* Profile management */
80if (script_basename() == 'profile')
81{
82  add_event_handler('loc_begin_profile', 'Register_PhpBB_InitPage', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
83
84  function Register_PhpBB_InitPage()
85  {
86    global $conf, $user;
87    include_once (REGPHPBB_PATH.'include/functions.inc.php');
88
89    if (isset($_POST['validate']) and !is_admin())
90    {
91    if (!empty($_POST['use_new_pwd']))
92      {
93      $query = '
94SELECT '.$conf['user_fields']['username'].' AS username
95FROM '.USERS_TABLE.'
96WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
97;';
98
99      list($username) = pwg_db_fetch_row(pwg_query($query));
100
101      PhpBB_Updateuser($user['id'], stripslashes($username), md5($_POST['use_new_pwd']), $_POST['mail_address']);
102      }
103    }
104  }
105}
106
107
108/* Access validation in PhpBB when validated in Piwigo through UAM plugin */
109add_event_handler('login_success', 'UAM_Bridge', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
110
111function UAM_Bridge()
112{
113  global $conf, $user;
114
115  $conf_Register_PhpBB = isset($conf['Register_PhpBB']) ? explode(";" , $conf['Register_PhpBB']) : array();
116
117  // Check if UAM is installed and if bridge is set - Exception for admins and webmasters
118  $query ='
119SELECT user_id, status
120FROM '.USER_INFOS_TABLE.'
121WHERE user_id = '.$user['id'].'
122;';
123  $data = pwg_db_fetch_assoc(pwg_query($query));
124
125  if ($data['status'] <> "admin" and $data['status'] <> "webmaster")
126  {
127    if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_PhpBB[5]) and $conf_Register_PhpBB[5] == 'true')
128    {
129      $conf_UAM = unserialize($conf['UserAdvManager']);
130
131      // Getting unvalidated users group else Piwigo's default group
132      if (isset($conf_UAM[2]) and $conf_UAM[2] != '-1')
133      {
134        $Waitingroup = $conf_UAM[2];
135      }
136      else
137      {
138        $query = '
139SELECT id
140FROM '.GROUPS_TABLE.'
141WHERE is_default = "true"
142LIMIT 1
143;';
144        $data = pwg_db_fetch_assoc(pwg_query($query));
145        $Waitingroup = $data['id'];
146      }
147
148      // check if logged in user is in a Piwigo's validated or unvalidated users group
149      $query = '
150SELECT *
151FROM '.USER_GROUP_TABLE.'
152WHERE user_id = '.$user['id'].'
153AND group_id = '.$Waitingroup.'
154;';
155      $count = pwg_db_num_rows(pwg_query($query));
156
157      // Check if logged in user is in a PhpBB's unvalidated group
158      $query = "
159SELECT group_id
160FROM ".PhpBB_USERS_TABLE."
161WHERE user_id = ".PhpBB_Searchuser($user['id'])."
162;";
163
164      $data = pwg_db_fetch_assoc(pwg_query($query));
165
166      $query = "
167SELECT group_id
168FROM ".PhpBB_GROUPS_TABLE."
169WHERE group_name = '".$conf_Register_PhpBB[6]."'
170;";
171      $data1 = pwg_db_fetch_assoc(pwg_query($query));
172
173      // Logged in user switch to the default PhpBB's group if he'is validated
174      if ($count == 0 and $data['group_id'] != $data1['group_id'])
175      {
176        $query = "
177SELECT group_id, group_colour
178FROM ".PhpBB_GROUPS_TABLE."
179WHERE group_name = '".$conf_Register_PhpBB[6]."'
180;";
181        $default_user = pwg_db_fetch_assoc(pwg_query($query));
182
183        $query = "
184UPDATE ".PhpBB_USERS_TABLE."
185SET group_id = '".$default_user['group_id']."', user_colour = '".$default_user['group_colour']."'
186WHERE user_id = ".PhpBB_Searchuser($user['id'])."
187;";
188        $result = pwg_query($query);
189
190        $query = "
191UPDATE ".PhpBB_USERGROUP_TABLE."
192SET group_id = '".$default_user['group_id']."'
193WHERE user_id = ".PhpBB_Searchuser($user['id'])."
194;";
195        $result = pwg_query($query);
196      }
197    }
198  }
199}
200?>
Note: See TracBrowser for help on using the repository browser.