forked from standardebooks/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add newsletter management functionality
- Loading branch information
Showing
57 changed files
with
1,017 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CREATE TABLE `NewsletterSubscribers` ( | ||
`NewsletterSubscriberId` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`Email` varchar(80) NOT NULL, | ||
`Uuid` char(36) NOT NULL, | ||
`FirstName` varchar(80) DEFAULT NULL, | ||
`LastName` varchar(80) DEFAULT NULL, | ||
`IsConfirmed` tinyint(1) unsigned NOT NULL DEFAULT 0, | ||
`IsSubscribedToNewsletter` tinyint(1) unsigned NOT NULL DEFAULT 1, | ||
`IsSubscribedToSummary` tinyint(1) unsigned NOT NULL DEFAULT 1, | ||
`Timestamp` datetime NOT NULL, | ||
PRIMARY KEY (`NewsletterSubscriberId`), | ||
UNIQUE KEY `Uuid_UNIQUE` (`Uuid`), | ||
UNIQUE KEY `Email_UNIQUE` (`Email`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
<? | ||
// Auto-included by Composer in composer.json to satisfy PHPStan | ||
use function Safe\define; | ||
use function Safe\file_get_contents; | ||
use function Safe\gmdate; | ||
use function Safe\strtotime; | ||
|
||
const SITE_STATUS_LIVE = 'live'; | ||
const SITE_STATUS_DEV = 'dev'; | ||
define('SITE_STATUS', getenv('SITE_STATUS') ?: SITE_STATUS_DEV); // Set in the PHP FPM pool configuration. Have to use define() and not const so we can use a function. | ||
|
||
// No trailing slash on any of the below constants. | ||
if(SITE_STATUS == SITE_STATUS_LIVE){ | ||
define('SITE_URL', 'https://standardebooks.org'); | ||
} | ||
else{ | ||
define('SITE_URL', 'https://standardebooks.test'); | ||
} | ||
|
||
const SITE_ROOT = '/standardebooks.org'; | ||
const WEB_ROOT = SITE_ROOT . '/web/www'; | ||
const REPOS_PATH = SITE_ROOT . '/ebooks'; | ||
const TEMPLATES_PATH = SITE_ROOT . '/web/templates'; | ||
const MANUAL_PATH = WEB_ROOT . '/manual'; | ||
const EBOOKS_DIST_PATH = WEB_ROOT . '/ebooks/'; | ||
|
||
const DATABASE_DEFAULT_DATABASE = 'se'; | ||
const DATABASE_DEFAULT_HOST = 'localhost'; | ||
|
||
|
@@ -16,9 +33,21 @@ | |
const SORT_READING_EASE = 'reading-ease'; | ||
const SORT_LENGTH = 'length'; | ||
|
||
const GET = 0; | ||
const POST = 1; | ||
const COOKIE = 2; | ||
const CAPTCHA_IMAGE_HEIGHT = 72; | ||
const CAPTCHA_IMAGE_WIDTH = 230; | ||
|
||
const NO_REPLY_EMAIL_ADDRESS = '[email protected]'; | ||
const EMAIL_SMTP_HOST = 'smtp-broadcasts.postmarkapp.com'; | ||
define('EMAIL_SMTP_USERNAME', trim(file_get_contents(SITE_ROOT . '/config/secrets/postmarkapp.com')) ?: ''); | ||
const EMAIL_SMTP_PASSWORD = EMAIL_SMTP_USERNAME; | ||
const EMAIL_POSTMARK_STREAM_BROADCAST = 'the-standard-ebooks-newsletter'; | ||
|
||
const REST = 0; | ||
const WEB = 1; | ||
|
||
const GET = 'GET'; | ||
const POST = 'POST'; | ||
const COOKIE = 'COOKIE'; | ||
|
||
const HTTP_VAR_INT = 0; | ||
const HTTP_VAR_STR = 1; | ||
|
@@ -47,17 +76,8 @@ | |
define('DONATION_ALERT_ON', DONATION_HOLIDAY_ALERT_ON || rand(1, 4) == 2); | ||
define('DONATION_DRIVE_ON', false); | ||
|
||
// No trailing slash on any of the below constants. | ||
const SITE_URL = 'https://standardebooks.org'; | ||
const SITE_ROOT = '/standardebooks.org'; | ||
const WEB_ROOT = SITE_ROOT . '/web/www'; | ||
const REPOS_PATH = SITE_ROOT . '/ebooks'; | ||
const TEMPLATES_PATH = SITE_ROOT . '/web/templates'; | ||
const MANUAL_PATH = WEB_ROOT . '/manual'; | ||
const EBOOKS_DIST_PATH = WEB_ROOT . '/ebooks/'; | ||
|
||
const GITHUB_SECRET_FILE_PATH = SITE_ROOT . '/config/secrets/[email protected]'; // Set in the GitHub organization global webhook settings. | ||
const GITHUB_WEBHOOK_LOG_FILE_PATH = '/var/log/local/webhooks-github.log'; // Must be writable by `www-data` Unix user. | ||
const GITHUB_IGNORED_REPOS = ['tools', 'manual', 'web']; // If we get GitHub push requests featuring these repos, silently ignore instead of returning an error. | ||
|
||
// If we get GitHub push requests featuring these repos, silently ignore instead of returning an error. | ||
const GITHUB_IGNORED_REPOS = ['tools', 'manual', 'web']; | ||
const POSTMARK_WEBHOOK_LOG_FILE_PATH = '/var/log/local/webhooks-postmark.log'; // Must be writable by `www-data` Unix user. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<? | ||
use PHPMailer\PHPMailer\PHPMailer; | ||
use PHPMailer\PHPMailer\Exception; | ||
|
||
class Email{ | ||
public $To = ''; | ||
public $From = ''; | ||
public $FromName = ''; | ||
public $ReplyTo = ''; | ||
public $Subject = ''; | ||
public $Body = ''; | ||
public $TextBody = ''; | ||
public $Attachments = array(); | ||
public $PostmarkStream = null; | ||
|
||
public function Send(): bool{ | ||
if($this->ReplyTo == ''){ | ||
$this->ReplyTo = $this->From; | ||
} | ||
|
||
if($this->To === null || $this->To == ''){ | ||
return false; | ||
} | ||
|
||
$phpMailer = new PHPMailer(true); | ||
|
||
try{ | ||
$phpMailer->SetFrom($this->From, $this->FromName); | ||
$phpMailer->AddReplyTo($this->ReplyTo); | ||
$phpMailer->AddAddress($this->To); | ||
$phpMailer->Subject = $this->Subject; | ||
$phpMailer->CharSet = 'UTF-8'; | ||
if($this->TextBody !== null && $this->TextBody != ''){ | ||
$phpMailer->IsHTML(true); | ||
$phpMailer->Body = $this->Body; | ||
$phpMailer->AltBody = $this->TextBody; | ||
} | ||
else{ | ||
$phpMailer->MsgHTML($this->Body); | ||
} | ||
|
||
foreach($this->Attachments as $attachment){ | ||
if(is_array($attachment)){ | ||
$phpMailer->addStringAttachment($attachment['contents'], $attachment['filename']); | ||
} | ||
} | ||
|
||
$phpMailer->IsSMTP(); | ||
$phpMailer->SMTPAuth = true; | ||
$phpMailer->SMTPSecure = 'tls'; | ||
$phpMailer->Port = 587; | ||
$phpMailer->Host = EMAIL_SMTP_HOST; | ||
$phpMailer->Username = EMAIL_SMTP_USERNAME; | ||
$phpMailer->Password = EMAIL_SMTP_PASSWORD; | ||
|
||
if($this->PostmarkStream !== null){ | ||
$phpMailer->addCustomHeader('X-PM-Message-Stream', $this->PostmarkStream); | ||
} | ||
|
||
if(SITE_STATUS == SITE_STATUS_DEV){ | ||
Logger::WriteErrorLogEntry('Sending mail to ' . $this->To . ' from ' . $this->From); | ||
Logger::WriteErrorLogEntry('Subject: ' . $this->Subject); | ||
Logger::WriteErrorLogEntry($this->Body); | ||
Logger::WriteErrorLogEntry($this->TextBody); | ||
} | ||
else{ | ||
$phpMailer->Send(); | ||
} | ||
} | ||
catch(Exception $ex){ | ||
if(SITE_STATUS != SITE_STATUS_DEV){ | ||
Logger::WriteErrorLogEntry('Failed sending email to ' . $this->To . ' Exception: ' . $ex->errorMessage() . "\n" . ' Subject: ' . $this->Subject . "\nBody:\n" . $this->Body); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function __construct(bool $isNoReplyEmail = false){ | ||
if($isNoReplyEmail){ | ||
$this->From = NO_REPLY_EMAIL_ADDRESS; | ||
$this->FromName = 'Standard Ebooks'; | ||
$this->ReplyTo = NO_REPLY_EMAIL_ADDRESS; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<? | ||
namespace Exceptions; | ||
|
||
class EbookParsingException extends SeException{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<? | ||
namespace Exceptions; | ||
|
||
class InvalidAuthorException extends SeException{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<? | ||
namespace Exceptions; | ||
|
||
class InvalidCaptchaException extends SeException{ | ||
protected $message = 'We couldn’t validate your CAPTCHA response.'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<? | ||
namespace Exceptions; | ||
|
||
class InvalidCollectionException extends SeException{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<? | ||
namespace Exceptions; | ||
|
||
class InvalidCredentialsException extends SeException{ | ||
protected $message = 'Invalid credentials.'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<? | ||
namespace Exceptions; | ||
|
||
class InvalidEbookException extends SeException{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<? | ||
namespace Exceptions; | ||
|
||
class InvalidEmailException extends SeException{ | ||
protected $message = 'We couldn’t understand your email address.'; | ||
} |
Oops, something went wrong.