source: extensions/NBC_UserAdvManager/branches/2.15/main.inc.php @ 9568

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