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

Last change on this file since 9470 was 9470, checked in by LucMorizur, 13 years ago

If chosen option is 0, $conf[insensitive_case_logon] must remain unchanged

File size: 5.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);
26load_language('messages.lang', LCAS_PATH);
27
28$t = pwg_db_fetch_row(pwg_query('
29  SELECT `value`
30  FROM `'.CONFIG_TABLE.'`
31  WHERE `param` = "LoginCaseAccentsSensitivity"
32  LIMIT 1;
33'));
34
35$conf['LoginCaseAccentsSensitivity'] = $t[0];
36
37/* Plugin admin */
38add_event_handler('get_admin_plugin_menu_links', 'LCAS_admin_menu');
39
40function LCAS_admin_menu($menu)
41{
42// +-----------------------------------------------------------------------+
43// |                      Getting plugin name                              |
44// +-----------------------------------------------------------------------+
45  $plugin =  LCAS_PluginInfos(LCAS_PATH);
46  $name = $plugin['name'];
47 
48                                                                                                // to be removed in final version :
49                                                                                                global $template; 
50                                                                                                $template->delete_compiled_templates(); 
51 
52  array_push($menu,
53    array(
54      'NAME' => $name,
55      'URL'  => get_admin_plugin_menu_link(LCAS_PATH.'/admin/LCAS_admin.php')
56    )
57  );
58
59  return $menu;
60}
61
62function LCAS_add_tooltips_prefilter_register($content, &$smarty) {
63  $search = 'for="login"';
64  $replacement = 'for="login" title="{$LCAS_username_tooltip}"';
65  $content = str_replace($search, $replacement, $content);
66  $search = 'name="login"';
67  $replacement = 'name="login" title="{$LCAS_username_tooltip}"';
68  $content = str_replace($search, $replacement, $content);
69  $search = 'for="password"';
70  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
71  $content = str_replace($search, $replacement, $content);
72  $search = 'name="password"';
73  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
74  $content = str_replace($search, $replacement, $content);
75  $search = 'for="password_conf"';
76  $replacement = 'for="password_conf" title="{$LCAS_password_tooltip}"';
77  $content = str_replace($search, $replacement, $content);
78  $search = 'name="password_conf"';
79  $replacement = 'name="password_conf" title="{$LCAS_password_tooltip}"';
80  $content = str_replace($search, $replacement, $content);
81  return $content;
82}
83
84// Check users identification
85add_event_handler('init', 'LCAS_InitPage');
86 
87function LCAS_InitPage()
88{
89  global $template, $conf, $lang;
90
91  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
92 
93  // Set $conf['insensitive_case_logon'] to false, as LCAS takes completely
94  // in charge everything around the case and the accents
95  if ($conf_LCAS[0] != '0')
96   $conf['insensitive_case_logon'] = false;
97 
98/* User identification */
99  if (script_basename() == 'identification')
100  {
101    if (isset($_POST['username']) and isset($conf_LCAS[0]))
102    {
103      $new_username = LCAS_SearchCaseUsername($_POST['username'],$conf_LCAS[0]);
104      $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
105    }
106  }
107 
108  // Add tooltips on register page
109  if (script_basename() == 'register') {
110    $template->assign(array(
111      'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])],
112      'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_register'],
113    ));
114    $template->set_prefilter('register', 'LCAS_add_tooltips_prefilter_register');
115  }
116}
117
118// Check users registration
119// Returns error
120add_event_handler('register_user_check', 'LCAS_RegistrationCheck');
121
122function LCAS_RegistrationCheck($errors)
123{
124  global $conf, $lang;
125 
126  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
127 
128  load_language('plugin.lang', LCAS_PATH);
129
130  if (isset($conf_LCAS[0]))
131   $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[0]);
132 
133  if (isset($NewPostLogin) and get_userid($NewPostLogin))
134   $errors[] = $lang['LCAS_error'][intval($conf_LCAS[0])];
135 
136  return $errors;
137}
138
139/**
140 *
141 * LCAS_add_tooltips()
142 * add tooltips on username and password fields
143 *
144 * @param no parameter
145 * @return no return value
146 */
147
148add_event_handler('blockmanager_apply', 'LCAS_add_tooltips_index');
149
150function LCAS_add_tooltips_prefilter_index($content, &$smarty) {
151  $search = 'for="username"';
152  $replacement = 'for="username" title="{$LCAS_username_tooltip}"';
153  $content = str_replace($search, $replacement, $content);
154  $search = 'name="username"';
155  $replacement = 'name="username" title="{$LCAS_username_tooltip}"';
156  $content = str_replace($search, $replacement, $content);
157  $search = 'for="password"';
158  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
159  $content = str_replace($search, $replacement, $content);
160  $search = 'name="password"';
161  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
162  $content = str_replace($search, $replacement, $content);
163  return $content;
164}
165
166function LCAS_add_tooltips_index() {
167  global $template, $conf, $lang;
168 
169  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
170 
171  $template->assign(array(
172    'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_index'][intval($conf_LCAS[0])],
173    'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_index'],
174  ));
175  $template->set_prefilter('menubar', 'LCAS_add_tooltips_prefilter_index');
176}
177
178?>
Note: See TracBrowser for help on using the repository browser.