source: extensions/UserAdvManager/branches/2.15/main.inc.php @ 9875

Last change on this file since 9875 was 8041, checked in by Eric, 13 years ago

bug 2050 fixed : Compatibility with Captcha
IT translation improved (thx to Rio)
New version 2.15.10 hard coded

  • Property svn:eol-style set to LF
File size: 12.8 KB
Line 
1<?php
2/*
3Plugin Name: UserAdvManager
4Version: 2.15.10
5Description: Renforcer la 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/* History:  UAM_PATH.'Changelog.txt.php' */
12
13/*
14 ***** TODO List *****
15See project bugtracker: http://piwigo.org/bugs/my_view_page.php
16*/
17
18if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
19if (!defined('UAM_DIR')) define('UAM_DIR' , basename(dirname(__FILE__)));
20if (!defined('UAM_PATH')) define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
21
22include_once (UAM_PATH.'include/constants.php');
23include_once (UAM_PATH.'include/functions.inc.php');
24
25load_language('plugin.lang', UAM_PATH);
26
27
28/* Plugin admin */
29add_event_handler('get_admin_plugin_menu_links', 'UAM_admin_menu');
30
31function UAM_admin_menu($menu)
32{
33// +-----------------------------------------------------------------------+
34// |                      Getting plugin name                              |
35// +-----------------------------------------------------------------------+
36  $plugin =  PluginInfos(UAM_PATH);
37  $name = $plugin['name'];
38 
39  array_push($menu,
40    array(
41      'NAME' => $name,
42      'URL'  => get_admin_plugin_menu_link(UAM_PATH.'/admin/UAM_admin.php')
43    )
44  );
45
46  return $menu;
47}
48
49/* Lastvisit table feed for Ghost Tracker */
50add_event_handler('loc_begin_index', 'UAM_GhostTracker');
51
52function UAM_GhostTracker()
53{
54  global $conf, $user;
55
56  $conf_UAM = unserialize($conf['UserAdvManager']);
57
58  /* Admins, Guests and Adult_Content users are not tracked for Ghost Tracker or Users Tracker */
59  if (!is_admin() and !is_a_guest() and $user['username'] != "16" and $user['username'] != "18")
60  {
61    if ((isset($conf_UAM[16]) and $conf_UAM[16] == 'true') or (isset($conf_UAM[19]) and $conf_UAM[19] == 'true'))
62    {
63
64      $userid = get_userid($user['username']);
65         
66      /* Looking for existing entry in last visit table */
67      $query = '
68SELECT *
69  FROM '.USER_LASTVISIT_TABLE.'
70WHERE user_id = '.$userid.'
71;';
72       
73      $count = pwg_db_num_rows(pwg_query($query));
74         
75      if ($count == 0)
76      {
77        /* If not, data are inserted in table */
78        $query = '
79INSERT INTO '.USER_LASTVISIT_TABLE.' (user_id, lastvisit, reminder)
80VALUES ('.$userid.', now(), "false")
81;';
82        pwg_query($query);
83      }
84      else if ($count > 0)
85      {
86        /* If yes, data are updated in table */
87        $query = '
88UPDATE '.USER_LASTVISIT_TABLE.'
89SET lastvisit = now(), reminder = "false"
90WHERE user_id = '.$userid.'
91LIMIT 1
92;';
93        pwg_query($query);
94      }
95    }
96  }
97}
98
99
100/* User creation */
101add_event_handler('register_user', 'UAM_Adduser');
102
103function UAM_Adduser($register_user)
104{
105  global $conf;
106
107  $conf_UAM = unserialize($conf['UserAdvManager']);
108
109  // Exclusion of Adult_Content users
110  if ($register_user['username'] != "16" and $register_user['username'] != "18")
111  {
112    if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
113    {
114      /* This is to send an information email and set user to "waiting" group or status until admin validation */
115      $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
116      SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false);
117      setgroup($register_user['id']);// Set to "waiting" group or status until admin validation
118    }
119    elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'false') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
120    {
121      /* This is to set user to "waiting" group or status until admin validation */
122      setgroup($register_user['id']);// Set to "waiting" group or status until admin validation
123    }
124    elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'false'))
125    {
126      /* This is to send an information email without validation key */
127      $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
128      SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false);
129    }
130    /* Sending registration confirmation by email */
131    elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true' or $conf_UAM[0] == 'false') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true'))
132    {
133      if (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'true')
134      {
135        $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
136        SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); 
137      }
138      elseif (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'false')
139      {
140        $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
141        SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false);
142      }
143      elseif (!is_admin())
144      {
145        $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
146        SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true);
147      }
148    }
149  }
150}
151
152
153/* User deletion */
154add_event_handler('delete_user', 'UAM_Deluser');
155
156function UAM_Deluser($user_id)
157{
158  /* Cleanup for ConfirmMail table */
159  DeleteConfirmMail($user_id);
160  /* Cleanup for LastVisit table */
161  DeleteLastVisit($user_id);
162  /* Cleanup Redirection settings */
163  DeleteRedir($user_id);
164}
165
166
167// Check users registration
168add_event_handler('register_user_check', 'UAM_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
169
170function UAM_RegistrationCheck($errors, $user)
171{
172  global $conf;
173
174  // Exclusion of Adult_Content users
175  if ($user['username'] != "16" and $user['username'] != "18")
176  {
177    load_language('plugin.lang', UAM_PATH);
178
179    $PasswordCheck = 0;
180
181    $conf_UAM = unserialize($conf['UserAdvManager']);
182
183    // Password enforcement control
184    if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14]))
185    {
186      if (!empty($user['password']) and !is_admin())
187      {
188        $PasswordCheck = testpassword($user['password']);
189 
190        if ($PasswordCheck < $conf_UAM[14])
191        {
192          $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
193          $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14];
194          array_push($errors, $lang['reg_err_pass']);
195        }
196      }
197      else if (!empty($user['password']) and is_admin() and isset($conf_UAM[15]) and $conf_UAM[15] == 'true')
198      {
199        $PasswordCheck = testpassword($user['password']);
200 
201        if ($PasswordCheck < $conf_UAM[14])
202        {
203          $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
204          $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14];
205          array_push($errors, $lang['reg_err_pass']);
206        }
207      }
208    }
209
210    // Username without forbidden keys
211    if (isset($conf_UAM[6]) and $conf_UAM[6] == 'true' and !empty($user['username']) and ValidateUsername($user['username']) and !is_admin())
212    {
213      $lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_UAM[7]."'";
214      array_push($errors, $lang['reg_err_login1']);
215    }
216
217    // Email without forbidden domains
218    if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($user['email']) and ValidateEmailProvider($user['email']) and !is_admin())
219    {
220      $lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_UAM[12]."'";
221      array_push($errors, $lang['reg_err_login1']);
222    }
223    return $errors;
224  }
225}
226
227
228if (script_basename() == 'profile')
229{
230  add_event_handler('loc_begin_profile', 'UAM_Profile_Init');
231
232  function UAM_Profile_Init()
233  {
234    global $conf, $user, $template;
235
236    $conf_UAM = unserialize($conf['UserAdvManager']);
237   
238    if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true'))
239    {
240      $user_idsOK = array();
241      if (!check_consult($user['id'], $user_idsOK))
242      {
243        $user_idsOK[] = $user['id'];
244       
245        $query = "
246          UPDATE ".CONFIG_TABLE."
247          SET value = \"".implode(',', $user_idsOK)."\"
248          WHERE param = 'UserAdvManager_Redir';";
249         
250        pwg_query($query);
251      }
252    }
253
254    if (isset($_POST['validate']) and !is_admin())
255    {
256      /* Email without forbidden domains */
257      if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['mail_address']))
258      {
259        if (ValidateEmailProvider($_POST['mail_address']))
260        {
261          $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[12]."'");
262          unset($_POST['validate']);
263        }
264      }
265
266      $typemail = 3;
267     
268      if (!empty($_POST['use_new_pwd']))
269      {
270        $typemail = 2;
271       
272        /* Password enforcement control */
273        if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14]))
274        {
275          $PasswordCheck = testpassword($_POST['use_new_pwd']);
276         
277          if ($PasswordCheck < $conf_UAM[14])
278          {
279            $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
280            $template->append('errors', l10n_args($message).$conf_UAM[14]);
281            unset($_POST['use_new_pwd']);
282            unset($_POST['validate']);
283          }
284        }
285      }
286     
287      /* Sending registration confirmation by email */
288      if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
289      {
290        $confirm_mail_need = false;
291             
292        if (!empty($_POST['mail_address']))
293        {
294          $query = '
295SELECT '.$conf['user_fields']['email'].' AS email
296FROM '.USERS_TABLE.'
297WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
298;';
299         
300          list($current_email) = pwg_db_fetch_row(pwg_query($query));
301
302          /* This is to send a new validation key */
303          if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true'))
304       
305            $confirm_mail_need = true;
306
307          /* This is to set the user to "waiting" group or status until admin validation */
308          if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
309       
310            setgroup($register_user['id']);// Set to "waiting" group or status until admin validation
311            $confirm_mail_need = false;
312        }
313       
314        if ((!empty($_POST['use_new_pwd']) and (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or $confirm_mail_need))
315        {
316          $query = '
317SELECT '.$conf['user_fields']['username'].'
318FROM '.USERS_TABLE.'
319WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
320;';
321       
322          list($username) = pwg_db_fetch_row(pwg_query($query));
323
324          SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need);
325        }
326      }
327    }
328  }
329}
330
331
332// RedirectToProfile - Thx to LucMorizur
333// redirects a visitor (except for admins, webmasters and generic statuses) to his
334// profile.php page
335//
336// no variable, no return
337add_event_handler('login_success', 'RedirectToProfile');
338
339function RedirectToProfile()
340{
341  global $conf, $user;
342 
343  $conf_UAM = unserialize($conf['UserAdvManager']);
344 
345  $query ='
346SELECT user_id, status
347FROM '.USER_INFOS_TABLE.'
348WHERE user_id = '.$user['id'].'
349;';
350  $data = pwg_db_fetch_assoc(pwg_query($query));
351 
352  if ($data['status'] <> "admin" and $data['status'] <> "webmaster" and $data['status'] <> "generic")
353  {
354    if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true'))
355    {
356      $user_idsOK = array();
357      if (!check_consult($user['id'], $user_idsOK))
358        redirect(PHPWG_ROOT_PATH.'profile.php');
359    }
360  }
361}
362
363
364add_event_handler('init', 'UAM_InitPage');
365/* *** Important ! This is necessary to make email exclusion work in admin's users management panel *** */
366function UAM_InitPage()
367{
368  load_language('plugin.lang', UAM_PATH);
369  global $conf, $template, $page, $lang, $errors;
370
371  $conf_UAM = unserialize($conf['UserAdvManager']);
372
373/* Admin user management */
374  if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list')
375  {
376    if (isset($_POST['submit_add']))
377    {
378      /* Email without forbidden domains */
379      if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['email']) and ValidateEmailProvider($_POST['email']))
380      {
381        $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[12]."'");
382        unset($_POST['submit_add']);
383      }
384    }
385  }
386}
387
388
389add_event_handler('user_comment_check', 'UAM_CheckEmptyCommentAuthor', 50, 2);
390
391function UAM_CheckEmptyCommentAuthor($comment_action, $comm)
392{
393  load_language('plugin.lang', UAM_PATH);
394  global $infos, $conf, $template;
395
396  $conf_UAM = unserialize($conf['UserAdvManager']);
397
398/* User creation OR update */
399  if (isset($conf_UAM[5]) and $conf_UAM[5] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest')
400  {
401    $comment_action = 'reject';
402
403    array_push($infos, l10n('UAM_Empty Author'));
404  }
405
406  return $comment_action;
407}
408?>
Note: See TracBrowser for help on using the repository browser.