From 26a24cdbe2095f3d96703d508f5665cb5ccf57a7 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Sat, 24 Dec 2022 15:44:42 -0600 Subject: [PATCH] Pretty print SQL --- lib/NewsletterSubscription.php | 36 +++++++++++-- lib/Patron.php | 40 +++++++++++--- lib/Payment.php | 17 +++++- lib/Poll.php | 26 ++++++++-- lib/PollItem.php | 13 ++++- lib/PollVote.php | 21 ++++++-- lib/Session.php | 27 ++++++++-- lib/User.php | 41 ++++++++++++--- .../delete-unconfirmed-newsletter-subscribers | 7 ++- scripts/process-pending-payments | 43 ++++++++++++--- scripts/update-patrons-circle | 23 ++++++-- www/about/index.php | 52 ++++++++----------- www/donate/index.php | 6 ++- www/feeds/download.php | 7 ++- www/polls/index.php | 18 ++++++- www/webhooks/postmark.php | 14 ++++- www/webhooks/zoho.php | 7 ++- 17 files changed, 316 insertions(+), 82 deletions(-) diff --git a/lib/NewsletterSubscription.php b/lib/NewsletterSubscription.php index 7e648e8c..34d0ae79 100644 --- a/lib/NewsletterSubscription.php +++ b/lib/NewsletterSubscription.php @@ -47,7 +47,14 @@ class NewsletterSubscription extends PropertiesBase{ $this->Created = new DateTime(); try{ - Db::Query('INSERT into NewsletterSubscriptions (UserId, IsConfirmed, IsSubscribedToNewsletter, IsSubscribedToSummary, Created) values (?, ?, ?, ?, ?);', [$this->User->UserId, false, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary, $this->Created]); + Db::Query(' + INSERT into NewsletterSubscriptions (UserId, IsConfirmed, IsSubscribedToNewsletter, IsSubscribedToSummary, Created) + values (?, + ?, + ?, + ?, + ?) + ', [$this->User->UserId, false, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary, $this->Created]); } catch(PDOException $ex){ if($ex->errorInfo[1] == 1062){ @@ -66,7 +73,13 @@ class NewsletterSubscription extends PropertiesBase{ public function Save(): void{ $this->Validate(); - Db::Query('UPDATE NewsletterSubscriptions set IsConfirmed = ?, IsSubscribedToNewsletter = ?, IsSubscribedToSummary = ? where UserId = ?', [$this->IsConfirmed, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary, $this->UserId]); + Db::Query(' + UPDATE NewsletterSubscriptions + set IsConfirmed = ?, + IsSubscribedToNewsletter = ?, + IsSubscribedToSummary = ? + where UserId = ? + ', [$this->IsConfirmed, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary, $this->UserId]); } public function SendConfirmationEmail(): void{ @@ -83,11 +96,19 @@ class NewsletterSubscription extends PropertiesBase{ } public function Confirm(): void{ - Db::Query('UPDATE NewsletterSubscriptions set IsConfirmed = true where UserId = ?;', [$this->UserId]); + Db::Query(' + UPDATE NewsletterSubscriptions + set IsConfirmed = true + where UserId = ? + ', [$this->UserId]); } public function Delete(): void{ - Db::Query('DELETE from NewsletterSubscriptions where UserId = ?;', [$this->UserId]); + Db::Query(' + DELETE + from NewsletterSubscriptions + where UserId = ? + ', [$this->UserId]); } public function Validate(): void{ @@ -112,7 +133,12 @@ class NewsletterSubscription extends PropertiesBase{ // *********** public static function Get(string $uuid): NewsletterSubscription{ - $result = Db::Query('SELECT ns.* from NewsletterSubscriptions ns inner join Users u using(UserId) where u.Uuid = ?', [$uuid], 'NewsletterSubscription'); + $result = Db::Query(' + SELECT ns.* + from NewsletterSubscriptions ns + inner join Users u using(UserId) + where u.Uuid = ? + ', [$uuid], 'NewsletterSubscription'); if(sizeof($result) == 0){ throw new Exceptions\InvalidNewsletterSubscriptionException(); diff --git a/lib/Patron.php b/lib/Patron.php index f4511b45..9065e9cd 100644 --- a/lib/Patron.php +++ b/lib/Patron.php @@ -20,14 +20,33 @@ class Patron extends PropertiesBase{ public function Create(): void{ $this->Created = new DateTime(); - Db::Query('INSERT into Patrons (Created, UserId, IsAnonymous, AlternateName, IsSubscribedToEmails) values(?, ?, ?, ?, ?);', [$this->Created, $this->UserId, $this->IsAnonymous, $this->AlternateName, $this->IsSubscribedToEmails]); + Db::Query(' + INSERT into Patrons (Created, UserId, IsAnonymous, AlternateName, IsSubscribedToEmails) + values(?, + ?, + ?, + ?, + ?) + ', [$this->Created, $this->UserId, $this->IsAnonymous, $this->AlternateName, $this->IsSubscribedToEmails]); - - Db::Query('INSERT into Benefits (UserId, CanVote, CanAccessFeeds, CanBulkDownload) values (?, true, true, true) on duplicate key update CanVote = true, CanAccessFeeds = true, CanBulkDownload = true', [$this->UserId]); + Db::Query(' + INSERT into Benefits (UserId, CanVote, CanAccessFeeds, CanBulkDownload) + values (?, + true, + true, + true) on duplicate key + update CanVote = true, + CanAccessFeeds = true, + CanBulkDownload = true + ', [$this->UserId]); // If this is a patron for the first time, send the first-time patron email. // Otherwise, send the returning patron email. - $isReturning = Db::QueryInt('SELECT count(*) from Patrons where UserId = ?', [$this->UserId]) > 1; + $isReturning = Db::QueryInt(' + SELECT count(*) + from Patrons + where UserId = ? + ', [$this->UserId]) > 1; $this->SendWelcomeEmail($isReturning); } @@ -60,7 +79,11 @@ class Patron extends PropertiesBase{ // *********** public static function Get(?int $userId): Patron{ - $result = Db::Query('SELECT * from Patrons where UserId = ?', [$userId], 'Patron'); + $result = Db::Query(' + SELECT * + from Patrons + where UserId = ? + ', [$userId], 'Patron'); if(sizeof($result) == 0){ throw new Exceptions\InvalidPatronException(); @@ -70,7 +93,12 @@ class Patron extends PropertiesBase{ } public static function GetByEmail(?string $email): Patron{ - $result = Db::Query('SELECT p.* from Patrons p inner join Users u using(UserId) where u.Email = ?', [$email], 'Patron'); + $result = Db::Query(' + SELECT p.* + from Patrons p + inner join Users u using(UserId) + where u.Email = ? + ', [$email], 'Patron'); if(sizeof($result) == 0){ throw new Exceptions\InvalidPatronException(); diff --git a/lib/Payment.php b/lib/Payment.php index cb4871ba..7ff9e87c 100644 --- a/lib/Payment.php +++ b/lib/Payment.php @@ -33,7 +33,11 @@ class Payment extends PropertiesBase{ $this->User = $user; // Update their name in case we have their email (but not name) recorded from a newsletter subscription - Db::Query('UPDATE Users set Name = ? where UserId = ?', [$this->User->Name, $this->User->UserId]); + Db::Query(' + UPDATE Users + set Name = ? + where UserId = ? + ', [$this->User->Name, $this->User->UserId]); } catch(Exceptions\InvalidUserException $ex){ // User doesn't exist, create it now @@ -45,7 +49,16 @@ class Payment extends PropertiesBase{ } try{ - Db::Query('INSERT into Payments (UserId, Created, ChannelId, TransactionId, Amount, Fee, IsRecurring) values(?, ?, ?, ?, ?, ?, ?);', [$this->UserId, $this->Created, $this->ChannelId, $this->TransactionId, $this->Amount, $this->Fee, $this->IsRecurring]); + Db::Query(' + INSERT into Payments (UserId, Created, ChannelId, TransactionId, Amount, Fee, IsRecurring) + values(?, + ?, + ?, + ?, + ?, + ?, + ?) + ', [$this->UserId, $this->Created, $this->ChannelId, $this->TransactionId, $this->Amount, $this->Fee, $this->IsRecurring]); } catch(PDOException $ex){ if($ex->errorInfo[1] == 1062){ diff --git a/lib/Poll.php b/lib/Poll.php index 89a3387d..8bea0f7a 100644 --- a/lib/Poll.php +++ b/lib/Poll.php @@ -36,7 +36,12 @@ class Poll extends PropertiesBase{ protected function GetVoteCount(): int{ if($this->_VoteCount === null){ - $this->_VoteCount = Db::QueryInt('SELECT count(*) from PollVotes pv inner join PollItems pi using (PollItemId) where pi.PollId = ?', [$this->PollId]); + $this->_VoteCount = Db::QueryInt(' + SELECT count(*) + from PollVotes pv + inner join PollItems pi using (PollItemId) + where pi.PollId = ? + ', [$this->PollId]); } return $this->_VoteCount; @@ -47,7 +52,12 @@ class Poll extends PropertiesBase{ */ protected function GetPollItems(): array{ if($this->_PollItems === null){ - $this->_PollItems = Db::Query('SELECT * from PollItems where PollId = ? order by SortOrder asc', [$this->PollId], 'PollItem'); + $this->_PollItems = Db::Query(' + SELECT * + from PollItems + where PollId = ? + order by SortOrder asc + ', [$this->PollId], 'PollItem'); } return $this->_PollItems; @@ -91,7 +101,11 @@ class Poll extends PropertiesBase{ throw new Exceptions\InvalidPollException(); } - $result = Db::Query('SELECT * from Polls where PollId = ?', [$pollId], 'Poll'); + $result = Db::Query(' + SELECT * + from Polls + where PollId = ? + ', [$pollId], 'Poll'); if(sizeof($result) == 0){ throw new Exceptions\InvalidPollException(); @@ -105,7 +119,11 @@ class Poll extends PropertiesBase{ throw new Exceptions\InvalidPollException(); } - $result = Db::Query('SELECT * from Polls where UrlName = ?', [$urlName], 'Poll'); + $result = Db::Query(' + SELECT * + from Polls + where UrlName = ? + ', [$urlName], 'Poll'); if(sizeof($result) == 0){ throw new Exceptions\InvalidPollException(); diff --git a/lib/PollItem.php b/lib/PollItem.php index 2760b25c..cf9ce783 100644 --- a/lib/PollItem.php +++ b/lib/PollItem.php @@ -19,7 +19,12 @@ class PollItem extends PropertiesBase{ protected function GetVoteCount(): int{ if($this->_VoteCount === null){ - $this->_VoteCount = Db::QueryInt('SELECT count(*) from PollVotes pv inner join PollItems pi using (PollItemId) where pi.PollItemId = ?', [$this->PollItemId]); + $this->_VoteCount = Db::QueryInt(' + SELECT count(*) + from PollVotes pv + inner join PollItems pi using (PollItemId) + where pi.PollItemId = ? + ', [$this->PollItemId]); } return $this->_VoteCount; @@ -35,7 +40,11 @@ class PollItem extends PropertiesBase{ throw new Exceptions\InvalidPollItemException(); } - $result = Db::Query('SELECT * from PollItems where PollItemId = ?', [$pollItemId], 'PollItem'); + $result = Db::Query(' + SELECT * + from PollItems + where PollItemId = ? + ', [$pollItemId], 'PollItem'); if(sizeof($result) == 0){ throw new Exceptions\InvalidPollItemException(); diff --git a/lib/PollVote.php b/lib/PollVote.php index fef5d54b..b050a37c 100644 --- a/lib/PollVote.php +++ b/lib/PollVote.php @@ -93,7 +93,12 @@ class PollVote extends PropertiesBase{ $this->Validate(); $this->Created = new DateTime(); - Db::Query('INSERT into PollVotes (UserId, PollItemId, Created) values (?, ?, ?)', [$this->UserId, $this->PollItemId, $this->Created]); + Db::Query(' + INSERT into PollVotes (UserId, PollItemId, Created) + values (?, + ?, + ?) + ', [$this->UserId, $this->PollItemId, $this->Created]); } public static function Get(?string $pollUrlName, ?int $userId): PollVote{ @@ -101,10 +106,16 @@ class PollVote extends PropertiesBase{ throw new Exceptions\InvalidPollVoteException(); } - $result = Db::Query('SELECT pv.* from PollVotes pv inner join - (select pi.PollItemId from PollItems pi inner join Polls p using (PollId) - where p.UrlName = ? - ) x using (PollItemId) where pv.UserId = ?', [$pollUrlName, $userId], 'PollVote'); + $result = Db::Query(' + SELECT pv.* + from PollVotes pv + inner join + (select pi.PollItemId + from PollItems pi + inner join Polls p using (PollId) + where p.UrlName = ? ) x using (PollItemId) + where pv.UserId = ? + ', [$pollUrlName, $userId], 'PollVote'); if(sizeof($result) == 0){ throw new Exceptions\InvalidPollVoteException(); diff --git a/lib/Session.php b/lib/Session.php index 79a72e1f..8c03965f 100644 --- a/lib/Session.php +++ b/lib/Session.php @@ -36,7 +36,12 @@ class Session extends PropertiesBase{ $this->User = User::GetIfRegistered($email); $this->UserId = $this->User->UserId; - $existingSessions = Db::Query('SELECT SessionId, Created from Sessions where UserId = ?', [$this->UserId]); + $existingSessions = Db::Query(' + SELECT SessionId, + Created + from Sessions + where UserId = ? + ', [$this->UserId]); if(sizeof($existingSessions) > 0){ $this->SessionId = $existingSessions[0]->SessionId; @@ -46,7 +51,12 @@ class Session extends PropertiesBase{ $uuid = Uuid::uuid4(); $this->SessionId = $uuid->toString(); $this->Created = new DateTime(); - Db::Query('INSERT into Sessions (UserId, SessionId, Created) values (?, ?, ?)', [$this->UserId, $this->SessionId, $this->Created]); + Db::Query(' + INSERT into Sessions (UserId, SessionId, Created) + values (?, + ?, + ?) + ', [$this->UserId, $this->SessionId, $this->Created]); } $this->SetSessionCookie($this->SessionId); @@ -56,7 +66,12 @@ class Session extends PropertiesBase{ $sessionId = HttpInput::Str(COOKIE, 'sessionid'); if($sessionId !== null){ - $result = Db::Query('SELECT u.* from Users u inner join Sessions s using (UserId) where s.SessionId = ?', [$sessionId], 'User'); + $result = Db::Query(' + SELECT u.* + from Users u + inner join Sessions s using (UserId) + where s.SessionId = ? + ', [$sessionId], 'User'); if(sizeof($result) > 0){ self::SetSessionCookie($sessionId); @@ -76,7 +91,11 @@ class Session extends PropertiesBase{ throw new Exceptions\InvalidSessionException(); } - $result = Db::Query('SELECT * from Sessions where SessionId = ?', [$sessionId], 'Session'); + $result = Db::Query(' + SELECT * + from Sessions + where SessionId = ? + ', [$sessionId], 'Session'); if(sizeof($result) == 0){ throw new Exceptions\InvalidSessionException(); diff --git a/lib/User.php b/lib/User.php index 3bce7361..4b6ac03d 100644 --- a/lib/User.php +++ b/lib/User.php @@ -26,7 +26,12 @@ class User extends PropertiesBase{ */ protected function GetPayments(): array{ if($this->_Payments === null){ - $this->_Payments = Db::Query('select * from Payments where UserId = ? order by Created desc', [$this->UserId], 'Payment'); + $this->_Payments = Db::Query(' + SELECT * + from Payments + where UserId = ? + order by Created desc + ', [$this->UserId], 'Payment'); } return $this->_Payments; @@ -34,7 +39,11 @@ class User extends PropertiesBase{ protected function GetBenefits(): Benefits{ if($this->_Benefits === null){ - $result = Db::Query('select * from Benefits where UserId = ?', [$this->UserId], 'Benefits'); + $result = Db::Query(' + SELECT * + from Benefits + where UserId = ? + ', [$this->UserId], 'Benefits'); if(sizeof($result) == 0){ $this->_Benefits = new Benefits(); @@ -70,7 +79,13 @@ class User extends PropertiesBase{ $this->Created = new DateTime(); try{ - Db::Query('INSERT into Users (Email, Name, Uuid, Created) values (?, ?, ?, ?);', [$this->Email, $this->Name, $this->Uuid, $this->Created]); + Db::Query(' + INSERT into Users (Email, Name, Uuid, Created) + values (?, + ?, + ?, + ?) + ', [$this->Email, $this->Name, $this->Uuid, $this->Created]); } catch(PDOException $ex){ if($ex->errorInfo[1] == 1062){ @@ -91,7 +106,11 @@ class User extends PropertiesBase{ // *********** public static function Get(?int $userId): User{ - $result = Db::Query('SELECT * from Users where UserId = ?', [$userId], 'User'); + $result = Db::Query(' + SELECT * + from Users + where UserId = ? + ', [$userId], 'User'); if(sizeof($result) == 0){ throw new Exceptions\InvalidUserException(); @@ -105,7 +124,11 @@ class User extends PropertiesBase{ throw new Exceptions\InvalidUserException(); } - $result = Db::Query('SELECT * from Users where Email = ?', [$email], 'User'); + $result = Db::Query(' + SELECT * + from Users + where Email = ? + ', [$email], 'User'); if(sizeof($result) == 0){ throw new Exceptions\InvalidUserException(); @@ -122,7 +145,13 @@ class User extends PropertiesBase{ throw new Exceptions\InvalidUserException(); } - $result = Db::Query('SELECT u.* from Users u inner join Benefits using (UserId) where u.Email = ? or u.Uuid = ?', [$identifier, $identifier], 'User'); + $result = Db::Query(' + SELECT u.* + from Users u + inner join Benefits using (UserId) + where u.Email = ? + or u.Uuid = ? + ', [$identifier, $identifier], 'User'); if(sizeof($result) == 0){ throw new Exceptions\InvalidUserException(); diff --git a/scripts/delete-unconfirmed-newsletter-subscribers b/scripts/delete-unconfirmed-newsletter-subscribers index e008a2c7..cb094643 100755 --- a/scripts/delete-unconfirmed-newsletter-subscribers +++ b/scripts/delete-unconfirmed-newsletter-subscribers @@ -3,5 +3,10 @@ require_once('/standardebooks.org/web/lib/Core.php'); // Delete unconfirmed newsletter subscribers who are more than a week old -Db::Query('DELETE from NewsletterSubscriptions where IsConfirmed = false and datediff(utc_timestamp(), Created) >= 7'); +Db::Query(' + DELETE + from NewsletterSubscriptions + where IsConfirmed = false + and datediff(utc_timestamp(), Created) >= 7 + '); ?> diff --git a/scripts/process-pending-payments b/scripts/process-pending-payments index b693e75a..b8702c75 100755 --- a/scripts/process-pending-payments +++ b/scripts/process-pending-payments @@ -44,10 +44,19 @@ $faPassword = get_cfg_var('se.secrets.fractured_atlas.password'); // 946554ca-ffc0-4259-bcc6-be6c844fbbdc Regular donation, patrons, private, recurring // 416608c6-cbf5-4153-8956-cb9051bb849e Regular donation, patrons, public, one time, in memory of -$pendingPayments = Db::Query('start transaction; - select * from PendingPayments where ProcessedOn is null; - update PendingPayments set ProcessedOn = utc_timestamp() where ProcessedOn is null; - commit;'); +$pendingPayments = Db::Query(' + start transaction; + + SELECT * + from PendingPayments + where ProcessedOn is null; + + UPDATE PendingPayments + set ProcessedOn = utc_timestamp() + where ProcessedOn is null; + + commit; + '); if(sizeof($pendingPayments) == 0){ // Don't start the very slow Selenium driver if we have nothing to process @@ -61,7 +70,11 @@ try{ if($pendingPayment->ChannelId == PAYMENT_CHANNEL_FA){ $log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...'); - if(Db::QueryInt('SELECT count(*) from Payments where TransactionId = ?', [$pendingPayment->TransactionId]) > 0){ + if(Db::QueryInt(' + SELECT count(*) + from Payments + where TransactionId = ? + ', [$pendingPayment->TransactionId]) > 0){ $log->Write('Donation already exists in database.'); continue; } @@ -157,7 +170,12 @@ try{ // This payment is eligible for the Patrons Circle! if($payment->User !== null){ // Are we already a patron? - if(Db::QueryInt('SELECT count(*) from Patrons where UserId = ? and Ended is null', [$payment->UserId]) == 0){ + if(Db::QueryInt(' + SELECT count(*) + from Patrons + where UserId = ? + and Ended is null + ', [$payment->UserId]) == 0){ // Not a patron yet, add them to the Patrons Circle $patron = new Patron(); @@ -194,7 +212,12 @@ try{ else{ // Not eligible to be a patron; send a thank you email anyway, but only if this is a non-recurring donation, or if it's their very first recurring donation if($payment->User !== null){ - $previousPaymentCount = Db::QueryInt('SELECT count(*) from Payments where UserId = ? and IsRecurring = true', [$payment->UserId]); + $previousPaymentCount = Db::QueryInt(' + SELECT count(*) + from Payments + where UserId = ? + and IsRecurring = true + ', [$payment->UserId]); // We just added a payment to the system, so if this is their very first recurring payment, we expect the count to be exactly 1 if(!$payment->IsRecurring || $previousPaymentCount == 1){ @@ -212,7 +235,11 @@ try{ } } - Db::Query('DELETE from PendingPayments where TransactionId = ?;', [$pendingPayment->TransactionId]); + Db::Query(' + DELETE + from PendingPayments + where TransactionId = ? + ', [$pendingPayment->TransactionId]); $log->Write('Donation processed.'); } diff --git a/scripts/update-patrons-circle b/scripts/update-patrons-circle index a7376303..3063605d 100755 --- a/scripts/update-patrons-circle +++ b/scripts/update-patrons-circle @@ -46,12 +46,29 @@ if(sizeof($expiredPatrons) > 0){ } foreach($expiredPatrons as $patron){ - Db::Query('UPDATE Patrons set Ended = ? where UserId = ?', [$now, $patron->UserId]); - Db::Query('UPDATE Benefits set CanAccessFeeds = false, CanVote = false, CanBulkDownload = false where UserId = ?', [$patron->UserId]); + Db::Query(' + UPDATE Patrons + set Ended = ? + where UserId = ? + ', [$now, $patron->UserId]); + + Db::Query(' + UPDATE Benefits + set CanAccessFeeds = false, + CanVote = false, + CanBulkDownload = false + where UserId = ? + ', [$patron->UserId]); // Email the patron to notify them their term has ended // Is the patron a recurring subscriber? - $lastPayment = Db::Query('SELECT * from Payments where UserId = ? order by Created desc limit 1;', [$patron->UserId], 'Payment'); + $lastPayment = Db::Query(' + SELECT * + from Payments + where UserId = ? + order by Created desc + limit 1 + ', [$patron->UserId], 'Payment'); if(sizeof($lastPayment) > 0 && $patron->User->Email !== null){ $em = new Email(); diff --git a/www/about/index.php b/www/about/index.php index 4e365ae8..a847689a 100644 --- a/www/about/index.php +++ b/www/about/index.php @@ -7,38 +7,32 @@ $anonymousPatronCount = 0; // Get the Patrons Circle and try to sort by last name ascending // See for Unicode character properties -$patronsCircle = Db::Query('SELECT if(p.AlternateName is not null, p.AlternateName, u.Name) as SortedName - from Patrons p inner join Users u - using(UserId) - where - p.IsAnonymous = false - and p.Ended is null +$patronsCircle = Db::Query(' + SELECT if(p.AlternateName is not null, p.AlternateName, u.Name) as SortedName + from Patrons p + inner join Users u using(UserId) + where p.IsAnonymous = false + and p.Ended is null order by regexp_substr(SortedName, "[\\\p{Lu}][\\\p{L}\-]*$") asc; '); -$anonymousPatronCount = Db::QueryInt('SELECT sum(cnt) - from - ( - ( - select count(*) cnt from Payments - where - UserId is null - and - ( - (IsRecurring = true and Amount >= 10 and Created >= utc_timestamp() - interval 30 day) - or - (IsRecurring = false and Amount >= 100 and Created >= utc_timestamp() - interval 1 year) - ) - ) - union all - ( - select count(*) as cnt from Patrons - where - IsAnonymous = true - and - Ended is null - ) - ) x +$anonymousPatronCount = Db::QueryInt(' + SELECT sum(cnt) + from ( + ( select count(*) cnt + from Payments + where UserId is null + and ( (IsRecurring = true + and Amount >= 10 + and Created >= utc_timestamp() - interval 30 day) + or (IsRecurring = false + and Amount >= 100 + and Created >= utc_timestamp() - interval 1 year) ) ) + union all + ( select count(*) as cnt + from Patrons + where IsAnonymous = true + and Ended is null ) ) x '); ?> 'About Standard Ebooks', 'highlight' => 'about', 'description' => 'Standard Ebooks is a volunteer-driven effort to produce a collection of high quality, carefully formatted, accessible, open source, and free public domain ebooks that meet or exceed the quality of commercially produced ebooks. The text and cover art in our ebooks is already believed to be in the public domain, and Standard Ebook dedicates its own work to the public domain, thus releasing the entirety of each ebook file into the public domain.']) ?> diff --git a/www/donate/index.php b/www/donate/index.php index 62f80ab1..f2b34a9b 100644 --- a/www/donate/index.php +++ b/www/donate/index.php @@ -1,7 +1,11 @@ 'Donate', 'highlight' => 'donate', 'description' => 'Donate to Standard Ebooks.']) ?>
diff --git a/www/feeds/download.php b/www/feeds/download.php index 92835a3d..7b247849 100644 --- a/www/feeds/download.php +++ b/www/feeds/download.php @@ -26,7 +26,12 @@ try{ // Certain user agents may bypass login entirely $isUserAgentAllowed = false; if(isset($_SERVER['HTTP_USER_AGENT'])){ - $isUserAgentAllowed = Db::QueryInt('select count(*) from FeedUserAgents where instr(?, UserAgent) limit 1', [$_SERVER['HTTP_USER_AGENT']]); + $isUserAgentAllowed = Db::QueryInt(' + SELECT count(*) + from FeedUserAgents + where instr(?, UserAgent) + limit 1 + ', [$_SERVER['HTTP_USER_AGENT']]); } if(!$isUserAgentAllowed){ diff --git a/www/polls/index.php b/www/polls/index.php index b0c3e1b4..a27ec646 100644 --- a/www/polls/index.php +++ b/www/polls/index.php @@ -1,9 +1,23 @@ = End order by Created desc', [], 'Poll'); +$pastPolls = Db::Query(' + SELECT * + from Polls + where utc_timestamp() >= end + order by Created desc + ', [], 'Poll'); -$openPolls = Db::Query('select * from Polls where (End is null or utc_timestamp() <= End) and (Start is null or Start <= utc_timestamp()) order by Created desc', [], 'Poll'); +$openPolls = Db::Query(' + SELECT * + from Polls + where (end is null + or utc_timestamp() <= end) + and + (start is null + or start <= utc_timestamp()) + order by Created desc + ', [], 'Poll'); ?> 'Polls', 'highlight' => '', 'description' => 'The various polls active at Standard Ebooks.']) ?>
diff --git a/www/webhooks/postmark.php b/www/webhooks/postmark.php index a315dbf7..a1fa430c 100644 --- a/www/webhooks/postmark.php +++ b/www/webhooks/postmark.php @@ -36,7 +36,12 @@ try{ // Received when a user marks an email as spam $log->Write('Event type: spam complaint.'); - Db::Query('DELETE ns.* from NewsletterSubscriptions ns inner join Users u using(UserId) where u.Email = ?', [$post->Email]); + Db::Query(' + DELETE ns.* + from NewsletterSubscriptions ns + inner join Users u using(UserId) + where u.Email = ? + ', [$post->Email]); } elseif($post->RecordType == 'SubscriptionChange' && $post->SuppressSending){ // Received when a user clicks Postmark's "Unsubscribe" link in a newsletter email @@ -45,7 +50,12 @@ try{ $email = $post->Recipient; // Remove the email from our newsletter list - Db::Query('DELETE ns.* from NewsletterSubscriptions ns inner join Users u using(UserId) where u.Email = ?', [$email]); + Db::Query(' + DELETE ns.* + from NewsletterSubscriptions ns + inner join Users u using(UserId) + where u.Email = ? + ', [$email]); // Remove the suppression from Postmark, since we deleted it from our own list we will never email them again anyway $handle = curl_init(); diff --git a/www/webhooks/zoho.php b/www/webhooks/zoho.php index 6bdc5c86..d2f9d101 100644 --- a/www/webhooks/zoho.php +++ b/www/webhooks/zoho.php @@ -37,7 +37,12 @@ try{ if(sizeof($matches) == 2){ $transactionId = $matches[1]; - Db::Query('INSERT into PendingPayments (Created, ChannelId, TransactionId) values (utc_timestamp(), ?, ?);', [PAYMENT_CHANNEL_FA, $transactionId]); + Db::Query(' + INSERT into PendingPayments (Created, ChannelId, TransactionId) + values (utc_timestamp(), + ?, + ?) + ', [PAYMENT_CHANNEL_FA, $transactionId]); $log->Write('Donation ID: ' . $transactionId); }