diff options
Diffstat (limited to 'inc/3rdparty/libraries/send2kindle')
39 files changed, 0 insertions, 5268 deletions
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/CharacterEntities.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/CharacterEntities.php deleted file mode 100644 index de896f87..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/ContentProvider.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/ContentProvider.php deleted file mode 100644 index dcf9c4de..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/EXTHHelper.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/EXTHHelper.php deleted file mode 100644 index 275142bf..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/FileByte.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileByte.php deleted file mode 100644 index 05fc7d04..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/FileDate.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileDate.php deleted file mode 100644 index 2284eba2..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/FileElement.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileElement.php deleted file mode 100644 index 552d04a8..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/FileInt.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileInt.php deleted file mode 100644 index ebe86f86..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/FileObject.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileObject.php deleted file mode 100644 index 0df17df1..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/FileRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileRecord.php deleted file mode 100644 index 494a72e4..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/FileShort.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileShort.php deleted file mode 100644 index 9921ea82..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/FileString.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileString.php deleted file mode 100644 index 16e906a6..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/FileTri.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileTri.php deleted file mode 100644 index 6cacc0b0..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/Http.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/Http.php deleted file mode 100644 index 9e5852e3..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/ImageHandler.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/ImageHandler.php deleted file mode 100644 index f620fc1f..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/ImageHandler.php +++ /dev/null | |||
@@ -1,28 +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 | @imagefilter($imgFile, IMG_FILTER_GRAYSCALE); | ||
15 | |||
16 | ob_start(); | ||
17 | @imagejpeg($imgFile); | ||
18 | $image = ob_get_contents(); | ||
19 | ob_end_clean(); | ||
20 | |||
21 | @imagedestroy($imgFile); | ||
22 | |||
23 | return $image; | ||
24 | } | ||
25 | return false; | ||
26 | } | ||
27 | } | ||
28 | ?> | ||
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php deleted file mode 100644 index 9532bbf1..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php +++ /dev/null | |||
@@ -1,205 +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__).'/OnlineArticle.php'); | ||
22 | require_once(dirname(__FILE__).'/PalmRecord.php'); | ||
23 | require_once(dirname(__FILE__).'/PEOFRecord.php'); | ||
24 | require_once(dirname(__FILE__).'/PFCISRecord.php'); | ||
25 | require_once(dirname(__FILE__).'/PFLISRecord.php'); | ||
26 | require_once(dirname(__FILE__).'/Prc.php'); | ||
27 | require_once(dirname(__FILE__).'/PreprocessedArticle.php'); | ||
28 | require_once(dirname(__FILE__).'/RecognizeURL.php'); | ||
29 | require_once(dirname(__FILE__).'/Record.php'); | ||
30 | require_once(dirname(__FILE__).'/RecordFactory.php'); | ||
31 | require_once(dirname(__FILE__).'/Settings.php'); | ||
32 | |||
33 | /** | ||
34 | * Description of MOBI. | ||
35 | * | ||
36 | * Usage: | ||
37 | * include("MOBIClass/MOBI.php"); | ||
38 | * | ||
39 | * $mobi = new MOBI(); | ||
40 | * | ||
41 | * //Then use one of the following ways to prepare information (it should be in the form of valid html) | ||
42 | * $mobi->setInternetSource($url); //Load URL, the result will be cleaned using a Readability port | ||
43 | * $mobi->setFileSource($file); //Load a local file without any extra changes | ||
44 | * $mobi->setData($data); //Load data | ||
45 | * | ||
46 | * //If you want, you can set some optional settings | ||
47 | * $options = array( | ||
48 | * "title"=>"Insert title here", | ||
49 | * "author"=>"Author" | ||
50 | * ); | ||
51 | * $mobi->setOptions($options); | ||
52 | * | ||
53 | * //Then there are two ways to output it: | ||
54 | * $mobi->save($file); //Save the file locally | ||
55 | * $mobi->download($name); //Let the client download the file, make sure the page | ||
56 | * //that calls it doesn't output anything, otherwise it might | ||
57 | * //conflict with the download. $name contains the file name, | ||
58 | * //usually something like "title.mobi" (where the title should | ||
59 | * //be cleaned so as not to contain illegal characters). | ||
60 | * | ||
61 | * | ||
62 | * @author Sander Kromwijk | ||
63 | */ | ||
64 | class MOBI { | ||
65 | private $source = false; | ||
66 | private $images = array(); | ||
67 | private $optional = array(); | ||
68 | private $imgCounter = 0; | ||
69 | private $debug = false; | ||
70 | private $prc = false; | ||
71 | |||
72 | public function __construct(){ | ||
73 | |||
74 | } | ||
75 | |||
76 | public function getTitle(){ | ||
77 | if(isset($this->optional["title"])){ | ||
78 | return $this->optional["title"]; | ||
79 | } | ||
80 | return false; | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * Set a content provider as source | ||
85 | * @param ContentProvider $content Content Provider to use | ||
86 | */ | ||
87 | public function setContentProvider($content){ | ||
88 | $this->setOptions($content->getMetaData()); | ||
89 | $this->images = $content->getImages(); | ||
90 | $this->setData($content->getTextData()); | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * Set a local file as source | ||
95 | * @param string $file Path to the file | ||
96 | */ | ||
97 | public function setFileSource($file){ | ||
98 | $this->setData(file_get_contents($file)); | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * Set the data to use | ||
103 | * @param string $data Data to put in the file | ||
104 | */ | ||
105 | public function setData($data){ | ||
106 | //$data = utf8_encode($data); | ||
107 | $data = CharacterEntities::convert($data); | ||
108 | //$data = utf8_decode($data); | ||
109 | //$this->source = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $data); | ||
110 | $this->source = $data; | ||
111 | $this->prc = false; | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * Set the images to use | ||
116 | * @param array $data Data to put in the file | ||
117 | */ | ||
118 | public function setImages($data){ | ||
119 | $this->images = $data; | ||
120 | $this->prc = false; | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * Set options, usually for things like titles, authors, etc... | ||
125 | * @param array $options Options to set | ||
126 | */ | ||
127 | public function setOptions($options){ | ||
128 | $this->optional = $options; | ||
129 | $this->prc = false; | ||
130 | } | ||
131 | |||
132 | /** | ||
133 | * Prepare the prc file | ||
134 | * @return Prc The file that can be used to be saved/downloaded | ||
135 | */ | ||
136 | private function preparePRC(){ | ||
137 | if($this->source === false){ | ||
138 | throw new Exception("No data set"); | ||
139 | } | ||
140 | if($this->prc !== false) return $this->prc; | ||
141 | |||
142 | $data = $this->source; | ||
143 | $len = strlen($data); | ||
144 | |||
145 | $settings = new Settings($this->optional); | ||
146 | $rec = new RecordFactory($settings); | ||
147 | $dataRecords = $rec->createRecords($data); | ||
148 | $nRecords = sizeof($dataRecords); | ||
149 | $mobiHeader = new PalmRecord($settings, $dataRecords, $nRecords, $len, sizeof($this->images)); | ||
150 | array_unshift($dataRecords, $mobiHeader); | ||
151 | $dataRecords = array_merge($dataRecords, $this->images); | ||
152 | $mobiFooter1 = new PFLISRecord($len); | ||
153 | $mobiFooter2 = new PFCISRecord($len); | ||
154 | $mobiFooter3 = new PEOFRecord($len); | ||
155 | $dataRecords[] = $mobiFooter1; | ||
156 | $dataRecords[] = $mobiFooter2; | ||
157 | $dataRecords[] = $mobiFooter3; | ||
158 | /*$dataRecords = array_merge($dataRecords, $mobiFooter); | ||
159 | *$dataRecords[] = $rec->createFLISRecord();* | ||
160 | $dataRecords[] = $rec->createFCISRecord($len); | ||
161 | $dataRecords[] = $rec->createEOFRecord();*/ | ||
162 | $this->prc = new Prc($settings, $dataRecords); | ||
163 | return $this->prc; | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * Save the file locally | ||
168 | * @param string $filename Path to save the file | ||
169 | */ | ||
170 | public function save($filename){ | ||
171 | $prc = $this->preparePRC(); | ||
172 | $prc->save($filename); | ||
173 | } | ||
174 | |||
175 | /** | ||
176 | * Let the client download the file. Warning! No data should be | ||
177 | * outputted before or after. | ||
178 | * @param string $name Name used for download, usually "title.mobi" | ||
179 | */ | ||
180 | public function download($name){ | ||
181 | $prc = $this->preparePRC(); | ||
182 | $data = $prc->serialize(); | ||
183 | $length = strlen($data); | ||
184 | |||
185 | if($this->debug) return; //In debug mode, don't start the download | ||
186 | /* | ||
187 | header("Content-Type: application/x-mobipocket-ebook"); | ||
188 | header("Content-Disposition: attachment; filename=\"".$name."\""); | ||
189 | header("Content-Transfer-Encoding: binary"); | ||
190 | header("Accept-Ranges: bytes"); | ||
191 | header("Cache-control: private"); | ||
192 | header('Pragma: private'); | ||
193 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); | ||
194 | header("Content-Length: ".$length); | ||
195 | echo $data;*/ | ||
196 | |||
197 | |||
198 | $hh = fopen("D:\hakuna.mobi", "w"); | ||
199 | fwrite($hh, $data); | ||
200 | fclose($hh); | ||
201 | //Finished! | ||
202 | } | ||
203 | |||
204 | } | ||
205 | ?> \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/MultipleFileHandler.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/MultipleFileHandler.php deleted file mode 100644 index e9792816..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/OnlineArticle.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/OnlineArticle.php deleted file mode 100644 index ec3182fe..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/PEOFRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PEOFRecord.php deleted file mode 100644 index a2b0fee8..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/PEOFRecord.php +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * A Record of a End file | ||
4 | * | ||
5 | * @author Pratyush | ||
6 | */ | ||
7 | class PEOFRecord extends FileObject { | ||
8 | /** | ||
9 | * @var FileElement | ||
10 | */ | ||
11 | private $elements; | ||
12 | |||
13 | public function __construct($leng){ | ||
14 | $this->elements = new FileElement(array( | ||
15 | |||
16 | "offset44"=>new FileInt(0xe98e0d0a) | ||
17 | )); | ||
18 | } | ||
19 | public function getByteLength(){ | ||
20 | return $this->getLength(); | ||
21 | } | ||
22 | |||
23 | public function getLength(){ | ||
24 | return $this->elements->getByteLength(); | ||
25 | } | ||
26 | |||
27 | public function get(){ | ||
28 | return $this; | ||
29 | } | ||
30 | |||
31 | public function set($elements){ | ||
32 | throw new Exception("Unallowed set"); | ||
33 | } | ||
34 | |||
35 | public function serialize() { | ||
36 | return $this->elements->serialize(); | ||
37 | } | ||
38 | |||
39 | public function unserialize($data) { | ||
40 | $this->elements->unserialize($data); | ||
41 | } | ||
42 | |||
43 | public function __toString(){ | ||
44 | $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n"; | ||
45 | $output .= $this->elements; | ||
46 | return $output; | ||
47 | } | ||
48 | |||
49 | } \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/PFCISRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PFCISRecord.php deleted file mode 100644 index 9e72cc1c..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/PFCISRecord.php +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * A Record of a End file | ||
4 | * | ||
5 | * @author Pratyush | ||
6 | */ | ||
7 | class PFCISRecord extends FileObject { | ||
8 | /** | ||
9 | * @var FileElement | ||
10 | */ | ||
11 | private $elements; | ||
12 | |||
13 | public function __construct($leng){ | ||
14 | $this->elements = new FileElement(array( | ||
15 | "offset0"=>new FileString("FCIS", 4), //FCIS | ||
16 | "offset4"=>new FileInt(0x014), | ||
17 | "offset8"=>new FileInt(0x10), | ||
18 | "offset12"=>new FileInt(0x01), | ||
19 | "offset16"=>new FileInt(), | ||
20 | "offset20"=>new FileInt($leng), | ||
21 | "offset24"=>new FileInt(), | ||
22 | "offset28"=>new FileInt(0x20), | ||
23 | "offset32"=>new FileInt(0x08), | ||
24 | "offset36"=>new FileShort(0x01), | ||
25 | "offset38"=>new FileShort(0x01), | ||
26 | "offset40"=>new FileInt() | ||
27 | )); | ||
28 | } | ||
29 | public function getByteLength(){ | ||
30 | return $this->getLength(); | ||
31 | } | ||
32 | |||
33 | public function getLength(){ | ||
34 | return $this->elements->getByteLength(); | ||
35 | } | ||
36 | |||
37 | public function get(){ | ||
38 | return $this; | ||
39 | } | ||
40 | |||
41 | public function set($elements){ | ||
42 | throw new Exception("Unallowed set"); | ||
43 | } | ||
44 | |||
45 | public function serialize() { | ||
46 | return $this->elements->serialize(); | ||
47 | } | ||
48 | |||
49 | public function unserialize($data) { | ||
50 | $this->elements->unserialize($data); | ||
51 | } | ||
52 | |||
53 | public function __toString(){ | ||
54 | $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n"; | ||
55 | $output .= $this->elements; | ||
56 | return $output; | ||
57 | } | ||
58 | |||
59 | } \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/PFLISRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PFLISRecord.php deleted file mode 100644 index dbd8ecf5..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/PFLISRecord.php +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * A Record of a End file | ||
4 | * | ||
5 | * @author Pratyush | ||
6 | */ | ||
7 | class PFLISRecord extends FileObject { | ||
8 | /** | ||
9 | * @var FileElement | ||
10 | */ | ||
11 | private $elements; | ||
12 | |||
13 | public function __construct($leng){ | ||
14 | $this->elements = new FileElement(array( | ||
15 | "offsetL0"=>new FileString("FLIS", 4), //FLIS | ||
16 | "offsetL4"=>new FileInt(0x08), | ||
17 | "offsetL8"=>new FileShort(0x41), | ||
18 | "offsetL10"=>new FileString(6), | ||
19 | "offsetL16"=>new FileInt(0xFFFFFFFF), | ||
20 | "offsetL20"=>new FileShort(0x01), | ||
21 | "offsetL22"=>new FileShort(0x03), | ||
22 | "offsetL24"=>new FileInt(0x03), | ||
23 | "offsetL28"=>new FileInt(0x01), | ||
24 | "offsetL32"=>new FileInt(0xFFFFFFFF) | ||
25 | |||
26 | )); | ||
27 | } | ||
28 | public function getByteLength(){ | ||
29 | return $this->getLength(); | ||
30 | } | ||
31 | |||
32 | public function getLength(){ | ||
33 | return $this->elements->getByteLength(); | ||
34 | } | ||
35 | |||
36 | public function get(){ | ||
37 | return $this; | ||
38 | } | ||
39 | |||
40 | public function set($elements){ | ||
41 | throw new Exception("Unallowed set"); | ||
42 | } | ||
43 | |||
44 | public function serialize() { | ||
45 | return $this->elements->serialize(); | ||
46 | } | ||
47 | |||
48 | public function unserialize($data) { | ||
49 | $this->elements->unserialize($data); | ||
50 | } | ||
51 | |||
52 | public function __toString(){ | ||
53 | $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n"; | ||
54 | $output .= $this->elements; | ||
55 | return $output; | ||
56 | } | ||
57 | |||
58 | } \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/PalmRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PalmRecord.php deleted file mode 100644 index 29dc978a..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/PalmRecord.php +++ /dev/null | |||
@@ -1,154 +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(0x50), | ||
42 | "unknown"=>new FileString(32), | ||
43 | "drmOffset"=>new FileInt(0xFFFFFFFF), | ||
44 | "drmCount"=>new FileInt(0xFFFFFFFF), | ||
45 | "drmSize"=>new FileInt(), | ||
46 | "drmFlags"=>new FileInt(), | ||
47 | "mobiFiller"=>new FileString(12), | ||
48 | "offset192"=>new FileShort(0x01), | ||
49 | "offset194"=>new FileShort(), | ||
50 | "offset196"=>new FileInt(0x01), | ||
51 | "offset200"=>new FileInt(), | ||
52 | "offset204"=>new FileInt(0x01), | ||
53 | "offset208"=>new FileInt(), | ||
54 | "offset212"=>new FileInt(0x01), | ||
55 | "offset216"=>new FileString(8), | ||
56 | "offset224"=>new FileInt(0xFFFFFFFF), | ||
57 | "offset228"=>new FileInt(), | ||
58 | "offset232"=>new FileString(8), | ||
59 | "offset240"=>new FileInt(0x01), | ||
60 | "offset244"=>new FileInt(0xFFFFFFFF), | ||
61 | //EXTH Header | ||
62 | "exthIdentifier"=>new FileString("EXTH", 4), | ||
63 | "exthHeaderLength"=>new FileInt(), | ||
64 | "exthRecordCount"=>new FileInt(), | ||
65 | "exthRecords"=>new FileElement(), | ||
66 | "exthPadding"=>new FileString(),//added the 2 extra pad bytes that comes before name/title | ||
67 | //"fullNamePadding"=>new FileString(100), | ||
68 | "fullName"=>new FileString() | ||
69 | )); | ||
70 | |||
71 | //Set values from the info block | ||
72 | foreach($settings->values as $name => $val){ | ||
73 | //echo $name.", "; | ||
74 | if($this->elements->exists($name)){ | ||
75 | $this->elements->get($name)->set($settings->get($name)); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | $els = $settings->values; | ||
80 | |||
81 | $exthElems = new FileElement(); | ||
82 | $i = 0; | ||
83 | $l = 0; | ||
84 | foreach($els as $name=>$val){ | ||
85 | $type = EXTHHelper::textToType($name); | ||
86 | if($type !== false){ | ||
87 | $type = new FileInt($type); | ||
88 | $length = new FileInt(8+strlen($val)); | ||
89 | $data = new FileString($val); | ||
90 | $l += 8+strlen($val); | ||
91 | $exthElems->add("type".$i, $type); | ||
92 | $exthElems->add("length".$i, $length); | ||
93 | $exthElems->add("data".$i, $data); | ||
94 | $i++; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | if($images > 0){ | ||
99 | $this->elements->get("firstImageIndex")->set($textRecords+2); | ||
100 | } | ||
101 | $this->elements->get("firstNonBookIndex")->set($textRecords+2+$images); | ||
102 | $this->elements->get("reserved")->set(str_pad("", 40, chr(255), STR_PAD_RIGHT)); | ||
103 | $this->elements->get("exthRecordCount")->set($i); | ||
104 | $this->elements->set("exthRecords", $exthElems); | ||
105 | $pad = $l%4; | ||
106 | $pad = (4-$pad)%4; | ||
107 | $this->elements->get("exthPadding")->set(str_pad("", $pad+2, "\0", STR_PAD_RIGHT)); | ||
108 | $this->elements->get("exthHeaderLength")->set(12+$l+$pad); | ||
109 | |||
110 | |||
111 | $this->elements->get("recordCount")->set($textRecords); | ||
112 | |||
113 | $this->elements->get("fullNameOffset")->set($this->elements->offsetToEntry("fullName"));//need to be checked | ||
114 | $this->elements->get("fullNameLength")->set(strlen($settings->get("title"))); | ||
115 | $this->elements->get("fullName")->set($settings->get("title")); | ||
116 | $this->elements->get("textLength")->set($textLength); | ||
117 | |||
118 | $this->elements->get("offset194")->set($textRecords+2+$images); | ||
119 | $this->elements->get("offset200")->set($textRecords+4+$images); | ||
120 | $this->elements->get("offset208")->set($textRecords+3+$images); | ||
121 | $this->elements->get("offset232")->set(str_pad("", 8, chr(255), STR_PAD_RIGHT)); | ||
122 | } | ||
123 | |||
124 | public function getByteLength(){ | ||
125 | return $this->getLength(); | ||
126 | } | ||
127 | |||
128 | public function getLength(){ | ||
129 | return $this->elements->getByteLength(); | ||
130 | } | ||
131 | |||
132 | public function get(){ | ||
133 | return $this; | ||
134 | } | ||
135 | |||
136 | public function set($elements){ | ||
137 | throw new Exception("Unallowed set"); | ||
138 | } | ||
139 | |||
140 | public function serialize() { | ||
141 | return $this->elements->serialize(); | ||
142 | } | ||
143 | |||
144 | public function unserialize($data) { | ||
145 | $this->elements->unserialize($data); | ||
146 | } | ||
147 | |||
148 | public function __toString(){ | ||
149 | $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n"; | ||
150 | $output .= $this->elements; | ||
151 | return $output; | ||
152 | } | ||
153 | } | ||
154 | ?> | ||
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/Prc.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/Prc.php deleted file mode 100644 index 1507e24b..00000000 --- a/inc/3rdparty/libraries/send2kindle/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(2*$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+=1; | ||
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/send2kindle/MOBIClass/PreprocessedArticle.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PreprocessedArticle.php deleted file mode 100644 index 2e992404..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/RecognizeURL.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/RecognizeURL.php deleted file mode 100644 index 6319ed57..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/Record.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/Record.php deleted file mode 100644 index 3cb39582..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/RecordFactory.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/RecordFactory.php deleted file mode 100644 index 8bf0c97d..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/RecordFactory.php +++ /dev/null | |||
@@ -1,129 +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 | |||
66 | $this->elements = new FileElement(array( | ||
67 | "offsetL0"=>new FileString("FLIS", 4), //FLIS | ||
68 | "offsetL4"=>new FileInt(0x08), | ||
69 | "offsetL8"=>new FileShort(0x41), | ||
70 | "offsetL10"=>new FileTri(), | ||
71 | "offsetL16"=>new FileInt(0xFFFFFFFF), | ||
72 | "offsetL20"=>new FileShort(0x01), | ||
73 | "offsetL22"=>new FileShort(0x03), | ||
74 | "offsetL24"=>new FileInt(0x03), | ||
75 | "offsetL28"=>new FileInt(0x01), | ||
76 | "offsetL32"=>new FileInt(0xFFFFFFFF) | ||
77 | )); | ||
78 | |||
79 | /*$r = "FLIS"; | ||
80 | $r .= $this->asString(8, 4); | ||
81 | $r .= $this->asString(65, 2); | ||
82 | $r .= $this->asString(0, 2); | ||
83 | $r .= $this->asString(0, 4); | ||
84 | $r .= $this->asString(-1, 4); | ||
85 | $r .= $this->asString(1, 2); | ||
86 | $r .= $this->asString(3, 2); | ||
87 | $r .= $this->asString(3, 4); | ||
88 | $r .= $this->asString(1, 4); | ||
89 | $r .= $this->asString(-1, 4); | ||
90 | return new Record($r);*/ | ||
91 | } | ||
92 | |||
93 | private function asString($int, $size){ | ||
94 | $out = ""; | ||
95 | for($i = 0; $i < $size; $i++){ | ||
96 | if($i > 0) $out = " ".$out; | ||
97 | $byte = dechex($int & 0xFF); | ||
98 | if(strlen($byte) == 1) $byte = "0".$byte; | ||
99 | $out = $byte.$out; | ||
100 | $int = $int >> 8; | ||
101 | } | ||
102 | return $out; | ||
103 | } | ||
104 | |||
105 | public function __toString() { | ||
106 | $out = "Record Factory: {\n"; | ||
107 | $out .= "\tRecord Size: ".$this->settings->get("recordSize")."\n"; | ||
108 | $out .= "\tCompression: ".$this->settings->get("compression")."\n"; | ||
109 | $out .= "}"; | ||
110 | return $out; | ||
111 | } | ||
112 | } | ||
113 | function mb_str_split($string, $split_length = 1){ | ||
114 | mb_internal_encoding('UTF-8'); | ||
115 | mb_regex_encoding('UTF-8'); | ||
116 | |||
117 | $split_length = ($split_length <= 0) ? 1 : $split_length; | ||
118 | |||
119 | $mb_strlen = mb_strlen($string, 'utf-8'); | ||
120 | |||
121 | $array = array(); | ||
122 | |||
123 | for($i = 0; $i < $mb_strlen; $i += $split_length){ | ||
124 | $array[] = mb_substr($string, $i, $split_length); | ||
125 | } | ||
126 | |||
127 | return $array; | ||
128 | } | ||
129 | ?> | ||
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/Settings.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/Settings.php deleted file mode 100644 index 6bde0ba9..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/Settings.php +++ /dev/null | |||
@@ -1,95 +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 | $this->values = array( | ||
23 | "attributes"=>0, | ||
24 | "version"=>0, | ||
25 | "creationTime"=>time()+94694400, | ||
26 | "modificationTime"=>time()+94694400, | ||
27 | "backupTime"=>0, | ||
28 | "modificationNumber"=>0, | ||
29 | "appInfoID"=>0, | ||
30 | "sortInfoID"=>0, | ||
31 | "prcType"=>"BOOK", | ||
32 | "creator"=>"MOBI", | ||
33 | "uniqueIDSeed"=>rand(), | ||
34 | "nextRecordListID"=>0, | ||
35 | "recordAttributes"=>0, | ||
36 | "compression"=>NO_COMPRESSION, | ||
37 | "recordSize"=>RECORD_SIZE, | ||
38 | "encryptionType"=>NO_ENCRYPTION, | ||
39 | "mobiIdentifier"=>"MOBI", | ||
40 | "mobiHeaderLength"=>0xe8, | ||
41 | "mobiType"=>MOBIPOCKET_BOOK, | ||
42 | "textEncoding"=>UTF8, | ||
43 | "uniqueID"=>rand(), | ||
44 | "fileVersion"=>6, | ||
45 | "locale"=>0x09, | ||
46 | "inputLanguage"=>0, | ||
47 | "outputLanguage"=>0, | ||
48 | "minimumVersion"=>6, | ||
49 | "huffmanRecordOffset"=>0, | ||
50 | "huffmanRecordCount"=>0, | ||
51 | "exthFlags"=>0x50, | ||
52 | "drmOffset"=>0xFFFFFFFF, | ||
53 | "drmCount"=>0xFFFFFFFF, | ||
54 | "drmSize"=>0, | ||
55 | "drmFlags"=>0, | ||
56 | "extraDataFlags"=>0, | ||
57 | "exthIdentifier"=>"EXTH", | ||
58 | "title"=>"Unknown title", | ||
59 | "author"=>"Unknown author", | ||
60 | "subject"=>"Unknown subject" | ||
61 | ); | ||
62 | |||
63 | foreach($additionalSettings as $key=>$value){ | ||
64 | $this->values[$key] = $value; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * Get a value from the settings | ||
70 | * @param string $key Key of the setting | ||
71 | * @return mixed The value of the setting | ||
72 | */ | ||
73 | public function get($key){ | ||
74 | return $this->values[$key]; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * Checks if a value is set | ||
79 | * @param string $key Key of the setting | ||
80 | * @return bool True if the value exists | ||
81 | */ | ||
82 | public function exists($key){ | ||
83 | return isset($this->values[$key]); | ||
84 | } | ||
85 | |||
86 | public function __toString() { | ||
87 | $out = "Settings: {\n"; | ||
88 | foreach($this->values as $key=>$value){ | ||
89 | $out .= "\t".$key.": ".$value."\n"; | ||
90 | } | ||
91 | $out .= "}"; | ||
92 | return $out; | ||
93 | } | ||
94 | } | ||
95 | ?> | ||
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/constants.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/constants.php deleted file mode 100644 index bd363118..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/downloaders/FanFictionNet.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/downloaders/FanFictionNet.php deleted file mode 100644 index 65d5a466..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/http_build_url.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/http_build_url.php deleted file mode 100644 index b475edb0..00000000 --- a/inc/3rdparty/libraries/send2kindle/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/send2kindle/MOBIClass/readability/JSLikeHTMLElement.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/readability/JSLikeHTMLElement.php deleted file mode 100644 index 1a8ec88c..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/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/send2kindle/MOBIClass/readability/Readability.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/readability/Readability.php deleted file mode 100644 index 91554243..00000000 --- a/inc/3rdparty/libraries/send2kindle/MOBIClass/readability/Readability.php +++ /dev/null | |||
@@ -1,1069 +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 | * ------------------------------------------------------ | ||
6 | * Original URL: http://lab.arc90.com/experiments/readability/js/readability.js | ||
7 | * Arc90's project URL: http://lab.arc90.com/experiments/readability/ | ||
8 | * JS Source: http://code.google.com/p/arc90labs-readability | ||
9 | * Ported by: Keyvan Minoukadeh, http://www.keyvan.net | ||
10 | * More information: http://fivefilters.org/content-only/ | ||
11 | * License: Apache License, Version 2.0 | ||
12 | * Requires: PHP5 | ||
13 | * Date: 2010-10-29 | ||
14 | * | ||
15 | * Differences between the PHP port and the original | ||
16 | * ------------------------------------------------------ | ||
17 | * Arc90's Readability is designed to run in the browser. It works on the DOM | ||
18 | * tree (the parsed HTML) after the page's CSS styles have been applied and | ||
19 | * Javascript code executed. This PHP port does not run inside a browser. | ||
20 | * We use PHP's ability to parse HTML to build our DOM tree, but we cannot | ||
21 | * rely on CSS or Javascript support. As such, the results will not always | ||
22 | * match Arc90's Readability. (For example, if a web page contains CSS style | ||
23 | * rules or Javascript code which hide certain HTML elements from display, | ||
24 | * Arc90's Readability will dismiss those from consideration but our PHP port, | ||
25 | * unable to understand CSS or Javascript, will not know any better.) | ||
26 | * | ||
27 | * Another significant difference is that the aim of Arc90's Readability is | ||
28 | * to re-present the main content block of a given web page so users can | ||
29 | * read it more easily in their browsers. Correct identification, clean up, | ||
30 | * and separation of the content block is only a part of this process. | ||
31 | * This PHP port is only concerned with this part, it does not include code | ||
32 | * that relates to presentation in the browser - Arc90 already do | ||
33 | * that extremely well, and for PDF output there's FiveFilters.org's | ||
34 | * PDF Newspaper: http://fivefilters.org/pdf-newspaper/. | ||
35 | * | ||
36 | * Finally, this class contains methods that might be useful for developers | ||
37 | * working on HTML document fragments. So without deviating too much from | ||
38 | * the original code (which I don't want to do because it makes debugging | ||
39 | * and updating more difficult), I've tried to make it a little more | ||
40 | * developer friendly. You should be able to use the methods here on | ||
41 | * existing DOMElement objects without passing an entire HTML document to | ||
42 | * be parsed. | ||
43 | */ | ||
44 | |||
45 | // This class allows us to do JavaScript like assignements to innerHTML | ||
46 | require_once(dirname(__FILE__).'/JSLikeHTMLElement.php'); | ||
47 | |||
48 | // Alternative usage (for testing only!) | ||
49 | // uncomment the lins below and call Readability.php in your browser | ||
50 | // passing it the URL of the page you'd like content from, e.g.: | ||
51 | // Readability.php?url=http://medialens.org/alerts/09/090615_the_guardian_climate.php | ||
52 | |||
53 | /* | ||
54 | if (!isset($_GET['url']) || $_GET['url'] == '') { | ||
55 | die('Please pass a URL to the script. E.g. Readability.php?url=bla.com/story.html'); | ||
56 | } | ||
57 | $url = $_GET['url']; | ||
58 | if (!preg_match('!^https?://!i', $url)) $url = 'http://'.$url; | ||
59 | $html = file_get_contents($url); | ||
60 | $r = new Readability($html, $url); | ||
61 | $r->init(); | ||
62 | echo $r->articleContent->innerHTML; | ||
63 | */ | ||
64 | |||
65 | class Readability | ||
66 | { | ||
67 | public $version = '1.7.1-without-multi-page'; | ||
68 | public $convertLinksToFootnotes = false; | ||
69 | public $revertForcedParagraphElements = true; | ||
70 | public $articleTitle; | ||
71 | public $articleContent; | ||
72 | public $dom; | ||
73 | public $url = null; // optional - URL where HTML was retrieved | ||
74 | public $debug = false; | ||
75 | protected $body = null; // | ||
76 | protected $bodyCache = null; // Cache the body HTML in case we need to re-use it later | ||
77 | protected $flags = 7; // 1 | 2 | 4; // Start with all flags set. | ||
78 | protected $success = false; // indicates whether we were able to extract or not | ||
79 | |||
80 | /** | ||
81 | * All of the regular expressions in use within readability. | ||
82 | * Defined up here so we don't instantiate them repeatedly in loops. | ||
83 | **/ | ||
84 | public $regexps = array( | ||
85 | 'unlikelyCandidates' => '/combx|comment|community|disqus|extra|foot|header|menu|remark|rss|shoutbox|sidebar|sponsor|ad-break|agegate|pagination|pager|popup|tweet|twitter/i', | ||
86 | 'okMaybeItsACandidate' => '/and|article|body|column|main|shadow/i', | ||
87 | 'positive' => '/article|body|content|entry|hentry|main|page|pagination|post|text|blog|story/i', | ||
88 | 'negative' => '/combx|comment|com-|contact|foot|footer|footnote|masthead|media|meta|outbrain|promo|related|scroll|shoutbox|sidebar|sponsor|shopping|tags|tool|widget/i', | ||
89 | 'divToPElements' => '/<(a|blockquote|dl|div|img|ol|p|pre|table|ul)/i', | ||
90 | 'replaceBrs' => '/(<br[^>]*>[ \n\r\t]*){2,}/i', | ||
91 | 'replaceFonts' => '/<(\/?)font[^>]*>/i', | ||
92 | // 'trimRe' => '/^\s+|\s+$/g', // PHP has trim() | ||
93 | 'normalize' => '/\s{2,}/', | ||
94 | 'killBreaks' => '/(<br\s*\/?>(\s| ?)*){1,}/', | ||
95 | 'video' => '/http:\/\/(www\.)?(youtube|vimeo)\.com/i', | ||
96 | 'skipFootnoteLink' => '/^\s*(\[?[a-z0-9]{1,2}\]?|^|edit|citation needed)\s*$/i' | ||
97 | ); | ||
98 | |||
99 | /* constants */ | ||
100 | const FLAG_STRIP_UNLIKELYS = 1; | ||
101 | const FLAG_WEIGHT_CLASSES = 2; | ||
102 | const FLAG_CLEAN_CONDITIONALLY = 4; | ||
103 | |||
104 | /** | ||
105 | * Create instance of Readability | ||
106 | * @param string UTF-8 encoded string | ||
107 | * @param string (optional) URL associated with HTML (used for footnotes) | ||
108 | */ | ||
109 | function __construct($html, $url=null) | ||
110 | { | ||
111 | /* Turn all double br's into p's */ | ||
112 | /* Note, this is pretty costly as far as processing goes. Maybe optimize later. */ | ||
113 | $html = preg_replace($this->regexps['replaceBrs'], '</p><p>', $html); | ||
114 | $html = preg_replace($this->regexps['replaceFonts'], '<$1span>', $html); | ||
115 | $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); | ||
116 | $this->dom = new DOMDocument(); | ||
117 | $this->dom->preserveWhiteSpace = false; | ||
118 | $this->dom->registerNodeClass('DOMElement', 'JSLikeHTMLElement'); | ||
119 | @$this->dom->loadHTML($html); | ||
120 | $this->url = $url; | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * Get article title element | ||
125 | * @return DOMElement | ||
126 | */ | ||
127 | public function getTitle() { | ||
128 | return $this->articleTitle; | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * Get article content element | ||
133 | * @return DOMElement | ||
134 | */ | ||
135 | public function getContent() { | ||
136 | return $this->articleContent; | ||
137 | } | ||
138 | |||
139 | /** | ||
140 | * Runs readability. | ||
141 | * | ||
142 | * Workflow: | ||
143 | * 1. Prep the document by removing script tags, css, etc. | ||
144 | * 2. Build readability's DOM tree. | ||
145 | * 3. Grab the article content from the current dom tree. | ||
146 | * 4. Replace the current DOM tree with the new one. | ||
147 | * 5. Read peacefully. | ||
148 | * | ||
149 | * @return boolean true if we found content, false otherwise | ||
150 | **/ | ||
151 | public function init() | ||
152 | { | ||
153 | $this->removeScripts($this->dom); | ||
154 | |||
155 | // Assume successful outcome | ||
156 | $this->success = true; | ||
157 | |||
158 | $bodyElems = $this->dom->getElementsByTagName('body'); | ||
159 | if ($bodyElems->length > 0) { | ||
160 | if ($this->bodyCache == null) { | ||
161 | $this->bodyCache = $bodyElems->item(0)->innerHTML; | ||
162 | } | ||
163 | if ($this->body == null) { | ||
164 | $this->body = $bodyElems->item(0); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | $this->prepDocument(); | ||
169 | |||
170 | //die($this->dom->documentElement->parentNode->nodeType); | ||
171 | //$this->setInnerHTML($this->dom->documentElement, $this->getInnerHTML($this->dom->documentElement)); | ||
172 | //die($this->getInnerHTML($this->dom->documentElement)); | ||
173 | |||
174 | /* Build readability's DOM tree */ | ||
175 | $overlay = $this->dom->createElement('div'); | ||
176 | $innerDiv = $this->dom->createElement('div'); | ||
177 | $articleTitle = $this->getArticleTitle(); | ||
178 | $articleContent = $this->grabArticle(); | ||
179 | |||
180 | if (!$articleContent) { | ||
181 | $this->success = false; | ||
182 | $articleContent = $this->dom->createElement('div'); | ||
183 | $articleContent->setAttribute('id', 'readability-content'); | ||
184 | $articleContent->innerHTML = '<p>Sorry, Readability was unable to parse this page for content.</p>'; | ||
185 | } | ||
186 | |||
187 | $overlay->setAttribute('id', 'readOverlay'); | ||
188 | $innerDiv->setAttribute('id', 'readInner'); | ||
189 | |||
190 | /* Glue the structure of our document together. */ | ||
191 | $innerDiv->appendChild($articleTitle); | ||
192 | $innerDiv->appendChild($articleContent); | ||
193 | $overlay->appendChild($innerDiv); | ||
194 | |||
195 | /* Clear the old HTML, insert the new content. */ | ||
196 | $this->body->innerHTML = ''; | ||
197 | $this->body->appendChild($overlay); | ||
198 | //document.body.insertBefore(overlay, document.body.firstChild); | ||
199 | $this->body->removeAttribute('style'); | ||
200 | |||
201 | $this->postProcessContent($articleContent); | ||
202 | |||
203 | // Set title and content instance variables | ||
204 | $this->articleTitle = $articleTitle; | ||
205 | $this->articleContent = $articleContent; | ||
206 | |||
207 | return $this->success; | ||
208 | } | ||
209 | |||
210 | /** | ||
211 | * Debug | ||
212 | */ | ||
213 | protected function dbg($msg) { | ||
214 | if ($this->debug) echo '* ',$msg, '<br />', "\n"; | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | * Run any post-process modifications to article content as necessary. | ||
219 | * | ||
220 | * @param DOMElement | ||
221 | * @return void | ||
222 | */ | ||
223 | public function postProcessContent($articleContent) { | ||
224 | if ($this->convertLinksToFootnotes && !preg_match('/wikipedia\.org/', @$this->url)) { | ||
225 | $this->addFootnotes($articleContent); | ||
226 | } | ||
227 | } | ||
228 | |||
229 | /** | ||
230 | * Get the article title as an H1. | ||
231 | * | ||
232 | * @return DOMElement | ||
233 | */ | ||
234 | protected function getArticleTitle() { | ||
235 | $curTitle = ''; | ||
236 | $origTitle = ''; | ||
237 | |||
238 | try { | ||
239 | $curTitle = $origTitle = $this->getInnerText($this->dom->getElementsByTagName('title')->item(0)); | ||
240 | } catch(Exception $e) {} | ||
241 | |||
242 | if (preg_match('/ [\|\-] /', $curTitle)) | ||
243 | { | ||
244 | $curTitle = preg_replace('/(.*)[\|\-] .*/i', '$1', $origTitle); | ||
245 | |||
246 | if (count(explode(' ', $curTitle)) < 3) { | ||
247 | $curTitle = preg_replace('/[^\|\-]*[\|\-](.*)/i', '$1', $origTitle); | ||
248 | } | ||
249 | } | ||
250 | else if (strpos($curTitle, ': ') !== false) | ||
251 | { | ||
252 | $curTitle = preg_replace('/.*:(.*)/i', '$1', $origTitle); | ||
253 | |||
254 | if (count(explode(' ', $curTitle)) < 3) { | ||
255 | $curTitle = preg_replace('/[^:]*[:](.*)/i','$1', $origTitle); | ||
256 | } | ||
257 | } | ||
258 | else if(strlen($curTitle) > 150 || strlen($curTitle) < 15) | ||
259 | { | ||
260 | $hOnes = $this->dom->getElementsByTagName('h1'); | ||
261 | if($hOnes->length == 1) | ||
262 | { | ||
263 | $curTitle = $this->getInnerText($hOnes->item(0)); | ||
264 | } | ||
265 | } | ||
266 | |||
267 | $curTitle = trim($curTitle); | ||
268 | |||
269 | if (count(explode(' ', $curTitle)) <= 4) { | ||
270 | $curTitle = $origTitle; | ||
271 | } | ||
272 | |||
273 | $articleTitle = $this->dom->createElement('h1'); | ||
274 | $articleTitle->innerHTML = $curTitle; | ||
275 | |||
276 | return $articleTitle; | ||
277 | } | ||
278 | |||
279 | /** | ||
280 | * Prepare the HTML document for readability to scrape it. | ||
281 | * This includes things like stripping javascript, CSS, and handling terrible markup. | ||
282 | * | ||
283 | * @return void | ||
284 | **/ | ||
285 | protected function prepDocument() { | ||
286 | /** | ||
287 | * In some cases a body element can't be found (if the HTML is totally hosed for example) | ||
288 | * so we create a new body node and append it to the document. | ||
289 | */ | ||
290 | if($this->dom->documentElement == null){ | ||
291 | throw new Exception("No document element"); | ||
292 | } | ||
293 | if ($this->body == null) | ||
294 | { | ||
295 | $this->body = $this->dom->createElement('body'); | ||
296 | $this->dom->documentElement->appendChild($this->body); | ||
297 | } | ||
298 | |||
299 | $this->body->setAttribute('id', 'readabilityBody'); | ||
300 | |||
301 | /* Remove all style tags in head */ | ||
302 | $styleTags = $this->dom->getElementsByTagName('style'); | ||
303 | for ($i = $styleTags->length-1; $i >= 0; $i--) | ||
304 | { | ||
305 | $styleTags->item($i)->parentNode->removeChild($styleTags->item($i)); | ||
306 | } | ||
307 | |||
308 | /* Turn all double br's into p's */ | ||
309 | /* Note, this is pretty costly as far as processing goes. Maybe optimize later. */ | ||
310 | //document.body.innerHTML = document.body.innerHTML.replace(readability.regexps.replaceBrs, '</p><p>').replace(readability.regexps.replaceFonts, '<$1span>'); | ||
311 | // We do this in the constructor for PHP as that's when we have raw HTML - before parsing it into a DOM tree. | ||
312 | // Manipulating innerHTML as it's done in JS is not possible in PHP. | ||
313 | } | ||
314 | |||
315 | /** | ||
316 | * For easier reading, convert this document to have footnotes at the bottom rather than inline links. | ||
317 | * @see http://www.roughtype.com/archives/2010/05/experiments_in.php | ||
318 | * | ||
319 | * @return void | ||
320 | **/ | ||
321 | public function addFootnotes($articleContent) { | ||
322 | $footnotesWrapper = $this->dom->createElement('div'); | ||
323 | $footnotesWrapper->setAttribute('id', 'readability-footnotes'); | ||
324 | $footnotesWrapper->innerHTML = '<h3>References</h3>'; | ||
325 | |||
326 | $articleFootnotes = $this->dom->createElement('ol'); | ||
327 | $articleFootnotes->setAttribute('id', 'readability-footnotes-list'); | ||
328 | $footnotesWrapper->appendChild($articleFootnotes); | ||
329 | |||
330 | $articleLinks = $articleContent->getElementsByTagName('a'); | ||
331 | |||
332 | $linkCount = 0; | ||
333 | for ($i = 0; $i < $articleLinks->length; $i++) | ||
334 | { | ||
335 | $articleLink = $articleLinks->item($i); | ||
336 | $footnoteLink = $articleLink->cloneNode(true); | ||
337 | $refLink = $this->dom->createElement('a'); | ||
338 | $footnote = $this->dom->createElement('li'); | ||
339 | $linkDomain = @parse_url($footnoteLink->getAttribute('href'), PHP_URL_HOST); | ||
340 | if (!$linkDomain && isset($this->url)) $linkDomain = @parse_url($this->url, PHP_URL_HOST); | ||
341 | //linkDomain = footnoteLink.host ? footnoteLink.host : document.location.host, | ||
342 | $linkText = $this->getInnerText($articleLink); | ||
343 | |||
344 | if ((strpos($articleLink->getAttribute('class'), 'readability-DoNotFootnote') !== false) || preg_match($this->regexps['skipFootnoteLink'], $linkText)) { | ||
345 | continue; | ||
346 | } | ||
347 | |||
348 | $linkCount++; | ||
349 | |||
350 | /** Add a superscript reference after the article link */ | ||
351 | $refLink->setAttribute('href', '#readabilityFootnoteLink-' . $linkCount); | ||
352 | $refLink->innerHTML = '<small><sup>[' . $linkCount . ']</sup></small>'; | ||
353 | $refLink->setAttribute('class', 'readability-DoNotFootnote'); | ||
354 | $refLink->setAttribute('style', 'color: inherit;'); | ||
355 | |||
356 | //TODO: does this work or should we use DOMNode.isSameNode()? | ||
357 | if ($articleLink->parentNode->lastChild == $articleLink) { | ||
358 | $articleLink->parentNode->appendChild($refLink); | ||
359 | } else { | ||
360 | $articleLink->parentNode->insertBefore($refLink, $articleLink->nextSibling); | ||
361 | } | ||
362 | |||
363 | $articleLink->setAttribute('style', 'color: inherit; text-decoration: none;'); | ||
364 | $articleLink->setAttribute('name', 'readabilityLink-' . $linkCount); | ||
365 | |||
366 | $footnote->innerHTML = '<small><sup><a href="#readabilityLink-' . $linkCount . '" title="Jump to Link in Article">^</a></sup></small> '; | ||
367 | |||
368 | $footnoteLink->innerHTML = ($footnoteLink->getAttribute('title') != '' ? $footnoteLink->getAttribute('title') : $linkText); | ||
369 | $footnoteLink->setAttribute('name', 'readabilityFootnoteLink-' . $linkCount); | ||
370 | |||
371 | $footnote->appendChild($footnoteLink); | ||
372 | if ($linkDomain) $footnote->innerHTML = $footnote->innerHTML . '<small> (' . $linkDomain . ')</small>'; | ||
373 | |||
374 | $articleFootnotes->appendChild($footnote); | ||
375 | } | ||
376 | |||
377 | if ($linkCount > 0) { | ||
378 | $articleContent->appendChild($footnotesWrapper); | ||
379 | } | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * Reverts P elements with class 'readability-styled' | ||
384 | * to text nodes - which is what they were before. | ||
385 | * | ||
386 | * @param DOMElement | ||
387 | * @return void | ||
388 | */ | ||
389 | function revertReadabilityStyledElements($articleContent) { | ||
390 | $xpath = new DOMXPath($articleContent->ownerDocument); | ||
391 | $elems = $xpath->query('.//p[@class="readability-styled"]', $articleContent); | ||
392 | //$elems = $articleContent->getElementsByTagName('p'); | ||
393 | for ($i = $elems->length-1; $i >= 0; $i--) { | ||
394 | $e = $elems->item($i); | ||
395 | $e->parentNode->replaceChild($articleContent->ownerDocument->createTextNode($e->textContent), $e); | ||
396 | //if ($e->hasAttribute('class') && $e->getAttribute('class') == 'readability-styled') { | ||
397 | // $e->parentNode->replaceChild($this->dom->createTextNode($e->textContent), $e); | ||
398 | //} | ||
399 | } | ||
400 | } | ||
401 | |||
402 | /** | ||
403 | * Prepare the article node for display. Clean out any inline styles, | ||
404 | * iframes, forms, strip extraneous <p> tags, etc. | ||
405 | * | ||
406 | * @param DOMElement | ||
407 | * @return void | ||
408 | */ | ||
409 | function prepArticle($articleContent) { | ||
410 | $this->cleanStyles($articleContent); | ||
411 | $this->killBreaks($articleContent); | ||
412 | if ($this->revertForcedParagraphElements) { | ||
413 | $this->revertReadabilityStyledElements($articleContent); | ||
414 | } | ||
415 | |||
416 | /* Clean out junk from the article content */ | ||
417 | $this->cleanConditionally($articleContent, 'form'); | ||
418 | $this->clean($articleContent, 'object'); | ||
419 | $this->clean($articleContent, 'h1'); | ||
420 | |||
421 | /** | ||
422 | * If there is only one h2, they are probably using it | ||
423 | * as a header and not a subheader, so remove it since we already have a header. | ||
424 | ***/ | ||
425 | if ($articleContent->getElementsByTagName('h2')->length == 1) { | ||
426 | $this->clean($articleContent, 'h2'); | ||
427 | } | ||
428 | $this->clean($articleContent, 'iframe'); | ||
429 | |||
430 | $this->cleanHeaders($articleContent); | ||
431 | |||
432 | /* Do these last as the previous stuff may have removed junk that will affect these */ | ||
433 | $this->cleanConditionally($articleContent, 'table'); | ||
434 | $this->cleanConditionally($articleContent, 'ul'); | ||
435 | $this->cleanConditionally($articleContent, 'div'); | ||
436 | |||
437 | /* Remove extra paragraphs */ | ||
438 | $articleParagraphs = $articleContent->getElementsByTagName('p'); | ||
439 | for ($i = $articleParagraphs->length-1; $i >= 0; $i--) | ||
440 | { | ||
441 | $imgCount = $articleParagraphs->item($i)->getElementsByTagName('img')->length; | ||
442 | $embedCount = $articleParagraphs->item($i)->getElementsByTagName('embed')->length; | ||
443 | $objectCount = $articleParagraphs->item($i)->getElementsByTagName('object')->length; | ||
444 | |||
445 | if ($imgCount === 0 && $embedCount === 0 && $objectCount === 0 && $this->getInnerText($articleParagraphs->item($i), false) == '') | ||
446 | { | ||
447 | $articleParagraphs->item($i)->parentNode->removeChild($articleParagraphs->item($i)); | ||
448 | } | ||
449 | } | ||
450 | |||
451 | try { | ||
452 | $articleContent->innerHTML = preg_replace('/<br[^>]*>\s*<p/i', '<p', $articleContent->innerHTML); | ||
453 | //articleContent.innerHTML = articleContent.innerHTML.replace(/<br[^>]*>\s*<p/gi, '<p'); | ||
454 | } | ||
455 | catch (Exception $e) { | ||
456 | $this->dbg("Cleaning innerHTML of breaks failed. This is an IE strict-block-elements bug. Ignoring.: " . $e); | ||
457 | } | ||
458 | } | ||
459 | |||
460 | /** | ||
461 | * Initialize a node with the readability object. Also checks the | ||
462 | * className/id for special names to add to its score. | ||
463 | * | ||
464 | * @param Element | ||
465 | * @return void | ||
466 | **/ | ||
467 | protected function initializeNode($node) { | ||
468 | $readability = $this->dom->createAttribute('readability'); | ||
469 | $readability->value = 0; // this is our contentScore | ||
470 | $node->setAttributeNode($readability); | ||
471 | |||
472 | switch (strtoupper($node->tagName)) { // unsure if strtoupper is needed, but using it just in case | ||
473 | case 'DIV': | ||
474 | $readability->value += 5; | ||
475 | break; | ||
476 | |||
477 | case 'PRE': | ||
478 | case 'TD': | ||
479 | case 'BLOCKQUOTE': | ||
480 | $readability->value += 3; | ||
481 | break; | ||
482 | |||
483 | case 'ADDRESS': | ||
484 | case 'OL': | ||
485 | case 'UL': | ||
486 | case 'DL': | ||
487 | case 'DD': | ||
488 | case 'DT': | ||
489 | case 'LI': | ||
490 | case 'FORM': | ||
491 | $readability->value -= 3; | ||
492 | break; | ||
493 | |||
494 | case 'H1': | ||
495 | case 'H2': | ||
496 | case 'H3': | ||
497 | case 'H4': | ||
498 | case 'H5': | ||
499 | case 'H6': | ||
500 | case 'TH': | ||
501 | $readability->value -= 5; | ||
502 | break; | ||
503 | } | ||
504 | $readability->value += $this->getClassWeight($node); | ||
505 | } | ||
506 | |||
507 | /*** | ||
508 | * grabArticle - Using a variety of metrics (content score, classname, element types), find the content that is | ||
509 | * most likely to be the stuff a user wants to read. Then return it wrapped up in a div. | ||
510 | * | ||
511 | * @return DOMElement | ||
512 | **/ | ||
513 | protected function grabArticle($page=null) { | ||
514 | $stripUnlikelyCandidates = $this->flagIsActive(self::FLAG_STRIP_UNLIKELYS); | ||
515 | if (!$page) $page = $this->dom; | ||
516 | $allElements = $page->getElementsByTagName('*'); | ||
517 | /** | ||
518 | * First, node prepping. Trash nodes that look cruddy (like ones with the class name "comment", etc), and turn divs | ||
519 | * into P tags where they have been used inappropriately (as in, where they contain no other block level elements.) | ||
520 | * | ||
521 | * Note: Assignment from index for performance. See http://www.peachpit.com/articles/article.aspx?p=31567&seqNum=5 | ||
522 | * TODO: Shouldn't this be a reverse traversal? | ||
523 | **/ | ||
524 | $node = null; | ||
525 | $nodesToScore = array(); | ||
526 | for ($nodeIndex = 0; ($node = $allElements->item($nodeIndex)); $nodeIndex++) { | ||
527 | //for ($nodeIndex=$targetList->length-1; $nodeIndex >= 0; $nodeIndex--) { | ||
528 | //$node = $targetList->item($nodeIndex); | ||
529 | $tagName = strtoupper($node->tagName); | ||
530 | /* Remove unlikely candidates */ | ||
531 | if ($stripUnlikelyCandidates) { | ||
532 | $unlikelyMatchString = $node->getAttribute('class') . $node->getAttribute('id'); | ||
533 | if ( | ||
534 | preg_match($this->regexps['unlikelyCandidates'], $unlikelyMatchString) && | ||
535 | !preg_match($this->regexps['okMaybeItsACandidate'], $unlikelyMatchString) && | ||
536 | $tagName != 'BODY' | ||
537 | ) | ||
538 | { | ||
539 | $this->dbg('Removing unlikely candidate - ' . $unlikelyMatchString); | ||
540 | //$nodesToRemove[] = $node; | ||
541 | $node->parentNode->removeChild($node); | ||
542 | $nodeIndex--; | ||
543 | continue; | ||
544 | } | ||
545 | } | ||
546 | |||
547 | if ($tagName == 'P' || $tagName == 'TD' || $tagName == 'PRE') { | ||
548 | $nodesToScore[] = $node; | ||
549 | } | ||
550 | |||
551 | /* Turn all divs that don't have children block level elements into p's */ | ||
552 | if ($tagName == 'DIV') { | ||
553 | if (!preg_match($this->regexps['divToPElements'], $node->innerHTML)) { | ||
554 | //$this->dbg('Altering div to p'); | ||
555 | $newNode = $this->dom->createElement('p'); | ||
556 | try { | ||
557 | $newNode->innerHTML = $node->innerHTML; | ||
558 | //$nodesToReplace[] = array('new'=>$newNode, 'old'=>$node); | ||
559 | $node->parentNode->replaceChild($newNode, $node); | ||
560 | $nodeIndex--; | ||
561 | $nodesToScore[] = $node; // or $newNode? | ||
562 | } | ||
563 | catch(Exception $e) { | ||
564 | $this->dbg('Could not alter div to p, reverting back to div.: ' . $e); | ||
565 | } | ||
566 | } | ||
567 | else | ||
568 | { | ||
569 | /* EXPERIMENTAL */ | ||
570 | // TODO: change these p elements back to text nodes after processing | ||
571 | for ($i = 0, $il = $node->childNodes->length; $i < $il; $i++) { | ||
572 | $childNode = $node->childNodes->item($i); | ||
573 | if ($childNode->nodeType == 3) { // XML_TEXT_NODE | ||
574 | //$this->dbg('replacing text node with a p tag with the same content.'); | ||
575 | $p = $this->dom->createElement('p'); | ||
576 | $p->innerHTML = $childNode->nodeValue; | ||
577 | $p->setAttribute('style', 'display: inline;'); | ||
578 | $p->setAttribute('class', 'readability-styled'); | ||
579 | $childNode->parentNode->replaceChild($p, $childNode); | ||
580 | } | ||
581 | } | ||
582 | } | ||
583 | } | ||
584 | } | ||
585 | |||
586 | /** | ||
587 | * Loop through all paragraphs, and assign a score to them based on how content-y they look. | ||
588 | * Then add their score to their parent node. | ||
589 | * | ||
590 | * A score is determined by things like number of commas, class names, etc. Maybe eventually link density. | ||
591 | **/ | ||
592 | $candidates = array(); | ||
593 | for ($pt=0; $pt < count($nodesToScore); $pt++) { | ||
594 | $parentNode = $nodesToScore[$pt]->parentNode; | ||
595 | // $grandParentNode = $parentNode ? $parentNode->parentNode : null; | ||
596 | $grandParentNode = !$parentNode ? null : (($parentNode->parentNode instanceof DOMElement) ? $parentNode->parentNode : null); | ||
597 | $innerText = $this->getInnerText($nodesToScore[$pt]); | ||
598 | |||
599 | if (!$parentNode || !isset($parentNode->tagName)) { | ||
600 | continue; | ||
601 | } | ||
602 | |||
603 | /* If this paragraph is less than 25 characters, don't even count it. */ | ||
604 | if(strlen($innerText) < 25) { | ||
605 | continue; | ||
606 | } | ||
607 | |||
608 | /* Initialize readability data for the parent. */ | ||
609 | if (!$parentNode->hasAttribute('readability')) | ||
610 | { | ||
611 | $this->initializeNode($parentNode); | ||
612 | $candidates[] = $parentNode; | ||
613 | } | ||
614 | |||
615 | /* Initialize readability data for the grandparent. */ | ||
616 | if ($grandParentNode && !$grandParentNode->hasAttribute('readability') && isset($grandParentNode->tagName)) | ||
617 | { | ||
618 | $this->initializeNode($grandParentNode); | ||
619 | $candidates[] = $grandParentNode; | ||
620 | } | ||
621 | |||
622 | $contentScore = 0; | ||
623 | |||
624 | /* Add a point for the paragraph itself as a base. */ | ||
625 | $contentScore++; | ||
626 | |||
627 | /* Add points for any commas within this paragraph */ | ||
628 | $contentScore += count(explode(',', $innerText)); | ||
629 | |||
630 | /* For every 100 characters in this paragraph, add another point. Up to 3 points. */ | ||
631 | $contentScore += min(floor(strlen($innerText) / 100), 3); | ||
632 | |||
633 | /* Add the score to the parent. The grandparent gets half. */ | ||
634 | $parentNode->getAttributeNode('readability')->value += $contentScore; | ||
635 | |||
636 | if ($grandParentNode) { | ||
637 | $grandParentNode->getAttributeNode('readability')->value += $contentScore/2; | ||
638 | } | ||
639 | } | ||
640 | |||
641 | /** | ||
642 | * After we've calculated scores, loop through all of the possible candidate nodes we found | ||
643 | * and find the one with the highest score. | ||
644 | **/ | ||
645 | $topCandidate = null; | ||
646 | for ($c=0, $cl=count($candidates); $c < $cl; $c++) | ||
647 | { | ||
648 | /** | ||
649 | * Scale the final candidates score based on link density. Good content should have a | ||
650 | * relatively small link density (5% or less) and be mostly unaffected by this operation. | ||
651 | **/ | ||
652 | $readability = $candidates[$c]->getAttributeNode('readability'); | ||
653 | $readability->value = $readability->value * (1-$this->getLinkDensity($candidates[$c])); | ||
654 | |||
655 | $this->dbg('Candidate: ' . $candidates[$c]->tagName . ' (' . $candidates[$c]->getAttribute('class') . ':' . $candidates[$c]->getAttribute('id') . ') with score ' . $readability->value); | ||
656 | |||
657 | if (!$topCandidate || $readability->value > (int)$topCandidate->getAttribute('readability')) { | ||
658 | $topCandidate = $candidates[$c]; | ||
659 | } | ||
660 | } | ||
661 | |||
662 | /** | ||
663 | * If we still have no top candidate, just use the body as a last resort. | ||
664 | * We also have to copy the body node so it is something we can modify. | ||
665 | **/ | ||
666 | if ($topCandidate === null || strtoupper($topCandidate->tagName) == 'BODY') | ||
667 | { | ||
668 | $topCandidate = $this->dom->createElement('div'); | ||
669 | $topCandidate->innerHTML = ($page instanceof DOMDocument) ? $page->saveXML($page->documentElement) : $page->innerHTML; | ||
670 | $page->innerHTML = ''; | ||
671 | $page->appendChild($topCandidate); | ||
672 | $this->initializeNode($topCandidate); | ||
673 | } | ||
674 | |||
675 | /** | ||
676 | * Now that we have the top candidate, look through its siblings for content that might also be related. | ||
677 | * Things like preambles, content split by ads that we removed, etc. | ||
678 | **/ | ||
679 | $articleContent = $this->dom->createElement('div'); | ||
680 | $articleContent->setAttribute('id', 'readability-content'); | ||
681 | $siblingScoreThreshold = max(10, ((int)$topCandidate->getAttribute('readability')) * 0.2); | ||
682 | $siblingNodes = $topCandidate->parentNode->childNodes; | ||
683 | |||
684 | for ($s=0, $sl=$siblingNodes->length; $s < $sl; $s++) | ||
685 | { | ||
686 | $siblingNode = $siblingNodes->item($s); | ||
687 | $append = false; | ||
688 | |||
689 | $this->dbg('Looking at sibling node: ' . $siblingNode->nodeName . (($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('readability')) ? (' with score ' . $siblingNode->getAttribute('readability')) : '')); | ||
690 | |||
691 | //dbg('Sibling has score ' . ($siblingNode->readability ? siblingNode.readability.contentScore : 'Unknown')); | ||
692 | |||
693 | if ($siblingNode === $topCandidate) | ||
694 | // or if ($siblingNode->isSameNode($topCandidate)) | ||
695 | { | ||
696 | $append = true; | ||
697 | } | ||
698 | |||
699 | $contentBonus = 0; | ||
700 | /* Give a bonus if sibling nodes and top candidates have the example same classname */ | ||
701 | if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->getAttribute('class') == $topCandidate->getAttribute('class') && $topCandidate->getAttribute('class') != '') { | ||
702 | $contentBonus += ((int)$topCandidate->getAttribute('readability')) * 0.2; | ||
703 | } | ||
704 | |||
705 | if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('readability') && (((int)$siblingNode->getAttribute('readability')) + $contentBonus) >= $siblingScoreThreshold) | ||
706 | { | ||
707 | $append = true; | ||
708 | } | ||
709 | |||
710 | if (strtoupper($siblingNode->nodeName) == 'P') { | ||
711 | $linkDensity = $this->getLinkDensity($siblingNode); | ||
712 | $nodeContent = $this->getInnerText($siblingNode); | ||
713 | $nodeLength = strlen($nodeContent); | ||
714 | |||
715 | if ($nodeLength > 80 && $linkDensity < 0.25) | ||
716 | { | ||
717 | $append = true; | ||
718 | } | ||
719 | else if ($nodeLength < 80 && $linkDensity === 0 && preg_match('/\.( |$)/', $nodeContent)) | ||
720 | { | ||
721 | $append = true; | ||
722 | } | ||
723 | } | ||
724 | |||
725 | if ($append) | ||
726 | { | ||
727 | $this->dbg('Appending node: ' . $siblingNode->nodeName); | ||
728 | |||
729 | $nodeToAppend = null; | ||
730 | $sibNodeName = strtoupper($siblingNode->nodeName); | ||
731 | if ($sibNodeName != 'DIV' && $sibNodeName != 'P') { | ||
732 | /* 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. */ | ||
733 | |||
734 | $this->dbg('Altering siblingNode of ' . $sibNodeName . ' to div.'); | ||
735 | $nodeToAppend = $this->dom->createElement('div'); | ||
736 | try { | ||
737 | $nodeToAppend->setAttribute('id', $siblingNode->getAttribute('id')); | ||
738 | $nodeToAppend->innerHTML = $siblingNode->innerHTML; | ||
739 | } | ||
740 | catch(Exception $e) | ||
741 | { | ||
742 | $this->dbg('Could not alter siblingNode to div, reverting back to original.'); | ||
743 | $nodeToAppend = $siblingNode; | ||
744 | $s--; | ||
745 | $sl--; | ||
746 | } | ||
747 | } else { | ||
748 | $nodeToAppend = $siblingNode; | ||
749 | $s--; | ||
750 | $sl--; | ||
751 | } | ||
752 | |||
753 | /* To ensure a node does not interfere with readability styles, remove its classnames */ | ||
754 | $nodeToAppend->removeAttribute('class'); | ||
755 | |||
756 | /* Append sibling and subtract from our list because it removes the node when you append to another node */ | ||
757 | $articleContent->appendChild($nodeToAppend); | ||
758 | } | ||
759 | } | ||
760 | |||
761 | /** | ||
762 | * So we have all of the content that we need. Now we clean it up for presentation. | ||
763 | **/ | ||
764 | $this->prepArticle($articleContent); | ||
765 | |||
766 | /** | ||
767 | * Now that we've gone through the full algorithm, check to see if we got any meaningful content. | ||
768 | * If we didn't, we may need to re-run grabArticle with different flags set. This gives us a higher | ||
769 | * likelihood of finding the content, and the sieve approach gives us a higher likelihood of | ||
770 | * finding the -right- content. | ||
771 | **/ | ||
772 | if (strlen($this->getInnerText($articleContent, false)) < 250) | ||
773 | { | ||
774 | $this->body->innerHTML = $this->bodyCache; | ||
775 | |||
776 | if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS)) { | ||
777 | $this->removeFlag(self::FLAG_STRIP_UNLIKELYS); | ||
778 | return $this->grabArticle($this->body); | ||
779 | } | ||
780 | else if ($this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) { | ||
781 | $this->removeFlag(self::FLAG_WEIGHT_CLASSES); | ||
782 | return $this->grabArticle($this->body); | ||
783 | } | ||
784 | else if ($this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) { | ||
785 | $this->removeFlag(self::FLAG_CLEAN_CONDITIONALLY); | ||
786 | return $this->grabArticle($this->body); | ||
787 | } | ||
788 | else { | ||
789 | return false; | ||
790 | } | ||
791 | } | ||
792 | return $articleContent; | ||
793 | } | ||
794 | |||
795 | /** | ||
796 | * Remove script tags from document | ||
797 | * | ||
798 | * @param DOMElement | ||
799 | * @return void | ||
800 | */ | ||
801 | public function removeScripts($doc) { | ||
802 | $scripts = $doc->getElementsByTagName('script'); | ||
803 | for($i = $scripts->length-1; $i >= 0; $i--) | ||
804 | { | ||
805 | $scripts->item($i)->parentNode->removeChild($scripts->item($i)); | ||
806 | } | ||
807 | } | ||
808 | |||
809 | /** | ||
810 | * Get the inner text of a node. | ||
811 | * This also strips out any excess whitespace to be found. | ||
812 | * | ||
813 | * @param DOMElement $ | ||
814 | * @param boolean $normalizeSpaces (default: true) | ||
815 | * @return string | ||
816 | **/ | ||
817 | public function getInnerText($e, $normalizeSpaces=true) { | ||
818 | $textContent = ''; | ||
819 | |||
820 | if (!isset($e->textContent) || $e->textContent == '') { | ||
821 | return ''; | ||
822 | } | ||
823 | |||
824 | $textContent = trim($e->textContent); | ||
825 | |||
826 | if ($normalizeSpaces) { | ||
827 | return preg_replace($this->regexps['normalize'], ' ', $textContent); | ||
828 | } else { | ||
829 | return $textContent; | ||
830 | } | ||
831 | } | ||
832 | |||
833 | /** | ||
834 | * Get the number of times a string $s appears in the node $e. | ||
835 | * | ||
836 | * @param DOMElement $e | ||
837 | * @param string - what to count. Default is "," | ||
838 | * @return number (integer) | ||
839 | **/ | ||
840 | public function getCharCount($e, $s=',') { | ||
841 | return substr_count($this->getInnerText($e), $s); | ||
842 | } | ||
843 | |||
844 | /** | ||
845 | * Remove the style attribute on every $e and under. | ||
846 | * | ||
847 | * @param DOMElement $e | ||
848 | * @return void | ||
849 | */ | ||
850 | public function cleanStyles($e) { | ||
851 | $elems = $e->getElementsByTagName('*'); | ||
852 | foreach ($elems as $elem) { | ||
853 | $elem->removeAttribute('style'); | ||
854 | } | ||
855 | } | ||
856 | |||
857 | /** | ||
858 | * Get the density of links as a percentage of the content | ||
859 | * This is the amount of text that is inside a link divided by the total text in the node. | ||
860 | * | ||
861 | * @param DOMElement $e | ||
862 | * @return number (float) | ||
863 | */ | ||
864 | public function getLinkDensity($e) { | ||
865 | $links = $e->getElementsByTagName('a'); | ||
866 | $textLength = strlen($this->getInnerText($e)); | ||
867 | $linkLength = 0; | ||
868 | for ($i=0, $il=$links->length; $i < $il; $i++) | ||
869 | { | ||
870 | $linkLength += strlen($this->getInnerText($links->item($i))); | ||
871 | } | ||
872 | if ($textLength > 0) { | ||
873 | return $linkLength / $textLength; | ||
874 | } else { | ||
875 | return 0; | ||
876 | } | ||
877 | } | ||
878 | |||
879 | /** | ||
880 | * Get an elements class/id weight. Uses regular expressions to tell if this | ||
881 | * element looks good or bad. | ||
882 | * | ||
883 | * @param DOMElement $e | ||
884 | * @return number (Integer) | ||
885 | */ | ||
886 | public function getClassWeight($e) { | ||
887 | if(!$this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) { | ||
888 | return 0; | ||
889 | } | ||
890 | |||
891 | $weight = 0; | ||
892 | |||
893 | /* Look for a special classname */ | ||
894 | if ($e->hasAttribute('class') && $e->getAttribute('class') != '') | ||
895 | { | ||
896 | if (preg_match($this->regexps['negative'], $e->getAttribute('class'))) { | ||
897 | $weight -= 25; | ||
898 | } | ||
899 | if (preg_match($this->regexps['positive'], $e->getAttribute('class'))) { | ||
900 | $weight += 25; | ||
901 | } | ||
902 | } | ||
903 | |||
904 | /* Look for a special ID */ | ||
905 | if ($e->hasAttribute('id') && $e->getAttribute('id') != '') | ||
906 | { | ||
907 | if (preg_match($this->regexps['negative'], $e->getAttribute('id'))) { | ||
908 | $weight -= 25; | ||
909 | } | ||
910 | if (preg_match($this->regexps['positive'], $e->getAttribute('id'))) { | ||
911 | $weight += 25; | ||
912 | } | ||
913 | } | ||
914 | return $weight; | ||
915 | } | ||
916 | |||
917 | /** | ||
918 | * Remove extraneous break tags from a node. | ||
919 | * | ||
920 | * @param DOMElement $node | ||
921 | * @return void | ||
922 | */ | ||
923 | public function killBreaks($node) { | ||
924 | $html = $node->innerHTML; | ||
925 | $html = preg_replace($this->regexps['killBreaks'], '<br />', $html); | ||
926 | $node->innerHTML = $html; | ||
927 | } | ||
928 | |||
929 | /** | ||
930 | * Clean a node of all elements of type "tag". | ||
931 | * (Unless it's a youtube/vimeo video. People love movies.) | ||
932 | * | ||
933 | * @param DOMElement $e | ||
934 | * @param string $tag | ||
935 | * @return void | ||
936 | */ | ||
937 | public function clean($e, $tag) { | ||
938 | $targetList = $e->getElementsByTagName($tag); | ||
939 | $isEmbed = ($tag == 'object' || $tag == 'embed'); | ||
940 | |||
941 | for ($y=$targetList->length-1; $y >= 0; $y--) { | ||
942 | /* Allow youtube and vimeo videos through as people usually want to see those. */ | ||
943 | if ($isEmbed) { | ||
944 | $attributeValues = ''; | ||
945 | for ($i=0, $il=$targetList->item($y)->attributes->length; $i < $il; $i++) { | ||
946 | $attributeValues .= $targetList->item($y)->attributes->item($i)->value . '|'; // DOMAttr? (TODO: test) | ||
947 | } | ||
948 | |||
949 | /* First, check the elements attributes to see if any of them contain youtube or vimeo */ | ||
950 | if (preg_match($this->regexps['video'], $attributeValues)) { | ||
951 | continue; | ||
952 | } | ||
953 | |||
954 | /* Then check the elements inside this element for the same. */ | ||
955 | if (preg_match($this->regexps['video'], $targetList->item($y)->innerHTML)) { | ||
956 | continue; | ||
957 | } | ||
958 | } | ||
959 | $targetList->item($y)->parentNode->removeChild($targetList->item($y)); | ||
960 | } | ||
961 | } | ||
962 | |||
963 | /** | ||
964 | * Clean an element of all tags of type "tag" if they look fishy. | ||
965 | * "Fishy" is an algorithm based on content length, classnames, | ||
966 | * link density, number of images & embeds, etc. | ||
967 | * | ||
968 | * @param DOMElement $e | ||
969 | * @param string $tag | ||
970 | * @return void | ||
971 | */ | ||
972 | public function cleanConditionally($e, $tag) { | ||
973 | if (!$this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) { | ||
974 | return; | ||
975 | } | ||
976 | |||
977 | $tagsList = $e->getElementsByTagName($tag); | ||
978 | $curTagsLength = $tagsList->length; | ||
979 | |||
980 | /** | ||
981 | * Gather counts for other typical elements embedded within. | ||
982 | * Traverse backwards so we can remove nodes at the same time without effecting the traversal. | ||
983 | * | ||
984 | * TODO: Consider taking into account original contentScore here. | ||
985 | */ | ||
986 | for ($i=$curTagsLength-1; $i >= 0; $i--) { | ||
987 | $weight = $this->getClassWeight($tagsList->item($i)); | ||
988 | $contentScore = ($tagsList->item($i)->hasAttribute('readability')) ? (int)$tagsList->item($i)->getAttribute('readability') : 0; | ||
989 | |||
990 | $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')) : '')); | ||
991 | |||
992 | if ($weight + $contentScore < 0) { | ||
993 | $tagsList->item($i)->parentNode->removeChild($tagsList->item($i)); | ||
994 | } | ||
995 | else if ( $this->getCharCount($tagsList->item($i), ',') < 10) { | ||
996 | /** | ||
997 | * If there are not very many commas, and the number of | ||
998 | * non-paragraph elements is more than paragraphs or other ominous signs, remove the element. | ||
999 | **/ | ||
1000 | $p = $tagsList->item($i)->getElementsByTagName('p')->length; | ||
1001 | $img = $tagsList->item($i)->getElementsByTagName('img')->length; | ||
1002 | $li = $tagsList->item($i)->getElementsByTagName('li')->length-100; | ||
1003 | $input = $tagsList->item($i)->getElementsByTagName('input')->length; | ||
1004 | |||
1005 | $embedCount = 0; | ||
1006 | $embeds = $tagsList->item($i)->getElementsByTagName('embed'); | ||
1007 | for ($ei=0, $il=$embeds->length; $ei < $il; $ei++) { | ||
1008 | if (preg_match($this->regexps['video'], $embeds->item($ei)->getAttribute('src'))) { | ||
1009 | $embedCount++; | ||
1010 | } | ||
1011 | } | ||
1012 | |||
1013 | $linkDensity = $this->getLinkDensity($tagsList->item($i)); | ||
1014 | $contentLength = strlen($this->getInnerText($tagsList->item($i))); | ||
1015 | $toRemove = false; | ||
1016 | |||
1017 | if ( $img > $p ) { | ||
1018 | $toRemove = true; | ||
1019 | } else if ($li > $p && $tag != 'ul' && $tag != 'ol') { | ||
1020 | $toRemove = true; | ||
1021 | } else if ( $input > floor($p/3) ) { | ||
1022 | $toRemove = true; | ||
1023 | } else if ($contentLength < 25 && ($img === 0 || $img > 2) ) { | ||
1024 | $toRemove = true; | ||
1025 | } else if($weight < 25 && $linkDensity > 0.2) { | ||
1026 | $toRemove = true; | ||
1027 | } else if($weight >= 25 && $linkDensity > 0.5) { | ||
1028 | $toRemove = true; | ||
1029 | } else if(($embedCount == 1 && $contentLength < 75) || $embedCount > 1) { | ||
1030 | $toRemove = true; | ||
1031 | } | ||
1032 | |||
1033 | if ($toRemove) { | ||
1034 | $tagsList->item($i)->parentNode->removeChild($tagsList->item($i)); | ||
1035 | } | ||
1036 | } | ||
1037 | } | ||
1038 | } | ||
1039 | |||
1040 | /** | ||
1041 | * Clean out spurious headers from an Element. Checks things like classnames and link density. | ||
1042 | * | ||
1043 | * @param DOMElement $e | ||
1044 | * @return void | ||
1045 | */ | ||
1046 | public function cleanHeaders($e) { | ||
1047 | for ($headerIndex = 1; $headerIndex < 3; $headerIndex++) { | ||
1048 | $headers = $e->getElementsByTagName('h' . $headerIndex); | ||
1049 | for ($i=$headers->length-1; $i >=0; $i--) { | ||
1050 | if ($this->getClassWeight($headers->item($i)) < 0 || $this->getLinkDensity($headers->item($i)) > 0.33) { | ||
1051 | $headers->item($i)->parentNode->removeChild($headers->item($i)); | ||
1052 | } | ||
1053 | } | ||
1054 | } | ||
1055 | } | ||
1056 | |||
1057 | public function flagIsActive($flag) { | ||
1058 | return ($this->flags & $flag) > 0; | ||
1059 | } | ||
1060 | |||
1061 | public function addFlag($flag) { | ||
1062 | $this->flags = $this->flags | $flag; | ||
1063 | } | ||
1064 | |||
1065 | public function removeFlag($flag) { | ||
1066 | $this->flags = $this->flags & ~$flag; | ||
1067 | } | ||
1068 | } | ||
1069 | ?> \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/api.php b/inc/3rdparty/libraries/send2kindle/api.php deleted file mode 100644 index 564c171c..00000000 --- a/inc/3rdparty/libraries/send2kindle/api.php +++ /dev/null | |||
@@ -1,234 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * @author Dimmduh | ||
4 | * @email dimmduh@gmail.com | ||
5 | */ | ||
6 | class API{ | ||
7 | |||
8 | private $service; | ||
9 | private $auth; | ||
10 | private $token; | ||
11 | private $source = 'GoogleReaderAPIClass-0.1'; | ||
12 | private $client = 'scroll'; | ||
13 | private $account_type = 'HOSTED_OR_GOOGLE'; | ||
14 | private $clientlogin_url = 'https://www.google.com/accounts/ClientLogin'; | ||
15 | private $reader_api_url = 'http://www.google.com/reader/api/0/'; | ||
16 | private $session_var_auth_name = 'google_auth'; | ||
17 | |||
18 | |||
19 | public function __construct( $email, $password, $service = 'reader' ){ | ||
20 | if (isset( $service ) ){ | ||
21 | $this -> service = $service; | ||
22 | } | ||
23 | /* if ( isset($_SESSION[ $this -> session_var_auth_name ] ) ){ | ||
24 | $this -> auth = $_SESSION[ $this -> session_var_auth_name ]; | ||
25 | echo "Loading"; | ||
26 | } else { */ | ||
27 | $this -> clientLogin( $email, $password ); | ||
28 | $this -> get_token(); | ||
29 | /* } */ | ||
30 | } | ||
31 | |||
32 | |||
33 | private function request( $url, $type = 'get', $headers = false, $fields = false, $cookie = false){ | ||
34 | |||
35 | $curl = curl_init(); | ||
36 | |||
37 | if ( $fields ){ | ||
38 | if ($type == 'get'){ | ||
39 | $url .= '?'.http_build_query( $fields ); | ||
40 | } else { | ||
41 | curl_setopt($curl, CURLOPT_POST, true); | ||
42 | curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($fields) ); | ||
43 | } | ||
44 | } | ||
45 | if ( $headers ){ | ||
46 | curl_setopt($curl, CURLOPT_HEADER, true); | ||
47 | curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | ||
48 | } | ||
49 | if ( $cookie ){ | ||
50 | curl_setopt($curl, CURLOPT_COOKIE, $cookie); | ||
51 | } | ||
52 | |||
53 | curl_setopt($curl, CURLOPT_URL, $url); | ||
54 | if (strpos($url, 'https://') !== false){ | ||
55 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | ||
56 | } | ||
57 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | ||
58 | curl_setopt($curl, CURLINFO_HEADER_OUT, true); | ||
59 | |||
60 | $response = array(); | ||
61 | $response['text'] = curl_exec($curl); | ||
62 | $response['info'] = curl_getinfo( $curl); | ||
63 | $response['code'] = curl_getinfo( $curl, CURLINFO_HTTP_CODE ); | ||
64 | $response['body'] = substr( $response['text'], $response['info']['header_size'] ); | ||
65 | |||
66 | curl_close( $curl ); | ||
67 | return $response; | ||
68 | } | ||
69 | |||
70 | private function request2google( $url, $type = 'get', $headers = false, $fields = false ){ | ||
71 | if ( $this -> auth ){ | ||
72 | $headers[] = 'Content-type: application/x-www-form-urlencoded'; | ||
73 | $headers[] = 'Authorization: GoogleLogin auth='.$this -> auth; | ||
74 | |||
75 | if ( strpos( $url, 'http://') === false && strpos( $url, 'https://' ) === false ){ | ||
76 | $url = $this -> reader_api_url.$url; | ||
77 | } | ||
78 | |||
79 | $response = $this -> request( $url, $type, $headers, $fields); | ||
80 | if ( $response['code'] == 200 ){ | ||
81 | if ( isset( $fields['output'] ) ){ | ||
82 | switch ($fields['output']){ | ||
83 | case 'xml': | ||
84 | return (new SimpleXMLElement( $response['body'] ) ); | ||
85 | break; | ||
86 | case 'json': | ||
87 | default: | ||
88 | return json_decode( $response['body'] ); | ||
89 | break; | ||
90 | } | ||
91 | } else { | ||
92 | return $response['body']; | ||
93 | } | ||
94 | } else { | ||
95 | Throw new AutentificationException('Auth error: server response '.$response['code'] ); | ||
96 | } | ||
97 | |||
98 | } else { | ||
99 | Throw new AutentificationException('Auth error: not finded Auth token'); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public function get_tag_list( $output = 'json' ){ | ||
104 | return $this -> request2google('tag/list', "get", false, array( | ||
105 | 'output' => $output, | ||
106 | 'ck' => time(), | ||
107 | 'client' => $this -> client, | ||
108 | )); | ||
109 | } | ||
110 | public function get_subscription_list( $output = 'json' ){ | ||
111 | return $this -> request2google('subscription/list', "get", false, array( | ||
112 | 'output' => $output, | ||
113 | 'ck' => time(), | ||
114 | 'client' => $this -> client, | ||
115 | )); | ||
116 | } | ||
117 | public function get_preference_list( $output = 'json' ){ | ||
118 | return $this -> request2google('preference/list', "get", false, array( | ||
119 | 'output' => $output, | ||
120 | 'ck' => time(), | ||
121 | 'client' => $this -> client, | ||
122 | )); | ||
123 | } | ||
124 | public function get_unread_count( $output = 'json' ){ | ||
125 | return $this -> request2google('unread-count', "get", false, array( | ||
126 | 'all' => true, | ||
127 | 'output' => $output, | ||
128 | 'ck' => time(), | ||
129 | 'client' => $this -> client, | ||
130 | )); | ||
131 | } | ||
132 | public function get_user_info( $output = 'json' ){ | ||
133 | return $this -> request2google('user-info', "get", false, array( | ||
134 | 'output' => $output, | ||
135 | 'ck' => time(), | ||
136 | 'client' => $this -> client, | ||
137 | )); | ||
138 | } | ||
139 | private function get_token(){ | ||
140 | $this -> token = $this -> request2google('token'); | ||
141 | } | ||
142 | |||
143 | //get contents functions | ||
144 | /* | ||
145 | r - order | ||
146 | r = n - new items | ||
147 | r = o - old items | ||
148 | r = a - auto sort | ||
149 | |||
150 | */ | ||
151 | private function get_content( $content_url = '', $number = 20, $order = 'n', $exclude_target = '', $start_time = '', $continuation = ''){ | ||
152 | $fields = array( | ||
153 | 'ck' => time(), | ||
154 | 'client' => $this -> client, | ||
155 | 'n' => $number, | ||
156 | 'r' => $order, | ||
157 | 'output' => 'json', | ||
158 | ); | ||
159 | if ( !empty($exclude_target) ){$fields['xt'] = $exclude_target;} | ||
160 | if ( !empty($start_time) ){$fields['ot'] = $start_time;} | ||
161 | if ( !empty($continuation) ){$fields['c'] = $continuation;} | ||
162 | |||
163 | return $this -> request2google('stream/contents/'.Utils::urlencode( $content_url ), 'get', false, $fields); | ||
164 | } | ||
165 | |||
166 | public function get_content_feed( $feed_url = '', $number = 20, $order = 'n', $exclude_target = '', $start_time = '', $continuation = ''){ | ||
167 | return $this -> get_content( $feed_url, $number, $order, $exclude_target, $start_time, $continuation ); | ||
168 | } | ||
169 | public function get_content_by_label( $label = '', $number = 20, $order = 'n', $exclude_target = '', $start_time = '', $continuation = ''){ | ||
170 | return $this -> get_content( (strpos($label, '/') === false?'user/-/label/':'').$label, $number, $order, $exclude_target, $start_time, $continuation ); | ||
171 | } | ||
172 | public function get_content_by_state( $state = '', $number = 20, $order = 'n', $exclude_target = '', $start_time = '', $continuation = ''){ | ||
173 | return $this -> get_content( (strpos($state, '/') === false?'user/-/state/com.google/':'').$state, $number, $order, $exclude_target, $start_time, $continuation ); | ||
174 | } | ||
175 | |||
176 | public function get_unread( $number = 20, $order = 'n' ){ | ||
177 | return $this ->get_content_by_state('reading-list', $number, $order, 'user/-/state/com.google/read'); | ||
178 | } | ||
179 | |||
180 | public function get_starred($number = 20, $order = 'n'){ | ||
181 | return $this ->get_content_by_state('starred', $number, $order); | ||
182 | } | ||
183 | |||
184 | /* | ||
185 | Edit functions | ||
186 | */ | ||
187 | private function edit_do( $api_function , $post_fields ){ | ||
188 | $post_fields['T'] = $this -> token; | ||
189 | if ( $this -> request2google( $api_function, "post", false, $post_fields ) == "OK"){ | ||
190 | return true; | ||
191 | } else { | ||
192 | return false; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | /* public function edit_subscription( | ||
197 | s return $this -> edit_do( 'subscription/edit', | ||
198 | } */ | ||
199 | public function set_state( $itemId, $state = 'read'){ | ||
200 | $post_fields = array( | ||
201 | "i" => $itemId, | ||
202 | "a" => 'user/-/state/com.google/'.$state, | ||
203 | ); | ||
204 | //print_r( $post_fields ); | ||
205 | return $this ->edit_do('edit-tag?client='.$this -> client, $post_fields); | ||
206 | } | ||
207 | |||
208 | private function clientLogin( $email, $password ){ | ||
209 | |||
210 | $response = $this -> request( $this -> clientlogin_url, 'post', false, array( | ||
211 | "accountType" => $this -> account_type, | ||
212 | "Email" => $email, | ||
213 | "Passwd" => $password, | ||
214 | "service" => $this -> service, | ||
215 | "source" => $this -> source, | ||
216 | )); | ||
217 | |||
218 | if ( $response['code'] == 200) { | ||
219 | preg_match("/Auth=([a-z0-9_\-]+)/i", $response['body'], $matches_auth); | ||
220 | if ($matches_auth[1]){ | ||
221 | $this -> auth = $matches_auth[1]; | ||
222 | $_SESSION[ $this -> session_var_auth_name ] = $this -> auth; | ||
223 | return true; | ||
224 | } else { | ||
225 | Throw new AutentificationException('Auth error: not finded Auth token in response'); | ||
226 | } | ||
227 | } else { | ||
228 | Throw new AutentificationException('Auth error: server response '.$response['code'] ); | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | |||
233 | //Exceptions | ||
234 | class AutentificationException extends Exception {} \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/images.php b/inc/3rdparty/libraries/send2kindle/images.php deleted file mode 100644 index 63f0562a..00000000 --- a/inc/3rdparty/libraries/send2kindle/images.php +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Get images from content and prepare to save in articles | ||
5 | */ | ||
6 | class Images { | ||
7 | |||
8 | /** | ||
9 | * JPER quality for resize | ||
10 | */ | ||
11 | const JPEG_QUALITY = 80; | ||
12 | |||
13 | /** | ||
14 | * Articles content | ||
15 | * @var string | ||
16 | */ | ||
17 | private $_content; | ||
18 | |||
19 | /** | ||
20 | * Storage to keep images | ||
21 | * @var object Storage | ||
22 | */ | ||
23 | private $_storage; | ||
24 | |||
25 | /** | ||
26 | * images from content | ||
27 | * @var array | ||
28 | */ | ||
29 | private $_images_from_content = array(); | ||
30 | |||
31 | /** | ||
32 | * Prepare get images | ||
33 | * @param Strage $storage | ||
34 | * @param string $article_content | ||
35 | */ | ||
36 | public function __construct(Storage $storage, $article_content) | ||
37 | { | ||
38 | $this->_storage = $storage; | ||
39 | $this->_content = $article_content; | ||
40 | $this->_images_from_content = $this->_get_images_from_content($article_content); | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * get images from url | ||
45 | * @param string $content | ||
46 | * @return array images hashtable | ||
47 | */ | ||
48 | private function _get_images_from_content($content) | ||
49 | { | ||
50 | $result = array(); | ||
51 | preg_match_all('/src=\"([a-zA-Z0-9\.\/\-\_\?\+\%\~\&\;\=\:]+)\"/i', $content, $result); | ||
52 | |||
53 | return $result[1]; | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * Start conversion | ||
58 | * @return string converted content | ||
59 | */ | ||
60 | public function convert() | ||
61 | { | ||
62 | foreach ( $this->_images_from_content as $n => $image_url ) | ||
63 | { | ||
64 | $image = $this->_get_image($image_url); | ||
65 | $this->_content = str_replace($image_url, '" recindex="'.(int)basename($image), $this->_content); | ||
66 | } | ||
67 | |||
68 | return $this->_content; | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * Resize image | ||
73 | * @param string $file path | ||
74 | * @param int $new_width max width | ||
75 | */ | ||
76 | private function _resize($file, $new_width = 500) | ||
77 | { | ||
78 | list($width, $height) = getimagesize($file); | ||
79 | |||
80 | $new_height = 0; | ||
81 | |||
82 | //setup the new size of the image | ||
83 | if( $width > $new_width ) | ||
84 | { | ||
85 | $ratio = $height/$width; | ||
86 | $new_height = $new_width * $ratio; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | $new_width = $width; | ||
91 | $new_height = $height; | ||
92 | } | ||
93 | |||
94 | // resample the image | ||
95 | $new_image = imagecreatetruecolor($new_width, $new_height); | ||
96 | |||
97 | $type = exif_imagetype ( $file ); | ||
98 | |||
99 | switch ( $type ) | ||
100 | { | ||
101 | case IMAGETYPE_JPEG: | ||
102 | $old_image = imagecreatefromjpeg($file); | ||
103 | imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); | ||
104 | imagejpeg($new_image, $file, self::JPEG_QUALITY); | ||
105 | break; | ||
106 | case IMAGETYPE_PNG: | ||
107 | $old_image = imagecreatefrompng($file); | ||
108 | imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); | ||
109 | imagepng($new_image, $file); | ||
110 | break; | ||
111 | case IMAGETYPE_GIF: | ||
112 | $old_image = imagecreatefromgif($file); | ||
113 | imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); | ||
114 | imagegif($new_image, $file); | ||
115 | break; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | /** | ||
120 | * Resize image | ||
121 | * @return string image path | ||
122 | */ | ||
123 | private function _get_image($url) | ||
124 | { | ||
125 | $image_data = @file_get_contents($url); | ||
126 | |||
127 | if ( $image_data !== false ) | ||
128 | { | ||
129 | $image_name = $this->_storage->save_image($image_data); | ||
130 | $this->_resize($image_name); | ||
131 | |||
132 | return $image_name; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | } \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/io.php b/inc/3rdparty/libraries/send2kindle/io.php deleted file mode 100644 index 284c08cc..00000000 --- a/inc/3rdparty/libraries/send2kindle/io.php +++ /dev/null | |||
@@ -1,250 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Simple output message and args prepared | ||
4 | * | ||
5 | * @author Jakub Westfalewski <jwest@jwest.pl> | ||
6 | */ | ||
7 | class IO { | ||
8 | |||
9 | /** | ||
10 | * Max line height | ||
11 | */ | ||
12 | const COMMAND_LENGTH = 50; | ||
13 | |||
14 | /** | ||
15 | * args for run screen | ||
16 | * @var array | ||
17 | */ | ||
18 | protected static $_args = array | ||
19 | ( | ||
20 | 'help' => array('value' => FALSE, 'description' => 'show help for news2kindle'), | ||
21 | 'grab' => array('value' => FALSE, 'description' => 'grab articles from google reader'), | ||
22 | 'mobi' => array('value' => FALSE, 'description' => 'prepare mobi format'), | ||
23 | 'send' => array('value' => FALSE, 'description' => 'send articles to kindle'), | ||
24 | 'login' => array('value' => NULL, 'description' => 'your login to google account *requred'), | ||
25 | 'password' => array('value' => NULL, 'description' => 'your password to google account *required'), | ||
26 | 'kindle' => array('value' => NULL, 'description' => 'your kindle email *required'), | ||
27 | 'items' => array('value' => 100, 'description' => 'max items to grab in run'), | ||
28 | 'render' => array('value' => 'std', 'description' => 'name of html template for newspapper'), | ||
29 | //'timeout' => array('value' => FALSE, 'description' => 'timeout is most important than items count'), | ||
30 | ); | ||
31 | |||
32 | /** | ||
33 | * Write on screen text line | ||
34 | * @param string $message | ||
35 | * @param bool $broken_line | ||
36 | */ | ||
37 | public static function msg($message, $broken_line = TRUE) | ||
38 | { | ||
39 | echo ( $broken_line ? "\n" : "" ) . $message; | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Write command for status | ||
44 | * @param string $message | ||
45 | */ | ||
46 | public static function command($message) | ||
47 | { | ||
48 | $output_whitespaces = ''; | ||
49 | |||
50 | for ($i = strlen($message); $i <= self::COMMAND_LENGTH; ++$i ) | ||
51 | { | ||
52 | $output_whitespaces .= '-'; | ||
53 | } | ||
54 | |||
55 | self::msg( $message . ' ' . $output_whitespaces.' ' ); | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * Status - OK | ||
60 | */ | ||
61 | public static function ok() | ||
62 | { | ||
63 | $colored_string = "\033[1;37m" . "\033[42m" . ' OK ' . "\033[0m"; | ||
64 | self::msg( $colored_string, FALSE ); | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * Status - Error | ||
69 | */ | ||
70 | public static function error($message = NULL) | ||
71 | { | ||
72 | $colored_string = "\033[1;37m" . "\033[41m" . ' ERROR ' . "\033[0m"; | ||
73 | self::msg( $colored_string, FALSE ); | ||
74 | |||
75 | if ( $message !== NULL ) | ||
76 | { | ||
77 | self::msg( ' - ' . $message ); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * Get run args | ||
83 | * @param string $name key config | ||
84 | * @return mixed config value | ||
85 | */ | ||
86 | public static function arg($name) | ||
87 | { | ||
88 | return self::$_args[$name]['value']; | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * Get config from ini | ||
93 | * @param string $path | ||
94 | * @return void | ||
95 | */ | ||
96 | protected static function _get_config($path) | ||
97 | { | ||
98 | $config = parse_ini_file( $path . 'config.ini' ); | ||
99 | |||
100 | foreach($config as $key => $value) | ||
101 | { | ||
102 | self::$_args[$key]['value'] = $value; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * Prepare args for script | ||
108 | * (from http://php.net/manual/en/features.commandline.php) | ||
109 | * @param array $argv array | ||
110 | * @param string $path | ||
111 | * @return bool success or error | ||
112 | */ | ||
113 | public static function prepare_args($argv, $path) | ||
114 | { | ||
115 | self::command('Parse args'); | ||
116 | |||
117 | self::_get_config($path); | ||
118 | |||
119 | array_shift($argv); | ||
120 | $out = array(); | ||
121 | |||
122 | foreach ( $argv as $arg ) | ||
123 | { | ||
124 | if ( substr($arg,0,2) == '--' ) | ||
125 | { | ||
126 | $eqPos = strpos($arg,'='); | ||
127 | |||
128 | if ( $eqPos === false ) | ||
129 | { | ||
130 | $key = substr($arg,2); | ||
131 | $out[$key] = isset($out[$key]) ? $out[$key] : true; | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | $key = substr($arg,2,$eqPos-2); | ||
136 | $out[$key] = substr($arg,$eqPos+1); | ||
137 | } | ||
138 | |||
139 | } | ||
140 | else if ( substr($arg,0,1) == '-' ) | ||
141 | { | ||
142 | if ( substr($arg,2,1) == '=' ) | ||
143 | { | ||
144 | $key = substr($arg,1,1); | ||
145 | $out[$key] = substr($arg,3); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | $chars = str_split(substr($arg,1)); | ||
150 | |||
151 | foreach ( $chars as $char ) | ||
152 | { | ||
153 | $key = $char; | ||
154 | $out[$key] = isset($out[$key]) ? $out[$key] : true; | ||
155 | } | ||
156 | } | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | $out[] = $arg; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | try | ||
165 | { | ||
166 | $args = self::_validate_args($out); | ||
167 | |||
168 | foreach ( $args as $key => $value ) | ||
169 | { | ||
170 | self::$_args[$key]['value'] = $value; | ||
171 | } | ||
172 | } | ||
173 | catch(Exception $e) | ||
174 | { | ||
175 | self::error($e->getMessage()); | ||
176 | return false; | ||
177 | } | ||
178 | |||
179 | self::ok(); | ||
180 | |||
181 | return true; | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * Validate args for script | ||
186 | * (from http://php.net/manual/en/features.commandline.php) | ||
187 | * @param array $argv array | ||
188 | * @return array args | ||
189 | */ | ||
190 | private static function _validate_args($args) | ||
191 | { | ||
192 | if( array_key_exists('help', $args) OR array_key_exists('h', $args) ) | ||
193 | { | ||
194 | $args['grab'] = false; | ||
195 | $args['mobi'] = false; | ||
196 | $args['send'] = false; | ||
197 | $args['login'] = false; | ||
198 | $args['password'] = false; | ||
199 | $args['kindle'] = false; | ||
200 | } | ||
201 | |||
202 | foreach ( $args as $key => $arg ) | ||
203 | { | ||
204 | if ( strlen($key) === 1 ) | ||
205 | { | ||
206 | foreach ( self::$_args as $keyA => $argA ) | ||
207 | { | ||
208 | if($keyA[0] === $key ) | ||
209 | { | ||
210 | unset( $args[$key] ); | ||
211 | $args[$keyA] = $arg; | ||
212 | $key = $keyA; | ||
213 | } | ||
214 | } | ||
215 | } | ||
216 | |||
217 | if ( ! array_key_exists($key, self::$_args) ) | ||
218 | { | ||
219 | throw new Exception('Param "'.$key.'" is invalid!'); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | foreach ( self::$_args as $key => $arg ) | ||
224 | { | ||
225 | if( self::$_args[$key]['value'] === NULL AND !array_key_exists($key, $args) ) | ||
226 | { | ||
227 | throw new Exception('Param "'.$key.'" must be declared!'); | ||
228 | } | ||
229 | } | ||
230 | |||
231 | return $args; | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * Prepare help | ||
236 | * @return array | ||
237 | */ | ||
238 | public static function get_help() | ||
239 | { | ||
240 | $output = array(); | ||
241 | |||
242 | foreach ( self::$_args as $arg => $item ) | ||
243 | { | ||
244 | $output[$arg] = $item['description']; | ||
245 | } | ||
246 | |||
247 | return $output; | ||
248 | } | ||
249 | |||
250 | } \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/readability.php b/inc/3rdparty/libraries/send2kindle/readability.php deleted file mode 100644 index 18c2dbde..00000000 --- a/inc/3rdparty/libraries/send2kindle/readability.php +++ /dev/null | |||
@@ -1,249 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * PHP Readability | ||
4 | * | ||
5 | * Readability PHP 版本,详见 | ||
6 | * http://code.google.com/p/arc90labs-readability/ | ||
7 | * | ||
8 | * ChangeLog: | ||
9 | * | ||
10 | * [+] 2011-02-17 初始化版本 | ||
11 | * | ||
12 | * @author mingcheng<i.feelinglucky#gmail.com> | ||
13 | * @date 2011-02-17 | ||
14 | * @link http://www.gracecode.com/ | ||
15 | */ | ||
16 | |||
17 | define("READABILITY_VERSION", 0.12); | ||
18 | |||
19 | class Readability2 { | ||
20 | // 保存判定结果的标记位名称 | ||
21 | const ATTR_CONTENT_SCORE = "contentScore"; | ||
22 | |||
23 | // DOM 解析类目前只支持 UTF-8 编码 | ||
24 | const DOM_DEFAULT_CHARSET = "utf-8"; | ||
25 | |||
26 | // 当判定失败时显示的内容 | ||
27 | const MESSAGE_CAN_NOT_GET = "Sorry, readability was unable to parse this page for content. \n | ||
28 | If you feel like it should have been able to, | ||
29 | please let me know by mail: lucky[at]gracecode.com"; | ||
30 | |||
31 | // DOM 解析类(PHP5 已内置) | ||
32 | protected $DOM = null; | ||
33 | |||
34 | // 需要解析的源代码 | ||
35 | protected $source = ""; | ||
36 | |||
37 | // 章节的父元素列表 | ||
38 | private $parentNodes = array(); | ||
39 | |||
40 | // 需要删除的标签 | ||
41 | private $junkTags = Array("style", "form", "iframe", "script", "button", "input", "textarea"); | ||
42 | |||
43 | // 需要删除的属性 | ||
44 | private $junkAttrs = Array("style", "class", "onclick", "onmouseover", "align", "border", "margin"); | ||
45 | |||
46 | |||
47 | /** | ||
48 | * 构造函数 | ||
49 | * @param $input_char 字符串的编码。默认 utf-8,可以省略 | ||
50 | */ | ||
51 | function __construct($source, $input_char = "utf-8") { | ||
52 | $this->source = $source; | ||
53 | |||
54 | // DOM 解析类只能处理 UTF-8 格式的字符 | ||
55 | $source = mb_convert_encoding($source, 'HTML-ENTITIES', $input_char); | ||
56 | |||
57 | // 预处理 HTML 标签,剔除冗余的标签等 | ||
58 | $source = $this->preparSource($source); | ||
59 | |||
60 | // 生成 DOM 解析类 | ||
61 | $this->DOM = new DOMDocument('1.0', $input_char); | ||
62 | try { | ||
63 | //libxml_use_internal_errors(true); | ||
64 | // 会有些错误信息,不过不要紧 :^) | ||
65 | if (!@$this->DOM->loadHTML('<?xml encoding="'.Readability2::DOM_DEFAULT_CHARSET.'">'.$source)) { | ||
66 | throw new Exception("Parse HTML Error!"); | ||
67 | } | ||
68 | |||
69 | foreach ($this->DOM->childNodes as $item) { | ||
70 | if ($item->nodeType == XML_PI_NODE) { | ||
71 | $this->DOM->removeChild($item); // remove hack | ||
72 | } | ||
73 | } | ||
74 | |||
75 | // insert proper | ||
76 | $this->DOM->encoding = Readability2::DOM_DEFAULT_CHARSET; | ||
77 | } catch (Exception $e) { | ||
78 | // ... | ||
79 | } | ||
80 | } | ||
81 | |||
82 | |||
83 | /** | ||
84 | * 预处理 HTML 标签,使其能够准确被 DOM 解析类处理 | ||
85 | * | ||
86 | * @return String | ||
87 | */ | ||
88 | private function preparSource($string) { | ||
89 | // 剔除多余的 HTML 编码标记,避免解析出错 | ||
90 | preg_match("/charset=([\w|\-]+);?/", $string, $match); | ||
91 | if (isset($match[1])) { | ||
92 | $string = preg_replace("/charset=([\w|\-]+);?/", "", $string, 1); | ||
93 | } | ||
94 | |||
95 | // Replace all doubled-up <BR> tags with <P> tags, and remove fonts. | ||
96 | $string = preg_replace("/<br\/?>[ \r\n\s]*<br\/?>/i", "</p><p>", $string); | ||
97 | $string = preg_replace("/<\/?font[^>]*>/i", "", $string); | ||
98 | |||
99 | return trim($string); | ||
100 | } | ||
101 | |||
102 | |||
103 | /** | ||
104 | * 删除 DOM 元素中所有的 $TagName 标签 | ||
105 | * | ||
106 | * @return DOMDocument | ||
107 | */ | ||
108 | private function removeJunkTag($RootNode, $TagName) { | ||
109 | $Tags = $RootNode->getElementsByTagName($TagName); | ||
110 | |||
111 | $i = 0; | ||
112 | while($Tag = $Tags->item($i++)) { | ||
113 | $parentNode = $Tag->parentNode; | ||
114 | $parentNode->removeChild($Tag); | ||
115 | } | ||
116 | |||
117 | return $RootNode; | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * 删除元素中所有不需要的属性 | ||
122 | */ | ||
123 | private function removeJunkAttr($RootNode, $Attr) { | ||
124 | $Tags = $RootNode->getElementsByTagName("*"); | ||
125 | |||
126 | $i = 0; | ||
127 | while($Tag = $Tags->item($i++)) { | ||
128 | $Tag->removeAttribute($Attr); | ||
129 | } | ||
130 | |||
131 | return $RootNode; | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * 根据评分获取页面主要内容的盒模型 | ||
136 | * 判定算法来自:http://code.google.com/p/arc90labs-readability/ | ||
137 | * | ||
138 | * @return DOMNode | ||
139 | */ | ||
140 | private function getTopBox() { | ||
141 | // 获得页面所有的章节 | ||
142 | $allParagraphs = $this->DOM->getElementsByTagName("p"); | ||
143 | |||
144 | // Study all the paragraphs and find the chunk that has the best score. | ||
145 | // A score is determined by things like: Number of <p>'s, commas, special classes, etc. | ||
146 | $i = 0; | ||
147 | while($paragraph = $allParagraphs->item($i++)) { | ||
148 | $parentNode = $paragraph->parentNode; | ||
149 | $contentScore = intval($parentNode->getAttribute(Readability2::ATTR_CONTENT_SCORE)); | ||
150 | $className = $parentNode->getAttribute("class"); | ||
151 | $id = $parentNode->getAttribute("id"); | ||
152 | |||
153 | // Look for a special classname | ||
154 | if (preg_match("/(comment|meta|footer|footnote)/i", $className)) { | ||
155 | $contentScore -= 50; | ||
156 | } else if(preg_match( | ||
157 | "/((^|\\s)(post|hentry|entry[-]?(content|text|body)?|article[-]?(content|text|body)?)(\\s|$))/i", | ||
158 | $className)) { | ||
159 | $contentScore += 25; | ||
160 | } | ||
161 | |||
162 | // Look for a special ID | ||
163 | if (preg_match("/(comment|meta|footer|footnote)/i", $id)) { | ||
164 | $contentScore -= 50; | ||
165 | } else if (preg_match( | ||
166 | "/^(post|hentry|entry[-]?(content|text|body)?|article[-]?(content|text|body)?)$/i", | ||
167 | $id)) { | ||
168 | $contentScore += 25; | ||
169 | } | ||
170 | |||
171 | // Add a point for the paragraph found | ||
172 | // Add points for any commas within this paragraph | ||
173 | if (strlen($paragraph->nodeValue) > 10) { | ||
174 | $contentScore += strlen($paragraph->nodeValue); | ||
175 | } | ||
176 | |||
177 | // 保存父元素的判定得分 | ||
178 | $parentNode->setAttribute(Readability2::ATTR_CONTENT_SCORE, $contentScore); | ||
179 | |||
180 | // 保存章节的父元素,以便下次快速获取 | ||
181 | array_push($this->parentNodes, $parentNode); | ||
182 | } | ||
183 | |||
184 | $topBox = $this->DOM->createElement('div', Readability2::MESSAGE_CAN_NOT_GET); | ||
185 | // Assignment from index for performance. | ||
186 | // See http://www.peachpit.com/articles/article.aspx?p=31567&seqNum=5 | ||
187 | for ($i = 0, $len = sizeof($this->parentNodes); $i < $len; $i++) { | ||
188 | $parentNode = $this->parentNodes[$i]; | ||
189 | $contentScore = intval($parentNode->getAttribute(Readability2::ATTR_CONTENT_SCORE)); | ||
190 | $orgContentScore = intval($topBox->getAttribute(Readability2::ATTR_CONTENT_SCORE)); | ||
191 | |||
192 | if ($contentScore && $contentScore > $orgContentScore) { | ||
193 | $topBox = $parentNode; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | // 此时,$topBox 应为已经判定后的页面内容主元素 | ||
198 | return $topBox; | ||
199 | } | ||
200 | |||
201 | |||
202 | /** | ||
203 | * 获取 HTML 页面标题 | ||
204 | * | ||
205 | * @return String | ||
206 | */ | ||
207 | public function getTitle() { | ||
208 | $title = $this->DOM->getElementsByTagName("title"); | ||
209 | return $title->item(0); | ||
210 | } | ||
211 | |||
212 | |||
213 | /** | ||
214 | * 获取页面的主要内容(Readability 以后的内容) | ||
215 | * | ||
216 | * @return Array | ||
217 | */ | ||
218 | public function getContent() { | ||
219 | if (!$this->DOM) return false; | ||
220 | |||
221 | // 获取页面标题 | ||
222 | $ContentTitle = $this->getTitle(); | ||
223 | |||
224 | // 获取页面主内容 | ||
225 | $ContentBox = $this->getTopBox(); | ||
226 | |||
227 | // 复制内容到新的 DOMDocument | ||
228 | $Target = new DOMDocument; | ||
229 | $Target->appendChild($Target->importNode($ContentBox, true)); | ||
230 | |||
231 | // 删除不需要的标签 | ||
232 | foreach ($this->junkTags as $tag) { | ||
233 | $Target = $this->removeJunkTag($Target, $tag); | ||
234 | } | ||
235 | |||
236 | // 删除不需要的属性 | ||
237 | foreach ($this->junkAttrs as $attr) { | ||
238 | $Target = $this->removeJunkAttr($Target, $attr); | ||
239 | } | ||
240 | |||
241 | // 多个数据,以数组的形式返回 | ||
242 | return Array( | ||
243 | 'title' => $ContentTitle ? $ContentTitle->nodeValue : "", | ||
244 | 'content' => $Target->saveHTML() | ||
245 | ); | ||
246 | } | ||
247 | |||
248 | function __destruct() { } | ||
249 | } | ||
diff --git a/inc/3rdparty/libraries/send2kindle/send.php b/inc/3rdparty/libraries/send2kindle/send.php deleted file mode 100644 index a4861d30..00000000 --- a/inc/3rdparty/libraries/send2kindle/send.php +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Send to kindle email | ||
4 | * @author jwest <jwest@jwest.pl> | ||
5 | */ | ||
6 | class Send { | ||
7 | |||
8 | /** | ||
9 | * Your kindle email | ||
10 | * @var string | ||
11 | */ | ||
12 | private $_kindle_email; | ||
13 | |||
14 | /** | ||
15 | * Your email (must be added on amazon) | ||
16 | * @var string | ||
17 | */ | ||
18 | private $_email; | ||
19 | |||
20 | /** | ||
21 | * Prepare mail | ||
22 | * @param string $kindle_email your kindle email | ||
23 | * @param string $email email for send to kindle | ||
24 | */ | ||
25 | public function __construct($kindle_email, $email) | ||
26 | { | ||
27 | $this->_kindle_email = $kindle_email; | ||
28 | $this->_email = $email; | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * Send file | ||
33 | * @param string $file path to file | ||
34 | * @return bool | ||
35 | */ | ||
36 | public function send($file) | ||
37 | { | ||
38 | //prepare file | ||
39 | $file_size = filesize($file); | ||
40 | $filename = basename($file); | ||
41 | $handle = fopen($file, "r"); | ||
42 | $content = fread($handle, $file_size); | ||
43 | fclose($handle); | ||
44 | $content = chunk_split(base64_encode($content)); | ||
45 | |||
46 | $uid = md5(uniqid(time())); | ||
47 | |||
48 | //generate header for mail | ||
49 | $header = "From: News2Kindle <".$this->_email.">\r\n"; | ||
50 | $header .= "MIME-Version: 1.0\r\n"; | ||
51 | $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; | ||
52 | $header .= "This is a multi-part message in MIME format.\r\n"; | ||
53 | $header .= "--".$uid."\r\n"; | ||
54 | $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; | ||
55 | $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; | ||
56 | $header .= "send via News2Kindle script\r\n\r\n"; | ||
57 | $header .= "--".$uid."\r\n"; | ||
58 | $header .= "Content-Type: application/x-mobipocket-ebook; name=\"".$filename."\"\r\n"; | ||
59 | $header .= "Content-Transfer-Encoding: base64\r\n"; | ||
60 | $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; | ||
61 | $header .= $content."\r\n\r\n"; | ||
62 | $header .= "--".$uid."--"; | ||
63 | |||
64 | //send mail | ||
65 | return mail( $this->_kindle_email, '[newsToKindle] ' . $filename, "", $header ); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | ?> \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/storage.php b/inc/3rdparty/libraries/send2kindle/storage.php deleted file mode 100644 index 5c38ce80..00000000 --- a/inc/3rdparty/libraries/send2kindle/storage.php +++ /dev/null | |||
@@ -1,230 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Storage for news2Kindle | ||
4 | * @author jwest <jwest@jwest.pl> | ||
5 | */ | ||
6 | class Storage { | ||
7 | |||
8 | /** | ||
9 | * Newspapper name | ||
10 | * @var string | ||
11 | */ | ||
12 | private $_name; | ||
13 | |||
14 | /** | ||
15 | * Default dir | ||
16 | * @var string | ||
17 | */ | ||
18 | private $_default_dir = 'data/'; | ||
19 | |||
20 | /** | ||
21 | * Info about newspapper | ||
22 | * @var array | ||
23 | */ | ||
24 | private $_info; | ||
25 | |||
26 | /** | ||
27 | * Prepare storage | ||
28 | * @param string $newspapper | ||
29 | * @param string $default_dir | ||
30 | */ | ||
31 | public function __construct($newspapper, $default_dir = NULL) | ||
32 | { | ||
33 | $this->_name = $newspapper; | ||
34 | |||
35 | if ( $default_dir !== NULL ) | ||
36 | { | ||
37 | $this->_default_dir = $default_dir; | ||
38 | } | ||
39 | |||
40 | $this->_info = $this->_get_info(); | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * save info before exit from script | ||
45 | */ | ||
46 | public function __destruct() | ||
47 | { | ||
48 | $this->_save_info($this->_info); | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Get path | ||
53 | * @param bool $newspapper path to newspapper | ||
54 | * @return string path to repository | ||
55 | */ | ||
56 | public function get_path($newspapper = true) | ||
57 | { | ||
58 | $path = $this->_default_dir; | ||
59 | |||
60 | if ( $newspapper ) | ||
61 | { | ||
62 | $path .= $this->_name . '/'; | ||
63 | } | ||
64 | |||
65 | return $path; | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * Get info about newspapper | ||
70 | * @return array newspapper info | ||
71 | */ | ||
72 | private function _get_info() | ||
73 | { | ||
74 | $content = unserialize( $this->_get_file('info.dat') ); | ||
75 | |||
76 | if( $content === FALSE ) | ||
77 | { | ||
78 | $content = (object) array | ||
79 | ( | ||
80 | 'images_count' => 0, | ||
81 | 'articles_count' => 0, | ||
82 | 'images' => array(), | ||
83 | ); | ||
84 | |||
85 | $this->_save_info($content); | ||
86 | } | ||
87 | |||
88 | return $content; | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * Get info key | ||
93 | * @param $key | ||
94 | * @return mixed | ||
95 | */ | ||
96 | public function info($key) | ||
97 | { | ||
98 | return $this->_info->$key; | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * Save info | ||
103 | * @param array $info info from class | ||
104 | */ | ||
105 | private function _save_info($info) | ||
106 | { | ||
107 | $this->_save_file( 'info.dat', serialize($info) ); | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * Save image in storage | ||
112 | * @param resource $image | ||
113 | * @param string $name image name, if null create auto name | ||
114 | * @return string image name | ||
115 | */ | ||
116 | public function save_image($image, $name = NULL) | ||
117 | { | ||
118 | if ( $name === NULL ) | ||
119 | { | ||
120 | $image_name = (string) $this->_info->images_count; | ||
121 | |||
122 | for ($i=strlen($image_name); $i<6; $i++) | ||
123 | { | ||
124 | $image_name = '0'.$image_name; | ||
125 | } | ||
126 | |||
127 | $this->_info->images_count++; | ||
128 | $this->_info->images[$this->_info->images_count] = $image_name; | ||
129 | |||
130 | $name = $image_name; | ||
131 | } | ||
132 | |||
133 | $this->_save_file($name, $image); | ||
134 | |||
135 | return $this->_default_dir . $this->_name . '/' . $name; | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * Get image | ||
140 | * @param string $name image name | ||
141 | * @return resource | ||
142 | */ | ||
143 | public function get_image($name) | ||
144 | { | ||
145 | return $this->_get_file($name); | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * Put article contents | ||
150 | * @param string $id unique id for article | ||
151 | * @param string $title | ||
152 | * @param string $content article content | ||
153 | * @param string $url url for article | ||
154 | * @param object $website | ||
155 | */ | ||
156 | public function add_content($id, $title, $content, $url, $website) | ||
157 | { | ||
158 | $articles = unserialize( $this->_get_file('articles.dat') ); | ||
159 | |||
160 | $articles[$id] = (object) array | ||
161 | ( | ||
162 | 'id' => $id, | ||
163 | 'title' => $title, | ||
164 | 'content' => $content, | ||
165 | 'url' => $url, | ||
166 | 'website' => $website, | ||
167 | ); | ||
168 | |||
169 | $this->_save_file( 'articles.dat', serialize($articles) ); | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * Get articles contents | ||
174 | * @param string $file_name | ||
175 | * @param string $file_content | ||
176 | */ | ||
177 | public function get_contents() | ||
178 | { | ||
179 | return unserialize( $this->_get_file( 'articles.dat' ) ); | ||
180 | } | ||
181 | |||
182 | /** | ||
183 | * Get file content | ||
184 | * @param string $file_name | ||
185 | * @param string $file_content | ||
186 | */ | ||
187 | private function _save_file($file_name, $file_content) | ||
188 | { | ||
189 | if( ! file_exists( $this->_default_dir . $this->_name ) ) | ||
190 | { | ||
191 | mkdir( $this->_default_dir . $this->_name, 0777, TRUE ); | ||
192 | } | ||
193 | |||
194 | file_put_contents($this->_default_dir . $this->_name . '/' . $file_name, $file_content); | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * Get file content | ||
199 | * @param string $file_name | ||
200 | * @param string $default_file_content (if file not exists) | ||
201 | * @return string file content | ||
202 | */ | ||
203 | private function _get_file($file_name, $default_file_content = NULL) | ||
204 | { | ||
205 | $content = @file_get_contents($this->_default_dir . $this->_name . '/' . $file_name); | ||
206 | |||
207 | if ($content === FALSE) | ||
208 | { | ||
209 | return $default_file_content; | ||
210 | } | ||
211 | |||
212 | return $content; | ||
213 | } | ||
214 | |||
215 | /** | ||
216 | * Clean newspapper after convert to mobi | ||
217 | */ | ||
218 | public function clean() | ||
219 | { | ||
220 | $files_to_remove = glob($this->_default_dir . $this->_name . '/*'); | ||
221 | |||
222 | foreach ( $files_to_remove as $file ) | ||
223 | { | ||
224 | unlink( $file ); | ||
225 | } | ||
226 | |||
227 | rmdir( $this->_default_dir . $this->_name ); | ||
228 | } | ||
229 | |||
230 | } \ No newline at end of file | ||
diff --git a/inc/3rdparty/libraries/send2kindle/utils.php b/inc/3rdparty/libraries/send2kindle/utils.php deleted file mode 100644 index 87cc3de0..00000000 --- a/inc/3rdparty/libraries/send2kindle/utils.php +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Utils for news2kindle | ||
4 | * @author jwest <jwest@jwest.pl> | ||
5 | */ | ||
6 | class Utils | ||
7 | { | ||
8 | /** | ||
9 | * URL encode | ||
10 | * @param string $url | ||
11 | * @return string $ar_url | ||
12 | */ | ||
13 | public static function urlencode( $url ) | ||
14 | { | ||
15 | $ar_url = explode( '/', $url ); | ||
16 | |||
17 | foreach ( $ar_url as $key => $val ) | ||
18 | { | ||
19 | $ar_url[ $key ] = urlencode( $val ); | ||
20 | } | ||
21 | |||
22 | return implode('/', $ar_url ); | ||
23 | } | ||
24 | |||
25 | /** | ||
26 | * Prepare ID for google rss article | ||
27 | * @param string $id | ||
28 | * @return string | ||
29 | */ | ||
30 | public static function prepare_id($id) | ||
31 | { | ||
32 | $char_in = array('/', '.', ',', ':'); | ||
33 | $id = str_replace($char_in, '-', $id); | ||
34 | |||
35 | return $id; | ||
36 | } | ||
37 | } \ No newline at end of file | ||