source: extensions/Register_FluxBB/branches/2.3/main.inc.php @ 6899

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

Merge from Trunk to Branch 2.3

  • Property svn:eol-style set to LF
File size: 7.8 KB
Line 
1<?php
2/*
3Plugin Name: Register FluxBB
4Version: 2.3.3
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     - 28/08/10  - Bug 1434 fixed : Bridge between Register_FluxBB and UserAdvManager for new users validation
58
592.3.1     - 31/08/10  - Bug 1825 fixed : Password corruption after Piwigo's profile page visit
60
612.3.2     - 11/09/10  - Bug 1847 fixed : Admins and webmasters was not excluded from registration validation
62
632.3.3     - 13/09/10  - Bug 1853 fixed : Add of controls on plugin configuration settings to avoid some mistakes
64                      - Bug 1855 fixed : Improvement of use of UAM bridge (fixes php notices)
65                      - Several language files fix
66--------------------------------------------------------------------------------
67*/
68
69// pour faciliter le debug - make debug easier :o)
70//ini_set('error_reporting', E_ALL);
71//ini_set('display_errors', true);
72
73if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
74
75if (!defined('REGFLUXBB_DIR')) define('REGFLUXBB_DIR' , basename(dirname(__FILE__)));
76if (!defined('REGFLUXBB_PATH')) define('REGFLUXBB_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
77
78include_once (REGFLUXBB_PATH.'include/constants.php');
79include_once (REGFLUXBB_PATH.'include/functions.inc.php');
80
81
82/* plugin administration */
83add_event_handler('get_admin_plugin_menu_links', 'Register_FluxBB_admin_menu');
84
85function Register_FluxBB_admin_menu($menu)
86{
87  array_push($menu, array(
88    'NAME' => 'Register FluxBB',
89    'URL'  => get_admin_plugin_menu_link(REGFLUXBB_PATH.'admin/admin.php')));
90  return $menu;
91}
92
93
94/* user creation*/
95add_event_handler('register_user', 'Register_FluxBB_Adduser');
96
97function Register_FluxBB_Adduser($register_user)
98{
99  global $conf;
100       
101  include_once (REGFLUXBB_PATH.'include/functions.inc.php');
102
103  // Warning : FluxBB uses Sha1 hash instead of md5 for Piwigo!
104  FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']);
105}
106
107
108/* user deletion */
109add_event_handler('delete_user', 'Register_FluxBB_Deluser');
110
111function Register_FluxBB_Deluser($user_id)
112{
113  include_once (REGFLUXBB_PATH.'include/functions.inc.php');
114
115  FluxBB_Deluser( FluxBB_Searchuser($user_id), true );
116}
117
118
119/* Profile management */
120if (script_basename() == 'profile')
121{
122  add_event_handler('loc_begin_profile', 'Register_FluxBB_InitPage', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
123
124  function Register_FluxBB_InitPage()
125  {
126    global $conf, $user;
127    include_once (REGFLUXBB_PATH.'include/functions.inc.php');
128   
129    if (isset($_POST['validate']) and !is_admin())
130    {
131    if (!empty($_POST['use_new_pwd']))
132      {
133      $query = '
134SELECT '.$conf['user_fields']['username'].' AS username
135FROM '.USERS_TABLE.'
136WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
137;';
138
139      list($username) = pwg_db_fetch_row(pwg_query($query));
140
141      FluxBB_Updateuser($user['id'], stripslashes($username), sha1($_POST['use_new_pwd']), $_POST['mail_address']);
142      }
143    }
144  }
145}
146
147
148/* Access validation in FluxBB when validated in Piwigo through UAM plugin */
149add_event_handler('login_success', 'UAM_Bridge', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
150
151function UAM_Bridge()
152{
153  global $conf, $user;
154 
155  $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array();
156 
157  // Check if UAM is installed and if bridge is set - Exception for admins and webmasters
158  $query ='
159SELECT user_id, status
160FROM '.USER_INFOS_TABLE.'
161WHERE user_id = '.$user['id'].'
162;';
163  $data = pwg_db_fetch_assoc(pwg_query($query));
164 
165  if ($data['status'] <> "admin" and $data['status'] <> "webmaster")
166  {
167    if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB[6]) and $conf_Register_FluxBB[6] == 'true')
168    {
169      $conf_UAM = unserialize($conf['UserAdvManager']);
170   
171      // Getting unvalidated users group else Piwigo's default group
172      if (isset($conf_UAM[2]) and $conf_UAM[2] != '-1')
173      {
174        $Waitingroup = $conf_UAM[2];
175      }
176      else
177      {
178        $query = '
179SELECT id
180FROM '.GROUPS_TABLE.'
181WHERE is_default = "true"
182LIMIT 1
183;';
184        $data = pwg_db_fetch_assoc(pwg_query($query));
185        $Waitingroup = $data['id'];
186      }
187   
188      // check if logged in user is in a Piwigo's validated or unvalidated users group
189      $query = '
190SELECT *
191FROM '.USER_GROUP_TABLE.'
192WHERE user_id = '.$user['id'].'
193AND group_id = '.$Waitingroup.'
194;';
195      $count = pwg_db_num_rows(pwg_query($query));
196
197      // Check if logged in user is in a FluxBB's unvalidated group
198      $query = "
199SELECT group_id
200FROM ".FluxBB_USERS_TABLE."
201WHERE id = ".FluxBB_Searchuser($user['id'])."
202;";
203
204      $data = pwg_db_fetch_assoc(pwg_query($query));
205
206      // Logged in user switch to the default FluxBB's group if he'is validated
207      if ($count == 0 and $data['group_id'] = $conf_Register_FluxBB[7])
208      {
209        $query = "
210SELECT conf_value
211FROM ".FluxBB_CONFIG_TABLE."
212WHERE conf_name = 'o_default_user_group'
213;";
214
215        $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query));
216     
217        $query = "
218UPDATE ".FluxBB_USERS_TABLE."
219SET group_id = ".$o_default_user_group['conf_value']."
220WHERE id = ".FluxBB_Searchuser($user['id'])."
221;";
222        pwg_query($query);
223      }
224    }
225  }
226}
227?>
Note: See TracBrowser for help on using the repository browser.