mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 02:21:55 -04:00
Add CanEditEbooks benefit and clean up some PHPStan errors
This commit is contained in:
parent
23b5c8ef31
commit
1a742baa51
10 changed files with 75 additions and 14 deletions
|
@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS `Benefits` (
|
|||
`CanReviewOwnArtwork` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
`CanEditUsers` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
`CanEditCollections` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
`CanEditEbooks` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
`CanCreateEbookPlaceholders` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`UserId`),
|
||||
KEY `idxBenefits` (`CanAccessFeeds`,`CanVote`,`CanBulkDownload`)
|
||||
|
|
|
@ -55,15 +55,22 @@ class AtomFeed extends Feed{
|
|||
foreach($this->Entries as $entry){
|
||||
$obj = new StdClass();
|
||||
if($entry instanceof Ebook){
|
||||
if($entry->EbookUpdated !== null){
|
||||
$obj->Updated = $entry->EbookUpdated->format(Enums\DateTimeFormat::Iso->value);
|
||||
$obj->Id = SITE_URL . $entry->Url;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if($entry->Updated !== null){
|
||||
$obj->Updated = $entry->Updated->format(Enums\DateTimeFormat::Iso->value);
|
||||
$obj->Id = $entry->Id;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($obj->Id)){
|
||||
$currentEntries[] = $obj;
|
||||
}
|
||||
}
|
||||
|
||||
$oldEntries = [];
|
||||
try{
|
||||
|
|
|
@ -16,6 +16,7 @@ class Benefits{
|
|||
public bool $CanReviewOwnArtwork = false;
|
||||
public bool $CanEditUsers = false;
|
||||
public bool $CanEditCollections = false;
|
||||
public bool $CanEditEbooks = false;
|
||||
public bool $CanCreateEbookPlaceholders = false;
|
||||
|
||||
protected bool $_HasBenefits;
|
||||
|
@ -30,6 +31,10 @@ class Benefits{
|
|||
||
|
||||
$this->CanEditUsers
|
||||
||
|
||||
$this->CanEditCollections
|
||||
||
|
||||
$this->CanEditEbooks
|
||||
||
|
||||
$this->CanCreateEbookPlaceholders
|
||||
){
|
||||
return true;
|
||||
|
|
|
@ -444,7 +444,7 @@ class Ebook{
|
|||
|
||||
protected function GetReadingTime(): string{
|
||||
if(!isset($this->_ReadingTime)){
|
||||
$readingTime = ceil($this->WordCount / AVERAGE_READING_WORDS_PER_MINUTE);
|
||||
$readingTime = ceil(($this->WordCount ?? 0) / AVERAGE_READING_WORDS_PER_MINUTE);
|
||||
$this->_ReadingTime = (string)$readingTime;
|
||||
|
||||
if($readingTime < 60){
|
||||
|
|
|
@ -110,6 +110,10 @@ foreach(Ebook::GetAll() as $ebook){
|
|||
continue;
|
||||
}
|
||||
|
||||
if($ebook->EbookCreated === null || $ebook->EbookUpdated === null){
|
||||
continue;
|
||||
}
|
||||
|
||||
$timestamp = $ebook->EbookCreated->format('Y-m');
|
||||
$updatedTimestamp = $ebook->EbookUpdated->getTimestamp();
|
||||
|
||||
|
|
|
@ -47,7 +47,9 @@ $collection = $collection ?? null;
|
|||
</div>
|
||||
<? } ?>
|
||||
<? if(!$ebook->IsPlaceholder()){ ?>
|
||||
<? if($ebook->WordCount !== null){ ?>
|
||||
<p><?= number_format($ebook->WordCount) ?> words • <?= $ebook->ReadingEase ?> reading ease</p>
|
||||
<? } ?>
|
||||
<ul class="tags">
|
||||
<? foreach($ebook->Tags as $tag){ ?>
|
||||
<li>
|
||||
|
|
|
@ -24,9 +24,9 @@ use function Safe\filesize;
|
|||
<? } ?>
|
||||
</author>
|
||||
<? } ?>
|
||||
<published><?= $entry->EbookCreated->format(Enums\DateTimeFormat::Iso->value) ?></published>
|
||||
<dc:issued><?= $entry->EbookCreated->format(Enums\DateTimeFormat::Iso->value) ?></dc:issued>
|
||||
<updated><?= $entry->EbookUpdated->format(Enums\DateTimeFormat::Iso->value) ?></updated>
|
||||
<published><?= $entry->EbookCreated?->format(Enums\DateTimeFormat::Iso->value) ?></published>
|
||||
<dc:issued><?= $entry->EbookCreated?->format(Enums\DateTimeFormat::Iso->value) ?></dc:issued>
|
||||
<updated><?= $entry->EbookUpdated?->format(Enums\DateTimeFormat::Iso->value) ?></updated>
|
||||
<dc:language><?= Formatter::EscapeXml($entry->Language) ?></dc:language>
|
||||
<dc:publisher>Standard Ebooks</dc:publisher>
|
||||
<rights>Public domain in the United States. Users located outside of the United States must check their local laws before using this ebook. Original content released to the public domain via the Creative Commons CC0 1.0 Universal Public Domain Dedication.</rights>
|
||||
|
|
|
@ -10,7 +10,7 @@ use function Safe\preg_replace;
|
|||
<title><?= Formatter::EscapeXml($entry->Title) ?>, by <?= Formatter::EscapeXml(strip_tags($entry->AuthorsHtml)) ?></title>
|
||||
<link><?= SITE_URL . Formatter::EscapeXml($entry->Url) ?></link>
|
||||
<description><?= Formatter::EscapeXml($entry->Description) ?></description>
|
||||
<pubDate><?= $entry->EbookCreated->format(Enums\DateTimeFormat::Rss->value) ?></pubDate>
|
||||
<pubDate><?= $entry->EbookCreated?->format(Enums\DateTimeFormat::Rss->value) ?></pubDate>
|
||||
<guid><?= Formatter::EscapeXml(preg_replace('/^url:/ius', '', $entry->Identifier)) ?></guid>
|
||||
<? foreach($entry->Tags as $tag){ ?>
|
||||
<category domain="https://standardebooks.org/vocab/subjects"><?= Formatter::EscapeXml($tag->Name) ?></category>
|
||||
|
|
|
@ -102,6 +102,24 @@ catch(Exceptions\EbookNotFoundException){
|
|||
<p>This book is not yet in the U.S. public domain. We can’t offer it until it is.</p>
|
||||
<? } ?>
|
||||
</section>
|
||||
|
||||
<? if(Session::$User?->Benefits->CanEditEbooks){ ?>
|
||||
<section id="metadata">
|
||||
<h2>Metadata</h2>
|
||||
<table class="admin-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Ebook ID:</td>
|
||||
<td><?= $ebook->EbookId ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Identifier:</td>
|
||||
<td><?= Formatter::EscapeHtml($ebook->Identifier) ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<? } ?>
|
||||
</article>
|
||||
</main>
|
||||
<?= Template::Footer() ?>
|
||||
|
|
|
@ -123,7 +123,9 @@ catch(Exceptions\EbookNotFoundException){
|
|||
|
||||
|
||||
<aside id="reading-ease">
|
||||
<? if($ebook->WordCount !== null){ ?>
|
||||
<p><?= number_format($ebook->WordCount) ?> words (<?= $ebook->ReadingTime ?>) with a reading ease of <?= $ebook->ReadingEase ?> (<?= $ebook->ReadingEaseDescription ?>)</p>
|
||||
<? } ?>
|
||||
<? if($ebook->ContributorsHtml != ''){ ?>
|
||||
<p><?= $ebook->ContributorsHtml ?></p>
|
||||
<? } ?>
|
||||
|
@ -175,8 +177,12 @@ catch(Exceptions\EbookNotFoundException){
|
|||
<meta property="schema:image" content="<?= Formatter::EscapeHtml(SITE_URL . $ebook->DistCoverUrl) ?>"/>
|
||||
<meta property="schema:thumbnailUrl" content="<?= Formatter::EscapeHtml(SITE_URL . $ebook->Url . '/downloads/cover-thumbnail.jpg') ?>"/>
|
||||
<meta property="schema:inLanguage" content="<?= Formatter::EscapeHtml($ebook->Language) ?>"/>
|
||||
<? if($ebook->EbookCreated !== null){ ?>
|
||||
<meta property="schema:datePublished" content="<?= Formatter::EscapeHtml($ebook->EbookCreated->format('Y-m-d')) ?>"/>
|
||||
<? } ?>
|
||||
<? if($ebook->EbookUpdated !== null){ ?>
|
||||
<meta property="schema:dateModified" content="<?= Formatter::EscapeHtml($ebook->EbookUpdated->format('Y-m-d')) ?>"/>
|
||||
<? } ?>
|
||||
<div property="schema:potentialAction" typeof="http://schema.org/ReadAction">
|
||||
<meta property="schema:actionStatus" content="http://schema.org/PotentialActionStatus"/>
|
||||
<div property="schema:target" typeof="schema:EntryPoint">
|
||||
|
@ -391,6 +397,24 @@ catch(Exceptions\EbookNotFoundException){
|
|||
<p>You can also <a href="/donate">donate to Standard Ebooks</a> to help fund continuing improvement of this and other ebooks.</p>
|
||||
</section>
|
||||
|
||||
<? if(Session::$User?->Benefits->CanEditEbooks){ ?>
|
||||
<section id="metadata">
|
||||
<h2>Metadata</h2>
|
||||
<table class="admin-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Ebook ID:</td>
|
||||
<td><?= $ebook->EbookId ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Identifier:</td>
|
||||
<td><?= Formatter::EscapeHtml($ebook->Identifier) ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<? } ?>
|
||||
|
||||
<? if(sizeof($carousel) > 0){ ?>
|
||||
<aside id="more-ebooks">
|
||||
<h2>More free<? if($carouselTag !== null){ ?> <?= strtolower($carouselTag->Name) ?><? } ?> ebooks</h2>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue