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

Last change on this file since 9326 was 9326, checked in by Eric, 10 years ago
  • Bug 2066 fixed : There was a bug still remaining in the notification feature.
  • Tablesorter JQuery script updated
  • Initial config updated
  • Refactory of LCAS options vars ($conf_LCAS[x]) : We start now with offset 0 instead of 1
File size: 5.9 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$t = pwg_db_fetch_row(pwg_query('
29  SELECT `value`
30  FROM `'.CONFIG_TABLE.'`
31  WHERE `param` = "LoginCaseAccentsSensitivity"
32  LIMIT 1;
33'));
34
35$conf['LoginCaseAccentsSensitivity'] = $t[0];
36
37/* Plugin admin */
38add_event_handler('get_admin_plugin_menu_links', 'LCAS_admin_menu');
39
40function LCAS_admin_menu($menu)
41{
42// +-----------------------------------------------------------------------+
43// |                      Getting plugin name                              |
44// +-----------------------------------------------------------------------+
45  $plugin =  LCAS_PluginInfos(LCAS_PATH);
46  $name = $plugin['name'];
47 
48                                                                                                // to be removed in final version :
49                                                                                                global $template; 
50                                                                                                $template->delete_compiled_templates(); 
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  return $menu;
60}
61
62function LCAS_add_tooltips_prefilter_register($content, &$smarty) {
63  $search = 'for="login"';
64  $replacement = 'for="login" title="{$LCAS_username_tooltip}"';
65  $content = str_replace($search, $replacement, $content);
66  $search = 'name="login"';
67  $replacement = 'name="login" title="{$LCAS_username_tooltip}"';
68  $content = str_replace($search, $replacement, $content);
69  $search = 'for="password"';
70  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
71  $content = str_replace($search, $replacement, $content);
72  $search = 'name="password"';
73  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
74  $content = str_replace($search, $replacement, $content);
75  $search = 'for="password_conf"';
76  $replacement = 'for="password_conf" title="{$LCAS_password_tooltip}"';
77  $content = str_replace($search, $replacement, $content);
78  $search = 'name="password_conf"';
79  $replacement = 'name="password_conf" title="{$LCAS_password_tooltip}"';
80  $content = str_replace($search, $replacement, $content);
81  return $content;
82}
83
84// Check users identification
85add_event_handler('init', 'LCAS_InitPage');
86 
87function LCAS_InitPage()
88{
89  global $template, $conf, $lang;
90
91  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
92 
93  // Set $conf['insensitive_case_logon'] to false, as LCAS takes completely
94  // in charge everything around the case and the accents
95  $conf['insensitive_case_logon'] = false;
96 
97/* User identification */
98  if (script_basename() == 'identification')
99  {
100    if (isset($_POST['username']) and isset($conf_LCAS[0]))
101    {
102      $new_username = LCAS_SearchCaseUsername($_POST['username'],$conf_LCAS[0]);
103      $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
104    }
105  }
106 
107  // Add tooltips on register page
108  if (script_basename() == 'register') {
109    $template->assign(array(
110      'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_register'][intval($conf_LCAS[0])],
111      'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_register'],
112    ));
113    $template->set_prefilter('register', 'LCAS_add_tooltips_prefilter_register');
114  }
115}
116
117// Check users registration
118// Returns error
119add_event_handler('register_user_check', 'LCAS_RegistrationCheck');
120
121function LCAS_RegistrationCheck($errors)
122{
123  global $conf, $lang;
124 
125  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
126 
127  load_language('plugin.lang', LCAS_PATH);
128
129  if (isset($conf_LCAS[0]))
130   $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[0]);
131 
132  if (isset($NewPostLogin) and get_userid($NewPostLogin))
133   $errors[] = $lang['LCAS_error'][intval($conf_LCAS[0])];
134 
135  return $errors;
136}
137
138/**
139 *
140 * LCAS_add_tooltips()
141 * add tooltips on username and password fields
142 *
143 * @param no parameter
144 * @return no return value
145 */
146
147add_event_handler('blockmanager_apply', 'LCAS_add_tooltips_index');
148
149function LCAS_add_tooltips_prefilter_index($content, &$smarty) {
150  $search = 'for="username"';
151  $replacement = 'for="username" title="{$LCAS_username_tooltip}"';
152  $content = str_replace($search, $replacement, $content);
153  $search = 'name="username"';
154  $replacement = 'name="username" title="{$LCAS_username_tooltip}"';
155  $content = str_replace($search, $replacement, $content);
156  $search = 'for="password"';
157  $replacement = 'for="password" title="{$LCAS_password_tooltip}"';
158  $content = str_replace($search, $replacement, $content);
159  $search = 'name="password"';
160  $replacement = 'name="password" title="{$LCAS_password_tooltip}"';
161  $content = str_replace($search, $replacement, $content);
162  return $content;
163}
164
165function LCAS_add_tooltips_index() {
166  global $template, $conf, $lang;
167 
168  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
169 
170  $template->assign(array(
171    'LCAS_username_tooltip' => $lang['LCAS_tooltip_username_index'][intval($conf_LCAS[0])],
172    'LCAS_password_tooltip' => $lang['LCAS_tooltip_password_index'],
173  ));
174  $template->set_prefilter('menubar', 'LCAS_add_tooltips_prefilter_index');
175}
176
177?>
Note: See TracBrowser for help on using the repository browser.