From d714971e068b8b359df2d13f71ddc862f43ca735 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Thu, 17 Jun 2021 18:42:53 -0500 Subject: [PATCH] Further improve RDFa metadata --- lib/Ebook.php | 87 +++++++++++++++++++++++++++++++++++--------- www/about/index.php | 4 +- www/ebooks/ebook.php | 5 ++- 3 files changed, 74 insertions(+), 22 deletions(-) diff --git a/lib/Ebook.php b/lib/Ebook.php index aa664021..dd7ce742 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -297,7 +297,7 @@ class Ebook{ // If we added an illustrator who is also the translator, remove the illustrator credit so the name doesn't appear twice foreach($this->Illustrators as $key => $illustrator){ foreach($this->Translators as $translator){ - if($translator->Name == $c->Name){ + if($translator->Name == $illustrator->Name){ unset($this->Illustrators[$key]); break; } @@ -427,18 +427,18 @@ class Ebook{ // Put together the full contributor string. $titleContributors = ''; if(sizeof($this->Contributors) > 0){ - $titleContributors .= '. With ' . $this->GenerateContributorList($this->Contributors); - $this->ContributorsHtml .= ' with ' . $this->GenerateContributorList($this->Contributors) . ';'; + $titleContributors .= '. With ' . $this->GenerateContributorList($this->Contributors, false); + $this->ContributorsHtml .= ' with ' . $this->GenerateContributorList($this->Contributors, false) . ';'; } if(sizeof($this->Translators) > 0){ - $titleContributors .= '. Translated by ' . $this->GenerateContributorList($this->Translators); - $this->ContributorsHtml .= ' translated by ' . $this->GenerateContributorList($this->Translators) . ';'; + $titleContributors .= '. Translated by ' . $this->GenerateContributorList($this->Translators, false); + $this->ContributorsHtml .= ' translated by ' . $this->GenerateContributorList($this->Translators, false) . ';'; } if(sizeof($this->Illustrators) > 0){ - $titleContributors .= '. Illustrated by ' . $this->GenerateContributorList($this->Illustrators); - $this->ContributorsHtml .= ' illustrated by ' . $this->GenerateContributorList($this->Illustrators) . ';'; + $titleContributors .= '. Illustrated by ' . $this->GenerateContributorList($this->Illustrators, false); + $this->ContributorsHtml .= ' illustrated by ' . $this->GenerateContributorList($this->Illustrators, false) . ';'; } if($this->ContributorsHtml !== null){ @@ -449,7 +449,7 @@ class Ebook{ } } - $this->AuthorsHtml = $this->GenerateContributorList($this->Authors); + $this->AuthorsHtml = $this->GenerateContributorList($this->Authors, true); // Now the complete title with credits. $this->TitleWithCreditsHtml = Formatter::ToPlainText($this->Title) . ', by ' . str_replace('&', '&', $this->AuthorsHtml . $titleContributors); @@ -610,12 +610,13 @@ class Ebook{ /** * @param array $contributors + * @param bool $includeRdfa */ - private function GenerateContributorList(array $contributors): string{ + private function GenerateContributorList(array $contributors, bool $includeRdfa): string{ $string = ''; $i = 0; - foreach($contributors as $contributor){ + foreach($contributors as $contributor){ $role = 'schema:contributor'; switch($contributor->MarcRole){ case 'trl': @@ -627,22 +628,32 @@ class Ebook{ } if($contributor->WikipediaUrl){ - $string .= '' . Formatter::ToPlainText($contributor->Name) . ''; + if($includeRdfa){ + $string .= '' . Formatter::ToPlainText($contributor->Name) . ''; - if($contributor->NacoafUrl){ - $string .= ''; + if($contributor->NacoafUrl){ + $string .= ''; + } + } + else{ + $string .= '' . Formatter::ToPlainText($contributor->Name); } $string .= ''; } else{ - $string .= '' . Formatter::ToPlainText($contributor->Name) . ''; + if($includeRdfa){ + $string .= '' . Formatter::ToPlainText($contributor->Name) . ''; - if($contributor->NacoafUrl){ - $string .= ''; + if($contributor->NacoafUrl){ + $string .= ''; + } + + $string .= ''; + } + else{ + $string .= Formatter::ToPlainText($contributor->Name); } - - $string .= ''; } if($i == sizeof($contributors) - 2 && sizeof($contributors) > 2){ @@ -661,6 +672,46 @@ class Ebook{ return $string; } + public function GenerateContributorsRdfa(): string{ + $string = ''; + $i = 0; + + foreach($this->Translators as $contributor){ + $role = 'schema:contributor'; + switch($contributor->MarcRole){ + case 'trl': + $role = 'schema:translator'; + break; + case 'ill': + $role = 'schema:illustrator'; + break; + } + + if($contributor->WikipediaUrl){ + $string .= '
' . "\n"; + } + else{ + $string .= '
' . "\n"; + } + + $string .= '' . "\n"; + + if($contributor->WikipediaUrl){ + $string .= '' . "\n"; + } + + if($contributor->NacoafUrl){ + $string .= '' . "\n"; + } + + $string .= '
'; + + $i++; + } + + return $string; + } + private function NullIfEmpty($elements): ?string{ if($elements === false){ return null; diff --git a/www/about/index.php b/www/about/index.php index d9c1afd4..45a7df1b 100644 --- a/www/about/index.php +++ b/www/about/index.php @@ -150,7 +150,7 @@ require_once('Core.php');

Anonymous × 3

- + @@ -159,7 +159,7 @@ require_once('Core.php');

Firstname Lastname

- + */ ?> diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index 332cf976..29a5fd41 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -90,6 +90,7 @@ catch(\Exception $ex){ Name) ?> NacoafUrl){ ?> + WikipediaUrl){ ?> @@ -138,10 +139,9 @@ catch(\Exception $ex){ HasDownloads){ ?> -
+
-
@@ -168,6 +168,7 @@ catch(\Exception $ex){
+ GenerateContributorsRdfa() ?>

Read free

This ebook is only thought to be free of copyright restrictions in the United States. It may still be under copyright in other countries. If you’re not located in the United States, you must check your local laws to verify that the contents of this ebook are free of copyright restrictions in the country you’re located in before downloading or using this ebook.