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

Last change on this file since 9474 was 9474, checked in by Eric, 13 years ago

bug 2208 re-fixed : Duplicate user control improvement on username update will work fine on this way (hopefully !)

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