221 lines
9.8 KiB
PHP
221 lines
9.8 KiB
PHP
<?php
|
||||
|
|
/**
|
|||
|
|
* 一本书(v24 第 14 批 用户第 5 条):封面 + 元信息 + 读到哪 + 笔记。
|
|||
|
|
*
|
|||
|
|
* 页面两块内容,按"看书的人先想知道什么"排:
|
|||
|
|
* ① 这本书本身(封面、作者、读到哪、读完没读完);
|
|||
|
|
* ② 读的时候留下的字(划线 / 笔记 / 书评)—— 这是以后回看时最有价值的部分。
|
|||
|
|
*
|
|||
|
|
* @param array $b 书
|
|||
|
|
* @param array $chapters 章节目录(没有正文)
|
|||
|
|
* @param array $notes 笔记
|
|||
|
|
*/
|
|||
|
|
$canWrite = \App\Auth::canWrite();
|
|||
|
|
$meId = (int)\App\Auth::personId();
|
|||
|
|
$st = (string)($b['status'] ?? 'wish');
|
|||
|
|
$chapters = $chapters ?? [];
|
|||
|
|
$notes = $notes ?? [];
|
|||
|
|
$hasFile = !empty($b['file_key']);
|
|||
|
|
$readable = $hasFile && ((int)($b['chapter_count'] ?? 0) > 0 || \App\BookParser::inlinable($b['file_format'] ?? ''));
|
|||
|
|
?>
|
|||
|
|
<div class="page-head">
|
|||
|
|
<h1><?= e((string)$b['title']) ?></h1>
|
|||
|
|
<span class="sub">
|
|||
|
|
<?php if (!empty($b['author'])): ?><?= e((string)$b['author']) ?> · <?php endif; ?>
|
|||
|
|
<?= e(\App\Book::statusWord($st)) ?>
|
|||
|
|
</span>
|
|||
|
|
<div class="actions">
|
|||
|
|
<?php if ($readable): ?>
|
|||
|
|
<a class="btn" href="<?= e(url('books/read', ['id' => (int)$b['id']])) ?>">
|
|||
|
|
<?= (int)($b['progress'] ?? 0) > 0 ? '继续读' : '开始读' ?>
|
|||
|
|
</a>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if ($canWrite): ?>
|
|||
|
|
<a class="btn btn-ghost" href="<?= e(url('books/edit', ['id' => (int)$b['id']])) ?>">编辑</a>
|
|||
|
|
<form method="post" action="<?= e(url('books/destroy')) ?>" class="res-inline"
|
|||
|
|
onsubmit="return confirm('把《<?= e((string)$b['title']) ?>》从书架移走吗?文件与笔记会一起删掉,不可恢复。')">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= (int)$b['id'] ?>">
|
|||
|
|
<button class="btn btn-danger" type="submit">移出书架</button>
|
|||
|
|
</form>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<a class="btn btn-ghost" href="<?= e(url('books')) ?>">返回书架</a>
|
|||
|
|
<?php $bkSetCurrent = 'show'; require __DIR__ . '/_settings_menu.php'; ?>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="card card-pad book-hero">
|
|||
|
|
<div class="book-hero-cover">
|
|||
|
|
<?php if (!empty($b['cover_key'])): ?>
|
|||
|
|
<img src="<?= e(media_url((string)$b['cover_key'])) ?>" alt="">
|
|||
|
|
<?php else: ?>
|
|||
|
|
<span class="book-cover-empty">📖</span>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</div>
|
|||
|
|
<div class="book-hero-body">
|
|||
|
|
<?php if (!empty($b['subtitle'])): ?>
|
|||
|
|
<p class="book-sub"><?= e((string)$b['subtitle']) ?></p>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<?php /* 状态的一排快捷:想读 → 在读 → 读完(与任务卡片上那个徽标同款思路,
|
|||
|
|
都是"点一下就变",不用进编辑页)。 */ ?>
|
|||
|
|
<div class="book-states">
|
|||
|
|
<?php foreach (\App\Book::STATUS as $sk => $sv): ?>
|
|||
|
|
<?php if ($canWrite): ?>
|
|||
|
|
<form method="post" action="<?= e(url('books/status')) ?>" class="res-inline">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= (int)$b['id'] ?>">
|
|||
|
|
<input type="hidden" name="status" value="<?= e($sk) ?>">
|
|||
|
|
<button class="kb-st is-<?= e($sk === 'reading' ? 'doing' : ($sk === 'done' ? 'done' : 'todo')) ?><?= $st === $sk ? ' is-on' : '' ?>"
|
|||
|
|
type="submit" title="标成「<?= e($sv) ?>」"><?= e($sv) ?></button>
|
|||
|
|
</form>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<span class="kb-st is-<?= e($sk === 'reading' ? 'doing' : ($sk === 'done' ? 'done' : 'todo')) ?><?= $st === $sk ? ' is-on' : '' ?> is-static"><?= e($sv) ?></span>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<dl class="kv">
|
|||
|
|
<?php if (!empty($b['author'])): ?>
|
|||
|
|
<div class="kv-row"><dt>作者</dt><dd><?= e((string)$b['author']) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($b['translator'])): ?>
|
|||
|
|
<div class="kv-row"><dt>译者</dt><dd><?= e((string)$b['translator']) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($b['publisher'])): ?>
|
|||
|
|
<div class="kv-row"><dt>出版社</dt><dd><?= e((string)$b['publisher']) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($b['published'])): ?>
|
|||
|
|
<div class="kv-row"><dt>出版时间</dt><dd><?= e((string)$b['published']) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($b['category'])): ?>
|
|||
|
|
<div class="kv-row"><dt>分类</dt><dd><?= e((string)$b['category']) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($b['tags'])): ?>
|
|||
|
|
<div class="kv-row"><dt>标签</dt><dd><?= e((string)$b['tags']) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if ((int)($b['pages'] ?? 0) > 0): ?>
|
|||
|
|
<div class="kv-row"><dt>页数</dt><dd><?= (int)$b['pages'] ?> 页</dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if ((int)($b['words'] ?? 0) > 0): ?>
|
|||
|
|
<div class="kv-row"><dt>字数</dt><dd><?= e(\App\Book::wordsWord($b['words'])) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if ($b['rating'] !== null): ?>
|
|||
|
|
<div class="kv-row"><dt>评分</dt><dd><?= (int)$b['rating'] ?> / 10</dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($b['started_at'])): ?>
|
|||
|
|
<div class="kv-row"><dt>开始读</dt><dd><?= e((string)$b['started_at']) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($b['finished_at'])): ?>
|
|||
|
|
<div class="kv-row"><dt>读完于</dt><dd><?= e((string)$b['finished_at']) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($b['file_key'])): ?>
|
|||
|
|
<div class="kv-row">
|
|||
|
|
<dt>文件</dt>
|
|||
|
|
<dd>
|
|||
|
|
<?= e(\App\BookParser::formatWord((string)($b['file_format'] ?? ''))) ?>
|
|||
|
|
<?php if ((int)($b['file_size'] ?? 0) > 0): ?>
|
|||
|
|
· <?= e(\App\Book::sizeWord($b['file_size'])) ?>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
· <a class="link-quiet" href="<?= e(media_url((string)$b['file_key'], ['dl' => 1])) ?>">下载</a>
|
|||
|
|
</dd>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($b['owner_name'])): ?>
|
|||
|
|
<div class="kv-row"><dt>在读的人</dt><dd><?= e((string)$b['owner_name']) ?></dd></div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</dl>
|
|||
|
|
|
|||
|
|
<?php if (!empty($b['summary'])): ?>
|
|||
|
|
<div class="book-sum">
|
|||
|
|
<h2 class="cinema-h2">内容简介</h2>
|
|||
|
|
<p class="info-text"><?= nl2br(e((string)$b['summary'])) ?></p>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<?php if ($chapters): ?>
|
|||
|
|
<div class="book-toc-box">
|
|||
|
|
<h2 class="cinema-h2">目录(<?= count($chapters) ?> 章)</h2>
|
|||
|
|
<ol class="book-toc">
|
|||
|
|
<?php foreach ($chapters as $c): ?>
|
|||
|
|
<li<?= (int)$c['seq'] === (int)($b['progress'] ?? 0) ? ' class="is-cur"' : '' ?>>
|
|||
|
|
<a href="<?= e(url('books/read', ['id' => (int)$b['id'], 'seq' => (int)$c['seq']])) ?>">
|
|||
|
|
<?= e((string)$c['title']) ?>
|
|||
|
|
</a>
|
|||
|
|
<?php if ((int)$c['words'] > 0): ?>
|
|||
|
|
<span class="small muted"><?= (int)$c['words'] ?> 字</span>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</li>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</ol>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<?php /* ==================== 笔记 ==================== */ ?>
|
|||
|
|
<div class="card card-pad">
|
|||
|
|
<h2 class="cinema-h2">
|
|||
|
|
笔记与划线(<?= count($notes) ?>)
|
|||
|
|
<span class="hint">读的时候留下的字;也可以从微信读书等 App 导入</span>
|
|||
|
|
</h2>
|
|||
|
|
|
|||
|
|
<?php if ($canWrite): ?>
|
|||
|
|
<form method="post" action="<?= e(url('books/note_add')) ?>" class="book-note-form">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="id" value="<?= (int)$b['id'] ?>">
|
|||
|
|
<div class="bn-row">
|
|||
|
|
<select class="select" name="kind" aria-label="笔记类型">
|
|||
|
|
<?php foreach (\App\Book::NOTE_KINDS as $kk => $kv): ?>
|
|||
|
|
<option value="<?= e($kk) ?>"><?= e($kv) ?></option>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</select>
|
|||
|
|
<input class="input" name="chapter" placeholder="在第几章(可不填)">
|
|||
|
|
</div>
|
|||
|
|
<textarea class="input" name="content" rows="3" required
|
|||
|
|
placeholder="记一句想法,或把原文抄下来…"></textarea>
|
|||
|
|
<div class="btn-row">
|
|||
|
|
<button class="btn btn-sm" type="submit">记下来</button>
|
|||
|
|
<a class="btn btn-ghost btn-sm" href="<?= e(url('books/notes_import')) ?>">批量导入</a>
|
|||
|
|
</div>
|
|||
|
|
</form>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<?php if (!$notes): ?>
|
|||
|
|
<p class="empty-hint">还没有笔记。读到哪记到哪,以后翻起来才有意思。</p>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<ul class="book-notes">
|
|||
|
|
<?php foreach ($notes as $n): ?>
|
|||
|
|
<?php
|
|||
|
|
$kind = (string)($n['kind'] ?? 'note');
|
|||
|
|
$mine = (int)($n['person_id'] ?? 0) === $meId;
|
|||
|
|
?>
|
|||
|
|
<li class="book-note is-<?= e($kind) ?>">
|
|||
|
|
<div class="bn-head">
|
|||
|
|
<span class="bn-kind"><?= e(\App\Book::kindWord($kind)) ?></span>
|
|||
|
|
<?php if (!empty($n['chapter'])): ?>
|
|||
|
|
<span class="bn-ch"><?= e((string)$n['chapter']) ?></span>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if ((string)($n['source'] ?? 'manual') !== 'manual'): ?>
|
|||
|
|
<span class="bn-src">来自 <?= e(\App\Book::sourceWord((string)$n['source'])) ?></span>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<?php if (!empty($n['person_name'])): ?>
|
|||
|
|
<span class="bn-who"><?= e((string)($n['person_name'])) ?></span>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
<span class="bn-time small muted"><?= e(substr((string)$n['created_at'], 0, 16)) ?></span>
|
|||
|
|
<?php if ($canWrite && ($mine || (int)($n['person_id'] ?? 0) === 0)): ?>
|
|||
|
|
<form method="post" action="<?= e(url('books/note_del')) ?>" class="res-inline bn-del">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="note_id" value="<?= (int)$n['id'] ?>">
|
|||
|
|
<button class="btn btn-ghost btn-sm" type="submit"
|
|||
|
|
onclick="return confirm('删掉这条笔记?')">删</button>
|
|||
|
|
</form>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</div>
|
|||
|
|
<div class="bn-body"><?= nl2br(e((string)$n['content'])) ?></div>
|
|||
|
|
</li>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</ul>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</div>
|