<?php
$UserInfo = $db->where('user_name', $output[1])->getOne('users');
if (!$UserInfo) {
    if (ERROR_PAGE == true) {
        require __DIR__ . '/ErrorPage.php';
    } else {
        Redirect(APP_URL);
    }
    exit;
}
$files_2 = '';

$db->join(TABLE_CAT . ' c', 'f.cid=c.id', "INNER");

if ($isLogged) {
    $db->where('(f.approved_at IS NOT NULL OR f.user_id="' . $AuthUser['id'] . '")');
} else {
    $db->where('f.approved_at', NULL, 'IS NOT');
}

$files_1 = $db->where('f.deleted_at',NULL,'IS')->where('f.status', 1)->where('user_id', $UserInfo['id'])->orderBy('f.id')->get(TABLE_FILES . ' f', FILES_PER_PAGE, 'f.id,f.dname,f.id,f.ext,f.thumb,f.duration,f.name,f.slug,f.created_at,f.download,c.folder');


if ($isLogged && $UserInfo['id'] == $AuthUser['id']) : // My Favourite Songs
    $db->join(TABLE_CAT . ' c', 'f.cid=c.id', "INNER");
    $db->join('favourite fav', 'f.id=fav.file_id', "INNER");
    
    if ($isLogged) {
        $db->where('(f.approved_at IS NOT NULL OR f.user_id="' . $AuthUser['id'] . '")');
    } else {
        $db->where('f.approved_at', NULL, 'IS NOT');
    }
    
    $files_2 = $db->where('fav.user_id', $AuthUser['id'])->where('f.deleted_at',NULL,'IS')->where('f.status', 1)->orderBy('fav.id')->get(TABLE_FILES . ' f', FILES_PER_PAGE, 'f.*,c.name as category_name,c.thumb as category_thumb,c.folder');
endif;


$usrImgPath = $RootPath . '/upload_file/userthumb/150x150/' . $UserInfo['user_name'] . '.jpg';

if (file_exists($usrImgPath)) {
    $usrImg = APP_URL . '/upload_file/userthumb/150x150/' . $UserInfo['user_name'] . '.jpg';
} else {
    $usrImg = APP_URL . '/assets/images/user.svg';
}

$breadhtml = '<nav aria-label="breadcrumb"><ol class="breadcrumb mt-2"><li class="breadcrumb-item"><a href="' . APP_URL . '"><i class="fa fa-home" aria-hidden="true"></i> Home</a></li>';
$breadcrumb[] =  [
    "@type" => "ListItem",
    "position" => 2,
    "item" => [
        "@id" => APP_URL . '/user/' . $output[1] . $endRoute,
        "name" => $UserInfo['name']
    ]
];
$breadhtml .= '<li class="breadcrumb-item"><a href="' . APP_URL . '/user/' . $output[1] . $endRoute . '">' . $UserInfo['name'] . '</a></li>';
$breadhtml .= '</ol></nav>';
$schema = [
    "@context" => "https://schema.org",
    "@type" => "BreadcrumbList",
    "itemListElement" => $breadcrumb
];

$title = str_replace(array('{{USER_NAME}}'), array($UserInfo['name']), $lang['USER_TITLE']) . ' - ' . APP_NAME;
$metadescription = str_replace(array('{{USER_NAME}}'), array($UserInfo['name']), $lang['USER_META_DESCRIPTION']);
$metakeywords = str_replace(array('{{USER_NAME}}'), array($UserInfo['name']), $lang['USER_META_KEYWORDS']);


require_once $Template . '/header.php';
require_once $Template . '/Profile.php';
require_once $Template . '/footer.php';
