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

Last change on this file since 27296 was 27296, checked in by LucMorizur, 11 years ago

Fix bug:3044

File size: 6.8 KB
Line 
1<?php
2/*
3Plugin Name: LCAS
4Version: 2.3.0
5Description: Allow to disable login/register name to be sensible to the case/accents
6Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=513
7Author: Eric, Whiler, LucMorizur
8Author URI: http://www.infernoweb.net, http://blogs.wittwer.fr/whiler, http://myr.luc.free.fr
9*/
10
11/* History:  LCAS_PATH.'CHANGELOG.txt' */
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_PATH'))
20 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);
26load_language('messages.lang', LCAS_PATH);
27
28
29/* Plugin admin */
30add_event_handler('get_admin_plugin_menu_links', 'LCAS_admin_menu');
31
32function LCAS_admin_menu($menu)
33{
34// +-----------------------------------------------------------------------+
35// |                      Getting plugin name                              |
36// +-----------------------------------------------------------------------+
37  $plugin =  LCAS_PluginInfos(LCAS_PATH);
38  $name = $plugin['name'];
39
40  array_push($menu,
41    array(
42      'NAME' => $name,
43      'URL' => get_root_url().'admin.php?page=plugin-'.basename(LCAS_PATH)
44    )
45  );
46
47  return $menu;
48}
49
50// Check users identification
51// Define prefilter to add tooltips on register page
52add_event_handler('init', 'LCAS_InitPage');
53
54// For page password.php, modifies $POST['username_or_email'] with registered
55// username, if this username is found in the DB with current rules of LCAS.
56add_event_handler('loc_begin_password', 'LCAS_InitPage');
57
58function LCAS_InitPage()
59{
60  global $conf;
61
62  $conf_LCAS = unserialize($conf['LoginCaseAccentsSensitivity']);
63 
64  // Set $conf['insensitive_case_logon'] to false, as LCAS takes completely
65  // in charge everything concerning the case and the accents in the login
66  if ($conf_LCAS[0] != '0') $conf['insensitive_case_logon'] = false;
67
68  $s = script_basename();
69  // Add tooltips on register page
70  if ($s == 'register') {
71    $template->assign(array(
72      'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])],
73      'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_register'],
74    ));
75    $template->set_prefilter('register', 'LCAS_add_tooltips_prefilter_register');
76  }
77  else if ($s == 'identification') $p = 'username';
78  else if ($s == 'password') $p = 'username_or_email';
79  else return false;
80  if (isset($_POST[$p]) and isset($conf_LCAS[0])) {
81    $new_username = LCAS_SearchCaseUsername($_POST[$p],$conf_LCAS[0]);
82    $_POST[$p] = $new_username == '' ? $_POST[$p] : $new_username;
83  }
84}
85
86function LCAS_add_tooltips_prefilter_register($content, &$smarty) {
87  $search = 'for="login"';
88  $replacement = 'for="login" title="{$LCAS_username_tooltip}"';
89  $content = str_replace($search, $replacement, $content);
90  $search = 'name="login"';
91  $replacement = 'name="login" title="{$LCAS_username_tooltip}"';
92  $content = str_replace($search, $replacement, $content);
93  $search = 'for="password"';
94  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
95  $content = str_replace($search, $replacement, $content);
96  $search = 'name="password"';
97  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
98  $content = str_replace($search, $replacement, $content);
99  $search = 'for="password_conf"';
100  $replacement = 'for="password_conf" title="{$LCAS_password_tooltip}"';
101  $content = str_replace($search, $replacement, $content);
102  $search = 'name="password_conf"';
103  $replacement = 'name="password_conf" title="{$LCAS_password_tooltip}"';
104  $content = str_replace($search, $replacement, $content);
105  return $content;
106}
107
108// Check users registration
109// Returns error
110add_event_handler('register_user_check', 'LCAS_RegistrationCheck');
111
112function LCAS_RegistrationCheck($errors)
113{
114  global $conf, $lang;
115 
116  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
117 
118  load_language('plugin.lang', LCAS_PATH);
119
120  if (isset($conf_LCAS[0]))
121   $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[0]);
122 
123  if (isset($NewPostLogin) and get_userid($NewPostLogin))
124   $errors[] = $lang['LCAS_error'][intval($conf_LCAS[0])];
125 
126  return $errors;
127}
128
129/**
130 *
131 * LCAS_add_tooltips()
132 * add tooltips on username and password fields
133 *
134 * @param no parameter
135 * @return no return value
136 */
137
138add_event_handler('blockmanager_apply', 'LCAS_add_tooltips_index');
139
140function LCAS_add_tooltips_index() {
141  global $template, $conf, $lang;
142 
143  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
144 
145  $template->assign(array(
146    'LCAS_username_tooltip' =>
147     $lang['LCAS_tooltip_username_index'][intval($conf_LCAS[0])],
148    'LCAS_password_tooltip' =>
149     $lang['LCAS_tooltip_password_index'],
150  ));
151  $template->set_prefilter('menubar', 'LCAS_add_tooltips_prefilter_index');
152}
153
154function LCAS_add_tooltips_prefilter_index($content, &$smarty) {
155  $search = 'for="username"';
156  $replacement = 'for="username" title="{$LCAS_username_tooltip}"';
157  $content = str_replace($search, $replacement, $content);
158  $search = 'name="username"';
159  $replacement = 'name="username" title="{$LCAS_username_tooltip}"';
160  $content = str_replace($search, $replacement, $content);
161  $search = 'for="password"';
162  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
163  $content = str_replace($search, $replacement, $content);
164  $search = 'name="password"';
165  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
166  $content = str_replace($search, $replacement, $content);
167  return $content;
168}
169
170// LCAS_admin_user_filter
171//
172// Allow to use LCAS for searching usernames, in admin user_list page
173//
174add_event_handler('loc_end_admin', 'LCAS_admin_user_filter');
175
176function LCAS_admin_user_filter() {
177  if (
178    strpos($_SERVER['REQUEST_URI'], 'user_list') !== false and
179    isset($_GET['username']) and !empty($_GET['username'])
180  ) include(LCAS_PATH.'include/admin_search.inc.php');
181}
182
183// LCAS_add_tooltips_user_list
184//
185// Also set prefilter to add tooltip
186//
187add_event_handler('loc_begin_admin', 'LCAS_add_tooltips_user_list');
188
189function LCAS_add_tooltips_user_list() {
190global $template, $conf, $lang;
191 
192  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
193 
194  if (strpos($_SERVER['REQUEST_URI'], 'user_list') !== false) {
195    $template->assign(
196      'LCAS_username_tooltip_admin',
197      $lang['LCAS_tooltip_username_admin'][intval($conf_LCAS[0])]
198    );
199    $template->set_prefilter('user_list','LCAS_add_tooltips_prefilter_admin');
200  }
201}
202
203function LCAS_add_tooltips_prefilter_admin($content, &$smarty) {
204  $search = 'name="username"';
205  $replacement = 'name="username" title="{$LCAS_username_tooltip_admin}"';
206  $content = str_replace($search, $replacement, $content);
207  return $content;
208}
209
210?>
Note: See TracBrowser for help on using the repository browser.