source: extensions/NBC_UserAdvManager/trunk/main.inc.php @ 3917

Last change on this file since 3917 was 3917, checked in by Eric, 15 years ago

[NBC_UserAdvManager] Fix for bug 1175

Bad language tag for french translation

  • Property svn:eol-style set to LF
File size: 14.6 KB
Line 
1<?php
2/*
3Plugin Name: NBC UserAdvManager
4Version: 2.11.3
5Description: Permet de renforcer les possibilités de gestion des utilisateurs - Enforce users management
6Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=216
7Author: Nicco, Eric
8Author URI: http://gallery-nicco.no-ip.org, http://www.infernoweb.net
9*/
10
11/*
12 ***** Plugin history (branch 2.10)*****
13
14-- 2.10.0-beta : Initial beta release for Piwigo compatibility
15-- 2.10.1-beta : Small correction on generated path
16-- 2.10.2-beta : Bug resolved on register validation page
17
18-- 2.10.3 : Final and fully functional release
19                        Bug resolved on plugin activation
20
21-- 2.10.4 : Bug fixed on profiles update
22
23-- 2.10.5 : Improved code on profiles update
24
25-- 2.10.6 : Old language packs (iso) deleted (forget from PWG 1.7.x version)
26
27-- 2.10.7 : Bug fixed on user's validation email sending
28
29-- 2.10.8 : ConfirmMail page looks better (Sylvia theme only)
30                        Improved code for checking author on guest comments
31
32-- 2.10.9 : Bug fixed - Missing english translation
33                        Bug fixed - Notice on forbidden characters function use
34                        Bug fixed - Audit on forbidden characters in username didn't work
35                        Adding of email provider exclusion (like *@hotmail.com) - Warning ! -> Known bug : This feature doesn't work on user profile page. So, already registered users can change their email address to a forbiden one.
36
37-- 2.10.9a : Email provider exclusion is no longer case sensitive
38
39-- 2.10.9b : Bug fixed - Home icon wasn't linked to gallery url in ConfirmMail page. If GALLERY_URL is not set, Home icon gets the pwg root path.
40
41-- 2.10.9c : Bug fixed - If Email provider exclusion is set off, new registered user will have a PHP notice on "Undefined variable: ncsemail"
42
43-- 2.10.9d : Code simplification - need no more ""template"" sub-directory in plugin directory for enhance "back link" icon in ConfirMail.tpl
44
45-- 2.10.9e : Compatibility improvement with PHP 5.3 - Some old functions will be deprecated like :
46                                ereg replaced by preg_match
47                                eregi replace by preg_match with "i" moderator
48                                split replace by preg_split
49                               
50-- 2.10.9f : Compatibility bug fixed when used with DynamicRecentPeriod plugin
51
52-- 2.11.0 : New tabsheet menu to manage ConfirMail functions (setting a timeout without validation, Cleanup expired user's accounts, Force confirmation, Renew validation key, list unvalidated users,...)
53                                                Beautify plugin's main admin panel
54                                               
55-- 2.11.1 : Bug fixed with install and upgrade functions
56                                                Language files correction
57
58-- 2.11.2 : Bug fixed on bad query for unvalidated users display in unvalidated users list
59                                                Bug fixed : Sql syntax error on plugin activation
60
61-- 2.11.3 : On Patricia's request (french forum), the unvalidated users management tab shows users according with the settings of unvalidated group and / or unvalidated status.
62                                                Improvement of unvalidated users management tab - Expired users are displayed in red color text.
63
64*/
65
66/*
67
68 ***** TODO List *****
69
70++ No validation needed for admins users comments (new trigger needed in comments.php)
71
72++ No single email check for admins (new trigger needed in (functions_user.inc.php ?))
73
74++ Password control and enforcement
75  -- Empty password (done in Piwigo 2.x)
76  ++ Can not be the same as username
77  ++ complexity of the password (Numbers+Lettrers+Low and high case+Special+minimal length)
78 
79++ Security : Blocking brut-force attacks !
80
81++ Opportunity to copy a registered user for new user creation
82  ++ new copied user will (or not) belong to the same groups
83  ++ new copied user will (or not) get the same status (visitor, admin, webmaster, guest (??))
84  ++ new copied user will (or not) get the same properties
85  ++ new copied user will (or not) get the same language
86  ... and so on
87 
88*/
89
90
91if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
92
93define('NBC_UserAdvManager_DIR' , basename(dirname(__FILE__)));
94define('NBC_UserAdvManager_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
95
96include_once (NBC_UserAdvManager_PATH.'include/constants.php');
97include_once (NBC_UserAdvManager_PATH.'include/functions_UserAdvManager.inc.php');
98
99load_language('plugin.lang', NBC_UserAdvManager_PATH);
100
101
102/* Plugin admin */
103add_event_handler('get_admin_plugin_menu_links', 'nbc_UserAdvManager_admin_menu');
104
105function nbc_UserAdvManager_admin_menu($menu)
106{
107  array_push($menu,
108    array(
109      'NAME' => 'UserAdvManager',
110      'URL'  => get_admin_plugin_menu_link(NBC_UserAdvManager_PATH.'/admin/UserAdvManager_admin.php')
111    )
112  );
113
114  return $menu;
115}
116
117
118
119/* User creation */
120add_event_handler('register_user', 'UserAdvManager_Adduser');
121
122function UserAdvManager_Adduser($register_user)
123{
124  global $conf;
125 
126  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
127
128  if (( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true'))
129       
130        SendMail2User(1, $register_user['id'], $register_user['username'], $_POST['password'], $register_user['email'], true);
131}
132
133
134
135/* User deletion */
136add_event_handler('delete_user', 'UserAdvManager_Deluser');
137
138function UserAdvManager_Deluser($user_id)
139{
140
141  DeleteConfirmMail($user_id);
142
143}
144
145
146
147add_event_handler('init', 'UserAdvManager_InitPage');
148 
149function UserAdvManager_InitPage()
150{
151  load_language('plugin.lang', NBC_UserAdvManager_PATH);
152  global $conf, $template, $page, $lang;
153
154  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
155 
156
157  if ( isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' )
158    $lang['reg_err_login5'] = l10n('reg_err_login5');
159 
160
161 
162/* User identification */
163  if (script_basename() == 'identification')
164  {
165    if (isset($_POST['login']))
166    {
167      /* User non case sensitive */
168      if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' )
169      {
170        $new_username =  NotSensibleSearchUsername($_POST['username']);
171        $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
172      }
173    }
174  }
175
176
177
178/* Admin user management */
179  if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list')
180  {
181    if (isset($_POST['submit_add']))
182    {
183      /* User non case sensitive */
184      if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' )
185      {
186        $new_username =  NotSensibleSearchUsername($_POST['login']);
187        $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username;
188      }
189
190
191      /* Username without forbidden keys */
192      if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login']))
193      {
194        $lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'";
195        $_POST['login'] = '';
196      }
197
198      /* Email without forbidden domains */
199      /* This don't work on call of ValidateEmailProvider() function - Why ?? -> Due to the "return = false|true" in function ?*/
200      //if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['email']) and !ValidateEmailProvider($_POST['email']))
201      //{
202      //  $lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
203          //  $_POST['login'] = '';
204          //}
205      /* This work with a code copy of ValidateEmailProvider() function */
206                        if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['email']))
207                        {
208                        $ncsemail = strtolower($_POST['email']);
209                        $conf_nbc_MailExclusion = preg_split('/,/',$conf_nbc_UserAdvManager[13]);
210                        for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
211                    {
212                  $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
213                                if (preg_match($pattern, $ncsemail))
214                        {
215                        $lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
216                        $_POST['login'] = '';
217                                        }
218                                }
219                        }
220    }
221  }
222
223/* User creation */
224  if (script_basename() == 'register')
225  {
226    if (isset($_POST['submit']))
227    {
228      /* Username non case sensitive */
229      if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true')
230      {
231        $new_username =  NotSensibleSearchUsername($_POST['login']);
232        $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username;
233      }
234
235
236      /* Username without forbidden keys */
237      if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login']))
238      {
239        $lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'";
240        $_POST['login'] = '';
241      }
242
243
244      /* Email without forbidden domains */
245      /* This don't work on call of ValidateEmailProvider() function - Why ?? -> Due to the "return = false|true" in function ?*/
246      //if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']) and !ValidateEmailProvider($_POST['mail_address']))
247      //{
248      //  $lang['reg_err_mail_address'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
249      //  $_POST['mail_address'] = '';
250      //}
251      /* This work with a code copy of ValidateEmailProvider() function */
252                        if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']))
253                  {
254                        $ncsemail = strtolower($_POST['mail_address']);
255                    $conf_nbc_MailExclusion = preg_split('/,/',$conf_nbc_UserAdvManager[13]);
256                                for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
257                          {
258                                $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
259                                if (preg_match($pattern, $ncsemail))
260                                  {
261                                        $lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
262                                                $_POST['login'] = '';
263                                  }
264                          }
265                  }
266    }
267  }
268
269/* User profile update */
270  if (script_basename() == 'profile')
271  {
272    if (isset($_POST['validate']))
273    {
274      /* Sending email to user */
275      if (( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true'))
276      {
277        global $conf, $user ;
278        $errors = array();
279 
280        $int_pattern = '/^\d+$/';
281        if (empty($_POST['nb_image_line'])
282            or (!preg_match($int_pattern, $_POST['nb_image_line'])))
283        {
284          $errors[] = l10n('nb_image_line_error');
285        }
286     
287        if (empty($_POST['nb_line_page'])
288            or (!preg_match($int_pattern, $_POST['nb_line_page'])))
289        {
290          $errors[] = l10n('nb_line_page_error');
291        }
292     
293        if ($_POST['maxwidth'] != ''
294            and (!preg_match($int_pattern, $_POST['maxwidth'])
295                 or $_POST['maxwidth'] < 50))
296        {
297          $errors[] = l10n('maxwidth_error');
298        }
299        if ($_POST['maxheight']
300             and (!preg_match($int_pattern, $_POST['maxheight'])
301                   or $_POST['maxheight'] < 50))
302        {
303          $errors[] = l10n('maxheight_error');
304        }
305
306        if (isset($_POST['mail_address']))
307        {
308          $mail_error = validate_mail_address($user['id'], $_POST['mail_address']);
309          if (!empty($mail_error))
310          {
311            $errors[] = $mail_error;
312          }
313         
314                                        if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']))
315                                {
316                                        $ncsemail = strtolower($_POST['mail_address']);
317                                $conf_nbc_MailExclusion = preg_split('/,/',$conf_nbc_UserAdvManager[13]);
318                                                for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
319                                        {
320                                                $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
321                                                if (preg_match($pattern, $ncsemail))
322                                                {
323                                                $mail_error = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
324                                                }
325                                        }
326                                }
327                if (!empty($mail_error))
328          {
329            $errors[] = $mail_error;
330          }
331        }
332
333        $typemail = 3;
334       
335        if (!empty($_POST['use_new_pwd']))
336        {
337          $typemail = 2;
338
339          // password must be the same as its confirmation
340          if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
341          {
342            $errors[] = l10n('New password confirmation does not correspond');
343          }
344     
345          if ( !defined('IN_ADMIN') )
346          {// changing password requires old password
347            $query = '
348              SELECT '.$conf['user_fields']['password'].' AS password
349              FROM '.USERS_TABLE.'
350              WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
351            ;';
352            list($current_password) = mysql_fetch_row(pwg_query($query));
353       
354            if ($conf['pass_convert']($_POST['password']) != $current_password)
355            {
356              $errors[] = l10n('Current password is wrong');
357            }
358          }
359        }
360       
361        $confirm_mail_need = false;
362             
363        if (!empty($_POST['mail_address']))
364        {
365          $query = '
366            SELECT '.$conf['user_fields']['email'].' AS email
367            FROM '.USERS_TABLE.'
368            WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
369          ;';
370          list($current_email) = mysql_fetch_row(pwg_query($query));
371     
372          if ( $_POST['mail_address'] != $current_email and ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true') )
373            $confirm_mail_need = true;
374        }
375
376        if (count($errors) == 0 and (!empty($_POST['use_new_pwd']) and ( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or $confirm_mail_need) )
377        {
378          $query = '
379            SELECT '.$conf['user_fields']['username'].'
380            FROM '.USERS_TABLE.'
381            WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
382          ;';
383          list($username) = mysql_fetch_row(pwg_query($query));
384
385
386          SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need);
387        }
388      }
389    }
390  }
391}
392
393add_event_handler('user_comment_check', 'UserAdvManager_CheckEmptyCommentAuthor', 50, 2);
394
395function UserAdvManager_CheckEmptyCommentAuthor($comment_action, $comm)
396{
397  load_language('plugin.lang', NBC_UserAdvManager_PATH);
398  global $infos, $conf, $template;
399
400  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
401
402/* User creation OR update */
403  if (isset($conf_nbc_UserAdvManager[6]) and $conf_nbc_UserAdvManager[6] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest')
404  {
405    $comment_action = 'reject';
406
407    array_push($infos, l10n('UserAdvManager_Empty Author'));
408  }
409
410  return $comment_action;
411}
412
413?>
Note: See TracBrowser for help on using the repository browser.