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

Last change on this file since 8143 was 8143, checked in by Whiler, 13 years ago

Parameters labels weren't good... (opposite from what we are expecting) - fixed
Second tab only show users who are duplicated with the chosen options

File size: 21.6 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/*
29 * Changes the characters of the given string as stated by values of
30 * $conf['insensitive_case_logon'] and $LCAS_lang['char_replacement_set'].
31 *
32 * @param mix s: string, or array of strings, to evaluate
33 *
34 * @return : string, or array of strings, modified as stated
35*/
36function LCAS_change_case($Username, $Conf)
37{
38  $LCAS_lang                         = array();
39  $LCAS_lang['char_replacement_set'] = array();
40
41
42
43  // 0 : case sensitive, accents sensitive
44  $LCAS_lang['char_replacement_set'][1] = array(
45  // 1 : case insensitive, accents sensitive
46   
47  // Latin
48   
49    'a'  => 'A',
50    'à'  => 'À',
51    'â'  => 'Â',
52    'á'  => 'Á',
53    'ã'  => 'Ã',
54    'ä'  => 'Ä',
55    'å'  => 'Å',
56    'ā'  => 'Ā',
57    'ă'  => 'Ă',
58    'ą'  => 'Ą',
59    'ǻ'  => 'Ǻ',
60    'ạ'  => 'Ạ',
61    'ả'  => 'Ả',
62    'ấ'  => 'Ấ',
63    'ầ'  => 'Ầ',
64    'ẩ'  => 'Ẩ',
65    'ẫ'  => 'Ẫ',
66    'ậ'  => 'Ậ',
67    'ắ'  => 'Ắ',
68    'ằ'  => 'Ằ',
69    'ẳ'  => 'Ẳ',
70    'ẵ'  => 'Ẵ',
71    'ặ'  => 'Ặ',
72   
73    'b'  => 'B',
74   
75    'c'  => 'C',
76    'ç'  => 'Ç',
77    'ć'  => 'Ć',
78    'ĉ'  => 'Ĉ',
79    'ċ'  => 'Ċ',
80    'č'  => 'Č',
81
82    'd'  => 'D',
83    'ď'  => 'Ď',
84    'đ'  => 'Đ',
85   
86    'e'  => 'E',
87    'è'  => 'È',
88    'é'  => 'É',
89    'ê'  => 'Ê',
90    'ë'  => 'Ë',
91    'ē'  => 'Ē',
92    'ĕ'  => 'Ĕ',
93    'ė'  => 'Ė',
94    'ę'  => 'Ę',
95    'ě'  => 'Ě',
96    'ẹ'  => 'Ẹ',
97    'ẻ'  => 'Ẻ',
98    'ẽ'  => 'Ẽ',
99    'ế'  => 'Ế',
100    'ề'  => 'Ề',
101    'ể'  => 'Ể',
102    'ễ'  => 'Ễ',
103    'ệ'  => 'Ệ',
104   
105    'f'  => 'F ƒ',
106   
107    'g'  => 'G',
108    'ĝ'  => 'Ĝ',
109    'ğ'  => 'Ğ',
110    'ġ'  => 'Ġ',
111    'ģ'  => 'Ģ',
112   
113    'h'  => 'H',
114    'ĥ'  => 'Ĥ',
115    'ħ'  => 'Ħ',
116   
117    'i'  => 'I ı İ',
118    'ì'  => 'Ì',
119    'í'  => 'Í',
120    'î'  => 'Î',
121    'ï'  => 'Ï',
122    'ĩ'  => 'Ĩ',
123    'ī'  => 'Ī',
124    'ĭ'  => 'Ĭ',
125    'į'  => 'Į',
126    'ǐ'  => 'Ǐ',
127    'ỉ'  => 'Ỉ',
128    'ị'  => 'Ị',
129   
130    'j'  => 'J',
131    'ĵ'  => 'Ĵ',
132   
133    'k'  => 'K',
134    'ķ'  => 'Ķ',
135   
136    'l'  => 'L',
137    'ĺ'  => 'Ĺ',
138    'ļ'  => 'Ļ',
139    'ľ'  => 'Ľ',
140    'ŀ'  => 'Ŀ',
141    'ł'  => 'Ł',
142   
143    'm'  => 'M',
144   
145    'n'  => 'N',
146    'ñ'  => 'Ñ',
147    'ń'  => 'Ń',
148    'ņ'  => 'Ņ',
149    'ň'  => 'Ň',
150   
151    'o'  => 'O',
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   
177    'p'  => 'P',
178   
179    'q'  => 'Q ĸ',
180   
181    'r'  => 'R',
182    'ŕ'  => 'Ŕ',
183    'ŗ'  => 'Ŗ',
184    'ř'  => 'Ř',
185   
186    's'  => 'S',
187    'ś'  => 'Ś',
188    'ŝ'  => 'Ŝ',
189    'ş'  => 'Ş',
190    'š'  => 'Š',
191    's'  => 'ſ',
192    'ss' => 'ß',
193   
194    't'  => 'T',
195    'ţ'  => 'Ţ',
196    'ť'  => 'Ť',
197    'ŧ'  => 'Ŧ',
198   
199    'u'  => 'U',
200    'ù'  => 'Ù',
201    'ú'  => 'Ú',
202    'û'  => 'Û',
203    'ü'  => 'Ü',
204    'ũ'  => 'Ũ',
205    'ū'  => 'Ū',
206    'ŭ'  => 'Ŭ',
207    'ů'  => 'Ů',
208    'ű'  => 'Ű',
209    'ų'  => 'Ų',
210    'ǔ'  => 'Ǔ',
211    'ǖ'  => 'Ǖ',
212    'ǘ'  => 'Ǘ',
213    'ǚ'  => 'Ǚ',
214    'ǜ'  => 'Ǜ',
215    'ư'  => 'Ư',
216    'ụ'  => 'Ụ',
217    'ủ'  => 'Ủ',
218    'ứ'  => 'Ứ',
219    'ừ'  => 'Ừ',
220    'ử'  => 'Ử',
221    'ữ'  => 'Ữ',
222    'ự'  => 'Ự',
223   
224    'v'  => 'V',
225   
226    'w'  => 'W',
227    'ŵ'  => 'Ŵ',
228    'ẁ'  => 'Ẁ',
229    'ẃ'  => 'Ẃ',
230    'ẅ'  => 'Ẅ',
231   
232    'x'  => 'X',
233   
234    'y'  => 'Y',
235    'ý'  => 'Ý',
236    'ÿ'  => 'Ÿ',
237    'ỳ'  => 'Ỳ',
238    'ỵ'  => 'Ỵ',
239    'ỷ'  => 'Ỷ',
240    'ỹ'  => 'Ỹ',
241    'ŷ'  => 'Ŷ',
242   
243    'z'  => 'Z',
244    'ź'  => 'Ź',
245    'ż'  => 'Ż',
246    'ž'  => 'Ž',
247   
248    'ae' => 'æ Æ',
249    'aé' => 'ǽ Ǽ',
250    'ð'  => 'Ð',
251    'ə'  => 'Ə',
252    'ij' => 'ij IJ',
253    'ŋ'  => 'Ŋ',
254    'oe' => 'œ Œ',
255    'þ'  => 'Þ',
256   
257  // Greek
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    'ώ'  => 'Ώ',
292   
293  // Cyrillic
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  );
356
357  $LCAS_lang['char_replacement_set'][2] = array(
358  // 2 : case insensitive, accents insensitive
359   
360  // Latin
361   
362    'a'  => 'A à À â Â á Á ã Ã ä Ä å Å ā Ā ă Ă ą Ą ǻ Ǻ ạ Ạ ả Ả ấ Ấ ầ Ầ ẩ Ẩ ẫ Ẫ ậ Ậ ắ Ắ ằ Ằ ẳ Ẳ ẵ Ẵ ặ Ặ @',
363    'b'  => 'B',
364    'c'  => 'C ç Ç ć Ć ĉ Ĉ ċ Ċ č Č',
365    'd'  => 'D ď Ď đ Đ',
366    'e'  => 'E è È é É ê Ê ë Ë ē Ē ĕ Ĕ ė Ė ę Ę ě Ě ẹ Ẹ ẻ Ẻ ẽ Ẽ ế Ế ề Ề ể Ể ễ Ễ ệ Ệ',
367    'f'  => 'F ƒ',
368    'g'  => 'G ĝ Ĝ ğ Ğ ġ Ġ ģ Ģ',
369    'h'  => 'H ĥ Ĥ ħ Ħ',
370    'i'  => 'I ı İ ì Ì í Í î Î ï Ï ĩ Ĩ ī Ī ĭ Ĭ į Į ǐ Ǐ ỉ Ỉ ị Ị',
371    'j'  => 'J ĵ Ĵ',
372    'k'  => 'K ķ Ķ',
373    'l'  => 'L ĺ Ĺ ļ Ļ ľ Ľ ŀ Ŀ ł Ł',
374    'm'  => 'M',
375    'n'  => 'N ʼn ñ Ñ ń Ń ņ Ņ ň Ň',
376    'o'  => 'O ò Ò ó Ó ô Ô õ Õ ö Ö ø Ø ō Ō ŏ Ŏ ő Ő ơ Ơ ǒ Ǒ ǿ Ǿ ọ Ọ ỏ Ỏ ố Ố ồ Ồ ổ Ổ ỗ Ỗ ộ Ộ ớ Ớ ờ Ờ ở Ở ỡ Ỡ ợ Ợ',
377    'p'  => 'P',
378    'q'  => 'Q ĸ',
379    'r'  => 'R ŕ Ŕ ŗ Ŗ ř Ř',
380    's'  => 'S ś Ś ŝ Ŝ ş Ş š Š s ſ',
381    'ss' => 'ß',
382    't'  => 'T ţ Ţ ť Ť ŧ Ŧ',
383    'u'  => 'U ù Ù ú Ú û Û ü Ü ũ Ũ ū Ū ŭ Ŭ ů Ů ű Ű ų Ų ǔ Ǔ ǖ Ǖ ǘ Ǘ ǚ Ǚ ǜ Ǜ ư Ư ụ Ụ ủ Ủ ứ Ứ ừ Ừ ử Ử ữ Ữ ự Ự',
384    'v'  => 'V',
385    'w'  => 'W ŵ Ŵ ẁ Ẁ ẃ Ẃ ẅ Ẅ',
386    'x'  => 'X',
387    'y'  => 'Y ý Ý ÿ Ÿ ỳ Ỳ ỵ Ỵ ỷ Ỷ ỹ Ỹ ŷ Ŷ',
388    'z'  => 'Z ź Ź ż Ż ž Ž',
389    'ae' => 'æ Æ Ǽ ǽ',
390    'ð'  => 'Ð',
391    'ə'  => 'Ə',
392    'ij' => 'ij IJ',
393    'ŋ'  => 'Ŋ',
394    'oe' => 'œ Œ',
395    'þ'  => 'Þ',
396   
397  // Greek
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    'ω'  => 'Ω ώ Ώ',
423   
424  // Cyrillic
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  );
479
480  $LCAS_lang['char_replacement_set'][3] = array(
481  // 3 : case sensitive, accents insensitive
482   
483  // Latin
484   
485    'a'  => 'à â á ã ä å ā ă ą ǻ ạ ả ấ ầ ẩ ẫ ậ ắ ằ ẳ ẵ ặ @',
486    'A'  => 'À Â Á Ã Ä Å Ā Ă Ą Ǻ Ạ Ả Ấ Ầ Ẩ Ẫ Ậ Ắ Ằ Ẳ Ẵ Ặ',
487    'c'  => 'ç ć ĉ ċ č',
488    'C'  => 'Ç Ć Ĉ Ċ Č',
489    'd'  => 'ď đ',
490    'D'  => 'Ď Đ',
491    'e'  => 'è é ê ë ē ĕ ė ę ě ẹ ẻ ẽ ế ề ể ễ ệ',
492    'E'  => 'È É Ê Ë Ē Ĕ Ė Ę Ě Ẹ Ẻ Ẽ Ế Ề Ể Ễ Ệ',
493    'f'  => 'ƒ',
494    'g'  => 'ĝ ğ ġ ģ',
495    'G'  => 'Ĝ Ğ Ġ Ģ',
496    'h'  => 'ĥ ħ',
497    'H'  => 'Ĥ Ħ',
498    'i'  => 'ì í î ï ĩ ī ĭ į ǐ ỉ ị ı',
499    'I'  => 'Ì Í Î Ï Ĩ Ī Ĭ Į Ǐ Ỉ Ị İ',
500    'j'  => 'ĵ',
501    'J'  => 'Ĵ',
502    'k'  => 'ķ',
503    'K'  => 'Ķ',
504    'l'  => 'ĺ ļ ľ ŀ ł',
505    'L'  => 'Ĺ Ļ Ľ Ŀ Ł',
506    'n'  => 'ñ ń ņ ň ʼn',
507    'N'  => 'Ñ Ń Ņ Ň',
508    'o'  => 'ò ó ô õ ö ø ō ŏ ő ơ ǒ ǿ ọ ỏ ố ồ ổ ỗ ộ ớ ờ ở ỡ ợ',
509    'O'  => 'Ò Ó Ô Õ Ö Ø Ō Ŏ Ő Ơ Ǒ Ǿ Ọ Ỏ Ố Ồ Ổ Ỗ Ộ Ớ Ờ Ở Ỡ Ợ',
510    'q'  => 'ĸ',
511    'r'  => 'ŕ ŗ ř',
512    'R'  => 'Ŕ Ŗ Ř',
513    's'  => 'ś ŝ ş š ſ',
514    'S'  => 'Ś Ŝ Ş Š',
515    'ss' => 'ß',
516    't'  => 'ţ ť ŧ',
517    'T'  => 'Ţ Ť Ŧ',
518    'u'  => 'ù ú û ü ũ ū ŭ ů ű ų ǔ ǖ ǘ ǚ ǜ ư ụ ủ ứ ừ ử ữ ự',
519    'U'  => 'Ù Ú Û Ü Ũ Ū Ŭ Ů Ű Ų Ǔ Ǖ Ǘ Ǚ Ǜ Ư Ụ Ủ Ứ Ừ Ử Ữ Ự',
520    'w'  => 'ŵ ẁ ẃ ẅ',
521    'W'  => 'Ŵ Ẁ Ẃ Ẅ',
522    'y'  => 'ý ÿ ỳ ỵ ỷ ỹ ŷ',
523    'Y'  => 'Ý Ÿ Ỳ Ỵ Ỷ Ỹ Ŷ',
524    'z'  => 'ź ż ž',
525    'Z'  => 'Ź Ż Ž',
526    'ae' => 'ǽ',
527    'AE' => 'Ǽ',
528    'ij' => 'ij',
529    'IJ' => 'IJ',
530    'oe' => 'œ',
531    'OE' => 'Œ',
532   
533  // Greek
534   
535    'α'  => 'ά',
536    'Α'  => 'Ά',
537    'ε'  => 'έ',
538    'Ε'  => 'Έ',
539    'μ'  => 'µ',
540    'η'  => 'ή',
541    'Η'  => 'Ή',
542    'ι'  => 'ί ϊ ΐ',
543    'Ι'  => 'Ί Ϊ',
544    'ο'  => 'ό',
545    'Ο'  => 'Ό',
546    'σ'  => 'ς',
547    'υ'  => 'ύ ϋ ΰ',
548    'Υ'  => 'Ύ Ϋ',
549    'ω'  => 'ώ',
550    'Ω'  => 'Ώ',
551   
552  // Cyrillic
553   
554    'г'  => 'ґ ғ',
555    'Г'  => 'Ґ Ғ',
556    'ж'  => 'җ',
557    'Ж'  => 'Җ',
558    'к'  => 'қ ҝ',
559    'К'  => 'Қ Ҝ',
560    'н'  => 'ң',
561    'Н'  => 'Ң',
562    'х'  => 'ҳ',
563    'Х'  => 'Ҳ',
564    'ч'  => 'ҹ',
565    'Ч'  => 'Ҹ',
566   
567  );
568  // Exits immediately without changing the parameter, if the configuration
569  // is set on "case sensitive and accent sensitive".
570  if (!isset($Conf) or
571    $Conf != 1 and
572    $Conf != 2 and
573    $Conf != 3
574  ) return $Username;
575 
576  // $v remembers if the given parameter was an array or not
577  $s2 = ($v = (is_array($Username))) ? $Username : array(0 => $Username);
578 
579  // Builds an array of characters that must be replaced
580  // $rep_char is the replacement character ; $char_rep_arr is an array of
581  // characters which have to be replaced. ie :
582  // if
583  // $LCAS_lang['char_replacement_set'][$conf['insensitive_case_logon']]['e'] ='é è'
584  // then
585  // $char_rep_arr['é'] = 'e' ; $char_rep_arr['è'] = 'e'.
586  $char_rep_arr = array();
587  foreach (
588   $LCAS_lang['char_replacement_set'][$Conf]
589   as $rep_char => $char_rep_list
590  ) {
591    $t = explode(' ', $char_rep_list);
592    foreach ($t as $c) $char_rep_arr[$c] = $rep_char;
593  }
594 
595  // Replacement in each string of $s2 of the characters
596  // that needs to be replaced
597  $r = array();
598  foreach ($s2 as $s) {
599    $t = LCAS_mbStringToArray($s); $t2 ='';
600    foreach ($t as $c) {
601      if (array_key_exists($c, $char_rep_arr))
602       $t2.= $char_rep_arr[$c];
603      else
604       $t2.= $c;
605    }
606    $r[] = $t2;
607  }
608 
609  // Return of the result
610  if ($v) return $r;
611  else return $r[0];
612}
613
614
615
616
617
618
619
620
621
622
623
624
625/* Function called from main.inc.php to send validation email */
626function LCAS_SendMail2User($typemail, $id, $username, $password, $email, $confirm)
627{
628  global $conf;
629
630  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
631 
632        include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
633 
634        $infos1_perso = "";
635  $infos2_perso = "";
636
637/* We have to get the user's language in database */
638  $query ='
639SELECT user_id, language
640FROM '.USER_INFOS_TABLE.'
641WHERE user_id = '.$id.'
642;';
643  $data = pwg_db_fetch_assoc(pwg_query($query));
644
645/* Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language */
646  if (empty($data))
647  {
648/* And switch gallery to this language before using personalized and multilangual contents */
649    $language = pwg_get_session_var( 'lang_switch', $user['language'] );
650    switch_lang_to($language);
651  }
652  else
653  {
654/* And switch gallery to this language before using personalized and multilangual contents */
655    $language = $data['language']; /* Usefull for debugging */
656    switch_lang_to($data['language']);
657    load_language('plugin.lang', LCAS_PATH);
658  }
659
660  switch($typemail)
661  {
662    case 1:
663      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', stripslashes($username)));
664      $password = $password <> '' ? $password : l10n('LCAS_empty_pwd');
665     
666      if (isset($conf_LCAS[9]) and $conf_LCAS[9] <> '')
667      {
668        if (function_exists('get_user_language_desc'))
669        {
670          $infos1_perso = get_user_language_desc($conf_LCAS[9])."\n\n";
671        }
672        else $infos1_perso = l10n($conf_LCAS[9])."\n\n"; 
673      }
674     
675      break;
676     
677    case 2:
678      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username)));
679      $password = $password <> '' ? $password : l10n('LCAS_empty_pwd');
680
681      break;
682       
683    case 3:
684      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', stripslashes($username)));
685      $password = $password <> '' ? $password : l10n('LCAS_no_update_pwd');
686
687      break;
688  }
689
690  if (isset($conf_LCAS[0]) and $conf_LCAS[0] == 'true')
691  {
692    $infos1 = array(
693      get_l10n_args('infos_mail %s', stripslashes($username)),
694      get_l10n_args('User: %s', stripslashes($username)),
695      get_l10n_args('Password: %s', $password),
696      get_l10n_args('Email: %s', $email),
697      get_l10n_args('', ''),
698    );
699  }
700
701
702  if ( isset($conf_LCAS[1]) and $conf_LCAS[1] == 'true' and $confirm)
703  {
704    $infos2 = array
705    (
706      get_l10n_args('Link: %s', AddConfirmMail($id, $email)),
707      get_l10n_args('', ''),
708    );
709
710    if (isset($conf_LCAS[10]) and $conf_LCAS[10] <> '')
711    {
712      if (function_exists('get_user_language_desc'))
713      {
714        $infos2_perso = get_user_language_desc($conf_LCAS[10])."\n\n";
715      }
716      else $infos2_perso = l10n($conf_LCAS[10])."\n\n";
717    }
718  }
719
720/* ******************************************************** */
721/* **** Pending code since to find how to make it work **** */
722/* ******************************************************** */
723// Testing if FCK Editor is used. Then decoding htmlchars to avoid problems with pwg_mail()
724/*$areas = array();
725array_push( $areas,'LCAS_MailInfo_Text','LCAS_ConfirmMail_Text');
726
727if (function_exists('set_fckeditor_instance'))
728{
729  $fcke_config = unserialize($conf['FCKEditor']);
730  foreach($areas as $area)
731  {
732    if (isset($fcke_config['LCAS_MailInfo_Text']) and $fcke_config['LCAS_MailInfo_Text'] = true)
733    {
734      $infos1_perso = html_entity_decode($infos1_perso,ENT_QUOTES,UTF-8);
735    }
736   
737    if (isset($fcke_config['LCAS_ConfirmMail_Text']) and $fcke_config['LCAS_ConfirmMail_Text'] = true)
738    {
739      $infos2_perso = html_entity_decode($infos2_perso,ENT_QUOTES,UTF-8);
740    }
741  }
742}*/
743
744/* Sending the email with subject and contents */
745  pwg_mail($email, array(
746    'subject' => $subject,
747    'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(),
748  ));
749
750/* ********************** */
751/* Email sending debugger */
752/* This is only to trace  */
753/* the send of emails for */
754/* debugging              */
755/* ********************** */
756//$content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url();   
757//MailLog($email,$subject,$content,$language);
758/* ********************** */
759
760/* Switching back to default language */
761switch_lang_back();
762}
763
764/* Function called from LCAS_admin.php and main.inc.php to get the plugin version and name */
765function LCAS_PluginInfos($dir)
766{
767  $path = $dir;
768
769  $plg_data = implode( '', file($path.'main.inc.php') );
770  if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
771  {
772    $plugin['name'] = trim( $val[1] );
773  }
774  if (preg_match("|Version: (.*)|", $plg_data, $val))
775  {
776    $plugin['version'] = trim($val[1]);
777  }
778  if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
779  {
780    $plugin['uri'] = trim($val[1]);
781  }
782  if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
783  {
784    $plugin['description'] = trim($desc);
785  }
786  elseif ( preg_match("|Description: (.*)|", $plg_data, $val) )
787  {
788    $plugin['description'] = trim($val[1]);
789  }
790  if ( preg_match("|Author: (.*)|", $plg_data, $val) )
791  {
792    $plugin['author'] = trim($val[1]);
793  }
794  if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
795  {
796    $plugin['author uri'] = trim($val[1]);
797  }
798  if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
799  {
800    list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
801    if (is_numeric($extension)) $plugin['extension'] = $extension;
802  }
803// IMPORTANT SECURITY !
804  $plugin = array_map('htmlspecialchars', $plugin);
805
806  return $plugin ;
807}
808
809// Fonctionnel mais optimisable
810function LCAS_GetDuplicates($source) {
811        $users      = array();
812        $duplicates = array();
813       
814        // Liste des utilisateurs uniques
815        foreach($source as $user) {
816                if (isset($users[$user['transformed']])) {
817                        $users[$user['transformed']] += 1;
818                }
819                else {
820                        $users[$user['transformed']] = 1;
821                }
822        }
823       
824        // On récupère les doublons
825        foreach($source as $user) {
826                if ($users[$user['transformed']] > 1) {
827                        array_push($duplicates, $user);
828                }
829        }
830       
831        return $duplicates;
832}
833
834/* Function called from UserAdvManager.php - Get all users to display the number of days since their last visit */
835function LCAS_get_user_list($rule)
836{
837        global $conf, $page;
838 
839  $users = array();
840
841        /* search users depending expiration date */
842  $query = '
843SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
844                u.'.$conf['user_fields']['username'].' AS username,
845                u.'.$conf['user_fields']['email'].' AS email
846FROM '.USERS_TABLE.' AS u
847;';
848
849        $result = pwg_query($query);
850     
851  while ($row = pwg_db_fetch_assoc($result))
852  {
853        $user = $row;
854        $user['transformed'] = LCAS_change_case($user['username'], $rule); 
855    array_push($users, $user);
856        }
857
858        return LCAS_GetDuplicates($users);
859}
860
861function LCAS_clean_obsolete_files()
862{
863  if (file_exists(LCAS_PATH.'obsolete.list')
864    and $old_files = file(LCAS_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES)
865    and !empty($old_files))
866  {
867    array_push($old_files, 'obsolete.list');
868    foreach($old_files as $old_file)
869    {
870      $path = LCAS_PATH.$old_file;
871      if (is_file($path))
872      {
873        @unlink($path);
874      }
875    }
876  }
877}
878
879?>
Note: See TracBrowser for help on using the repository browser.