<?php
include "internal/header.php";
include "internal/footer.php";
include "internal/mysql.php";

if (strpos($_SERVER['HTTP_HOST'], '.onion') !== false) {
    $heIMG = "/internal/getImage.php?imgID=1";
    $abuseIPIMG = "/internal/getImage.php?imgID=2";
} else {
    $abuseIPIMG = "https://www.abuseipdb.com/contributor/45130.svg";
    $heIMG = "https://ipv6.he.net/certification/create_badge.php?pass_name=jonasled&badge=3";
}

getHeader("Jonas Leder", "home");
?>
    <div class="center">
        <img id="homeImage" src="img/bildHome.webp" data-noPreview="true">
        <h2>&Uuml;ber mich</h2>
        <p class="left block">Hallo, mein Name ist Jonas Leder. Ich bin aktuell Student an der Dualen Hochschule Baden-Württemberg in Mannheim Fachrichtung Angewandte Informatik.</p>
        <p><a href="about.php"><button>Mehr</button></a></p>
        <div class="spacer"></div>

        <h2>Blog</h2>
        <div id="blog">
            <?php
            $result = $conn->query("SELECT * FROM posts order by id desc limit $homeMaxPost");
            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    $title = $row["title"];
                    $id = $row["id"];
                    $content = explode(" ", $row["content"]);
                    $contentNew = "";
                    if(count($content) > 800){
                        $temp = str_split($content, 800);
                        $contentNew = $temp[0];
                        $contentNew = $content . explode(" ", $temp[1])[0] . " ...";
                    } else {
                        $contentNew = $row["content"];
                    }
                    echo(<<<EOF
            <article class="breakWord">
                <h2>$title</h2>
                <p breakWord>$contentNew</p>
                <p class="center"><a href="/post.php?id=$id"><button>Mehr lesen</button></a></p>
            </article>
            EOF);
                }
            }
            ?>
        </div>
        <div id="banner">
        <h2>Banner</h2>
        <a target="_blank" href="https://ipv6.he.net"><img src="<?php echo($heIMG); ?>" data-noPreview="true"></a>
        <a target="_blank" href="https://www.abuseipdb.com/user/45130"><img style="width: 391px;background: #35c246 linear-gradient(rgba(255,255,255,0), rgba(255,255,255,.3) 50%, rgba(0,0,0,.2) 51%, rgba(0,0,0,0));padding: 5px;" src="<?php echo($abuseIPIMG); ?>" style="width: 401px;" data-noPreview="true"></a>
        </div>
        <br>
        <br>
        <?php
        if (strpos($_SERVER['HTTP_HOST'], '.onion') == false) {
            echo('<p class="breakWord">Diese Website ist auch als hidden Service unter folgendem URL zu erreichen: <a href="http://jonasledtmdcrenuxuobwqn3n6onq3smssicbeyocolgx4sk75xwmxqd.onion">jonasledtmdcrenuxuobwqn3n6onq3smssicbeyocolgx4sk75xwmxqd.onion</a></p>');
        }
        ?>
    </div>
<?php
getFooter();