source: trunk/wtorrent/lib/inc/string.inc.php @ 93

Revision 93, 4.8 KB checked in by royger, 2 years ago (diff)
  • Migrated database from sqlite 2 to sqlite 3.
  • From now on, you will need php to be compiled with PDO and sqlite to run wTorrent.
  • Applied patch from tn123 to migrate to PDO and use prepared statements (ticket #188).
  • Created new install script.
  • To apply this update you will need to run sqlite_migration.sh to migrate your old database to sqlite3. This script assumes you have your database in db/database.db, if that's not the case edit the script and change the path.
Line 
1<?php
2/*
3This file is part of wTorrent.
4
5wTorrent is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 3 of the License, or
8(at your option) any later version.
9
10wTorrent is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18Class done by David Marco Martinez
19*/
20/**
21 * Verifica si un string esta codificado en UTF-8
22 *
23 * @param string $str
24 * @return bool
25 */
26function is_UTF8( $str )
27{
28        return preg_match( '%(?:
29                [\xC2-\xDF][\x80-\xBF]                          # non-overlong 2-byte
30                |\xE0[\xA0-\xBF][\x80-\xBF]                     # excluding overlongs
31                |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}      # straight 3-byte
32                |\xED[\x80-\x9F][\x80-\xBF]                     # excluding surrogates
33                |\xF0[\x90-\xBF][\x80-\xBF]{2}          # planes 1-3
34                |[\xF1-\xF3][\x80-\xBF]{3}                      # planes 4-15
35                |\xF4[\x80-\x8F][\x80-\xBF]{2}          # plane 16
36                )+%xs', $str );
37}
38
39function _unescape_internal($var)
40{
41        switch (gettype($var)) {
42        case 'array':
43                return array_map('_unescape_internal', $var);
44        case 'string':
45                return stripslashes($var);
46        default:
47                return $var;
48        }
49}
50function unescape( $var )
51{
52        if (!get_magic_quotes_gpc())
53        {
54                return;
55        }
56        return _unescape_internal($var);
57}
58function html( $str )
59{
60        $str = str_replace( array( 'ñ', 'Ñ' ), array( '&ntilde;', '&Ntilde;' ), $str );
61        return preg_replace( '/[^\x00-\x7F]/e', '"&#".ord("$0").";"', $str );
62
63        return str_replace( array_keys( getHtmlChars( ) ), getHtmlChars( ), $str );
64}
65
66function getHtmlChars( )
67{
68        return array(
69        '!' => '&#33;',
70        '"' => '&quot;',
71        '#' => '&#35;',
72        '$' => '&#36;',
73        '%' => '&#37;',
74        '&' => '&amp;',
75        '\'' => '&#39;',
76        '(' => '&#40;',
77        ')' => '&#41;',
78        '*' => '&#42;',
79        '+' => '&#43;',
80        ',' => '&#44;',
81        '-' => '&#45;',
82        '.' => '&#46;',
83        '/' => '&#47;',
84        ':' => '&#58;',
85        ';' => '&#59;',
86        '<' => '&lt;',
87        '=' => '&#61;',
88        '>' => '&gt;',
89        '?' => '&#63;',
90        '@' => '&#64;',
91        '[' => '&#91;',
92        '\\' => '&#92;',
93        ']' => '&#93;',
94        '^' => '&#94;',
95        '_' => '&#95;',
96        '`' => '&#96;',
97        '{' => '&#123;',
98        '|' => '&#124;',
99        '}' => '&#125;',
100        '~' => '&#126;',
101        '€' => '&#128;',
102        '‚' => '&#130;',
103        'Œ' => '&#140;',
104        'Ž' => '&#142;',
105        '‘' => '&#145;',
106        '’' => '&#146;',
107        '“' => '&#147;',
108        '”' => '&#148;',
109        '•' => '&#149;',
110        '–' => '&#150;',
111        '—' => '&#151;',
112        '˜' => '&#152;',
113        '™' => '&#153;',
114        'š' => '&#154;',
115        '›' => '&#155;',
116        'œ' => '&#156;',
117        'Ÿ' => '&#159;',
118        '¡' => '&iexcl;',
119        '¢' => '&cent;',
120        '£' => '&pound;',
121        '¤' => '&curren;',
122        '¥' => '&yen;',
123        '¦' => '&brvbar;',
124        '§' => '&sect;',
125        '¨' => '&uml;',
126        '©' => '&copy;',
127        'ª' => '&ordf;',
128        '«' => '&laquo;',
129        '¬' => '&not;',
130        '­' => '&shy;',
131        '®' => '&reg;',
132        '¯' => '&macr;',
133        '°' => '&deg;',
134        '±' => '&plusmn;',
135        '²' => '&sup2;',
136        '³' => '&sup3;',
137        '´' => '&acute;',
138        'µ' => '&micro;',
139        '¶' => '&para;',
140        '·' => '&middot;',
141        '¸' => '&cedil;',
142        '¹' => '&sup1;',
143        'º' => '&ordm;',
144        '»' => '&raquo;',
145        '¼' => '&frac14;',
146        '½' => '&frac12;',
147        '¾' => '&frac34;',
148        '¿' => '&iquest;',
149        'À' => '&Agrave;',
150        'Á' => '&Aacute;',
151        'Â' => '&Acirc;',
152        'Ã' => '&Atilde;',
153        'Ä' => '&Auml;',
154        'Å' => '&Aring;',
155        'Æ' => '&AElig;',
156        'Ç' => '&Ccedil;',
157        'È' => '&Egrave;',
158        'É' => '&Eacute;',
159        'Ê' => '&Ecirc;',
160        'Ë' => '&Euml;',
161        'Ì' => '&Igrave;',
162        'Í' => '&Iacute;',
163        'Î' => '&Icirc;',
164        'Ï' => '&Iuml;',
165        'Ð' => '&ETH;',
166        'Ñ' => '&Ntilde;',
167        'Ò' => '&Ograve;',
168        'Ó' => '&Oacute;',
169        'Ô' => '&Ocirc;',
170        'Õ' => '&Otilde;',
171        'Ö' => '&Ouml;',
172        '×' => '&times;',
173        'Ø' => '&Oslash;',
174        'Ù' => '&Ugrave;',
175        'Ú' => '&Uacute;',
176        'Û' => '&Ucirc;',
177        'Ü' => '&Uuml;',
178        'Ý' => '&Yacute;',
179        'Þ' => '&THORN;',
180        'ß' => '&szlig;',
181        'à' => '&agrave;',
182        'á' => '&aacute;',
183        'â' => '&acirc;',
184        'ã' => '&atilde;',
185        'ä' => '&auml;',
186        'å' => '&aring;',
187        'æ' => '&aelig;',
188        'ç' => '&ccedil;',
189        'è' => '&egrave;',
190        'é' => '&eacute;',
191        'ê' => '&ecirc;',
192        'ë' => '&euml;',
193        'ì' => '&igrave;',
194        'í' => '&iacute;',
195        'î' => '&icirc;',
196        'ï' => '&iuml;',
197        'ð' => '&eth;',
198        'ñ' => '&ntilde;',
199        'ò' => '&ograve;',
200        'ó' => '&oacute;',
201        'ô' => '&ocirc;',
202        'õ' => '&otilde;',
203        'ö' => '&ouml;',
204        '÷' => '&divide;',
205        'ø' => '&oslash;',
206        'ù' => '&ugrave;',
207        'ú' => '&uacute;',
208        'û' => '&ucirc;',
209        'ü' => '&uuml;',
210        'ý' => '&yacute;',
211        'þ' => '&thorn;',
212        'ÿ' => '&yuml;',
213        'Œ' => '&OElig;',
214        'œ' => '&oelig;',
215        'Š' => '&Scaron;',
216        'š' => '&scaron;',
217        'Ÿ' => '&Yuml;',
218        'ˆ' => '&circ;',
219        '˜' => '&tilde;',
220        '–' => '&ndash;',
221        '—' => '&mdash;',
222        '‘' => '&lsquo;',
223        '’' => '&rsquo;',
224        '‚' => '&sbquo;',
225        '“' => '&ldquo;',
226        '”' => '&rdquo;',
227        '„' => '&bdquo;',
228        '†' => '&dagger;',
229        '‡' => '&Dagger;',
230        '‰' => '&permil;',
231        '‹' => '&lsaquo;',
232        '›' => '&rsaquo;' );
233}
234?>
Note: See TracBrowser for help on using the repository browser.