Subversion Repositories cheapmusic

Rev

Rev 127 | Rev 130 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
error_reporting(E_ALL);

// BUGBUG {"message": "You are making requests too quickly."}
function findDiscogsMaster($stxt) {
    $vendors = Vendors::getInstance();
    $config = $vendors->getVendor(Vendors::DISCOGS);
    $maxMasterCount = $config['maxMasters'];

    $_SESSION["discogs"] = "";

// bugbug $url =  "https://api.discogs.com/artists/" . $stxt . "/releases?";
    $params = [];
    $params["token"] = $config['token'];
    if (empty($_SESSION["barcode"]["Type"])) {
        $params["type"] = "All";

        if (!empty($_SESSION["discogsTitle"]) || !empty($_SESSION["discogsArtist"])) {
            if (!empty($_SESSION["discogsTitle"])) {
                $params["release_title"] = $_SESSION["discogsTitle"];
            }

            if (!empty($_SESSION["discogsArtist"])) {
                $params["artist"] = $_SESSION["discogsArtist"];
            }
        }
        else {
            $params["query"] = ($stxt == "***RANDOM***" ? mt_rand($config['minRelease'], $config['maxRelease']) : $stxt);
        }
    }
    else {
        $params["barcode"] = $_SESSION["barcode"]["Value"];
    }

    $pairs = array();
    foreach ($params as $key => $value) {
        array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
    }
    $canonical_query_string = join("&", $pairs);

    $url = "https://api.discogs.com/database/search?" . $canonical_query_string;

    $searchResp = ($stxt == "***RANDOM***" ? false : getSearchCache("Discogs", $stxt, ""));
    if ($searchResp === false) {
        $searchResp = getUrl($url, $config['userAgent']);
        if ($stxt != "***RANDOM***") {
            saveSearchCache("Discogs", $stxt, "", $searchResp);
        }
    }
    $searchResp = utf8_encode($searchResp);
    $searchResp = json_decode($searchResp);

    if (empty($searchResp)) {
        return;
    }

    if (!empty($searchResp->{'message'})) {
        if ($searchResp->{'message'} == "You are making requests too quickly.") {
            my_error_log("Discogs: You are making requests too quickly.");
            return;
        }
        return;
    }

    if ($searchResp->{'pagination'}->{'items'} < 1) {
        if ($stxt == "***RANDOM***") { // must find something
            findDiscogsMaster("***RANDOM***", !empty($_SESSION['sessData']['userLoggedIn']));
        }

        return;
    }

    $xh = new Html;
    $xh->init($_SESSION["htmlIndent"]);

    $xh->add_attribute("class", "container-fluid bg-light");
    $xh->tag('div');
    $xh->add_attribute("class", "text-center py-2");
    $xh->tag('h2', ($stxt == "***RANDOM***" ? "Random" : "Matching") . " Albums");
    $xh->add_attribute("method", "post");
    $xh->add_attribute("action", "/index.php");
    $xh->tag('form');
    $xh->insert_code(inputSessionTab());
    $xh->insert_code(inputNonce());
    $xh->add_attribute("id", "discogsTitle");
    $xh->add_attribute("type", "hidden");
    $xh->add_attribute("name", "discogsTitle");
    $xh->add_attribute("value", "");
    $xh->single_tag('input');
    $xh->add_attribute("id", "discogsArtist");
    $xh->add_attribute("type", "hidden");
    $xh->add_attribute("name", "discogsArtist");
    $xh->add_attribute("value", "");
    $xh->single_tag('input');
    $xh->add_attribute("id", "discogsBarcode");
    $xh->add_attribute("type", "hidden");
    $xh->add_attribute("name", "discogsBarcode");
    $xh->add_attribute("value", "");
    $xh->single_tag('input');
    $xh->add_attribute("id", "discogsDeck");
    $xh->add_attribute("class", "card-deck");
    $xh->tag('div');

    $masterCount = 0;
    $processedMasters = [];
    $wlAddArr = [];
    $wlSearchArr = [];
    $searchUrls = [];
    $masterResps_cache = [];
    foreach ($searchResp->{'results'} as $searchey => $searchValue) {
// bugbug foreach ($searchResp->{'releases'} as $searchey => $searchValue) {
        if (!in_array($searchValue->{'type'}, array(
            "master",
            "release"
        )) && empty($_SESSION["barcode"]['Type'])) {
            continue;
        }

        if (empty($_SESSION["barcode"]['Type']) && $searchValue->{'type'} == "release" && $searchValue->{'master_id'} > 0) {
            continue;
        }

        if ($searchValue->{'master_id'} > 0 && in_array($searchValue->{'master_id'}, $processedMasters)) {
            continue;
        }
        $processedMasters[] = $searchValue->{'master_id'};

        if (++$masterCount > $maxMasterCount) {
            break;
        }

        $searchUrl = $searchValue->{'master_id'} != 0 ? $searchValue->{'master_url'} : $searchValue->{'resource_url'};
        
        $searchType[$searchUrl] = $searchValue->{'type'};
        $searchThumb[$searchUrl] = $searchValue->{'thumb'};
        $searchCoverImage[$searchUrl] = $searchValue->{'cover_image'};
        
        $masterResps_cache[$searchUrl] = getSearchCache("Discogs", $searchUrl, "");

        if ($masterResps_cache[$searchUrl] === false) {
            $searchUrls[] = $searchUrl;
            unset($masterResps_cache[$searchUrl]);
        }
    }

    $masterResps = [];
    if (count($searchUrls) > 0) {
        $masterResps = getMultiUrl($searchUrls, $config['userAgent']);
    }

    foreach($masterResps as $key => $html) {
        saveSearchCache("Discogs", $key, "", $html);
    }

    foreach($masterResps_cache as $key => $html) {
        $masterResps[$key] = $html;
    }
    unset($masterResps_cache);

    $masterCount = 0;
    foreach($masterResps as $key => $html) {
        $html = utf8_encode($html);
        $html = json_decode($html);

        if (!empty($html->{'message'})) {
            my_error_log("Discogs: " . $html->{'message'});
        } else if (!empty($html)) {
            $xh->insert_code(processMaster($html, $searchType[$key], $searchThumb[$key], $searchCoverImage[$key], ++$masterCount, $wlAddArr, $wlSearchArr));
        }
    }
    
    if ($masterCount == 0) {
        $xh->clear_buffer();
    } else {
        $xh->close(); // div
        $xh->close(); // form
        $xh->close(); // div
        
        $xh->add_attribute("nonce", "xxxNONCExxx");
        $xh->tag('script');
        $str = 'function addDiscogsEventsWait() {';
        $str .= 'document.addEventListener("DOMContentLoaded", function() {';
        $str .= 'addDiscogsEvents();';
        $str .= '});';
        $str .= '}';

        $str .= 'function addDiscogsEvents() {';
        foreach($wlAddArr as $k=>$v) {
            $str .= 'el = document.getElementById("' . $k . '");';
            $str .= 'if (el) document.getElementById("' . $k . '").addEventListener("click", function() {';
            $str .= $v;
            $str .= '});';
        }

        foreach($wlSearchArr as $k=>$v) {
            $str .= 'el = document.getElementById("' . $k . '");';
            $str .= 'if (el) document.getElementById("' . $k . '").addEventListener("click", function() {';
            $str .= $v;
            $str .= '});';
        }
        $str .= '}';
        $str .= 'addDiscogsEventsWait();';
        $xh->insert_code($str);
        $xh->close(); // script
        
        if ($stxt == "***RANDOM***") {
            $xh->add_attribute("class", "container-fluid text-center");
            $xh->tag('div');
              $xh->add_attribute("method", "post");
              $xh->add_attribute("action", "/index.php");
              $xh->tag('form');
                $xh->insert_code(inputSessionTab());
                $xh->insert_code(inputSearchTerm());
                $xh->insert_code(inputNonce());
                $xh->add_attribute("id", "randomBtn");
                $xh->add_attribute("type", "submit");
                $xh->add_attribute("class", "btn btn-success m-2 rounded");
                $xh->add_attribute("name", "submit");
                $xh->add_attribute("value", "random");
                $xh->tag('button', "More Random Album Suggestions");
              $xh->close(); // form
            $xh->close(); // div
        }
    }

    $_SESSION["discogs"] = $xh->flush();
    //error_log(print_r($_SESSION["discogs"], 1));

    return;
}

function processMaster($master, $type, $thumbnail, $coverImage, $cnt, &$wlAddArr, &$wlSearchArr) {
    $xh = new Html;
    $xh->init($_SESSION["htmlIndent"]);
    $xhmod = new Html;
    $xhmod->init($_SESSION["htmlIndent"]);

    $artists = [];
    foreach ($master->{'artists'} as $key => $value) {
        $artists[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$value->{'name'}));
    }

    $genres = [];
    foreach ($master->{'genres'} as $key => $value) {
        $genres[] = (string)$value;
    }

    $labels = [];
    if (isset($master->{'labels'})) {
        foreach ($master->{'labels'} as $key => $value) {
            $labels[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$value->{'name'}));
        }
    }

    $formats = [];
    if (isset($master->{'formats'})) {
        foreach ($master->{'formats'} as $key => $value) {
            $formats[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$value->{'name'}));
        }
    }

    $country = '';
    if (isset($master->{'country'})) {
        $country = (string)$master->{'country'};
    }

    $xh->add_attribute("class", "card mx-auto discogs-card");
    $xh->tag('div');

    $xh->add_attribute("class", "card-header bg-secondary d-flex");
    $xh->tag('div');
    $searchArtists = "";
    if (count($artists) < 5) {
        $wlArtists = join(", ", $artists);
        if ($artists[0] != 'Various') {
            $searchArtists = join(" ", $artists);
        }
    }
    else {
        $wlArtists = "Various Artists";
    }
    $xh->add_attribute("class", "card-title font-weight-bold small flex-grow-1");
    $xh->tag('p', htmlentities((string)$master->{'title'}) . " by " . htmlentities($wlArtists));
    $xh->close(); // div
    
    if (empty($thumbnail) || preg_match("/spacer.gif$/", $thumbnail)) {
        $thumbnail = "images/no-image-available.jpg";
    }
    $xh->add_attribute("class", "card-body d-flex justify-content-center align-items-center p-1 m-0");
    $xh->tag('div');
    $xh->add_attribute("class", "btn p-0 m-0 lazyload");
    $xh->add_attribute("src",PIXEL);
    $xh->add_attribute("data-src", $thumbnail);
    $xh->add_attribute("data-toggle", "modal");
    $xh->add_attribute("data-target", "#masterModal" . $cnt);
    $xh->add_attribute("title", "Album Information");
    $xh->add_attribute("data-toggle2", "tooltip");
    $xh->add_attribute("alt", "Discogs Cover Thumbnail");
    $xh->single_tag('img');
    $xh->close(); // div
    $xh->add_attribute("class", "card-footer bg-secondary p-0 m-0");
    $xh->tag('div');
    $xh->add_attribute("class", "container clearfix p-0 m-0");
    $xh->tag('div');
    $xh->add_attribute("class", "float-left btn-group-sm");
    $xh->tag('span');
    $xh->add_attribute("type", "button");
    $xh->add_attribute("class", "btn btn-info btn-sm");
    $xh->add_attribute("data-toggle", "modal");
    $xh->add_attribute("data-target", "#masterModal" . $cnt);
    $xh->add_attribute("title", "Album Information");
    $xh->add_attribute("aria-label", "Album Information");
    $xh->add_attribute("data-toggle2", "tooltip");
    $xh->tag('button');
    $xh->add_attribute("class", "material-icons");
    $xh->tag('i', "info_outline");
    $xh->close(); // button

    if (isset($master->{'videos'})) {
        $xh->tag('span', " ");
        $xh->add_attribute("type", "button");
        $xh->add_attribute("class", "btn btn-info btn-sm");
        $xh->add_attribute("data-toggle", "modal");
        $xh->add_attribute("data-target", "#videoModal" . $cnt);
        $xh->add_attribute("title", "Videos");
        $xh->add_attribute("aria-label", "Music videos");
        $xh->add_attribute("data-toggle2", "tooltip");
        $xh->tag('button');
        $xh->add_attribute("class", "material-icons");
        $xh->tag('i', "videocam");
        $xh->close(); // button

        $xhmod->add_attribute("id", "videoModal" . $cnt);
        $xhmod->add_attribute("class", "modal");
        $xhmod->tag('div');
        $xhmod->add_attribute("class", "modal-dialog");
        $xhmod->tag('div');
        $xhmod->add_attribute("class", "modal-content");
        $xhmod->tag('div');
        $xhmod->add_attribute("class", "modal-header bg-secondary");
        $xhmod->tag('div');
        if (count($artists) < 5) {
            $str = htmlentities(join(", ", $artists));
        }
        else {
            $str = "Various Artists";
        }
        $xhmod->add_attribute("class", "modal-title mx-auto display-6");
        $xhmod->tag('p', htmlentities((string)$master->{'title'}) . " by " . $str);

        $xhmod->add_attribute("type", "button");
        $xhmod->add_attribute("class", "close");
        $xhmod->add_attribute("data-dismiss", "modal");
        $xhmod->tag('button');
        $xhmod->add_attribute("class", "material-icons btn-dismiss");
        $xhmod->tag('i', "cancel_presentation");
        $xhmod->close(); // button
        $xhmod->close(); // div

        $xhmod->add_attribute("class", "modal-body mx-auto");
        $xhmod->tag('div');
        $xhmod->add_attribute("class", "display-6");
        $xhmod->tag('p', "Videos");
        $xhmod->add_attribute("class", "list-group");
        $xhmod->tag('ul');

        foreach ($master->{'videos'} as $video) {
            $xhmod->add_attribute("class", "list-group-item");
            $xhmod->tag('li');
            $xhmod->add_attribute("class", "row");
            $xhmod->tag('div');
            $xhmod->add_attribute("class", "col-1");
            $xhmod->tag('div');
            $xhmod->add_attribute("class", "svg-yt");
            $xhmod->add_attribute("viewBox", "0 0 24 24");
            $xhmod->tag('svg');
            $xhmod->add_attribute("fill", "currentColor");
            $xhmod->add_attribute("d", "M10,15L15.19,12L10,9V15M21.56,7.17C21.69,7.64 21.78,8.27 21.84,9.07C21.91,9.87 21.94,10.56 21.94,11.16L22,12C22,14.19 21.84,15.8 21.56,16.83C21.31,17.73 20.73,18.31 19.83,18.56C19.36,18.69 18.5,18.78 17.18,18.84C15.88,18.91 14.69,18.94 13.59,18.94L12,19C7.81,19 5.2,18.84 4.17,18.56C3.27,18.31 2.69,17.73 2.44,16.83C2.31,16.36 2.22,15.73 2.16,14.93C2.09,14.13 2.06,13.44 2.06,12.84L2,12C2,9.81 2.16,8.2 2.44,7.17C2.69,6.27 3.27,5.69 4.17,5.44C4.64,5.31 5.5,5.22 6.82,5.16C8.12,5.09 9.31,5.06 10.41,5.06L12,5C16.19,5 18.8,5.16 19.83,5.44C20.73,5.69 21.31,6.27 21.56,7.17Z");
            $xhmod->single_tag('path');
            $xhmod->close(); // svg
            $xhmod->close(); // div
            $xhmod->add_attribute("class", "col");
            $xhmod->tag('div');
            $xhmod->add_attribute("href", $video->uri);
            $xhmod->add_attribute("target", "_blank");
            $xhmod->add_attribute("rel", "noreferrer noopener");
            $xhmod->add_attribute("class", "btn btn-light btn-link text-left");
            $xhmod->add_attribute("role", "button");
            $xhmod->tag('a', htmlentities($video->title) . " [" . gmdate('H:i:s', $video->duration) . "]");
            $xhmod->close(); // div
            $xhmod->close(); // div
            $xhmod->close(); // li
            // bugbug too many videos don't run embedded
            // $videoParam = basename($video->uri);
            // $videoIdx = strpos($videoParam, "=") + 1;
            // $str .= "<iframe width=\"280\" height=\"158\" src=\"https://www.youtube-nocookie.com/embed/" . substr($videoParam, $videoIdx) . "?rel=0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>";
            
        }

        $xhmod->close(); // ul
        $xhmod->close(); // div
        $xhmod->add_attribute("class", "modal-footer bg-secondary justify-content-between");
        $xhmod->tag('div');
        $xhmod->add_attribute("class", "font-weight-lighter small");
        $xhmod->tag('span');
        $xhmod->tag('span', "Data provided by ");

        $xhmod->add_attribute("href", (string)$master->{'uri'});
        $xhmod->add_attribute("target", "_blank");
        $xhmod->add_attribute("rel", "noreferrer noopener");
        $xhmod->tag('a', "Discogs");
        $xhmod->close(); // span

        $xhmod->add_attribute("class", "float-right");
        $xhmod->tag('span');
        $xhmod->add_attribute("type", "button");
        $xhmod->add_attribute("class", "btn btn-danger");
        $xhmod->add_attribute("data-dismiss", "modal");
        $xhmod->tag('button', "Close");
        $xhmod->close(); // span
        $xhmod->close(); // div
        $xhmod->close(); // div
        $xhmod->close(); // div
        $xhmod->close(); // div
    }

    $xh->close(); // span

    $xh->add_attribute("class", "float-right btn-group-sm");
    $xh->tag('span');

    $barcode = "";
    if (empty($_SESSION["barcode"]['Type']) && !empty($master->{'identifiers'})) {
        foreach ($master->{'identifiers'} as $identifier) {
            if ($identifier->{'type'} == 'Barcode') {
                $tmpBarcode = preg_replace("/[^0-9]/", "", $identifier->{'value'});
                $barcodeType = clsLibGTIN::GTINCheck($tmpBarcode, false, 1);
                if (!empty($barcodeType)) {
                    $barcode = $tmpBarcode;
                }
            }
        }
    }
    else if (!empty($_SESSION["barcode"]['Type'])) {
        $barcode = $_SESSION["barcode"]['Value'];
    }

    if (isLoggedIn() && !checkWishlist($type, $master->{'id'})) {
        $wlArr = array(
            ($type == "master" ? 'mid' : 'rid') => $master->{'id'},
            'title' => (string)$master->{'title'},
            'artist' => $wlArtists,
            'barcode' => $barcode,
            'thumbnail' => $thumbnail,
            'url' => (string)$master->{'uri'}
        );
        $wl = base64_encode(json_encode($wlArr));

        $xh->add_attribute("id", "wl" . $cnt . "Btn");
        $xh->add_attribute("type", "button");
        $xh->add_attribute("class", "btn btn-info btn-sm");
        $xh->add_attribute("title", "Add to Wishlist");
        $xh->add_attribute("aria-label", "Add to Wishlist");
        $xh->add_attribute("data-toggle", "tooltip");
        $xh->tag('button');
        $xh->add_attribute("class", "material-icons");
        $xh->tag('i', "bookmark");
        $xh->close(); // button

        $wlAddArr["wl" . $cnt . "Btn"] = 'addWishlist("' . $_SESSION['sessData']['userID'] . '", this,' . $cnt . ',"' . $wl . '");';
    }

    $searchTitle = 'Searching for:<br><br><strong>' . htmlentities((string)$master->{'title'}) . ' by ' . (empty($searchArtists) ? 'Various Artists' : htmlentities($searchArtists)) . '</strong>';
    if (!empty($barcode)) {
        $searchTitle .= " (" . displayBarcode($barcode) . ")";
    }

    $xh->tag('span', " ");
    $xh->add_attribute("id", "discogsSearch" . $cnt . "Btn");
    $xh->add_attribute("type", "submit");
    $xh->add_attribute("name", "submit");
    $xh->add_attribute("value", "discogsSearch");
    $xh->add_attribute("class", "btn btn-success btn-sm");
    $xh->add_attribute("title", "Search for Store Offers");
    $xh->add_attribute("aria-label", "Search for Store Offers");
    $xh->add_attribute("data-toggle", "tooltip");
    $xh->tag('button');
    $xh->add_attribute("class", "material-icons");
    $xh->tag('i', "search");
    $xh->close(); // button
    $xh->close(); // span
    $xh->close(); // div
 
    $wlSearchArr["discogsSearch" . $cnt . "Btn"] = 'document.getElementById("discogsTitle").value = "' . addslashes((string)$master->{"title"}) . '";' .
                                                   'document.getElementById("discogsArtist").value = "' . addslashes($searchArtists) . '";' .
                                                   'document.getElementById("discogsBarcode").value = "' . $barcode . '";' .
                                                   'progressBar("' . $searchTitle . '");';

    $xh->add_attribute("id", "wishlistAdd" . $cnt);
    $xh->tag('span', "");
    $xh->close(); // div

    $xhmod->add_attribute("id", "masterModal" . $cnt);
    $xhmod->add_attribute("class", "modal");
    $xhmod->tag('div');
    $xhmod->add_attribute("class", "modal-dialog");
    $xhmod->tag('div');
    $xhmod->add_attribute("class", "modal-content");
    $xhmod->tag('div');
    $xhmod->add_attribute("class", "modal-header bg-secondary");
    $xhmod->tag('div');
    if (count($artists) < 5) {
        $str = htmlentities(join(", ", $artists));
    }
    else {
        $str = "Various Artists";
    }
    $xhmod->add_attribute("class", "modal-title mx-auto display-6");
    $xhmod->tag('p', htmlentities((string)$master->{'title'}) . " by " . $str);
    $xhmod->add_attribute("type", "button");
    $xhmod->add_attribute("class", "close");
    $xhmod->add_attribute("data-dismiss", "modal");
    $xhmod->tag('button');
    $xhmod->add_attribute("class", "material-icons btn-dismiss");
    $xhmod->tag('i', "cancel_presentation");
    $xhmod->close(); // button
    $xhmod->close(); // div

    $xhmod->add_attribute("class", "modal-body mx-auto");
    $xhmod->tag('div');

    if (!empty($coverImage) && !preg_match("/spacer.gif$/", $coverImage)) {
        $xhmod->add_attribute("class", "responsive-image mx-auto mb-4 lazyload");
        $xhmod->add_attribute("src", $coverImage);
        $xhmod->add_attribute("alt", "Discogs Cover");
        $xhmod->single_tag('img');
    }

    $xhmod->add_attribute("class", "table-borderless table-condensed small mx-auto");
    $xhmod->tag('table');

    $xhmod->tag('tr');
    $xhmod->add_attribute("class", "px-1");
    $xhmod->tag('td', "Title:");
    $xhmod->add_attribute("class", "px-1");
    $xhmod->tag('td', htmlentities((string)$master->{'title'}));
    $xhmod->close(); // tr

    $xhmod->tag('tr');
    $xhmod->add_attribute("class", "px-1");
    $xhmod->tag('td', "Artist:");
    $xhmod->add_attribute("class", "px-1");
    $xhmod->tag('td', htmlentities(join(", ", $artists)));
    $xhmod->close(); // tr

    if (!empty($barcode)) {
        $xhmod->tag('tr');
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', "Barcode:");
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', displayBarcode($barcode));
        $xhmod->close(); // tr
    }

    if (!empty($labels)) {
        $xhmod->tag('tr');
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', "Label:");
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', htmlentities($labels[0]));
        $xhmod->close(); // tr
    }

    if (!empty($formats)) {
        $xhmod->tag('tr');
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', "Format:");
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', htmlentities(join(", ", $formats)));
        $xhmod->close(); // tr
    }

    if (!empty($country)) {
        $xhmod->tag('tr');
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', "Country:");
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', htmlentities($country));
        $xhmod->close(); // tr
    }

    if ($master->{'year'} > 0) {
        $xhmod->tag('tr');
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', "Year:");
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', htmlentities((string)$master->{'year'}));
        $xhmod->close(); // tr
    }

    $xhmod->tag('tr');
    $xhmod->add_attribute("class", "px-1");
    $xhmod->tag('td', "Genre:");
    $xhmod->add_attribute("class", "px-1");
    $xhmod->tag('td', htmlentities(join(", ", $genres)));
    $xhmod->close(); // tr

    if (isset($master->{'styles'})) {
        $styles = [];
        foreach ($master->{'styles'} as $key => $value) {
            $styles[] = $value;
        }
        $xhmod->tag('tr');
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', "Style:");
        $xhmod->add_attribute("class", "px-1");
        $xhmod->tag('td', htmlentities(join(", ", $styles)));
        $xhmod->close(); // tr
    }

    if (is_array($master->{'tracklist'})) {
        $xhmod->tag('tr');
        $xhmod->add_attribute("class", "px-1");
        $xhmod->add_attribute("colspan", "2");
        $xhmod->tag('td', "Tracks:");
        $xhmod->close(); // tr

        $xhmod->tag('tr');
        $xhmod->add_attribute("class", "px-1");
        $xhmod->add_attribute("colspan", "2");
        $xhmod->tag('td');
        $xhmod->add_attribute("class", "pl-3 pt-0 small list-unstyled");
        $xhmod->tag('ul');
        foreach ($master->{'tracklist'} as $key => $value) {
            if ((string)$value->{'type_'} == "heading") {
                $xhmod->add_attribute("class", "font-weight-bold");
                $xhmod->tag('li', htmlentities((string)$value->{'title'}));
            }
            else if ((string)$value->{'type_'} == "index") {
                $xhmod->add_attribute("class", "font-italic");
                $xhmod->tag('li');
                $xhmod->add_attribute("class", "font-italic");
                $xhmod->tag('span', htmlentities((string)$value->{'title'}));
                foreach ($value->{'sub_tracks'} as $subkey => $subvalue) {
                    $xhmod->add_attribute("class", "pl-3 pt-0 list-unstyled");
                    $xhmod->tag('ul');
                    $xhmod->insert_code(processTrack($subvalue, false));
                    $xhmod->close(); // ul
                }
                $xhmod->close(); // li
            }
            else if ((string)$value->{'type_'} == "track") {
                $xhmod->insert_code(processTrack($value, true));
            }
        }
        $xhmod->close(); // ul
        $xhmod->close(); // td
        $xhmod->close(); // tr
    }

    $xhmod->close(); // table
    $xhmod->close(); // div
    $xhmod->add_attribute("class", "modal-footer bg-secondary justify-content-between");
    $xhmod->tag('div');
    $xhmod->tag('span');
    $xhmod->tag('span', "Data provided by ");
    $xhmod->add_attribute("href", (string)$master->{'uri'});
    $xhmod->add_attribute("target", "_blank");
    $xhmod->add_attribute("rel", "noreferrer noopener");
    $xhmod->tag('a', "Discogs");
    $xhmod->close(); // span
    $xhmod->add_attribute("class", "float-right");
    $xhmod->tag('span');
    $xhmod->add_attribute("type", "button");
    $xhmod->add_attribute("class", "btn btn-danger");
    $xhmod->add_attribute("data-dismiss", "modal");
    $xhmod->tag('button', "Close");
    $xhmod->close(); // span
    $xhmod->close(); // div
    $xhmod->close(); // div
    $xhmod->close(); // div
    $xhmod->close(); // div

    $html = $xhmod->flush();
    //error_log(print_r($html, 1));

    $xh->insert_code($html);
    $xh->close(); // div

    $html = $xh->flush();
    //error_log(print_r($html, 1));

    return $html;
}

function processTrack($value, $posFlag) {
    $xh = new Html;
    $xh->init($_SESSION["htmlIndent"]);

    $str = "";

    if ($posFlag && !empty($value->{'position'})) {
        if (!preg_match("/^[a-zA-Z][0-9]/", (string)$value->{'position'}) && !preg_match("/^[a-zA-Z]$/", (string)$value->{'position'})) {
            $str .= (string)$value->{'position'} . '. ';
        }
    }

    $str .= (string)$value->{'title'};

    $trackArtists = [];
    if (isset($value->{'artists'})) {
        foreach ($value->{'artists'} as $taKey => $taValue) {
            $trackArtists[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$taValue->{'name'}));
        }
        if (count($trackArtists)) {
            $str .= " - " . join(", ", $trackArtists);
        }
    }

    if (!empty($value->{'duration'})) {
        $str .= " [" . (string)$value->{'duration'} . "]";
    }

    $xh->tag('li', $str);

    $html = $xh->flush();
    //error_log(print_r($html, 1));

    return $html;
}