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

Last change on this file since 25774 was 25774, checked in by LucMorizur, 11 years ago

Compatibility with Piwigo version 2.6

File size: 6.9 KB
Line 
1<?php
2/*
3Plugin Name: LCAS
4Version: 2.2.4
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 = LCAS_SearchCaseUsername($_POST['username'],$conf_LCAS[0]);
83      $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
84    }
85  }
86 
87  // Add tooltips on register page
88  if (script_basename() == 'register') {
89    $template->assign(array(
90      'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])],
91      'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_register'],
92    ));
93    $template->set_prefilter('register', 'LCAS_add_tooltips_prefilter_register');
94  }
95}
96
97function 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
119// Check users registration
120// Returns error
121add_event_handler('register_user_check', 'LCAS_RegistrationCheck');
122
123function LCAS_RegistrationCheck($errors)
124{
125  global $conf, $lang;
126 
127  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
128 
129  load_language('plugin.lang', LCAS_PATH);
130
131  if (isset($conf_LCAS[0]))
132   $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[0]);
133 
134  if (isset($NewPostLogin) and get_userid($NewPostLogin))
135   $errors[] = $lang['LCAS_error'][intval($conf_LCAS[0])];
136 
137  return $errors;
138}
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
149add_event_handler('blockmanager_apply', 'LCAS_add_tooltips_index');
150
151function LCAS_add_tooltips_index() {
152  global $template, $conf, $lang;
153 
154  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
155 
156  $template->assign(array(
157    'LCAS_username_tooltip' =>
158     $lang['LCAS_tooltip_username_index'][intval($conf_LCAS[0])],
159    'LCAS_password_tooltip' =>
160     $lang['LCAS_tooltip_password_index'],
161  ));
162  $template->set_prefilter('menubar', 'LCAS_add_tooltips_prefilter_index');
163}
164
165function 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
181// LCAS_admin_user_filter
182//
183// Allow to use LCAS for searching usernames, in admin user_list page
184//
185add_event_handler('loc_end_admin', 'LCAS_admin_user_filter');
186
187function LCAS_admin_user_filter() {
188  if (
189    strpos($_SERVER['REQUEST_URI'], 'user_list') !== false and
190    isset($_GET['username']) and !empty($_GET['username'])
191  ) include(LCAS_PATH.'include/admin_search.inc.php');
192}
193
194// LCAS_add_tooltips_user_list
195//
196// Also set prefilter to add tooltip
197//
198add_event_handler('loc_begin_admin', 'LCAS_add_tooltips_user_list');
199
200function LCAS_add_tooltips_user_list() {
201global $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
214function 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
221?>
Note: See TracBrowser for help on using the repository browser.