<?php
function gen_navigation($links, $currentId)
{
    $articleIds = [1, 2, 3, 4];
    $selectValue = in_array($currentId, $articleIds) ? 5 : $currentId;
    $result = "<nav><div class=\"container\">";
    foreach ($links as $value) {
        $linkName = explode(" ", $value["title"])[0];
        $result .= "<a";
        $result .= $selectValue == $value["id"] ? " class=\"selected\"" : "";
        $result .= " href=\"?id={$value["id"]}\">$linkName</a>";
    }
    $result .= "</div></nav>";
    return $result;
}

function gen_articlelist($links, $currentId)
{
    $result = "<aside><div class=\"container\"><a";
    $result .= $currentId == 5 ? " class=\"selected\"" : "";
    $result .= " href=\"?id=5\">Articles</a>";
    foreach ($links as $value) {
        $linkName = explode(" ", $value["title"])[0];
        $result .= "<a";
        $result .= $currentId == $value["id"] ? " class=\"selected\"" : "";
        $result .= " href=\"?id={$value["id"]}\">$linkName</a>";
    }
    $result .= "</div></aside>";
    return $result;
}

function display_all($objects)
{
    $result = "";
    foreach ($objects as $object) {
        $ipatharr = explode("/", $object["image"]);
        $img = $ipatharr[count($ipatharr) - 1];
        $result .= "<div class=\"o-li\">";
        $result .= "<div class=\"o-li-i\">";
        $result .= "<a href=\"?id=6&amp;object={$object["id"]}\">"; # 6 should be $currentId
        $result .= "<img src=\"img/250x250/$img\" alt=\"{$object["title"]}\">";
        $result .= "</a>";
        $result .= "</div>";
        $result .= "<div>";
        $result .= "<h3>{$object["title"]}</h3>";
        $result .= "<p>{$object["text"]}</p>";
        $result .= "<i>Category: {$object["category"]}<br>Owner: {$object["owner"]}</i>";
        $result .= "</div>";
        $result .= "</div>";
    }
    return $result;
}

function display_object($object)
{
    $ipatharr = explode("/", $object["image"]);
    $img = $ipatharr[count($ipatharr) - 1];

    $result = "<img src=\"img/full-size/$img\" alt=\"{$object["title"]}\">";
    $result .= "<h3>{$object["title"]}</h3>";
    $result .= "<p>{$object["text"]}</p>";
    $result .= "<i>Category: {$object["category"]}<br>Owner: {$object["owner"]}</i>";
    return $result;
}
