|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * PRE-FLIGHT CHECKLIST |
| 5 | + * |
| 6 | + * - [ ] Subject updated |
| 7 | + * - [ ] Body updated to new template |
| 8 | + * - [ ] Test send to admins |
| 9 | + * - [ ] Verify all links |
| 10 | + * - [ ] Verify all images being server from codeforphilly.org with 2x resolution |
| 11 | + */ |
| 12 | + |
| 13 | +$GLOBALS['Session']->requireAccountLevel('Developer'); |
| 14 | + |
| 15 | +#if ($_SERVER['REQUEST_METHOD'] != 'POST') { |
| 16 | +# die('must be post'); |
| 17 | +#} |
| 18 | + |
| 19 | +header('X-Accel-Buffering: no'); |
| 20 | +header('Content-Type: text/plain; charset=utf-8'); |
| 21 | +ob_end_flush(); |
| 22 | +set_time_limit(0); |
| 23 | + |
| 24 | + |
| 25 | +// select newsletter |
| 26 | +$newsletterDate = '2018-05-21'; |
| 27 | + |
| 28 | + |
| 29 | +// get body markup |
| 30 | +if (!$mjmlNode = Site::resolvePath("newsletters/$newsletterDate/index.mjml")) { |
| 31 | + RequestHandler::throwNotFoundError('Newsletter markup not found'); |
| 32 | +} |
| 33 | + |
| 34 | +$html = shell_exec('hab pkg exec jarvus/mjml mjml -r '.escapeshellarg($mjmlNode->RealPath)); |
| 35 | + |
| 36 | +$url = Emergence\Util\Url::buildAbsolute(['newsletters', $newsletterDate, '']); |
| 37 | +$html = str_replace('[[SHORT_PERMALINK]]', $url, $html); |
| 38 | + |
| 39 | + |
| 40 | +// get recipients |
| 41 | +$Users = Emergence\People\User::getAllByWhere([ |
| 42 | + 'Newsletter' => true, |
| 43 | + 'Email IS NOT NULL' |
| 44 | + |
| 45 | + // toggle to test: |
| 46 | + ,'Username' => [ |
| 47 | + 'values' => ['chris', 'a_priori_rainbows', 'rmcmillen50', 'Tonimacattack'] |
| 48 | + ] |
| 49 | +]); |
| 50 | +printf("Found %u subscribed users\n\n", count($Users)); |
| 51 | + |
| 52 | + |
| 53 | +// send to each recipient |
| 54 | +foreach ($Users as $i => $User) { |
| 55 | + printf("Sending #%u to %s\n", $i+1, $User->EmailRecipient); |
| 56 | + |
| 57 | +# Emergence\Mailer\Mailer::send( |
| 58 | +# $User->EmailRecipient, |
| 59 | +## 'π Open Data, Open Source, Open this email! π', |
| 60 | +## 'π This weekend: Help a project lift off at our Civic Engagement Launchpad π', |
| 61 | +# 'π Celebrate a successful launch: itβs time for demo night! π', |
| 62 | +# $html, |
| 63 | +# 'Code for Philly <hello@codeforphilly.org>' |
| 64 | +# ); |
| 65 | + |
| 66 | + ob_flush(); |
| 67 | + flush(); |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | +printf("\n\nDone\n"); |
0 commit comments