about summary refs log tree commit diff stats
path: root/superstack.php
blob: 8eccd56a5f9d79fb7bd705283bad9f6a897d7e42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
$site = urldecode($_GET['page']);
$ch = curl_init($site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);
if (curl_error($ch)) {
    echo curl_error($ch);
}
$doc = new DOMDocument();
$doc->loadHTML($page);
$title = $doc->getElementsByTagName('title')[0]->textContent;
?>
    <!DOCTYPE html>
        <html>
        <head><title><?php echo $title ?> -- Superstack</title>
       <style>
       body{max-width:42em;padding:1em;margin:auto;font:18px/1.4 sans-serif;}
img{max-width:100%;}
</style>
    <body>

<?php

    echo '<h1>' . $title . '</h1>';
echo '<p><em>' . $site . '</em>';
echo ' <a href="' . $site . '">[orig]</a></p>';

$content = $doc->getElementsBytagName('div');

foreach ($content as $el) {
    if (stripos($el->getAttribute('class'), 'body') !== false) {

        $ret = new DOMDocument();
        $node = $ret->importNode($el, true);
        $ret->appendChild($node);
        echo $ret->saveHTML();

        // echo $el->nodeValue;
        // echo '<tr>';
        // echo '<td>' . $el->getAttribute('class') . '</td>';
        // echo '<td>' . stripos($el->getAttribute('class'), 'body') . '</td>';
        // echo '</tr>';
    }
}

?>

    </body>
        </html>