source: extensions/LCAS/trunk/main.inc.php @ 8239

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

bug 2079 fixed : Accents sensitivity enabled on registration
Localisation files updates
English translation done

File size: 3.9 KB
Line 
1<?php
2/*
3Plugin Name: LCAS
4Version: 2.1.0
5Description: Allow to disable login/register name to be sensible to the case/accents
6Plugin URI: http://fr.piwigo.org/forum/viewtopic.php?pid=158563
7Author: Eric, LucMorizur, Whiler
8Author URI: http://www.infernoweb.net, http://blogs.wittwer.fr/whiler/
9*/
10
11/* History:  LCAS_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('LCAS_DIR')) define('LCAS_DIR' , basename(dirname(__FILE__)));
20if (!defined('LCAS_PATH')) define('LCAS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
21
22include_once (LCAS_PATH.'include/constants.php');
23include_once (LCAS_PATH.'include/functions.inc.php');
24
25load_language('plugin.lang', LCAS_PATH);
26
27
28/* Plugin admin */
29add_event_handler('get_admin_plugin_menu_links', 'LCAS_admin_menu');
30
31function LCAS_admin_menu($menu)
32{
33// +-----------------------------------------------------------------------+
34// |                      Getting plugin name                              |
35// +-----------------------------------------------------------------------+
36  $plugin =  LCAS_PluginInfos(LCAS_PATH);
37  $name = $plugin['name'];
38 
39  array_push($menu,
40    array(
41      'NAME' => $name,
42      'URL'  => get_admin_plugin_menu_link(LCAS_PATH.'/admin/LCAS_admin.php')
43    )
44  );
45
46  return $menu;
47}
48
49// Check users identification
50add_event_handler('init', 'LCAS_InitPage');
51 
52function LCAS_InitPage()
53{
54  global $conf;
55
56  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
57 
58/* User identification */
59  if (script_basename() == 'identification')
60  {
61    if (isset($_POST['username']))
62    {
63      /* Username is case insensitive only */
64      if (isset($conf_LCAS[0]) and $conf_LCAS[0] == 'true' and isset($conf_LCAS[1]) and $conf_LCAS[1] == 'false')
65      {
66        $new_username = LCAS_SearchCaseUsername($_POST['username'],1);
67        $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
68      }
69
70      /* Username is accent insensitive only */
71      if (isset($conf_LCAS[0]) and $conf_LCAS[0] == 'false' and isset($conf_LCAS[1]) and $conf_LCAS[1] == 'true')
72      {
73        $new_username = LCAS_SearchCaseUsername($_POST['username'],2);
74        $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
75      }
76
77      //* Username is accent and case insensitive */
78      if (isset($conf_LCAS[0]) and $conf_LCAS[0] == 'true' and isset($conf_LCAS[1]) and $conf_LCAS[1] == 'true')
79      {
80        $new_username = LCAS_SearchCaseUsername($_POST['username'],3);
81        $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
82      }
83    }
84  }
85}
86
87// Check users registration
88add_event_handler('register_user_check', 'LCAS_RegistrationCheck');
89
90function LCAS_RegistrationCheck($errors)
91{
92  global $conf, $lang;
93 
94  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
95 
96  load_language('plugin.lang', LCAS_PATH);
97
98  /* Username is accent and case insensitive */
99  if (isset($conf_LCAS[0]) and $conf_LCAS[0] == 'true' and $conf['insensitive_case_logon'] == true and isset($conf_LCAS[1]) and $conf_LCAS[1] == 'true')
100  {
101    $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'],3);
102  }
103  /* Username is accent insensitive only */
104  elseif (isset($conf_LCAS[0]) and $conf_LCAS[0] == 'false' and $conf['insensitive_case_logon'] == false and isset($conf_LCAS[1]) and $conf_LCAS[1] == 'true')
105  {
106    $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'],2);
107  }
108  /* Username is case insensitive only is already controled by Piwigo with $conf['insensitive_case_logon'] == true */
109
110  if (isset($NewPostLogin) and get_userid($NewPostLogin))
111  {
112    $lang['reg_err_login5'] = $lang['reg_err_login5'].l10n('LCAS_accent_error');
113    array_push($errors, $lang['reg_err_login5']);
114  }
115 
116  return $errors;
117}
118?>
Note: See TracBrowser for help on using the repository browser.