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

Last change on this file since 10245 was 10245, checked in by LucMorizur, 13 years ago

Code cleaning

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