| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 Polytechnique.org * |
| 4 | * http://opensource.polytechnique.org/ * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., * |
| 19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | function quoted_printable_encode($input, $line_max = 76) { |
| 23 | $lines = preg_split("/(?:\r\n|\r|\n)/", $input); |
| 24 | $eol = "\n"; |
| 25 | $linebreak = "=0D=0A=\n "; |
| 26 | $escape = "="; |
| 27 | $output = ""; |
| 28 | |
| 29 | foreach ($lines as $j => $line) { |
| 30 | $linlen = strlen($line); |
| 31 | $newline = ""; |
| 32 | for($i = 0; $i < $linlen; $i++) { |
| 33 | $c = $line{$i}; |
| 34 | $dec = ord($c); |
| 35 | if ( ($dec == 32) && ($i == ($linlen - 1)) ) { |
| 36 | // convert space at eol only |
| 37 | $c = "=20"; |
| 38 | } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { |
| 39 | // always encode "\t", which is *not* required |
| 40 | $c = $escape.strtoupper(sprintf("%02x",$dec)); |
| 41 | } |
| 42 | if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
| 43 | $output .= $newline.$escape.$eol; |
| 44 | $newline = " "; |
| 45 | } |
| 46 | $newline .= $c; |
| 47 | } // end of for |
| 48 | $output .= $newline; |
| 49 | if ($j<count($lines)-1) $output .= $linebreak; |
| 50 | } |
| 51 | return trim($output); |
| 52 | } |
| 53 | |
| 54 | /** vérifie si une adresse email convient comme adresse de redirection |
| 55 | * @param $email l'adresse email a verifier |
| 56 | * @return BOOL |
| 57 | */ |
| 58 | function isvalid_email_redirection($email) { |
| 59 | return isvalid_email($email) && |
| 60 | !preg_match("/@(polytechnique\.(org|edu)|melix\.(org|net)|m4x\.org)$/", $email); |
| 61 | } |
| 62 | |
| 63 | /* Un soundex en français posté par Frédéric Bouchery |
| 64 | Voici une adaptation en PHP de la fonction soundex2 francisée de Frédéric BROUARD (http://sqlpro.developpez.com/Soundex/). |
| 65 | C'est une bonne démonstration de la force des expressions régulières compatible Perl. |
| 66 | trouvé sur http://expreg.com/voirsource.php?id=40&type=Chaines%20de%20caract%E8res */ |
| 67 | function soundex_fr($sIn) |
| 68 | { |
| 69 | // Si il n'y a pas de mot, on sort immédiatement |
| 70 | if ( $sIn === '' ) return ' '; |
| 71 | // On met tout en minuscule |
| 72 | $sIn = strtoupper( $sIn ); |
| 73 | // On supprime les accents |
| 74 | $sIn = strtr( $sIn, '\ 0ÀÇÈÉÊ˼ÎÏÔÖÙÛÜ', 'AAASEEEEEIIOOUUU' ); |
| 75 | // On supprime tout ce qui n'est pas une lettre |
| 76 | $sIn = preg_replace( '`[^A-Z]`', '', $sIn ); |
| 77 | // Si la chaîne ne fait qu'un seul caractère, on sort avec. |
| 78 | if ( strlen( $sIn ) === 1 ) return $sIn . ' '; |
| 79 | // on remplace les consonnances primaires |
| 80 | $convIn = array( 'GUI', 'GUE', 'GA', 'GO', 'GU', 'CA', 'CO', 'CU', 'Q', 'CC', 'CK' ); |
| 81 | $convOut = array( 'KI', 'KE', 'KA', 'KO', 'K', 'KA', 'KO', 'KU', 'K', 'K', 'K' ); |
| 82 | $sIn = str_replace( $convIn, $convOut, $sIn ); |
| 83 | // on remplace les voyelles sauf le Y et sauf la première par A |
| 84 | $sIn = preg_replace( '`(?<!^)[EIOU]`', 'A', $sIn ); |
| 85 | // on remplace les préfixes puis on conserve la première lettre |
| 86 | // et on fait les remplacements complémentaires |
| 87 | $convIn = array( '`^KN`', '`^(PH|PF)`', '`^MAC`', '`^SCH`', '`^ASA`', '`(?<!^)KN`', '`(?<!^)(PH|PF)`', '`(?<!^)MAC`', '`(?<!^)SCH`', '`(?<!^)ASA`' ); |
| 88 | $convOut = array( 'NN', 'FF', 'MCC', 'SSS', 'AZA', 'NN', 'FF', 'MCC', 'SSS', 'AZA' ); |
| 89 | $sIn = preg_replace( $convIn, $convOut, $sIn ); |
| 90 | // suppression des H sauf CH ou SH |
| 91 | $sIn = preg_replace( '`(?<![CS])H`', '', $sIn ); |
| 92 | // suppression des Y sauf précédés d'un A |
| 93 | $sIn = preg_replace( '`(?<!A)Y`', '', $sIn ); |
| 94 | // on supprime les terminaisons A, T, D, S |
| 95 | $sIn = preg_replace( '`[ATDS]$`', '', $sIn ); |
| 96 | // suppression de tous les A sauf en tête |
| 97 | $sIn = preg_replace( '`(?!^)A`', '', $sIn ); |
| 98 | // on supprime les lettres répétitives |
| 99 | $sIn = preg_replace( '`(.)\1`', '$1', $sIn ); |
| 100 | // on ne retient que 4 caractères ou on complète avec des blancs |
| 101 | return substr( $sIn . ' ', 0, 4); |
| 102 | } |
| 103 | |
| 104 | function make_forlife($prenom,$nom,$promo) { |
| 105 | $prenomUS = replace_accent(trim($prenom)); |
| 106 | $nomUS = replace_accent(trim($nom)); |
| 107 | |
| 108 | $forlife = strtolower($prenomUS.".".$nomUS.".".$promo); |
| 109 | $forlife = str_replace(" ","-",$forlife); |
| 110 | $forlife = str_replace("'","",$forlife); |
| 111 | return $forlife; |
| 112 | } |
| 113 | ?> |