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

Last change on this file since 12864 was 10712, checked in by LucMorizur, 14 years ago

Add tooltips on identification page

File size: 7.8 KB
Line 
1<?php
2/*
3Plugin Name: LCAS
4Version: 2.2.2
5Description: Allow to disable login/register name to be sensible to the case/accents
6Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=513
7Author: Eric, Whiler, LucMorizur
8Author URI: http://www.infernoweb.net, http://blogs.wittwer.fr/whiler, http://myr.luc.free.fr
9*/
10
11/* History:  LCAS_PATH.'CHANGELOG.txt' */
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_PATH'))
20 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  // 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
60  return $menu;
61}
62
63// Check users identification
64// Define prefilter to add tooltips on register page
65add_event_handler('init', 'LCAS_InitPage');
66 
67function LCAS_InitPage()
68{
69  global $template, $conf, $lang;
70
71  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
72 
73  // Set $conf['insensitive_case_logon'] to false, as LCAS takes completely
74  // in charge everything concerning the case and the accents in the login
75  if ($conf_LCAS[0] != '0') $conf['insensitive_case_logon'] = false;
76 
77  /* User identification */
78  if (script_basename() == 'identification')
79  {
80    if (isset($_POST['username']) and isset($conf_LCAS[0]))
81    {
82      $new_username =
83       LCAS_SearchCaseUsername($_POST['username'], $conf_LCAS[0]);
84      $_POST['username'] = ($new_username == '') ?
85       $_POST['username'] : $new_username;
86    }
87  }
88 
89  // Add tooltips on register and identification page
90  $sb = script_basename(); $fn = '';
91  if ($sb == 'register' or $sb == 'identification')
92   $fn = ($sb == 'register') ?
93    'LCAS_add_tooltips_prefilter_register' :
94    'LCAS_add_tooltips_prefilter_identification';
95  if ($fn != '') {
96    $template->assign(array(
97      'LCAS_username_tooltip' =>
98       $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])],
99      'LCAS_password_tooltip' =>
100       $lang['LCAS_tooltip_password_register'],
101    ));
102    $template->set_prefilter($sb, $fn);
103  }
104}
105
106function LCAS_add_tooltips_prefilter_register($content, &$smarty) {
107  $search = 'for="login"';
108  $replacement = 'for="login" title="{$LCAS_username_tooltip}"';
109  $content = str_replace($search, $replacement, $content);
110  $search = 'name="login"';
111  $replacement = 'name="login" title="{$LCAS_username_tooltip}"';
112  $content = str_replace($search, $replacement, $content);
113  $search = 'for="password"';
114  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
115  $content = str_replace($search, $replacement, $content);
116  $search = 'name="password"';
117  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
118  $content = str_replace($search, $replacement, $content);
119  $search = 'for="password_conf"';
120  $replacement = 'for="password_conf" title="{$LCAS_password_tooltip}"';
121  $content = str_replace($search, $replacement, $content);
122  $search = 'name="password_conf"';
123  $replacement = 'name="password_conf" title="{$LCAS_password_tooltip}"';
124  $content = str_replace($search, $replacement, $content);
125  return $content;
126}
127
128function LCAS_add_tooltips_prefilter_identification($content, &$smarty) {
129  $search = 'for="username"';
130  $replacement = 'for="username" title="{$LCAS_username_tooltip}"';
131  $content = str_replace($search, $replacement, $content);
132  $search = 'name="username"';
133  $replacement = 'name="username" title="{$LCAS_username_tooltip}"';
134  $content = str_replace($search, $replacement, $content);
135  $search = 'for="password"';
136  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
137  $content = str_replace($search, $replacement, $content);
138  $search = 'name="password"';
139  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
140  $content = str_replace($search, $replacement, $content);
141  return $content;
142}
143
144// Check users registration
145// Returns error
146add_event_handler('register_user_check', 'LCAS_RegistrationCheck');
147
148function LCAS_RegistrationCheck($errors)
149{
150  global $conf, $lang;
151 
152  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
153 
154  load_language('plugin.lang', LCAS_PATH);
155
156  if (isset($conf_LCAS[0]))
157   $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[0]);
158 
159  if (isset($NewPostLogin) and get_userid($NewPostLogin))
160   $errors[] = $lang['LCAS_error'][intval($conf_LCAS[0])];
161 
162  return $errors;
163}
164
165/**
166 *
167 * LCAS_add_tooltips()
168 * add tooltips on username and password fields
169 *
170 * @param no parameter
171 * @return no return value
172 */
173
174add_event_handler('blockmanager_apply', 'LCAS_add_tooltips_index');
175
176function LCAS_add_tooltips_index() {
177  global $template, $conf, $lang;
178 
179  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
180 
181  $template->assign(array(
182    'LCAS_username_tooltip' =>
183     $lang['LCAS_tooltip_username_index'][intval($conf_LCAS[0])],
184    'LCAS_password_tooltip' =>
185     $lang['LCAS_tooltip_password_index'],
186  ));
187  $template->set_prefilter('menubar', 'LCAS_add_tooltips_prefilter_index');
188}
189
190function LCAS_add_tooltips_prefilter_index($content, &$smarty) {
191  $search = 'for="username"';
192  $replacement = 'for="username" title="{$LCAS_username_tooltip}"';
193  $content = str_replace($search, $replacement, $content);
194  $search = 'name="username"';
195  $replacement = 'name="username" title="{$LCAS_username_tooltip}"';
196  $content = str_replace($search, $replacement, $content);
197  $search = 'for="password"';
198  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
199  $content = str_replace($search, $replacement, $content);
200  $search = 'name="password"';
201  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
202  $content = str_replace($search, $replacement, $content);
203  return $content;
204}
205
206// LCAS_admin_user_filter
207//
208// Allow to use LCAS for searching usernames, in admin user_list page
209//
210add_event_handler('loc_end_admin', 'LCAS_admin_user_filter');
211
212function LCAS_admin_user_filter() {
213  if (
214    strpos($_SERVER['REQUEST_URI'], 'user_list') !== false and
215    isset($_GET['username']) and !empty($_GET['username'])
216  ) include(LCAS_PATH.'include/admin_search.inc.php');
217}
218
219// LCAS_add_tooltips_user_list
220//
221// Also set prefilter to add tooltip
222//
223add_event_handler('loc_begin_admin', 'LCAS_add_tooltips_user_list');
224
225function LCAS_add_tooltips_user_list() {
226global $template, $conf, $lang;
227 
228  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
229 
230  if (strpos($_SERVER['REQUEST_URI'], 'user_list') !== false) {
231    $template->assign(
232      'LCAS_username_tooltip_admin',
233      $lang['LCAS_tooltip_username_admin'][intval($conf_LCAS[0])]
234    );
235    $template->set_prefilter('user_list','LCAS_add_tooltips_prefilter_admin');
236  }
237}
238
239function LCAS_add_tooltips_prefilter_admin($content, &$smarty) {
240  $search = 'name="username"';
241  $replacement = 'name="username" title="{$LCAS_username_tooltip_admin}"';
242  $content = str_replace($search, $replacement, $content);
243  return $content;
244}
245
246?>
Note: See TracBrowser for help on using the repository browser.