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

Last change on this file since 8157 was 8157, checked in by Eric, 13 years ago

UTF8 encoding fix

File size: 20.4 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    'a'  => 'A',
57    'a'  => 'A',
58    'a'  => 'A',
59    '?'  => '?',
60    '?'  => '?',
61    '?'  => '?',
62    '?'  => '?',
63    '?'  => '?',
64    '?'  => '?',
65    '?'  => '?',
66    '?'  => '?',
67    '?'  => '?',
68    '?'  => '?',
69    '?'  => '?',
70    '?'  => '?',
71    '?'  => '?',
72   
73    'b'  => 'B',
74   
75    'c'  => 'C',
76    'ç'  => 'Ç',
77    'c'  => 'C',
78    'c'  => 'C',
79    'c'  => 'C',
80    'c'  => 'C',
81
82    'd'  => 'D',
83    'd'  => 'D',
84    'd'  => 'Ð',
85   
86    'e'  => 'E',
87    'è'  => 'È',
88    'é'  => 'É',
89    'ê'  => 'Ê',
90    'ë'  => 'Ë',
91    'e'  => 'E',
92    'e'  => 'E',
93    'e'  => 'E',
94    'e'  => 'E',
95    'e'  => 'E',
96    '?'  => '?',
97    '?'  => '?',
98    '?'  => '?',
99    '?'  => '?',
100    '?'  => '?',
101    '?'  => '?',
102    '?'  => '?',
103    '?'  => '?',
104   
105    'f'  => 'F ƒ',
106   
107    'g'  => 'G',
108    'g'  => 'G',
109    'g'  => 'G',
110    'g'  => 'G',
111    'g'  => 'G',
112   
113    'h'  => 'H',
114    'h'  => 'H',
115    'h'  => 'H',
116   
117    'i'  => 'I i I',
118    'ì'  => 'Ì',
119    'í'  => 'Í',
120    'î'  => 'Î',
121    'ï'  => 'Ï',
122    'i'  => 'I',
123    'i'  => 'I',
124    'i'  => 'I',
125    'i'  => 'I',
126    'i'  => 'I',
127    '?'  => '?',
128    '?'  => '?',
129   
130    'j'  => 'J',
131    'j'  => 'J',
132   
133    'k'  => 'K',
134    'k'  => 'K',
135   
136    'l'  => 'L',
137    'l'  => 'L',
138    'l'  => 'L',
139    'l'  => 'L',
140    '?'  => '?',
141    'l'  => 'L',
142   
143    'm'  => 'M',
144   
145    'n'  => 'N',
146    'ñ'  => 'Ñ',
147    'n'  => 'N',
148    'n'  => 'N',
149    'n'  => 'N',
150   
151    'o'  => 'O',
152    'ò'  => 'Ò',
153    'ó'  => 'Ó',
154    'ô'  => 'Ô',
155    'õ'  => 'Õ',
156    'ö'  => 'Ö',
157    'ø'  => 'Ø',
158    'o'  => 'O',
159    'o'  => 'O',
160    'o'  => 'O',
161    'o'  => 'O',
162    'o'  => 'O',
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    'r'  => 'R',
183    'r'  => 'R',
184    'r'  => 'R',
185   
186    's'  => 'S',
187    's'  => 'S',
188    's'  => 'S',
189    's'  => 'S',
190    'š'  => 'Š',
191    's'  => '?',
192    'ss' => 'ß',
193   
194    't'  => 'T',
195    't'  => 'T',
196    't'  => 'T',
197    't'  => 'T',
198   
199    'u'  => 'U',
200    'ù'  => 'Ù',
201    'ú'  => 'Ú',
202    'û'  => 'Û',
203    'ü'  => 'Ü',
204    'u'  => 'U',
205    'u'  => 'U',
206    'u'  => 'U',
207    'u'  => 'U',
208    'u'  => 'U',
209    'u'  => 'U',
210    'u'  => 'U',
211    'u'  => 'U',
212    'u'  => 'U',
213    'u'  => 'U',
214    'u'  => 'U',
215    'u'  => 'U',
216    '?'  => '?',
217    '?'  => '?',
218    '?'  => '?',
219    '?'  => '?',
220    '?'  => '?',
221    '?'  => '?',
222    '?'  => '?',
223   
224    'v'  => 'V',
225   
226    'w'  => 'W',
227    'w'  => 'W',
228    '?'  => '?',
229    '?'  => '?',
230    '?'  => '?',
231   
232    'x'  => 'X',
233   
234    'y'  => 'Y',
235    'ý'  => 'Ý',
236    'ÿ'  => 'Ÿ',
237    '?'  => '?',
238    '?'  => '?',
239    '?'  => '?',
240    '?'  => '?',
241    'y'  => 'Y',
242   
243    'z'  => 'Z',
244    'z'  => 'Z',
245    'z'  => 'Z',
246    'ž'  => 'Ž',
247   
248    'ae' => 'æ Æ',
249    'aé' => '? ?',
250    'ð'  => 'Ð',
251    '?'  => '?',
252    'ij' => '? ?',
253    '?'  => '?',
254    'oe' => 'œ Œ',
255    'þ'  => 'Þ',
256   
257  // Greek
258   
259    'a'  => '?',
260    '?'  => '?',
261    'ß'  => '?',
262    '?'  => 'G',
263    'd'  => '?',
264    'e'  => '?',
265    '?'  => '?',
266    '?'  => '?',
267    '?'  => '?',
268    '?'  => '?',
269    '?'  => 'T',
270    '?'  => '?',
271    '?'  => '?',
272    '?'  => '?',
273    '?'  => '?',
274    '?'  => '?',
275    'µ'  => '? µ',
276    '?'  => '?',
277    '?'  => '?',
278    '?'  => '?',
279    '?'  => '?',
280    'p'  => '?',
281    '?'  => '?',
282    's'  => 'S ?',
283    't'  => '?',
284    '?'  => '?',
285    '?'  => '?',
286    '?'  => '?',
287    'f'  => 'F',
288    '?'  => '?',
289    '?'  => '?',
290    '?'  => 'O',
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    'h'  => '?',
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 à À â Â á Á ã Ã ä Ä å Å a A a A a A ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @',
363    'b'  => 'B',
364    'c'  => 'C ç Ç c C c C c C c C',
365    'd'  => 'D d D d Ð',
366    'e'  => 'E è È é É ê Ê ë Ë e E e E e E e E e E ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?',
367    'f'  => 'F ƒ',
368    'g'  => 'G g G g G g G g G',
369    'h'  => 'H h H h H',
370    'i'  => 'I i I ì Ì í Í î Î ï Ï i I i I i I i I i I ? ? ? ?',
371    'j'  => 'J j J',
372    'k'  => 'K k K',
373    'l'  => 'L l L l L l L ? ? l L',
374    'm'  => 'M',
375    'n'  => 'N ? ñ Ñ n N n N n N',
376    'o'  => 'O ò Ò ó Ó ô Ô õ Õ ö Ö ø Ø o O o O o O o O o O ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?',
377    'p'  => 'P',
378    'q'  => 'Q ?',
379    'r'  => 'R r R r R r R',
380    's'  => 'S s S s S s S š Š s ?',
381    'ss' => 'ß',
382    't'  => 'T t T t T t T',
383    'u'  => 'U ù Ù ú Ú û Û ü Ü u U u U u U u U u U u U u U u U u U u U u U u U ? ? ? ? ? ? ? ? ? ? ? ? ? ?',
384    'v'  => 'V',
385    'w'  => 'W w W ? ? ? ? ? ?',
386    'x'  => 'X',
387    'y'  => 'Y ý Ý ÿ Ÿ ? ? ? ? ? ? ? ? y Y',
388    'z'  => 'Z z Z z Z ž Ž',
389    'ae' => 'æ Æ ? ?',
390    'ð'  => 'Ð',
391    '?'  => '?',
392    'ij' => '? ?',
393    '?'  => '?',
394    'oe' => 'œ Œ',
395    'þ'  => 'Þ',
396   
397  // Greek
398   
399    'a'  => '? ? ?',
400    'ß'  => '?',
401    '?'  => 'G',
402    'd'  => '?',
403    'e'  => '? ? ?',
404    '?'  => '?',
405    '?'  => '? ? ?',
406    '?'  => 'T',
407    '?'  => '? ? ? ? ? ?',
408    '?'  => '?',
409    '?'  => '?',
410    'µ'  => '? µ',
411    '?'  => '?',
412    '?'  => '?',
413    '?'  => '? ? ?',
414    'p'  => '?',
415    '?'  => '?',
416    's'  => 'S ?',
417    't'  => '?',
418    '?'  => '? ? ? ? ? ?',
419    'f'  => 'F',
420    '?'  => '?',
421    '?'  => '?',
422    '?'  => 'O ? ?',
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    'h'  => '?',
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'  => 'à â á ã ä å a a a ? ? ? ? ? ? ? ? ? ? ? ? ? @',
486    'A'  => 'À Â Á Ã Ä Å A A A ? ? ? ? ? ? ? ? ? ? ? ? ?',
487    'c'  => 'ç c c c c',
488    'C'  => 'Ç C C C C',
489    'd'  => 'd d',
490    'D'  => 'D Ð',
491    'e'  => 'è é ê ë e e e e e ? ? ? ? ? ? ? ?',
492    'E'  => 'È É Ê Ë E E E E E ? ? ? ? ? ? ? ?',
493    'f'  => 'ƒ',
494    'g'  => 'g g g g',
495    'G'  => 'G G G G',
496    'h'  => 'h h',
497    'H'  => 'H H',
498    'i'  => 'ì í î ï i i i i i ? ? i',
499    'I'  => 'Ì Í Î Ï I I I I I ? ? I',
500    'j'  => 'j',
501    'J'  => 'J',
502    'k'  => 'k',
503    'K'  => 'K',
504    'l'  => 'l l l ? l',
505    'L'  => 'L L L ? L',
506    'n'  => 'ñ n n n ?',
507    'N'  => 'Ñ N N N',
508    'o'  => 'ò ó ô õ ö ø o o o o o ? ? ? ? ? ? ? ? ? ? ? ? ?',
509    'O'  => 'Ò Ó Ô Õ Ö Ø O O O O O ? ? ? ? ? ? ? ? ? ? ? ? ?',
510    'q'  => '?',
511    'r'  => 'r r r',
512    'R'  => 'R R R',
513    's'  => 's s s š ?',
514    'S'  => 'S S S Š',
515    'ss' => 'ß',
516    't'  => 't t t',
517    'T'  => 'T T T',
518    'u'  => 'ù ú û ü u u u u u u u u u u u u ? ? ? ? ? ? ?',
519    'U'  => 'Ù Ú Û Ü U U U U U U U U U U U U ? ? ? ? ? ? ?',
520    'w'  => 'w ? ? ?',
521    'W'  => 'W ? ? ?',
522    'y'  => 'ý ÿ ? ? ? ? y',
523    'Y'  => 'Ý Ÿ ? ? ? ? Y',
524    'z'  => 'z z ž',
525    'Z'  => 'Z Z Ž',
526    'ae' => '?',
527    'AE' => '?',
528    'ij' => '?',
529    'IJ' => '?',
530    'oe' => 'œ',
531    'OE' => 'Œ',
532   
533  // Greek
534   
535    'a'  => '?',
536    '?'  => '?',
537    'e'  => '?',
538    '?'  => '?',
539    'µ'  => 'µ',
540    '?'  => '?',
541    '?'  => '?',
542    '?'  => '? ? ?',
543    '?'  => '? ?',
544    '?'  => '?',
545    '?'  => '?',
546    's'  => '?',
547    '?'  => '? ? ?',
548    '?'  => '? ?',
549    '?'  => '?',
550    'O'  => '?',
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_accentSensitive_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_accentSensitive_Text']) and $fcke_config['LCAS_accentSensitive_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// Tri les doublons
810function CompareTransformedUser($a, $b)
811{
812        return strcmp($a['transformed'], $b['transformed']);
813}
814
815// Fonctionnel mais optimisable
816function LCAS_GetDuplicates($source) {
817        $users      = array();
818        $duplicates = array();
819       
820        // Liste des utilisateurs uniques
821        foreach($source as $user) {
822                if (isset($users[$user['transformed']])) {
823                        $users[$user['transformed']] += 1;
824                }
825                else {
826                        $users[$user['transformed']] = 1;
827                }
828        }
829       
830        // On récupère les doublons
831        foreach($source as $user) {
832                if ($users[$user['transformed']] > 1) {
833                        array_push($duplicates, $user);
834                }
835        }
836       
837        // Trier le tableau
838        usort($duplicates, 'CompareTransformedUser');
839       
840        return $duplicates;
841}
842
843/* Get all users to display the number of days since their last visit */
844function LCAS_get_user_list($rule)
845{
846        global $conf, $page;
847 
848  $users = array();
849
850        /* search users depending expiration date */
851  $query = '
852SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
853                u.'.$conf['user_fields']['username'].' AS username,
854                u.'.$conf['user_fields']['email'].' AS email
855FROM '.USERS_TABLE.' AS u
856;';
857
858        $result = pwg_query($query);
859     
860  while ($row = pwg_db_fetch_assoc($result))
861  {
862        $user = $row;
863        $user['transformed'] = LCAS_change_case($user['username'], $rule); 
864    array_push($users, $user);
865        }
866
867        return LCAS_GetDuplicates($users);
868}
869
870function LCAS_clean_obsolete_files()
871{
872  if (file_exists(LCAS_PATH.'obsolete.list')
873    and $old_files = file(LCAS_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES)
874    and !empty($old_files))
875  {
876    array_push($old_files, 'obsolete.list');
877    foreach($old_files as $old_file)
878    {
879      $path = LCAS_PATH.$old_file;
880      if (is_file($path))
881      {
882        @unlink($path);
883      }
884    }
885  }
886}
887
888?>
Note: See TracBrowser for help on using the repository browser.