| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /*************************************************************************** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  *  For license information see doc/license.txt | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  *  Unicode Reminder メモ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  ***************************************************************************/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * RFC(2)822 Email Parser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * By Cal Henderson <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * This code is licensed under a Creative Commons Attribution-ShareAlike 2.5 License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * http://creativecommons.org/licenses/by-sa/2.5/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Revision 4 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | function is_valid_email_address($email) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * NO-WS-CTL       =       %d1-8 /         ; US-ASCII control characters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      *                         %d11 /          ;  that do not include the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      *                         %d12 /          ;  carriage return, line feed, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      *                         %d14-31 /       ;  and white space characters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      *                         %d127 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * ALPHA          =  %x41-5A / %x61-7A   ; A-Z / a-z | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * DIGIT          =  %x30-39 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     $no_ws_ctl = "[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     $alpha = "[\\x41-\\x5a\\x61-\\x7a]"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     $digit = "[\\x30-\\x39]"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     $cr = "\\x0d"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     $lf = "\\x0a"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     $crlf = "($cr$lf)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      *obs-char        =       %d0-9 / %d11 /          ; %d0-127 except CR and | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      *                         %d12 / %d14-127         ;  LF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * obs-text        =       *LF *CR *(obs-char *LF *CR) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * text            =       %d1-9 /         ; Characters excluding CR and LF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      *                         %d11 / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      *                         %d12 / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      *                         %d14-127 / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      *                         obs-text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * obs-qp          =       "\" (%d0-127) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * quoted-pair     =       ("\" text) / obs-qp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     $obs_char = "[\\x00-\\x09\\x0b\\x0c\\x0e-\\x7f]"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     $obs_text = "($lf*$cr*($obs_char$lf*$cr*)*)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     $text = "([\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f]|$obs_text)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     $obs_qp = "(\\x5c[\\x00-\\x7f])"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     $quoted_pair = "(\\x5c$text|$obs_qp)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * obs-FWS         =       1*WSP *(CRLF 1*WSP) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * FWS             =       ([*WSP CRLF] 1*WSP) /   ; Folding white space | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      *                         obs-FWS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * ctext           =       NO-WS-CTL /     ; Non white space controls | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      *                         %d33-39 /       ; The rest of the US-ASCII | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      *                         %d42-91 /       ;  characters not including "(", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      *                         %d93-126        ;  ")", or "\" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * ccontent        =       ctext / quoted-pair / comment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * comment         =       "(" *([FWS] ccontent) [FWS] ")" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * CFWS            =       *([FWS] comment) (([FWS] comment) / FWS) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * note: we translate ccontent only partially to avoid an infinite loop | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * instead, we'll recursively strip comments before processing the input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     $wsp = "[\\x20\\x09]"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     $obs_fws = "($wsp+($crlf$wsp+)*)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     $fws = "((($wsp*$crlf)?$wsp+)|$obs_fws)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     $ctext = "($no_ws_ctl|[\\x21-\\x27\\x2A-\\x5b\\x5d-\\x7e])"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     $ccontent = "($ctext|$quoted_pair)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     $comment = "(\\x28($fws?$ccontent)*$fws?\\x29)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     $cfws = "(($fws?$comment)*($fws?$comment|$fws))"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     $cfws = "$fws*"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * atext           =       ALPHA / DIGIT / ; Any character except controls, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      *                         "!" / "#" /     ;  SP, and specials. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      *                         "$" / "%" /     ;  Used for atoms | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      *                         "&" / "'" / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      *                         "*" / "+" / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      *                         "-" / "/" / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      *                         "=" / "?" / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      *                         "^" / "_" / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      *                         "" / "{" / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      *                         "|" / "}" / | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      *                         "~" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * atom            =       [CFWS] 1*atext [CFWS] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     $atext = "($alpha|$digit|[\\x21\\x23-\\x27\\x2a\\x2b\\x2d\\x2e\\x3d\\x3f\\x5e\\x5f\\x60\\x7b-\\x7e])"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     $atom = "($cfws?$atext+$cfws?)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * qtext           =       NO-WS-CTL /     ; Non white space controls | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      *                         %d33 /          ; The rest of the US-ASCII | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      *                         %d35-91 /       ;  characters not including "\" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      *                         %d93-126        ;  or the quote character | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * qcontent        =       qtext / quoted-pair | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * quoted-string   =       [CFWS] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      *                         DQUOTE *([FWS] qcontent) [FWS] DQUOTE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      *                         [CFWS] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * word            =       atom / quoted-string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     $qtext = "($no_ws_ctl|[\\x21\\x23-\\x5b\\x5d-\\x7e])"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     $qcontent = "($qtext|$quoted_pair)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     $quoted_string = "($cfws?\\x22($fws?$qcontent)*$fws?\\x22$cfws?)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     $word = "($atom|$quoted_string)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * obs-local-part  =       word *("." word) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * obs-domain      =       atom *("." atom) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     $obs_local_part = "($word(\\x2e$word)*)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     $obs_domain = "($atom(\\x2e$atom)*)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      * dot-atom-text   =       1*atext *("." 1*atext) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      * dot-atom        =       [CFWS] dot-atom-text [CFWS] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     $dot_atom_text = "($atext+(\\x2e$atext+)*)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     $dot_atom = "($cfws?$dot_atom_text$cfws?)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * domain-literal  =       [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * dcontent        =       dtext / quoted-pair | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * dtext           =       NO-WS-CTL /     ; Non white space controls | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      *                         %d33-90 /       ; The rest of the US-ASCII | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      *                         %d94-126        ;  characters not including "[", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      *                                         ;  "]", or "\" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     $dtext = "($no_ws_ctl|[\\x21-\\x5a\\x5e-\\x7e])"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     $dcontent = "($dtext|$quoted_pair)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     $domain_literal = "($cfws?\\x5b($fws?$dcontent)*$fws?\\x5d$cfws?)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * local-part      =       dot-atom / quoted-string / obs-local-part | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * domain          =       dot-atom / domain-literal / obs-domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * addr-spec       =       local-part "@" domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     $local_part = "($dot_atom|$quoted_string|$obs_local_part)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     $domain = "($dot_atom|$domain_literal|$obs_domain)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     $addr_spec = "($local_part\\x40$domain)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * we need to strip comments first (repeat until we can't find any more) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     $done = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     while (!$done) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         $new = preg_replace("!$comment!", '', $email); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         if (strlen($new) == strlen($email)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |             $done = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         $email = $new; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      * now match what's left | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     return preg_match("!^$addr_spec$!", $email) ? 1 : 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 197 |  | View Code Duplication | function mb_trim($str) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     $bLoop = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |     while ($bLoop == true) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         $sPos = mb_substr($str, 0, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         if ($sPos == ' ' || $sPos == "\r" || $sPos == "\n" || $sPos == "\t" || $sPos == "\x0B" || $sPos == "\0") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |             $str = mb_substr($str, 1, mb_strlen($str) - 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |             $bLoop = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |     $bLoop = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |     while ($bLoop == true) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         $sPos = mb_substr($str, - 1, 1); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         if ($sPos == ' ' || $sPos == "\r" || $sPos == "\n" || $sPos == "\t" || $sPos == "\x0B" || $sPos == "\0") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |             $str = mb_substr($str, 0, mb_strlen($str) - 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |             $bLoop = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |     return $str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 224 |  |  | // explode with more than one separator | 
            
                                                                        
                            
            
                                    
            
            
                | 225 |  |  | function explode_multi($str, $sep) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 226 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 227 |  |  |     $ret = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 228 |  |  |     $nCurPos = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 230 |  |  |     while ($nCurPos < mb_strlen($str)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 231 |  |  |         $nNextSep = mb_strlen($str); | 
            
                                                                        
                            
            
                                    
            
            
                | 232 |  |  |         for ($nSepPos = 0; $nSepPos < mb_strlen($sep); $nSepPos ++) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 233 |  |  |             $nThisPos = mb_strpos($str, mb_substr($sep, $nSepPos, 1), $nCurPos); | 
            
                                                                        
                            
            
                                    
            
            
                | 234 |  |  |             if ($nThisPos !== false) { | 
            
                                                                        
                            
            
                                    
            
            
                | 235 |  |  |                 if ($nNextSep > $nThisPos) { | 
            
                                                                        
                            
            
                                    
            
            
                | 236 |  |  |                     $nNextSep = $nThisPos; | 
            
                                                                        
                            
            
                                    
            
            
                | 237 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 238 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 239 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 240 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 241 |  |  |         $ret[] = mb_substr($str, $nCurPos, $nNextSep - $nCurPos); | 
            
                                                                        
                            
            
                                    
            
            
                | 242 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 243 |  |  |         $nCurPos = $nNextSep + 1; | 
            
                                                                        
                            
            
                                    
            
            
                | 244 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 245 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 246 |  |  |     return $ret; | 
            
                                                                        
                            
            
                                    
            
            
                | 247 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | function getSysConfig($name, $default) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |     return sql_value("SELECT `value` FROM `sysconfig` WHERE `name`='&1'", $default, $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | function setSysConfig($name, $value) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |     sql( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |         "INSERT INTO `sysconfig` (`name`, `value`) VALUES ('&1', '&2') ON DUPLICATE KEY UPDATE `value`='&2'", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         $name, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | function read_file($filename, $maxlength) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |     $content = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |     $f = fopen($filename, 'r'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     if ($f === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |     while ($line = fread($f, 4096)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         $content .= $line; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |     fclose($f); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |     return $content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | // encodes &<>"' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | function xmlentities($str) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |     return htmlspecialchars(xmlfilterevilchars($str), ENT_QUOTES, 'UTF-8'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  | // encodes &<> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  | // This is ok for XML content text between tags, but not for XML attribute contents. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  | function text_xmlentities($str) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |     return htmlspecialchars(xmlfilterevilchars($str), ENT_NOQUOTES, 'UTF-8'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | function xmlfilterevilchars($str) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |     // the same for for ISO-8859-1 and UTF-8 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |     // following 2016-3-1: allowed Tabs (\x{09}) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |     return mb_ereg_replace('[\x{00}-\x{08}\x{0B}\x{0C}\x{0E}-\x{1F}]*', '', $str); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  | // decimal longitude to string E/W hhh°mm.mmm | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 302 |  | View Code Duplication | function help_lonToDegreeStr($lon) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |     if ($lon < 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |         $retval = 'W '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |         $lon = - $lon; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |         $retval = 'E '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |     $retval = $retval . sprintf("%03d", floor($lon)) . '° '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |     $lon = $lon - floor($lon); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |     $retval = $retval . sprintf("%06.3f", round($lon * 60, 3)) . '\''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |     return $retval; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  | // decimal latitude to string N/S hh°mm.mmm | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 319 |  | View Code Duplication | function help_latToDegreeStr($lat) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |     if ($lat < 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |         $retval = 'S '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |         $lat = - $lat; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |         $retval = 'N '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |     $retval = $retval . sprintf("%02d", floor($lat)) . '° '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |     $lat = $lat - floor($lat); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |     $retval = $retval . sprintf("%06.3f", round($lat * 60, 3)) . '\''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |     return $retval; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  | function escape_javascript($text) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |     return str_replace('\'', '\\\'', str_replace('"', '"', $text)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  | // perform str_rot13 without renaming parts in [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  | function str_rot13_gc($str) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |     $delimiter[0][0] = '['; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |     $delimiter[0][1] = ']'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |     $retval = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 350 |  | View Code Duplication |     while (mb_strlen($retval) < mb_strlen($str)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |         $nNextStart = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |         $sNextEndChar = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |         foreach ($delimiter as $del) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |             $nThisStart = mb_strpos($str, $del[0], mb_strlen($retval)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |             if ($nThisStart !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |                 if (($nNextStart > $nThisStart) || ($nNextStart === false)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |                     $nNextStart = $nThisStart; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |                     $sNextEndChar = $del[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |         if ($nNextStart === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |             $retval .= str_rot13(mb_substr($str, mb_strlen($retval), mb_strlen($str) - mb_strlen($retval))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |             // crypted part | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |             $retval .= str_rot13(mb_substr($str, mb_strlen($retval), $nNextStart - mb_strlen($retval))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |             // uncrypted part | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |             $nNextEnd = mb_strpos($str, $sNextEndChar, $nNextStart); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |             if ($nNextEnd === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |                 $retval .= mb_substr($str, $nNextStart, mb_strlen($str) - mb_strlen($retval)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |                 $retval .= mb_substr($str, $nNextStart, $nNextEnd - $nNextStart + 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |     return $retval; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  | // format number with 1000s dots | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  | function number1000($n) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |     global $opt; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |     if (isset($opt['locale'][$opt['template']['locale']]['format']['dot1000']) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |         $opt['locale'][$opt['template']['locale']]['format']['dot1000'] == ',' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |         return number_format($n); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |     } else { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |         return str_replace(',', '.', number_format($n)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 397 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 398 |  |  |  |