123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- require_once __DIR__ . '/../include/utils.php';
- require_once __DIR__ . '/../include/artworks_grid.php';
- require_once __DIR__ . '/../include/paginator.php';
- require_once __DIR__ . '/../include/truncated_text.php';
- if (!isset($_GET['id']) || !ctype_digit($_GET['id'])) {
- die_with_message(400, get_string('illegal-id'));
- }
- $id = $_GET['id'];
- list($info, $error) = get_user_info($id);
- if ($error) {
- die_with_message(500, get_string($error));
- }
- $info = $info->body;
- $categories = ['artworks', 'illustrations', 'manga', 'bookmarks'];
- if (!isset($_GET['category']) || !in_array($_GET['category'], $categories)) {
- $_GET['category'] = 'artworks';
- }
- $category = $_GET['category'];
- $pathname = BASE_URL . "/users/$id";
- render_page_header($info->name);
- ?>
- <div class="container">
- <h1 class="img-with-text">
- <img loading="lazy" class="avatar" src="<?= get_proxy_url($info->imageBig) ?>" alt=" ">
- <span><?= htmlspecialchars($info->name) ?></span>
- </h1>
- <div class="description">
- <?= render_truncated_text(str_replace(PHP_EOL, "<br />", htmlspecialchars($info->comment))) ?>
- </div>
- <div class="category-selector"><?php
- foreach ($categories as $c) { ?>
- <a href="<?= "$pathname/$c" ?>" class="<?php if ($c == $category) echo 'selected'; ?>">
- <?= get_string('user.' . $c) ?>
- </a><?php
- } ?>
- </div>
- <?php
- switch (true) {
- case ($category == 'bookmarks'):
-
- $current_page = (isset($_GET['p']) && ctype_digit($_GET['p']) && $_GET['p'] > 0) ? $_GET['p'] : 1;
- list($bookmarks, $error) = get_user_bookmarks(
- $id,
- ARTWORKS_PER_PAGE * ($current_page - 1),
- ARTWORKS_PER_PAGE
- );
- if ($error) { ?>
- <p><?= get_string($error); ?></p><?php
- break;
- }
- $bookmarks = $bookmarks->body;
-
- $page_count = ceil($bookmarks->total / ARTWORKS_PER_PAGE);?>
- <h2 id="artworks"><?= sprintf(get_string('user.work-count'), $bookmarks->total) ?></h2><?php
- render_artworks_grid($bookmarks->works, true);
- render_paginator($page_count, $current_page, function($page) use ($pathname) {
- return "$pathname/bookmarks?p=$page#artworks";
- });
- break;
- case (isset($_GET['tag']) && strlen($_GET['tag'])):
-
- $tag = $_GET['tag'];
- $current_page = (isset($_GET['p']) && ctype_digit($_GET['p']) && $_GET['p'] > 0) ? $_GET['p'] : 1;
- list($artworks, $error) = get_user_artworks_with_tag(
- $id, $category, $tag,
- ARTWORKS_PER_PAGE * ($current_page - 1), ARTWORKS_PER_PAGE
- );
- if ($error) { ?>
- <p><?= get_string($error); ?></p><?php
- break;
- }
- $artworks = $artworks->body;
- $page_count = ceil($artworks->total / ARTWORKS_PER_PAGE); ?>
-
- <h2 id="artworks"><?= sprintf(get_string('user.work-count-with-tag'), htmlspecialchars($tag), $artworks->total) ?></h2>
- <div class="frequent-tags">
- <a href="<?= "$pathname/$category" ?>"><?= get_string('user.clear-filter') ?></a>
- </div><?php
- render_artworks_grid($artworks->works);
- render_paginator($page_count, $current_page, function($page) use ($pathname, $category, $tag) {
- $tag_encoded = urlencode($tag);
- return "$pathname/$category/$tag_encoded?p=$page#artworks";
- });
- break;
- default:
-
- list($artworks_list, $error) = get_user_artworks_list($id);
- if ($error) { ?>
- <p><?= get_string($error); ?></p><?php
- break;
- }
- $selected_ids = [];
- if ($category == 'artworks' || $category == 'illustrations') {
- $selected_ids = array_merge(array_keys($artworks_list['body']['illusts']), $selected_ids);
- }
- if ($category == 'artworks' || $category == 'manga') {
- $selected_ids = array_merge(array_keys($artworks_list['body']['manga']), $selected_ids);
- }
- rsort($selected_ids);
- $artwork_count = count($selected_ids); ?>
- <h2 id="artworks"><?= sprintf(get_string('user.work-count'), $artwork_count) ?></h2><?php
- if (empty($selected_ids)) { ?>
- <p><?= get_string('no-works') ?></p><?php
- break;
- }
- list($frequent_tags, $error) = get_frequent_tags(array_slice($selected_ids, 0, 50));
- if (!$error) {
- $frequent_tags = $frequent_tags->body ?>
- <div class="frequent-tags"><?php
- foreach ($frequent_tags as $tag) {
- $tag_encoded = urlencode($tag->tag) ?>
- <a href="<?= "$pathname/$category/$tag_encoded" ?>">
- <b><?= htmlspecialchars($tag->tag) ?></b>
- <small><?= htmlspecialchars($tag->tag_translation) ?></small>
- </a><?php
- } ?>
- </div><?php
- }
- $page_count = ceil($artwork_count / ARTWORKS_PER_PAGE);
- $current_page = (
- isset($_GET['p']) && ctype_digit($_GET['p']) && $_GET['p'] > 0 && $_GET['p'] <= $page_count
- ) ? $_GET['p'] : 1;
- $selected_ids_in_page = array_slice($selected_ids, ($current_page - 1) * ARTWORKS_PER_PAGE, ARTWORKS_PER_PAGE);
- list($artworks, $error) = get_user_artworks($id, $selected_ids_in_page);
- if ($error) { ?>
- <p><?= get_string($error) ?></p><?php
- }
- $artworks = $artworks->body->works;
- render_artworks_grid($artworks);
- render_paginator($page_count, $current_page, function($page) use ($pathname, $category) {
- return "$pathname/$category?p=$page#artworks";
- });
- } ?>
- </div>
- <?php
- render_page_footer();
|