[9229] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: LCAS |
---|
[10692] | 4 | Version: 2.2.2 |
---|
[9229] | 5 | Description: Allow to disable login/register name to be sensible to the case/accents |
---|
[10493] | 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 |
---|
[9229] | 9 | */ |
---|
| 10 | |
---|
[10534] | 11 | /* History: LCAS_PATH.'CHANGELOG.txt' */ |
---|
[9229] | 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!'); |
---|
[10493] | 19 | if (!defined('LCAS_PATH')) |
---|
| 20 | define('LCAS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
[9229] | 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); |
---|
[9232] | 26 | load_language('messages.lang', LCAS_PATH); |
---|
[9229] | 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 | |
---|
[10692] | 40 | // Compliance with Piwigo 2.2 |
---|
| 41 | if (version_compare(PHPWG_VERSION, '2.2', '>=') ) |
---|
| 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 | else // Compliance with Piwigo 2.1 |
---|
| 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 | |
---|
[9229] | 60 | return $menu; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | // Check users identification |
---|
[10493] | 64 | // Define prefilter to add tooltips on register page |
---|
[9229] | 65 | add_event_handler('init', 'LCAS_InitPage'); |
---|
| 66 | |
---|
| 67 | function LCAS_InitPage() |
---|
| 68 | { |
---|
[9232] | 69 | global $template, $conf, $lang; |
---|
[9229] | 70 | |
---|
| 71 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
| 72 | |
---|
| 73 | // Set $conf['insensitive_case_logon'] to false, as LCAS takes completely |
---|
[10493] | 74 | // in charge everything concerning the case and the accents in the login |
---|
| 75 | if ($conf_LCAS[0] != '0') $conf['insensitive_case_logon'] = false; |
---|
[9229] | 76 | |
---|
[10493] | 77 | /* User identification */ |
---|
[9229] | 78 | if (script_basename() == 'identification') |
---|
| 79 | { |
---|
[9326] | 80 | if (isset($_POST['username']) and isset($conf_LCAS[0])) |
---|
[9229] | 81 | { |
---|
[9326] | 82 | $new_username = LCAS_SearchCaseUsername($_POST['username'],$conf_LCAS[0]); |
---|
[9229] | 83 | $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username; |
---|
| 84 | } |
---|
| 85 | } |
---|
[9232] | 86 | |
---|
| 87 | // Add tooltips on register page |
---|
| 88 | if (script_basename() == 'register') { |
---|
| 89 | $template->assign(array( |
---|
[9326] | 90 | 'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])], |
---|
[9232] | 91 | 'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_register'], |
---|
| 92 | )); |
---|
| 93 | $template->set_prefilter('register', 'LCAS_add_tooltips_prefilter_register'); |
---|
| 94 | } |
---|
[9229] | 95 | } |
---|
| 96 | |
---|
[10493] | 97 | function LCAS_add_tooltips_prefilter_register($content, &$smarty) { |
---|
| 98 | $search = 'for="login"'; |
---|
| 99 | $replacement = 'for="login" title="{$LCAS_username_tooltip}"'; |
---|
| 100 | $content = str_replace($search, $replacement, $content); |
---|
| 101 | $search = 'name="login"'; |
---|
| 102 | $replacement = 'name="login" title="{$LCAS_username_tooltip}"'; |
---|
| 103 | $content = str_replace($search, $replacement, $content); |
---|
| 104 | $search = 'for="password"'; |
---|
| 105 | $replacement = 'for="password" title="{$LCAS_password_tooltip}"'; |
---|
| 106 | $content = str_replace($search, $replacement, $content); |
---|
| 107 | $search = 'name="password"'; |
---|
| 108 | $replacement = 'name="password" title="{$LCAS_password_tooltip}"'; |
---|
| 109 | $content = str_replace($search, $replacement, $content); |
---|
| 110 | $search = 'for="password_conf"'; |
---|
| 111 | $replacement = 'for="password_conf" title="{$LCAS_password_tooltip}"'; |
---|
| 112 | $content = str_replace($search, $replacement, $content); |
---|
| 113 | $search = 'name="password_conf"'; |
---|
| 114 | $replacement = 'name="password_conf" title="{$LCAS_password_tooltip}"'; |
---|
| 115 | $content = str_replace($search, $replacement, $content); |
---|
| 116 | return $content; |
---|
| 117 | } |
---|
| 118 | |
---|
[9229] | 119 | // Check users registration |
---|
| 120 | // Returns error |
---|
| 121 | add_event_handler('register_user_check', 'LCAS_RegistrationCheck'); |
---|
| 122 | |
---|
| 123 | function LCAS_RegistrationCheck($errors) |
---|
| 124 | { |
---|
| 125 | global $conf, $lang; |
---|
| 126 | |
---|
| 127 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
| 128 | |
---|
| 129 | load_language('plugin.lang', LCAS_PATH); |
---|
| 130 | |
---|
[9326] | 131 | if (isset($conf_LCAS[0])) |
---|
| 132 | $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[0]); |
---|
[9229] | 133 | |
---|
| 134 | if (isset($NewPostLogin) and get_userid($NewPostLogin)) |
---|
[9326] | 135 | $errors[] = $lang['LCAS_error'][intval($conf_LCAS[0])]; |
---|
[9229] | 136 | |
---|
| 137 | return $errors; |
---|
| 138 | } |
---|
[9232] | 139 | |
---|
| 140 | /** |
---|
| 141 | * |
---|
| 142 | * LCAS_add_tooltips() |
---|
| 143 | * add tooltips on username and password fields |
---|
| 144 | * |
---|
| 145 | * @param no parameter |
---|
| 146 | * @return no return value |
---|
| 147 | */ |
---|
| 148 | |
---|
| 149 | add_event_handler('blockmanager_apply', 'LCAS_add_tooltips_index'); |
---|
| 150 | |
---|
[10221] | 151 | function LCAS_add_tooltips_index() { |
---|
| 152 | global $template, $conf, $lang; |
---|
| 153 | |
---|
| 154 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
| 155 | |
---|
| 156 | $template->assign(array( |
---|
[10493] | 157 | 'LCAS_username_tooltip' => |
---|
| 158 | $lang['LCAS_tooltip_username_index'][intval($conf_LCAS[0])], |
---|
| 159 | 'LCAS_password_tooltip' => |
---|
| 160 | $lang['LCAS_tooltip_password_index'], |
---|
[10221] | 161 | )); |
---|
| 162 | $template->set_prefilter('menubar', 'LCAS_add_tooltips_prefilter_index'); |
---|
| 163 | } |
---|
| 164 | |
---|
[9232] | 165 | function LCAS_add_tooltips_prefilter_index($content, &$smarty) { |
---|
| 166 | $search = 'for="username"'; |
---|
| 167 | $replacement = 'for="username" title="{$LCAS_username_tooltip}"'; |
---|
| 168 | $content = str_replace($search, $replacement, $content); |
---|
| 169 | $search = 'name="username"'; |
---|
| 170 | $replacement = 'name="username" title="{$LCAS_username_tooltip}"'; |
---|
| 171 | $content = str_replace($search, $replacement, $content); |
---|
| 172 | $search = 'for="password"'; |
---|
| 173 | $replacement = 'for="password" title="{$LCAS_password_tooltip}"'; |
---|
| 174 | $content = str_replace($search, $replacement, $content); |
---|
| 175 | $search = 'name="password"'; |
---|
| 176 | $replacement = 'name="password" title="{$LCAS_password_tooltip}"'; |
---|
| 177 | $content = str_replace($search, $replacement, $content); |
---|
| 178 | return $content; |
---|
| 179 | } |
---|
| 180 | |
---|
[10087] | 181 | // LCAS_admin_user_filter |
---|
| 182 | // |
---|
[10088] | 183 | // Allow to use LCAS for searching usernames, in admin user_list page |
---|
[10087] | 184 | // |
---|
| 185 | add_event_handler('loc_end_admin', 'LCAS_admin_user_filter'); |
---|
| 186 | |
---|
| 187 | function LCAS_admin_user_filter() { |
---|
| 188 | if ( |
---|
| 189 | strpos($_SERVER['REQUEST_URI'], 'user_list') !== false and |
---|
| 190 | isset($_GET['username']) and !empty($_GET['username']) |
---|
[10088] | 191 | ) include(LCAS_PATH.'include/admin_search.inc.php'); |
---|
[10087] | 192 | } |
---|
| 193 | |
---|
[10244] | 194 | // LCAS_add_tooltips_user_list |
---|
| 195 | // |
---|
| 196 | // Also set prefilter to add tooltip |
---|
| 197 | // |
---|
| 198 | add_event_handler('loc_begin_admin', 'LCAS_add_tooltips_user_list'); |
---|
| 199 | |
---|
| 200 | function LCAS_add_tooltips_user_list() { |
---|
| 201 | global $template, $conf, $lang; |
---|
| 202 | |
---|
| 203 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
| 204 | |
---|
| 205 | if (strpos($_SERVER['REQUEST_URI'], 'user_list') !== false) { |
---|
| 206 | $template->assign( |
---|
| 207 | 'LCAS_username_tooltip_admin', |
---|
| 208 | $lang['LCAS_tooltip_username_admin'][intval($conf_LCAS[0])] |
---|
| 209 | ); |
---|
| 210 | $template->set_prefilter('user_list','LCAS_add_tooltips_prefilter_admin'); |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | function LCAS_add_tooltips_prefilter_admin($content, &$smarty) { |
---|
| 215 | $search = 'name="username"'; |
---|
| 216 | $replacement = 'name="username" title="{$LCAS_username_tooltip_admin}"'; |
---|
| 217 | $content = str_replace($search, $replacement, $content); |
---|
| 218 | return $content; |
---|
| 219 | } |
---|
| 220 | |
---|
[8141] | 221 | ?> |
---|