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

Revision 6791, 6.7 KB checked in by Eric, 10 years ago (diff)
  • Bug 1812 fixed - Compliance with FluxBB 1.4
  • New version 2.2.4 hard coded
  • Property svn:eol-style set to LF
Line 
1<?php
2/*
3Plugin Name: Register FluxBB
4Version: 2.2.4
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--------------------------------------------------------------------------------
57*/
58
59// pour faciliter le debug - make debug easier :o)
60//ini_set('error_reporting', E_ALL);
61//ini_set('display_errors', true);
62
63if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
64
65if (!defined('REGFLUXBB_DIR')) define('REGFLUXBB_DIR' , basename(dirname(__FILE__)));
66if (!defined('REGFLUXBB_PATH')) define('REGFLUXBB_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
67
68include_once (REGFLUXBB_PATH.'include/constants.php');
69include_once (REGFLUXBB_PATH.'include/functions.inc.php');
70
71
72/* plugin administration */
73add_event_handler('get_admin_plugin_menu_links', 'Register_FluxBB_admin_menu');
74
75function Register_FluxBB_admin_menu($menu)
76{
77  array_push($menu, array(
78    'NAME' => 'Register FluxBB',
79    'URL'  => get_admin_plugin_menu_link(REGFLUXBB_PATH.'admin/admin.php')));
80  return $menu;
81}
82
83
84/* user creation*/
85add_event_handler('register_user', 'Register_FluxBB_Adduser');
86
87function Register_FluxBB_Adduser($register_user)
88{
89  global $conf;
90       
91  include_once (REGFLUXBB_PATH.'include/functions.inc.php');
92
93  // Warning : FluxBB uses Sha1 hash instead of md5 for Piwigo !
94  FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']);
95}
96
97
98/* user deletion */
99add_event_handler('delete_user', 'Register_FluxBB_Deluser');
100
101function Register_FluxBB_Deluser($user_id)
102{
103  include_once (REGFLUXBB_PATH.'include/functions.inc.php');
104
105  FluxBB_Deluser( FluxBB_Searchuser($user_id), true );
106}
107
108
109
110add_event_handler('init', 'Register_FluxBB_InitPage');
111 
112function Register_FluxBB_InitPage()
113{
114  global $conf, $user ;
115  include_once (REGFLUXBB_PATH.'include/functions.inc.php');
116
117/* user update */
118  if (script_basename() == 'profile')
119  {
120    if (isset($_POST['validate']))
121    {
122      $errors = array();
123
124      $int_pattern = '/^\d+$/';
125      if (empty($_POST['nb_image_line'])
126        or (!preg_match($int_pattern, $_POST['nb_image_line'])))
127      {
128        $errors[] = l10n('nb_image_line_error');
129      }
130   
131      if (empty($_POST['nb_line_page'])
132        or (!preg_match($int_pattern, $_POST['nb_line_page'])))
133      {
134        $errors[] = l10n('nb_line_page_error');
135      }
136   
137      if ($_POST['maxwidth'] != ''
138        and (!preg_match($int_pattern, $_POST['maxwidth'])
139        or $_POST['maxwidth'] < 50))
140      {
141        $errors[] = l10n('maxwidth_error');
142      }
143
144      if ($_POST['maxheight']
145        and (!preg_match($int_pattern, $_POST['maxheight'])
146        or $_POST['maxheight'] < 50))
147      {
148        $errors[] = l10n('maxheight_error');
149      }
150
151      if (isset($_POST['mail_address']))
152      {
153        $mail_error = validate_mail_address($user['id'],$_POST['mail_address']);
154        if (!empty($mail_error))
155        {
156          $errors[] = $mail_error;
157        }
158      }
159   
160      if (!empty($_POST['use_new_pwd']))
161      {
162        // password must be the same as its confirmation
163        if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
164        {
165          $errors[] = l10n('New password confirmation does not correspond');
166        }
167   
168        if ( !defined('IN_ADMIN') )
169        {// changing password requires old password
170          $query = '
171SELECT '.$conf['user_fields']['password'].' AS password
172FROM '.USERS_TABLE.'
173WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
174;';
175
176          list($current_password) = pwg_db_fetch_row(pwg_query($query));
177     
178          if ($conf['pass_convert']($_POST['password']) != $current_password)
179          {
180            $errors[] = l10n('Current password is wrong');
181          }
182        }
183      }
184   
185      if (count($errors) == 0)
186      {
187        include_once (REGFLUXBB_PATH.'include/functions.inc.php');
188     
189        $query = '
190SELECT '.$conf['user_fields']['username'].' AS username
191FROM '.USERS_TABLE.'
192WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
193;';
194
195        list($username) = pwg_db_fetch_row(pwg_query($query));
196
197        FluxBB_Updateuser($user['id'], stripslashes($username), sha1($_POST['use_new_pwd']), $_POST['mail_address']);
198      }
199    }
200  }
201}
202?>
Note: See TracBrowser for help on using the repository browser.