source: extensions/LCAS/branch/2.3/main.inc.php @ 27127

Revision 27127, 6.6 KB checked in by LucMorizur, 6 years ago (diff)

Add branch 2.3

  • Property svn:eol-style set to LF
Line 
1<?php
2/*
3Plugin Name: LCAS
4Version: 2.2.5
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  array_push($menu,
41    array(
42      'NAME' => $name,
43      'URL' => get_root_url().'admin.php?page=plugin-'.basename(LCAS_PATH)
44    )
45  );
46
47  return $menu;
48}
49
50// Check users identification
51// Define prefilter to add tooltips on register page
52add_event_handler('init', 'LCAS_InitPage');
53 
54function LCAS_InitPage()
55{
56  global $template, $conf, $lang;
57
58  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
59 
60  // Set $conf['insensitive_case_logon'] to false, as LCAS takes completely
61  // in charge everything concerning the case and the accents in the login
62  if ($conf_LCAS[0] != '0') $conf['insensitive_case_logon'] = false;
63 
64  /* User identification */
65  if (script_basename() == 'identification')
66  {
67    if (isset($_POST['username']) and isset($conf_LCAS[0]))
68    {
69      $new_username = LCAS_SearchCaseUsername($_POST['username'],$conf_LCAS[0]);
70      $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
71    }
72  }
73 
74  // Add tooltips on register page
75  if (script_basename() == 'register') {
76    $template->assign(array(
77      'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])],
78      'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_register'],
79    ));
80    $template->set_prefilter('register', 'LCAS_add_tooltips_prefilter_register');
81  }
82}
83
84function LCAS_add_tooltips_prefilter_register($content, &$smarty) {
85  $search = 'for="login"';
86  $replacement = 'for="login" title="{$LCAS_username_tooltip}"';
87  $content = str_replace($search, $replacement, $content);
88  $search = 'name="login"';
89  $replacement = 'name="login" title="{$LCAS_username_tooltip}"';
90  $content = str_replace($search, $replacement, $content);
91  $search = 'for="password"';
92  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
93  $content = str_replace($search, $replacement, $content);
94  $search = 'name="password"';
95  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
96  $content = str_replace($search, $replacement, $content);
97  $search = 'for="password_conf"';
98  $replacement = 'for="password_conf" title="{$LCAS_password_tooltip}"';
99  $content = str_replace($search, $replacement, $content);
100  $search = 'name="password_conf"';
101  $replacement = 'name="password_conf" title="{$LCAS_password_tooltip}"';
102  $content = str_replace($search, $replacement, $content);
103  return $content;
104}
105
106// Check users registration
107// Returns error
108add_event_handler('register_user_check', 'LCAS_RegistrationCheck');
109
110function LCAS_RegistrationCheck($errors)
111{
112  global $conf, $lang;
113 
114  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
115 
116  load_language('plugin.lang', LCAS_PATH);
117
118  if (isset($conf_LCAS[0]))
119   $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[0]);
120 
121  if (isset($NewPostLogin) and get_userid($NewPostLogin))
122   $errors[] = $lang['LCAS_error'][intval($conf_LCAS[0])];
123 
124  return $errors;
125}
126
127/**
128 *
129 * LCAS_add_tooltips()
130 * add tooltips on username and password fields
131 *
132 * @param no parameter
133 * @return no return value
134 */
135
136add_event_handler('blockmanager_apply', 'LCAS_add_tooltips_index');
137
138function LCAS_add_tooltips_index() {
139  global $template, $conf, $lang;
140 
141  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
142 
143  $template->assign(array(
144    'LCAS_username_tooltip' =>
145     $lang['LCAS_tooltip_username_index'][intval($conf_LCAS[0])],
146    'LCAS_password_tooltip' =>
147     $lang['LCAS_tooltip_password_index'],
148  ));
149  $template->set_prefilter('menubar', 'LCAS_add_tooltips_prefilter_index');
150}
151
152function LCAS_add_tooltips_prefilter_index($content, &$smarty) {
153  $search = 'for="username"';
154  $replacement = 'for="username" title="{$LCAS_username_tooltip}"';
155  $content = str_replace($search, $replacement, $content);
156  $search = 'name="username"';
157  $replacement = 'name="username" title="{$LCAS_username_tooltip}"';
158  $content = str_replace($search, $replacement, $content);
159  $search = 'for="password"';
160  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
161  $content = str_replace($search, $replacement, $content);
162  $search = 'name="password"';
163  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
164  $content = str_replace($search, $replacement, $content);
165  return $content;
166}
167
168// LCAS_admin_user_filter
169//
170// Allow to use LCAS for searching usernames, in admin user_list page
171//
172add_event_handler('loc_end_admin', 'LCAS_admin_user_filter');
173
174function LCAS_admin_user_filter() {
175  if (
176    strpos($_SERVER['REQUEST_URI'], 'user_list') !== false and
177    isset($_GET['username']) and !empty($_GET['username'])
178  ) include(LCAS_PATH.'include/admin_search.inc.php');
179}
180
181// LCAS_add_tooltips_user_list
182//
183// Also set prefilter to add tooltip
184//
185add_event_handler('loc_begin_admin', 'LCAS_add_tooltips_user_list');
186
187function LCAS_add_tooltips_user_list() {
188global $template, $conf, $lang;
189 
190  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
191 
192  if (strpos($_SERVER['REQUEST_URI'], 'user_list') !== false) {
193    $template->assign(
194      'LCAS_username_tooltip_admin',
195      $lang['LCAS_tooltip_username_admin'][intval($conf_LCAS[0])]
196    );
197    $template->set_prefilter('user_list','LCAS_add_tooltips_prefilter_admin');
198  }
199}
200
201function LCAS_add_tooltips_prefilter_admin($content, &$smarty) {
202  $search = 'name="username"';
203  $replacement = 'name="username" title="{$LCAS_username_tooltip_admin}"';
204  $content = str_replace($search, $replacement, $content);
205  return $content;
206}
207
208?>
Note: See TracBrowser for help on using the repository browser.