]>
Commit | Line | Data |
---|---|---|
cc85704f | 1 | <?php |
0862a602 | 2 | class Af_RedditImgur extends Plugin { |
19c73507 AD |
3 | private $host; |
4 | ||
d2a421e3 | 5 | function about() { |
7a866114 | 6 | return array(1.0, |
a95fb169 | 7 | "Inline images (and other content) in Reddit RSS feeds", |
7a866114 AD |
8 | "fox"); |
9 | } | |
10 | ||
41245888 AD |
11 | function flags() { |
12 | return array("needs_curl" => true); | |
13 | } | |
14 | ||
d2a421e3 | 15 | function init($host) { |
19c73507 AD |
16 | $this->host = $host; |
17 | ||
18 | $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); | |
b90c4468 AD |
19 | $host->add_hook($host::HOOK_PREFS_TAB, $this); |
20 | } | |
21 | ||
22 | function hook_prefs_tab($args) { | |
23 | if ($args != "prefFeeds") return; | |
24 | ||
25 | print "<div id=\"af_redditimgur_prefs\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('af_redditimgur settings')."\">"; | |
26 | ||
27 | $enable_readability = $this->host->get($this, "enable_readability"); | |
28 | $enable_readability_checked = $enable_readability ? "checked" : ""; | |
29 | ||
891b77f9 AD |
30 | $enable_content_dupcheck = $this->host->get($this, "enable_content_dupcheck"); |
31 | $enable_content_dupcheck_checked = $enable_content_dupcheck ? "checked" : ""; | |
8788698b | 32 | |
b90c4468 AD |
33 | print "<form dojoType=\"dijit.form.Form\">"; |
34 | ||
35 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
36 | evt.preventDefault(); | |
37 | if (this.validate()) { | |
38 | console.log(dojo.objectToQuery(this.getValues())); | |
39 | new Ajax.Request('backend.php', { | |
40 | parameters: dojo.objectToQuery(this.getValues()), | |
41 | onComplete: function(transport) { | |
42 | notify_info(transport.responseText); | |
43 | } | |
44 | }); | |
45 | //this.reset(); | |
46 | } | |
47 | </script>"; | |
48 | ||
49 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">"; | |
50 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">"; | |
51 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"af_redditimgur\">"; | |
52 | ||
73dfda1d | 53 | print "<p>" . __("Uses Readability (full-text-rss) implementation by <a target='_blank' href='https://bitbucket.org/fivefilters/'>FiveFilters.org</a>"); |
b90c4468 AD |
54 | print "<p/>"; |
55 | ||
56 | print "<input dojoType=\"dijit.form.CheckBox\" id=\"enable_readability\" | |
57 | $enable_readability_checked name=\"enable_readability\"> "; | |
58 | ||
59 | print "<label for=\"enable_readability\">" . __("Extract missing content using Readability") . "</label>"; | |
60 | ||
891b77f9 | 61 | print "<br/>"; |
8788698b | 62 | |
891b77f9 AD |
63 | print "<input dojoType=\"dijit.form.CheckBox\" id=\"enable_content_dupcheck\" |
64 | $enable_content_dupcheck_checked name=\"enable_content_dupcheck\"> "; | |
65 | ||
66 | print "<label for=\"enable_content_dupcheck\">" . __("Enable additional duplicate checking") . "</label>"; | |
b90c4468 AD |
67 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". |
68 | __("Save")."</button>"; | |
69 | ||
70 | print "</form>"; | |
71 | ||
72 | print "</div>"; | |
73 | } | |
74 | ||
75 | function save() { | |
76 | $enable_readability = checkbox_to_sql_bool($_POST["enable_readability"]) == "true"; | |
891b77f9 | 77 | $enable_content_dupcheck = checkbox_to_sql_bool($_POST["enable_content_dupcheck"]) == "true"; |
4533b3ef | 78 | |
891b77f9 AD |
79 | $this->host->set($this, "enable_readability", $enable_readability, false); |
80 | $this->host->set($this, "enable_content_dupcheck", $enable_content_dupcheck); | |
b90c4468 AD |
81 | |
82 | echo __("Configuration saved"); | |
19c73507 AD |
83 | } |
84 | ||
ec482d28 | 85 | private function inline_stuff($article, &$doc, $xpath, $debug = false) { |
cc85704f | 86 | |
6322fc68 | 87 | $entries = $xpath->query('(//a[@href]|//img[@src])'); |
cc85704f | 88 | |
6322fc68 | 89 | $found = false; |
ce7d5e87 | 90 | |
6322fc68 AD |
91 | foreach ($entries as $entry) { |
92 | if ($entry->hasAttribute("href")) { | |
299aeb30 | 93 | |
ec482d28 AD |
94 | _debug("processing href: " . $entry->getAttribute("href"), $debug); |
95 | ||
6322fc68 | 96 | $matches = array(); |
5d429910 | 97 | |
8788698b AD |
98 | if (preg_match("/^https?:\/\/twitter.com\/(.*?)\/status\/(.*)/", $entry->getAttribute("href"), $matches)) { |
99 | _debug("handling as twitter: " . $matches[1] . " " . $matches[2], $debug); | |
100 | ||
101 | $oembed_result = fetch_file_contents("https://publish.twitter.com/oembed?url=" . urlencode($entry->getAttribute("href"))); | |
102 | ||
103 | if ($oembed_result) { | |
104 | $oembed_result = json_decode($oembed_result, true); | |
105 | ||
106 | if ($oembed_result && isset($oembed_result["html"])) { | |
107 | ||
108 | $tmp = new DOMDocument(); | |
109 | if ($tmp->loadHTML($oembed_result["html"])) { | |
110 | $p = $doc->createElement("p"); | |
111 | ||
112 | $p->appendChild($doc->importNode( | |
113 | $tmp->getElementsByTagName("blockquote")->item(0), TRUE)); | |
114 | ||
115 | $br = $doc->createElement('br'); | |
116 | $entry->parentNode->insertBefore($p, $entry); | |
117 | $entry->parentNode->insertBefore($br, $entry); | |
118 | ||
119 | $found = 1; | |
120 | } | |
121 | } | |
122 | } | |
123 | } | |
124 | ||
43db5b99 | 125 | if (!$found && preg_match("/\.gfycat.com\/([a-z]+)?(\.[a-z]+)$/i", $entry->getAttribute("href"), $matches)) { |
5f297a5c AD |
126 | $entry->setAttribute("href", "http://www.gfycat.com/".$matches[1]); |
127 | } | |
128 | ||
43db5b99 | 129 | if (!$found && preg_match("/https?:\/\/(www\.)?gfycat.com\/([a-z]+)$/i", $entry->getAttribute("href"), $matches)) { |
5d429910 | 130 | |
ec482d28 AD |
131 | _debug("Handling as Gfycat", $debug); |
132 | ||
6322fc68 | 133 | $tmp = fetch_file_contents($entry->getAttribute("href")); |
5d429910 | 134 | |
6322fc68 AD |
135 | if ($tmp) { |
136 | $tmpdoc = new DOMDocument(); | |
5d429910 | 137 | |
58a44ecb | 138 | if (@$tmpdoc->loadHTML($tmp)) { |
6322fc68 | 139 | $tmpxpath = new DOMXPath($tmpdoc); |
b8887ebb | 140 | |
1f6732b2 | 141 | $source_meta = $tmpxpath->query("//meta[@name='twitter:player:stream' and contains(@content, '.mp4')]")->item(0); |
b8887ebb | 142 | $poster_meta = $tmpxpath->query("//meta[@property='og:image' and contains(@content,'thumbs.gfycat.com')]")->item(0); |
5d429910 | 143 | |
6322fc68 AD |
144 | if ($source_meta) { |
145 | $source_stream = $source_meta->getAttribute("content"); | |
b8887ebb | 146 | $poster_url = false; |
5d429910 | 147 | |
6322fc68 | 148 | if ($source_stream) { |
b8887ebb AD |
149 | |
150 | if ($poster_meta) | |
151 | $poster_url = $poster_meta->getAttribute("content"); | |
152 | ||
153 | $this->handle_as_video($doc, $entry, $source_stream, $poster_url); | |
6322fc68 | 154 | $found = 1; |
5d429910 | 155 | } |
5d429910 | 156 | } |
6322fc68 AD |
157 | } |
158 | } | |
5d429910 | 159 | |
6322fc68 | 160 | } |
98e20510 | 161 | |
5f297a5c | 162 | // imgur .gif -> .gifv |
43db5b99 | 163 | if (!$found && preg_match("/i\.imgur\.com\/(.*?)\.gif$/i", $entry->getAttribute("href"))) { |
ec482d28 AD |
164 | _debug("Handling as imgur gif (->gifv)", $debug); |
165 | ||
5f297a5c AD |
166 | $entry->setAttribute("href", |
167 | str_replace(".gif", ".gifv", $entry->getAttribute("href"))); | |
168 | } | |
169 | ||
43db5b99 | 170 | if (!$found && preg_match("/\.(gifv)$/i", $entry->getAttribute("href"))) { |
ec482d28 | 171 | _debug("Handling as imgur gifv", $debug); |
5d429910 | 172 | |
6322fc68 | 173 | $source_stream = str_replace(".gifv", ".mp4", $entry->getAttribute("href")); |
b8887ebb | 174 | |
49048482 | 175 | if (strpos($source_stream, "imgur.com") !== FALSE) |
b8887ebb AD |
176 | $poster_url = str_replace(".mp4", "h.jpg", $source_stream); |
177 | ||
ec482d28 | 178 | $this->handle_as_video($doc, $entry, $source_stream, $poster_url, $debug); |
98e20510 | 179 | |
6322fc68 AD |
180 | $found = true; |
181 | } | |
9875d717 | 182 | |
6322fc68 | 183 | $matches = array(); |
43db5b99 | 184 | if (!$found && preg_match("/youtube\.com\/v\/([\w-]+)/", $entry->getAttribute("href"), $matches) || |
0a361964 AD |
185 | preg_match("/youtube\.com\/.*?[\&\?]v=([\w-]+)/", $entry->getAttribute("href"), $matches) || |
186 | preg_match("/youtube\.com\/watch\?v=([\w-]+)/", $entry->getAttribute("href"), $matches) || | |
6322fc68 | 187 | preg_match("/\/\/youtu.be\/([\w-]+)/", $entry->getAttribute("href"), $matches)) { |
3b9ca4e6 | 188 | |
6322fc68 | 189 | $vid_id = $matches[1]; |
3b9ca4e6 | 190 | |
ec482d28 AD |
191 | _debug("Handling as youtube: $vid_id", $debug); |
192 | ||
6322fc68 AD |
193 | $iframe = $doc->createElement("iframe"); |
194 | $iframe->setAttribute("class", "youtube-player"); | |
195 | $iframe->setAttribute("type", "text/html"); | |
196 | $iframe->setAttribute("width", "640"); | |
197 | $iframe->setAttribute("height", "385"); | |
198 | $iframe->setAttribute("src", "https://www.youtube.com/embed/$vid_id"); | |
199 | $iframe->setAttribute("allowfullscreen", "1"); | |
200 | $iframe->setAttribute("frameborder", "0"); | |
3b9ca4e6 | 201 | |
6322fc68 AD |
202 | $br = $doc->createElement('br'); |
203 | $entry->parentNode->insertBefore($iframe, $entry); | |
204 | $entry->parentNode->insertBefore($br, $entry); | |
3b9ca4e6 | 205 | |
6322fc68 AD |
206 | $found = true; |
207 | } | |
3b9ca4e6 | 208 | |
43db5b99 | 209 | if (!$found && preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?$/i", $entry->getAttribute("href")) || |
90e45935 AD |
210 | mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE || |
211 | mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE) { | |
eb95d1bd | 212 | |
ec482d28 AD |
213 | _debug("Handling as a picture", $debug); |
214 | ||
6322fc68 AD |
215 | $img = $doc->createElement('img'); |
216 | $img->setAttribute("src", $entry->getAttribute("href")); | |
cc85704f | 217 | |
6322fc68 AD |
218 | $br = $doc->createElement('br'); |
219 | $entry->parentNode->insertBefore($img, $entry); | |
220 | $entry->parentNode->insertBefore($br, $entry); | |
ce7d5e87 | 221 | |
6322fc68 AD |
222 | $found = true; |
223 | } | |
ce7d5e87 | 224 | |
d4ac4fc6 | 225 | // linked albums & pages |
35055d05 | 226 | |
43db5b99 | 227 | if (!$found && preg_match("/^https?:\/\/(m\.)?imgur.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches) || |
8b2a52c6 | 228 | preg_match("/^https?:\/\/(m\.)?imgur.com\/(a|album|gallery)\/[^\.]+$/", $entry->getAttribute("href"), $matches)) { |
35055d05 | 229 | |
c80175bd | 230 | _debug("Handling as an imgur page/album/gallery", $debug); |
ec482d28 | 231 | |
6322fc68 AD |
232 | $album_content = fetch_file_contents($entry->getAttribute("href"), |
233 | false, false, false, false, 10); | |
35055d05 | 234 | |
6322fc68 AD |
235 | if ($album_content) { |
236 | $adoc = new DOMDocument(); | |
35055d05 | 237 | |
58a44ecb | 238 | if (@$adoc->loadHTML($album_content)) { |
6322fc68 | 239 | $axpath = new DOMXPath($adoc); |
ec482d28 | 240 | |
a6fde6c9 | 241 | $aentries = $axpath->query("(//div[@class='post-image']/img[@src] | //a[@class='zoom']/img[@src] | //div[@class='video-elements']/source)"); |
ec482d28 AD |
242 | $urls = []; |
243 | ||
244 | foreach ($aentries as $aentry) { | |
245 | ||
246 | $url = $aentry->getAttribute("src"); | |
247 | ||
248 | if (!in_array($url, $urls)) { | |
ec482d28 | 249 | |
a6fde6c9 | 250 | if ($aentry->tagName == "img") { |
ec482d28 | 251 | |
a6fde6c9 AD |
252 | $img = $doc->createElement('img'); |
253 | $img->setAttribute("src", $url); | |
254 | $entry->parentNode->insertBefore($doc->createElement('br'), $entry); | |
255 | ||
256 | $br = $doc->createElement('br'); | |
257 | ||
258 | $entry->parentNode->insertBefore($img, $entry); | |
259 | $entry->parentNode->insertBefore($br, $entry); | |
260 | } else if ($aentry->tagName == "source") { | |
261 | ||
49048482 | 262 | if (strpos($url, "imgur.com") !== FALSE) |
a6fde6c9 AD |
263 | $poster_url = str_replace(".mp4", "h.jpg", $url); |
264 | else | |
265 | $poster_url = ""; | |
266 | ||
267 | $this->handle_as_video($doc, $entry, $url, $poster_url); | |
268 | ||
269 | } | |
ec482d28 AD |
270 | |
271 | array_push($urls, $url); | |
272 | ||
273 | $found = true; | |
274 | } | |
275 | ||
35055d05 | 276 | } |
ec482d28 AD |
277 | |
278 | if ($debug) print_r($urls); | |
cc85704f | 279 | } |
cc85704f | 280 | } |
6322fc68 | 281 | } |
58a44ecb AD |
282 | |
283 | // wtf is this even | |
43db5b99 | 284 | if (!$found && preg_match("/^https?:\/\/gyazo\.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) { |
58a44ecb AD |
285 | $img_id = $matches[1]; |
286 | ||
ec482d28 AD |
287 | _debug("handling as gyazo: $img_id", $debug); |
288 | ||
58a44ecb AD |
289 | $img = $doc->createElement('img'); |
290 | $img->setAttribute("src", "https://i.gyazo.com/$img_id.jpg"); | |
291 | ||
292 | $br = $doc->createElement('br'); | |
293 | $entry->parentNode->insertBefore($img, $entry); | |
294 | $entry->parentNode->insertBefore($br, $entry); | |
295 | ||
296 | $found = true; | |
297 | } | |
6322fc68 AD |
298 | } |
299 | ||
300 | // remove tiny thumbnails | |
301 | if ($entry->hasAttribute("src")) { | |
302 | if ($entry->parentNode && $entry->parentNode->parentNode) { | |
303 | $entry->parentNode->parentNode->removeChild($entry->parentNode); | |
304 | } | |
305 | } | |
306 | } | |
cc85704f | 307 | |
6322fc68 AD |
308 | return $found; |
309 | } | |
b90c4468 | 310 | |
6322fc68 | 311 | function hook_article_filter($article) { |
b90c4468 | 312 | |
6322fc68 AD |
313 | if (strpos($article["link"], "reddit.com/r/") !== FALSE) { |
314 | $doc = new DOMDocument(); | |
315 | @$doc->loadHTML($article["content"]); | |
316 | $xpath = new DOMXPath($doc); | |
99bb8b3b | 317 | |
582ff3cf AD |
318 | $content_link = $xpath->query("(//a[contains(., '[link]')])")->item(0); |
319 | ||
891b77f9 | 320 | if ($this->host->get($this, "enable_content_dupcheck")) { |
902b1ac7 | 321 | |
891b77f9 AD |
322 | if ($content_link) { |
323 | $content_href = db_escape_string($content_link->getAttribute("href")); | |
324 | $entry_guid = db_escape_string($article["guid_hashed"]); | |
325 | $owner_uid = $article["owner_uid"]; | |
902b1ac7 | 326 | |
891b77f9 AD |
327 | if (DB_TYPE == "pgsql") { |
328 | $interval_qpart = "date_entered < NOW() - INTERVAL '1 day'"; | |
329 | } else { | |
330 | $interval_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY)"; | |
331 | } | |
902b1ac7 | 332 | |
891b77f9 AD |
333 | $result = db_query("SELECT COUNT(id) AS cid |
334 | FROM ttrss_entries, ttrss_user_entries WHERE | |
335 | ref_id = id AND | |
336 | $interval_qpart AND | |
337 | guid != '$entry_guid' AND | |
338 | owner_uid = '$owner_uid' AND | |
339 | content LIKE '%href=\"$content_href\">[link]%'"); | |
902b1ac7 | 340 | |
891b77f9 AD |
341 | if ($result) { |
342 | $num_found = db_fetch_result($result, 0, "cid"); | |
902b1ac7 | 343 | |
891b77f9 AD |
344 | if ($num_found > 0) $article["force_catchup"] = true; |
345 | } | |
902b1ac7 | 346 | } |
891b77f9 | 347 | } |
4f5204dd | 348 | |
4533b3ef | 349 | $found = $this->inline_stuff($article, $doc, $xpath); |
b90c4468 | 350 | |
aa03bac4 | 351 | if (!defined('NO_CURL') && function_exists("curl_init") && !$found && $this->host->get($this, "enable_readability") && |
6475fc7e AD |
352 | mb_strlen(strip_tags($article["content"])) <= 150) { |
353 | ||
8b08d9d7 | 354 | if (!class_exists("Readability")) require_once(dirname(dirname(__DIR__)). "/lib/readability/Readability.php"); |
b90c4468 | 355 | |
12d880d7 AD |
356 | if ($content_link && |
357 | strpos($content_link->getAttribute("href"), "twitter.com") === FALSE && | |
9ec9a8f9 | 358 | strpos($content_link->getAttribute("href"), "youtube.com") === FALSE && |
12d880d7 | 359 | strpos($content_link->getAttribute("href"), "reddit.com") === FALSE) { |
fd61fd6e | 360 | |
6475fc7e AD |
361 | /* link may lead to a huge video file or whatever, we need to check content type before trying to |
362 | parse it which p much requires curl */ | |
fd61fd6e | 363 | |
76ba1df7 AD |
364 | $useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"; |
365 | ||
90e45935 | 366 | $content_type = $this->get_content_type($content_link->getAttribute("href"), $useragent_compat); |
b90c4468 | 367 | |
6475fc7e | 368 | if ($content_type && strpos($content_type, "text/html") !== FALSE) { |
fd61fd6e | 369 | |
76ba1df7 AD |
370 | $tmp = fetch_file_contents(array("url" => $content_link->getAttribute("href"), |
371 | "useragent" => $useragent_compat)); | |
fd61fd6e | 372 | |
4d03c5c5 AD |
373 | //_debug("tmplen: " . mb_strlen($tmp)); |
374 | ||
76ba1df7 | 375 | if ($tmp && mb_strlen($tmp) < 1024 * 250) { |
4d03c5c5 | 376 | |
6475fc7e | 377 | $r = new Readability($tmp, $content_link->getAttribute("href")); |
fd61fd6e | 378 | |
6475fc7e | 379 | if ($r->init()) { |
b90c4468 | 380 | |
6475fc7e | 381 | $tmpxpath = new DOMXPath($r->dom); |
b90c4468 | 382 | |
6475fc7e | 383 | $entries = $tmpxpath->query('(//a[@href]|//img[@src])'); |
6322fc68 | 384 | |
6475fc7e AD |
385 | foreach ($entries as $entry) { |
386 | if ($entry->hasAttribute("href")) { | |
387 | $entry->setAttribute("href", | |
388 | rewrite_relative_url($content_link->getAttribute("href"), $entry->getAttribute("href"))); | |
389 | ||
390 | } | |
b90c4468 | 391 | |
6475fc7e AD |
392 | if ($entry->hasAttribute("src")) { |
393 | $entry->setAttribute("src", | |
394 | rewrite_relative_url($content_link->getAttribute("href"), $entry->getAttribute("src"))); | |
cc85704f | 395 | |
6475fc7e | 396 | } |
6322fc68 | 397 | |
6475fc7e AD |
398 | } |
399 | ||
400 | $article["content"] = $r->articleContent->innerHTML . "<hr/>" . $article["content"]; | |
401 | ||
47888b3d AD |
402 | // prob not a very good idea (breaks wikipedia pages, etc) - |
403 | // inliner currently is not really fit for any random web content | |
6475fc7e | 404 | |
47888b3d AD |
405 | //$doc = new DOMDocument(); |
406 | //@$doc->loadHTML($article["content"]); | |
407 | //$xpath = new DOMXPath($doc); | |
408 | //$found = $this->inline_stuff($article, $doc, $xpath); | |
6475fc7e | 409 | } |
6322fc68 | 410 | } |
a16d7a5d | 411 | } |
cc85704f | 412 | } |
6322fc68 AD |
413 | |
414 | } | |
415 | ||
416 | $node = $doc->getElementsByTagName('body')->item(0); | |
417 | ||
418 | if ($node && $found) { | |
419 | $article["content"] = $doc->saveXML($node); | |
420 | } | |
cc85704f AD |
421 | } |
422 | ||
423 | return $article; | |
424 | } | |
106a3de9 AD |
425 | |
426 | function api_version() { | |
427 | return 2; | |
428 | } | |
429 | ||
ec482d28 AD |
430 | private function handle_as_video($doc, $entry, $source_stream, $poster_url = false, $debug = false) { |
431 | ||
432 | _debug("handle_as_video: $source_stream", $debug); | |
5d429910 AD |
433 | |
434 | $video = $doc->createElement('video'); | |
435 | $video->setAttribute("autoplay", "1"); | |
5dcc7bf1 | 436 | $video->setAttribute("controls", "1"); |
5d429910 AD |
437 | $video->setAttribute("loop", "1"); |
438 | ||
b8887ebb AD |
439 | if ($poster_url) $video->setAttribute("poster", $poster_url); |
440 | ||
5d429910 AD |
441 | $source = $doc->createElement('source'); |
442 | $source->setAttribute("src", $source_stream); | |
443 | $source->setAttribute("type", "video/mp4"); | |
444 | ||
445 | $video->appendChild($source); | |
446 | ||
447 | $br = $doc->createElement('br'); | |
448 | $entry->parentNode->insertBefore($video, $entry); | |
449 | $entry->parentNode->insertBefore($br, $entry); | |
450 | ||
451 | $img = $doc->createElement('img'); | |
452 | $img->setAttribute("src", | |
453 | "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D"); | |
454 | ||
455 | $entry->parentNode->insertBefore($img, $entry); | |
456 | } | |
ec482d28 AD |
457 | |
458 | function testurl() { | |
459 | $url = htmlspecialchars($_REQUEST["url"]); | |
460 | ||
461 | header("Content-type: text/plain"); | |
462 | ||
463 | print "URL: $url\n"; | |
464 | ||
465 | $doc = new DOMDocument(); | |
466 | @$doc->loadHTML("<html><body><a href=\"$url\">[link]</a></body>"); | |
467 | $xpath = new DOMXPath($doc); | |
468 | ||
469 | print "Inline result: " . $this->inline_stuff([], $doc, $xpath, true) . "\n"; | |
470 | ||
471 | print "\nResulting HTML:\n"; | |
472 | ||
473 | print $doc->saveHTML(); | |
474 | ||
475 | } | |
90e45935 AD |
476 | |
477 | private function get_content_type($url, $useragent = SELF_USER_AGENT) { | |
478 | $content_type = false; | |
479 | ||
480 | if (function_exists("curl_init") && !defined("NO_CURL")) { | |
481 | $ch = curl_init($url); | |
482 | curl_setopt($ch, CURLOPT_TIMEOUT, 5); | |
483 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
484 | curl_setopt($ch, CURLOPT_HEADER, true); | |
485 | curl_setopt($ch, CURLOPT_NOBODY, true); | |
486 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir")); | |
487 | curl_setopt($ch, CURLOPT_USERAGENT, $useragent); | |
488 | ||
489 | @$result = curl_exec($ch); | |
490 | $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); | |
491 | } | |
492 | ||
493 | return $content_type; | |
494 | } | |
cc85704f AD |
495 | } |
496 | ?> |