source: extensions/Register_FluxBB/trunk/main.inc.php @ 6815

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

bug 1434 fixed : Bridge between Register_FluxBB and UAM for users registration control

  • Language files updated (FR and EN are OK. DE is to do)
  • Admin page small refactory
  • Database upgrade process updated for new plugin version
  • Version 2.3.0 hard coded
  • Property svn:eol-style set to LF
File size: 8.8 KB
Line 
1<?php
2/*
3Plugin Name: Register FluxBB
4Version: 2.3.0
5Description: Link user registration from Piwigo to FluxBB forum (registration, password changing, deletion) - Original Nicco's NBC_LinkUser2PunBB plugin upgraded to Piwigo / Liez l'inscription des utilisateurs de Piwigo avec votre forum FluxBB - Portage du plugin NBC_LinkUser2PunBB de Nicco vers Piwigo
6Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=252
7Author: Eric
8Author URI: http://www.infernoweb.net
9*/
10
11/*
12--------------------------------------------------------------------------------
13  Author     : Eric
14    email    : lucifer@infernoweb.net
15    website  : http://www.infernoweb.net
16    PWG user : http://forum.phpwebgallery.net/profile.php?id=1106
17--------------------------------------------------------------------------------
18
19:: HISTORY
20
212.0.0b          - 23/11/08  - Initial release. Basic changes to be available for Piwigo 2.0RC4
22
232.0.1b          - 24/11/08  - Small bug correction on submit button display
24
252.0.2                   - 19/02/09      - Language pack correction
26
272.1.0                   - 25/04/09  - Admin panel with tabsheets
28                      - Radio buttons functionnalities corrections (now radio buttons show the configuration saved in database)
29                      - Language files (fr - en) improvement
30
312.1.1                   - 30/04/09      - Bug fixed on profile update
32
332.1.2                   - 22/08/09      - Compatibility bug fixed when used with DynamicRecentPeriod plugin
34
352.1.3     - 16/11/09  - Using sha1 hash instead of md5 for password hashing in FluxBB
36                      - Escaping all characters in login names and be able to retreive them without slashes - FluxBB does not allow this so Piwigo's user names with escaped characters will not been escaped in FluxBB (ie : "it's" in Piwigo will be "It\'s" in FluxBB)
37                      - Code refactoring
38                      - Full HTML 4.0 for tpl
39
402.2.0     - 03/04/10  - Piwigo 2.1 compatibility
41                      - Adding css file
42                      - Templates refactory: Moved with css in a "template" subdirectory of admin directory, Moving icons in template directory, using css rules to improve important text display
43                      - functions_Register_FluxBB.inc.php renamed in functions.inc.php
44                      - Language files revision
45                      - Obsolete files management
46
472.2.1     - 04/04/10  - Bug 1577 fixed : Multiple database support
48
492.2.2     - 23/05/10  - Bug 1674 fixed : Adding of mods for Fluxbb when users loose their password
50                      - Adding of German language (Thx to duke)
51
522.2.3     - 23/05/10  - Bug 1674 re-fixed : Bad link fixed
53                      - Re-adding of German language that was missed at last release :-( (Thx to duke)
54
552.2.4     - 22/08/10  - Bug 1812 fixed : Compliance with FluxBB 1.4
56
572.3.0     - 01/09/10  - Bug 1434 fixed : Bridge between Register_FluxBB and UserAdvManager for new users validation
58--------------------------------------------------------------------------------
59*/
60
61// pour faciliter le debug - make debug easier :o)
62//ini_set('error_reporting', E_ALL);
63//ini_set('display_errors', true);
64
65if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
66
67if (!defined('REGFLUXBB_DIR')) define('REGFLUXBB_DIR' , basename(dirname(__FILE__)));
68if (!defined('REGFLUXBB_PATH')) define('REGFLUXBB_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
69
70include_once (REGFLUXBB_PATH.'include/constants.php');
71include_once (REGFLUXBB_PATH.'include/functions.inc.php');
72
73
74/* plugin administration */
75add_event_handler('get_admin_plugin_menu_links', 'Register_FluxBB_admin_menu');
76
77function Register_FluxBB_admin_menu($menu)
78{
79  array_push($menu, array(
80    'NAME' => 'Register FluxBB',
81    'URL'  => get_admin_plugin_menu_link(REGFLUXBB_PATH.'admin/admin.php')));
82  return $menu;
83}
84
85
86/* user creation*/
87add_event_handler('register_user', 'Register_FluxBB_Adduser');
88
89function Register_FluxBB_Adduser($register_user)
90{
91  global $conf;
92       
93  include_once (REGFLUXBB_PATH.'include/functions.inc.php');
94
95  // Warning : FluxBB uses Sha1 hash instead of md5 for Piwigo!
96  FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']);
97}
98
99
100/* user deletion */
101add_event_handler('delete_user', 'Register_FluxBB_Deluser');
102
103function Register_FluxBB_Deluser($user_id)
104{
105  include_once (REGFLUXBB_PATH.'include/functions.inc.php');
106
107  FluxBB_Deluser( FluxBB_Searchuser($user_id), true );
108}
109
110
111
112add_event_handler('init', 'Register_FluxBB_InitPage');
113 
114function Register_FluxBB_InitPage()
115{
116  global $conf, $user ;
117  include_once (REGFLUXBB_PATH.'include/functions.inc.php');
118
119/* user update */
120  if (script_basename() == 'profile')
121  {
122    if (isset($_POST['validate']))
123    {
124      $errors = array();
125
126      $int_pattern = '/^\d+$/';
127      if (empty($_POST['nb_image_line'])
128        or (!preg_match($int_pattern, $_POST['nb_image_line'])))
129      {
130        $errors[] = l10n('nb_image_line_error');
131      }
132   
133      if (empty($_POST['nb_line_page'])
134        or (!preg_match($int_pattern, $_POST['nb_line_page'])))
135      {
136        $errors[] = l10n('nb_line_page_error');
137      }
138   
139      if ($_POST['maxwidth'] != ''
140        and (!preg_match($int_pattern, $_POST['maxwidth'])
141        or $_POST['maxwidth'] < 50))
142      {
143        $errors[] = l10n('maxwidth_error');
144      }
145
146      if ($_POST['maxheight']
147        and (!preg_match($int_pattern, $_POST['maxheight'])
148        or $_POST['maxheight'] < 50))
149      {
150        $errors[] = l10n('maxheight_error');
151      }
152
153      if (isset($_POST['mail_address']))
154      {
155        $mail_error = validate_mail_address($user['id'],$_POST['mail_address']);
156        if (!empty($mail_error))
157        {
158          $errors[] = $mail_error;
159        }
160      }
161   
162      if (!empty($_POST['use_new_pwd']))
163      {
164        // password must be the same as its confirmation
165        if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
166        {
167          $errors[] = l10n('New password confirmation does not correspond');
168        }
169   
170        if ( !defined('IN_ADMIN') )
171        {// changing password requires old password
172          $query = '
173SELECT '.$conf['user_fields']['password'].' AS password
174FROM '.USERS_TABLE.'
175WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
176;';
177
178          list($current_password) = pwg_db_fetch_row(pwg_query($query));
179     
180          if ($conf['pass_convert']($_POST['password']) != $current_password)
181          {
182            $errors[] = l10n('Current password is wrong');
183          }
184        }
185      }
186   
187      if (count($errors) == 0)
188      {
189        include_once (REGFLUXBB_PATH.'include/functions.inc.php');
190     
191        $query = '
192SELECT '.$conf['user_fields']['username'].' AS username
193FROM '.USERS_TABLE.'
194WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
195;';
196
197        list($username) = pwg_db_fetch_row(pwg_query($query));
198
199        FluxBB_Updateuser($user['id'], stripslashes($username), sha1($_POST['use_new_pwd']), $_POST['mail_address']);
200      }
201    }
202  }
203}
204
205
206/* Access validation in FluxBB when validated in Piwigo through UAM plugin */
207add_event_handler('login_success', 'UAM_Bridge');
208
209function UAM_Bridge()
210{
211  global $conf, $user;
212 
213  $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array();
214 
215  // Check if UAM is installed and if bridge is set - Exception for admins and webmasters
216  if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB[6]) and $conf_Register_FluxBB[6] == 'true' and !is_admin() and !is_webmaster())
217  {
218    $conf_UAM = unserialize($conf['UserAdvManager']);
219   
220    // Getting unvalidated users group else Piwigo's default group
221    if (isset($conf_UAM[2]) and $conf_UAM[2] != '-1')
222    {
223      $Waitingroup = $conf_UAM[2];
224    }
225    else
226    {
227      $query = '
228SELECT id
229FROM '.GROUPS_TABLE.'
230WHERE is_default = "true"
231LIMIT 1
232;';
233      $data = pwg_db_fetch_assoc(pwg_query($query));
234      $Waitingroup = $data['id'];
235    }
236   
237    // check if logged in user is in a Piwigo's validated or unvalidated users group
238    $query = '
239SELECT *
240FROM '.USER_GROUP_TABLE.'
241WHERE user_id = '.$user['id'].'
242AND group_id = '.$Waitingroup.'
243;';
244    $count = pwg_db_num_rows(pwg_query($query));
245
246    // Check if logged in user is in a FluxBB's unvalidated group
247    $query = "
248SELECT group_id
249FROM ".FluxBB_USERS_TABLE."
250WHERE id = ".FluxBB_Searchuser($user['id'])."
251;";
252
253    $data = pwg_db_fetch_assoc(pwg_query($query));
254
255    // Logged in user switch to the default FluxBB's group if he'is validated
256    if ($count == 0 and $data['group_id'] = $conf_Register_FluxBB[7])
257    {
258      $query = "
259SELECT conf_value
260FROM ".FluxBB_CONFIG_TABLE."
261WHERE conf_name = 'o_default_user_group'
262;";
263
264      $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query));
265     
266      $query = "
267UPDATE ".FluxBB_USERS_TABLE."
268SET group_id = ".$o_default_user_group['conf_value']."
269WHERE id = ".FluxBB_Searchuser($user['id'])."
270;";
271      pwg_query($query);
272    }
273  }
274}
275?>
Note: See TracBrowser for help on using the repository browser.