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

Revision 28237, 8.5 KB checked in by LucMorizur, 6 years ago (diff)

Version 2.3.1: fix bug:3044 thanks to svn:27296 and svn:27322

Line 
1<?php
2/*
3Plugin Name: LCAS
4Version: 2.3.1
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 $template, $conf, $lang;
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  $p = '';
69
70  switch (script_basename()) {
71
72    case 'register':
73      $template->assign(array(
74        'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])],
75        'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_register'],
76      ));
77      $template->set_prefilter('register', 'LCAS_add_tooltips_prefilter_register');
78    break;
79
80    case 'identification':
81      $p = 'username';
82      $template->assign(array(
83        'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])],
84        'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_register'],
85      ));
86      $template->set_prefilter('identification', 'LCAS_add_tooltips_prefilter_identification');
87    break;
88
89    case 'password':
90      $p = 'username_or_email';
91      $template->assign(array(
92        'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])],
93      ));
94      $template->set_prefilter('password', 'LCAS_add_tooltips_prefilter_password');
95    break;
96
97    default: return false;
98  }
99
100  if (($p != '') and isset($_POST[$p]) and isset($conf_LCAS[0])) {
101    $new_username = LCAS_SearchCaseUsername($_POST[$p],$conf_LCAS[0]);
102    $_POST[$p] = $new_username == '' ? $_POST[$p] : $new_username;
103  }
104}
105
106function LCAS_add_tooltips_prefilter_password($content, &$smarty) {
107  $search = '<label>
108      {\'Username or email\'';
109  $replacement = '<label title="{$LCAS_username_tooltip}">
110      {\'Username or email\'';
111  $content = str_replace($search, $replacement, $content);
112  $search = 'name="username_or_email"';
113  $replacement = 'name="username_or_email" title="{$LCAS_username_tooltip}"';
114  $content = str_replace($search, $replacement, $content);
115  return $content;
116}
117
118function LCAS_add_tooltips_prefilter_register($content, &$smarty) {
119  $search = 'for="login"';
120  $replacement = 'for="login" title="{$LCAS_username_tooltip}"';
121  $content = str_replace($search, $replacement, $content);
122  $search = 'name="login"';
123  $replacement = 'name="login" title="{$LCAS_username_tooltip}"';
124  $content = str_replace($search, $replacement, $content);
125  $search = 'for="password"';
126  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
127  $content = str_replace($search, $replacement, $content);
128  $search = 'name="password"';
129  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
130  $content = str_replace($search, $replacement, $content);
131  $search = 'for="password_conf"';
132  $replacement = 'for="password_conf" title="{$LCAS_password_tooltip}"';
133  $content = str_replace($search, $replacement, $content);
134  $search = 'name="password_conf"';
135  $replacement = 'name="password_conf" title="{$LCAS_password_tooltip}"';
136  $content = str_replace($search, $replacement, $content);
137  return $content;
138}
139
140function LCAS_add_tooltips_prefilter_identification($content, &$smarty) {
141  $search = 'for="username"';
142  $replacement = 'for="username" title="{$LCAS_username_tooltip}"';
143  $content = str_replace($search, $replacement, $content);
144  $search = 'name="username"';
145  $replacement = 'name="username" title="{$LCAS_username_tooltip}"';
146  $content = str_replace($search, $replacement, $content);
147  $search = 'for="password"';
148  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
149  $content = str_replace($search, $replacement, $content);
150  $search = 'name="password"';
151  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
152  $content = str_replace($search, $replacement, $content);
153  return $content;
154}
155
156// Check users registration
157// Returns error
158add_event_handler('register_user_check', 'LCAS_RegistrationCheck');
159
160function LCAS_RegistrationCheck($errors)
161{
162  global $conf, $lang;
163 
164  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
165 
166  load_language('plugin.lang', LCAS_PATH);
167
168  if (isset($conf_LCAS[0]))
169   $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[0]);
170 
171  if (isset($NewPostLogin) and get_userid($NewPostLogin))
172   $errors[] = $lang['LCAS_error'][intval($conf_LCAS[0])];
173 
174  return $errors;
175}
176
177/**
178 *
179 * LCAS_add_tooltips()
180 * add tooltips on username and password fields
181 *
182 * @param no parameter
183 * @return no return value
184 */
185
186add_event_handler('blockmanager_apply', 'LCAS_add_tooltips_index');
187
188function LCAS_add_tooltips_index() {
189  global $template, $conf, $lang;
190 
191  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
192 
193  $template->assign(array(
194    'LCAS_username_tooltip' =>
195     $lang['LCAS_tooltip_username_index'][intval($conf_LCAS[0])],
196    'LCAS_password_tooltip' =>
197     $lang['LCAS_tooltip_password_index'],
198  ));
199  $template->set_prefilter('menubar', 'LCAS_add_tooltips_prefilter_index');
200}
201
202function LCAS_add_tooltips_prefilter_index($content, &$smarty) {
203  $search = 'for="username"';
204  $replacement = 'for="username" title="{$LCAS_username_tooltip}"';
205  $content = str_replace($search, $replacement, $content);
206  $search = 'name="username"';
207  $replacement = 'name="username" title="{$LCAS_username_tooltip}"';
208  $content = str_replace($search, $replacement, $content);
209  $search = 'for="password"';
210  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
211  $content = str_replace($search, $replacement, $content);
212  $search = 'name="password"';
213  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
214  $content = str_replace($search, $replacement, $content);
215  return $content;
216}
217
218// LCAS_admin_user_filter
219//
220// Allow to use LCAS for searching usernames, in admin user_list page
221//
222add_event_handler('loc_end_admin', 'LCAS_admin_user_filter');
223
224function LCAS_admin_user_filter() {
225  if (
226    strpos($_SERVER['REQUEST_URI'], 'user_list') !== false and
227    isset($_GET['username']) and !empty($_GET['username'])
228  ) include(LCAS_PATH.'include/admin_search.inc.php');
229}
230
231// LCAS_add_tooltips_user_list
232//
233// Also set prefilter to add tooltip
234//
235add_event_handler('loc_begin_admin', 'LCAS_add_tooltips_user_list');
236
237function LCAS_add_tooltips_user_list() {
238global $template, $conf, $lang;
239 
240  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
241 
242  if (strpos($_SERVER['REQUEST_URI'], 'user_list') !== false) {
243    $template->assign(
244      'LCAS_username_tooltip_admin',
245      $lang['LCAS_tooltip_username_admin'][intval($conf_LCAS[0])]
246    );
247    $template->set_prefilter('user_list','LCAS_add_tooltips_prefilter_admin');
248  }
249}
250
251function LCAS_add_tooltips_prefilter_admin($content, &$smarty) {
252  $search = 'name="username"';
253  $replacement = 'name="username" title="{$LCAS_username_tooltip_admin}"';
254  $content = str_replace($search, $replacement, $content);
255  return $content;
256}
257
258?>
Note: See TracBrowser for help on using the repository browser.