mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 06:40:33 -04:00
Refactor HttpInput::Str and rename some exceptions for consistency
This commit is contained in:
parent
2b5f4f55a2
commit
ca3fc6dbfd
54 changed files with 163 additions and 159 deletions
|
@ -142,7 +142,7 @@ Before submitting design contributions, please discuss them with the Standard Eb
|
||||||
|
|
||||||
- Include in-use ebook slug as a search parameter when searching for artwork by keyword.
|
- Include in-use ebook slug as a search parameter when searching for artwork by keyword.
|
||||||
|
|
||||||
- Artwork searching/filtering should be done in pure SQL, no after-sql filtering in PHP.
|
- Artwork searching/filtering should be done in pure SQL, no after-SQL filtering in PHP.
|
||||||
|
|
||||||
- Allow listing artwork by artist by visiting `/artworks/<artist-name>`, and link instances of artist name to that URL.
|
- Allow listing artwork by artist by visiting `/artworks/<artist-name>`, and link instances of artist name to that URL.
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ class Artist extends PropertiesBase{
|
||||||
|
|
||||||
public static function Get(?int $artistId): Artist{
|
public static function Get(?int $artistId): Artist{
|
||||||
if($artistId === null){
|
if($artistId === null){
|
||||||
throw new Exceptions\InvalidArtistException();
|
throw new Exceptions\ArtistNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
|
@ -95,7 +95,7 @@ class Artist extends PropertiesBase{
|
||||||
', [$artistId], 'Artist');
|
', [$artistId], 'Artist');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidArtistException();
|
throw new Exceptions\ArtistNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
|
|
@ -135,7 +135,7 @@ class Artwork extends PropertiesBase{
|
||||||
try{
|
try{
|
||||||
$this->_Submitter = User::Get($this->SubmitterUserId);
|
$this->_Submitter = User::Get($this->SubmitterUserId);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidUserException){
|
catch(Exceptions\UserNotFoundException){
|
||||||
// Return null
|
// Return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ class Artwork extends PropertiesBase{
|
||||||
try{
|
try{
|
||||||
$this->_Reviewer = User::Get($this->ReviewerUserId);
|
$this->_Reviewer = User::Get($this->ReviewerUserId);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidUserException){
|
catch(Exceptions\UserNotFoundException){
|
||||||
// Return null
|
// Return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -486,7 +486,7 @@ class Artwork extends PropertiesBase{
|
||||||
// But we do a basic check that the string includes one _. It might not include a dash, for example anonymous_poetry
|
// But we do a basic check that the string includes one _. It might not include a dash, for example anonymous_poetry
|
||||||
if($this->EbookWwwFilesystemPath !== null){
|
if($this->EbookWwwFilesystemPath !== null){
|
||||||
if(mb_stripos($this->EbookWwwFilesystemPath, '_') === false){
|
if(mb_stripos($this->EbookWwwFilesystemPath, '_') === false){
|
||||||
$error->Add(new Exceptions\InvalidEbookException('Invalid ebook. Expected file system slug like “c-s-lewis_poetry”.'));
|
$error->Add(new Exceptions\EbookNotFoundException('Invalid ebook. Expected file system slug like “c-s-lewis_poetry”.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -900,23 +900,23 @@ class Artwork extends PropertiesBase{
|
||||||
$artwork = new Artwork();
|
$artwork = new Artwork();
|
||||||
$artwork->Artist = new Artist();
|
$artwork->Artist = new Artist();
|
||||||
|
|
||||||
$artwork->Artist->Name = HttpInput::Str(POST, 'artist-name', false);
|
$artwork->Artist->Name = HttpInput::Str(POST, 'artist-name');
|
||||||
$artwork->Artist->DeathYear = HttpInput::Int(POST, 'artist-year-of-death');
|
$artwork->Artist->DeathYear = HttpInput::Int(POST, 'artist-year-of-death');
|
||||||
|
|
||||||
$artwork->Name = HttpInput::Str(POST, 'artwork-name', false);
|
$artwork->Name = HttpInput::Str(POST, 'artwork-name');
|
||||||
$artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year');
|
$artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year');
|
||||||
$artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa', false) ?? false;
|
$artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa') ?? false;
|
||||||
$artwork->Tags = HttpInput::Str(POST, 'artwork-tags', false) ?? [];
|
$artwork->Tags = HttpInput::Str(POST, 'artwork-tags') ?? [];
|
||||||
$artwork->Status = HttpInput::Str(POST, 'artwork-status', false) ?? ArtworkStatus::Unverified;
|
$artwork->Status = HttpInput::Str(POST, 'artwork-status') ?? ArtworkStatus::Unverified;
|
||||||
$artwork->EbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path', false);
|
$artwork->EbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path');
|
||||||
$artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us', false);
|
$artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us') ?? false;
|
||||||
$artwork->PublicationYear = HttpInput::Int(POST, 'artwork-publication-year');
|
$artwork->PublicationYear = HttpInput::Int(POST, 'artwork-publication-year');
|
||||||
$artwork->PublicationYearPageUrl = HttpInput::Str(POST, 'artwork-publication-year-page-url', false);
|
$artwork->PublicationYearPageUrl = HttpInput::Str(POST, 'artwork-publication-year-page-url');
|
||||||
$artwork->CopyrightPageUrl = HttpInput::Str(POST, 'artwork-copyright-page-url', false);
|
$artwork->CopyrightPageUrl = HttpInput::Str(POST, 'artwork-copyright-page-url');
|
||||||
$artwork->ArtworkPageUrl = HttpInput::Str(POST, 'artwork-artwork-page-url', false);
|
$artwork->ArtworkPageUrl = HttpInput::Str(POST, 'artwork-artwork-page-url');
|
||||||
$artwork->MuseumUrl = HttpInput::Str(POST, 'artwork-museum-url', false);
|
$artwork->MuseumUrl = HttpInput::Str(POST, 'artwork-museum-url');
|
||||||
$artwork->Exception = HttpInput::Str(POST, 'artwork-exception', false);
|
$artwork->Exception = HttpInput::Str(POST, 'artwork-exception');
|
||||||
$artwork->Notes = HttpInput::Str(POST, 'artwork-notes', false);
|
$artwork->Notes = HttpInput::Str(POST, 'artwork-notes');
|
||||||
|
|
||||||
return $artwork;
|
return $artwork;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,20 +91,20 @@ class Ebook{
|
||||||
}
|
}
|
||||||
catch(Exception){
|
catch(Exception){
|
||||||
// We may get an exception from preg_replace if the passed repo wwwFilesystemPath contains invalid UTF-8 characters, whichis a common injection attack vector
|
// We may get an exception from preg_replace if the passed repo wwwFilesystemPath contains invalid UTF-8 characters, whichis a common injection attack vector
|
||||||
throw new Exceptions\InvalidEbookException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath);
|
throw new Exceptions\EbookNotFoundException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_dir($wwwFilesystemPath)){
|
if(!is_dir($wwwFilesystemPath)){
|
||||||
throw new Exceptions\InvalidEbookException('Invalid www filesystem path: ' . $wwwFilesystemPath);
|
throw new Exceptions\EbookNotFoundException('Invalid www filesystem path: ' . $wwwFilesystemPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_dir($this->RepoFilesystemPath)){
|
if(!is_dir($this->RepoFilesystemPath)){
|
||||||
throw new Exceptions\InvalidEbookException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath);
|
throw new Exceptions\EbookNotFoundException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_file($wwwFilesystemPath . '/content.opf')){
|
if(!is_file($wwwFilesystemPath . '/content.opf')){
|
||||||
throw new Exceptions\InvalidEbookException('Invalid content.opf file: ' . $wwwFilesystemPath . '/content.opf');
|
throw new Exceptions\EbookNotFoundException('Invalid content.opf file: ' . $wwwFilesystemPath . '/content.opf');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->WwwFilesystemPath = $wwwFilesystemPath;
|
$this->WwwFilesystemPath = $wwwFilesystemPath;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?
|
<?
|
||||||
namespace Exceptions;
|
namespace Exceptions;
|
||||||
|
|
||||||
class InvalidArtistException extends AppException{
|
class ArtistNotFoundException extends AppException{
|
||||||
protected $message = 'We couldn’t locate that artist.';
|
protected $message = 'We couldn’t locate that artist.';
|
||||||
}
|
}
|
5
lib/Exceptions/AuthorNotFoundException.php
Normal file
5
lib/Exceptions/AuthorNotFoundException.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?
|
||||||
|
namespace Exceptions;
|
||||||
|
|
||||||
|
class AuthorNotFoundException extends AppException{
|
||||||
|
}
|
5
lib/Exceptions/CollectionNotFoundException.php
Normal file
5
lib/Exceptions/CollectionNotFoundException.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?
|
||||||
|
namespace Exceptions;
|
||||||
|
|
||||||
|
class CollectionNotFoundException extends AppException{
|
||||||
|
}
|
5
lib/Exceptions/EbookNotFoundException.php
Normal file
5
lib/Exceptions/EbookNotFoundException.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?
|
||||||
|
namespace Exceptions;
|
||||||
|
|
||||||
|
class EbookNotFoundException extends AppException{
|
||||||
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
<?
|
|
||||||
namespace Exceptions;
|
|
||||||
|
|
||||||
class InvalidAuthorException extends AppException{
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?
|
|
||||||
namespace Exceptions;
|
|
||||||
|
|
||||||
class InvalidCollectionException extends AppException{
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?
|
|
||||||
namespace Exceptions;
|
|
||||||
|
|
||||||
class InvalidEbookException extends AppException{
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?
|
|
||||||
namespace Exceptions;
|
|
||||||
|
|
||||||
class InvalidSessionException extends AppException{
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?
|
<?
|
||||||
namespace Exceptions;
|
namespace Exceptions;
|
||||||
|
|
||||||
class InvalidNewsletterSubscriptionException extends AppException{
|
class NewsletterSubscriptionNotFoundException extends AppException{
|
||||||
protected $message = 'We couldn’t find you in our newsletter subscribers list.';
|
protected $message = 'We couldn’t find you in our newsletter subscribers list.';
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
<?
|
<?
|
||||||
namespace Exceptions;
|
namespace Exceptions;
|
||||||
|
|
||||||
class InvalidPollItemException extends AppException{
|
class PollItemNotFoundException extends AppException{
|
||||||
protected $message = 'We couldn’t locate that poll item.';
|
protected $message = 'We couldn’t locate that poll item.';
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
<?
|
<?
|
||||||
namespace Exceptions;
|
namespace Exceptions;
|
||||||
|
|
||||||
class InvalidPollException extends AppException{
|
class PollNotFoundException extends AppException{
|
||||||
protected $message = 'We couldn’t locate that poll.';
|
protected $message = 'We couldn’t locate that poll.';
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
<?
|
<?
|
||||||
namespace Exceptions;
|
namespace Exceptions;
|
||||||
|
|
||||||
class InvalidPollVoteException extends AppException{
|
class PollVoteNotFoundException extends AppException{
|
||||||
protected $message = 'We couldn’t locate that vote.';
|
protected $message = 'We couldn’t locate that vote.';
|
||||||
}
|
}
|
5
lib/Exceptions/SessionNotFoundException.php
Normal file
5
lib/Exceptions/SessionNotFoundException.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?
|
||||||
|
namespace Exceptions;
|
||||||
|
|
||||||
|
class SessionNotFoundException extends AppException{
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
<?
|
<?
|
||||||
namespace Exceptions;
|
namespace Exceptions;
|
||||||
|
|
||||||
class InvalidUserException extends AppException{
|
class UserNotFoundException extends AppException{
|
||||||
protected $message = 'We couldn’t locate that user.';
|
protected $message = 'We couldn’t locate that user.';
|
||||||
}
|
}
|
|
@ -50,30 +50,30 @@ class HttpInput{
|
||||||
return preg_match('/\btext\/html\b/ius', $_SERVER['HTTP_ACCEPT'] ?? '') ? WEB : REST;
|
return preg_match('/\btext\/html\b/ius', $_SERVER['HTTP_ACCEPT'] ?? '') ? WEB : REST;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Str(string $type, string $variable, bool $allowEmptyString = true, string $default = null): ?string{
|
public static function Str(string $type, string $variable, $allowEmptyString = false): ?string{
|
||||||
$var = self::GetHttpVar($variable, HTTP_VAR_STR, $type, $default);
|
$var = self::GetHttpVar($variable, HTTP_VAR_STR, $type);
|
||||||
|
|
||||||
if(is_array($var)){
|
if(is_array($var)){
|
||||||
return $default;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$allowEmptyString && $var === ''){
|
if(!$allowEmptyString && $var == ''){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $var;
|
return $var;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Int(string $type, string $variable, int $default = null): ?int{
|
public static function Int(string $type, string $variable): ?int{
|
||||||
return self::GetHttpVar($variable, HTTP_VAR_INT, $type, $default);
|
return self::GetHttpVar($variable, HTTP_VAR_INT, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Bool(string $type, string $variable, bool $default = null): ?bool{
|
public static function Bool(string $type, string $variable): ?bool{
|
||||||
return self::GetHttpVar($variable, HTTP_VAR_BOOL, $type, $default);
|
return self::GetHttpVar($variable, HTTP_VAR_BOOL, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Dec(string $type, string $variable, float $default = null): ?float{
|
public static function Dec(string $type, string $variable): ?float{
|
||||||
return self::GetHttpVar($variable, HTTP_VAR_DEC, $type, $default);
|
return self::GetHttpVar($variable, HTTP_VAR_DEC, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,11 +81,11 @@ class HttpInput{
|
||||||
* @param array<mixed> $default
|
* @param array<mixed> $default
|
||||||
* @return array<string>
|
* @return array<string>
|
||||||
*/
|
*/
|
||||||
public static function GetArray(string $variable, array $default = null): ?array{
|
public static function GetArray(string $variable): ?array{
|
||||||
return self::GetHttpVar($variable, HTTP_VAR_ARRAY, GET, $default);
|
return self::GetHttpVar($variable, HTTP_VAR_ARRAY, GET);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function GetHttpVar(string $variable, int $type, string $set, mixed $default): mixed{
|
private static function GetHttpVar(string $variable, int $type, string $set): mixed{
|
||||||
$vars = [];
|
$vars = [];
|
||||||
|
|
||||||
switch($set){
|
switch($set){
|
||||||
|
@ -110,7 +110,7 @@ class HttpInput{
|
||||||
}
|
}
|
||||||
elseif($type !== HTTP_VAR_ARRAY && is_array($vars[$variable])){
|
elseif($type !== HTTP_VAR_ARRAY && is_array($vars[$variable])){
|
||||||
// We asked for not an array, but we got an array
|
// We asked for not an array, but we got an array
|
||||||
return $default;
|
return null;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$var = trim($vars[$variable]);
|
$var = trim($vars[$variable]);
|
||||||
|
@ -126,7 +126,7 @@ class HttpInput{
|
||||||
return intval($var);
|
return intval($var);
|
||||||
}
|
}
|
||||||
catch(Exception){
|
catch(Exception){
|
||||||
return $default;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -143,13 +143,13 @@ class HttpInput{
|
||||||
return floatval($var);
|
return floatval($var);
|
||||||
}
|
}
|
||||||
catch(Exception){
|
catch(Exception){
|
||||||
return $default;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $default;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class NewsletterSubscription extends PropertiesBase{
|
||||||
try{
|
try{
|
||||||
$this->User = User::GetByEmail($this->User->Email);
|
$this->User = User::GetByEmail($this->User->Email);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidUserException){
|
catch(Exceptions\UserNotFoundException){
|
||||||
// User doesn't exist, create the user
|
// User doesn't exist, create the user
|
||||||
$this->User->Create();
|
$this->User->Create();
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,11 @@ class NewsletterSubscription extends PropertiesBase{
|
||||||
// ORM METHODS
|
// ORM METHODS
|
||||||
// ***********
|
// ***********
|
||||||
|
|
||||||
public static function Get(string $uuid): NewsletterSubscription{
|
public static function Get(?string $uuid): NewsletterSubscription{
|
||||||
|
if($uuid === null){
|
||||||
|
throw new Exceptions\NewsletterSubscriptionNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
SELECT ns.*
|
SELECT ns.*
|
||||||
from NewsletterSubscriptions ns
|
from NewsletterSubscriptions ns
|
||||||
|
@ -141,7 +145,7 @@ class NewsletterSubscription extends PropertiesBase{
|
||||||
', [$uuid], 'NewsletterSubscription');
|
', [$uuid], 'NewsletterSubscription');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidNewsletterSubscriptionException();
|
throw new Exceptions\NewsletterSubscriptionNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Payment extends PropertiesBase{
|
||||||
where UserId = ?
|
where UserId = ?
|
||||||
', [$this->User->Name, $this->User->UserId]);
|
', [$this->User->Name, $this->User->UserId]);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidUserException){
|
catch(Exceptions\UserNotFoundException){
|
||||||
// User doesn't exist, create it now
|
// User doesn't exist, create it now
|
||||||
$this->User->Create();
|
$this->User->Create();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ class Poll extends PropertiesBase{
|
||||||
|
|
||||||
public static function Get(?int $pollId): Poll{
|
public static function Get(?int $pollId): Poll{
|
||||||
if($pollId === null){
|
if($pollId === null){
|
||||||
throw new Exceptions\InvalidPollException();
|
throw new Exceptions\PollNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
|
@ -110,7 +110,7 @@ class Poll extends PropertiesBase{
|
||||||
', [$pollId], 'Poll');
|
', [$pollId], 'Poll');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidPollException();
|
throw new Exceptions\PollNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
@ -118,7 +118,7 @@ class Poll extends PropertiesBase{
|
||||||
|
|
||||||
public static function GetByUrlName(?string $urlName): Poll{
|
public static function GetByUrlName(?string $urlName): Poll{
|
||||||
if($urlName === null){
|
if($urlName === null){
|
||||||
throw new Exceptions\InvalidPollException();
|
throw new Exceptions\PollNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
|
@ -128,7 +128,7 @@ class Poll extends PropertiesBase{
|
||||||
', [$urlName], 'Poll');
|
', [$urlName], 'Poll');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidPollException();
|
throw new Exceptions\PollNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
|
|
@ -36,7 +36,7 @@ class PollItem extends PropertiesBase{
|
||||||
|
|
||||||
public static function Get(?int $pollItemId): PollItem{
|
public static function Get(?int $pollItemId): PollItem{
|
||||||
if($pollItemId === null ){
|
if($pollItemId === null ){
|
||||||
throw new Exceptions\InvalidPollItemException();
|
throw new Exceptions\PollItemNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
|
@ -46,7 +46,7 @@ class PollItem extends PropertiesBase{
|
||||||
', [$pollItemId], 'PollItem');
|
', [$pollItemId], 'PollItem');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidPollItemException();
|
throw new Exceptions\PollItemNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
|
|
@ -36,7 +36,7 @@ class PollVote extends PropertiesBase{
|
||||||
$error = new Exceptions\ValidationException();
|
$error = new Exceptions\ValidationException();
|
||||||
|
|
||||||
if($this->User === null){
|
if($this->User === null){
|
||||||
$error->Add(new Exceptions\InvalidUserException());
|
$error->Add(new Exceptions\UserNotFoundException());
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->PollItemId === null){
|
if($this->PollItemId === null){
|
||||||
|
@ -44,11 +44,11 @@ class PollVote extends PropertiesBase{
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if($this->PollItem === null){
|
if($this->PollItem === null){
|
||||||
$error->Add(new Exceptions\InvalidPollException());
|
$error->Add(new Exceptions\PollNotFoundException());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if($this->PollItem->Poll === null){
|
if($this->PollItem->Poll === null){
|
||||||
$error->Add(new Exceptions\InvalidPollException());
|
$error->Add(new Exceptions\PollNotFoundException());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(!$this->PollItem->Poll->IsActive()){
|
if(!$this->PollItem->Poll->IsActive()){
|
||||||
|
@ -67,7 +67,7 @@ class PollVote extends PropertiesBase{
|
||||||
$vote = PollVote::Get($this->PollItem->Poll->UrlName, $this->UserId);
|
$vote = PollVote::Get($this->PollItem->Poll->UrlName, $this->UserId);
|
||||||
$error->Add(new Exceptions\PollVoteExistsException($vote));
|
$error->Add(new Exceptions\PollVoteExistsException($vote));
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidPollVoteException){
|
catch(Exceptions\PollVoteNotFoundException){
|
||||||
// User hasn't voted yet, carry on
|
// User hasn't voted yet, carry on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class PollVote extends PropertiesBase{
|
||||||
$this->User = User::GetByEmail($email);
|
$this->User = User::GetByEmail($email);
|
||||||
$this->UserId = $this->User->UserId;
|
$this->UserId = $this->User->UserId;
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidUserException){
|
catch(Exceptions\UserNotFoundException){
|
||||||
// Can't validate patron email - do nothing for now,
|
// Can't validate patron email - do nothing for now,
|
||||||
// this will be caught later when we validate the vote during creation.
|
// this will be caught later when we validate the vote during creation.
|
||||||
// Save the email in the User object in case we want it later,
|
// Save the email in the User object in case we want it later,
|
||||||
|
@ -109,7 +109,7 @@ class PollVote extends PropertiesBase{
|
||||||
|
|
||||||
public static function Get(?string $pollUrlName, ?int $userId): PollVote{
|
public static function Get(?string $pollUrlName, ?int $userId): PollVote{
|
||||||
if($pollUrlName === null || $userId === null){
|
if($pollUrlName === null || $userId === null){
|
||||||
throw new Exceptions\InvalidPollVoteException();
|
throw new Exceptions\PollVoteNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
|
@ -124,7 +124,7 @@ class PollVote extends PropertiesBase{
|
||||||
', [$pollUrlName, $userId], 'PollVote');
|
', [$pollUrlName, $userId], 'PollVote');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidPollVoteException();
|
throw new Exceptions\PollVoteNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
|
|
@ -64,7 +64,7 @@ class Session extends PropertiesBase{
|
||||||
|
|
||||||
self::SetSessionCookie($this->SessionId);
|
self::SetSessionCookie($this->SessionId);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidUserException){
|
catch(Exceptions\UserNotFoundException){
|
||||||
throw new InvalidLoginException();
|
throw new InvalidLoginException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ class Session extends PropertiesBase{
|
||||||
|
|
||||||
public static function Get(?string $sessionId): Session{
|
public static function Get(?string $sessionId): Session{
|
||||||
if($sessionId === null){
|
if($sessionId === null){
|
||||||
throw new Exceptions\InvalidSessionException();
|
throw new Exceptions\SessionNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
|
@ -105,7 +105,7 @@ class Session extends PropertiesBase{
|
||||||
', [$sessionId], 'Session');
|
', [$sessionId], 'Session');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidSessionException();
|
throw new Exceptions\SessionNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
|
14
lib/User.php
14
lib/User.php
|
@ -115,7 +115,7 @@ class User extends PropertiesBase{
|
||||||
|
|
||||||
public static function Get(?int $userId): User{
|
public static function Get(?int $userId): User{
|
||||||
if($userId === null){
|
if($userId === null){
|
||||||
throw new Exceptions\InvalidUserException();
|
throw new Exceptions\UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
|
@ -125,7 +125,7 @@ class User extends PropertiesBase{
|
||||||
', [$userId], 'User');
|
', [$userId], 'User');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidUserException();
|
throw new Exceptions\UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
@ -133,7 +133,7 @@ class User extends PropertiesBase{
|
||||||
|
|
||||||
public static function GetByEmail(?string $email): User{
|
public static function GetByEmail(?string $email): User{
|
||||||
if($email === null){
|
if($email === null){
|
||||||
throw new Exceptions\InvalidUserException();
|
throw new Exceptions\UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
|
@ -143,7 +143,7 @@ class User extends PropertiesBase{
|
||||||
', [$email], 'User');
|
', [$email], 'User');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidUserException();
|
throw new Exceptions\UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
@ -154,7 +154,7 @@ class User extends PropertiesBase{
|
||||||
// Emails without that row may only be signed up for the newsletter and thus are not "registered" users
|
// Emails without that row may only be signed up for the newsletter and thus are not "registered" users
|
||||||
// The identifier is either an email or a UUID (api key)
|
// The identifier is either an email or a UUID (api key)
|
||||||
if($identifier === null){
|
if($identifier === null){
|
||||||
throw new Exceptions\InvalidUserException();
|
throw new Exceptions\UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
|
@ -166,7 +166,7 @@ class User extends PropertiesBase{
|
||||||
', [$identifier, $identifier], 'User');
|
', [$identifier, $identifier], 'User');
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\InvalidUserException();
|
throw new Exceptions\UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($result[0]->PasswordHash !== null && $password === null){
|
if($result[0]->PasswordHash !== null && $password === null){
|
||||||
|
@ -175,7 +175,7 @@ class User extends PropertiesBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
if($result[0]->PasswordHash !== null && !password_verify($password ?? '', $result[0]->PasswordHash)){
|
if($result[0]->PasswordHash !== null && !password_verify($password ?? '', $result[0]->PasswordHash)){
|
||||||
throw new Exceptions\InvalidUserException();
|
throw new Exceptions\UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
|
|
@ -13,7 +13,7 @@ try{
|
||||||
}
|
}
|
||||||
|
|
||||||
if($artwork === null){
|
if($artwork === null){
|
||||||
$artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name', false) ?? '', HttpInput::Str(GET, 'artwork-url-name', false) ?? '');
|
$artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name'), HttpInput::Str(GET, 'artwork-url-name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$artwork->CanBeEditedBy($GLOBALS['User'])){
|
if(!$artwork->CanBeEditedBy($GLOBALS['User'])){
|
||||||
|
|
|
@ -3,11 +3,11 @@ use function Safe\session_unset;
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
$saved = HttpInput::Bool(SESSION, 'artwork-saved', false);
|
$saved = HttpInput::Bool(SESSION, 'artwork-saved') ?? false;
|
||||||
$exception = $_SESSION['exception'] ?? null;
|
$exception = $_SESSION['exception'] ?? null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name') ?? '', HttpInput::Str(GET, 'artwork-url-name') ?? '');
|
$artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name'), HttpInput::Str(GET, 'artwork-url-name'));
|
||||||
$isAdminView = $GLOBALS['User']->Benefits->CanReviewArtwork ?? false;
|
$isAdminView = $GLOBALS['User']->Benefits->CanReviewArtwork ?? false;
|
||||||
|
|
||||||
// If the artwork is not approved, and we're not an admin or the submitter when they can edit, don't show it.
|
// If the artwork is not approved, and we're not an admin or the submitter when they can edit, don't show it.
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?
|
<?
|
||||||
$page = HttpInput::Int(GET, 'page') ?? 1;
|
$page = HttpInput::Int(GET, 'page') ?? 1;
|
||||||
$perPage = HttpInput::Int(GET, 'per-page') ?? ARTWORK_PER_PAGE;
|
$perPage = HttpInput::Int(GET, 'per-page') ?? ARTWORK_PER_PAGE;
|
||||||
$query = HttpInput::Str(GET, 'query', false) ?? '';
|
$query = HttpInput::Str(GET, 'query') ?? '';
|
||||||
$status = HttpInput::Str(GET, 'status', false) ?? null;
|
$status = HttpInput::Str(GET, 'status') ?? null;
|
||||||
$filterArtworkStatus = $status;
|
$filterArtworkStatus = $status;
|
||||||
$sort = HttpInput::Str(GET, 'sort', false);
|
$sort = HttpInput::Str(GET, 'sort');
|
||||||
$pages = 0;
|
$pages = 0;
|
||||||
$totalArtworkCount = 0;
|
$totalArtworkCount = 0;
|
||||||
$pageDescription = '';
|
$pageDescription = '';
|
||||||
|
|
|
@ -3,7 +3,7 @@ use function Safe\session_unset;
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
$created = HttpInput::Bool(SESSION, 'artwork-created', false);
|
$created = HttpInput::Bool(SESSION, 'artwork-created') ?? false;
|
||||||
$exception = $_SESSION['exception'] ?? null;
|
$exception = $_SESSION['exception'] ?? null;
|
||||||
/** @var Artwork $artwork */
|
/** @var Artwork $artwork */
|
||||||
$artwork = $_SESSION['artwork'] ?? null;
|
$artwork = $_SESSION['artwork'] ?? null;
|
||||||
|
|
|
@ -52,7 +52,7 @@ try{
|
||||||
|
|
||||||
// PUTing an artwork
|
// PUTing an artwork
|
||||||
if($httpMethod == HTTP_PUT){
|
if($httpMethod == HTTP_PUT){
|
||||||
$originalArtwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name', false), HttpInput::Str(GET, 'artwork-url-name', false));
|
$originalArtwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name'), HttpInput::Str(GET, 'artwork-url-name'));
|
||||||
|
|
||||||
if(!$originalArtwork->CanBeEditedBy($GLOBALS['User'])){
|
if(!$originalArtwork->CanBeEditedBy($GLOBALS['User'])){
|
||||||
throw new Exceptions\InvalidPermissionsException();
|
throw new Exceptions\InvalidPermissionsException();
|
||||||
|
@ -65,7 +65,7 @@ try{
|
||||||
$artwork->Created = $originalArtwork->Created;
|
$artwork->Created = $originalArtwork->Created;
|
||||||
$artwork->SubmitterUserId = $originalArtwork->SubmitterUserId;
|
$artwork->SubmitterUserId = $originalArtwork->SubmitterUserId;
|
||||||
|
|
||||||
$newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status', false) ?? '');
|
$newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '');
|
||||||
if($newStatus !== null){
|
if($newStatus !== null){
|
||||||
if($originalArtwork->Status != $newStatus && !$originalArtwork->CanStatusBeChangedBy($GLOBALS['User'])){
|
if($originalArtwork->Status != $newStatus && !$originalArtwork->CanStatusBeChangedBy($GLOBALS['User'])){
|
||||||
throw new Exceptions\InvalidPermissionsException();
|
throw new Exceptions\InvalidPermissionsException();
|
||||||
|
@ -97,13 +97,13 @@ try{
|
||||||
|
|
||||||
// PATCHing a new artwork
|
// PATCHing a new artwork
|
||||||
if($httpMethod == HTTP_PATCH){
|
if($httpMethod == HTTP_PATCH){
|
||||||
$artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name', false), HttpInput::Str(GET, 'artwork-url-name', false));
|
$artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name'), HttpInput::Str(GET, 'artwork-url-name'));
|
||||||
|
|
||||||
$exceptionRedirectUrl = $artwork->Url;
|
$exceptionRedirectUrl = $artwork->Url;
|
||||||
|
|
||||||
// We can PATCH the status, the ebook www filesystem path, or both.
|
// We can PATCH the status, the ebook www filesystem path, or both.
|
||||||
|
|
||||||
$newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status', false) ?? '');
|
$newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '');
|
||||||
if($newStatus !== null){
|
if($newStatus !== null){
|
||||||
if($artwork->Status != $newStatus && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){
|
if($artwork->Status != $newStatus && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){
|
||||||
throw new Exceptions\InvalidPermissionsException();
|
throw new Exceptions\InvalidPermissionsException();
|
||||||
|
@ -112,7 +112,7 @@ try{
|
||||||
$artwork->ReviewerUserId = $GLOBALS['User']->UserId;
|
$artwork->ReviewerUserId = $GLOBALS['User']->UserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newEbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path', false) ?? null;
|
$newEbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path') ?? null;
|
||||||
if($artwork->EbookWwwFilesystemPath != $newEbookWwwFilesystemPath && !$artwork->CanEbookWwwFilesysemPathBeChangedBy($GLOBALS['User'])){
|
if($artwork->EbookWwwFilesystemPath != $newEbookWwwFilesystemPath && !$artwork->CanEbookWwwFilesysemPathBeChangedBy($GLOBALS['User'])){
|
||||||
throw new Exceptions\InvalidPermissionsException();
|
throw new Exceptions\InvalidPermissionsException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use function Safe\apcu_fetch;
|
||||||
use function Safe\preg_replace;
|
use function Safe\preg_replace;
|
||||||
|
|
||||||
$canDownload = false;
|
$canDownload = false;
|
||||||
$class = HttpInput::Str(GET, 'class', false) ?? '';
|
$class = HttpInput::Str(GET, 'class');
|
||||||
|
|
||||||
if($class != 'authors' && $class != 'collections' && $class != 'subjects' && $class != 'months'){
|
if($class != 'authors' && $class != 'collections' && $class != 'subjects' && $class != 'months'){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?
|
<?
|
||||||
use function Safe\preg_match;
|
use function Safe\preg_match;
|
||||||
|
|
||||||
$path = HttpInput::Str(GET, 'path', false) ?? '';
|
$path = HttpInput::Str(GET, 'path') ?? '';
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$path = '/bulk-downloads/' . $path;
|
$path = '/bulk-downloads/' . $path;
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
use function Safe\apcu_fetch;
|
use function Safe\apcu_fetch;
|
||||||
|
|
||||||
$collection = null;
|
$collection = null;
|
||||||
$collectionUrlName = HttpInput::Str(GET, 'collection', false);
|
$collectionUrlName = HttpInput::Str(GET, 'collection');
|
||||||
$collection = null;
|
$collection = null;
|
||||||
$authorUrlName = HttpInput::Str(GET, 'author', false);
|
$authorUrlName = HttpInput::Str(GET, 'author');
|
||||||
$canDownload = false;
|
$canDownload = false;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
@ -32,7 +32,7 @@ try{
|
||||||
}
|
}
|
||||||
|
|
||||||
if($collection === null){
|
if($collection === null){
|
||||||
throw new Exceptions\InvalidCollectionException();
|
throw new Exceptions\CollectionNotFoundException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,14 +56,14 @@ try{
|
||||||
}
|
}
|
||||||
|
|
||||||
if($collection === null){
|
if($collection === null){
|
||||||
throw new Exceptions\InvalidAuthorException();
|
throw new Exceptions\AuthorNotFoundException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidAuthorException){
|
catch(Exceptions\AuthorNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidCollectionException){
|
catch(Exceptions\CollectionNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,24 +4,24 @@ $author = '';
|
||||||
$authorUrl = '';
|
$authorUrl = '';
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path', true) ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
|
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
|
||||||
$wwwFilesystemPath = EBOOKS_DIST_PATH . $urlPath; // Path to the deployed WWW files for this ebook
|
$wwwFilesystemPath = EBOOKS_DIST_PATH . $urlPath; // Path to the deployed WWW files for this ebook
|
||||||
|
|
||||||
if($urlPath == '' || mb_stripos($wwwFilesystemPath, EBOOKS_DIST_PATH) !== 0 || !is_dir($wwwFilesystemPath)){
|
if($urlPath == '' || mb_stripos($wwwFilesystemPath, EBOOKS_DIST_PATH) !== 0 || !is_dir($wwwFilesystemPath)){
|
||||||
// Ensure the path exists and that the root is in our www directory
|
// Ensure the path exists and that the root is in our www directory
|
||||||
throw new Exceptions\InvalidAuthorException();
|
throw new Exceptions\AuthorNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$ebooks = Library::GetEbooksByAuthor($wwwFilesystemPath);
|
$ebooks = Library::GetEbooksByAuthor($wwwFilesystemPath);
|
||||||
|
|
||||||
if(sizeof($ebooks) == 0){
|
if(sizeof($ebooks) == 0){
|
||||||
throw new Exceptions\InvalidAuthorException();
|
throw new Exceptions\AuthorNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$author = strip_tags($ebooks[0]->AuthorsHtml);
|
$author = strip_tags($ebooks[0]->AuthorsHtml);
|
||||||
$authorUrl = Formatter::EscapeHtml($ebooks[0]->AuthorsUrl);
|
$authorUrl = Formatter::EscapeHtml($ebooks[0]->AuthorsUrl);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidAuthorException){
|
catch(Exceptions\AuthorNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
?><?= Template::Header(['title' => 'Ebooks by ' . $author, 'feedUrl' => str_replace('/ebooks/', '/authors/', $authorUrl), 'feedTitle' => 'Standard Ebooks - Ebooks by ' . $author, 'highlight' => 'ebooks', 'description' => 'All of the Standard Ebooks ebooks by ' . $author]) ?>
|
?><?= Template::Header(['title' => 'Ebooks by ' . $author, 'feedUrl' => str_replace('/ebooks/', '/authors/', $authorUrl), 'feedTitle' => 'Standard Ebooks - Ebooks by ' . $author, 'highlight' => 'ebooks', 'description' => 'All of the Standard Ebooks ebooks by ' . $author]) ?>
|
||||||
|
|
|
@ -14,12 +14,12 @@ $carousel = [];
|
||||||
$carouselTag = null;
|
$carouselTag = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path', true) ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
|
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
|
||||||
$wwwFilesystemPath = EBOOKS_DIST_PATH . $urlPath; // Path to the deployed WWW files for this ebook
|
$wwwFilesystemPath = EBOOKS_DIST_PATH . $urlPath; // Path to the deployed WWW files for this ebook
|
||||||
|
|
||||||
if($urlPath == '' || mb_stripos($wwwFilesystemPath, EBOOKS_DIST_PATH) !== 0){
|
if($urlPath == '' || mb_stripos($wwwFilesystemPath, EBOOKS_DIST_PATH) !== 0){
|
||||||
// Ensure the path exists and that the root is in our www directory
|
// Ensure the path exists and that the root is in our www directory
|
||||||
throw new Exceptions\InvalidEbookException();
|
throw new Exceptions\EbookNotFoundException();
|
||||||
}
|
}
|
||||||
// Were we passed the author and a work but not the translator?
|
// Were we passed the author and a work but not the translator?
|
||||||
// For example:
|
// For example:
|
||||||
|
@ -104,7 +104,7 @@ catch(Exceptions\SeeOtherEbookException $ex){
|
||||||
header('Location: ' . $ex->Url);
|
header('Location: ' . $ex->Url);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidEbookException){
|
catch(Exceptions\EbookNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description]) ?>
|
?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description]) ?>
|
||||||
|
|
|
@ -4,11 +4,11 @@ use function Safe\preg_replace;
|
||||||
try{
|
try{
|
||||||
$page = HttpInput::Int(GET, 'page') ?? 1;
|
$page = HttpInput::Int(GET, 'page') ?? 1;
|
||||||
$perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
|
$perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
|
||||||
$query = HttpInput::Str(GET, 'query', false) ?? '';
|
$query = HttpInput::Str(GET, 'query') ?? '';
|
||||||
$tags = HttpInput::GetArray('tags') ?? [];
|
$tags = HttpInput::GetArray('tags') ?? [];
|
||||||
$collection = HttpInput::Str(GET, 'collection', false);
|
$collection = HttpInput::Str(GET, 'collection');
|
||||||
$view = HttpInput::Str(GET, 'view', false);
|
$view = HttpInput::Str(GET, 'view');
|
||||||
$sort = HttpInput::Str(GET, 'sort', false);
|
$sort = HttpInput::Str(GET, 'sort');
|
||||||
$pages = 0;
|
$pages = 0;
|
||||||
$totalEbooks = 0;
|
$totalEbooks = 0;
|
||||||
$collectionObject = null;
|
$collectionObject = null;
|
||||||
|
@ -71,7 +71,7 @@ try{
|
||||||
$pageHeader = 'Free Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . ucfirst($collectionType);
|
$pageHeader = 'Free Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . ucfirst($collectionType);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
throw new Exceptions\InvalidCollectionException();
|
throw new Exceptions\CollectionNotFoundException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -118,7 +118,7 @@ try{
|
||||||
$feedTitle = 'Standard Ebooks - Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType;
|
$feedTitle = 'Standard Ebooks - Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidCollectionException){
|
catch(Exceptions\CollectionNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
?><?= Template::Header(['title' => $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?>
|
?><?= Template::Header(['title' => $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?>
|
||||||
|
|
|
@ -4,7 +4,7 @@ use Safe\DateTime;
|
||||||
$ebooks = [];
|
$ebooks = [];
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$query = HttpInput::Str(GET, 'query', false) ?? '';
|
$query = HttpInput::Str(GET, 'query') ?? '';
|
||||||
|
|
||||||
if($query !== ''){
|
if($query !== ''){
|
||||||
$ebooks = Library::Search($query);
|
$ebooks = Library::Search($query);
|
||||||
|
|
|
@ -4,8 +4,8 @@ use function Safe\glob;
|
||||||
use function Safe\preg_replace;
|
use function Safe\preg_replace;
|
||||||
use function Safe\usort;
|
use function Safe\usort;
|
||||||
|
|
||||||
$class = HttpInput::Str(GET, 'class', false) ?? '';
|
$class = HttpInput::Str(GET, 'class') ?? '';
|
||||||
$type = HttpInput::Str(GET, 'type', false) ?? '';
|
$type = HttpInput::Str(GET, 'type') ?? '';
|
||||||
|
|
||||||
if($class != 'authors' && $class != 'collections' && $class != 'subjects'){
|
if($class != 'authors' && $class != 'collections' && $class != 'subjects'){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
|
|
|
@ -5,7 +5,7 @@ use function Safe\preg_match;
|
||||||
// Basic authorization is handled in Core.php. By the time we get here,
|
// Basic authorization is handled in Core.php. By the time we get here,
|
||||||
// a valid user has a session.
|
// a valid user has a session.
|
||||||
|
|
||||||
$path = HttpInput::Str(GET, 'path', false) ?? '';
|
$path = HttpInput::Str(GET, 'path') ?? '';
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$path = '/feeds/' . $path;
|
$path = '/feeds/' . $path;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?
|
<?
|
||||||
use function Safe\exec;
|
use function Safe\exec;
|
||||||
|
|
||||||
$author = HttpInput::Str(GET, 'author', false);
|
$author = HttpInput::Str(GET, 'author');
|
||||||
$collection = HttpInput::Str(GET, 'collection', false);
|
$collection = HttpInput::Str(GET, 'collection');
|
||||||
$name = null;
|
$name = null;
|
||||||
$target = null;
|
$target = null;
|
||||||
$feedTypes = ['opds', 'atom', 'rss'];
|
$feedTypes = ['opds', 'atom', 'rss'];
|
||||||
|
@ -24,12 +24,12 @@ if($collection !== null){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if($target === null || $name === null){
|
if($target === null || $name === null){
|
||||||
throw new Exceptions\InvalidCollectionException();
|
throw new Exceptions\CollectionNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = WEB_ROOT . '/feeds/opds/' . $name . '/' . $target . '.xml';
|
$file = WEB_ROOT . '/feeds/opds/' . $name . '/' . $target . '.xml';
|
||||||
if(!is_file($file)){
|
if(!is_file($file)){
|
||||||
throw new Exceptions\InvalidCollectionException();
|
throw new Exceptions\CollectionNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$label = exec('attr -g se-label ' . escapeshellarg($file)) ?: basename($file, '.xml');
|
$label = exec('attr -g se-label ' . escapeshellarg($file)) ?: basename($file, '.xml');
|
||||||
|
@ -48,7 +48,7 @@ try{
|
||||||
|
|
||||||
$feedUrl = '/' . $name . '/' . $target;
|
$feedUrl = '/' . $name . '/' . $target;
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidCollectionException){
|
catch(Exceptions\CollectionNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
?><?= Template::Header(['title' => $title, 'feedTitle' => $feedTitle, 'feedUrl' => $feedUrl, 'description' => $description]) ?>
|
?><?= Template::Header(['title' => $title, 'feedTitle' => $feedTitle, 'feedUrl' => $feedUrl, 'description' => $description]) ?>
|
||||||
|
|
|
@ -4,7 +4,7 @@ use Safe\DateTime;
|
||||||
$ebooks = [];
|
$ebooks = [];
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$query = HttpInput::Str(GET, 'query', false) ?? '';
|
$query = HttpInput::Str(GET, 'query') ?? '';
|
||||||
|
|
||||||
if($query !== ''){
|
if($query !== ''){
|
||||||
$ebooks = Library::Search($query);
|
$ebooks = Library::Search($query);
|
||||||
|
|
|
@ -4,7 +4,7 @@ use Safe\DateTime;
|
||||||
$ebooks = [];
|
$ebooks = [];
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$query = HttpInput::Str(GET, 'query', false) ?? '';
|
$query = HttpInput::Str(GET, 'query') ?? '';
|
||||||
|
|
||||||
if($query !== ''){
|
if($query !== ''){
|
||||||
$ebooks = Library::Search($query);
|
$ebooks = Library::Search($query);
|
||||||
|
|
|
@ -7,7 +7,7 @@ use function Safe\sort;
|
||||||
|
|
||||||
$currentManual = Manual::GetLatestVersion();
|
$currentManual = Manual::GetLatestVersion();
|
||||||
|
|
||||||
$url = HttpInput::Str(GET, 'url', true) ?? '';
|
$url = HttpInput::Str(GET, 'url') ?? '';
|
||||||
$url = preg_replace('|^/|ius', '', $url);
|
$url = preg_replace('|^/|ius', '', $url);
|
||||||
$url = preg_replace('|\.php$|ius', '', $url);
|
$url = preg_replace('|\.php$|ius', '', $url);
|
||||||
$url = preg_replace('|/$|ius', '', $url);
|
$url = preg_replace('|/$|ius', '', $url);
|
||||||
|
|
|
@ -4,7 +4,7 @@ session_start();
|
||||||
$subscription = new NewsletterSubscription();
|
$subscription = new NewsletterSubscription();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid') ?? '');
|
$subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid'));
|
||||||
|
|
||||||
if(!$subscription->IsConfirmed){
|
if(!$subscription->IsConfirmed){
|
||||||
$subscription->Confirm();
|
$subscription->Confirm();
|
||||||
|
@ -14,6 +14,6 @@ try{
|
||||||
http_response_code(303);
|
http_response_code(303);
|
||||||
header('Location: ' . $subscription->Url);
|
header('Location: ' . $subscription->Url);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidNewsletterSubscriptionException){
|
catch(Exceptions\NewsletterSubscriptionNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ try{
|
||||||
throw new Exceptions\InvalidRequestException();
|
throw new Exceptions\InvalidRequestException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid') ?? '');
|
$subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid'));
|
||||||
$subscription->Delete();
|
$subscription->Delete();
|
||||||
|
|
||||||
if($requestType == REST){
|
if($requestType == REST){
|
||||||
|
@ -20,7 +20,7 @@ catch(Exceptions\InvalidRequestException){
|
||||||
http_response_code(405);
|
http_response_code(405);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidNewsletterSubscriptionException){
|
catch(Exceptions\NewsletterSubscriptionNotFoundException){
|
||||||
if($requestType == WEB){
|
if($requestType == WEB){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ try{
|
||||||
$created = true;
|
$created = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid', false) ?? '');
|
$subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid'));
|
||||||
|
|
||||||
if(isset($_SESSION['subscription-created']) && $_SESSION['subscription-created'] == $subscription->UserId){
|
if(isset($_SESSION['subscription-created']) && $_SESSION['subscription-created'] == $subscription->UserId){
|
||||||
$created = true;
|
$created = true;
|
||||||
|
|
|
@ -13,7 +13,7 @@ $requestType = HttpInput::RequestType();
|
||||||
|
|
||||||
$subscription = new NewsletterSubscription();
|
$subscription = new NewsletterSubscription();
|
||||||
|
|
||||||
if(HttpInput::Str(POST, 'automationtest', false)){
|
if(HttpInput::Str(POST, 'automationtest')){
|
||||||
// A bot filled out this form field, which should always be empty. Pretend like we succeeded.
|
// A bot filled out this form field, which should always be empty. Pretend like we succeeded.
|
||||||
if($requestType == WEB){
|
if($requestType == WEB){
|
||||||
http_response_code(303);
|
http_response_code(303);
|
||||||
|
@ -34,11 +34,11 @@ if(HttpInput::Str(POST, 'automationtest', false)){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$subscription->User = new User();
|
$subscription->User = new User();
|
||||||
$subscription->User->Email = HttpInput::Str(POST, 'email', false);
|
$subscription->User->Email = HttpInput::Str(POST, 'email');
|
||||||
$subscription->IsSubscribedToNewsletter = HttpInput::Bool(POST, 'issubscribedtonewsletter') ?? false;
|
$subscription->IsSubscribedToNewsletter = HttpInput::Bool(POST, 'issubscribedtonewsletter') ?? false;
|
||||||
$subscription->IsSubscribedToSummary = HttpInput::Bool(POST, 'issubscribedtosummary') ?? false;
|
$subscription->IsSubscribedToSummary = HttpInput::Bool(POST, 'issubscribedtosummary') ?? false;
|
||||||
|
|
||||||
$captcha = HttpInput::Str(SESSION, 'captcha', false) ?? '';
|
$captcha = HttpInput::Str(SESSION, 'captcha') ?? '';
|
||||||
|
|
||||||
$exception = new Exceptions\ValidationException();
|
$exception = new Exceptions\ValidationException();
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ try{
|
||||||
$exception->Add($ex);
|
$exception->Add($ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($captcha === '' || mb_strtolower($captcha) !== mb_strtolower(HttpInput::Str(POST, 'captcha', false) ?? '')){
|
if($captcha === '' || mb_strtolower($captcha) !== mb_strtolower(HttpInput::Str(POST, 'captcha') ?? '')){
|
||||||
$exception->Add(new Exceptions\InvalidCaptchaException());
|
$exception->Add(new Exceptions\InvalidCaptchaException());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ $poll = new Poll();
|
||||||
$canVote = true; // Allow non-logged-in users to see the 'vote' button
|
$canVote = true; // Allow non-logged-in users to see the 'vote' button
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false));
|
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname'));
|
||||||
|
|
||||||
if(!$poll->IsActive() && $poll->End !== null && $poll->End < new DateTime()){
|
if(!$poll->IsActive() && $poll->End !== null && $poll->End < new DateTime()){
|
||||||
// If the poll ended, redirect to the results
|
// If the poll ended, redirect to the results
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
$poll = new Poll();
|
$poll = new Poll();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false));
|
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname'));
|
||||||
}
|
}
|
||||||
catch(Exceptions\AppException){
|
catch(Exceptions\AppException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
|
|
|
@ -19,7 +19,7 @@ try{
|
||||||
$vote->User = $GLOBALS['User'];
|
$vote->User = $GLOBALS['User'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false));
|
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname'));
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$vote = PollVote::Get($poll->UrlName, $GLOBALS['User']->UserId);
|
$vote = PollVote::Get($poll->UrlName, $GLOBALS['User']->UserId);
|
||||||
|
@ -27,7 +27,7 @@ try{
|
||||||
// Vote was found, don't allow another vote
|
// Vote was found, don't allow another vote
|
||||||
throw new Exceptions\PollVoteExistsException($vote);
|
throw new Exceptions\PollVoteExistsException($vote);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidPollVoteException){
|
catch(Exceptions\PollVoteNotFoundException){
|
||||||
// Vote was not found, user is OK to vote
|
// Vote was not found, user is OK to vote
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ try{
|
||||||
catch(Exceptions\LoginRequiredException){
|
catch(Exceptions\LoginRequiredException){
|
||||||
Template::RedirectToLogin();
|
Template::RedirectToLogin();
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidPollException){
|
catch(Exceptions\PollNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
catch(Exceptions\PollVoteExistsException $ex){
|
catch(Exceptions\PollVoteExistsException $ex){
|
||||||
|
|
|
@ -15,7 +15,7 @@ $vote = new PollVote();
|
||||||
try{
|
try{
|
||||||
$vote->PollItemId = HttpInput::Int(POST, 'pollitemid');
|
$vote->PollItemId = HttpInput::Int(POST, 'pollitemid');
|
||||||
|
|
||||||
$vote->Create(HttpInput::Str(POST, 'email', false));
|
$vote->Create(HttpInput::Str(POST, 'email'));
|
||||||
|
|
||||||
session_unset();
|
session_unset();
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ catch(Exceptions\AppException $ex){
|
||||||
|
|
||||||
// Access via form; 303 redirect to the form, which will emit a 422 Unprocessable Entity
|
// Access via form; 303 redirect to the form, which will emit a 422 Unprocessable Entity
|
||||||
http_response_code(303);
|
http_response_code(303);
|
||||||
header('Location: /polls/' . HttpInput::Str(GET, 'pollurlname', false) . '/votes/new');
|
header('Location: /polls/' . (HttpInput::Str(GET, 'pollurlname') ?? '') . '/votes/new');
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Access via REST api; 422 Unprocessable Entity
|
// Access via REST api; 422 Unprocessable Entity
|
||||||
|
|
|
@ -8,8 +8,8 @@ if($GLOBALS['User'] !== null){
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$email = HttpInput::Str(SESSION, 'email', false);
|
$email = HttpInput::Str(SESSION, 'email');
|
||||||
$redirect = HttpInput::Str(SESSION, 'redirect', false) ?? HttpInput::Str(GET, 'redirect', false);
|
$redirect = HttpInput::Str(SESSION, 'redirect') ?? HttpInput::Str(GET, 'redirect');
|
||||||
|
|
||||||
$exception = $_SESSION['exception'] ?? null;
|
$exception = $_SESSION['exception'] ?? null;
|
||||||
$passwordRequired = false;
|
$passwordRequired = false;
|
||||||
|
|
|
@ -12,9 +12,9 @@ session_start();
|
||||||
$requestType = HttpInput::RequestType();
|
$requestType = HttpInput::RequestType();
|
||||||
|
|
||||||
$session = new Session();
|
$session = new Session();
|
||||||
$email = HttpInput::Str(POST, 'email', false);
|
$email = HttpInput::Str(POST, 'email');
|
||||||
$password = HttpInput::Str(POST, 'password', false);
|
$password = HttpInput::Str(POST, 'password');
|
||||||
$redirect = HttpInput::Str(POST, 'redirect', false);
|
$redirect = HttpInput::Str(POST, 'redirect');
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if($redirect === null){
|
if($redirect === null){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue