source: extensions/LCAS/trunk/include/functions.inc.php @ 8475

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

Ambiguous accounts are logged in only when properly typed in; but not ambiguous accounts will benefit of LCAS.

File size: 21.2 KB
Line 
1<?php
2          // Keeps file coded in UTF-8 without BOM : é
3include_once (LCAS_PATH.'include/constants.php');
4load_language('plugin.lang', LCAS_PATH);
5
6
7/**
8 * Splits a multi-byte string in a array of each of its characters.
9 * Many thanks to adjwilli in
10 * http://www.php.net/manual/fr/function.mb-split.php#80046
11 *
12 * @param string s: string to split
13 *
14 * @return : array of each character of s
15*/
16function LCAS_mbStringToArray($s) {
17  $l = mb_strlen($s); $a = array();
18  while ($l) {
19    $a[] = mb_substr($s, 0, 1, 'UTF-8');
20    $s = mb_substr($s, 1, $l, 'UTF-8');
21    $l = mb_strlen($s);
22  }
23  return $a;
24}
25
26
27/**
28 * Changes the characters of the given string as stated by values of
29 * $conf['insensitive_case_logon'] and $LCAS_lang['char_replacement_set'].
30 *
31 * @param mix s: string, or array of strings, to evaluate
32 *
33 * @return : string, or array of strings, modified as stated
34*/
35function LCAS_change_case($Username, $Conf)
36{
37  $LCAS_lang                         = array();
38  $LCAS_lang['char_replacement_set'] = array();
39
40
41
42  // 0 : case sensitive, accents sensitive
43  $LCAS_lang['char_replacement_set'][1] = array(
44  // 1 : case insensitive, accents sensitive
45   
46  // Latin
47   
48    'a'  => 'A',
49    'à'  => 'À',
50    'â'  => 'Â',
51    'á'  => 'Á',
52    'ã'  => 'Ã',
53    'ä'  => 'Ä',
54    'å'  => 'Å',
55    'ā'  => 'Ā',
56    'ă'  => 'Ă',
57    'ą'  => 'Ą',
58    'ǻ'  => 'Ǻ',
59    'ạ'  => 'Ạ',
60    'ả'  => 'Ả',
61    'ấ'  => 'Ấ',
62    'ầ'  => 'Ầ',
63    'ẩ'  => 'Ẩ',
64    'ẫ'  => 'Ẫ',
65    'ậ'  => 'Ậ',
66    'ắ'  => 'Ắ',
67    'ằ'  => 'Ằ',
68    'ẳ'  => 'Ẳ',
69    'ẵ'  => 'Ẵ',
70    'ặ'  => 'Ặ',
71   
72    'b'  => 'B',
73   
74    'c'  => 'C',
75    'ç'  => 'Ç',
76    'ć'  => 'Ć',
77    'ĉ'  => 'Ĉ',
78    'ċ'  => 'Ċ',
79    'č'  => 'Č',
80
81    'd'  => 'D',
82    'ď'  => 'Ď',
83    'đ'  => 'Đ',
84   
85    'e'  => 'E',
86    'è'  => 'È',
87    'é'  => 'É',
88    'ê'  => 'Ê',
89    'ë'  => 'Ë',
90    'ē'  => 'Ē',
91    'ĕ'  => 'Ĕ',
92    'ė'  => 'Ė',
93    'ę'  => 'Ę',
94    'ě'  => 'Ě',
95    'ẹ'  => 'Ẹ',
96    'ẻ'  => 'Ẻ',
97    'ẽ'  => 'Ẽ',
98    'ế'  => 'Ế',
99    'ề'  => 'Ề',
100    'ể'  => 'Ể',
101    'ễ'  => 'Ễ',
102    'ệ'  => 'Ệ',
103   
104    'f'  => 'F ƒ',
105   
106    'g'  => 'G',
107    'ĝ'  => 'Ĝ',
108    'ğ'  => 'Ğ',
109    'ġ'  => 'Ġ',
110    'ģ'  => 'Ģ',
111   
112    'h'  => 'H',
113    'ĥ'  => 'Ĥ',
114    'ħ'  => 'Ħ',
115   
116    'i'  => 'I ı İ',
117    'ì'  => 'Ì',
118    'í'  => 'Í',
119    'î'  => 'Î',
120    'ï'  => 'Ï',
121    'ĩ'  => 'Ĩ',
122    'ī'  => 'Ī',
123    'ĭ'  => 'Ĭ',
124    'į'  => 'Į',
125    'ǐ'  => 'Ǐ',
126    'ỉ'  => 'Ỉ',
127    'ị'  => 'Ị',
128   
129    'j'  => 'J',
130    'ĵ'  => 'Ĵ',
131   
132    'k'  => 'K',
133    'ķ'  => 'Ķ',
134   
135    'l'  => 'L',
136    'ĺ'  => 'Ĺ',
137    'ļ'  => 'Ļ',
138    'ľ'  => 'Ľ',
139    'ŀ'  => 'Ŀ',
140    'ł'  => 'Ł',
141   
142    'm'  => 'M',
143   
144    'n'  => 'N',
145    'ñ'  => 'Ñ',
146    'ń'  => 'Ń',
147    'ņ'  => 'Ņ',
148    'ň'  => 'Ň',
149   
150    'o'  => 'O',
151    'ò'  => 'Ò',
152    'ó'  => 'Ó',
153    'ô'  => 'Ô',
154    'õ'  => 'Õ',
155    'ö'  => 'Ö',
156    'ø'  => 'Ø',
157    'ō'  => 'Ō',
158    'ŏ'  => 'Ŏ',
159    'ő'  => 'Ő',
160    'ơ'  => 'Ơ',
161    'ǒ'  => 'Ǒ',
162    'ǿ'  => 'Ǿ',
163    'ọ'  => 'Ọ',
164    'ỏ'  => 'Ỏ',
165    'ố'  => 'Ố',
166    'ồ'  => 'Ồ',
167    'ổ'  => 'Ổ',
168    'ỗ'  => 'Ỗ',
169    'ộ'  => 'Ộ',
170    'ớ'  => 'Ớ',
171    'ờ'  => 'Ờ',
172    'ở'  => 'Ở',
173    'ỡ'  => 'Ỡ',
174    'ợ'  => 'Ợ',
175   
176    'p'  => 'P',
177   
178    'q'  => 'Q ĸ',
179   
180    'r'  => 'R',
181    'ŕ'  => 'Ŕ',
182    'ŗ'  => 'Ŗ',
183    'ř'  => 'Ř',
184   
185    's'  => 'S ſ',
186    'ś'  => 'Ś',
187    'ŝ'  => 'Ŝ',
188    'ş'  => 'Ş',
189    'š'  => 'Š',
190    'ss' => 'ß',
191   
192    't'  => 'T',
193    'ţ'  => 'Ţ',
194    'ť'  => 'Ť',
195    'ŧ'  => 'Ŧ',
196   
197    'u'  => 'U',
198    'ù'  => 'Ù',
199    'ú'  => 'Ú',
200    'û'  => 'Û',
201    'ü'  => 'Ü',
202    'ũ'  => 'Ũ',
203    'ū'  => 'Ū',
204    'ŭ'  => 'Ŭ',
205    'ů'  => 'Ů',
206    'ű'  => 'Ű',
207    'ų'  => 'Ų',
208    'ǔ'  => 'Ǔ',
209    'ǖ'  => 'Ǖ',
210    'ǘ'  => 'Ǘ',
211    'ǚ'  => 'Ǚ',
212    'ǜ'  => 'Ǜ',
213    'ư'  => 'Ư',
214    'ụ'  => 'Ụ',
215    'ủ'  => 'Ủ',
216    'ứ'  => 'Ứ',
217    'ừ'  => 'Ừ',
218    'ử'  => 'Ử',
219    'ữ'  => 'Ữ',
220    'ự'  => 'Ự',
221   
222    'v'  => 'V',
223   
224    'w'  => 'W',
225    'ŵ'  => 'Ŵ',
226    'ẁ'  => 'Ẁ',
227    'ẃ'  => 'Ẃ',
228    'ẅ'  => 'Ẅ',
229   
230    'x'  => 'X',
231   
232    'y'  => 'Y',
233    'ý'  => 'Ý',
234    'ÿ'  => 'Ÿ',
235    'ỳ'  => 'Ỳ',
236    'ỵ'  => 'Ỵ',
237    'ỷ'  => 'Ỷ',
238    'ỹ'  => 'Ỹ',
239    'ŷ'  => 'Ŷ',
240   
241    'z'  => 'Z',
242    'ź'  => 'Ź',
243    'ż'  => 'Ż',
244    'ž'  => 'Ž',
245   
246    'ae' => 'æ Æ',
247    'aé' => 'ǽ Ǽ',
248    'ð'  => 'Ð',
249    'ə'  => 'Ə',
250    'ij' => 'ij IJ',
251    'ŋ'  => 'Ŋ',
252    'oe' => 'œ Œ',
253    'þ'  => 'Þ',
254   
255  // Greek
256   
257    'α'  => 'Α',
258    'ά'  => 'Ά',
259    'β'  => 'Β',
260    'γ'  => 'Γ',
261    'δ'  => 'Δ',
262    'ε'  => 'Ε',
263    'έ'  => 'Έ',
264    'ζ'  => 'Ζ',
265    'η'  => 'Η',
266    'ή'  => 'Ή',
267    'θ'  => 'Θ',
268    'ι'  => 'Ι',
269    'ί'  => 'Ί',
270    'ϊ'  => 'Ϊ',
271    'κ'  => 'Κ',
272    'λ'  => 'Λ',
273    'μ'  => 'Μ µ',
274    'ν'  => 'Ν',
275    'ξ'  => 'Ξ',
276    'ο'  => 'Ο',
277    'ό'  => 'Ό',
278    'π'  => 'Π',
279    'ρ'  => 'Ρ',
280    'σ'  => 'Σ ς',
281    'τ'  => 'Τ',
282    'υ'  => 'Υ',
283    'ύ'  => 'Ύ',
284    'ϋ'  => 'Ϋ',
285    'φ'  => 'Φ',
286    'χ'  => 'Χ',
287    'ψ'  => 'Ψ',
288    'ω'  => 'Ω',
289    'ώ'  => 'Ώ',
290   
291  // Cyrillic
292   
293    'а'  => 'А',
294    'б'  => 'Б',
295    'в'  => 'В',
296    'г'  => 'Г',
297    'ґ'  => 'Ґ',
298    'ғ'  => 'Ғ',
299    'д'  => 'Д',
300    'е'  => 'Е',
301    'ж'  => 'Ж',
302    'җ'  => 'Җ',
303    'з'  => 'З',
304    'и'  => 'И',
305    'й'  => 'Й',
306    'к'  => 'К',
307    'қ'  => 'Қ',
308    'ҝ'  => 'Ҝ',
309    'л'  => 'Л',
310    'м'  => 'М',
311    'н'  => 'Н',
312    'ң'  => 'Ң',
313    'о'  => 'О',
314    'п'  => 'П',
315    'р'  => 'Р',
316    'с'  => 'С',
317    'т'  => 'Т',
318    'у'  => 'У',
319    'ү'  => 'Ү',
320    'ұ'  => 'Ұ',
321    'ф'  => 'Ф',
322    'х'  => 'Х',
323    'ҳ'  => 'Ҳ',
324    'ц'  => 'Ц',
325    'ч'  => 'Ч',
326    'ҹ'  => 'Ҹ',
327    'ш'  => 'Ш',
328    'щ'  => 'Щ',
329    'ъ'  => 'Ъ',
330    'ы'  => 'Ы',
331    'ь'  => 'Ь',
332    'э'  => 'Э',
333    'ю'  => 'Ю',
334    'я'  => 'Я',
335    'ё'  => 'Ё',
336    'ђ'  => 'Ђ',
337    'ѓ'  => 'Ѓ',
338    'є'  => 'Є',
339    'ѕ'  => 'Ѕ',
340    'і'  => 'І',
341    'ї'  => 'Ї',
342    'ј'  => 'Ј',
343    'љ'  => 'Љ',
344    'њ'  => 'Њ',
345    'ћ'  => 'Ћ',
346    'ќ'  => 'Ќ',
347    'ў'  => 'Ў',
348    'џ'  => 'Џ',
349    'һ'  => 'Һ',
350    'ә'  => 'Ә',
351    'ө'  => 'Ө',
352   
353  );
354
355  $LCAS_lang['char_replacement_set'][3] = array(
356  // 3 : case insensitive, accents insensitive
357   
358  // Latin
359   
360    'a'  => 'A à À â Â á Á ã Ã ä Ä å Å ā Ā ă Ă ą Ą ǻ Ǻ ạ Ạ ả Ả ấ Ấ ầ Ầ ẩ Ẩ ẫ Ẫ ậ Ậ ắ Ắ ằ Ằ ẳ Ẳ ẵ Ẵ ặ Ặ @',
361    'b'  => 'B',
362    'c'  => 'C ç Ç ć Ć ĉ Ĉ ċ Ċ č Č',
363    'd'  => 'D ď Ď đ Đ',
364    'e'  => 'E è È é É ê Ê ë Ë ē Ē ĕ Ĕ ė Ė ę Ę ě Ě ẹ Ẹ ẻ Ẻ ẽ Ẽ ế Ế ề Ề ể Ể ễ Ễ ệ Ệ',
365    'f'  => 'F ƒ',
366    'g'  => 'G ĝ Ĝ ğ Ğ ġ Ġ ģ Ģ',
367    'h'  => 'H ĥ Ĥ ħ Ħ',
368    'i'  => 'I ı İ ì Ì í Í î Î ï Ï ĩ Ĩ ī Ī ĭ Ĭ į Į ǐ Ǐ ỉ Ỉ ị Ị',
369    'j'  => 'J ĵ Ĵ',
370    'k'  => 'K ķ Ķ',
371    'l'  => 'L ĺ Ĺ ļ Ļ ľ Ľ ŀ Ŀ ł Ł',
372    'm'  => 'M',
373    'n'  => 'N ʼn ñ Ñ ń Ń ņ Ņ ň Ň',
374    'o'  => 'O ò Ò ó Ó ô Ô õ Õ ö Ö ø Ø ō Ō ŏ Ŏ ő Ő ơ Ơ ǒ Ǒ ǿ Ǿ ọ Ọ ỏ Ỏ ố Ố ồ Ồ ổ Ổ ỗ Ỗ ộ Ộ ớ Ớ ờ Ờ ở Ở ỡ Ỡ ợ Ợ',
375    'p'  => 'P',
376    'q'  => 'Q ĸ',
377    'r'  => 'R ŕ Ŕ ŗ Ŗ ř Ř',
378    's'  => 'S ś Ś ŝ Ŝ ş Ş š Š s ſ',
379    'ss' => 'ß',
380    't'  => 'T ţ Ţ ť Ť ŧ Ŧ',
381    'u'  => 'U ù Ù ú Ú û Û ü Ü ũ Ũ ū Ū ŭ Ŭ ů Ů ű Ű ų Ų ǔ Ǔ ǖ Ǖ ǘ Ǘ ǚ Ǚ ǜ Ǜ ư Ư ụ Ụ ủ Ủ ứ Ứ ừ Ừ ử Ử ữ Ữ ự Ự',
382    'v'  => 'V',
383    'w'  => 'W ŵ Ŵ ẁ Ẁ ẃ Ẃ ẅ Ẅ',
384    'x'  => 'X',
385    'y'  => 'Y ý Ý ÿ Ÿ ỳ Ỳ ỵ Ỵ ỷ Ỷ ỹ Ỹ ŷ Ŷ',
386    'z'  => 'Z ź Ź ż Ż ž Ž',
387    'ae' => 'æ Æ Ǽ ǽ',
388    'ð'  => 'Ð',
389    'ə'  => 'Ə',
390    'ij' => 'ij IJ',
391    'ŋ'  => 'Ŋ',
392    'oe' => 'œ Œ',
393    'þ'  => 'Þ',
394   
395  // Greek
396   
397    'α'  => 'Α ά Ά',
398    'β'  => 'Β',
399    'γ'  => 'Γ',
400    'δ'  => 'Δ',
401    'ε'  => 'Ε έ Έ',
402    'ζ'  => 'Ζ',
403    'η'  => 'Η ή Ή',
404    'θ'  => 'Θ',
405    'ι'  => 'Ι ί Ί ϊ Ϊ ΐ',
406    'κ'  => 'Κ',
407    'λ'  => 'Λ',
408    'μ'  => 'Μ µ',
409    'ν'  => 'Ν',
410    'ξ'  => 'Ξ',
411    'ο'  => 'Ο ό Ό',
412    'π'  => 'Π',
413    'ρ'  => 'Ρ',
414    'σ'  => 'Σ ς',
415    'τ'  => 'Τ',
416    'υ'  => 'Υ ύ Ύ ϋ Ϋ ΰ',
417    'φ'  => 'Φ',
418    'χ'  => 'Χ',
419    'ψ'  => 'Ψ',
420    'ω'  => 'Ω ώ Ώ',
421   
422  // Cyrillic
423   
424    'а'  => 'А',
425    'б'  => 'Б',
426    'в'  => 'В',
427    'г'  => 'Г ґ Ґ ғ Ғ',
428    'д'  => 'Д',
429    'е'  => 'Е',
430    'ж'  => 'Ж җ Җ',
431    'з'  => 'З',
432    'и'  => 'И',
433    'й'  => 'Й',
434    'к'  => 'К қ Қ ҝ Ҝ',
435    'л'  => 'Л',
436    'м'  => 'М',
437    'н'  => 'Н ң Ң',
438    'о'  => 'О',
439    'п'  => 'П',
440    'р'  => 'Р',
441    'с'  => 'С',
442    'т'  => 'Т',
443    'у'  => 'У',
444    'ү'  => 'Ү',
445    'ұ'  => 'Ұ',
446    'ф'  => 'Ф',
447    'х'  => 'Х ҳ Ҳ',
448    'ц'  => 'Ц',
449    'ч'  => 'Ч ҹ Ҹ',
450    'ш'  => 'Ш',
451    'щ'  => 'Щ',
452    'ъ'  => 'Ъ',
453    'ы'  => 'Ы',
454    'ь'  => 'Ь',
455    'э'  => 'Э',
456    'ю'  => 'Ю',
457    'я'  => 'Я',
458    'ё'  => 'Ё',
459    'ђ'  => 'Ђ',
460    'ѓ'  => 'Ѓ',
461    'є'  => 'Є',
462    'ѕ'  => 'Ѕ',
463    'і'  => 'І',
464    'ї'  => 'Ї',
465    'ј'  => 'Ј',
466    'љ'  => 'Љ',
467    'њ'  => 'Њ',
468    'ћ'  => 'Ћ',
469    'ќ'  => 'Ќ',
470    'ў'  => 'Ў',
471    'џ'  => 'Џ',
472    'һ'  => 'Һ',
473    'ә'  => 'Ә',
474    'ө'  => 'Ө',
475   
476  );
477
478  $LCAS_lang['char_replacement_set'][2] = array(
479  // 2 : case sensitive, accents insensitive
480   
481  // Latin
482   
483    'a'  => 'à â á ã ä å ā ă ą ǻ ạ ả ấ ầ ẩ ẫ ậ ắ ằ ẳ ẵ ặ @',
484    'A'  => 'À Â Á Ã Ä Å Ā Ă Ą Ǻ Ạ Ả Ấ Ầ Ẩ Ẫ Ậ Ắ Ằ Ẳ Ẵ Ặ',
485    'c'  => 'ç ć ĉ ċ č',
486    'C'  => 'Ç Ć Ĉ Ċ Č',
487    'd'  => 'ď đ',
488    'D'  => 'Ď Đ',
489    'e'  => 'è é ê ë ē ĕ ė ę ě ẹ ẻ ẽ ế ề ể ễ ệ',
490    'E'  => 'È É Ê Ë Ē Ĕ Ė Ę Ě Ẹ Ẻ Ẽ Ế Ề Ể Ễ Ệ',
491    'f'  => 'ƒ',
492    'g'  => 'ĝ ğ ġ ģ',
493    'G'  => 'Ĝ Ğ Ġ Ģ',
494    'h'  => 'ĥ ħ',
495    'H'  => 'Ĥ Ħ',
496    'i'  => 'ì í î ï ĩ ī ĭ į ǐ ỉ ị ı',
497    'I'  => 'Ì Í Î Ï Ĩ Ī Ĭ Į Ǐ Ỉ Ị İ',
498    'j'  => 'ĵ',
499    'J'  => 'Ĵ',
500    'k'  => 'ķ',
501    'K'  => 'Ķ',
502    'l'  => 'ĺ ļ ľ ŀ ł',
503    'L'  => 'Ĺ Ļ Ľ Ŀ Ł',
504    'n'  => 'ñ ń ņ ň ʼn',
505    'N'  => 'Ñ Ń Ņ Ň',
506    'o'  => 'ò ó ô õ ö ø ō ŏ ő ơ ǒ ǿ ọ ỏ ố ồ ổ ỗ ộ ớ ờ ở ỡ ợ',
507    'O'  => 'Ò Ó Ô Õ Ö Ø Ō Ŏ Ő Ơ Ǒ Ǿ Ọ Ỏ Ố Ồ Ổ Ỗ Ộ Ớ Ờ Ở Ỡ Ợ',
508    'q'  => 'ĸ',
509    'r'  => 'ŕ ŗ ř',
510    'R'  => 'Ŕ Ŗ Ř',
511    's'  => 'ś ŝ ş š ſ',
512    'S'  => 'Ś Ŝ Ş Š',
513    'ss' => 'ß',
514    't'  => 'ţ ť ŧ',
515    'T'  => 'Ţ Ť Ŧ',
516    'u'  => 'ù ú û ü ũ ū ŭ ů ű ų ǔ ǖ ǘ ǚ ǜ ư ụ ủ ứ ừ ử ữ ự',
517    'U'  => 'Ù Ú Û Ü Ũ Ū Ŭ Ů Ű Ų Ǔ Ǖ Ǘ Ǚ Ǜ Ư Ụ Ủ Ứ Ừ Ử Ữ Ự',
518    'w'  => 'ŵ ẁ ẃ ẅ',
519    'W'  => 'Ŵ Ẁ Ẃ Ẅ',
520    'y'  => 'ý ÿ ỳ ỵ ỷ ỹ ŷ',
521    'Y'  => 'Ý Ÿ Ỳ Ỵ Ỷ Ỹ Ŷ',
522    'z'  => 'ź ż ž',
523    'Z'  => 'Ź Ż Ž',
524    'ae' => 'ǽ',
525    'AE' => 'Ǽ',
526    'ij' => 'ij',
527    'IJ' => 'IJ',
528    'oe' => 'œ',
529    'OE' => 'Œ',
530   
531  // Greek
532   
533    'α'  => 'ά',
534    'Α'  => 'Ά',
535    'ε'  => 'έ',
536    'Ε'  => 'Έ',
537    'μ'  => 'µ',
538    'η'  => 'ή',
539    'Η'  => 'Ή',
540    'ι'  => 'ί ϊ ΐ',
541    'Ι'  => 'Ί Ϊ',
542    'ο'  => 'ό',
543    'Ο'  => 'Ό',
544    'σ'  => 'ς',
545    'υ'  => 'ύ ϋ ΰ',
546    'Υ'  => 'Ύ Ϋ',
547    'ω'  => 'ώ',
548    'Ω'  => 'Ώ',
549   
550  // Cyrillic
551   
552    'г'  => 'ґ ғ',
553    'Г'  => 'Ґ Ғ',
554    'ж'  => 'җ',
555    'Ж'  => 'Җ',
556    'к'  => 'қ ҝ',
557    'К'  => 'Қ Ҝ',
558    'н'  => 'ң',
559    'Н'  => 'Ң',
560    'х'  => 'ҳ',
561    'Х'  => 'Ҳ',
562    'ч'  => 'ҹ',
563    'Ч'  => 'Ҹ',
564   
565  );
566  // Exits immediately without changing the parameter, if the configuration
567  // is set on "case sensitive and accent sensitive".
568  if (!isset($Conf) or
569    $Conf != 1 and
570    $Conf != 2 and
571    $Conf != 3
572  ) return $Username;
573 
574  // $v remembers if the given parameter was an array or not
575  $s2 = ($v = (is_array($Username))) ? $Username : array(0 => $Username);
576 
577  // Builds an array of characters that must be replaced
578  // $rep_char is the replacement character ; $char_rep_arr is an array of
579  // characters which have to be replaced. ie :
580  // if
581  // $LCAS_lang['char_replacement_set'][$conf['insensitive_case_logon']]['e'] ='é è'
582  // then
583  // $char_rep_arr['é'] = 'e' ; $char_rep_arr['è'] = 'e'.
584  $char_rep_arr = array();
585  foreach (
586   $LCAS_lang['char_replacement_set'][$Conf]
587   as $rep_char => $char_rep_list
588  ) {
589    $t = explode(' ', $char_rep_list);
590    foreach ($t as $c) $char_rep_arr[$c] = $rep_char;
591  }
592 
593  // Replacement in each string of $s2 of the characters
594  // that needs to be replaced
595  $r = array();
596  foreach ($s2 as $s) {
597    $t = LCAS_mbStringToArray($s); $t2 ='';
598    foreach ($t as $c) {
599      if (array_key_exists($c, $char_rep_arr))
600       $t2.= $char_rep_arr[$c];
601      else
602       $t2.= $c;
603    }
604    $r[] = $t2;
605  }
606 
607  // Return of the result
608  if ($v) return $r;
609  else return $r[0];
610}
611
612
613
614
615
616
617
618
619
620
621
622
623/* Function called from LCAS_admin.php to send notification email */
624function LCAS_SendMail($id, $username)
625{
626  global $conf;
627
628  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
629 
630        include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
631
632/* We have to get the user's language in database */
633  $query ='
634SELECT user_id, language
635FROM '.USER_INFOS_TABLE.'
636WHERE user_id = '.$id.'
637;';
638  $data = pwg_db_fetch_assoc(pwg_query($query));
639
640/* Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language */
641  if (empty($data))
642  {
643/* And switch gallery to this language before using personalized and multilangual contents */
644    $language = pwg_get_session_var( 'lang_switch', $user['language'] );
645    switch_lang_to($language);
646  }
647  else
648  {
649/* And switch gallery to this language before using personalized and multilangual contents */
650    $language = $data['language']; /* Usefull for debugging */
651    switch_lang_to($data['language']);
652    load_language('plugin.lang', LCAS_PATH);
653  }
654
655  $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Username_updated_for_%s', stripslashes($username)));
656
657  if (isset($conf_LCAS[3]) and $conf_LCAS[3] <> '')
658  {
659    if (function_exists('get_user_language_desc'))
660    {
661      $customtxt = get_user_language_desc($conf_LCAS[3])."\n\n";
662    }
663    else $customtxt = l10n($conf_LCAS[3])."\n\n"; 
664  }
665
666/* Send the email with subject and contents */
667  pwg_mail($email, array(
668    'subject' => $subject,
669    'content' => ($customtxt),
670  ));
671
672/* Switching back to default language */
673switch_lang_back();
674}
675
676
677/* Function called from LCAS_admin.php and main.inc.php to get the plugin version and name */
678function LCAS_PluginInfos($dir)
679{
680  $path = $dir;
681
682  $plg_data = implode( '', file($path.'main.inc.php') );
683  if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
684  {
685    $plugin['name'] = trim( $val[1] );
686  }
687  if (preg_match("|Version: (.*)|", $plg_data, $val))
688  {
689    $plugin['version'] = trim($val[1]);
690  }
691  if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
692  {
693    $plugin['uri'] = trim($val[1]);
694  }
695  if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
696  {
697    $plugin['description'] = trim($desc);
698  }
699  elseif ( preg_match("|Description: (.*)|", $plg_data, $val) )
700  {
701    $plugin['description'] = trim($val[1]);
702  }
703  if ( preg_match("|Author: (.*)|", $plg_data, $val) )
704  {
705    $plugin['author'] = trim($val[1]);
706  }
707  if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
708  {
709    $plugin['author uri'] = trim($val[1]);
710  }
711  if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
712  {
713    list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
714    if (is_numeric($extension)) $plugin['extension'] = $extension;
715  }
716// IMPORTANT SECURITY !
717  $plugin = array_map('htmlspecialchars', $plugin);
718
719  return $plugin ;
720}
721
722
723// Tri les doublons
724function CompareTransformedUser($a, $b)
725{
726        return strcmp($a['transformed'], $b['transformed']);
727}
728
729
730// Fonctionnel mais optimisable
731function LCAS_GetDuplicates($source) {
732        $users      = array();
733        $duplicates = array();
734       
735        // Liste des utilisateurs uniques
736        foreach($source as $user) {
737                if (isset($users[$user['transformed']])) {
738                        $users[$user['transformed']] += 1;
739                }
740                else {
741                        $users[$user['transformed']] = 1;
742                }
743        }
744       
745        // On récupère les doublons
746        foreach($source as $user) {
747                if ($users[$user['transformed']] > 1) {
748                        array_push($duplicates, $user);
749                }
750        }
751       
752        // Trier le tableau
753        usort($duplicates, 'CompareTransformedUser');
754       
755        return $duplicates;
756}
757
758
759/**
760 * Retreive duplicate users according of case and or accent sensitivity
761 *
762 * @param : $rule for LCAS_change_case())
763 *
764 * @return : List of duplicate $username
765 *
766 */
767function LCAS_get_user_list($rule)
768{
769        global $conf, $page;
770 
771  $users = array();
772
773        /* search users depending expiration date */
774  $query = '
775SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
776                u.'.$conf['user_fields']['username'].' AS username,
777                u.'.$conf['user_fields']['email'].' AS email
778FROM '.USERS_TABLE.' AS u
779;';
780
781        $result = pwg_query($query);
782     
783  while ($row = pwg_db_fetch_assoc($result))
784  {
785        $user = $row;
786        $user['transformed'] = LCAS_change_case($user['username'], $rule); 
787    array_push($users, $user);
788        }
789
790        return LCAS_GetDuplicates($users);
791}
792
793
794// Cleaning obsolete files at plugin upgrade
795function LCAS_clean_obsolete_files()
796{
797  if (file_exists(LCAS_PATH.'obsolete.list')
798    and $old_files = file(LCAS_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES)
799    and !empty($old_files))
800  {
801    array_push($old_files, 'obsolete.list');
802    foreach($old_files as $old_file)
803    {
804      $path = LCAS_PATH.$old_file;
805      if (is_file($path))
806      {
807        @unlink($path);
808      }
809    }
810  }
811}
812
813
814/**
815 * Function called from main.inc.php - For test on username case sensitivity
816 * Have to be deleted before first release build
817 *
818 * @param : $username typed in by user for identification
819 *
820 * @return : $username found in database
821 *
822 */
823function LCAS_SearchCaseUsername($username, $rule)
824{
825  global $conf;
826
827  $username_c = LCAS_change_case($username, $rule);
828
829  if (isset($username))
830  {   
831    $LCAS_users = array();
832   
833    $q = pwg_query("
834      SELECT ".$conf['user_fields']['username']." AS username
835      FROM `".USERS_TABLE."`;
836    ");
837    while ($r = pwg_db_fetch_assoc($q))
838     $LCAS_users[$r['username']] = LCAS_change_case($r['username'], $rule);
839     // $LCAS_users is now an associative table where the key is the account as
840     // registered in the DB, and the value is this same account, in lower case
841
842    $users_found = array_keys($LCAS_users, $username_c);
843    // $users_found is now a table of which the values are all the accounts
844    // which can be written in lowercase the same way as $username
845    if (count($users_found) != 1) // If ambiguous, don't allow lowercase writing
846     return $username;            // but normal writing will work
847    else
848     return $users_found[0];
849  }
850}
851
852
853/*
854 * str_from_var3($var)
855 * returns a string easing array var informations displaying in Piwigo :
856 *   _ the string return value starts with"<p style = "text-align:left;">" ;
857 *   _ all "TAB" characters (chr(10)) are replaced by "<br>" ;
858 *   _ all spaces are replaced by "&nbsp;".
859 *
860 * @param
861 *   $var : variable to display
862 * @return
863 *   string easy to display in Piwigo
864 */
865function str_from_var3($var) {
866  return
867   '<p style = "text-align:left;">'.
868   str_replace(
869    chr(10),'<br>',
870    str_replace(' ','&nbsp;', print_r /* var_dump */ ($var,true))
871   ).
872   '</p>';
873}
874
875
876// DebugLog function
877function DebugLog($var1, $var2, $var3, $var4, $var5)
878{
879   $fo=fopen (LCAS_PATH.'admin/debuglog.txt','a') ;
880   fwrite($fo,"======================\n") ;
881   fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n");
882   fwrite($fo, "\n" . $var1 . "\r\n") ;
883   fwrite($fo, "\n" . $var2 . "\r\n") ;
884   fwrite($fo, "\n" . $var3 . "\r\n") ;
885   fwrite($fo, "\n" . $var4 . "\r\n") ;
886   fwrite($fo, "\n" . $var5 . "\r\n") ;
887   fclose($fo) ;
888}
889?>
Note: See TracBrowser for help on using the repository browser.