1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: LCAS |
---|
4 | Version: 0.0.0RC1 |
---|
5 | Description: Allow to disable login/register name to be sensible to the case/accents |
---|
6 | Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=513 |
---|
7 | Author: Eric, Whiler, LucMorizur |
---|
8 | Author URI: http://www.infernoweb.net, http://blogs.wittwer.fr/whiler, http://myr.luc.free.fr |
---|
9 | */ |
---|
10 | |
---|
11 | /* History: LCAS_PATH.'Changelog.txt.php' */ |
---|
12 | |
---|
13 | /* |
---|
14 | ***** TODO List ***** |
---|
15 | See project bugtracker: http://piwigo.org/bugs/my_view_page.php |
---|
16 | */ |
---|
17 | |
---|
18 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
19 | if (!defined('LCAS_PATH')) |
---|
20 | define('LCAS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
21 | |
---|
22 | include_once (LCAS_PATH.'include/constants.php'); |
---|
23 | include_once (LCAS_PATH.'include/functions.inc.php'); |
---|
24 | |
---|
25 | load_language('plugin.lang', LCAS_PATH); |
---|
26 | load_language('messages.lang', LCAS_PATH); |
---|
27 | |
---|
28 | |
---|
29 | /* Plugin admin */ |
---|
30 | add_event_handler('get_admin_plugin_menu_links', 'LCAS_admin_menu'); |
---|
31 | |
---|
32 | function 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 |
---|
52 | add_event_handler('init', 'LCAS_InitPage'); |
---|
53 | |
---|
54 | function LCAS_InitPage() |
---|
55 | { |
---|
56 | global $template, $conf, $lang; |
---|
57 | |
---|
58 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
59 | |
---|
60 | // Set $conf['insensitive_case_logon'] to false, as LCAS takes completely |
---|
61 | // in charge everything concerning the case and the accents in the login |
---|
62 | if ($conf_LCAS[0] != '0') $conf['insensitive_case_logon'] = false; |
---|
63 | |
---|
64 | /* User identification */ |
---|
65 | if (script_basename() == 'identification') |
---|
66 | { |
---|
67 | if (isset($_POST['username']) and isset($conf_LCAS[0])) |
---|
68 | { |
---|
69 | $new_username = LCAS_SearchCaseUsername($_POST['username'],$conf_LCAS[0]); |
---|
70 | $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username; |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | // Add tooltips on register page |
---|
75 | if (script_basename() == 'register') { |
---|
76 | $template->assign(array( |
---|
77 | 'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])], |
---|
78 | 'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_register'], |
---|
79 | )); |
---|
80 | $template->set_prefilter('register', 'LCAS_add_tooltips_prefilter_register'); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | function LCAS_add_tooltips_prefilter_register($content, &$smarty) { |
---|
85 | $search = 'for="login"'; |
---|
86 | $replacement = 'for="login" title="{$LCAS_username_tooltip}"'; |
---|
87 | $content = str_replace($search, $replacement, $content); |
---|
88 | $search = 'name="login"'; |
---|
89 | $replacement = 'name="login" title="{$LCAS_username_tooltip}"'; |
---|
90 | $content = str_replace($search, $replacement, $content); |
---|
91 | $search = 'for="password"'; |
---|
92 | $replacement = 'for="password" title="{$LCAS_password_tooltip}"'; |
---|
93 | $content = str_replace($search, $replacement, $content); |
---|
94 | $search = 'name="password"'; |
---|
95 | $replacement = 'name="password" title="{$LCAS_password_tooltip}"'; |
---|
96 | $content = str_replace($search, $replacement, $content); |
---|
97 | $search = 'for="password_conf"'; |
---|
98 | $replacement = 'for="password_conf" title="{$LCAS_password_tooltip}"'; |
---|
99 | $content = str_replace($search, $replacement, $content); |
---|
100 | $search = 'name="password_conf"'; |
---|
101 | $replacement = 'name="password_conf" title="{$LCAS_password_tooltip}"'; |
---|
102 | $content = str_replace($search, $replacement, $content); |
---|
103 | return $content; |
---|
104 | } |
---|
105 | |
---|
106 | // Check users registration |
---|
107 | // Returns error |
---|
108 | add_event_handler('register_user_check', 'LCAS_RegistrationCheck'); |
---|
109 | |
---|
110 | function LCAS_RegistrationCheck($errors) |
---|
111 | { |
---|
112 | global $conf, $lang; |
---|
113 | |
---|
114 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
115 | |
---|
116 | load_language('plugin.lang', LCAS_PATH); |
---|
117 | |
---|
118 | if (isset($conf_LCAS[0])) |
---|
119 | $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[0]); |
---|
120 | |
---|
121 | if (isset($NewPostLogin) and get_userid($NewPostLogin)) |
---|
122 | $errors[] = $lang['LCAS_error'][intval($conf_LCAS[0])]; |
---|
123 | |
---|
124 | return $errors; |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * |
---|
129 | * LCAS_add_tooltips() |
---|
130 | * add tooltips on username and password fields |
---|
131 | * |
---|
132 | * @param no parameter |
---|
133 | * @return no return value |
---|
134 | */ |
---|
135 | |
---|
136 | add_event_handler('blockmanager_apply', 'LCAS_add_tooltips_index'); |
---|
137 | |
---|
138 | function LCAS_add_tooltips_index() { |
---|
139 | global $template, $conf, $lang; |
---|
140 | |
---|
141 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
142 | |
---|
143 | $template->assign(array( |
---|
144 | 'LCAS_username_tooltip' => |
---|
145 | $lang['LCAS_tooltip_username_index'][intval($conf_LCAS[0])], |
---|
146 | 'LCAS_password_tooltip' => |
---|
147 | $lang['LCAS_tooltip_password_index'], |
---|
148 | )); |
---|
149 | $template->set_prefilter('menubar', 'LCAS_add_tooltips_prefilter_index'); |
---|
150 | } |
---|
151 | |
---|
152 | function LCAS_add_tooltips_prefilter_index($content, &$smarty) { |
---|
153 | $search = 'for="username"'; |
---|
154 | $replacement = 'for="username" title="{$LCAS_username_tooltip}"'; |
---|
155 | $content = str_replace($search, $replacement, $content); |
---|
156 | $search = 'name="username"'; |
---|
157 | $replacement = 'name="username" title="{$LCAS_username_tooltip}"'; |
---|
158 | $content = str_replace($search, $replacement, $content); |
---|
159 | $search = 'for="password"'; |
---|
160 | $replacement = 'for="password" title="{$LCAS_password_tooltip}"'; |
---|
161 | $content = str_replace($search, $replacement, $content); |
---|
162 | $search = 'name="password"'; |
---|
163 | $replacement = 'name="password" title="{$LCAS_password_tooltip}"'; |
---|
164 | $content = str_replace($search, $replacement, $content); |
---|
165 | return $content; |
---|
166 | } |
---|
167 | |
---|
168 | // LCAS_admin_user_filter |
---|
169 | // |
---|
170 | // Allow to use LCAS for searching usernames, in admin user_list page |
---|
171 | // |
---|
172 | add_event_handler('loc_end_admin', 'LCAS_admin_user_filter'); |
---|
173 | |
---|
174 | function LCAS_admin_user_filter() { |
---|
175 | if ( |
---|
176 | strpos($_SERVER['REQUEST_URI'], 'user_list') !== false and |
---|
177 | isset($_GET['username']) and !empty($_GET['username']) |
---|
178 | ) include(LCAS_PATH.'include/admin_search.inc.php'); |
---|
179 | } |
---|
180 | |
---|
181 | // LCAS_add_tooltips_user_list |
---|
182 | // |
---|
183 | // Also set prefilter to add tooltip |
---|
184 | // |
---|
185 | add_event_handler('loc_begin_admin', 'LCAS_add_tooltips_user_list'); |
---|
186 | |
---|
187 | function LCAS_add_tooltips_user_list() { |
---|
188 | global $template, $conf, $lang; |
---|
189 | |
---|
190 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
191 | |
---|
192 | if (strpos($_SERVER['REQUEST_URI'], 'user_list') !== false) { |
---|
193 | $template->assign( |
---|
194 | 'LCAS_username_tooltip_admin', |
---|
195 | $lang['LCAS_tooltip_username_admin'][intval($conf_LCAS[0])] |
---|
196 | ); |
---|
197 | $template->set_prefilter('user_list','LCAS_add_tooltips_prefilter_admin'); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | function LCAS_add_tooltips_prefilter_admin($content, &$smarty) { |
---|
202 | $search = 'name="username"'; |
---|
203 | $replacement = 'name="username" title="{$LCAS_username_tooltip_admin}"'; |
---|
204 | $content = str_replace($search, $replacement, $content); |
---|
205 | return $content; |
---|
206 | } |
---|
207 | |
---|
208 | ?> |
---|