diff --git a/config/apache/rewrites/projects.conf b/config/apache/rewrites/projects.conf index f868fa25..6543dd4f 100644 --- a/config/apache/rewrites/projects.conf +++ b/config/apache/rewrites/projects.conf @@ -2,5 +2,11 @@ RewriteRule ^/ebooks/([^\.]+?)/projects/new$ /projects/new.php?ebook-url-path=$ RewriteRule ^/projects/([\d]+)/edit$ /projects/edit.php?project-id=$1 +# Query string may contain `indent=`. +RewriteRule ^/projects/([\d]+)/reviewer$ /projects/reviewer/get.php?project-id=$1 [QSA] + +# Query string may contain `indent=`. +RewriteRule ^/ebooks/(.+?)/projects/in-progress/reviewer$ /projects/reviewer/get.php?url-path=$1 [QSA] + RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" RewriteRule ^/projects/([\d]+)$ /projects/post.php?project-id=$1 [L] diff --git a/lib/Project.php b/lib/Project.php index 73e3fb86..414f4ea3 100644 --- a/lib/Project.php +++ b/lib/Project.php @@ -675,6 +675,17 @@ final class Project{ return Db::Query('SELECT * from Projects where ProjectId = ?', [$projectId], Project::class)[0] ?? throw new Exceptions\ProjectNotFoundException(); } + /** + * @throws Exceptions\ProjectNotFoundException If the `Project` can't be found. + */ + public static function GetByIdentifierAndIsInProgress(?string $identifier): Project{ + if($identifier === null){ + throw new Exceptions\ProjectNotFoundException(); + } + + return Db::Query('SELECT Projects.* from Ebooks inner join Projects using (EbookId) where Ebooks.Identifier = ? and Projects.Status = ?', [$identifier, Enums\ProjectStatusType::InProgress], Project::class)[0] ?? throw new Exceptions\ProjectNotFoundException(); + } + /** * @return array */ diff --git a/lib/User.php b/lib/User.php index 13e177ff..a07dc7b0 100644 --- a/lib/User.php +++ b/lib/User.php @@ -13,7 +13,8 @@ use function Safe\preg_match; * @property ?Patron $Patron * @property ?NewsletterSubscription $NewsletterSubscription * @property ?Payment $LastPayment - * @property string $DisplayName A string that represent's the `User`'s name, or email, or ID. + * @property string $DisplayName The `User`'s name, or email, or ID. + * @property ?string $SortName The `User`'s name in an (attempted) sort order, or `null` if the `User` has no name. */ class User{ use Traits\Accessor; @@ -37,12 +38,41 @@ class User{ protected ?Patron $_Patron; protected ?NewsletterSubscription $_NewsletterSubscription; protected string $_DisplayName; + protected ?string $_SortName = null; // ******* // GETTERS // ******* + protected function GetSortName(): string{ + if(!isset($this->_SortName)){ + if($this->Name !== null){ + preg_match('/\s(?:de |de la |di |van |von )?[^\s]+$/iu', $this->Name, $lastNameMatches); + if(sizeof($lastNameMatches) == 0){ + $this->SortName = $this->Name; + } + else{ + $lastName = trim($lastNameMatches[0]); + + preg_match('/^(.+)' . preg_quote($lastName, '/') . '$/u', $this->Name, $firstNameMatches); + + if(sizeof($firstNameMatches) == 0){ + $this->SortName = $this->Name; + } + else{ + $this->_SortName = $lastName . ', ' . trim($firstNameMatches[1]); + } + } + } + else{ + $this->_SortName = null; + } + } + + return $this->_SortName; + } + protected function GetDisplayName(): string{ if(!isset($this->_DisplayName)){ if($this->Name !== null){ diff --git a/scripts/deploy-ebook-to-www b/scripts/deploy-ebook-to-www index ad0998c2..d41d5a1e 100755 --- a/scripts/deploy-ebook-to-www +++ b/scripts/deploy-ebook-to-www @@ -58,7 +58,7 @@ recompose="true" feeds="true" bulkDownloads="true" -if [ $# -eq 0 ]; then +if [ $# -eq 0 ]; then usage fi diff --git a/www/projects/reviewer/get.php b/www/projects/reviewer/get.php new file mode 100644 index 00000000..0f6a7793 --- /dev/null +++ b/www/projects/reviewer/get.php @@ -0,0 +1,61 @@ +Name = $project->Reviewer->Name; + $output->SortName = $project->Reviewer->SortName; + + switch($output->Name){ + case 'Alex Cabal': + $output->Url = 'https://alexcabal.com'; + break; + + case 'Emma Sweeney': + $output->Url = 'https://www.linkedin.com/in/emma-sweeney-554927190/'; + break; + + case 'Weijia Cheng': + $output->Url = 'https://weijiarhymeswith.asia'; + break; + + case 'Robin Whittleton': + $output->Url = 'https://www.robinwhittleton.com'; + break; + + case 'Vince Rice': + $output->Url = 'https://www.brokenandsa'; + break; + + case 'David Reimer': + $output->Url = 'https://github.com/dajare'; + $output->NacoafUrl = 'http://id.loc.gov/authorities/names/n92075987'; + break; + } + + header('Content-type: text/plain'); +} +catch(Exceptions\ProjectNotFoundException){ + Template::ExitWithCode(Enums\HttpCode::NotFound); +} +?> + Name) ?> + SortName) ?> +Url)){ ?> + Url) ?> + +NacoafUrl)){ ?> + NacoafUrl) ?> + + pfr