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