diff options
author | Nicolas Lœuillet <nicolas@loeuillet.org> | 2015-01-19 13:37:32 +0100 |
---|---|---|
committer | Nicolas Lœuillet <nicolas@loeuillet.org> | 2015-01-19 13:37:32 +0100 |
commit | 3d99ce9dadca82765832ab669dabc22c554fd78e (patch) | |
tree | e47e84483e03ccc289bf5768526dedacdff07add | |
parent | 99410a21eb261f50234cc4148323a52b345e15e1 (diff) | |
download | wallabag-3d99ce9dadca82765832ab669dabc22c554fd78e.tar.gz wallabag-3d99ce9dadca82765832ab669dabc22c554fd78e.tar.zst wallabag-3d99ce9dadca82765832ab669dabc22c554fd78e.zip |
travis configuration
31 files changed, 3 insertions, 4106 deletions
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..e74c4235 --- /dev/null +++ b/.travis.yml | |||
@@ -0,0 +1,3 @@ | |||
1 | branches: | ||
2 | only: | ||
3 | - refactor \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/CharacterEntities.php b/inc/3rdparty/libraries/MOBIClass/CharacterEntities.php deleted file mode 100644 index de896f87..00000000 --- a/inc/3rdparty/libraries/MOBIClass/CharacterEntities.php +++ /dev/null | |||
@@ -1,413 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of CharacterEntities | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class CharacterEntities { | ||
9 | public static function convert($str){ | ||
10 | //Assume the encoding is UTF-8 -> output is UTF-8 | ||
11 | return $str; | ||
12 | //return utf8_encode($str); | ||
13 | //Convert to CP1252 | ||
14 | list($from, $to) = CharacterEntities::generateTables(); | ||
15 | return str_replace($from, $to, $str); | ||
16 | } | ||
17 | |||
18 | private static function generateTables(){ | ||
19 | $from = array(); | ||
20 | $to = array(); | ||
21 | |||
22 | for($i = 0; $i < 256; $i++){ | ||
23 | $from[$i] = $to[$i] = chr($i); | ||
24 | } | ||
25 | |||
26 | $from[0x80] = "€"; | ||
27 | $from[0x82] = "‚"; | ||
28 | $from[0x83] = "ƒ"; | ||
29 | $from[0x84] = "„"; | ||
30 | $from[0x85] = "…"; | ||
31 | $from[0x86] = "†"; | ||
32 | $from[0x87] = "‡"; | ||
33 | $from[0x88] = "ˆ"; | ||
34 | $from[0x89] = "‰"; | ||
35 | $from[0x8A] = "Š"; | ||
36 | $from[0x8B] = "‹"; | ||
37 | $from[0x8C] = "Œ"; | ||
38 | $from[0x8E] = "Ž"; | ||
39 | |||
40 | $from[0x91] = "‘"; | ||
41 | $from[0x92] = "’"; | ||
42 | $from[0x93] = "“"; | ||
43 | $from[0x94] = "”"; | ||
44 | $from[0x95] = "•"; | ||
45 | $from[0x96] = "–"; | ||
46 | $from[0x97] = "—"; | ||
47 | $from[0x98] = "˜"; | ||
48 | $from[0x99] = "™"; | ||
49 | $from[0x9A] = "š"; | ||
50 | $from[0x9B] = "›"; | ||
51 | $from[0x9C] = "œ"; | ||
52 | $from[0x9E] = "ž"; | ||
53 | $from[0x9F] = "Ÿ"; | ||
54 | |||
55 | $from[0xA1] = "¡"; | ||
56 | $from[0xA2] = "¢"; | ||
57 | $from[0xA3] = "£"; | ||
58 | $from[0xA4] = "¤"; | ||
59 | $from[0xA5] = "¥"; | ||
60 | $from[0xA6] = "¦"; | ||
61 | $from[0xA7] = "§"; | ||
62 | $from[0xA8] = "¨"; | ||
63 | $from[0xA9] = "©"; | ||
64 | $from[0xAA] = "ª"; | ||
65 | $from[0xAB] = "«"; | ||
66 | $from[0xAC] = "¬"; | ||
67 | $from[0xAE] = "®"; | ||
68 | $from[0xAF] = "¯"; | ||
69 | |||
70 | $from[0xB0] = "°"; | ||
71 | $from[0xB1] = "±"; | ||
72 | $from[0xB2] = "²"; | ||
73 | $from[0xB3] = "³"; | ||
74 | $from[0xB4] = "´"; | ||
75 | $from[0xB5] = "µ"; | ||
76 | $from[0xB6] = "¶"; | ||
77 | $from[0xB7] = "·"; | ||
78 | $from[0xB8] = "¸"; | ||
79 | $from[0xB9] = "¹"; | ||
80 | $from[0xBA] = "º"; | ||
81 | $from[0xBB] = "»"; | ||
82 | $from[0xBC] = "¼"; | ||
83 | $from[0xBD] = "½"; | ||
84 | $from[0xBE] = "¾"; | ||
85 | $from[0xBF] = "¿"; | ||
86 | |||
87 | $from[0xC0] = "À"; | ||
88 | $from[0xC1] = "Á"; | ||
89 | $from[0xC2] = "Â"; | ||
90 | $from[0xC3] = "Ã"; | ||
91 | $from[0xC4] = "Ä"; | ||
92 | $from[0xC5] = "Å"; | ||
93 | $from[0xC6] = "Æ"; | ||
94 | $from[0xC7] = "Ç"; | ||
95 | $from[0xC8] = "È"; | ||
96 | $from[0xC9] = "É"; | ||
97 | $from[0xCA] = "Ê"; | ||
98 | $from[0xCB] = "Ë"; | ||
99 | $from[0xCC] = "Ì"; | ||
100 | $from[0xCD] = "Í"; | ||
101 | $from[0xCE] = "Î"; | ||
102 | $from[0xCF] = "Ï"; | ||
103 | |||
104 | $from[0xD0] = "Ð"; | ||
105 | $from[0xD1] = "Ñ"; | ||
106 | $from[0xD2] = "Ò"; | ||
107 | $from[0xD3] = "Ó"; | ||
108 | $from[0xD4] = "Ô"; | ||
109 | $from[0xD5] = "Õ"; | ||
110 | $from[0xD6] = "Ö"; | ||
111 | $from[0xD7] = "×"; | ||
112 | $from[0xD8] = "Ø"; | ||
113 | $from[0xD9] = "Ù"; | ||
114 | $from[0xDA] = "Ú"; | ||
115 | $from[0xDB] = "Û"; | ||
116 | $from[0xDC] = "Ü"; | ||
117 | $from[0xDD] = "Ý"; | ||
118 | $from[0xDE] = "Þ"; | ||
119 | $from[0xDF] = "ß"; | ||
120 | |||
121 | $from[0xE0] = "à"; | ||
122 | $from[0xE1] = "á"; | ||
123 | $from[0xE2] = "â"; | ||
124 | $from[0xE3] = "ã"; | ||
125 | $from[0xE4] = "ä"; | ||
126 | $from[0xE5] = "å"; | ||
127 | $from[0xE6] = "æ"; | ||
128 | $from[0xE7] = "ç"; | ||
129 | $from[0xE8] = "è"; | ||
130 | $from[0xE9] = "é"; | ||
131 | $from[0xEA] = "ê"; | ||
132 | $from[0xEB] = "ë"; | ||
133 | $from[0xEC] = "ì"; | ||
134 | $from[0xED] = "í"; | ||
135 | $from[0xEE] = "î"; | ||
136 | $from[0xEF] = "ï"; | ||
137 | |||
138 | $from[0xF0] = "ð"; | ||
139 | $from[0xF1] = "ñ"; | ||
140 | $from[0xF2] = "ò"; | ||
141 | $from[0xF3] = "ó"; | ||
142 | $from[0xF4] = "ô"; | ||
143 | $from[0xF5] = "õ"; | ||
144 | $from[0xF6] = "ö"; | ||
145 | $from[0xF7] = "÷"; | ||
146 | $from[0xF8] = "ø"; | ||
147 | $from[0xF9] = "ù"; | ||
148 | $from[0xFA] = "ú"; | ||
149 | $from[0xFB] = "û"; | ||
150 | $from[0xFC] = "ü"; | ||
151 | $from[0xFD] = "ý"; | ||
152 | $from[0xFE] = "þ"; | ||
153 | $from[0xFF] = "ÿ"; | ||
154 | |||
155 | |||
156 | return array($from, $to); | ||
157 | } | ||
158 | /* | ||
159 | 00 = U+0000 : NULL | ||
160 | 01 = U+0001 : START OF HEADING | ||
161 | 02 = U+0002 : START OF TEXT | ||
162 | 03 = U+0003 : END OF TEXT | ||
163 | 04 = U+0004 : END OF TRANSMISSION | ||
164 | 05 = U+0005 : ENQUIRY | ||
165 | 06 = U+0006 : ACKNOWLEDGE | ||
166 | 07 = U+0007 : BELL | ||
167 | 08 = U+0008 : BACKSPACE | ||
168 | 09 = U+0009 : HORIZONTAL TABULATION | ||
169 | 0A = U+000A : LINE FEED | ||
170 | 0B = U+000B : VERTICAL TABULATION | ||
171 | 0C = U+000C : FORM FEED | ||
172 | 0D = U+000D : CARRIAGE RETURN | ||
173 | 0E = U+000E : SHIFT OUT | ||
174 | 0F = U+000F : SHIFT IN | ||
175 | 10 = U+0010 : DATA LINK ESCAPE | ||
176 | 11 = U+0011 : DEVICE CONTROL ONE | ||
177 | 12 = U+0012 : DEVICE CONTROL TWO | ||
178 | 13 = U+0013 : DEVICE CONTROL THREE | ||
179 | 14 = U+0014 : DEVICE CONTROL FOUR | ||
180 | 15 = U+0015 : NEGATIVE ACKNOWLEDGE | ||
181 | 16 = U+0016 : SYNCHRONOUS IDLE | ||
182 | 17 = U+0017 : END OF TRANSMISSION BLOCK | ||
183 | 18 = U+0018 : CANCEL | ||
184 | 19 = U+0019 : END OF MEDIUM | ||
185 | 1A = U+001A : SUBSTITUTE | ||
186 | 1B = U+001B : ESCAPE | ||
187 | 1C = U+001C : FILE SEPARATOR | ||
188 | 1D = U+001D : GROUP SEPARATOR | ||
189 | 1E = U+001E : RECORD SEPARATOR | ||
190 | 1F = U+001F : UNIT SEPARATOR | ||
191 | 20 = U+0020 : SPACE | ||
192 | 21 = U+0021 : EXCLAMATION MARK | ||
193 | 22 = U+0022 : QUOTATION MARK | ||
194 | 23 = U+0023 : NUMBER SIGN | ||
195 | 24 = U+0024 : DOLLAR SIGN | ||
196 | 25 = U+0025 : PERCENT SIGN | ||
197 | 26 = U+0026 : AMPERSAND | ||
198 | 27 = U+0027 : APOSTROPHE | ||
199 | 28 = U+0028 : LEFT PARENTHESIS | ||
200 | 29 = U+0029 : RIGHT PARENTHESIS | ||
201 | 2A = U+002A : ASTERISK | ||
202 | 2B = U+002B : PLUS SIGN | ||
203 | 2C = U+002C : COMMA | ||
204 | 2D = U+002D : HYPHEN-MINUS | ||
205 | 2E = U+002E : FULL STOP | ||
206 | 2F = U+002F : SOLIDUS | ||
207 | 30 = U+0030 : DIGIT ZERO | ||
208 | 31 = U+0031 : DIGIT ONE | ||
209 | 32 = U+0032 : DIGIT TWO | ||
210 | 33 = U+0033 : DIGIT THREE | ||
211 | 34 = U+0034 : DIGIT FOUR | ||
212 | 35 = U+0035 : DIGIT FIVE | ||
213 | 36 = U+0036 : DIGIT SIX | ||
214 | 37 = U+0037 : DIGIT SEVEN | ||
215 | 38 = U+0038 : DIGIT EIGHT | ||
216 | 39 = U+0039 : DIGIT NINE | ||
217 | 3A = U+003A : COLON | ||
218 | 3B = U+003B : SEMICOLON | ||
219 | 3C = U+003C : LESS-THAN SIGN | ||
220 | 3D = U+003D : EQUALS SIGN | ||
221 | 3E = U+003E : GREATER-THAN SIGN | ||
222 | 3F = U+003F : QUESTION MARK | ||
223 | 40 = U+0040 : COMMERCIAL AT | ||
224 | 41 = U+0041 : LATIN CAPITAL LETTER A | ||
225 | 42 = U+0042 : LATIN CAPITAL LETTER B | ||
226 | 43 = U+0043 : LATIN CAPITAL LETTER C | ||
227 | 44 = U+0044 : LATIN CAPITAL LETTER D | ||
228 | 45 = U+0045 : LATIN CAPITAL LETTER E | ||
229 | 46 = U+0046 : LATIN CAPITAL LETTER F | ||
230 | 47 = U+0047 : LATIN CAPITAL LETTER G | ||
231 | 48 = U+0048 : LATIN CAPITAL LETTER H | ||
232 | 49 = U+0049 : LATIN CAPITAL LETTER I | ||
233 | 4A = U+004A : LATIN CAPITAL LETTER J | ||
234 | 4B = U+004B : LATIN CAPITAL LETTER K | ||
235 | 4C = U+004C : LATIN CAPITAL LETTER L | ||
236 | 4D = U+004D : LATIN CAPITAL LETTER M | ||
237 | 4E = U+004E : LATIN CAPITAL LETTER N | ||
238 | 4F = U+004F : LATIN CAPITAL LETTER O | ||
239 | 50 = U+0050 : LATIN CAPITAL LETTER P | ||
240 | 51 = U+0051 : LATIN CAPITAL LETTER Q | ||
241 | 52 = U+0052 : LATIN CAPITAL LETTER R | ||
242 | 53 = U+0053 : LATIN CAPITAL LETTER S | ||
243 | 54 = U+0054 : LATIN CAPITAL LETTER T | ||
244 | 55 = U+0055 : LATIN CAPITAL LETTER U | ||
245 | 56 = U+0056 : LATIN CAPITAL LETTER V | ||
246 | 57 = U+0057 : LATIN CAPITAL LETTER W | ||
247 | 58 = U+0058 : LATIN CAPITAL LETTER X | ||
248 | 59 = U+0059 : LATIN CAPITAL LETTER Y | ||
249 | 5A = U+005A : LATIN CAPITAL LETTER Z | ||
250 | 5B = U+005B : LEFT SQUARE BRACKET | ||
251 | 5C = U+005C : REVERSE SOLIDUS | ||
252 | 5D = U+005D : RIGHT SQUARE BRACKET | ||
253 | 5E = U+005E : CIRCUMFLEX ACCENT | ||
254 | 5F = U+005F : LOW LINE | ||
255 | 60 = U+0060 : GRAVE ACCENT | ||
256 | 61 = U+0061 : LATIN SMALL LETTER A | ||
257 | 62 = U+0062 : LATIN SMALL LETTER B | ||
258 | 63 = U+0063 : LATIN SMALL LETTER C | ||
259 | 64 = U+0064 : LATIN SMALL LETTER D | ||
260 | 65 = U+0065 : LATIN SMALL LETTER E | ||
261 | 66 = U+0066 : LATIN SMALL LETTER F | ||
262 | 67 = U+0067 : LATIN SMALL LETTER G | ||
263 | 68 = U+0068 : LATIN SMALL LETTER H | ||
264 | 69 = U+0069 : LATIN SMALL LETTER I | ||
265 | 6A = U+006A : LATIN SMALL LETTER J | ||
266 | 6B = U+006B : LATIN SMALL LETTER K | ||
267 | 6C = U+006C : LATIN SMALL LETTER L | ||
268 | 6D = U+006D : LATIN SMALL LETTER M | ||
269 | 6E = U+006E : LATIN SMALL LETTER N | ||
270 | 6F = U+006F : LATIN SMALL LETTER O | ||
271 | 70 = U+0070 : LATIN SMALL LETTER P | ||
272 | 71 = U+0071 : LATIN SMALL LETTER Q | ||
273 | 72 = U+0072 : LATIN SMALL LETTER R | ||
274 | 73 = U+0073 : LATIN SMALL LETTER S | ||
275 | 74 = U+0074 : LATIN SMALL LETTER T | ||
276 | 75 = U+0075 : LATIN SMALL LETTER U | ||
277 | 76 = U+0076 : LATIN SMALL LETTER V | ||
278 | 77 = U+0077 : LATIN SMALL LETTER W | ||
279 | 78 = U+0078 : LATIN SMALL LETTER X | ||
280 | 79 = U+0079 : LATIN SMALL LETTER Y | ||
281 | 7A = U+007A : LATIN SMALL LETTER Z | ||
282 | 7B = U+007B : LEFT CURLY BRACKET | ||
283 | 7C = U+007C : VERTICAL LINE | ||
284 | 7D = U+007D : RIGHT CURLY BRACKET | ||
285 | 7E = U+007E : TILDE | ||
286 | 7F = U+007F : DELETE | ||
287 | 80 = U+20AC : EURO SIGN | ||
288 | 82 = U+201A : SINGLE LOW-9 QUOTATION MARK | ||
289 | 83 = U+0192 : LATIN SMALL LETTER F WITH HOOK | ||
290 | 84 = U+201E : DOUBLE LOW-9 QUOTATION MARK | ||
291 | 85 = U+2026 : HORIZONTAL ELLIPSIS | ||
292 | 86 = U+2020 : DAGGER | ||
293 | 87 = U+2021 : DOUBLE DAGGER | ||
294 | 88 = U+02C6 : MODIFIER LETTER CIRCUMFLEX ACCENT | ||
295 | 89 = U+2030 : PER MILLE SIGN | ||
296 | 8A = U+0160 : LATIN CAPITAL LETTER S WITH CARON | ||
297 | 8B = U+2039 : SINGLE LEFT-POINTING ANGLE QUOTATION MARK | ||
298 | 8C = U+0152 : LATIN CAPITAL LIGATURE OE | ||
299 | 8E = U+017D : LATIN CAPITAL LETTER Z WITH CARON | ||
300 | 91 = U+2018 : LEFT SINGLE QUOTATION MARK | ||
301 | 92 = U+2019 : RIGHT SINGLE QUOTATION MARK | ||
302 | 93 = U+201C : LEFT DOUBLE QUOTATION MARK | ||
303 | 94 = U+201D : RIGHT DOUBLE QUOTATION MARK | ||
304 | 95 = U+2022 : BULLET | ||
305 | 96 = U+2013 : EN DASH | ||
306 | 97 = U+2014 : EM DASH | ||
307 | 98 = U+02DC : SMALL TILDE | ||
308 | 99 = U+2122 : TRADE MARK SIGN | ||
309 | 9A = U+0161 : LATIN SMALL LETTER S WITH CARON | ||
310 | 9B = U+203A : SINGLE RIGHT-POINTING ANGLE QUOTATION MARK | ||
311 | 9C = U+0153 : LATIN SMALL LIGATURE OE | ||
312 | 9E = U+017E : LATIN SMALL LETTER Z WITH CARON | ||
313 | 9F = U+0178 : LATIN CAPITAL LETTER Y WITH DIAERESIS | ||
314 | A0 = U+00A0 : NO-BREAK SPACE | ||
315 | A1 = U+00A1 : INVERTED EXCLAMATION MARK | ||
316 | A2 = U+00A2 : CENT SIGN | ||
317 | A3 = U+00A3 : POUND SIGN | ||
318 | A4 = U+00A4 : CURRENCY SIGN | ||
319 | A5 = U+00A5 : YEN SIGN | ||
320 | A6 = U+00A6 : BROKEN BAR | ||
321 | A7 = U+00A7 : SECTION SIGN | ||
322 | A8 = U+00A8 : DIAERESIS | ||
323 | A9 = U+00A9 : COPYRIGHT SIGN | ||
324 | AA = U+00AA : FEMININE ORDINAL INDICATOR | ||
325 | AB = U+00AB : LEFT-POINTING DOUBLE ANGLE QUOTATION MARK | ||
326 | AC = U+00AC : NOT SIGN | ||
327 | AD = U+00AD : SOFT HYPHEN | ||
328 | AE = U+00AE : REGISTERED SIGN | ||
329 | AF = U+00AF : MACRON | ||
330 | B0 = U+00B0 : DEGREE SIGN | ||
331 | B1 = U+00B1 : PLUS-MINUS SIGN | ||
332 | B2 = U+00B2 : SUPERSCRIPT TWO | ||
333 | B3 = U+00B3 : SUPERSCRIPT THREE | ||
334 | B4 = U+00B4 : ACUTE ACCENT | ||
335 | B5 = U+00B5 : MICRO SIGN | ||
336 | B6 = U+00B6 : PILCROW SIGN | ||
337 | B7 = U+00B7 : MIDDLE DOT | ||
338 | B8 = U+00B8 : CEDILLA | ||
339 | B9 = U+00B9 : SUPERSCRIPT ONE | ||
340 | BA = U+00BA : MASCULINE ORDINAL INDICATOR | ||
341 | BB = U+00BB : RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK | ||
342 | BC = U+00BC : VULGAR FRACTION ONE QUARTER | ||
343 | BD = U+00BD : VULGAR FRACTION ONE HALF | ||
344 | BE = U+00BE : VULGAR FRACTION THREE QUARTERS | ||
345 | BF = U+00BF : INVERTED QUESTION MARK | ||
346 | C0 = U+00C0 : LATIN CAPITAL LETTER A WITH GRAVE | ||
347 | C1 = U+00C1 : LATIN CAPITAL LETTER A WITH ACUTE | ||
348 | C2 = U+00C2 : LATIN CAPITAL LETTER A WITH CIRCUMFLEX | ||
349 | C3 = U+00C3 : LATIN CAPITAL LETTER A WITH TILDE | ||
350 | C4 = U+00C4 : LATIN CAPITAL LETTER A WITH DIAERESIS | ||
351 | C5 = U+00C5 : LATIN CAPITAL LETTER A WITH RING ABOVE | ||
352 | C6 = U+00C6 : LATIN CAPITAL LETTER AE | ||
353 | C7 = U+00C7 : LATIN CAPITAL LETTER C WITH CEDILLA | ||
354 | C8 = U+00C8 : LATIN CAPITAL LETTER E WITH GRAVE | ||
355 | C9 = U+00C9 : LATIN CAPITAL LETTER E WITH ACUTE | ||
356 | CA = U+00CA : LATIN CAPITAL LETTER E WITH CIRCUMFLEX | ||
357 | CB = U+00CB : LATIN CAPITAL LETTER E WITH DIAERESIS | ||
358 | CC = U+00CC : LATIN CAPITAL LETTER I WITH GRAVE | ||
359 | CD = U+00CD : LATIN CAPITAL LETTER I WITH ACUTE | ||
360 | CE = U+00CE : LATIN CAPITAL LETTER I WITH CIRCUMFLEX | ||
361 | CF = U+00CF : LATIN CAPITAL LETTER I WITH DIAERESIS | ||
362 | D0 = U+00D0 : LATIN CAPITAL LETTER ETH | ||
363 | D1 = U+00D1 : LATIN CAPITAL LETTER N WITH TILDE | ||
364 | D2 = U+00D2 : LATIN CAPITAL LETTER O WITH GRAVE | ||
365 | D3 = U+00D3 : LATIN CAPITAL LETTER O WITH ACUTE | ||
366 | D4 = U+00D4 : LATIN CAPITAL LETTER O WITH CIRCUMFLEX | ||
367 | D5 = U+00D5 : LATIN CAPITAL LETTER O WITH TILDE | ||
368 | D6 = U+00D6 : LATIN CAPITAL LETTER O WITH DIAERESIS | ||
369 | D7 = U+00D7 : MULTIPLICATION SIGN | ||
370 | D8 = U+00D8 : LATIN CAPITAL LETTER O WITH STROKE | ||
371 | D9 = U+00D9 : LATIN CAPITAL LETTER U WITH GRAVE | ||
372 | DA = U+00DA : LATIN CAPITAL LETTER U WITH ACUTE | ||
373 | DB = U+00DB : LATIN CAPITAL LETTER U WITH CIRCUMFLEX | ||
374 | DC = U+00DC : LATIN CAPITAL LETTER U WITH DIAERESIS | ||
375 | DD = U+00DD : LATIN CAPITAL LETTER Y WITH ACUTE | ||
376 | DE = U+00DE : LATIN CAPITAL LETTER THORN | ||
377 | DF = U+00DF : LATIN SMALL LETTER SHARP S | ||
378 | E0 = U+00E0 : LATIN SMALL LETTER A WITH GRAVE | ||
379 | E1 = U+00E1 : LATIN SMALL LETTER A WITH ACUTE | ||
380 | E2 = U+00E2 : LATIN SMALL LETTER A WITH CIRCUMFLEX | ||
381 | E3 = U+00E3 : LATIN SMALL LETTER A WITH TILDE | ||
382 | E4 = U+00E4 : LATIN SMALL LETTER A WITH DIAERESIS | ||
383 | E5 = U+00E5 : LATIN SMALL LETTER A WITH RING ABOVE | ||
384 | E6 = U+00E6 : LATIN SMALL LETTER AE | ||
385 | E7 = U+00E7 : LATIN SMALL LETTER C WITH CEDILLA | ||
386 | E8 = U+00E8 : LATIN SMALL LETTER E WITH GRAVE | ||
387 | E9 = U+00E9 : LATIN SMALL LETTER E WITH ACUTE | ||
388 | EA = U+00EA : LATIN SMALL LETTER E WITH CIRCUMFLEX | ||
389 | EB = U+00EB : LATIN SMALL LETTER E WITH DIAERESIS | ||
390 | EC = U+00EC : LATIN SMALL LETTER I WITH GRAVE | ||
391 | ED = U+00ED : LATIN SMALL LETTER I WITH ACUTE | ||
392 | EE = U+00EE : LATIN SMALL LETTER I WITH CIRCUMFLEX | ||
393 | EF = U+00EF : LATIN SMALL LETTER I WITH DIAERESIS | ||
394 | F0 = U+00F0 : LATIN SMALL LETTER ETH | ||
395 | F1 = U+00F1 : LATIN SMALL LETTER N WITH TILDE | ||
396 | F2 = U+00F2 : LATIN SMALL LETTER O WITH GRAVE | ||
397 | F3 = U+00F3 : LATIN SMALL LETTER O WITH ACUTE | ||
398 | F4 = U+00F4 : LATIN SMALL LETTER O WITH CIRCUMFLEX | ||
399 | F5 = U+00F5 : LATIN SMALL LETTER O WITH TILDE | ||
400 | F6 = U+00F6 : LATIN SMALL LETTER O WITH DIAERESIS | ||
401 | F7 = U+00F7 : DIVISION SIGN | ||
402 | F8 = U+00F8 : LATIN SMALL LETTER O WITH STROKE | ||
403 | F9 = U+00F9 : LATIN SMALL LETTER U WITH GRAVE | ||
404 | FA = U+00FA : LATIN SMALL LETTER U WITH ACUTE | ||
405 | FB = U+00FB : LATIN SMALL LETTER U WITH CIRCUMFLEX | ||
406 | FC = U+00FC : LATIN SMALL LETTER U WITH DIAERESIS | ||
407 | FD = U+00FD : LATIN SMALL LETTER Y WITH ACUTE | ||
408 | FE = U+00FE : LATIN SMALL LETTER THORN | ||
409 | FF = U+00FF : LATIN SMALL LETTER Y WITH DIAERESIS | ||
410 | * | ||
411 | */ | ||
412 | } | ||
413 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/ContentProvider.php b/inc/3rdparty/libraries/MOBIClass/ContentProvider.php deleted file mode 100644 index dcf9c4de..00000000 --- a/inc/3rdparty/libraries/MOBIClass/ContentProvider.php +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | abstract class ContentProvider{ | ||
4 | /** | ||
5 | * Get the text data to be integrated in the MOBI file | ||
6 | * @return string | ||
7 | */ | ||
8 | public abstract function getTextData(); | ||
9 | /** | ||
10 | * Get the images (an array containing the jpeg data). Array entry 0 will | ||
11 | * correspond to image record 0. | ||
12 | * @return array | ||
13 | */ | ||
14 | public abstract function getImages(); | ||
15 | /** | ||
16 | * Get the metadata in the form of a hashtable (for example, title or author). | ||
17 | * @return array | ||
18 | */ | ||
19 | public abstract function getMetaData(); | ||
20 | } | ||
21 | |||
22 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/EXTHHelper.php b/inc/3rdparty/libraries/MOBIClass/EXTHHelper.php deleted file mode 100644 index 275142bf..00000000 --- a/inc/3rdparty/libraries/MOBIClass/EXTHHelper.php +++ /dev/null | |||
@@ -1,132 +0,0 @@ | |||
1 | <?php | ||
2 | //Reference: http://wiki.mobileread.com/wiki/MOBI | ||
3 | |||
4 | class EXTHHelper{ | ||
5 | static function typeToText($type){ | ||
6 | $types = self::$types; | ||
7 | if(isset($types[$type])){ | ||
8 | return $types[$type]; | ||
9 | } | ||
10 | return $type; | ||
11 | } | ||
12 | static function textToType($text){ | ||
13 | $text = strtolower($text); | ||
14 | if(isset(self::$flippedTypes[$text])){ | ||
15 | return self::$flippedTypes[$text]; | ||
16 | } | ||
17 | return false; | ||
18 | } | ||
19 | |||
20 | static function convert($n, $size){ | ||
21 | $mask = 0xFF; | ||
22 | $out = ""; | ||
23 | for($i = 0; $i < $size; $i++){ | ||
24 | $out = chr(($n & $mask) >> (8*$i)).$out; | ||
25 | $mask = $mask << 8; | ||
26 | } | ||
27 | return $out; | ||
28 | } | ||
29 | |||
30 | static function getRightRepresentation($type, $value){ | ||
31 | if($type >= 100 && $type < 200){ | ||
32 | return $value; | ||
33 | }else{ | ||
34 | return self::toHex($value); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | static function toHex($value){ | ||
39 | $out = ""; | ||
40 | for($i = 0, $len = strlen($value); $i < $len; $i++){ | ||
41 | if($i > 0) $out .= " "; | ||
42 | $hex = dechex(ord($value[$i])); | ||
43 | if(strlen($hex) < 2) $hex = "0".$hex; | ||
44 | $out .= $hex; | ||
45 | } | ||
46 | return $out; | ||
47 | } | ||
48 | |||
49 | |||
50 | static private $types = array( | ||
51 | 1 => "drm server id", | ||
52 | 2 => "drm commerce id", | ||
53 | 3 => "drm ebookbase book id", | ||
54 | 100 => "author", | ||
55 | 101 => "publisher", | ||
56 | 102 => "imprint", | ||
57 | 103 => "description", | ||
58 | 104 => "isbn", | ||
59 | 105 => "subject", | ||
60 | 106 => "publishingdate", | ||
61 | 107 => "review", | ||
62 | 108 => "contributor", | ||
63 | 109 => "rights", | ||
64 | 110 => "subjectcode", | ||
65 | 111 => "type", | ||
66 | 112 => "source", | ||
67 | 113 => "asin", | ||
68 | 114 => "versionnumber", | ||
69 | 115 => "sample", | ||
70 | 116 => "startreading", | ||
71 | 118 => "retail price", | ||
72 | 119 => "retail price currency", | ||
73 | 201 => "coveroffset", | ||
74 | 202 => "thumboffset", | ||
75 | 203 => "hasfakecover", | ||
76 | 204 => "Creator Software", | ||
77 | 205 => "Creator Major Version", | ||
78 | 206 => "Creator Minor Version", | ||
79 | 207 => "Creator Build Number", | ||
80 | 208 => "watermark", | ||
81 | 209 => "tamper proof keys", | ||
82 | 300 => "fontsignature", | ||
83 | 401 => "clippinglimit", | ||
84 | 402 => "publisherlimit", | ||
85 | 403 => "403", | ||
86 | 404 => "ttsflag", | ||
87 | 501 => "cdetype", | ||
88 | 502 => "lastupdatetime", | ||
89 | 503 => "updatedtitle" | ||
90 | ); | ||
91 | static private $flippedTypes = array( | ||
92 | "drm server id" => 1, | ||
93 | "drm commerce id" => 2, | ||
94 | "drm ebookbase book id" => 3, | ||
95 | "author" => 100, | ||
96 | "publisher" => 101, | ||
97 | "imprint" => 102, | ||
98 | "description" => 103, | ||
99 | "isbn" => 104, | ||
100 | "subject" => 105, | ||
101 | "publishingdate" => 106, | ||
102 | "review" => 107, | ||
103 | "contributor" => 108, | ||
104 | "rights" => 109, | ||
105 | "subjectcode" => 110, | ||
106 | "type" => 111, | ||
107 | "source" => 112, | ||
108 | "asin" => 113, | ||
109 | "versionnumber" => 114, | ||
110 | "sample" => 115, | ||
111 | "startreading" => 116, | ||
112 | "retail price" => 118, | ||
113 | "retail price currency" => 119, | ||
114 | "coveroffset" => 201, | ||
115 | "thumboffset" => 202, | ||
116 | "hasfakecover" => 203, | ||
117 | "Creator Software" => 204, | ||
118 | "Creator Major Version" => 205, | ||
119 | "Creator Minor Version" => 206, | ||
120 | "Creator Build Number" => 207, | ||
121 | "watermark" => 208, | ||
122 | "tamper proof keys" => 209, | ||
123 | "fontsignature" => 300, | ||
124 | "clippinglimit" => 401, | ||
125 | "publisherlimit" => 402, | ||
126 | "403" => 403, | ||
127 | "ttsflag" => 404, | ||
128 | "cdetype" => 501, | ||
129 | "lastupdatetime" => 502, | ||
130 | "updatedtitle" => 503 | ||
131 | ); | ||
132 | } \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/FileByte.php b/inc/3rdparty/libraries/MOBIClass/FileByte.php deleted file mode 100644 index 05fc7d04..00000000 --- a/inc/3rdparty/libraries/MOBIClass/FileByte.php +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileByte | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FileByte extends FileObject { | ||
9 | private $data; | ||
10 | |||
11 | /** | ||
12 | * Make a short to be stored in a file | ||
13 | * @param short $n | ||
14 | */ | ||
15 | public function __construct($n = 0){ | ||
16 | parent::__construct(1); | ||
17 | $this->set($n); | ||
18 | } | ||
19 | |||
20 | public function get(){ | ||
21 | return $this->data; | ||
22 | } | ||
23 | |||
24 | public function set($value){ | ||
25 | $this->data = intval($value) & 0xFF; | ||
26 | } | ||
27 | |||
28 | public function serialize() { | ||
29 | return $this->byteToString($this->data); | ||
30 | } | ||
31 | |||
32 | public function unserialize($data) { | ||
33 | __construct($this->toInt($data)); | ||
34 | } | ||
35 | |||
36 | |||
37 | public function __toString(){ | ||
38 | return "FileByte: {".$this->byteAsString($this->data)."}"; | ||
39 | } | ||
40 | } | ||
41 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/FileDate.php b/inc/3rdparty/libraries/MOBIClass/FileDate.php deleted file mode 100644 index 2284eba2..00000000 --- a/inc/3rdparty/libraries/MOBIClass/FileDate.php +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileDate | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FileDate extends FileObject { | ||
9 | private $data; | ||
10 | |||
11 | /** | ||
12 | * Make an integer to be stored in a file | ||
13 | * @param int $n | ||
14 | */ | ||
15 | public function __construct($n = 0){ | ||
16 | parent::__construct(4); | ||
17 | $this->set($n); | ||
18 | } | ||
19 | |||
20 | public function get(){ | ||
21 | return $this->data; | ||
22 | } | ||
23 | |||
24 | public function set($value){ | ||
25 | $this->data = intval($value); | ||
26 | } | ||
27 | |||
28 | public function serialize() { | ||
29 | return $this->intToString($this->data); | ||
30 | } | ||
31 | |||
32 | public function unserialize($data) { | ||
33 | __construct($this->toInt($data)); | ||
34 | } | ||
35 | |||
36 | public function __toString(){ | ||
37 | return "FileDate: {".(date("r", $this->data-94694400))."}"; | ||
38 | } | ||
39 | } | ||
40 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/FileElement.php b/inc/3rdparty/libraries/MOBIClass/FileElement.php deleted file mode 100644 index 552d04a8..00000000 --- a/inc/3rdparty/libraries/MOBIClass/FileElement.php +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileElement | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FileElement { | ||
9 | /** | ||
10 | * @var FileObject | ||
11 | */ | ||
12 | public $elements; | ||
13 | |||
14 | /** | ||
15 | * Make a record to be stored in a file | ||
16 | * @param Record $record | ||
17 | */ | ||
18 | public function __construct($elements = array()){ | ||
19 | $this->elements = $elements; | ||
20 | } | ||
21 | |||
22 | public function getByteLength(){ | ||
23 | return $this->getLength(); | ||
24 | } | ||
25 | |||
26 | public function getLength(){ | ||
27 | $total = 0; | ||
28 | foreach($this->elements as $val){ | ||
29 | $total += $val->getByteLength(); | ||
30 | } | ||
31 | return $total; | ||
32 | } | ||
33 | |||
34 | public function offsetToEntry($name){ | ||
35 | $pos = 0; | ||
36 | foreach($this->elements as $key=>$value){ | ||
37 | if($name == $key){ | ||
38 | break; | ||
39 | } | ||
40 | $pos += $value->getByteLength(); | ||
41 | } | ||
42 | return $pos; | ||
43 | } | ||
44 | |||
45 | public function exists($key){ | ||
46 | return isset($this->elements[$key]); | ||
47 | } | ||
48 | /** | ||
49 | * @param string $key | ||
50 | * @return FileObject | ||
51 | */ | ||
52 | public function get($key){ | ||
53 | return $this->elements[$key]; | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * @param string $key | ||
58 | * @param FileObject $value | ||
59 | */ | ||
60 | public function set($key, $value){ | ||
61 | $this->elements[$key] = $value; | ||
62 | } | ||
63 | |||
64 | public function add($key, $value){ | ||
65 | $this->elements[$key] = $value; | ||
66 | } | ||
67 | |||
68 | public function serialize() { | ||
69 | $result = ""; | ||
70 | foreach($this->elements as $val){ | ||
71 | $result .= $val->serialize(); | ||
72 | } | ||
73 | return $result; | ||
74 | } | ||
75 | |||
76 | public function unserialize($data) { | ||
77 | //TODO: If reading is needed -> way more complex | ||
78 | } | ||
79 | |||
80 | public function __toString(){ | ||
81 | $output = "FileElement (".$this->getByteLength()." bytes): {\n"; | ||
82 | foreach($this->elements as $key=>$value){ | ||
83 | $output .= "\t".$key.": ".$value."\n"; | ||
84 | } | ||
85 | $output .= "}"; | ||
86 | return $output; | ||
87 | } | ||
88 | } | ||
89 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/FileInt.php b/inc/3rdparty/libraries/MOBIClass/FileInt.php deleted file mode 100644 index ebe86f86..00000000 --- a/inc/3rdparty/libraries/MOBIClass/FileInt.php +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileInt | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FileInt extends FileObject { | ||
9 | private $data; | ||
10 | |||
11 | /** | ||
12 | * Make an integer to be stored in a file | ||
13 | * @param int $n | ||
14 | */ | ||
15 | public function __construct($n = 0){ | ||
16 | parent::__construct(4); | ||
17 | $this->set($n); | ||
18 | } | ||
19 | |||
20 | public function get(){ | ||
21 | return $this->data; | ||
22 | } | ||
23 | |||
24 | public function set($value){ | ||
25 | $this->data = intval($value); | ||
26 | } | ||
27 | |||
28 | public function serialize() { | ||
29 | return $this->intToString($this->data); | ||
30 | } | ||
31 | |||
32 | public function unserialize($data) { | ||
33 | __construct($this->toInt($data)); | ||
34 | } | ||
35 | |||
36 | public function __toString(){ | ||
37 | return "FileInt: {".$this->intAsString($this->data)."}"; | ||
38 | } | ||
39 | } | ||
40 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/FileObject.php b/inc/3rdparty/libraries/MOBIClass/FileObject.php deleted file mode 100644 index 0df17df1..00000000 --- a/inc/3rdparty/libraries/MOBIClass/FileObject.php +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileObject | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | abstract class FileObject { | ||
9 | private $byteLength = -1; | ||
10 | |||
11 | public function __construct($byteLength = -1){ | ||
12 | $this->byteLength = $byteLength; | ||
13 | } | ||
14 | |||
15 | public function getByteLength(){ | ||
16 | if($this->byteLength >= 0){ | ||
17 | return $this->byteLength; | ||
18 | } | ||
19 | return $this->getLength(); | ||
20 | } | ||
21 | |||
22 | public function getLength(){ | ||
23 | throw new Exception("Sub-class needs to implement this if it doesn't have a fixed length"); | ||
24 | } | ||
25 | |||
26 | /** | ||
27 | * Convert a string to byte format (maximum 4 bytes) | ||
28 | * @param string $string Input string | ||
29 | * @return int Output integer | ||
30 | */ | ||
31 | public function toInt($string){ | ||
32 | $out = 0; | ||
33 | for($i = 0, $len = min(4, strlen($string)); $i < $len; $i++){ | ||
34 | $out = $out | (ord($string[$i]) << (($len-$i-1)*8)); | ||
35 | } | ||
36 | return $out; | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * Convert a byte (stored in an integer) to a string | ||
41 | * @param byte $int | ||
42 | * @return string | ||
43 | */ | ||
44 | public function byteToString($int){ | ||
45 | return $this->toString($int, 1); | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * Convert a byte (stored in an integer) to a string | ||
50 | * @param byte $int | ||
51 | * @return string | ||
52 | */ | ||
53 | public function byteAsString($int){ | ||
54 | return $this->asString($int, 1); | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * Convert a short (stored in an integer) to a string | ||
59 | * @param short $int | ||
60 | * @return string | ||
61 | */ | ||
62 | public function shortToString($int){ | ||
63 | return $this->toString($int, 2); | ||
64 | } | ||
65 | |||
66 | /** | ||
67 | * Convert a short (stored in an integer) to a string | ||
68 | * @param short $int | ||
69 | * @return string | ||
70 | */ | ||
71 | public function shortAsString($int){ | ||
72 | return $this->asString($int, 2); | ||
73 | } | ||
74 | |||
75 | /** | ||
76 | * Convert a tri-byte (stored in an integer) to a string | ||
77 | * @param tri-byte $int | ||
78 | * @return string | ||
79 | */ | ||
80 | public function triToString($int){ | ||
81 | return $this->toString($int, 3); | ||
82 | } | ||
83 | |||
84 | /** | ||
85 | * Convert a tri-byte (stored in an integer) to a string | ||
86 | * @param tri-byte $int | ||
87 | * @return string | ||
88 | */ | ||
89 | public function triAsString($int){ | ||
90 | return $this->asString($int, 3); | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * Convert an integer to a string | ||
95 | * @param int $int | ||
96 | * @return string | ||
97 | */ | ||
98 | public function intToString($int){ | ||
99 | return $this->toString($int, 4); | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * Convert an integer to a string | ||
104 | * @param int $int | ||
105 | * @return string | ||
106 | */ | ||
107 | public function intAsString($int){ | ||
108 | return $this->asString($int, 4); | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * Convert a number of n bytes to a string | ||
113 | * @param int $int Number that should be converted | ||
114 | * @param int $size Number of bytes to convert | ||
115 | * @return string Output string | ||
116 | */ | ||
117 | private function toString($int, $size){ | ||
118 | $out = ""; | ||
119 | for($i = 0; $i < $size; $i++){ | ||
120 | $out = chr($int & 0xFF).$out; | ||
121 | $int = $int >> 8; | ||
122 | } | ||
123 | return $out; | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * Convert a number of n bytes to a string | ||
128 | * @param int $int Number that should be converted | ||
129 | * @param int $size Number of bytes to convert | ||
130 | * @return string Output string | ||
131 | */ | ||
132 | private function asString($int, $size){ | ||
133 | $out = ""; | ||
134 | for($i = 0; $i < $size; $i++){ | ||
135 | if($i > 0) $out = " ".$out; | ||
136 | $byte = dechex($int & 0xFF); | ||
137 | if(strlen($byte) == 1) $byte = "0".$byte; | ||
138 | $out = $byte.$out; | ||
139 | $int = $int >> 8; | ||
140 | } | ||
141 | return $out; | ||
142 | } | ||
143 | |||
144 | /** | ||
145 | * Get the value | ||
146 | * @return mixed Value to get | ||
147 | */ | ||
148 | abstract public function get(); | ||
149 | |||
150 | /** | ||
151 | * Set the value | ||
152 | * @return mixed Value to set | ||
153 | */ | ||
154 | abstract public function set($value); | ||
155 | |||
156 | /** | ||
157 | * Serialize the object | ||
158 | * @return string String representation | ||
159 | */ | ||
160 | abstract public function serialize(); | ||
161 | |||
162 | /** | ||
163 | * Unserialize the object | ||
164 | * @param string $data String representation | ||
165 | */ | ||
166 | abstract public function unserialize($data); | ||
167 | } | ||
168 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/FileRecord.php b/inc/3rdparty/libraries/MOBIClass/FileRecord.php deleted file mode 100644 index 494a72e4..00000000 --- a/inc/3rdparty/libraries/MOBIClass/FileRecord.php +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileRecord | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FileRecord extends FileObject { | ||
9 | /** | ||
10 | * @var Record | ||
11 | */ | ||
12 | private $record; | ||
13 | |||
14 | /** | ||
15 | * Make a record to be stored in a file | ||
16 | * @param Record $record | ||
17 | */ | ||
18 | public function __construct($record){ | ||
19 | $this->record = $record; | ||
20 | } | ||
21 | |||
22 | public function getByteLength(){ | ||
23 | return $this->getLength(); | ||
24 | } | ||
25 | |||
26 | public function getLength(){ | ||
27 | return $this->record->getLength(); | ||
28 | } | ||
29 | |||
30 | public function get(){ | ||
31 | return $this->record; | ||
32 | } | ||
33 | |||
34 | public function set($record){ | ||
35 | $this->record = $record; | ||
36 | } | ||
37 | |||
38 | public function serialize() { | ||
39 | return $this->record->serialize(); | ||
40 | } | ||
41 | |||
42 | public function unserialize($data) { | ||
43 | __construct($this->record->unserialize($data)); | ||
44 | } | ||
45 | } | ||
46 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/FileShort.php b/inc/3rdparty/libraries/MOBIClass/FileShort.php deleted file mode 100644 index 9921ea82..00000000 --- a/inc/3rdparty/libraries/MOBIClass/FileShort.php +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileShort | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FileShort extends FileObject { | ||
9 | private $data; | ||
10 | |||
11 | /** | ||
12 | * Make a short to be stored in a file | ||
13 | * @param short $n | ||
14 | */ | ||
15 | public function __construct($n = 0){ | ||
16 | parent::__construct(2); | ||
17 | $this->set($n); | ||
18 | } | ||
19 | |||
20 | public function get(){ | ||
21 | return $this->data; | ||
22 | } | ||
23 | |||
24 | public function set($value){ | ||
25 | $this->data = intval($value) & 0xFFFF; | ||
26 | } | ||
27 | |||
28 | public function serialize() { | ||
29 | return $this->shortToString($this->data); | ||
30 | } | ||
31 | |||
32 | public function unserialize($data) { | ||
33 | __construct($this->toInt($data)); | ||
34 | } | ||
35 | |||
36 | |||
37 | public function __toString(){ | ||
38 | return "FileShort: {".$this->shortAsString($this->data)."}"; | ||
39 | } | ||
40 | } | ||
41 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/FileString.php b/inc/3rdparty/libraries/MOBIClass/FileString.php deleted file mode 100644 index 16e906a6..00000000 --- a/inc/3rdparty/libraries/MOBIClass/FileString.php +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileString | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FileString extends FileObject { | ||
9 | private $forcedLength; | ||
10 | private $data; | ||
11 | |||
12 | /** | ||
13 | * Make a string to be stored in a file | ||
14 | * @param string|int $first Optional, if it is a string, it will be the contents, | ||
15 | * if it is a number, it will set the forced length. | ||
16 | * @param int $second Optional, will set the forced length. Can only be used when the | ||
17 | * first argument is contents. | ||
18 | */ | ||
19 | public function __construct($first = null, $second = null){ | ||
20 | $this->forcedLength = -1; | ||
21 | $this->data = ""; | ||
22 | |||
23 | if($second != null){ | ||
24 | $this->data = $first; | ||
25 | $this->forcedLength = $second; | ||
26 | }else if($first != null){ | ||
27 | if(is_string($first)){ | ||
28 | $this->data = $first; | ||
29 | }else{ | ||
30 | $this->forcedLength = $first; | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | |||
35 | public function getByteLength(){ | ||
36 | return $this->getLength(); | ||
37 | } | ||
38 | |||
39 | public function getLength(){ | ||
40 | if($this->forcedLength >= 0){ | ||
41 | return $this->forcedLength; | ||
42 | } | ||
43 | return strlen($this->data); | ||
44 | } | ||
45 | |||
46 | public function get(){ | ||
47 | return $this->data; | ||
48 | } | ||
49 | |||
50 | public function set($value){ | ||
51 | $this->data = $value; | ||
52 | } | ||
53 | |||
54 | public function serialize() { | ||
55 | $output = $this->data; | ||
56 | $curLength = strlen($output); | ||
57 | |||
58 | if($this->forcedLength >= 0){ | ||
59 | if($this->forcedLength > $curLength){ | ||
60 | return str_pad($output, $this->forcedLength, "\0", STR_PAD_RIGHT); | ||
61 | }elseif($this->forcedLength == $curLength){ | ||
62 | return $output; | ||
63 | }else{ | ||
64 | return substr($output, 0, $this->forcedLength); | ||
65 | } | ||
66 | } | ||
67 | return $output; | ||
68 | } | ||
69 | |||
70 | public function unserialize($data) { | ||
71 | __construct($data); | ||
72 | } | ||
73 | |||
74 | public function __toString(){ | ||
75 | $out = "FileString"; | ||
76 | if($this->forcedLength >= 0){ | ||
77 | $out .= " ".$this->forcedLength; | ||
78 | } | ||
79 | $out .= ": {\"".str_replace(array(" ", "\0"), " ", $this->serialize())."\"}"; | ||
80 | return $out; | ||
81 | } | ||
82 | } | ||
83 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/FileTri.php b/inc/3rdparty/libraries/MOBIClass/FileTri.php deleted file mode 100644 index 6cacc0b0..00000000 --- a/inc/3rdparty/libraries/MOBIClass/FileTri.php +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileTri | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FileTri extends FileObject { | ||
9 | private $data; | ||
10 | |||
11 | /** | ||
12 | * Make a tri-byte to be stored in a file | ||
13 | * @param tri-byte $n | ||
14 | */ | ||
15 | public function __construct($n = 0){ | ||
16 | parent::__construct(3); | ||
17 | $this->set($n); | ||
18 | } | ||
19 | |||
20 | public function get(){ | ||
21 | return $this->data; | ||
22 | } | ||
23 | |||
24 | public function set($value){ | ||
25 | $this->data = intval($value) & 0xFFFFFF; | ||
26 | } | ||
27 | |||
28 | public function serialize() { | ||
29 | return $this->triToString($this->data); | ||
30 | } | ||
31 | |||
32 | public function unserialize($data) { | ||
33 | __construct($this->toInt($data)); | ||
34 | } | ||
35 | |||
36 | |||
37 | public function __toString(){ | ||
38 | return "FileTri: {".$this->triAsString($this->data)."}"; | ||
39 | } | ||
40 | } | ||
41 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/Http.php b/inc/3rdparty/libraries/MOBIClass/Http.php deleted file mode 100644 index 9e5852e3..00000000 --- a/inc/3rdparty/libraries/MOBIClass/Http.php +++ /dev/null | |||
@@ -1,171 +0,0 @@ | |||
1 | <?php | ||
2 | class Http{ | ||
3 | private static $cache = false; | ||
4 | |||
5 | public static function Request($url){ | ||
6 | $url_parts = parse_url($url); | ||
7 | $url_parts["port"] = isset($url_parts["port"]) ? $url_parts["port"] : 80; | ||
8 | $url_parts["path"] = isset($url_parts["path"]) ? $url_parts["path"] : "/"; | ||
9 | |||
10 | return self::FullRequest("GET", $url_parts["host"], $url_parts["port"], $url_parts["path"]); | ||
11 | } | ||
12 | |||
13 | public static function FullRequest( | ||
14 | $verb = 'GET', /* HTTP Request Method (GET and POST supported) */ | ||
15 | $ip, /* Target IP/Hostname */ | ||
16 | $port = 80, /* Target TCP port */ | ||
17 | $uri = '/', /* Target URI */ | ||
18 | $getdata = array(), /* HTTP GET Data ie. array('var1' => 'val1', 'var2' => 'val2') */ | ||
19 | $postdata = array(), /* HTTP POST Data ie. array('var1' => 'val1', 'var2' => 'val2') */ | ||
20 | $cookie = array(), /* HTTP Cookie Data ie. array('var1' => 'val1', 'var2' => 'val2') */ | ||
21 | $custom_headers = array(), /* Custom HTTP headers ie. array('Referer: http://localhost/ */ | ||
22 | $timeout = 1000, /* Socket timeout in milliseconds */ | ||
23 | $req_hdr = false, /* Include HTTP request headers */ | ||
24 | $res_hdr = false, /* Include HTTP response headers */ | ||
25 | $depth = 4 /* Depth of the iteration left (to avoid redirection loops) */ | ||
26 | ) | ||
27 | { | ||
28 | if(self::$cache){ | ||
29 | $cacheFile = "cache/".$ip."/".str_replace("/", "...", $uri); | ||
30 | |||
31 | if(is_file($cacheFile)){ | ||
32 | $data = file_get_contents($cacheFile); | ||
33 | |||
34 | return self::resolveTruncated($data); | ||
35 | } | ||
36 | } | ||
37 | $ret = ''; | ||
38 | $verb = strtoupper($verb); | ||
39 | $cookie_str = ''; | ||
40 | $getdata_str = count($getdata) ? '?' : ''; | ||
41 | $postdata_str = ''; | ||
42 | |||
43 | foreach ($getdata as $k => $v) | ||
44 | $getdata_str .= urlencode($k) .'='. urlencode($v); | ||
45 | |||
46 | foreach ($postdata as $k => $v) | ||
47 | $postdata_str .= urlencode($k) .'='. urlencode($v) .'&'; | ||
48 | |||
49 | foreach ($cookie as $k => $v) | ||
50 | $cookie_str .= urlencode($k) .'='. urlencode($v) .'; '; | ||
51 | |||
52 | $crlf = "\r\n"; | ||
53 | $req = $verb .' '. $uri . $getdata_str .' HTTP/1.1' . $crlf; | ||
54 | $req .= 'Host: '. $ip . $crlf; | ||
55 | $req .= 'User-Agent: Mozilla/5.0 Firefox/3.6.12' . $crlf; | ||
56 | $req .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . $crlf; | ||
57 | $req .= 'Accept-Language: en-us,en;q=0.5' . $crlf; | ||
58 | $req .= 'Accept-Encoding: deflate' . $crlf; | ||
59 | $req .= 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' . $crlf; | ||
60 | |||
61 | |||
62 | foreach ($custom_headers as $k => $v) | ||
63 | $req .= $k .': '. $v . $crlf; | ||
64 | |||
65 | if (!empty($cookie_str)) | ||
66 | $req .= 'Cookie: '. substr($cookie_str, 0, -2) . $crlf; | ||
67 | |||
68 | if ($verb == 'POST' && !empty($postdata_str)) | ||
69 | { | ||
70 | $postdata_str = substr($postdata_str, 0, -1); | ||
71 | $req .= 'Content-Type: application/x-www-form-urlencoded' . $crlf; | ||
72 | $req .= 'Content-Length: '. strlen($postdata_str) . $crlf . $crlf; | ||
73 | $req .= $postdata_str; | ||
74 | } | ||
75 | else $req .= $crlf; | ||
76 | |||
77 | if ($req_hdr) | ||
78 | $ret .= $req; | ||
79 | |||
80 | if (($fp = @fsockopen($ip, $port, $errno, $errstr)) == false) | ||
81 | return "Error $errno: $errstr\n"; | ||
82 | |||
83 | stream_set_timeout($fp, 0, $timeout * 1000); | ||
84 | |||
85 | fputs($fp, $req); | ||
86 | $ret .= stream_get_contents($fp); | ||
87 | fclose($fp); | ||
88 | |||
89 | $headerSplit = strpos($ret, "\r\n\r\n"); | ||
90 | $header = substr($ret, 0, $headerSplit); | ||
91 | |||
92 | $redirectURL = self::CheckForRedirect($header); | ||
93 | |||
94 | if($redirectURL !== false){ | ||
95 | if($depth > 0){ | ||
96 | $url_parts = parse_url($redirectURL); | ||
97 | $url_parts["port"] = isset($url_parts["port"]) ? $url_parts["port"] : 80; | ||
98 | $url_parts["path"] = isset($url_parts["path"]) ? $url_parts["path"] : "/"; | ||
99 | |||
100 | return self::FullRequest($verb, $url_parts["host"], $url_parts["port"], $url_parts["path"], $getdata, $postdata, $cookie, $custom_headers, $timeout, $req_hdr, $res_hdr, $depth-1); | ||
101 | }else{ | ||
102 | return "Redirect loop, stopping..."; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | $truncated = false; | ||
107 | $headerLines = explode("\r\n", $header); | ||
108 | foreach($headerLines as $line){ | ||
109 | list($name, $value) = explode(":", $line); | ||
110 | $name = trim($name); | ||
111 | $value = trim($value); | ||
112 | |||
113 | if(strtolower($name) == "transfer-encoding" && strtolower($value) == "chunked"){ //TODO: Put right values! | ||
114 | $truncated = true; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | if (!$res_hdr) | ||
119 | $ret = substr($ret, $headerSplit + 4); | ||
120 | |||
121 | if($truncated){ | ||
122 | $ret = self::resolveTruncated($ret); | ||
123 | } | ||
124 | if(self::$cache){ | ||
125 | if(!is_dir("cache")){ | ||
126 | mkdir("cache"); | ||
127 | } | ||
128 | if(!is_dir("cache/".$ip)){ | ||
129 | mkdir("cache/".$ip); | ||
130 | } | ||
131 | if(!is_file("cache/".$ip."/".str_replace("/", "...", $uri))){ | ||
132 | $h = fopen("cache/".$ip."/".str_replace("/", "...", $uri), "w"); | ||
133 | fwrite($h, $ret); | ||
134 | fclose($h); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | return $ret; | ||
139 | } | ||
140 | |||
141 | private static function resolveTruncated($data){ | ||
142 | $pos = 0; | ||
143 | $end = strlen($data); | ||
144 | $out = ""; | ||
145 | |||
146 | while($pos < $end){ | ||
147 | $endVal = strpos($data, "\r\n", $pos); | ||
148 | $value = hexdec(substr($data, $pos, $endVal-$pos)); | ||
149 | $out .= substr($data, $endVal+2, $value); | ||
150 | $pos = $endVal+2+$value; | ||
151 | } | ||
152 | |||
153 | return $out; | ||
154 | } | ||
155 | |||
156 | private static function CheckForRedirect($header){ | ||
157 | $firstLine = substr($header, 0, strpos($header, "\r\n")); | ||
158 | list($httpVersion, $statusCode, $message) = explode(" ", $firstLine); | ||
159 | |||
160 | if(substr($statusCode, 0, 1) == "3"){ | ||
161 | $part = substr($header, strpos(strtolower($header), "location: ")+strlen("location: ")); | ||
162 | $location = trim(substr($part, 0, strpos($part, "\r\n"))); | ||
163 | |||
164 | if(strlen($location) > 0){ | ||
165 | return $location; | ||
166 | } | ||
167 | } | ||
168 | return false; | ||
169 | } | ||
170 | } | ||
171 | ?> \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/ImageHandler.php b/inc/3rdparty/libraries/MOBIClass/ImageHandler.php deleted file mode 100644 index bcb48e9f..00000000 --- a/inc/3rdparty/libraries/MOBIClass/ImageHandler.php +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | class ImageHandler { | ||
4 | /** | ||
5 | * Download an image | ||
6 | * @param string $url Url to the image | ||
7 | * @return false|string False if failed, else the data of the image (converted to grayscale jpeg) | ||
8 | */ | ||
9 | public static function DownloadImage($url){ | ||
10 | $data = Http::Request($url); | ||
11 | $imgFile = @imagecreatefromstring($data); | ||
12 | |||
13 | if($imgFile !== false){ | ||
14 | $result = self::CreateImage($imgFile); | ||
15 | imagedestroy($imgFile); | ||
16 | return $result; | ||
17 | } | ||
18 | return false; | ||
19 | } | ||
20 | /** | ||
21 | * Create an image | ||
22 | * @param resource $img Create an image created with createimagetruecolor | ||
23 | * @return false|string False if failed, else the data of the image (converted to grayscale jpeg) | ||
24 | */ | ||
25 | public static function CreateImage($img){ | ||
26 | try{ | ||
27 | imagefilter($img, IMG_FILTER_GRAYSCALE); | ||
28 | |||
29 | ob_start(); | ||
30 | imagejpeg($img); | ||
31 | $image = ob_get_contents(); | ||
32 | ob_end_clean(); | ||
33 | |||
34 | return $image; | ||
35 | }catch(Exception $e){ | ||
36 | return false; | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/MOBI.php b/inc/3rdparty/libraries/MOBIClass/MOBI.php deleted file mode 100644 index df4826b0..00000000 --- a/inc/3rdparty/libraries/MOBIClass/MOBI.php +++ /dev/null | |||
@@ -1,192 +0,0 @@ | |||
1 | <?php | ||
2 | require_once(dirname(__FILE__)."/../readability/Readability.php"); | ||
3 | require_once(dirname(__FILE__).'/CharacterEntities.php'); | ||
4 | require_once(dirname(__FILE__).'/constants.php'); | ||
5 | require_once(dirname(__FILE__).'/ContentProvider.php'); | ||
6 | require_once(dirname(__FILE__).'/MultipleFileHandler.php'); | ||
7 | require_once(dirname(__FILE__)."/downloaders/FanFictionNet.php"); | ||
8 | require_once(dirname(__FILE__).'/EXTHHelper.php'); | ||
9 | require_once(dirname(__FILE__).'/FileObject.php'); | ||
10 | require_once(dirname(__FILE__).'/FileByte.php'); | ||
11 | require_once(dirname(__FILE__).'/FileDate.php'); | ||
12 | require_once(dirname(__FILE__).'/FileElement.php'); | ||
13 | require_once(dirname(__FILE__).'/FileInt.php'); | ||
14 | require_once(dirname(__FILE__).'/FileRecord.php'); | ||
15 | require_once(dirname(__FILE__).'/FileShort.php'); | ||
16 | require_once(dirname(__FILE__).'/FileString.php'); | ||
17 | require_once(dirname(__FILE__).'/FileTri.php'); | ||
18 | require_once(dirname(__FILE__).'/Http.php'); | ||
19 | require_once(dirname(__FILE__).'/http_build_url.php'); | ||
20 | require_once(dirname(__FILE__).'/ImageHandler.php'); | ||
21 | require_once(dirname(__FILE__).'/MOBIFile.php'); | ||
22 | require_once(dirname(__FILE__).'/OnlineArticle.php'); | ||
23 | require_once(dirname(__FILE__).'/PalmRecord.php'); | ||
24 | require_once(dirname(__FILE__).'/Prc.php'); | ||
25 | require_once(dirname(__FILE__).'/PreprocessedArticle.php'); | ||
26 | require_once(dirname(__FILE__).'/RecognizeURL.php'); | ||
27 | require_once(dirname(__FILE__).'/Record.php'); | ||
28 | require_once(dirname(__FILE__).'/RecordFactory.php'); | ||
29 | require_once(dirname(__FILE__).'/Settings.php'); | ||
30 | |||
31 | /** | ||
32 | * Description of MOBI. | ||
33 | * | ||
34 | * Usage: | ||
35 | * include("MOBIClass/MOBI.php"); | ||
36 | * | ||
37 | * $mobi = new MOBI(); | ||
38 | * | ||
39 | * //Then use one of the following ways to prepare information (it should be in the form of valid html) | ||
40 | * $mobi->setInternetSource($url); //Load URL, the result will be cleaned using a Readability port | ||
41 | * $mobi->setFileSource($file); //Load a local file without any extra changes | ||
42 | * $mobi->setData($data); //Load data | ||
43 | * | ||
44 | * //If you want, you can set some optional settings (see Settings.php for all recognized settings) | ||
45 | * $options = array( | ||
46 | * "title"=>"Insert title here", | ||
47 | * "author"=>"Author" | ||
48 | * ); | ||
49 | * $mobi->setOptions($options); | ||
50 | * | ||
51 | * //Then there are two ways to output it: | ||
52 | * $mobi->save($file); //Save the file locally | ||
53 | * $mobi->download($name); //Let the client download the file, make sure the page | ||
54 | * //that calls it doesn't output anything, otherwise it might | ||
55 | * //conflict with the download. $name contains the file name, | ||
56 | * //usually something like "title.mobi" (where the title should | ||
57 | * //be cleaned so as not to contain illegal characters). | ||
58 | * | ||
59 | * | ||
60 | * @author Sander Kromwijk | ||
61 | */ | ||
62 | class MOBI { | ||
63 | private $source = false; | ||
64 | private $images = array(); | ||
65 | private $optional = array(); | ||
66 | private $imgCounter = 0; | ||
67 | private $debug = false; | ||
68 | private $prc = false; | ||
69 | |||
70 | public function __construct(){ | ||
71 | |||
72 | } | ||
73 | |||
74 | public function getTitle(){ | ||
75 | if(isset($this->optional["title"])){ | ||
76 | return $this->optional["title"]; | ||
77 | } | ||
78 | return false; | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * Set a content provider as source | ||
83 | * @param ContentProvider $content Content Provider to use | ||
84 | */ | ||
85 | public function setContentProvider($content){ | ||
86 | $this->setOptions($content->getMetaData()); | ||
87 | $this->setImages($content->getImages()); | ||
88 | $this->setData($content->getTextData()); | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * Set a local file as source | ||
93 | * @param string $file Path to the file | ||
94 | */ | ||
95 | public function setFileSource($file){ | ||
96 | $this->setData(file_get_contents($file)); | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * Set the data to use | ||
101 | * @param string $data Data to put in the file | ||
102 | */ | ||
103 | public function setData($data){ | ||
104 | //$data = utf8_encode($data); | ||
105 | $data = CharacterEntities::convert($data); | ||
106 | //$data = utf8_decode($data); | ||
107 | //$this->source = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $data); | ||
108 | $this->source = $data; | ||
109 | $this->prc = false; | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * Set the images to use | ||
114 | * @param array $data Data to put in the file | ||
115 | */ | ||
116 | public function setImages($data){ | ||
117 | $this->images = $data; | ||
118 | $this->prc = false; | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * Set options, usually for things like titles, authors, etc... | ||
123 | * @param array $options Options to set | ||
124 | */ | ||
125 | public function setOptions($options){ | ||
126 | $this->optional = $options; | ||
127 | $this->prc = false; | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * Prepare the prc file | ||
132 | * @return Prc The file that can be used to be saved/downloaded | ||
133 | */ | ||
134 | private function preparePRC(){ | ||
135 | if($this->source === false){ | ||
136 | throw new Exception("No data set"); | ||
137 | } | ||
138 | if($this->prc !== false) return $this->prc; | ||
139 | |||
140 | $data = $this->source; | ||
141 | $len = strlen($data); | ||
142 | |||
143 | $settings = new Settings($this->optional); | ||
144 | $rec = new RecordFactory($settings); | ||
145 | $dataRecords = $rec->createRecords($data); | ||
146 | $nRecords = sizeof($dataRecords); | ||
147 | $mobiHeader = new PalmRecord($settings, $dataRecords, $nRecords, $len, sizeof($this->images)); | ||
148 | array_unshift($dataRecords, $mobiHeader); | ||
149 | $dataRecords = array_merge($dataRecords, $this->images); | ||
150 | $dataRecords[] = $rec->createFLISRecord(); | ||
151 | $dataRecords[] = $rec->createFCISRecord($len); | ||
152 | $dataRecords[] = $rec->createEOFRecord(); | ||
153 | $this->prc = new Prc($settings, $dataRecords); | ||
154 | return $this->prc; | ||
155 | } | ||
156 | |||
157 | /** | ||
158 | * Save the file locally | ||
159 | * @param string $filename Path to save the file | ||
160 | */ | ||
161 | public function save($filename){ | ||
162 | $prc = $this->preparePRC(); | ||
163 | $prc->save($filename); | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * Let the client download the file. Warning! No data should be | ||
168 | * outputted before or after. | ||
169 | * @param string $name Name used for download, usually "title.mobi" | ||
170 | */ | ||
171 | public function download($name){ | ||
172 | $prc = $this->preparePRC(); | ||
173 | $data = $prc->serialize(); | ||
174 | $length = strlen($data); | ||
175 | |||
176 | if($this->debug) return; //In debug mode, don't start the download | ||
177 | |||
178 | header("Content-Type: application/x-mobipocket-ebook"); | ||
179 | header("Content-Disposition: attachment; filename=\"".$name."\""); | ||
180 | header("Content-Transfer-Encoding: binary"); | ||
181 | header("Accept-Ranges: bytes"); | ||
182 | header("Cache-control: private"); | ||
183 | header('Pragma: private'); | ||
184 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); | ||
185 | header("Content-Length: ".$length); | ||
186 | |||
187 | echo $data; | ||
188 | //Finished! | ||
189 | } | ||
190 | |||
191 | } | ||
192 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/MOBIFile.php b/inc/3rdparty/libraries/MOBIClass/MOBIFile.php deleted file mode 100644 index 349227ae..00000000 --- a/inc/3rdparty/libraries/MOBIClass/MOBIFile.php +++ /dev/null | |||
@@ -1,157 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * This is the way MOBI files should be created if you want all features (TOC, images). | ||
4 | * | ||
5 | * File modified by Dawson for use in eBook Creator | ||
6 | * Added pagebreaks and a setting to remove table of contents. | ||
7 | */ | ||
8 | |||
9 | class MOBIFile extends ContentProvider { | ||
10 | const PARAGRAPH = 0; | ||
11 | const H2 = 1; | ||
12 | const H3 = 2; | ||
13 | const IMAGE = 3; | ||
14 | const PAGEBREAK = 4; | ||
15 | |||
16 | private $settings = array("title" => "Unknown Title", "toc" => true); | ||
17 | private $parts = array(); | ||
18 | private $images = array(); | ||
19 | |||
20 | /** | ||
21 | * Get the text data (the "html" code) | ||
22 | */ | ||
23 | public function getTextData(){ | ||
24 | $prefix = "<html><head><guide><reference title='CONTENT' type='toc' filepos=0000000000 /></guide></head><body>"; | ||
25 | |||
26 | $title = "<h1>".$this->settings["title"]."</h1>"; | ||
27 | |||
28 | list($text, $entries) = $this->generateText(); | ||
29 | |||
30 | if($this->settings["toc"]) { | ||
31 | $toc = $this->generateTOC($entries); //Generate TOC to get the right length | ||
32 | $toc = $this->generateTOC($entries, strlen($prefix)+strlen($toc)+strlen($title)); //Generate the real TOC | ||
33 | } | ||
34 | |||
35 | $suffix = "</body></html>"; | ||
36 | |||
37 | return $prefix.$toc.$title.$text.$suffix; | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * Generate the body's text and the chapter entries | ||
42 | * @return array($string, $entries) $string is the html data, $entries | ||
43 | * contains the level, the title and the position of the titles. | ||
44 | */ | ||
45 | public function generateText(){ | ||
46 | $str = ""; | ||
47 | $entries = array(); | ||
48 | |||
49 | for($i = 0; $i < sizeof($this->parts); $i++){ | ||
50 | list($type, $data) = $this->parts[$i]; | ||
51 | $id = "title_".$i; | ||
52 | switch($type){ | ||
53 | case self::PARAGRAPH: | ||
54 | $str .= "<p>".$data."</p>"; | ||
55 | break; | ||
56 | case self::PAGEBREAK: | ||
57 | $str .= '<mbp:pagebreak/>'; | ||
58 | break; | ||
59 | case self::H2: | ||
60 | $entries[] = array("level" => 2, "position" => strlen($str), "title" => $data, "id" => $id); | ||
61 | $str .= "<h2 id='" . $id . "'>".$data."</h2>"; | ||
62 | break; | ||
63 | case self::H3: | ||
64 | $entries[] = array("level" => 3, "position" => strlen($str), "title" => $data, "id" => $id); | ||
65 | $str .= "<h3 id='" . $id . "'>".$data."</h3>"; | ||
66 | break; | ||
67 | case self::IMAGE: | ||
68 | $str .= "<img recindex=".str_pad($data+1, 10, "0", STR_PAD_LEFT)." />"; | ||
69 | break; | ||
70 | } | ||
71 | } | ||
72 | return array($str, $entries); | ||
73 | } | ||
74 | |||
75 | /** | ||
76 | * Generate a TOC | ||
77 | * @param $entries The entries array generated by generateText | ||
78 | * @param $base The zero position | ||
79 | */ | ||
80 | public function generateTOC($entries, $base = 0){ | ||
81 | $toc = "<h2>Contents</h2>"; | ||
82 | $toc .= "<blockquote><table summary='Table of Contents'><col/><tbody>"; | ||
83 | for($i = 0, $len = sizeof($entries); $i < $len; $i++){ | ||
84 | $entry = $entries[$i]; | ||
85 | $pos = str_pad($entry["position"]+$base, 10, "0", STR_PAD_LEFT); | ||
86 | $toc .= "<tr><td><a href='#".$entry["id"]."' filepos='".$pos."'>".$entry["title"]."</a></td></tr>"; | ||
87 | } | ||
88 | return $toc."</tbody></b></table></blockquote><mbp:pagebreak/>"; | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * Get the file records of the images | ||
93 | */ | ||
94 | public function getImages(){ | ||
95 | return $this->images; | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | * Get the metadata | ||
100 | */ | ||
101 | public function getMetaData(){ | ||
102 | return $this->settings; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * Change the file's settings. For example set("author", "John Doe") or set("title", "The adventures of John Doe"). | ||
107 | * @param $key Key of the setting to insert. | ||
108 | */ | ||
109 | public function set($key, $value){ | ||
110 | $this->settings[$key] = $value; | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * Get the file's settings. | ||
115 | */ | ||
116 | public function get($key){ | ||
117 | return $this->settings[$key]; | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * Append a paragraph of text to the file. | ||
122 | * @param string $text The text to insert. | ||
123 | */ | ||
124 | public function appendParagraph($text){ | ||
125 | $this->parts[] = array(self::PARAGRAPH, $text); | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * Append a chapter title (H2) | ||
130 | * @param string $title The title to insert. | ||
131 | */ | ||
132 | public function appendChapterTitle($title){ | ||
133 | $this->parts[] = array(self::H2, $title); | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * Append a section title (H3) | ||
138 | * @param string $title The title to insert. | ||
139 | */ | ||
140 | public function appendSectionTitle($title){ | ||
141 | $this->parts[] = array(self::H3, $title); | ||
142 | } | ||
143 | |||
144 | public function appendPageBreak() { | ||
145 | $this->parts[] = array(self::PAGEBREAK, null); | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * Append an image. | ||
150 | * @param resource $img An image file (for example, created by `imagecreate`) | ||
151 | */ | ||
152 | public function appendImage($img){ | ||
153 | $imgIndex = sizeof($this->images); | ||
154 | $this->images[] = new FileRecord(new Record(ImageHandler::CreateImage($img))); | ||
155 | $this->parts[] = array(self::IMAGE, $imgIndex); | ||
156 | } | ||
157 | } \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/MultipleFileHandler.php b/inc/3rdparty/libraries/MOBIClass/MultipleFileHandler.php deleted file mode 100644 index e9792816..00000000 --- a/inc/3rdparty/libraries/MOBIClass/MultipleFileHandler.php +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of MultipleFileHandler | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | abstract class MultipleFileHandler extends ContentProvider { | ||
9 | /** | ||
10 | * @var array | ||
11 | */ | ||
12 | private $files = array(); | ||
13 | /** | ||
14 | * @var array | ||
15 | */ | ||
16 | private $images = array(); | ||
17 | /** | ||
18 | * @var array | ||
19 | */ | ||
20 | private $metadata = array(); | ||
21 | |||
22 | private $toc = array(); | ||
23 | |||
24 | /** | ||
25 | * Add a page to the file | ||
26 | * @param string $contents Contents of the chapter/page | ||
27 | * @param string $title Optional, title of the chapter/page. Will automatically add a h2 | ||
28 | * before the contents | ||
29 | */ | ||
30 | public function addPage($contents, $title = ""){ | ||
31 | if($title != ""){ | ||
32 | //TODO: Add in TOC (and add a way of generating it | ||
33 | $contents = "<h2>".$title."</h2>".$contents."<mbp:pagebreak>"; | ||
34 | } | ||
35 | $pos = 0; | ||
36 | |||
37 | if(sizeof($this->toc) > 0){ | ||
38 | $lastToc = $this->toc[sizeof($this->toc)-1]; | ||
39 | $lastFile = $this->files[sizeof($this->files)-1]; | ||
40 | $pos = $lastToc["pos"] + strlen($lastFile) + 1; | ||
41 | } | ||
42 | |||
43 | $this->files[] = $contents; | ||
44 | $this->toc[] = array("title"=>$title, "pos"=>$pos); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Add an image to the file | ||
49 | * @param string $imageContents Data string containing the binary data of the image | ||
50 | * @return int The reference of the image | ||
51 | */ | ||
52 | public function addImage($imageContents){ | ||
53 | $this->images[] = $imageContents; | ||
54 | return sizeof($this->images)-1; | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * Add an image to the file | ||
59 | * @param string $url Url to the image | ||
60 | * @return int The reference of the image, false if the image couldn't be downloaded | ||
61 | */ | ||
62 | public function addImageFromUrl($url){ | ||
63 | $image = ImageHandler::DownloadImage($url); | ||
64 | |||
65 | if($image === false) return false; | ||
66 | return $this->addImage($image); | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * Set the metadata | ||
71 | * @param string $key Key | ||
72 | * @param string $value Value | ||
73 | */ | ||
74 | public function setMetadata($key, $value){ | ||
75 | $this->metadata[$key] = $value; | ||
76 | } | ||
77 | |||
78 | /** | ||
79 | * Get the text data to be integrated in the MOBI file | ||
80 | * @return string | ||
81 | */ | ||
82 | public function getTextData(){ | ||
83 | $data = implode("\n", $this->files); | ||
84 | $begin = "<html><head><guide><reference title='CONTENT' type='toc' filepos=0000000000 /></guide></head><body>"; | ||
85 | $beforeTOC = $begin.$data; | ||
86 | |||
87 | $tocPos = strlen($beforeTOC); | ||
88 | |||
89 | $toc = $this->generateTOC(strlen($begin)); | ||
90 | |||
91 | $customBegin = "<html><head><guide><reference title='CONTENT' type='toc' filepos=".$this->forceLength($tocPos, 10)." /></guide></head><body>"; | ||
92 | $data = $customBegin.$data.$toc."</body></html>"; | ||
93 | return $data; | ||
94 | } | ||
95 | |||
96 | public function forceLength($n, $l){ | ||
97 | $str = $n.""; | ||
98 | $cur = strlen($str); | ||
99 | while($cur < $l){ | ||
100 | $str = "0".$str; | ||
101 | $cur++; | ||
102 | } | ||
103 | return $str; | ||
104 | } | ||
105 | |||
106 | public function generateTOC($base = 0){ | ||
107 | $toc = "<h2>Contents</h2>"; | ||
108 | $toc .= "<blockquote><table summary='Table of Contents'><b><col/><col/><tbody>"; | ||
109 | for($i = 0, $len = sizeof($this->toc); $i < $len; $i++){ | ||
110 | $entry = $this->toc[$i]; | ||
111 | $position = $entry["pos"]+$base; | ||
112 | $toc .= "<tr><td>".($i+1).".</td><td><a filepos=".$position.">".$entry["title"]."</a></td></tr>"; | ||
113 | } | ||
114 | $toc .= "</tbody></b></table></blockquote>"; | ||
115 | |||
116 | return $toc; | ||
117 | } | ||
118 | /** | ||
119 | * Get the images (an array containing the jpeg data). Array entry 0 will | ||
120 | * correspond to image record 0. | ||
121 | * @return array | ||
122 | */ | ||
123 | public function getImages(){ | ||
124 | return $this->images; | ||
125 | } | ||
126 | |||
127 | /** | ||
128 | * Get the metadata in the form of a hashtable (for example, title or author). | ||
129 | * @return array | ||
130 | */ | ||
131 | public function getMetaData(){ | ||
132 | return $this->metadata; | ||
133 | } | ||
134 | |||
135 | } | ||
136 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/OnlineArticle.php b/inc/3rdparty/libraries/MOBIClass/OnlineArticle.php deleted file mode 100644 index ec3182fe..00000000 --- a/inc/3rdparty/libraries/MOBIClass/OnlineArticle.php +++ /dev/null | |||
@@ -1,116 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of OnlineArticle | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class OnlineArticle extends ContentProvider { | ||
9 | private $text; | ||
10 | private $images; | ||
11 | private $metadata = array(); | ||
12 | private $imgCounter = 0; | ||
13 | |||
14 | public function __construct($url) { | ||
15 | if (!preg_match('!^https?://!i', $url)) $url = 'http://'.$url; | ||
16 | |||
17 | $data = Http::Request($url); | ||
18 | //$enc = mb_detect_encoding($str, "UTF-8,ISO-8859-1,ASCII"); | ||
19 | $html = mb_convert_encoding($data, "UTF-8", "UTF-8,ISO-8859-1,ASCII"); | ||
20 | //$html = utf8_encode($html); | ||
21 | $r = new Readability($html, $url); | ||
22 | $r->init(); | ||
23 | if(!isset($this->metadata["title"])){ | ||
24 | $this->metadata["title"] = CharacterEntities::convert(strip_tags($r->getTitle()->innerHTML)); | ||
25 | } | ||
26 | if(!isset($this->metadata["author"])){ | ||
27 | $parts = parse_url($url); | ||
28 | $this->metadata["author"] = $parts["host"]; | ||
29 | } | ||
30 | |||
31 | $article = $r->getContent()->innerHTML; | ||
32 | if(substr($article, 0, 5) == "<body"){ | ||
33 | $article = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/></head>".$article."</html>"; | ||
34 | }else{ | ||
35 | $article = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/></head><body>".$article."</body></html>"; | ||
36 | } | ||
37 | $doc = new DOMDocument(); | ||
38 | @$doc->loadHTML($article) or die($article); | ||
39 | $doc->normalizeDocument(); | ||
40 | |||
41 | $this->images = $this->handleImages($doc, $url); | ||
42 | $this->text = $doc->saveHTML(); | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * Get the text data to be integrated in the MOBI file | ||
47 | * @return string | ||
48 | */ | ||
49 | public function getTextData(){ | ||
50 | return $this->text; | ||
51 | } | ||
52 | /** | ||
53 | * Get the images (an array containing the jpeg data). Array entry 0 will | ||
54 | * correspond to image record 0. | ||
55 | * @return array | ||
56 | */ | ||
57 | public function getImages(){ | ||
58 | return $this->images; | ||
59 | } | ||
60 | /** | ||
61 | * Get the metadata in the form of a hashtable (for example, title or author). | ||
62 | * @return array | ||
63 | */ | ||
64 | public function getMetaData(){ | ||
65 | return $this->metadata; | ||
66 | } | ||
67 | /** | ||
68 | * | ||
69 | * @param DOMElement $dom | ||
70 | * @return array | ||
71 | */ | ||
72 | private function handleImages($dom, $url){ | ||
73 | $images = array(); | ||
74 | |||
75 | $parts = parse_url($url); | ||
76 | |||
77 | $savedImages = array(); | ||
78 | |||
79 | $imgElements = $dom->getElementsByTagName('img'); | ||
80 | foreach($imgElements as $img) { | ||
81 | $src = $img->getAttribute("src"); | ||
82 | |||
83 | $is_root = false; | ||
84 | if(substr($src, 0, 1) == "/"){ | ||
85 | $is_root = true; | ||
86 | } | ||
87 | |||
88 | $parsed = parse_url($src); | ||
89 | |||
90 | if(!isset($parsed["host"])){ | ||
91 | if($is_root){ | ||
92 | $src = http_build_url($url, $parsed, HTTP_URL_REPLACE); | ||
93 | }else{ | ||
94 | $src = http_build_url($url, $parsed, HTTP_URL_JOIN_PATH); | ||
95 | } | ||
96 | } | ||
97 | $img->setAttribute("src", ""); | ||
98 | if(isset($savedImages[$src])){ | ||
99 | $img->setAttribute("recindex", $savedImages[$src]); | ||
100 | }else{ | ||
101 | $image = ImageHandler::DownloadImage($src); | ||
102 | |||
103 | if($image !== false){ | ||
104 | $images[$this->imgCounter] = new FileRecord(new Record($image)); | ||
105 | |||
106 | $img->setAttribute("recindex", $this->imgCounter); | ||
107 | $savedImages[$src] = $this->imgCounter; | ||
108 | $this->imgCounter++; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | |||
113 | return $images; | ||
114 | } | ||
115 | } | ||
116 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/PalmRecord.php b/inc/3rdparty/libraries/MOBIClass/PalmRecord.php deleted file mode 100644 index d0de8dfe..00000000 --- a/inc/3rdparty/libraries/MOBIClass/PalmRecord.php +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * A Record of a PDB file | ||
4 | * | ||
5 | * @author Sander | ||
6 | */ | ||
7 | class PalmRecord extends FileObject { | ||
8 | /** | ||
9 | * @var FileElement | ||
10 | */ | ||
11 | private $elements; | ||
12 | |||
13 | public function __construct($settings, $records, $textRecords, $textLength, $images){ | ||
14 | $this->elements = new FileElement(array( | ||
15 | "compression"=>new FileShort(), | ||
16 | "unused"=>new FileShort(), | ||
17 | "textLength"=>new FileInt(), | ||
18 | "recordCount"=>new FileShort(), | ||
19 | "recordSize"=>new FileShort(), | ||
20 | "encryptionType"=>new FileShort(), | ||
21 | "unused2"=>new FileShort(), | ||
22 | //MOBI Header | ||
23 | "mobiIdentifier"=>new FileString("MOBI", 4), | ||
24 | "mobiHeaderLength"=>new FileInt(), | ||
25 | "mobiType"=>new FileInt(), | ||
26 | "textEncoding"=>new FileInt(), | ||
27 | "uniqueID"=>new FileInt(), | ||
28 | "fileVersion"=>new FileInt(), | ||
29 | "reserved"=>new FileString(40), | ||
30 | "firstNonBookIndex"=>new FileInt(), | ||
31 | "fullNameOffset"=>new FileInt(), | ||
32 | "fullNameLength"=>new FileInt(), | ||
33 | "locale"=>new FileInt(), | ||
34 | "inputLanguage"=>new FileInt(), | ||
35 | "outputLanguage"=>new FileInt(), | ||
36 | "minimumVersion"=>new FileInt(), | ||
37 | "firstImageIndex"=>new FileInt(), | ||
38 | "huffmanRecordOffset"=>new FileInt(), | ||
39 | "huffmanRecordCount"=>new FileInt(), | ||
40 | "unused3"=>new FileString(8), | ||
41 | "exthFlags"=>new FileInt(0x40), | ||
42 | "unknown"=>new FileString(32), | ||
43 | "drmOffset"=>new FileInt(0xFFFFFFFF), | ||
44 | "drmCount"=>new FileShort(0xFFFFFFFF), | ||
45 | "drmSize"=>new FileShort(), | ||
46 | "drmFlags"=>new FileInt(), | ||
47 | "mobiFiller"=>new FileString(72), | ||
48 | //EXTH Header | ||
49 | "exthIdentifier"=>new FileString("EXTH", 4), | ||
50 | "exthHeaderLength"=>new FileInt(), | ||
51 | "exthRecordCount"=>new FileInt(), | ||
52 | "exthRecords"=>new FileElement(), | ||
53 | "exthPadding"=>new FileString(), | ||
54 | //"fullNamePadding"=>new FileString(100), | ||
55 | "fullName"=>new FileString() | ||
56 | )); | ||
57 | |||
58 | //Set values from the info block | ||
59 | foreach($settings->values as $name => $val){ | ||
60 | //echo $name.", "; | ||
61 | if($this->elements->exists($name)){ | ||
62 | $this->elements->get($name)->set($settings->get($name)); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | $els = $settings->values; | ||
67 | |||
68 | $exthElems = new FileElement(); | ||
69 | $i = 0; | ||
70 | $l = 0; | ||
71 | foreach($els as $name=>$val){ | ||
72 | $type = EXTHHelper::textToType($name); | ||
73 | if($type !== false){ | ||
74 | $type = new FileInt($type); | ||
75 | $length = new FileInt(8+strlen($val)); | ||
76 | $data = new FileString($val); | ||
77 | $l += 8+strlen($val); | ||
78 | $exthElems->add("type".$i, $type); | ||
79 | $exthElems->add("length".$i, $length); | ||
80 | $exthElems->add("data".$i, $data); | ||
81 | $i++; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | if($images > 0){ | ||
86 | $this->elements->get("firstImageIndex")->set($textRecords+1); | ||
87 | } | ||
88 | $this->elements->get("firstNonBookIndex")->set($textRecords+2+$images); | ||
89 | $this->elements->get("reserved")->set(str_pad("", 40, chr(255), STR_PAD_RIGHT)); | ||
90 | $this->elements->get("exthRecordCount")->set($i); | ||
91 | $this->elements->set("exthRecords", $exthElems); | ||
92 | $pad = $l%4; | ||
93 | $pad = (4-$pad)%4; | ||
94 | $this->elements->get("exthPadding")->set(str_pad("", $pad, "\0", STR_PAD_RIGHT)); | ||
95 | $this->elements->get("exthHeaderLength")->set(12+$l+$pad); | ||
96 | |||
97 | |||
98 | $this->elements->get("recordCount")->set($textRecords); | ||
99 | |||
100 | $this->elements->get("fullNameOffset")->set($this->elements->offsetToEntry("fullName")); | ||
101 | $this->elements->get("fullNameLength")->set(strlen($settings->get("title"))); | ||
102 | $this->elements->get("fullName")->set($settings->get("title")); | ||
103 | $this->elements->get("textLength")->set($textLength); | ||
104 | } | ||
105 | |||
106 | public function getByteLength(){ | ||
107 | return $this->getLength(); | ||
108 | } | ||
109 | |||
110 | public function getLength(){ | ||
111 | return $this->elements->getByteLength(); | ||
112 | } | ||
113 | |||
114 | public function get(){ | ||
115 | return $this; | ||
116 | } | ||
117 | |||
118 | public function set($elements){ | ||
119 | throw new Exception("Unallowed set"); | ||
120 | } | ||
121 | |||
122 | public function serialize() { | ||
123 | return $this->elements->serialize(); | ||
124 | } | ||
125 | |||
126 | public function unserialize($data) { | ||
127 | $this->elements->unserialize($data); | ||
128 | } | ||
129 | |||
130 | public function __toString(){ | ||
131 | $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n"; | ||
132 | $output .= $this->elements; | ||
133 | return $output; | ||
134 | } | ||
135 | } | ||
136 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/Prc.php b/inc/3rdparty/libraries/MOBIClass/Prc.php deleted file mode 100644 index c40b5805..00000000 --- a/inc/3rdparty/libraries/MOBIClass/Prc.php +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of Prc | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class Prc extends FileElement { | ||
9 | public function __construct($settings, $records){ | ||
10 | parent::__construct(array( | ||
11 | "title"=>new FileString(32), | ||
12 | "attributes"=>new FileShort(), | ||
13 | "version"=>new FileShort(), | ||
14 | "creationTime"=>new FileDate(), | ||
15 | "modificationTime"=>new FileDate(), | ||
16 | "backupTime"=>new FileDate(), | ||
17 | "modificationNumber"=>new FileInt(), | ||
18 | "appInfoID"=>new FileInt(), | ||
19 | "sortInfoID"=>new FileInt(), | ||
20 | "prcType"=>new FileString(4), | ||
21 | "creator"=>new FileString(4), | ||
22 | "uniqueIDSeed"=>new FileInt(), | ||
23 | "nextRecordListID"=>new FileInt(), | ||
24 | "numberRecords"=>new FileShort(), | ||
25 | "recordList"=>new FileElement(), | ||
26 | "filler"=>new FileShort(), | ||
27 | "records"=>new FileElement() | ||
28 | )); | ||
29 | |||
30 | //Set values from the info block | ||
31 | foreach($this->elements as $name => $val){ | ||
32 | if($settings->exists($name)){ | ||
33 | $this->get($name)->set($settings->get($name)); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | $this->get("numberRecords")->set(sizeof($records)); | ||
38 | |||
39 | $i = 0; | ||
40 | foreach($records as $record){ | ||
41 | $offset = new FileInt(); | ||
42 | $attr = new FileByte(); | ||
43 | $uniqueID = new FileTri($i); | ||
44 | |||
45 | $this->elements["recordList"]->add("Rec".$i, new FileElement(array( | ||
46 | "offset"=>$offset, | ||
47 | "attribute"=>$attr, | ||
48 | "uniqueID"=>$uniqueID | ||
49 | ))); | ||
50 | |||
51 | $this->elements["records"]->add("Rec".$i, $record); | ||
52 | $i++; | ||
53 | } | ||
54 | |||
55 | $this->updateOffsets($records); | ||
56 | } | ||
57 | |||
58 | public function getByteLength(){ | ||
59 | throw new Exception("Test"); | ||
60 | } | ||
61 | |||
62 | public function updateOffsets($records){ | ||
63 | $base = $this->offsetToEntry("records"); | ||
64 | |||
65 | $i = 0; | ||
66 | |||
67 | foreach($records as $record){ | ||
68 | $el = $this->elements["recordList"]->get("Rec".$i); | ||
69 | |||
70 | $local = $this->elements["records"]->offsetToEntry("Rec".$i); | ||
71 | |||
72 | $el->get("offset")->set($base+$local); | ||
73 | |||
74 | $i++; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | public function save($file){ | ||
79 | $handle = fopen($file, "w"); | ||
80 | fwrite($handle, $this->serialize()); | ||
81 | fclose($handle); | ||
82 | } | ||
83 | |||
84 | public function output(){ | ||
85 | echo $this->serialize(); | ||
86 | } | ||
87 | |||
88 | public function __toString(){ | ||
89 | $output = "Prc (".$this->getByteLength()." bytes): {\n"; | ||
90 | foreach($this->elements as $key=>$value){ | ||
91 | $output .= "\t".$key.": ".$value."\n"; | ||
92 | } | ||
93 | $output .= "}"; | ||
94 | return $output; | ||
95 | } | ||
96 | } | ||
97 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php b/inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php deleted file mode 100644 index 2e992404..00000000 --- a/inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of OnlineArticle | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class PreprocessedArticle extends ContentProvider { | ||
9 | private $text; | ||
10 | private $images; | ||
11 | private $metadata = array(); | ||
12 | private $imgCounter = 0; | ||
13 | |||
14 | public function __construct($textData, $imageLinks, $metadata) { | ||
15 | $this->text = $textData; | ||
16 | $this->metadata = $metadata; | ||
17 | |||
18 | $this->images = $this->downloadImages($imageLinks); | ||
19 | } | ||
20 | |||
21 | /** | ||
22 | * Create a Preprocessed article from a json string | ||
23 | * @param string $json JSON data. Should be of the following format: | ||
24 | * {"text": "TEXT", "images: ["imageURL1", "imageURL2"], "metadata": {"key": "value"}} | ||
25 | * | ||
26 | * Note: Any image tags should have the recindex attribute set to the appropriate index (the | ||
27 | * same index as the image in the array) | ||
28 | * @return PreprocessedArticle The generated preprocessed array | ||
29 | */ | ||
30 | static public function CreateFromJson($json){ | ||
31 | $data = json_decode($json); | ||
32 | return new PreprocessedArticle($data["text"], $data["images"], $data["metadata"]); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Get the text data to be integrated in the MOBI file | ||
37 | * @return string | ||
38 | */ | ||
39 | public function getTextData(){ | ||
40 | return $this->text; | ||
41 | } | ||
42 | /** | ||
43 | * Get the images (an array containing the jpeg data). Array entry 0 will | ||
44 | * correspond to image record 0. | ||
45 | * @return array | ||
46 | */ | ||
47 | public function getImages(){ | ||
48 | return $this->images; | ||
49 | } | ||
50 | /** | ||
51 | * Get the metadata in the form of a hashtable (for example, title or author). | ||
52 | * @return array | ||
53 | */ | ||
54 | public function getMetaData(){ | ||
55 | return $this->metadata; | ||
56 | } | ||
57 | /** | ||
58 | * | ||
59 | * @param DOMElement $dom | ||
60 | * @return array | ||
61 | */ | ||
62 | private function downloadImages($links){ | ||
63 | $images = array(); | ||
64 | foreach($links as $link) { | ||
65 | $imgFile = @imagecreatefromstring(Http::Request($link)); | ||
66 | |||
67 | if($imgFile === false){ | ||
68 | $imgFile = @imagecreate(1, 1); | ||
69 | $black = @imagecolorallocate($imgFile, 255, 255, 255); | ||
70 | } | ||
71 | if($imgFile !== false){ | ||
72 | @imagefilter($imgFile, IMG_FILTER_GRAYSCALE); | ||
73 | |||
74 | ob_start(); | ||
75 | @imagejpeg($imgFile); | ||
76 | $image = ob_get_contents(); | ||
77 | ob_end_clean(); | ||
78 | |||
79 | $images[$this->imgCounter] = new FileRecord(new Record($image)); | ||
80 | imagedestroy($imgFile); | ||
81 | |||
82 | $this->imgCounter++; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | return $images; | ||
87 | } | ||
88 | } | ||
89 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/RecognizeURL.php b/inc/3rdparty/libraries/MOBIClass/RecognizeURL.php deleted file mode 100644 index 6319ed57..00000000 --- a/inc/3rdparty/libraries/MOBIClass/RecognizeURL.php +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of RecognizeURL | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class RecognizeURL { | ||
9 | public static function GetContentHandler($url){ | ||
10 | if(FanFictionNet::Matches($url)){ | ||
11 | return new FanFictionNet($url); | ||
12 | } | ||
13 | return null; | ||
14 | } | ||
15 | } | ||
16 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/Record.php b/inc/3rdparty/libraries/MOBIClass/Record.php deleted file mode 100644 index 3cb39582..00000000 --- a/inc/3rdparty/libraries/MOBIClass/Record.php +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * A Record of a PDB file | ||
4 | * | ||
5 | * @author Sander | ||
6 | */ | ||
7 | class Record extends FileObject { | ||
8 | /** | ||
9 | * Data in the record | ||
10 | * @var string | ||
11 | */ | ||
12 | private $data; | ||
13 | /** | ||
14 | * Length of the record | ||
15 | * @var int | ||
16 | */ | ||
17 | private $length; | ||
18 | |||
19 | /** | ||
20 | * Create a record | ||
21 | * @param string $data Data contained in the record | ||
22 | * @param int $length Length of the record (if set to -1, | ||
23 | * the length of $data will be taken) | ||
24 | */ | ||
25 | public function __construct($data = "", $length = -1){ | ||
26 | $this->data = $data; | ||
27 | if($length >= 0){ | ||
28 | $this->length = $length; | ||
29 | }else{ | ||
30 | $this->length = strlen($data); | ||
31 | } | ||
32 | } | ||
33 | |||
34 | public function compress($compression_method){ | ||
35 | switch($compression_method){ | ||
36 | case NO_COMPRESSION: | ||
37 | //Finished! | ||
38 | break; | ||
39 | case PALMDOC_COMPRESSION: | ||
40 | throw new Exception("Not implemented yet"); | ||
41 | break; | ||
42 | case HUFF: | ||
43 | throw new Exception("Not implemented yet"); | ||
44 | break; | ||
45 | default: | ||
46 | throw new Exception("Invalid argument"); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | public function getByteLength(){ | ||
51 | return $this->getLength(); | ||
52 | } | ||
53 | |||
54 | /** | ||
55 | * Get the length of the record | ||
56 | * @return int Length of the data | ||
57 | */ | ||
58 | public function getLength(){ | ||
59 | return $this->length; | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Get the data contained in the record | ||
64 | * @return string Data contained in the record | ||
65 | */ | ||
66 | public function get(){ | ||
67 | return $this->data; | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Set the data contained in the record | ||
72 | * @param string $value Data contained in the record | ||
73 | */ | ||
74 | public function set($value){ | ||
75 | $this->data = $value; | ||
76 | } | ||
77 | |||
78 | public function serialize(){ | ||
79 | return $this->data; | ||
80 | } | ||
81 | public function unserialize($data){ | ||
82 | __construct($data); | ||
83 | } | ||
84 | |||
85 | public function __toString() { | ||
86 | $toShow = $this->data; | ||
87 | if(strlen($this->data) > 103){ | ||
88 | $toShow = substr($this->data, 0, 100)."..."; | ||
89 | } | ||
90 | $out = "Record: {\n"; | ||
91 | $out .= "\t".htmlspecialchars($toShow)."\n"; | ||
92 | $out .= "}"; | ||
93 | return $out; | ||
94 | } | ||
95 | } | ||
96 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/RecordFactory.php b/inc/3rdparty/libraries/MOBIClass/RecordFactory.php deleted file mode 100644 index 12806fe3..00000000 --- a/inc/3rdparty/libraries/MOBIClass/RecordFactory.php +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Helper class to help with creating records from a | ||
5 | * long data stream | ||
6 | * | ||
7 | * @author Sander | ||
8 | */ | ||
9 | class RecordFactory { | ||
10 | /** | ||
11 | * Settings for the record factory | ||
12 | * @var Settings | ||
13 | */ | ||
14 | private $settings; | ||
15 | |||
16 | /** | ||
17 | * Create the helper class | ||
18 | * @param Settings $settings The Settings to be used for the records | ||
19 | */ | ||
20 | public function __construct($settings){ | ||
21 | $this->settings = $settings; | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * Create records from a data string | ||
26 | * @param string $data | ||
27 | * @return array(Record) | ||
28 | */ | ||
29 | public function createRecords($data){ | ||
30 | $records = array(); | ||
31 | $size = $this->settings->get("recordSize"); | ||
32 | $compression = $this->settings->get("compression"); | ||
33 | |||
34 | $dataEntries = mb_str_split($data, $size); | ||
35 | |||
36 | for($i = 0, $len = sizeof($dataEntries); $i < $len; $i++){ | ||
37 | $records[$i] = new Record($dataEntries[$i]); | ||
38 | $records[$i]->compress($compression); | ||
39 | } | ||
40 | |||
41 | return $records; | ||
42 | } | ||
43 | |||
44 | public function createEOFRecord(){ | ||
45 | return new Record(0xe98e0d0a); | ||
46 | } | ||
47 | |||
48 | public function createFCISRecord($textLength){ | ||
49 | $r = "FCIS"; | ||
50 | $r .= $this->asString(20, 4); | ||
51 | $r .= $this->asString(16, 4); | ||
52 | $r .= $this->asString(1, 4); | ||
53 | $r .= $this->asString(0, 4); | ||
54 | $r .= $this->asString($textLength, 4); | ||
55 | $r .= $this->asString(0, 4); | ||
56 | $r .= $this->asString(32, 4); | ||
57 | $r .= $this->asString(8, 4); | ||
58 | $r .= $this->asString(1, 2); | ||
59 | $r .= $this->asString(1, 2); | ||
60 | $r .= $this->asString(0, 4); | ||
61 | return new Record($r); | ||
62 | } | ||
63 | |||
64 | public function createFLISRecord(){ | ||
65 | $r = "FLIS"; | ||
66 | $r .= $this->asString(8, 4); | ||
67 | $r .= $this->asString(65, 2); | ||
68 | $r .= $this->asString(0, 2); | ||
69 | $r .= $this->asString(0, 4); | ||
70 | $r .= $this->asString(-1, 4); | ||
71 | $r .= $this->asString(1, 2); | ||
72 | $r .= $this->asString(3, 2); | ||
73 | $r .= $this->asString(3, 4); | ||
74 | $r .= $this->asString(1, 4); | ||
75 | $r .= $this->asString(-1, 4); | ||
76 | return new Record($r); | ||
77 | } | ||
78 | |||
79 | private function asString($int, $size){ | ||
80 | $out = ""; | ||
81 | for($i = 0; $i < $size; $i++){ | ||
82 | if($i > 0) $out = " ".$out; | ||
83 | $byte = dechex($int & 0xFF); | ||
84 | if(strlen($byte) == 1) $byte = "0".$byte; | ||
85 | $out = $byte.$out; | ||
86 | $int = $int >> 8; | ||
87 | } | ||
88 | return $out; | ||
89 | } | ||
90 | |||
91 | public function __toString() { | ||
92 | $out = "Record Factory: {\n"; | ||
93 | $out .= "\tRecord Size: ".$this->settings->get("recordSize")."\n"; | ||
94 | $out .= "\tCompression: ".$this->settings->get("compression")."\n"; | ||
95 | $out .= "}"; | ||
96 | return $out; | ||
97 | } | ||
98 | } | ||
99 | function mb_str_split($string, $split_length = 1){ | ||
100 | mb_internal_encoding('UTF-8'); | ||
101 | mb_regex_encoding('UTF-8'); | ||
102 | |||
103 | $split_length = ($split_length <= 0) ? 1 : $split_length; | ||
104 | |||
105 | $mb_strlen = mb_strlen($string, 'utf-8'); | ||
106 | |||
107 | $array = array(); | ||
108 | |||
109 | for($i = 0; $i < $mb_strlen; $i += $split_length){ | ||
110 | $array[] = mb_substr($string, $i, $split_length); | ||
111 | } | ||
112 | |||
113 | return $array; | ||
114 | } | ||
115 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/Settings.php b/inc/3rdparty/libraries/MOBIClass/Settings.php deleted file mode 100644 index ddcf2054..00000000 --- a/inc/3rdparty/libraries/MOBIClass/Settings.php +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of Settings | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class Settings { | ||
9 | /** | ||
10 | * Values of the settings | ||
11 | * @var array | ||
12 | */ | ||
13 | public $values; | ||
14 | |||
15 | /** | ||
16 | * Construct a Settings object with the default settings. If necessary, | ||
17 | * those settings can be extended with additional settings | ||
18 | * @param array $additionalSettings Additional settings to add (should | ||
19 | * be added with a key/value pair format. | ||
20 | */ | ||
21 | public function __construct($additionalSettings = array()) { | ||
22 | // Most values shouldn't be changed (the result will be an invalid file) | ||
23 | $this->values = array( | ||
24 | "attributes"=>0, | ||
25 | "version"=>0, | ||
26 | "creationTime"=>time()+94694400, | ||
27 | "modificationTime"=>time()+94694400, | ||
28 | "backupTime"=>0, | ||
29 | "modificationNumber"=>0, | ||
30 | "appInfoID"=>0, | ||
31 | "sortInfoID"=>0, | ||
32 | "prcType"=>"BOOK", | ||
33 | "creator"=>"MOBI", | ||
34 | "uniqueIDSeed"=>rand(), | ||
35 | "nextRecordListID"=>0, | ||
36 | "recordAttributes"=>0, | ||
37 | "compression"=>NO_COMPRESSION, | ||
38 | "recordSize"=>RECORD_SIZE, | ||
39 | "encryptionType"=>NO_ENCRYPTION, | ||
40 | "mobiIdentifier"=>"MOBI", | ||
41 | "mobiHeaderLength"=>0xe8, | ||
42 | "mobiType"=>MOBIPOCKET_BOOK, | ||
43 | "textEncoding"=>UTF8, | ||
44 | "uniqueID"=>rand(), | ||
45 | "fileVersion"=>6, | ||
46 | "locale"=>0x09, | ||
47 | "inputLanguage"=>0, | ||
48 | "outputLanguage"=>0, | ||
49 | "minimumVersion"=>6, | ||
50 | "huffmanRecordOffset"=>0, | ||
51 | "huffmanRecordCount"=>0, | ||
52 | "exthFlags"=>0x40, | ||
53 | "drmOffset"=>0xFFFFFFFF, | ||
54 | "drmCount"=>0, | ||
55 | "drmSize"=>0, | ||
56 | "drmFlags"=>0, | ||
57 | "extraDataFlags"=>0, | ||
58 | "exthIdentifier"=>"EXTH", | ||
59 | // These can be changed without any risk | ||
60 | "title"=>"Unknown title", | ||
61 | "author"=>"Unknown author", | ||
62 | "subject"=>"Unknown subject" | ||
63 | ); | ||
64 | |||
65 | foreach($additionalSettings as $key=>$value){ | ||
66 | $this->values[$key] = $value; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Get a value from the settings | ||
72 | * @param string $key Key of the setting | ||
73 | * @return mixed The value of the setting | ||
74 | */ | ||
75 | public function get($key){ | ||
76 | return $this->values[$key]; | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * Checks if a value is set | ||
81 | * @param string $key Key of the setting | ||
82 | * @return bool True if the value exists | ||
83 | */ | ||
84 | public function exists($key){ | ||
85 | return isset($this->values[$key]); | ||
86 | } | ||
87 | |||
88 | public function __toString() { | ||
89 | $out = "Settings: {\n"; | ||
90 | foreach($this->values as $key=>$value){ | ||
91 | $out .= "\t".$key.": ".$value."\n"; | ||
92 | } | ||
93 | $out .= "}"; | ||
94 | return $out; | ||
95 | } | ||
96 | } | ||
97 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/constants.php b/inc/3rdparty/libraries/MOBIClass/constants.php deleted file mode 100644 index bd363118..00000000 --- a/inc/3rdparty/libraries/MOBIClass/constants.php +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | <?php | ||
2 | define("NO_COMPRESSION", 1); | ||
3 | define("PALMDOC_COMPRESSION", 2); | ||
4 | define("HUFF", 17480); | ||
5 | define("RECORD_SIZE", 4096); | ||
6 | |||
7 | define("NO_ENCRYPTION", 0); | ||
8 | |||
9 | define("MOBIPOCKET_BOOK", 2); | ||
10 | define("CP1252", 1252); | ||
11 | define("UTF8", 65001); \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/downloaders/FanFictionNet.php b/inc/3rdparty/libraries/MOBIClass/downloaders/FanFictionNet.php deleted file mode 100644 index 65d5a466..00000000 --- a/inc/3rdparty/libraries/MOBIClass/downloaders/FanFictionNet.php +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FanFictionNet | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FanFictionNet extends MultipleFileHandler { | ||
9 | private static $prefix = "http://www.fanfiction.net/s/"; | ||
10 | private $downloadedMetadata = false; | ||
11 | private $id = 0; | ||
12 | private $chapterCount = -1; | ||
13 | |||
14 | public function __construct($url) { | ||
15 | $ending = substr($url, strlen(self::$prefix)); | ||
16 | $this->id = intval(substr($ending, 0, strpos($ending, "/"))); | ||
17 | |||
18 | for($i = 1; $i <= max(1, $this->chapterCount); $i++){ | ||
19 | $this->addChapter($i); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | private function addChapter($n){ | ||
24 | $doc = new DOMDocument(); | ||
25 | $file = Http::Request(self::$prefix.$this->id."/".$n."/"); | ||
26 | @$doc->loadHTML($file) or die($file); | ||
27 | |||
28 | if(!$this->downloadedMetadata){ | ||
29 | $this->loadMetadata($doc); | ||
30 | $this->downloadedMetadata = true; | ||
31 | } | ||
32 | if($this->chapterCount < 0){ | ||
33 | $this->chapterCount = $this->getNumberChapters($doc); | ||
34 | |||
35 | if($this->chapterCount > 4){ | ||
36 | die("Too many files to download, don't use php for this!"); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | $textEl = $doc->getElementById("storytext"); | ||
41 | if($textEl == null) die("Error: ".$doc->saveHTML()); | ||
42 | $horizontalRulebars = $doc->getElementsByTagName('hr'); | ||
43 | /** | ||
44 | * @var DOMNode | ||
45 | */ | ||
46 | $hr; | ||
47 | foreach($horizontalRulebars as $hr) { | ||
48 | $hr->setAttribute("size", null); | ||
49 | $hr->setAttribute("noshade", null); | ||
50 | } | ||
51 | $text = $this->innerHtml($textEl); | ||
52 | |||
53 | $title = ""; | ||
54 | $selects = $doc->getElementsByTagName('select'); | ||
55 | foreach($selects as $select) { | ||
56 | if($select->hasAttribute("name") && $select->getAttribute("name") == "chapter"){ | ||
57 | $options = $select->getElementsByTagName("option"); | ||
58 | |||
59 | $test = $n.". "; | ||
60 | foreach($options as $option){ | ||
61 | $val = $option->nodeValue; | ||
62 | if(substr($val, 0, strlen($test)) == $test){ | ||
63 | $title = substr($val, strlen($test)); | ||
64 | break; | ||
65 | } | ||
66 | } | ||
67 | break; | ||
68 | } | ||
69 | } | ||
70 | $this->addPage($text, $title); | ||
71 | } | ||
72 | |||
73 | private function getNumberChapters($doc){ | ||
74 | $selects = $doc->getElementsByTagName('select'); | ||
75 | foreach($selects as $select) { | ||
76 | if($select->hasAttribute("name") && $select->getAttribute("name") == "chapter"){ | ||
77 | $options = $select->getElementsByTagName("option"); | ||
78 | |||
79 | $count = $options->length; | ||
80 | return $count; | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | |||
85 | private function loadMetadata($doc){ | ||
86 | //Author | ||
87 | $links = $doc->getElementsByTagName('a'); | ||
88 | foreach($links as $link) { | ||
89 | if($link == null){ | ||
90 | var_dump($link); | ||
91 | } | ||
92 | if($link->hasAttribute("href") && substr($link->getAttribute("href"), 0, 3) == "/u/"){ | ||
93 | $this->setMetadata("author", $link->nodeValue); | ||
94 | } | ||
95 | } | ||
96 | //Title | ||
97 | /* | ||
98 | $links = $doc->getElementsByTagName('link'); | ||
99 | foreach($links as $link) { | ||
100 | if($link->hasAttribute("rel") && $link->getAttribute("rel") == "canonical"){ | ||
101 | $url = $link->getAttribute("href"); | ||
102 | $title = str_replace("_", " ", substr($url, strrpos($url, "/")+1)); | ||
103 | $this->setMetadata("title", $title); | ||
104 | } | ||
105 | }*/ | ||
106 | |||
107 | //TODO: Find a more reliable way to extract the title | ||
108 | $title = $doc->getElementsByTagName("b")->item(0)->nodeValue; | ||
109 | $this->setMetadata("title", $title); | ||
110 | } | ||
111 | |||
112 | private function innerHtml($node){ | ||
113 | $doc = new DOMDocument(); | ||
114 | foreach ($node->childNodes as $child) | ||
115 | $doc->appendChild($doc->importNode($child, true)); | ||
116 | |||
117 | return $doc->saveHTML(); | ||
118 | } | ||
119 | |||
120 | public static function Matches($url){ | ||
121 | //TODO: Implement with regex | ||
122 | return strpos($url, self::$prefix) !== false; | ||
123 | } | ||
124 | } | ||
125 | ?> | ||
diff --git a/inc/3rdparty/libraries/MOBIClass/http_build_url.php b/inc/3rdparty/libraries/MOBIClass/http_build_url.php deleted file mode 100644 index b475edb0..00000000 --- a/inc/3rdparty/libraries/MOBIClass/http_build_url.php +++ /dev/null | |||
@@ -1,94 +0,0 @@ | |||
1 | <?php | ||
2 | if(!is_callable("http_build_url")){ | ||
3 | define('HTTP_URL_REPLACE', 1); // Replace every part of the first URL when there's one of the second URL | ||
4 | define('HTTP_URL_JOIN_PATH', 2); // Join relative paths | ||
5 | define('HTTP_URL_JOIN_QUERY', 4); // Join query strings | ||
6 | define('HTTP_URL_STRIP_USER', 8); // Strip any user authentication information | ||
7 | define('HTTP_URL_STRIP_PASS', 16); // Strip any password authentication information | ||
8 | define('HTTP_URL_STRIP_AUTH', 32); // Strip any authentication information | ||
9 | define('HTTP_URL_STRIP_PORT', 64); // Strip explicit port numbers | ||
10 | define('HTTP_URL_STRIP_PATH', 128); // Strip complete path | ||
11 | define('HTTP_URL_STRIP_QUERY', 256); // Strip query string | ||
12 | define('HTTP_URL_STRIP_FRAGMENT', 512); // Strip any fragments (#identifier) | ||
13 | define('HTTP_URL_STRIP_ALL', 1024); // Strip anything but scheme and host | ||
14 | |||
15 | // Build an URL | ||
16 | // The parts of the second URL will be merged into the first according to the flags argument. | ||
17 | // | ||
18 | // @param mixed (Part(s) of) an URL in form of a string or associative array like parse_url() returns | ||
19 | // @param mixed Same as the first argument | ||
20 | // @param int A bitmask of binary or'ed HTTP_URL constants (Optional)HTTP_URL_REPLACE is the default | ||
21 | // @param array If set, it will be filled with the parts of the composed url like parse_url() would return | ||
22 | function http_build_url($url, $parts = array (), $flags = HTTP_URL_REPLACE, &$new_url = false) { | ||
23 | $keys = array ( | ||
24 | 'user', | ||
25 | 'pass', | ||
26 | 'port', | ||
27 | 'path', | ||
28 | 'query', | ||
29 | 'fragment' | ||
30 | ); | ||
31 | |||
32 | // HTTP_URL_STRIP_ALL becomes all the HTTP_URL_STRIP_Xs | ||
33 | if ($flags & HTTP_URL_STRIP_ALL) { | ||
34 | $flags |= HTTP_URL_STRIP_USER; | ||
35 | $flags |= HTTP_URL_STRIP_PASS; | ||
36 | $flags |= HTTP_URL_STRIP_PORT; | ||
37 | $flags |= HTTP_URL_STRIP_PATH; | ||
38 | $flags |= HTTP_URL_STRIP_QUERY; | ||
39 | $flags |= HTTP_URL_STRIP_FRAGMENT; | ||
40 | } | ||
41 | // HTTP_URL_STRIP_AUTH becomes HTTP_URL_STRIP_USER and HTTP_URL_STRIP_PASS | ||
42 | else if ($flags & HTTP_URL_STRIP_AUTH) { | ||
43 | $flags |= HTTP_URL_STRIP_USER; | ||
44 | $flags |= HTTP_URL_STRIP_PASS; | ||
45 | } | ||
46 | |||
47 | // Parse the original URL | ||
48 | $parse_url = parse_url($url); | ||
49 | |||
50 | // Scheme and Host are always replaced | ||
51 | if (isset($parts['scheme'])) | ||
52 | $parse_url['scheme'] = $parts['scheme']; | ||
53 | |||
54 | if (isset($parts['host'])) | ||
55 | $parse_url['host'] = $parts['host']; | ||
56 | |||
57 | // (If applicable) Replace the original URL with it's new parts | ||
58 | if ($flags & HTTP_URL_REPLACE) { | ||
59 | foreach ($keys as $key) { | ||
60 | if (isset($parts[$key])) | ||
61 | $parse_url[$key] = $parts[$key]; | ||
62 | } | ||
63 | } else { | ||
64 | // Join the original URL path with the new path | ||
65 | if (isset($parts['path']) && ($flags & HTTP_URL_JOIN_PATH)) { | ||
66 | if (isset($parse_url['path'])) | ||
67 | $parse_url['path'] = rtrim(str_replace(basename($parse_url['path']), '', $parse_url['path']), '/') . '/' . ltrim($parts['path'], '/'); | ||
68 | else | ||
69 | $parse_url['path'] = $parts['path']; | ||
70 | } | ||
71 | |||
72 | // Join the original query string with the new query string | ||
73 | if (isset($parts['query']) && ($flags & HTTP_URL_JOIN_QUERY)) { | ||
74 | if (isset($parse_url['query'])) | ||
75 | $parse_url['query'] .= '&' . $parts['query']; | ||
76 | else | ||
77 | $parse_url['query'] = $parts['query']; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | // Strips all the applicable sections of the URL | ||
82 | // Note: Scheme and Host are never stripped | ||
83 | foreach ($keys as $key) { | ||
84 | if ($flags & (int)constant('HTTP_URL_STRIP_' . strtoupper($key))) | ||
85 | unset($parse_url[$key]); | ||
86 | } | ||
87 | |||
88 | $new_url = $parse_url; | ||
89 | |||
90 | return ((isset($parse_url['scheme'])) ? $parse_url['scheme'] . '://' : '') . ((isset($parse_url['user'])) ? $parse_url['user'] . ((isset($parse_url['pass'])) ? ':' . $parse_url['pass'] : '') . '@' : '') | ||
91 | . ((isset($parse_url['host'])) ? $parse_url['host'] : '') . ((isset($parse_url['port'])) ? ':' . $parse_url['port'] : '') . ((isset($parse_url['path'])) ? $parse_url['path'] : '') | ||
92 | . ((isset($parse_url['query'])) ? '?' . $parse_url['query'] : '') . ((isset($parse_url['fragment'])) ? '#' . $parse_url['fragment'] : ''); | ||
93 | } | ||
94 | } | ||
diff --git a/inc/3rdparty/libraries/readability/JSLikeHTMLElement.php b/inc/3rdparty/libraries/readability/JSLikeHTMLElement.php deleted file mode 100644 index a8eeccf4..00000000 --- a/inc/3rdparty/libraries/readability/JSLikeHTMLElement.php +++ /dev/null | |||
@@ -1,110 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * JavaScript-like HTML DOM Element | ||
4 | * | ||
5 | * This class extends PHP's DOMElement to allow | ||
6 | * users to get and set the innerHTML property of | ||
7 | * HTML elements in the same way it's done in | ||
8 | * JavaScript. | ||
9 | * | ||
10 | * Example usage: | ||
11 | * @code | ||
12 | * require_once 'JSLikeHTMLElement.php'; | ||
13 | * header('Content-Type: text/plain'); | ||
14 | * $doc = new DOMDocument(); | ||
15 | * $doc->registerNodeClass('DOMElement', 'JSLikeHTMLElement'); | ||
16 | * $doc->loadHTML('<div><p>Para 1</p><p>Para 2</p></div>'); | ||
17 | * $elem = $doc->getElementsByTagName('div')->item(0); | ||
18 | * | ||
19 | * // print innerHTML | ||
20 | * echo $elem->innerHTML; // prints '<p>Para 1</p><p>Para 2</p>' | ||
21 | * echo "\n\n"; | ||
22 | * | ||
23 | * // set innerHTML | ||
24 | * $elem->innerHTML = '<a href="http://fivefilters.org">FiveFilters.org</a>'; | ||
25 | * echo $elem->innerHTML; // prints '<a href="http://fivefilters.org">FiveFilters.org</a>' | ||
26 | * echo "\n\n"; | ||
27 | * | ||
28 | * // print document (with our changes) | ||
29 | * echo $doc->saveXML(); | ||
30 | * @endcode | ||
31 | * | ||
32 | * @author Keyvan Minoukadeh - http://www.keyvan.net - keyvan@keyvan.net | ||
33 | * @see http://fivefilters.org (the project this was written for) | ||
34 | */ | ||
35 | class JSLikeHTMLElement extends DOMElement | ||
36 | { | ||
37 | /** | ||
38 | * Used for setting innerHTML like it's done in JavaScript: | ||
39 | * @code | ||
40 | * $div->innerHTML = '<h2>Chapter 2</h2><p>The story begins...</p>'; | ||
41 | * @endcode | ||
42 | */ | ||
43 | public function __set($name, $value) { | ||
44 | if ($name == 'innerHTML') { | ||
45 | // first, empty the element | ||
46 | for ($x=$this->childNodes->length-1; $x>=0; $x--) { | ||
47 | $this->removeChild($this->childNodes->item($x)); | ||
48 | } | ||
49 | // $value holds our new inner HTML | ||
50 | if ($value != '') { | ||
51 | $f = $this->ownerDocument->createDocumentFragment(); | ||
52 | // appendXML() expects well-formed markup (XHTML) | ||
53 | $result = @$f->appendXML($value); // @ to suppress PHP warnings | ||
54 | if ($result) { | ||
55 | if ($f->hasChildNodes()) $this->appendChild($f); | ||
56 | } else { | ||
57 | // $value is probably ill-formed | ||
58 | $f = new DOMDocument(); | ||
59 | $value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8'); | ||
60 | // Using <htmlfragment> will generate a warning, but so will bad HTML | ||
61 | // (and by this point, bad HTML is what we've got). | ||
62 | // We use it (and suppress the warning) because an HTML fragment will | ||
63 | // be wrapped around <html><body> tags which we don't really want to keep. | ||
64 | // Note: despite the warning, if loadHTML succeeds it will return true. | ||
65 | $result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>'); | ||
66 | if ($result) { | ||
67 | $import = $f->getElementsByTagName('htmlfragment')->item(0); | ||
68 | foreach ($import->childNodes as $child) { | ||
69 | $importedNode = $this->ownerDocument->importNode($child, true); | ||
70 | $this->appendChild($importedNode); | ||
71 | } | ||
72 | } else { | ||
73 | // oh well, we tried, we really did. :( | ||
74 | // this element is now empty | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | } else { | ||
79 | $trace = debug_backtrace(); | ||
80 | trigger_error('Undefined property via __set(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | /** | ||
85 | * Used for getting innerHTML like it's done in JavaScript: | ||
86 | * @code | ||
87 | * $string = $div->innerHTML; | ||
88 | * @endcode | ||
89 | */ | ||
90 | public function __get($name) | ||
91 | { | ||
92 | if ($name == 'innerHTML') { | ||
93 | $inner = ''; | ||
94 | foreach ($this->childNodes as $child) { | ||
95 | $inner .= $this->ownerDocument->saveXML($child); | ||
96 | } | ||
97 | return $inner; | ||
98 | } | ||
99 | |||
100 | $trace = debug_backtrace(); | ||
101 | trigger_error('Undefined property via __get(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE); | ||
102 | return null; | ||
103 | } | ||
104 | |||
105 | public function __toString() | ||
106 | { | ||
107 | return '['.$this->tagName.']'; | ||
108 | } | ||
109 | } | ||
110 | ?> \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/readability/Readability.php b/inc/3rdparty/libraries/readability/Readability.php deleted file mode 100755 index a30012ce..00000000 --- a/inc/3rdparty/libraries/readability/Readability.php +++ /dev/null | |||
@@ -1,1152 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Arc90's Readability ported to PHP for FiveFilters.org | ||
4 | * Based on readability.js version 1.7.1 (without multi-page support) | ||
5 | * Updated to allow HTML5 parsing with html5lib | ||
6 | * Updated with lightClean mode to preserve more images and youtube/vimeo/viddler embeds | ||
7 | * ------------------------------------------------------ | ||
8 | * Original URL: http://lab.arc90.com/experiments/readability/js/readability.js | ||
9 | * Arc90's project URL: http://lab.arc90.com/experiments/readability/ | ||
10 | * JS Source: http://code.google.com/p/arc90labs-readability | ||
11 | * Ported by: Keyvan Minoukadeh, http://www.keyvan.net | ||
12 | * More information: http://fivefilters.org/content-only/ | ||
13 | * License: Apache License, Version 2.0 | ||
14 | * Requires: PHP5 | ||
15 | * Date: 2012-09-19 | ||
16 | * | ||
17 | * Differences between the PHP port and the original | ||
18 | * ------------------------------------------------------ | ||
19 | * Arc90's Readability is designed to run in the browser. It works on the DOM | ||
20 | * tree (the parsed HTML) after the page's CSS styles have been applied and | ||
21 | * Javascript code executed. This PHP port does not run inside a browser. | ||
22 | * We use PHP's ability to parse HTML to build our DOM tree, but we cannot | ||
23 | * rely on CSS or Javascript support. As such, the results will not always | ||
24 | * match Arc90's Readability. (For example, if a web page contains CSS style | ||
25 | * rules or Javascript code which hide certain HTML elements from display, | ||
26 | * Arc90's Readability will dismiss those from consideration but our PHP port, | ||
27 | * unable to understand CSS or Javascript, will not know any better.) | ||
28 | * | ||
29 | * Another significant difference is that the aim of Arc90's Readability is | ||
30 | * to re-present the main content block of a given web page so users can | ||
31 | * read it more easily in their browsers. Correct identification, clean up, | ||
32 | * and separation of the content block is only a part of this process. | ||
33 | * This PHP port is only concerned with this part, it does not include code | ||
34 | * that relates to presentation in the browser - Arc90 already do | ||
35 | * that extremely well, and for PDF output there's FiveFilters.org's | ||
36 | * PDF Newspaper: http://fivefilters.org/pdf-newspaper/. | ||
37 | * | ||
38 | * Finally, this class contains methods that might be useful for developers | ||
39 | * working on HTML document fragments. So without deviating too much from | ||
40 | * the original code (which I don't want to do because it makes debugging | ||
41 | * and updating more difficult), I've tried to make it a little more | ||
42 | * developer friendly. You should be able to use the methods here on | ||
43 | * existing DOMElement objects without passing an entire HTML document to | ||
44 | * be parsed. | ||
45 | */ | ||
46 | |||
47 | // This class allows us to do JavaScript like assignements to innerHTML | ||
48 | require_once(dirname(__FILE__).'/JSLikeHTMLElement.php'); | ||
49 | libxml_use_internal_errors(true); | ||
50 | |||
51 | // Alternative usage (for testing only!) | ||
52 | // uncomment the lines below and call Readability.php in your browser | ||
53 | // passing it the URL of the page you'd like content from, e.g.: | ||
54 | // Readability.php?url=http://medialens.org/alerts/09/090615_the_guardian_climate.php | ||
55 | |||
56 | /* | ||
57 | if (!isset($_GET['url']) || $_GET['url'] == '') { | ||
58 | die('Please pass a URL to the script. E.g. Readability.php?url=bla.com/story.html'); | ||
59 | } | ||
60 | $url = $_GET['url']; | ||
61 | if (!preg_match('!^https?://!i', $url)) $url = 'http://'.$url; | ||
62 | $html = file_get_contents($url); | ||
63 | $r = new Readability($html, $url); | ||
64 | $r->init(); | ||
65 | echo $r->articleContent->innerHTML; | ||
66 | */ | ||
67 | |||
68 | class Readability | ||
69 | { | ||
70 | public $version = '1.7.1-without-multi-page'; | ||
71 | public $convertLinksToFootnotes = false; | ||
72 | public $revertForcedParagraphElements = true; | ||
73 | public $articleTitle; | ||
74 | public $articleContent; | ||
75 | public $dom; | ||
76 | public $url = null; // optional - URL where HTML was retrieved | ||
77 | public $debug = false; | ||
78 | public $lightClean = true; // preserves more content (experimental) added 2012-09-19 | ||
79 | protected $body = null; // | ||
80 | protected $bodyCache = null; // Cache the body HTML in case we need to re-use it later | ||
81 | protected $flags = 7; // 1 | 2 | 4; // Start with all flags set. | ||
82 | protected $success = false; // indicates whether we were able to extract or not | ||
83 | |||
84 | /** | ||
85 | * All of the regular expressions in use within readability. | ||
86 | * Defined up here so we don't instantiate them repeatedly in loops. | ||
87 | **/ | ||
88 | public $regexps = array( | ||
89 | 'unlikelyCandidates' => '/combx|comment|community|disqus|extra|foot|header|menu|remark|rss|shoutbox|sidebar|sponsor|ad-break|agegate|pagination|pager|popup/i', | ||
90 | 'okMaybeItsACandidate' => '/and|article|body|column|main|shadow/i', | ||
91 | 'positive' => '/article|body|content|entry|hentry|main|page|attachment|pagination|post|text|blog|story/i', | ||
92 | 'negative' => '/combx|comment|com-|contact|foot|footer|_nav|footnote|masthead|media|meta|outbrain|promo|related|scroll|shoutbox|sidebar|sponsor|shopping|tags|tool|widget/i', | ||
93 | 'divToPElements' => '/<(a|blockquote|dl|div|img|ol|p|pre|table|ul)/i', | ||
94 | 'replaceBrs' => '/(<br[^>]*>[ \n\r\t]*){2,}/i', | ||
95 | 'replaceFonts' => '/<(\/?)font[^>]*>/i', | ||
96 | // 'trimRe' => '/^\s+|\s+$/g', // PHP has trim() | ||
97 | 'normalize' => '/\s{2,}/', | ||
98 | 'killBreaks' => '/(<br\s*\/?>(\s| ?)*){1,}/', | ||
99 | 'video' => '!//(player\.|www\.)?(youtube|vimeo|viddler)\.com!i', | ||
100 | 'skipFootnoteLink' => '/^\s*(\[?[a-z0-9]{1,2}\]?|^|edit|citation needed)\s*$/i' | ||
101 | ); | ||
102 | |||
103 | /* constants */ | ||
104 | const FLAG_STRIP_UNLIKELYS = 1; | ||
105 | const FLAG_WEIGHT_CLASSES = 2; | ||
106 | const FLAG_CLEAN_CONDITIONALLY = 4; | ||
107 | |||
108 | /** | ||
109 | * Create instance of Readability | ||
110 | * @param string UTF-8 encoded string | ||
111 | * @param string (optional) URL associated with HTML (used for footnotes) | ||
112 | * @param string which parser to use for turning raw HTML into a DOMDocument (either 'libxml' or 'html5lib') | ||
113 | */ | ||
114 | function __construct($html, $url=null, $parser='libxml') | ||
115 | { | ||
116 | $this->url = $url; | ||
117 | /* Turn all double br's into p's */ | ||
118 | $html = preg_replace($this->regexps['replaceBrs'], '</p><p>', $html); | ||
119 | $html = preg_replace($this->regexps['replaceFonts'], '<$1span>', $html); | ||
120 | $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); | ||
121 | if (trim($html) == '') $html = '<html></html>'; | ||
122 | if ($parser=='html5lib' && ($this->dom = HTML5_Parser::parse($html))) { | ||
123 | // all good | ||
124 | } else { | ||
125 | $this->dom = new DOMDocument(); | ||
126 | $this->dom->preserveWhiteSpace = false; | ||
127 | @$this->dom->loadHTML($html); | ||
128 | } | ||
129 | $this->dom->registerNodeClass('DOMElement', 'JSLikeHTMLElement'); | ||
130 | } | ||
131 | |||
132 | /** | ||
133 | * Get article title element | ||
134 | * @return DOMElement | ||
135 | */ | ||
136 | public function getTitle() { | ||
137 | return $this->articleTitle; | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * Get article content element | ||
142 | * @return DOMElement | ||
143 | */ | ||
144 | public function getContent() { | ||
145 | return $this->articleContent; | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * Runs readability. | ||
150 | * | ||
151 | * Workflow: | ||
152 | * 1. Prep the document by removing script tags, css, etc. | ||
153 | * 2. Build readability's DOM tree. | ||
154 | * 3. Grab the article content from the current dom tree. | ||
155 | * 4. Replace the current DOM tree with the new one. | ||
156 | * 5. Read peacefully. | ||
157 | * | ||
158 | * @return boolean true if we found content, false otherwise | ||
159 | **/ | ||
160 | public function init() | ||
161 | { | ||
162 | if (!isset($this->dom->documentElement)) return false; | ||
163 | $this->removeScripts($this->dom); | ||
164 | //die($this->getInnerHTML($this->dom->documentElement)); | ||
165 | |||
166 | // Assume successful outcome | ||
167 | $this->success = true; | ||
168 | |||
169 | $bodyElems = $this->dom->getElementsByTagName('body'); | ||
170 | if ($bodyElems->length > 0) { | ||
171 | if ($this->bodyCache == null) { | ||
172 | $this->bodyCache = $bodyElems->item(0)->innerHTML; | ||
173 | } | ||
174 | if ($this->body == null) { | ||
175 | $this->body = $bodyElems->item(0); | ||
176 | } | ||
177 | } | ||
178 | |||
179 | $this->prepDocument(); | ||
180 | |||
181 | //die($this->dom->documentElement->parentNode->nodeType); | ||
182 | //$this->setInnerHTML($this->dom->documentElement, $this->getInnerHTML($this->dom->documentElement)); | ||
183 | //die($this->getInnerHTML($this->dom->documentElement)); | ||
184 | |||
185 | /* Build readability's DOM tree */ | ||
186 | $overlay = $this->dom->createElement('div'); | ||
187 | $innerDiv = $this->dom->createElement('div'); | ||
188 | $articleTitle = $this->getArticleTitle(); | ||
189 | $articleContent = $this->grabArticle(); | ||
190 | |||
191 | if (!$articleContent) { | ||
192 | $this->success = false; | ||
193 | $articleContent = $this->dom->createElement('div'); | ||
194 | $articleContent->setAttribute('id', 'readability-content'); | ||
195 | $articleContent->innerHTML = '<p>Sorry, Readability was unable to parse this page for content.</p>'; | ||
196 | } | ||
197 | |||
198 | $overlay->setAttribute('id', 'readOverlay'); | ||
199 | $innerDiv->setAttribute('id', 'readInner'); | ||
200 | |||
201 | /* Glue the structure of our document together. */ | ||
202 | $innerDiv->appendChild($articleTitle); | ||
203 | $innerDiv->appendChild($articleContent); | ||
204 | $overlay->appendChild($innerDiv); | ||
205 | |||
206 | /* Clear the old HTML, insert the new content. */ | ||
207 | $this->body->innerHTML = ''; | ||
208 | $this->body->appendChild($overlay); | ||
209 | //document.body.insertBefore(overlay, document.body.firstChild); | ||
210 | $this->body->removeAttribute('style'); | ||
211 | |||
212 | $this->postProcessContent($articleContent); | ||
213 | |||
214 | // Set title and content instance variables | ||
215 | $this->articleTitle = $articleTitle; | ||
216 | $this->articleContent = $articleContent; | ||
217 | |||
218 | return $this->success; | ||
219 | } | ||
220 | |||
221 | /** | ||
222 | * Debug | ||
223 | */ | ||
224 | protected function dbg($msg) { | ||
225 | if ($this->debug) echo '* ',$msg, "\n"; | ||
226 | } | ||
227 | |||
228 | /** | ||
229 | * Run any post-process modifications to article content as necessary. | ||
230 | * | ||
231 | * @param DOMElement | ||
232 | * @return void | ||
233 | */ | ||
234 | public function postProcessContent($articleContent) { | ||
235 | if ($this->convertLinksToFootnotes && !preg_match('/wikipedia\.org/', @$this->url)) { | ||
236 | $this->addFootnotes($articleContent); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * Get the article title as an H1. | ||
242 | * | ||
243 | * @return DOMElement | ||
244 | */ | ||
245 | protected function getArticleTitle() { | ||
246 | $curTitle = ''; | ||
247 | $origTitle = ''; | ||
248 | |||
249 | try { | ||
250 | $curTitle = $origTitle = $this->getInnerText($this->dom->getElementsByTagName('title')->item(0)); | ||
251 | } catch(Exception $e) {} | ||
252 | |||
253 | if (preg_match('/ [\|\-] /', $curTitle)) | ||
254 | { | ||
255 | $curTitle = preg_replace('/(.*)[\|\-] .*/i', '$1', $origTitle); | ||
256 | |||
257 | if (count(explode(' ', $curTitle)) < 3) { | ||
258 | $curTitle = preg_replace('/[^\|\-]*[\|\-](.*)/i', '$1', $origTitle); | ||
259 | } | ||
260 | } | ||
261 | else if (strpos($curTitle, ': ') !== false) | ||
262 | { | ||
263 | $curTitle = preg_replace('/.*:(.*)/i', '$1', $origTitle); | ||
264 | |||
265 | if (count(explode(' ', $curTitle)) < 3) { | ||
266 | $curTitle = preg_replace('/[^:]*[:](.*)/i','$1', $origTitle); | ||
267 | } | ||
268 | } | ||
269 | else if(strlen($curTitle) > 150 || strlen($curTitle) < 15) | ||
270 | { | ||
271 | $hOnes = $this->dom->getElementsByTagName('h1'); | ||
272 | if($hOnes->length == 1) | ||
273 | { | ||
274 | $curTitle = $this->getInnerText($hOnes->item(0)); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | $curTitle = trim($curTitle); | ||
279 | |||
280 | if (count(explode(' ', $curTitle)) <= 4) { | ||
281 | $curTitle = $origTitle; | ||
282 | } | ||
283 | |||
284 | $articleTitle = $this->dom->createElement('h1'); | ||
285 | $articleTitle->innerHTML = $curTitle; | ||
286 | |||
287 | return $articleTitle; | ||
288 | } | ||
289 | |||
290 | /** | ||
291 | * Prepare the HTML document for readability to scrape it. | ||
292 | * This includes things like stripping javascript, CSS, and handling terrible markup. | ||
293 | * | ||
294 | * @return void | ||
295 | **/ | ||
296 | protected function prepDocument() { | ||
297 | /** | ||
298 | * In some cases a body element can't be found (if the HTML is totally hosed for example) | ||
299 | * so we create a new body node and append it to the document. | ||
300 | */ | ||
301 | if ($this->body == null) | ||
302 | { | ||
303 | $this->body = $this->dom->createElement('body'); | ||
304 | $this->dom->documentElement->appendChild($this->body); | ||
305 | } | ||
306 | $this->body->setAttribute('id', 'readabilityBody'); | ||
307 | |||
308 | /* Remove all style tags in head */ | ||
309 | $styleTags = $this->dom->getElementsByTagName('style'); | ||
310 | for ($i = $styleTags->length-1; $i >= 0; $i--) | ||
311 | { | ||
312 | $styleTags->item($i)->parentNode->removeChild($styleTags->item($i)); | ||
313 | } | ||
314 | |||
315 | /* Turn all double br's into p's */ | ||
316 | /* Note, this is pretty costly as far as processing goes. Maybe optimize later. */ | ||
317 | //document.body.innerHTML = document.body.innerHTML.replace(readability.regexps.replaceBrs, '</p><p>').replace(readability.regexps.replaceFonts, '<$1span>'); | ||
318 | // We do this in the constructor for PHP as that's when we have raw HTML - before parsing it into a DOM tree. | ||
319 | // Manipulating innerHTML as it's done in JS is not possible in PHP. | ||
320 | } | ||
321 | |||
322 | /** | ||
323 | * For easier reading, convert this document to have footnotes at the bottom rather than inline links. | ||
324 | * @see http://www.roughtype.com/archives/2010/05/experiments_in.php | ||
325 | * | ||
326 | * @return void | ||
327 | **/ | ||
328 | public function addFootnotes($articleContent) { | ||
329 | $footnotesWrapper = $this->dom->createElement('div'); | ||
330 | $footnotesWrapper->setAttribute('id', 'readability-footnotes'); | ||
331 | $footnotesWrapper->innerHTML = '<h3>References</h3>'; | ||
332 | |||
333 | $articleFootnotes = $this->dom->createElement('ol'); | ||
334 | $articleFootnotes->setAttribute('id', 'readability-footnotes-list'); | ||
335 | $footnotesWrapper->appendChild($articleFootnotes); | ||
336 | |||
337 | $articleLinks = $articleContent->getElementsByTagName('a'); | ||
338 | |||
339 | $linkCount = 0; | ||
340 | for ($i = 0; $i < $articleLinks->length; $i++) | ||
341 | { | ||
342 | $articleLink = $articleLinks->item($i); | ||
343 | $footnoteLink = $articleLink->cloneNode(true); | ||
344 | $refLink = $this->dom->createElement('a'); | ||
345 | $footnote = $this->dom->createElement('li'); | ||
346 | $linkDomain = @parse_url($footnoteLink->getAttribute('href'), PHP_URL_HOST); | ||
347 | if (!$linkDomain && isset($this->url)) $linkDomain = @parse_url($this->url, PHP_URL_HOST); | ||
348 | //linkDomain = footnoteLink.host ? footnoteLink.host : document.location.host, | ||
349 | $linkText = $this->getInnerText($articleLink); | ||
350 | |||
351 | if ((strpos($articleLink->getAttribute('class'), 'readability-DoNotFootnote') !== false) || preg_match($this->regexps['skipFootnoteLink'], $linkText)) { | ||
352 | continue; | ||
353 | } | ||
354 | |||
355 | $linkCount++; | ||
356 | |||
357 | /** Add a superscript reference after the article link */ | ||
358 | $refLink->setAttribute('href', '#readabilityFootnoteLink-' . $linkCount); | ||
359 | $refLink->innerHTML = '<small><sup>[' . $linkCount . ']</sup></small>'; | ||
360 | $refLink->setAttribute('class', 'readability-DoNotFootnote'); | ||
361 | $refLink->setAttribute('style', 'color: inherit;'); | ||
362 | |||
363 | //TODO: does this work or should we use DOMNode.isSameNode()? | ||
364 | if ($articleLink->parentNode->lastChild == $articleLink) { | ||
365 | $articleLink->parentNode->appendChild($refLink); | ||
366 | } else { | ||
367 | $articleLink->parentNode->insertBefore($refLink, $articleLink->nextSibling); | ||
368 | } | ||
369 | |||
370 | $articleLink->setAttribute('style', 'color: inherit; text-decoration: none;'); | ||
371 | $articleLink->setAttribute('name', 'readabilityLink-' . $linkCount); | ||
372 | |||
373 | $footnote->innerHTML = '<small><sup><a href="#readabilityLink-' . $linkCount . '" title="Jump to Link in Article">^</a></sup></small> '; | ||
374 | |||
375 | $footnoteLink->innerHTML = ($footnoteLink->getAttribute('title') != '' ? $footnoteLink->getAttribute('title') : $linkText); | ||
376 | $footnoteLink->setAttribute('name', 'readabilityFootnoteLink-' . $linkCount); | ||
377 | |||
378 | $footnote->appendChild($footnoteLink); | ||
379 | if ($linkDomain) $footnote->innerHTML = $footnote->innerHTML . '<small> (' . $linkDomain . ')</small>'; | ||
380 | |||
381 | $articleFootnotes->appendChild($footnote); | ||
382 | } | ||
383 | |||
384 | if ($linkCount > 0) { | ||
385 | $articleContent->appendChild($footnotesWrapper); | ||
386 | } | ||
387 | } | ||
388 | |||
389 | /** | ||
390 | * Reverts P elements with class 'readability-styled' | ||
391 | * to text nodes - which is what they were before. | ||
392 | * | ||
393 | * @param DOMElement | ||
394 | * @return void | ||
395 | */ | ||
396 | function revertReadabilityStyledElements($articleContent) { | ||
397 | $xpath = new DOMXPath($articleContent->ownerDocument); | ||
398 | $elems = $xpath->query('.//p[@class="readability-styled"]', $articleContent); | ||
399 | //$elems = $articleContent->getElementsByTagName('p'); | ||
400 | for ($i = $elems->length-1; $i >= 0; $i--) { | ||
401 | $e = $elems->item($i); | ||
402 | $e->parentNode->replaceChild($articleContent->ownerDocument->createTextNode($e->textContent), $e); | ||
403 | //if ($e->hasAttribute('class') && $e->getAttribute('class') == 'readability-styled') { | ||
404 | // $e->parentNode->replaceChild($this->dom->createTextNode($e->textContent), $e); | ||
405 | //} | ||
406 | } | ||
407 | } | ||
408 | |||
409 | /** | ||
410 | * Prepare the article node for display. Clean out any inline styles, | ||
411 | * iframes, forms, strip extraneous <p> tags, etc. | ||
412 | * | ||
413 | * @param DOMElement | ||
414 | * @return void | ||
415 | */ | ||
416 | function prepArticle($articleContent) { | ||
417 | $this->cleanStyles($articleContent); | ||
418 | $this->killBreaks($articleContent); | ||
419 | if ($this->revertForcedParagraphElements) { | ||
420 | $this->revertReadabilityStyledElements($articleContent); | ||
421 | } | ||
422 | |||
423 | /* Clean out junk from the article content */ | ||
424 | $this->cleanConditionally($articleContent, 'form'); | ||
425 | $this->clean($articleContent, 'object'); | ||
426 | $this->clean($articleContent, 'h1'); | ||
427 | |||
428 | /** | ||
429 | * If there is only one h2, they are probably using it | ||
430 | * as a header and not a subheader, so remove it since we already have a header. | ||
431 | ***/ | ||
432 | if (!$this->lightClean && ($articleContent->getElementsByTagName('h2')->length == 1)) { | ||
433 | $this->clean($articleContent, 'h2'); | ||
434 | } | ||
435 | $this->clean($articleContent, 'iframe'); | ||
436 | |||
437 | $this->cleanHeaders($articleContent); | ||
438 | |||
439 | /* Do these last as the previous stuff may have removed junk that will affect these */ | ||
440 | $this->cleanConditionally($articleContent, 'table'); | ||
441 | $this->cleanConditionally($articleContent, 'ul'); | ||
442 | $this->cleanConditionally($articleContent, 'div'); | ||
443 | |||
444 | /* Remove extra paragraphs */ | ||
445 | $articleParagraphs = $articleContent->getElementsByTagName('p'); | ||
446 | for ($i = $articleParagraphs->length-1; $i >= 0; $i--) | ||
447 | { | ||
448 | $imgCount = $articleParagraphs->item($i)->getElementsByTagName('img')->length; | ||
449 | $embedCount = $articleParagraphs->item($i)->getElementsByTagName('embed')->length; | ||
450 | $objectCount = $articleParagraphs->item($i)->getElementsByTagName('object')->length; | ||
451 | $iframeCount = $articleParagraphs->item($i)->getElementsByTagName('iframe')->length; | ||
452 | |||
453 | if ($imgCount === 0 && $embedCount === 0 && $objectCount === 0 && $iframeCount === 0 && $this->getInnerText($articleParagraphs->item($i), false) == '') | ||
454 | { | ||
455 | $articleParagraphs->item($i)->parentNode->removeChild($articleParagraphs->item($i)); | ||
456 | } | ||
457 | } | ||
458 | |||
459 | try { | ||
460 | $articleContent->innerHTML = preg_replace('/<br[^>]*>\s*<p/i', '<p', $articleContent->innerHTML); | ||
461 | //articleContent.innerHTML = articleContent.innerHTML.replace(/<br[^>]*>\s*<p/gi, '<p'); | ||
462 | } | ||
463 | catch (Exception $e) { | ||
464 | $this->dbg("Cleaning innerHTML of breaks failed. This is an IE strict-block-elements bug. Ignoring.: " . $e); | ||
465 | } | ||
466 | } | ||
467 | |||
468 | /** | ||
469 | * Initialize a node with the readability object. Also checks the | ||
470 | * className/id for special names to add to its score. | ||
471 | * | ||
472 | * @param Element | ||
473 | * @return void | ||
474 | **/ | ||
475 | protected function initializeNode($node) { | ||
476 | $readability = $this->dom->createAttribute('readability'); | ||
477 | $readability->value = 0; // this is our contentScore | ||
478 | $node->setAttributeNode($readability); | ||
479 | |||
480 | switch (strtoupper($node->tagName)) { // unsure if strtoupper is needed, but using it just in case | ||
481 | case 'DIV': | ||
482 | $readability->value += 5; | ||
483 | break; | ||
484 | |||
485 | case 'PRE': | ||
486 | case 'TD': | ||
487 | case 'BLOCKQUOTE': | ||
488 | $readability->value += 3; | ||
489 | break; | ||
490 | |||
491 | case 'ADDRESS': | ||
492 | case 'OL': | ||
493 | case 'UL': | ||
494 | case 'DL': | ||
495 | case 'DD': | ||
496 | case 'DT': | ||
497 | case 'LI': | ||
498 | case 'FORM': | ||
499 | $readability->value -= 3; | ||
500 | break; | ||
501 | |||
502 | case 'H1': | ||
503 | case 'H2': | ||
504 | case 'H3': | ||
505 | case 'H4': | ||
506 | case 'H5': | ||
507 | case 'H6': | ||
508 | case 'TH': | ||
509 | $readability->value -= 5; | ||
510 | break; | ||
511 | } | ||
512 | $readability->value += $this->getClassWeight($node); | ||
513 | } | ||
514 | |||
515 | /*** | ||
516 | * grabArticle - Using a variety of metrics (content score, classname, element types), find the content that is | ||
517 | * most likely to be the stuff a user wants to read. Then return it wrapped up in a div. | ||
518 | * | ||
519 | * @return DOMElement | ||
520 | **/ | ||
521 | protected function grabArticle($page=null) { | ||
522 | $stripUnlikelyCandidates = $this->flagIsActive(self::FLAG_STRIP_UNLIKELYS); | ||
523 | if (!$page) $page = $this->dom; | ||
524 | $allElements = $page->getElementsByTagName('*'); | ||
525 | /** | ||
526 | * First, node prepping. Trash nodes that look cruddy (like ones with the class name "comment", etc), and turn divs | ||
527 | * into P tags where they have been used inappropriately (as in, where they contain no other block level elements.) | ||
528 | * | ||
529 | * Note: Assignment from index for performance. See http://www.peachpit.com/articles/article.aspx?p=31567&seqNum=5 | ||
530 | * TODO: Shouldn't this be a reverse traversal? | ||
531 | **/ | ||
532 | $node = null; | ||
533 | $nodesToScore = array(); | ||
534 | for ($nodeIndex = 0; ($node = $allElements->item($nodeIndex)); $nodeIndex++) { | ||
535 | //for ($nodeIndex=$targetList->length-1; $nodeIndex >= 0; $nodeIndex--) { | ||
536 | //$node = $targetList->item($nodeIndex); | ||
537 | $tagName = strtoupper($node->tagName); | ||
538 | /* Remove unlikely candidates */ | ||
539 | if ($stripUnlikelyCandidates) { | ||
540 | $unlikelyMatchString = $node->getAttribute('class') . $node->getAttribute('id'); | ||
541 | if ( | ||
542 | preg_match($this->regexps['unlikelyCandidates'], $unlikelyMatchString) && | ||
543 | !preg_match($this->regexps['okMaybeItsACandidate'], $unlikelyMatchString) && | ||
544 | $tagName != 'BODY' | ||
545 | ) | ||
546 | { | ||
547 | $this->dbg('Removing unlikely candidate - ' . $unlikelyMatchString); | ||
548 | //$nodesToRemove[] = $node; | ||
549 | $node->parentNode->removeChild($node); | ||
550 | $nodeIndex--; | ||
551 | continue; | ||
552 | } | ||
553 | } | ||
554 | |||
555 | if ($tagName == 'P' || $tagName == 'TD' || $tagName == 'PRE') { | ||
556 | $nodesToScore[] = $node; | ||
557 | } | ||
558 | |||
559 | /* Turn all divs that don't have children block level elements into p's */ | ||
560 | if ($tagName == 'DIV') { | ||
561 | if (!preg_match($this->regexps['divToPElements'], $node->innerHTML)) { | ||
562 | //$this->dbg('Altering div to p'); | ||
563 | $newNode = $this->dom->createElement('p'); | ||
564 | try { | ||
565 | $newNode->innerHTML = $node->innerHTML; | ||
566 | //$nodesToReplace[] = array('new'=>$newNode, 'old'=>$node); | ||
567 | $node->parentNode->replaceChild($newNode, $node); | ||
568 | $nodeIndex--; | ||
569 | $nodesToScore[] = $node; // or $newNode? | ||
570 | } | ||
571 | catch(Exception $e) { | ||
572 | $this->dbg('Could not alter div to p, reverting back to div.: ' . $e); | ||
573 | } | ||
574 | } | ||
575 | else | ||
576 | { | ||
577 | /* EXPERIMENTAL */ | ||
578 | // TODO: change these p elements back to text nodes after processing | ||
579 | for ($i = 0, $il = $node->childNodes->length; $i < $il; $i++) { | ||
580 | $childNode = $node->childNodes->item($i); | ||
581 | if ($childNode->nodeType == 3) { // XML_TEXT_NODE | ||
582 | //$this->dbg('replacing text node with a p tag with the same content.'); | ||
583 | $p = $this->dom->createElement('p'); | ||
584 | $p->innerHTML = $childNode->nodeValue; | ||
585 | $p->setAttribute('style', 'display: inline;'); | ||
586 | $p->setAttribute('class', 'readability-styled'); | ||
587 | $childNode->parentNode->replaceChild($p, $childNode); | ||
588 | } | ||
589 | } | ||
590 | } | ||
591 | } | ||
592 | } | ||
593 | |||
594 | /** | ||
595 | * Loop through all paragraphs, and assign a score to them based on how content-y they look. | ||
596 | * Then add their score to their parent node. | ||
597 | * | ||
598 | * A score is determined by things like number of commas, class names, etc. Maybe eventually link density. | ||
599 | **/ | ||
600 | $candidates = array(); | ||
601 | for ($pt=0; $pt < count($nodesToScore); $pt++) { | ||
602 | $parentNode = $nodesToScore[$pt]->parentNode; | ||
603 | // $grandParentNode = $parentNode ? $parentNode->parentNode : null; | ||
604 | $grandParentNode = !$parentNode ? null : (($parentNode->parentNode instanceof DOMElement) ? $parentNode->parentNode : null); | ||
605 | $innerText = $this->getInnerText($nodesToScore[$pt]); | ||
606 | |||
607 | if (!$parentNode || !isset($parentNode->tagName)) { | ||
608 | continue; | ||
609 | } | ||
610 | |||
611 | /* If this paragraph is less than 25 characters, don't even count it. */ | ||
612 | if(strlen($innerText) < 25) { | ||
613 | continue; | ||
614 | } | ||
615 | |||
616 | /* Initialize readability data for the parent. */ | ||
617 | if (!$parentNode->hasAttribute('readability')) | ||
618 | { | ||
619 | $this->initializeNode($parentNode); | ||
620 | $candidates[] = $parentNode; | ||
621 | } | ||
622 | |||
623 | /* Initialize readability data for the grandparent. */ | ||
624 | if ($grandParentNode && !$grandParentNode->hasAttribute('readability') && isset($grandParentNode->tagName)) | ||
625 | { | ||
626 | $this->initializeNode($grandParentNode); | ||
627 | $candidates[] = $grandParentNode; | ||
628 | } | ||
629 | |||
630 | $contentScore = 0; | ||
631 | |||
632 | /* Add a point for the paragraph itself as a base. */ | ||
633 | $contentScore++; | ||
634 | |||
635 | /* Add points for any commas within this paragraph */ | ||
636 | $contentScore += count(explode(',', $innerText)); | ||
637 | |||
638 | /* For every 100 characters in this paragraph, add another point. Up to 3 points. */ | ||
639 | $contentScore += min(floor(strlen($innerText) / 100), 3); | ||
640 | |||
641 | /* Add the score to the parent. The grandparent gets half. */ | ||
642 | $parentNode->getAttributeNode('readability')->value += $contentScore; | ||
643 | |||
644 | if ($grandParentNode) { | ||
645 | $grandParentNode->getAttributeNode('readability')->value += $contentScore/2; | ||
646 | } | ||
647 | } | ||
648 | |||
649 | /** | ||
650 | * After we've calculated scores, loop through all of the possible candidate nodes we found | ||
651 | * and find the one with the highest score. | ||
652 | **/ | ||
653 | $topCandidate = null; | ||
654 | for ($c=0, $cl=count($candidates); $c < $cl; $c++) | ||
655 | { | ||
656 | /** | ||
657 | * Scale the final candidates score based on link density. Good content should have a | ||
658 | * relatively small link density (5% or less) and be mostly unaffected by this operation. | ||
659 | **/ | ||
660 | $readability = $candidates[$c]->getAttributeNode('readability'); | ||
661 | $readability->value = $readability->value * (1-$this->getLinkDensity($candidates[$c])); | ||
662 | |||
663 | $this->dbg('Candidate: ' . $candidates[$c]->tagName . ' (' . $candidates[$c]->getAttribute('class') . ':' . $candidates[$c]->getAttribute('id') . ') with score ' . $readability->value); | ||
664 | |||
665 | if (!$topCandidate || $readability->value > (int)$topCandidate->getAttribute('readability')) { | ||
666 | $topCandidate = $candidates[$c]; | ||
667 | } | ||
668 | } | ||
669 | |||
670 | /** | ||
671 | * If we still have no top candidate, just use the body as a last resort. | ||
672 | * We also have to copy the body node so it is something we can modify. | ||
673 | **/ | ||
674 | if ($topCandidate === null || strtoupper($topCandidate->tagName) == 'BODY') | ||
675 | { | ||
676 | $topCandidate = $this->dom->createElement('div'); | ||
677 | if ($page instanceof DOMDocument) { | ||
678 | if (!isset($page->documentElement)) { | ||
679 | // we don't have a body either? what a mess! :) | ||
680 | } else { | ||
681 | $topCandidate->innerHTML = $page->documentElement->innerHTML; | ||
682 | $page->documentElement->innerHTML = ''; | ||
683 | $this->reinitBody(); | ||
684 | $page->documentElement->appendChild($topCandidate); | ||
685 | } | ||
686 | } else { | ||
687 | $topCandidate->innerHTML = $page->innerHTML; | ||
688 | $page->innerHTML = ''; | ||
689 | $page->appendChild($topCandidate); | ||
690 | } | ||
691 | $this->initializeNode($topCandidate); | ||
692 | } | ||
693 | |||
694 | /** | ||
695 | * Now that we have the top candidate, look through its siblings for content that might also be related. | ||
696 | * Things like preambles, content split by ads that we removed, etc. | ||
697 | **/ | ||
698 | $articleContent = $this->dom->createElement('div'); | ||
699 | $articleContent->setAttribute('id', 'readability-content'); | ||
700 | $siblingScoreThreshold = max(10, ((int)$topCandidate->getAttribute('readability')) * 0.2); | ||
701 | $siblingNodes = @$topCandidate->parentNode->childNodes; | ||
702 | if (!isset($siblingNodes)) { | ||
703 | $siblingNodes = new stdClass; | ||
704 | $siblingNodes->length = 0; | ||
705 | } | ||
706 | |||
707 | for ($s=0, $sl=$siblingNodes->length; $s < $sl; $s++) | ||
708 | { | ||
709 | $siblingNode = $siblingNodes->item($s); | ||
710 | $append = false; | ||
711 | |||
712 | $this->dbg('Looking at sibling node: ' . $siblingNode->nodeName . (($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('readability')) ? (' with score ' . $siblingNode->getAttribute('readability')) : '')); | ||
713 | |||
714 | //dbg('Sibling has score ' . ($siblingNode->readability ? siblingNode.readability.contentScore : 'Unknown')); | ||
715 | |||
716 | if ($siblingNode === $topCandidate) | ||
717 | // or if ($siblingNode->isSameNode($topCandidate)) | ||
718 | { | ||
719 | $append = true; | ||
720 | } | ||
721 | |||
722 | $contentBonus = 0; | ||
723 | /* Give a bonus if sibling nodes and top candidates have the example same classname */ | ||
724 | if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->getAttribute('class') == $topCandidate->getAttribute('class') && $topCandidate->getAttribute('class') != '') { | ||
725 | $contentBonus += ((int)$topCandidate->getAttribute('readability')) * 0.2; | ||
726 | } | ||
727 | |||
728 | if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('readability') && (((int)$siblingNode->getAttribute('readability')) + $contentBonus) >= $siblingScoreThreshold) | ||
729 | { | ||
730 | $append = true; | ||
731 | } | ||
732 | |||
733 | if (strtoupper($siblingNode->nodeName) == 'P') { | ||
734 | $linkDensity = $this->getLinkDensity($siblingNode); | ||
735 | $nodeContent = $this->getInnerText($siblingNode); | ||
736 | $nodeLength = strlen($nodeContent); | ||
737 | |||
738 | if ($nodeLength > 80 && $linkDensity < 0.25) | ||
739 | { | ||
740 | $append = true; | ||
741 | } | ||
742 | else if ($nodeLength < 80 && $linkDensity === 0 && preg_match('/\.( |$)/', $nodeContent)) | ||
743 | { | ||
744 | $append = true; | ||
745 | } | ||
746 | } | ||
747 | |||
748 | if ($append) | ||
749 | { | ||
750 | $this->dbg('Appending node: ' . $siblingNode->nodeName); | ||
751 | |||
752 | $nodeToAppend = null; | ||
753 | $sibNodeName = strtoupper($siblingNode->nodeName); | ||
754 | if ($sibNodeName != 'DIV' && $sibNodeName != 'P') { | ||
755 | /* We have a node that isn't a common block level element, like a form or td tag. Turn it into a div so it doesn't get filtered out later by accident. */ | ||
756 | |||
757 | $this->dbg('Altering siblingNode of ' . $sibNodeName . ' to div.'); | ||
758 | $nodeToAppend = $this->dom->createElement('div'); | ||
759 | try { | ||
760 | $nodeToAppend->setAttribute('id', $siblingNode->getAttribute('id')); | ||
761 | $nodeToAppend->innerHTML = $siblingNode->innerHTML; | ||
762 | } | ||
763 | catch(Exception $e) | ||
764 | { | ||
765 | $this->dbg('Could not alter siblingNode to div, reverting back to original.'); | ||
766 | $nodeToAppend = $siblingNode; | ||
767 | $s--; | ||
768 | $sl--; | ||
769 | } | ||
770 | } else { | ||
771 | $nodeToAppend = $siblingNode; | ||
772 | $s--; | ||
773 | $sl--; | ||
774 | } | ||
775 | |||
776 | /* To ensure a node does not interfere with readability styles, remove its classnames */ | ||
777 | $nodeToAppend->removeAttribute('class'); | ||
778 | |||
779 | /* Append sibling and subtract from our list because it removes the node when you append to another node */ | ||
780 | $articleContent->appendChild($nodeToAppend); | ||
781 | } | ||
782 | } | ||
783 | |||
784 | /** | ||
785 | * So we have all of the content that we need. Now we clean it up for presentation. | ||
786 | **/ | ||
787 | $this->prepArticle($articleContent); | ||
788 | |||
789 | /** | ||
790 | * Now that we've gone through the full algorithm, check to see if we got any meaningful content. | ||
791 | * If we didn't, we may need to re-run grabArticle with different flags set. This gives us a higher | ||
792 | * likelihood of finding the content, and the sieve approach gives us a higher likelihood of | ||
793 | * finding the -right- content. | ||
794 | **/ | ||
795 | if (strlen($this->getInnerText($articleContent, false)) < 250) | ||
796 | { | ||
797 | // TODO: find out why element disappears sometimes, e.g. for this URL http://www.businessinsider.com/6-hedge-fund-etfs-for-average-investors-2011-7 | ||
798 | // in the meantime, we check and create an empty element if it's not there. | ||
799 | $this->reinitBody(); | ||
800 | |||
801 | if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS)) { | ||
802 | $this->removeFlag(self::FLAG_STRIP_UNLIKELYS); | ||
803 | return $this->grabArticle($this->body); | ||
804 | } | ||
805 | else if ($this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) { | ||
806 | $this->removeFlag(self::FLAG_WEIGHT_CLASSES); | ||
807 | return $this->grabArticle($this->body); | ||
808 | } | ||
809 | else if ($this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) { | ||
810 | $this->removeFlag(self::FLAG_CLEAN_CONDITIONALLY); | ||
811 | return $this->grabArticle($this->body); | ||
812 | } | ||
813 | else { | ||
814 | return false; | ||
815 | } | ||
816 | } | ||
817 | return $articleContent; | ||
818 | } | ||
819 | |||
820 | /** | ||
821 | * Remove script tags from document | ||
822 | * | ||
823 | * @param DOMElement | ||
824 | * @return void | ||
825 | */ | ||
826 | public function removeScripts($doc) { | ||
827 | $scripts = $doc->getElementsByTagName('script'); | ||
828 | for($i = $scripts->length-1; $i >= 0; $i--) | ||
829 | { | ||
830 | $scripts->item($i)->parentNode->removeChild($scripts->item($i)); | ||
831 | } | ||
832 | } | ||
833 | |||
834 | /** | ||
835 | * Get the inner text of a node. | ||
836 | * This also strips out any excess whitespace to be found. | ||
837 | * | ||
838 | * @param DOMElement $ | ||
839 | * @param boolean $normalizeSpaces (default: true) | ||
840 | * @return string | ||
841 | **/ | ||
842 | public function getInnerText($e, $normalizeSpaces=true) { | ||
843 | $textContent = ''; | ||
844 | |||
845 | if (!isset($e->textContent) || $e->textContent == '') { | ||
846 | return ''; | ||
847 | } | ||
848 | |||
849 | $textContent = trim($e->textContent); | ||
850 | |||
851 | if ($normalizeSpaces) { | ||
852 | return preg_replace($this->regexps['normalize'], ' ', $textContent); | ||
853 | } else { | ||
854 | return $textContent; | ||
855 | } | ||
856 | } | ||
857 | |||
858 | /** | ||
859 | * Get the number of times a string $s appears in the node $e. | ||
860 | * | ||
861 | * @param DOMElement $e | ||
862 | * @param string - what to count. Default is "," | ||
863 | * @return number (integer) | ||
864 | **/ | ||
865 | public function getCharCount($e, $s=',') { | ||
866 | return substr_count($this->getInnerText($e), $s); | ||
867 | } | ||
868 | |||
869 | /** | ||
870 | * Remove the style attribute on every $e and under. | ||
871 | * | ||
872 | * @param DOMElement $e | ||
873 | * @return void | ||
874 | */ | ||
875 | public function cleanStyles($e) { | ||
876 | if (!is_object($e)) return; | ||
877 | $elems = $e->getElementsByTagName('*'); | ||
878 | foreach ($elems as $elem) { | ||
879 | $elem->removeAttribute('style'); | ||
880 | } | ||
881 | } | ||
882 | |||
883 | /** | ||
884 | * Get the density of links as a percentage of the content | ||
885 | * This is the amount of text that is inside a link divided by the total text in the node. | ||
886 | * | ||
887 | * @param DOMElement $e | ||
888 | * @return number (float) | ||
889 | */ | ||
890 | public function getLinkDensity($e) { | ||
891 | $links = $e->getElementsByTagName('a'); | ||
892 | $textLength = strlen($this->getInnerText($e)); | ||
893 | $linkLength = 0; | ||
894 | for ($i=0, $il=$links->length; $i < $il; $i++) | ||
895 | { | ||
896 | $linkLength += strlen($this->getInnerText($links->item($i))); | ||
897 | } | ||
898 | if ($textLength > 0) { | ||
899 | return $linkLength / $textLength; | ||
900 | } else { | ||
901 | return 0; | ||
902 | } | ||
903 | } | ||
904 | |||
905 | /** | ||
906 | * Get an elements class/id weight. Uses regular expressions to tell if this | ||
907 | * element looks good or bad. | ||
908 | * | ||
909 | * @param DOMElement $e | ||
910 | * @return number (Integer) | ||
911 | */ | ||
912 | public function getClassWeight($e) { | ||
913 | if(!$this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) { | ||
914 | return 0; | ||
915 | } | ||
916 | |||
917 | $weight = 0; | ||
918 | |||
919 | /* Look for a special classname */ | ||
920 | if ($e->hasAttribute('class') && $e->getAttribute('class') != '') | ||
921 | { | ||
922 | if (preg_match($this->regexps['negative'], $e->getAttribute('class'))) { | ||
923 | $weight -= 25; | ||
924 | } | ||
925 | if (preg_match($this->regexps['positive'], $e->getAttribute('class'))) { | ||
926 | $weight += 25; | ||
927 | } | ||
928 | } | ||
929 | |||
930 | /* Look for a special ID */ | ||
931 | if ($e->hasAttribute('id') && $e->getAttribute('id') != '') | ||
932 | { | ||
933 | if (preg_match($this->regexps['negative'], $e->getAttribute('id'))) { | ||
934 | $weight -= 25; | ||
935 | } | ||
936 | if (preg_match($this->regexps['positive'], $e->getAttribute('id'))) { | ||
937 | $weight += 25; | ||
938 | } | ||
939 | } | ||
940 | return $weight; | ||
941 | } | ||
942 | |||
943 | /** | ||
944 | * Remove extraneous break tags from a node. | ||
945 | * | ||
946 | * @param DOMElement $node | ||
947 | * @return void | ||
948 | */ | ||
949 | public function killBreaks($node) { | ||
950 | $html = $node->innerHTML; | ||
951 | $html = preg_replace($this->regexps['killBreaks'], '<br />', $html); | ||
952 | $node->innerHTML = $html; | ||
953 | } | ||
954 | |||
955 | /** | ||
956 | * Clean a node of all elements of type "tag". | ||
957 | * (Unless it's a youtube/vimeo video. People love movies.) | ||
958 | * | ||
959 | * Updated 2012-09-18 to preserve youtube/vimeo iframes | ||
960 | * | ||
961 | * @param DOMElement $e | ||
962 | * @param string $tag | ||
963 | * @return void | ||
964 | */ | ||
965 | public function clean($e, $tag) { | ||
966 | $targetList = $e->getElementsByTagName($tag); | ||
967 | $isEmbed = ($tag == 'iframe' || $tag == 'object' || $tag == 'embed'); | ||
968 | |||
969 | for ($y=$targetList->length-1; $y >= 0; $y--) { | ||
970 | /* Allow youtube and vimeo videos through as people usually want to see those. */ | ||
971 | if ($isEmbed) { | ||
972 | $attributeValues = ''; | ||
973 | for ($i=0, $il=$targetList->item($y)->attributes->length; $i < $il; $i++) { | ||
974 | $attributeValues .= $targetList->item($y)->attributes->item($i)->value . '|'; // DOMAttr? (TODO: test) | ||
975 | } | ||
976 | |||
977 | /* First, check the elements attributes to see if any of them contain youtube or vimeo */ | ||
978 | if (preg_match($this->regexps['video'], $attributeValues)) { | ||
979 | continue; | ||
980 | } | ||
981 | |||
982 | /* Then check the elements inside this element for the same. */ | ||
983 | if (preg_match($this->regexps['video'], $targetList->item($y)->innerHTML)) { | ||
984 | continue; | ||
985 | } | ||
986 | } | ||
987 | $targetList->item($y)->parentNode->removeChild($targetList->item($y)); | ||
988 | } | ||
989 | } | ||
990 | |||
991 | /** | ||
992 | * Clean an element of all tags of type "tag" if they look fishy. | ||
993 | * "Fishy" is an algorithm based on content length, classnames, | ||
994 | * link density, number of images & embeds, etc. | ||
995 | * | ||
996 | * @param DOMElement $e | ||
997 | * @param string $tag | ||
998 | * @return void | ||
999 | */ | ||
1000 | public function cleanConditionally($e, $tag) { | ||
1001 | if (!$this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) { | ||
1002 | return; | ||
1003 | } | ||
1004 | |||
1005 | $tagsList = $e->getElementsByTagName($tag); | ||
1006 | $curTagsLength = $tagsList->length; | ||
1007 | |||
1008 | /** | ||
1009 | * Gather counts for other typical elements embedded within. | ||
1010 | * Traverse backwards so we can remove nodes at the same time without effecting the traversal. | ||
1011 | * | ||
1012 | * TODO: Consider taking into account original contentScore here. | ||
1013 | */ | ||
1014 | for ($i=$curTagsLength-1; $i >= 0; $i--) { | ||
1015 | $weight = $this->getClassWeight($tagsList->item($i)); | ||
1016 | $contentScore = ($tagsList->item($i)->hasAttribute('readability')) ? (int)$tagsList->item($i)->getAttribute('readability') : 0; | ||
1017 | |||
1018 | $this->dbg('Cleaning Conditionally ' . $tagsList->item($i)->tagName . ' (' . $tagsList->item($i)->getAttribute('class') . ':' . $tagsList->item($i)->getAttribute('id') . ')' . (($tagsList->item($i)->hasAttribute('readability')) ? (' with score ' . $tagsList->item($i)->getAttribute('readability')) : '')); | ||
1019 | |||
1020 | if ($weight + $contentScore < 0) { | ||
1021 | $tagsList->item($i)->parentNode->removeChild($tagsList->item($i)); | ||
1022 | } | ||
1023 | else if ( $this->getCharCount($tagsList->item($i), ',') < 10) { | ||
1024 | /** | ||
1025 | * If there are not very many commas, and the number of | ||
1026 | * non-paragraph elements is more than paragraphs or other ominous signs, remove the element. | ||
1027 | **/ | ||
1028 | $p = $tagsList->item($i)->getElementsByTagName('p')->length; | ||
1029 | $img = $tagsList->item($i)->getElementsByTagName('img')->length; | ||
1030 | $li = $tagsList->item($i)->getElementsByTagName('li')->length-100; | ||
1031 | $input = $tagsList->item($i)->getElementsByTagName('input')->length; | ||
1032 | $a = $tagsList->item($i)->getElementsByTagName('a')->length; | ||
1033 | |||
1034 | $embedCount = 0; | ||
1035 | $embeds = $tagsList->item($i)->getElementsByTagName('embed'); | ||
1036 | for ($ei=0, $il=$embeds->length; $ei < $il; $ei++) { | ||
1037 | if (preg_match($this->regexps['video'], $embeds->item($ei)->getAttribute('src'))) { | ||
1038 | $embedCount++; | ||
1039 | } | ||
1040 | } | ||
1041 | $embeds = $tagsList->item($i)->getElementsByTagName('iframe'); | ||
1042 | for ($ei=0, $il=$embeds->length; $ei < $il; $ei++) { | ||
1043 | if (preg_match($this->regexps['video'], $embeds->item($ei)->getAttribute('src'))) { | ||
1044 | $embedCount++; | ||
1045 | } | ||
1046 | } | ||
1047 | |||
1048 | $linkDensity = $this->getLinkDensity($tagsList->item($i)); | ||
1049 | $contentLength = strlen($this->getInnerText($tagsList->item($i))); | ||
1050 | $toRemove = false; | ||
1051 | |||
1052 | if ($this->lightClean) { | ||
1053 | $this->dbg('Light clean...'); | ||
1054 | if ( ($img > $p) && ($img > 4) ) { | ||
1055 | $this->dbg(' more than 4 images and more image elements than paragraph elements'); | ||
1056 | $toRemove = true; | ||
1057 | } else if ($li > $p && $tag != 'ul' && $tag != 'ol') { | ||
1058 | $this->dbg(' too many <li> elements, and parent is not <ul> or <ol>'); | ||
1059 | $toRemove = true; | ||
1060 | } else if ( $input > floor($p/3) ) { | ||
1061 | $this->dbg(' too many <input> elements'); | ||
1062 | $toRemove = true; | ||
1063 | } else if ($contentLength < 10 && ($embedCount === 0 && ($img === 0 || $img > 2))) { | ||
1064 | $this->dbg(' content length less than 10 chars, 0 embeds and either 0 images or more than 2 images'); | ||
1065 | $toRemove = true; | ||
1066 | } else if($weight < 25 && $linkDensity > 0.2) { | ||
1067 | $this->dbg(' weight smaller than 25 and link density above 0.2'); | ||
1068 | $toRemove = true; | ||
1069 | } else if($a > 2 && ($weight >= 25 && $linkDensity > 0.5)) { | ||
1070 | $this->dbg(' more than 2 links and weight above 25 but link density greater than 0.5'); | ||
1071 | $toRemove = true; | ||
1072 | } else if($embedCount > 3) { | ||
1073 | $this->dbg(' more than 3 embeds'); | ||
1074 | $toRemove = true; | ||
1075 | } | ||
1076 | } else { | ||
1077 | $this->dbg('Standard clean...'); | ||
1078 | if ( $img > $p ) { | ||
1079 | $this->dbg(' more image elements than paragraph elements'); | ||
1080 | $toRemove = true; | ||
1081 | } else if ($li > $p && $tag != 'ul' && $tag != 'ol') { | ||
1082 | $this->dbg(' too many <li> elements, and parent is not <ul> or <ol>'); | ||
1083 | $toRemove = true; | ||
1084 | } else if ( $input > floor($p/3) ) { | ||
1085 | $this->dbg(' too many <input> elements'); | ||
1086 | $toRemove = true; | ||
1087 | } else if ($contentLength < 25 && ($img === 0 || $img > 2) ) { | ||
1088 | $this->dbg(' content length less than 25 chars and 0 images, or more than 2 images'); | ||
1089 | $toRemove = true; | ||
1090 | } else if($weight < 25 && $linkDensity > 0.2) { | ||
1091 | $this->dbg(' weight smaller than 25 and link density above 0.2'); | ||
1092 | $toRemove = true; | ||
1093 | } else if($weight >= 25 && $linkDensity > 0.5) { | ||
1094 | $this->dbg(' weight above 25 but link density greater than 0.5'); | ||
1095 | $toRemove = true; | ||
1096 | } else if(($embedCount == 1 && $contentLength < 75) || $embedCount > 1) { | ||
1097 | $this->dbg(' 1 embed and content length smaller than 75 chars, or more than one embed'); | ||
1098 | $toRemove = true; | ||
1099 | } | ||
1100 | } | ||
1101 | |||
1102 | if ($toRemove) { | ||
1103 | //$this->dbg('Removing: '.$tagsList->item($i)->innerHTML); | ||
1104 | $tagsList->item($i)->parentNode->removeChild($tagsList->item($i)); | ||
1105 | } | ||
1106 | } | ||
1107 | } | ||
1108 | } | ||
1109 | |||
1110 | /** | ||
1111 | * Clean out spurious headers from an Element. Checks things like classnames and link density. | ||
1112 | * | ||
1113 | * @param DOMElement $e | ||
1114 | * @return void | ||
1115 | */ | ||
1116 | public function cleanHeaders($e) { | ||
1117 | for ($headerIndex = 1; $headerIndex < 3; $headerIndex++) { | ||
1118 | $headers = $e->getElementsByTagName('h' . $headerIndex); | ||
1119 | for ($i=$headers->length-1; $i >=0; $i--) { | ||
1120 | if ($this->getClassWeight($headers->item($i)) < 0 || $this->getLinkDensity($headers->item($i)) > 0.33) { | ||
1121 | $headers->item($i)->parentNode->removeChild($headers->item($i)); | ||
1122 | } | ||
1123 | } | ||
1124 | } | ||
1125 | } | ||
1126 | |||
1127 | public function flagIsActive($flag) { | ||
1128 | return ($this->flags & $flag) > 0; | ||
1129 | } | ||
1130 | |||
1131 | public function addFlag($flag) { | ||
1132 | $this->flags = $this->flags | $flag; | ||
1133 | } | ||
1134 | |||
1135 | public function removeFlag($flag) { | ||
1136 | $this->flags = $this->flags & ~$flag; | ||
1137 | } | ||
1138 | |||
1139 | /** | ||
1140 | * Will recreate previously deleted body property | ||
1141 | * | ||
1142 | * @return void | ||
1143 | */ | ||
1144 | protected function reinitBody() { | ||
1145 | if (!isset($this->body->childNodes)) { | ||
1146 | $this->body = $this->dom->createElement('body'); | ||
1147 | $this->body->innerHTML = $this->bodyCache; | ||
1148 | } | ||
1149 | } | ||
1150 | |||
1151 | } | ||
1152 | ?> | ||