├── .prettierignore
├── phpstan.dist.neon
├── prettier.config.js
├── Deliverance
├── exceptions
│ ├── DeliveranceMailChimpTimeoutException.php
│ ├── DeliveranceException.php
│ ├── DeliveranceMailChimpClientException.php
│ └── DeliveranceMailChimpServerException.php
├── pages
│ ├── DeliveranceMailChimpSignUpPage.php
│ ├── DeliveranceMailChimpUnsubscribePage.php
│ ├── unsubscribe.xml
│ ├── signup.xml
│ ├── DeliveranceUnsubscribePage.php
│ └── DeliveranceSignUpPage.php
├── dataobjects
│ ├── DeliveranceMailingListInterestWrapper.php
│ └── DeliveranceMailingListInterest.php
├── DeliveranceCommandLineApplication.php
├── Deliverance.php
├── DeliveranceListFactory.php
├── DeliveranceMailChimpListUpdater.php
├── DeliveranceListUpdater.php
├── DeliveranceList.php
└── DeliveranceMailChimpList.php
├── sql
└── tables
│ ├── MailingListUpdateQueue.sql
│ ├── MailingListUnsubscribeQueue.sql
│ ├── MailingListSubscribeQueue.sql
│ └── MailingListInterest.sql
├── .gitignore
├── www
└── admin
│ └── styles
│ └── deliverance-newsletter-edit.css
├── README.md
├── .editorconfig
├── package.json
├── pnpm-lock.yaml
├── .github
├── pull_request_template.md
└── workflows
│ └── pull-requests.yml
├── Jenkinsfile
├── composer.json
├── .php-cs-fixer.php
├── phpstan-baseline.neon
└── LICENSE
/.prettierignore:
--------------------------------------------------------------------------------
1 | /composer.lock
2 | /pnpm-lock.yaml
3 | /.pnpm-store
4 |
--------------------------------------------------------------------------------
/phpstan.dist.neon:
--------------------------------------------------------------------------------
1 | includes:
2 | - phpstan-baseline.neon
3 |
4 | parameters:
5 | phpVersion: 80200
6 | level: 0
7 | paths:
8 | - Deliverance
9 | editorUrl: '%%file%%:%%line%%'
10 | editorUrlTitle: '%%file%%:%%line%%'
11 |
--------------------------------------------------------------------------------
/prettier.config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @see https://prettier.io/docs/en/configuration.html
3 | * @type {import("prettier").Config}
4 | */
5 | const config = {
6 | singleQuote: true,
7 | tabWidth: 2,
8 | trailingComma: 'none'
9 | };
10 |
11 | export default config;
12 |
--------------------------------------------------------------------------------
/Deliverance/exceptions/DeliveranceMailChimpTimeoutException.php:
--------------------------------------------------------------------------------
1 | =14'}
20 | hasBin: true
21 |
22 | snapshots:
23 |
24 | prettier@3.6.2: {}
25 |
--------------------------------------------------------------------------------
/sql/tables/MailingListInterest.sql:
--------------------------------------------------------------------------------
1 | create table MailingListInterest (
2 | id serial,
3 |
4 | shortname varchar(255) not null,
5 | group_shortname varchar(255) not null,
6 | title varchar(255) not null,
7 | displayorder integer not null default 0,
8 | visible boolean not null default true,
9 | is_default boolean not null default false,
10 |
11 | instance integer references Instance(id) on delete cascade,
12 |
13 | primary key (id)
14 | );
15 |
16 | create index MailingListInterest_shortname_index
17 | on MailingListInterest(shortname);
18 |
--------------------------------------------------------------------------------
/Deliverance/pages/DeliveranceMailChimpSignUpPage.php:
--------------------------------------------------------------------------------
1 | getDefaultSubscriberInfo();
14 |
15 | // Send welcome is used to signify a new signup to the list. In that
16 | // case set correct site as the source.
17 | if ($this->app->config->mail_chimp->source != '') {
18 | $info['source'] = $this->app->config->mail_chimp->source;
19 | }
20 |
21 | return $info;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Deliverance/pages/DeliveranceMailChimpUnsubscribePage.php:
--------------------------------------------------------------------------------
1 | setReplaceInterests(true);
14 | parent::removeInterests($list, $interests);
15 | }
16 |
17 | protected function getInterestInfo(array $interests_to_remove)
18 | {
19 | $info = [];
20 |
21 | $new_interests = $this->getNewInterests();
22 |
23 | // make sure interests changed, if not, don't update the info.
24 | if (count($new_interests) > 0
25 | && count($new_interests) !== count($this->getInterests())) {
26 | $info['interests'] = $new_interests;
27 | }
28 |
29 | return $info;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | Add a description of new changes, the reason for new changes, and how the new
4 | changes work here.
5 |
6 | # Testing Instructions (optional)
7 |
8 | Add step-by-step instructions for testing the PR, if necessary.
9 |
10 | 1. Check out this PR
11 | 2. …
12 |
13 | # Developer Checklist
14 |
15 | Before requesting review for this PR, make sure the following tasks are
16 | complete:
17 |
18 | - [ ] I added a link to the relevant Shortcut story, if applicable
19 | - [ ] I added testing instructions, if any
20 | - [ ] I made sure existing CI checks pass
21 | - [ ] I checked that all requirements of the ticket are fulfilled
22 |
23 | # Reviewer Checklist
24 |
25 | Before merging this PR, make sure the following tasks are complete:
26 |
27 | - [ ] I made sure there are no active labels that block merge
28 | - [ ] I followed the testing instructions
29 | - [ ] I made sure the CI checks pass
30 | - [ ] I reviewed the file changes on GitHub
31 | - [ ] I checked that all requirements of the ticket (if any) are fulfilled
32 |
--------------------------------------------------------------------------------
/Deliverance/pages/unsubscribe.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Email
9 |
10 | true
11 |
12 |
13 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline {
2 | agent any
3 | stages {
4 | stage('Install Composer Dependencies') {
5 | steps {
6 | sh 'rm -rf composer.lock vendor/'
7 | sh 'composer install'
8 | }
9 | }
10 |
11 | stage('Install NPM Dependencies') {
12 | environment {
13 | PNPM_CACHE_FOLDER = "${env.WORKSPACE}/pnpm-cache/${env.BUILD_NUMBER}"
14 | }
15 | steps {
16 | sh 'n -d exec engine corepack enable pnpm'
17 | sh 'n -d exec engine pnpm install'
18 | }
19 | }
20 |
21 |
22 | stage('Check PHP Coding Style') {
23 | steps {
24 | sh 'composer run phpcs:ci'
25 | }
26 | }
27 |
28 | stage('Check PHP Static Analysis') {
29 | steps {
30 | sh 'composer run phpstan:ci'
31 | }
32 | }
33 |
34 | stage('Check Formating') {
35 | steps {
36 | sh 'n -d exec engine pnpm prettier'
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Deliverance/dataobjects/DeliveranceMailingListInterestWrapper.php:
--------------------------------------------------------------------------------
1 | shortname;
19 | }
20 |
21 | return $shortnames;
22 | }
23 |
24 | public function getDefaultShortnames()
25 | {
26 | $shortnames = [];
27 |
28 | foreach ($this as $interest) {
29 | if ($interest->is_default) {
30 | $shortnames[] = $interest->shortname;
31 | }
32 | }
33 |
34 | return $shortnames;
35 | }
36 |
37 | protected function init()
38 | {
39 | parent::init();
40 |
41 | $this->row_wrapper_class = SwatDBClassMap::get(
42 | DeliveranceMailingListInterest::class
43 | );
44 |
45 | $this->index_field = 'id';
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Deliverance/pages/signup.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Email
9 | Privacy Policy.]]>
12 |
13 | text/xml
14 |
15 | true
16 | 255
17 |
18 |
19 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Deliverance/dataobjects/DeliveranceMailingListInterest.php:
--------------------------------------------------------------------------------
1 | table = 'MailingListInterest';
59 | $this->id_field = 'integer:id';
60 |
61 | $this->registerInternalProperty(
62 | 'instance',
63 | SwatDBClassMap::get(SiteInstance::class)
64 | );
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/.github/workflows/pull-requests.yml:
--------------------------------------------------------------------------------
1 | name: Pull Requests
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - master
7 |
8 | jobs:
9 | runner:
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - name: Check out repository code
14 | uses: actions/checkout@v4
15 |
16 | # Can maybe be replaced with pnpm/action-setup@v4 in the future
17 | - name: Setup pnpm/corepack
18 | uses: actions/setup-node@v4
19 | with:
20 | node-version-file: 'package.json'
21 | - run: npm i -g --force corepack && corepack enable
22 |
23 | - name: Setup Node
24 | uses: actions/setup-node@v4
25 | with:
26 | node-version-file: 'package.json'
27 | cache: 'pnpm'
28 |
29 | - name: Install dependencies
30 | run: pnpm install --frozen-lockfile
31 |
32 | - name: Setup PHP with tools
33 | uses: silverorange/actions-setup-php@v2
34 | with:
35 | php-version: '8.2'
36 | extensions: gd, imagick
37 |
38 | - name: Get composer cache directory
39 | id: composer-cache
40 | run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
41 |
42 | - name: Cache dependencies
43 | uses: actions/cache@v4
44 | with:
45 | path: ${{ steps.composer-cache.outputs.dir }}
46 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
47 | restore-keys: ${{ runner.os }}-composer-
48 |
49 | - name: Install PHP dependencies
50 | run: 'composer install'
51 |
52 | - name: Run tests
53 | timeout-minutes: 5
54 | run: |
55 | pnpm prettier
56 | composer run phpcs:ci
57 | composer run phpstan:ci
58 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "silverorange/deliverance",
3 | "description": "Mailing list framework.",
4 | "type": "library",
5 | "keywords": [
6 | "mailchimp",
7 | "mailinglist",
8 | "email",
9 | "newsletter"
10 | ],
11 | "homepage": "https://github.com/silverorange/deliverance",
12 | "license": "LGPL-2.1",
13 | "authors": [
14 | {
15 | "name": "Charles Waddell",
16 | "email": "charles@silverorange.com"
17 | },
18 | {
19 | "name": "Isaac Grant",
20 | "email": "isaac@silverorange.com"
21 | },
22 | {
23 | "name": "Michael Gauthier",
24 | "email": "mike@silverorange.com"
25 | },
26 | {
27 | "name": "Nick Burka",
28 | "email": "nick@silverorange.com"
29 | }
30 | ],
31 | "repositories": [
32 | {
33 | "type": "composer",
34 | "url": "https://composer.silverorange.com",
35 | "only": [
36 | "silverorange/*"
37 | ]
38 | }
39 | ],
40 | "require": {
41 | "php": ">=7.2",
42 | "ext-mbstring": "*",
43 | "silverorange/site": "^15.3.2",
44 | "silverorange/swat": "^7.9.2"
45 | },
46 | "require-dev": {
47 | "friendsofphp/php-cs-fixer": "3.64.0",
48 | "phpstan/phpstan": "^1.12"
49 | },
50 | "suggest": {
51 | "drewm/mailchimp-api": "Support for MailChimp mailing lists.",
52 | "silverorange/admin": "Admin pages for managing newsletters."
53 | },
54 | "scripts": {
55 | "phpcs": "./vendor/bin/php-cs-fixer check -v",
56 | "phpcs:ci": "./vendor/bin/php-cs-fixer check --config=.php-cs-fixer.php --no-interaction --show-progress=none --diff --using-cache=no -vvv",
57 | "phpcs:write": "./vendor/bin/php-cs-fixer fix -v",
58 | "phpstan": "./vendor/bin/phpstan analyze",
59 | "phpstan:ci": "./vendor/bin/phpstan analyze -vvv --no-progress --memory-limit 2G",
60 | "phpstan:baseline": "./vendor/bin/phpstan analyze --generate-baseline"
61 | },
62 | "autoload": {
63 | "classmap": [
64 | "Deliverance/"
65 | ]
66 | },
67 | "config": {
68 | "sort-packages": true
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/.php-cs-fixer.php:
--------------------------------------------------------------------------------
1 | in(__DIR__);
9 |
10 | return (new Config())
11 | ->setParallelConfig(ParallelConfigFactory::detect(null, null, 2**18-1))
12 | ->setRules([
13 | '@PhpCsFixer' => true,
14 | '@PHP82Migration' => true,
15 | 'indentation_type' => true,
16 |
17 | // Overrides for (opinionated) @PhpCsFixer and @Symfony rules:
18 |
19 | // Align "=>" in multi-line array definitions, unless a blank line exists between elements
20 | 'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal']],
21 |
22 | // Subset of statements that should be proceeded with blank line
23 | 'blank_line_before_statement' => ['statements' => ['case', 'continue', 'declare', 'default', 'return', 'throw', 'try', 'yield', 'yield_from']],
24 |
25 | // Enforce space around concatenation operator
26 | 'concat_space' => ['spacing' => 'one'],
27 |
28 | // Use {} for empty loop bodies
29 | 'empty_loop_body' => ['style' => 'braces'],
30 |
31 | // Don't change any increment/decrement styles
32 | 'increment_style' => false,
33 |
34 | // Forbid multi-line whitespace before the closing semicolon
35 | 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
36 |
37 | // Clean up PHPDocs, but leave @inheritDoc entries alone
38 | 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => false],
39 |
40 | // Ensure that traits are listed first in classes
41 | // (it would be nice to enforce more, but we'll start simple)
42 | 'ordered_class_elements' => ['order' => ['use_trait']],
43 |
44 | // Ensure that param and return types are sorted consistently, with null at end
45 | 'phpdoc_types_order' => ['sort_algorithm' => 'alpha', 'null_adjustment' => 'always_last'],
46 |
47 | // Yoda style is too weird
48 | 'yoda_style' => false,
49 | ])
50 | ->setIndent(' ')
51 | ->setLineEnding("\n")
52 | ->setFinder($finder);
53 |
--------------------------------------------------------------------------------
/phpstan-baseline.neon:
--------------------------------------------------------------------------------
1 | parameters:
2 | ignoreErrors:
3 | -
4 | message: "#^Instantiated class DrewM\\\\MailChimp\\\\Batch not found\\.$#"
5 | count: 6
6 | path: Deliverance/DeliveranceMailChimpList.php
7 |
8 | -
9 | message: "#^Instantiated class DrewM\\\\MailChimp\\\\MailChimp not found\\.$#"
10 | count: 1
11 | path: Deliverance/DeliveranceMailChimpList.php
12 |
13 | -
14 | message: "#^Access to undefined constant DeliveranceMailChimpList\\:\\:BOUNCED_ERROR_CODE\\.$#"
15 | count: 1
16 | path: Deliverance/DeliveranceMailChimpListUpdater.php
17 |
18 | -
19 | message: "#^Access to undefined constant DeliveranceMailChimpList\\:\\:INVALID_ADDRESS_ERROR_CODE\\.$#"
20 | count: 1
21 | path: Deliverance/DeliveranceMailChimpListUpdater.php
22 |
23 | -
24 | message: "#^Access to undefined constant DeliveranceMailChimpList\\:\\:NOT_FOUND_ERROR_CODE\\.$#"
25 | count: 1
26 | path: Deliverance/DeliveranceMailChimpListUpdater.php
27 |
28 | -
29 | message: "#^Access to undefined constant DeliveranceMailChimpList\\:\\:NOT_SUBSCRIBED_ERROR_CODE\\.$#"
30 | count: 1
31 | path: Deliverance/DeliveranceMailChimpListUpdater.php
32 |
33 | -
34 | message: "#^Access to undefined constant DeliveranceMailChimpList\\:\\:PREVIOUSLY_UNSUBSCRIBED_ERROR_CODE\\.$#"
35 | count: 1
36 | path: Deliverance/DeliveranceMailChimpListUpdater.php
37 |
38 | -
39 | message: "#^Call to an undefined static method DeliveranceListUpdater\\:\\:handleResult\\(\\)\\.$#"
40 | count: 1
41 | path: Deliverance/DeliveranceMailChimpListUpdater.php
42 |
43 | -
44 | message: "#^Call to an undefined method DeliveranceMailChimpUnsubscribePage\\:\\:getInterests\\(\\)\\.$#"
45 | count: 1
46 | path: Deliverance/pages/DeliveranceMailChimpUnsubscribePage.php
47 |
48 | -
49 | message: "#^Call to an undefined method DeliveranceMailChimpUnsubscribePage\\:\\:getNewInterests\\(\\)\\.$#"
50 | count: 1
51 | path: Deliverance/pages/DeliveranceMailChimpUnsubscribePage.php
52 |
53 | -
54 | message: "#^Call to an undefined static method DeliveranceUnsubscribePage\\:\\:removeInterests\\(\\)\\.$#"
55 | count: 1
56 | path: Deliverance/pages/DeliveranceMailChimpUnsubscribePage.php
57 |
--------------------------------------------------------------------------------
/Deliverance/pages/DeliveranceUnsubscribePage.php:
--------------------------------------------------------------------------------
1 | unsubscribe($this->getList());
19 | }
20 |
21 | protected function getList()
22 | {
23 | return DeliveranceListFactory::get($this->app, 'default');
24 | }
25 |
26 | protected function unsubscribe(DeliveranceList $list)
27 | {
28 | $this->handleUnsubscribeResponse(
29 | $list,
30 | $list->unsubscribe($this->getEmail())
31 | );
32 | }
33 |
34 | protected function getEmail()
35 | {
36 | return $this->ui->getWidget('email')->value;
37 | }
38 |
39 | protected function handleUnsubscribeResponse(
40 | DeliveranceList $list,
41 | $response
42 | ) {
43 | $this->handleMessage($list->handleUnsubscribeResponse($response));
44 | }
45 |
46 | protected function handleMessage(?SwatMessage $message = null)
47 | {
48 | if ($message instanceof SwatMessage) {
49 | $this->ui->getWidget('message_display')->add($message);
50 | }
51 | }
52 |
53 | protected function relocate(SwatForm $form)
54 | {
55 | if ($this->canRelocate($form)) {
56 | $this->addUnsubscribeMessage();
57 | $this->app->relocate(
58 | $this->getRelocateUri($form, $this->source . '/thankyou')
59 | );
60 | }
61 | }
62 |
63 | protected function canRelocate(SwatForm $form)
64 | {
65 | return $this->ui->getWidget('message_display')->getMessageCount() ==
66 | 0;
67 | }
68 |
69 | protected function addUnsubscribeMessage()
70 | {
71 | // TODO - add interest update messages.
72 | }
73 |
74 | protected function getRelocateUri(SwatForm $form, $default_relocate)
75 | {
76 | return $this->source . '/thankyou';
77 | }
78 |
79 | // build phase
80 |
81 | protected function buildForm(SwatForm $form)
82 | {
83 | parent::buildForm($form);
84 |
85 | $email = SiteApplication::initVar('email');
86 | if ($email != '') {
87 | $this->ui->getWidget('email')->value = $email;
88 | } elseif (!$form->isProcessed() && $this->app->session->isLoggedIn()) {
89 | $this->ui->getWidget('email')->value =
90 | $this->app->session->account->email;
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/Deliverance/DeliveranceCommandLineApplication.php:
--------------------------------------------------------------------------------
1 | addParameter(
25 | 'string',
26 | 'instance name must be specified.'
27 | );
28 |
29 | $this->addCommandLineArgument($instance);
30 |
31 | $dry_run = new SiteCommandLineArgument(
32 | ['--dry-run'],
33 | 'setDryRun',
34 | Deliverance::_('No data is actually modified.')
35 | );
36 |
37 | $this->addCommandLineArgument($dry_run);
38 | }
39 |
40 | public function setInstance($shortname)
41 | {
42 | putenv(sprintf('instance=%s', $shortname));
43 | $this->instance->init();
44 | $this->config->init();
45 | }
46 |
47 | public function setDryRun($dry_run)
48 | {
49 | $this->dry_run = (bool) $dry_run;
50 | }
51 |
52 | public function run()
53 | {
54 | parent::run();
55 |
56 | $this->lock();
57 | $this->runInternal();
58 | $this->unlock();
59 | }
60 |
61 | protected function runInternal()
62 | {
63 | // There are command-line applications that extend
64 | // DeliveranceCommandLineApplication and don't have a run() method
65 | // defined, so runInternal() cannot be abstract.
66 | }
67 |
68 | protected function getList()
69 | {
70 | $list = DeliveranceListFactory::get($this, 'default');
71 | $list->setTimeout(
72 | $this->config->deliverance->list_script_connection_timeout
73 | );
74 |
75 | return $list;
76 | }
77 |
78 | // boilerplate
79 |
80 | protected function addConfigDefinitions(SiteConfigModule $config)
81 | {
82 | parent::addConfigDefinitions($config);
83 | $config->addDefinitions(Deliverance::getConfigDefinitions());
84 | }
85 |
86 | protected function getDefaultModuleList()
87 | {
88 | return array_merge(
89 | parent::getDefaultModuleList(),
90 | [
91 | 'config' => SiteCommandLineConfigModule::class,
92 | 'database' => SiteDatabaseModule::class,
93 | 'instance' => SiteMultipleInstanceModule::class,
94 | ]
95 | );
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/Deliverance/Deliverance.php:
--------------------------------------------------------------------------------
1 | 1,
107 | 'deliverance.list_script_connection_timeout' => 300,
108 |
109 | // mailchimp specific
110 | 'mail_chimp.api_key' => null,
111 | 'mail_chimp.default_list' => null,
112 | 'mail_chimp.list_title' => null,
113 | 'mail_chimp.source' => null,
114 | ];
115 | }
116 |
117 | public static function init()
118 | {
119 | if (self::$is_initialized) {
120 | return;
121 | }
122 |
123 | Swat::init();
124 | Site::init();
125 |
126 | self::setupGettext();
127 |
128 | SwatUI::mapClassPrefixToPath('Deliverance', 'Deliverance');
129 |
130 | self::$is_initialized = true;
131 | }
132 |
133 | /**
134 | * Prevent instantiation of this static class.
135 | */
136 | private function __construct() {}
137 | }
138 |
--------------------------------------------------------------------------------
/Deliverance/pages/DeliveranceSignUpPage.php:
--------------------------------------------------------------------------------
1 | subscribe($this->getList());
19 | }
20 |
21 | protected function getList()
22 | {
23 | return DeliveranceListFactory::get($this->app, 'default');
24 | }
25 |
26 | protected function subscribe(DeliveranceList $list)
27 | {
28 | $default_info = $list->getDefaultSubscriberInfo();
29 |
30 | // Check to see if the email address is already a member before doing
31 | // anything else. This allows the welcome flag to be set correctly,
32 | // and for subscriber info to be based on whether it's a new member or
33 | // not.
34 | $email = $this->getEmail();
35 | $this->checkMember($list, $email);
36 |
37 | $info = $this->getSubscriberInfo($list);
38 |
39 | $response = $list->subscribe($email, $info);
40 |
41 | $this->handleSubscribeResponse($list, $response);
42 | }
43 |
44 | protected function handleSubscribeResponse(DeliveranceList $list, $response)
45 | {
46 | $message = $list->handleSubscribeResponse($response);
47 | $message_display = $this->getMessageDisplay();
48 |
49 | if (
50 | $message_display instanceof SwatMessageDisplay
51 | && $message instanceof SwatMessage
52 | ) {
53 | $message_display->add($message);
54 | }
55 | }
56 |
57 | protected function getEmail()
58 | {
59 | return $this->ui->getWidget('email')->value;
60 | }
61 |
62 | abstract protected function getSubscriberInfo(DeliveranceList $list);
63 |
64 | protected function checkMember(DeliveranceList $list, $email)
65 | {
66 | if ($list->isMember($email)) {
67 | $message = $this->getExistingMemberMessage($list, $email);
68 | if ($message != null) {
69 | $this->addAppMessage($message);
70 | }
71 | }
72 | }
73 |
74 | protected function getExistingMemberMessage(DeliveranceList $list, $email)
75 | {
76 | // TODO: rewrite.
77 | $message = new SwatMessage(
78 | Deliverance::_(
79 | 'Thank you. Your email address was already subscribed to ' .
80 | 'our newsletter.'
81 | ),
82 | 'notice'
83 | );
84 |
85 | $message->secondary_content = Deliverance::_(
86 | 'Your subscriber information has been updated, and you will ' .
87 | 'continue to receive mailings at this address.'
88 | );
89 |
90 | return $message;
91 | }
92 |
93 | protected function relocate(SwatForm $form)
94 | {
95 | if ($this->canRelocate($form)) {
96 | $this->app->relocate($this->source . '/thankyou');
97 | }
98 | }
99 |
100 | protected function canRelocate(SwatForm $form)
101 | {
102 | $can_relocate = true;
103 |
104 | $message_display = $this->getMessageDisplay();
105 | if (
106 | $message_display instanceof SwatMessageDisplay
107 | && $message_display->getMessageCount() > 0
108 | ) {
109 | $can_relocate = false;
110 | }
111 |
112 | return $can_relocate;
113 | }
114 |
115 | protected function getMessageDisplay(?SwatForm $form = null)
116 | {
117 | return $this->ui->getRoot()->getFirstDescendant(
118 | 'SwatMessageDisplay'
119 | );
120 | }
121 |
122 | protected function addAppMessage(SwatMessage $message)
123 | {
124 | $this->app->messages->add($message);
125 | }
126 |
127 | // build phase
128 |
129 | protected function buildForm(SwatForm $form)
130 | {
131 | parent::buildForm($form);
132 |
133 | $email = SiteApplication::initVar('email');
134 | if ($email != '') {
135 | $this->ui->getWidget('email')->value = $email;
136 | } elseif (!$form->isProcessed() && $this->app->session->isLoggedIn()) {
137 | $this->ui->getWidget('email')->value =
138 | $this->app->session->account->email;
139 | }
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/Deliverance/DeliveranceListFactory.php:
--------------------------------------------------------------------------------
1 | Deliverance' is included by default. Search paths can be added
10 | * and removed using the {@link DeliveranceListFactory::addPath()} and
11 | * {@link DeliveranceListFactory::removePath()} methods.
12 | *
13 | * @copyright 2012-2016 silverorange
14 | * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
15 | *
16 | * @see DeliveranceList
17 | */
18 | class DeliveranceListFactory extends SwatObject
19 | {
20 | /**
21 | * List of registered list classes indexed by the list type.
22 | *
23 | * @var array
24 | */
25 | private static $list_class_names_by_type = [];
26 |
27 | /**
28 | * Paths to search for class-definition files.
29 | *
30 | * @var array
31 | */
32 | private static $search_paths = ['Deliverance'];
33 |
34 | /**
35 | * Gets a list of the specified type.
36 | *
37 | * @param SiteApplication $app the application in which to get the list
38 | * @param string $type the type of list to get. There must be a list class
39 | * registered for this type.
40 | * @param string $shortname the shortname of the list to call the
41 | * constructor with
42 | *
43 | * @return DeliveranceList the list of the specified type. The list will be
44 | * an instance of whatever class was registered for
45 | * the list type.
46 | *
47 | * @throws InvalidArgumentException if there is no list registered for the
48 | * requested $type
49 | */
50 | public static function get(
51 | SiteApplication $app,
52 | $type = 'default',
53 | $shortname = null
54 | ) {
55 | if ($type === null) {
56 | $type = 'default';
57 | }
58 |
59 | $type = strval($type);
60 | if (!array_key_exists($type, self::$list_class_names_by_type)) {
61 | throw new InvalidArgumentException(sprintf(
62 | 'No lists are registered with the type "%s".',
63 | $type
64 | ));
65 | }
66 |
67 | $list_class_name = self::$list_class_names_by_type[$type];
68 | self::loadListClass($list_class_name);
69 |
70 | return new $list_class_name($app, $shortname);
71 | }
72 |
73 | /**
74 | * Registers a list class with the factory.
75 | *
76 | * List classes must be registed with the factory before they are used.
77 | * When a list class is registered for a particular type, an instance of
78 | * the list class is returned whenever a list of that type is requested.
79 | *
80 | * @param string $type the list type
81 | * @param string $list_class_name the class name of the list. The class
82 | * does not need to be defined until a
83 | * list of the specified type is requested.
84 | */
85 | public static function registerList($type, $list_class_name)
86 | {
87 | $type = strval($type);
88 | self::$list_class_names_by_type[$type] = $list_class_name;
89 | }
90 |
91 | /**
92 | * Adds a search path for class-definition files.
93 | *
94 | * When an undefined list class is requested, the factory attempts to find
95 | * and require a class-definition file for the list class.
96 | *
97 | * All search paths are relative to the PHP include path. The search path
98 | * 'Deliverance' is included by default.
99 | *
100 | * @param string $search_path the path to search for list class-definition
101 | * files
102 | *
103 | * @see DeliveranceListFactory::removePath()
104 | */
105 | public static function addPath($search_path)
106 | {
107 | if (!in_array($search_path, self::$search_paths, true)) {
108 | // add path to front of array since it is more likely we will find
109 | // class-definitions in manually added search paths
110 | array_unshift(self::$search_paths, $search_path);
111 | }
112 | }
113 |
114 | /**
115 | * Removes a search path for list class-definition files.
116 | *
117 | * @param string $path the path to remove
118 | *
119 | * @see DeliveranceListFactory::addPath()
120 | */
121 | public static function removePath($path)
122 | {
123 | $index = array_search($path, self::$search_paths);
124 | if ($index !== false) {
125 | array_splice(self::$search_paths, $index, 1);
126 | }
127 | }
128 |
129 | /**
130 | * Loads a list class-definition if it is not defined.
131 | *
132 | * This checks the factory search path for an appropriate source file.
133 | *
134 | * @param string $list_class_name the name of the list class
135 | *
136 | * @throws SwatClassNotFoundException if the list class is not defined and
137 | * no suitable file in the list search
138 | * path contains the class definition
139 | */
140 | private static function loadListClass($list_class_name)
141 | {
142 | if (!class_exists($list_class_name)) {
143 | throw new SwatClassNotFoundException(sprintf(
144 | 'List class "%s" does not exist and could not be found in ' .
145 | 'the search path.',
146 | $list_class_name
147 | ), 0, $list_class_name);
148 | }
149 | }
150 |
151 | /**
152 | * This class contains only static methods and should not be instantiated.
153 | */
154 | private function __construct() {}
155 | }
156 |
--------------------------------------------------------------------------------
/Deliverance/DeliveranceMailChimpListUpdater.php:
--------------------------------------------------------------------------------
1 | debug(sprintf(
20 | $success_message,
21 | $result['success_count']
22 | ));
23 |
24 | // add count doesn't always exist.
25 | if (isset($result['add_count']) && $result['add_count']) {
26 | $this->debug(
27 | sprintf(
28 | Deliverance::_('%s addresses added.') . "\n",
29 | $result['add_count']
30 | )
31 | );
32 | }
33 |
34 | // update count doesn't always exist.
35 | if (isset($result['update_count']) && $result['update_count']) {
36 | $this->debug(
37 | sprintf(
38 | Deliverance::_('%s addresses updated.') . "\n",
39 | $result['update_count']
40 | )
41 | );
42 | }
43 |
44 | // Queued requests can exist in errors or in the result message
45 | // depending on the request type.
46 | $queued_count = 0;
47 | if (isset($result['queued_count']) && $result['queued_count']) {
48 | $queued_count = $result['queued_count'];
49 | }
50 |
51 | if ($result['error_count']) {
52 | $errors = [];
53 | $not_found_count = 0;
54 | $bounced_count = 0;
55 | $previously_unsubscribed_count = 0;
56 | $invalid_count = 0;
57 |
58 | // don't throw errors for codes we know can be ignored.
59 | foreach ($result['errors'] as $error) {
60 | switch ($error['code']) {
61 | case DeliveranceMailChimpList::NOT_FOUND_ERROR_CODE:
62 | case DeliveranceMailChimpList::NOT_SUBSCRIBED_ERROR_CODE:
63 | $not_found_count++;
64 | break;
65 |
66 | case DeliveranceMailChimpList::PREVIOUSLY_UNSUBSCRIBED_ERROR_CODE:
67 | $previously_unsubscribed_count++;
68 | break;
69 |
70 | case DeliveranceMailChimpList::BOUNCED_ERROR_CODE:
71 | $bounced_count++;
72 | break;
73 |
74 | case DeliveranceMailChimpList::INVALID_ADDRESS_ERROR_CODE:
75 | $invalid_count++;
76 | break;
77 |
78 | case DeliveranceList::QUEUED:
79 | $queued_count++;
80 | break;
81 |
82 | default:
83 | $error_message = sprintf(
84 | Deliverance::_('code: %s - message: %s.'),
85 | $error['code'],
86 | $error['message']
87 | );
88 |
89 | $errors[] = $error_message;
90 | $execption = new SiteException($error_message);
91 | // don't exit on returned errors
92 | $execption->processAndContinue();
93 | }
94 | }
95 |
96 | if ($not_found_count > 0) {
97 | $this->debug(
98 | sprintf(
99 | Deliverance::_('%s addresses not found.') . "\n",
100 | $not_found_count
101 | )
102 | );
103 | }
104 |
105 | if ($previously_unsubscribed_count > 0) {
106 | $this->debug(
107 | sprintf(
108 | Deliverance::_(
109 | '%s addresses have previously subscribed, ' .
110 | 'and cannot be resubscribed.'
111 | ) . "\n",
112 | $previously_unsubscribed_count
113 | )
114 | );
115 | }
116 |
117 | if ($bounced_count > 0) {
118 | $this->debug(
119 | sprintf(
120 | Deliverance::_(
121 | '%s addresses have bounced, and cannot be ' .
122 | 'resubscribed.'
123 | ) . "\n",
124 | $bounced_count
125 | )
126 | );
127 | }
128 |
129 | if ($invalid_count > 0) {
130 | $this->debug(
131 | sprintf(
132 | Deliverance::_('%s invalid addresses.') . "\n",
133 | $invalid_count
134 | )
135 | );
136 | }
137 |
138 | if (count($errors)) {
139 | $this->debug(
140 | sprintf(
141 | Deliverance::_('%s errors:') . "\n",
142 | count($errors)
143 | )
144 | );
145 |
146 | foreach ($errors as $error) {
147 | $this->debug($error . "\n");
148 | }
149 | }
150 | }
151 |
152 | if ($queued_count > 0) {
153 | $clear_queued = false;
154 | $this->debug(
155 | sprintf(
156 | Deliverance::_('%s addresses queued.') . "\n",
157 | $queued_count
158 | )
159 | );
160 | }
161 | }
162 |
163 | return $clear_queued;
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/Deliverance/DeliveranceListUpdater.php:
--------------------------------------------------------------------------------
1 | getList();
17 |
18 | $this->debug(Deliverance::_('Updating Mailing List') . "\n\n", true);
19 |
20 | $this->debug(Deliverance::_('Subscribing:') . "\n--------------------\n");
21 | $this->subscribe($list);
22 | $this->debug(Deliverance::_('Done subscribing.') . "\n\n");
23 |
24 | $this->debug(Deliverance::_('Updating:') . "\n--------------------\n");
25 | $this->update($list);
26 | $this->debug(Deliverance::_('Done updating.') . "\n\n");
27 |
28 | $this->debug(
29 | Deliverance::_('Unsubscribing:') . "\n--------------------\n"
30 | );
31 |
32 | $this->unsubscribe($list);
33 | $this->debug(Deliverance::_('Done unsubscribing.') . "\n\n");
34 |
35 | $this->debug(Deliverance::_('All Done.') . "\n", true);
36 | }
37 |
38 | protected function subscribe(DeliveranceList $list)
39 | {
40 | if ($list->isAvailable()) {
41 | $this->subscribeQueued($list);
42 | } else {
43 | $this->debug(
44 | Deliverance::_(
45 | 'Mailing list unavailable. No queued addresses subscribed.'
46 | ) . "\n"
47 | );
48 | }
49 | }
50 |
51 | protected function update(DeliveranceList $list)
52 | {
53 | if ($list->isAvailable()) {
54 | $this->updateQueued($list);
55 | } else {
56 | $this->debug(
57 | Deliverance::_(
58 | 'Mailing list unavailable. No queued addresses updated.'
59 | ) . "\n"
60 | );
61 | }
62 | }
63 |
64 | protected function unsubscribe(DeliveranceList $list)
65 | {
66 | if ($list->isAvailable()) {
67 | $this->unsubscribeQueued($list);
68 | } else {
69 | $this->debug(
70 | Deliverance::_(
71 | 'Mailing list unavailable. No queued addresses ' .
72 | 'unsubscribed.'
73 | ) . "\n"
74 | );
75 | }
76 | }
77 |
78 | protected function subscribeQueued(DeliveranceList $list)
79 | {
80 | $addresses = $this->getQueuedSubscribes();
81 |
82 | if (count($addresses) == 0) {
83 | $this->debug(
84 | Deliverance::_(
85 | 'No queued addresses to subscribe.'
86 | ) . "\n"
87 | );
88 |
89 | return;
90 | }
91 |
92 | $this->debug(
93 | sprintf(
94 | Deliverance::_('Subscribing %s queued addresses.') . "\n",
95 | count($addresses)
96 | )
97 | );
98 |
99 | if ($this->dry_run === false) {
100 | $subscribed_ids = $list->batchSubscribe($addresses);
101 |
102 | $this->debug(
103 | sprintf(
104 | Deliverance::_('%s queued addresses subscribed.') . "\n",
105 | count($subscribed_ids)
106 | )
107 | );
108 |
109 | $this->clearQueuedSubscribes($subscribed_ids);
110 | }
111 |
112 | $this->debug(
113 | Deliverance::_(
114 | 'done subscribing queued addresses.'
115 | ) . "\n\n"
116 | );
117 | }
118 |
119 | protected function updateQueued(DeliveranceList $list)
120 | {
121 | $addresses = $this->getQueuedUpdates();
122 |
123 | if (count($addresses) == 0) {
124 | $this->debug(
125 | Deliverance::_(
126 | 'No queued addresses to update.'
127 | ) . "\n"
128 | );
129 |
130 | return;
131 | }
132 |
133 | $this->debug(
134 | sprintf(
135 | Deliverance::_('Updating %s queued addresses.') . "\n",
136 | count($addresses)
137 | )
138 | );
139 |
140 | if ($this->dry_run === false) {
141 | $updated_ids = $list->batchUpdate($addresses);
142 |
143 | $this->debug(
144 | sprintf(
145 | Deliverance::_('%s queued addresses updated.') . "\n",
146 | count($updated_ids)
147 | )
148 | );
149 |
150 | $this->clearQueuedUpdates($updated_ids);
151 | }
152 |
153 | $this->debug(
154 | Deliverance::_(
155 | 'done updating queued addresses.'
156 | ) . "\n\n"
157 | );
158 | }
159 |
160 | protected function unsubscribeQueued(DeliveranceList $list)
161 | {
162 | $addresses = $this->getQueuedUnsubscribes();
163 |
164 | if (count($addresses) == 0) {
165 | $this->debug(
166 | Deliverance::_(
167 | 'No queued addresses to unsubscribe.'
168 | ) . "\n"
169 | );
170 |
171 | return;
172 | }
173 |
174 | $this->debug(
175 | sprintf(
176 | Deliverance::_(
177 | 'Unsubscribing %s queued addresses.'
178 | ) . "\n",
179 | count($addresses)
180 | )
181 | );
182 |
183 | if ($this->dry_run === false) {
184 | $unsubscribed_ids = $list->batchUnsubscribe($addresses);
185 |
186 | $this->debug(
187 | sprintf(
188 | Deliverance::_('%s queued addresses unsubscribed.') . "\n",
189 | count($unsubscribed_ids)
190 | )
191 | );
192 |
193 | $this->clearQueuedUnsubscribes($unsubscribed_ids);
194 | }
195 |
196 | $this->debug(
197 | Deliverance::_(
198 | 'done unsubscribing queued addresses.'
199 | ) . "\n\n"
200 | );
201 | }
202 |
203 | protected function getQueuedSubscribes()
204 | {
205 | $addresses = [];
206 |
207 | $sql = 'select id, email, info
208 | from MailingListSubscribeQueue
209 | where instance %s %s';
210 |
211 | $sql = sprintf(
212 | $sql,
213 | SwatDB::equalityOperator($this->getInstanceId()),
214 | $this->db->quote($this->getInstanceId(), 'integer')
215 | );
216 |
217 | $rows = SwatDB::query($this->db, $sql);
218 | foreach ($rows as $row) {
219 | $address = unserialize($row->info);
220 | $address['id'] = $row->id;
221 | $address['email'] = $row->email;
222 |
223 | $addresses[] = $address;
224 | }
225 |
226 | return $addresses;
227 | }
228 |
229 | protected function getQueuedUpdates()
230 | {
231 | $addresses = [];
232 |
233 | $sql = 'select id, email, info
234 | from MailingListUpdateQueue
235 | where instance %s %s';
236 |
237 | $sql = sprintf(
238 | $sql,
239 | SwatDB::equalityOperator($this->getInstanceId()),
240 | $this->db->quote($this->getInstanceId(), 'integer')
241 | );
242 |
243 | $rows = SwatDB::query($this->db, $sql);
244 | foreach ($rows as $row) {
245 | $address = unserialize($row->info);
246 | $address['id'] = $row->id;
247 | $address['email'] = $row->email;
248 |
249 | $addresses[] = $address;
250 | }
251 |
252 | return $addresses;
253 | }
254 |
255 | protected function getQueuedUnsubscribes()
256 | {
257 | $addresses = [];
258 |
259 | $sql = 'select id, email
260 | from MailingListUnsubscribeQueue
261 | where instance %s %s';
262 |
263 | $sql = sprintf(
264 | $sql,
265 | SwatDB::equalityOperator($this->getInstanceId()),
266 | $this->db->quote($this->getInstanceId(), 'integer')
267 | );
268 |
269 | $rows = SwatDB::query($this->db, $sql);
270 | foreach ($rows as $row) {
271 | $addresses[$row->id] = $row->email;
272 | }
273 |
274 | return $addresses;
275 | }
276 |
277 | protected function clearQueuedSubscribes(array $ids)
278 | {
279 | $sql = 'delete from MailingListSubscribeQueue
280 | where id in (%s) and instance %s %s';
281 |
282 | $sql = sprintf(
283 | $sql,
284 | $this->getQuotedIds($ids),
285 | SwatDB::equalityOperator($this->getInstanceId()),
286 | $this->db->quote($this->getInstanceId(), 'integer')
287 | );
288 |
289 | $delete_count = SwatDB::exec($this->db, $sql);
290 |
291 | $this->debug(
292 | sprintf(
293 | Deliverance::_(
294 | '%s rows (%s addresses) cleared from the queue.'
295 | ) . "\n",
296 | $delete_count,
297 | count($ids)
298 | )
299 | );
300 | }
301 |
302 | protected function clearQueuedUpdates(array $ids)
303 | {
304 | $sql = 'delete from MailingListUpdateQueue
305 | where id in (%s) and instance %s %s';
306 |
307 | $sql = sprintf(
308 | $sql,
309 | $this->getQuotedIds($ids),
310 | SwatDB::equalityOperator($this->getInstanceId()),
311 | $this->db->quote($this->getInstanceId(), 'integer')
312 | );
313 |
314 | $delete_count = SwatDB::exec($this->db, $sql);
315 |
316 | $this->debug(
317 | sprintf(
318 | Deliverance::_(
319 | '%s rows (%s addresses) cleared from the queue.'
320 | ) . "\n",
321 | $delete_count,
322 | count($ids)
323 | )
324 | );
325 | }
326 |
327 | protected function clearQueuedUnsubscribes(array $ids)
328 | {
329 | $sql = 'delete from MailingListUnsubscribeQueue
330 | where id in (%s) and instance %s %s';
331 |
332 | $sql = sprintf(
333 | $sql,
334 | $this->getQuotedIds($ids),
335 | SwatDB::equalityOperator($this->getInstanceId()),
336 | $this->db->quote($this->getInstanceId(), 'integer')
337 | );
338 |
339 | $delete_count = SwatDB::exec($this->db, $sql);
340 |
341 | $this->debug(
342 | sprintf(
343 | Deliverance::_(
344 | '%s rows (%s addresses) cleared from the queue.'
345 | ) . "\n",
346 | $delete_count,
347 | count($ids)
348 | )
349 | );
350 | }
351 |
352 | protected function getQuotedIds(array $ids)
353 | {
354 | $quoted_id_array = [];
355 |
356 | foreach ($ids as $id) {
357 | $quoted_id_array[] = $this->db->quote($id, 'integer');
358 | }
359 |
360 | return implode(',', $quoted_id_array);
361 | }
362 |
363 | // boilerplate
364 |
365 | protected function addConfigDefinitions(SiteConfigModule $config)
366 | {
367 | parent::addConfigDefinitions($config);
368 | $config->addDefinitions(Deliverance::getConfigDefinitions());
369 | }
370 |
371 | protected function getDefaultModuleList()
372 | {
373 | return array_merge(
374 | parent::getDefaultModuleList(),
375 | [
376 | 'config' => SiteCommandLineConfigModule::class,
377 | 'database' => SiteDatabaseModule::class,
378 | ]
379 | );
380 | }
381 | }
382 |
--------------------------------------------------------------------------------
/Deliverance/DeliveranceList.php:
--------------------------------------------------------------------------------
1 | app = $app;
60 | $this->shortname = $shortname;
61 | }
62 |
63 | abstract public function isAvailable();
64 |
65 | // subscriber methods
66 |
67 | abstract public function subscribe($address, array $info = []);
68 |
69 | abstract public function batchSubscribe(
70 | array $addresses
71 | );
72 |
73 | public function handleSubscribeResponse($response)
74 | {
75 | switch ($response) {
76 | case self::INVALID:
77 | $message = new SwatMessage(
78 | Deliverance::_(
79 | 'Sorry, the email address you entered is not a valid ' .
80 | 'email address.'
81 | ),
82 | 'error'
83 | );
84 | break;
85 |
86 | case self::FAILURE:
87 | $message = new SwatMessage(
88 | Deliverance::_(
89 | 'Sorry, there was an issue subscribing you to the list.'
90 | ),
91 | 'error'
92 | );
93 |
94 | $message->content_type = 'text/xml';
95 | $message->secondary_content = sprintf(
96 | Deliverance::_(
97 | 'This can usually be resolved by trying again later. If ' .
98 | 'the issue persists please contact us.'
99 | ),
100 | $this->getContactUsLink()
101 | );
102 |
103 | $message->content_type = 'txt/xhtml';
104 | break;
105 |
106 | default:
107 | $message = null;
108 | }
109 |
110 | return $message;
111 | }
112 |
113 | abstract public function unsubscribe($address);
114 |
115 | abstract public function batchUnsubscribe(array $addresses);
116 |
117 | public function handleUnsubscribeResponse($response)
118 | {
119 | switch ($response) {
120 | case self::NOT_FOUND:
121 | $message = new SwatMessage(
122 | Deliverance::_(
123 | 'Thank you. Your email address was never subscribed to ' .
124 | 'our newsletter.'
125 | ),
126 | 'notice'
127 | );
128 |
129 | $message->secondary_content = Deliverance::_(
130 | 'You will not receive any mailings to this address.'
131 | );
132 |
133 | break;
134 |
135 | case self::NOT_SUBSCRIBED:
136 | $message = new SwatMessage(
137 | Deliverance::_(
138 | 'Thank you. Your email address has already been ' .
139 | 'unsubscribed from our newsletter.'
140 | ),
141 | 'notice'
142 | );
143 |
144 | $message->secondary_content = Deliverance::_(
145 | 'You will not receive any mailings to this address.'
146 | );
147 |
148 | break;
149 |
150 | case self::FAILURE:
151 | $message = new SwatMessage(
152 | Deliverance::_(
153 | 'Sorry, there was an issue unsubscribing from the list.'
154 | ),
155 | 'error'
156 | );
157 |
158 | $message->content_type = 'text/xml';
159 | $message->secondary_content = sprintf(
160 | Deliverance::_(
161 | 'This can usually be resolved by trying again later. ' .
162 | 'If the issue persists, please ' .
163 | 'contact us.'
164 | ),
165 | $this->getContactUsLink()
166 | );
167 |
168 | $message->content_type = 'txt/xhtml';
169 | break;
170 |
171 | default:
172 | $message = null;
173 | }
174 |
175 | return $message;
176 | }
177 |
178 | abstract public function isMember($address);
179 |
180 | protected function getContactUsLink()
181 | {
182 | return 'about/contact';
183 | }
184 |
185 | // interest methods
186 |
187 | abstract public function getDefaultSubscriberInfo();
188 |
189 | // queue methods
190 |
191 | /**
192 | * Enqueues a subscribe request for this list.
193 | *
194 | * If a duplicate address is added to the queue, the info field is updated
195 | * instead of inserting a new row. This prevents the queue from growing
196 | * exponentially if list subscribes are unavailable for a long time.
197 | *
198 | * @param string $address
199 | * @param bool $send_welcome
200 | *
201 | * @return int status code for a queued response
202 | */
203 | public function queueSubscribe($address, array $info, $send_welcome = false)
204 | {
205 | $transaction = new SwatDBTransaction($this->app->db);
206 |
207 | try {
208 | $sql = sprintf(
209 | 'select count(1) from MailingListSubscribeQueue
210 | where email = %s and instance %s %s',
211 | $this->app->db->quote($address, 'text'),
212 | SwatDB::equalityOperator($this->app->getInstanceId()),
213 | $this->app->db->quote($this->app->getInstanceId(), 'integer')
214 | );
215 |
216 | if (SwatDB::queryOne($this->app->db, $sql) === 0) {
217 | $sql = sprintf(
218 | 'insert into MailingListSubscribeQueue (
219 | email, info, send_welcome, instance
220 | ) values (%s, %s, %s, %s)',
221 | $this->app->db->quote($address, 'text'),
222 | $this->app->db->quote(serialize($info), 'text'),
223 | $this->app->db->quote($send_welcome, 'boolean'),
224 | $this->app->db->quote(
225 | $this->app->getInstanceId(),
226 | 'integer'
227 | )
228 | );
229 | } else {
230 | $sql = sprintf(
231 | 'update MailingListSubscribeQueue set
232 | info = %s, send_welcome = %s
233 | where email = %s and instance %s %s',
234 | $this->app->db->quote(serialize($info), 'text'),
235 | $this->app->db->quote($send_welcome, 'boolean'),
236 | $this->app->db->quote($address, 'text'),
237 | SwatDB::equalityOperator($this->app->getInstanceId()),
238 | $this->app->db->quote(
239 | $this->app->getInstanceId(),
240 | 'integer'
241 | )
242 | );
243 | }
244 |
245 | SwatDB::exec($this->app->db, $sql);
246 |
247 | $transaction->commit();
248 | } catch (SwatDBException $e) {
249 | $transaction->rollback();
250 |
251 | throw $e;
252 | }
253 |
254 | return self::QUEUED;
255 | }
256 |
257 | /**
258 | * Enqueues an update subscription request for this list.
259 | *
260 | * Duplicate rows are not added to the queue. This prevents the queue from
261 | * growing exponentially if list updates are unavailable for a long time.
262 | *
263 | * @param string $address
264 | *
265 | * @return int status code for a queued response
266 | */
267 | public function queueUpdate($address, array $info)
268 | {
269 | $info = serialize($info);
270 |
271 | $transaction = new SwatDBTransaction($this->app->db);
272 |
273 | try {
274 | $sql = sprintf(
275 | 'select count(1) from MailingListUpdateQueue
276 | where email = %s and info = %s and instance %s %s',
277 | $this->app->db->quote($address, 'text'),
278 | $this->app->db->quote($info, 'text'),
279 | SwatDB::equalityOperator($this->app->getInstanceId()),
280 | $this->app->db->quote($this->app->getInstanceId(), 'integer')
281 | );
282 |
283 | if (SwatDB::queryOne($this->app->db, $sql) === 0) {
284 | $sql = sprintf(
285 | 'insert into MailingListUpdateQueue (
286 | email, info, instance
287 | ) values (%s, %s, %s)',
288 | $this->app->db->quote($address, 'text'),
289 | $this->app->db->quote($info, 'text'),
290 | $this->app->db->quote(
291 | $this->app->getInstanceId(),
292 | 'integer'
293 | )
294 | );
295 |
296 | SwatDB::exec($this->app->db, $sql);
297 | }
298 |
299 | $transaction->commit();
300 | } catch (SwatDBException $e) {
301 | $transaction->rollback();
302 |
303 | throw $e;
304 | }
305 |
306 | return self::QUEUED;
307 | }
308 |
309 | /**
310 | * Enqueues an unsubscribe request for this list.
311 | *
312 | * Duplicate address are not added to the queue to prevent the queue from
313 | * growing exponentially if list unsubscribes are unavailable for a long
314 | * time.
315 | *
316 | * @param string $address
317 | *
318 | * @return int status code for a queued response
319 | */
320 | public function queueUnsubscribe($address)
321 | {
322 | $transaction = new SwatDBTransaction($this->app->db);
323 |
324 | try {
325 | $sql = sprintf(
326 | 'select count(1) from MailingListUnsubscribeQueue
327 | where email = %s and instance %s %s',
328 | $this->app->db->quote($address, 'text'),
329 | SwatDB::equalityOperator($this->app->getInstanceId()),
330 | $this->app->db->quote($this->app->getInstanceId(), 'integer')
331 | );
332 |
333 | if (SwatDB::queryOne($this->app->db, $sql) === 0) {
334 | $sql = sprintf(
335 | 'insert into MailingListUnsubscribeQueue
336 | (email, instance) values (%s, %s)',
337 | $this->app->db->quote($address, 'text'),
338 | $this->app->db->quote(
339 | $this->app->getInstanceId(),
340 | 'integer'
341 | )
342 | );
343 | SwatDB::exec($this->app->db, $sql);
344 | }
345 |
346 | $transaction->commit();
347 | } catch (SwatDBException $e) {
348 | $transaction->rollback();
349 |
350 | throw $e;
351 | }
352 |
353 | return self::QUEUED;
354 | }
355 |
356 | public function getShortname()
357 | {
358 | return $this->shortname;
359 | }
360 | }
361 |
--------------------------------------------------------------------------------
/Deliverance/DeliveranceMailChimpList.php:
--------------------------------------------------------------------------------
1 | 'null',
49 | 'city' => 'null',
50 | 'state' => 'null',
51 | 'zip' => 'null',
52 | ];
53 |
54 | protected $client;
55 |
56 | /**
57 | * The timeout length for any MailChimp client request.
58 | *
59 | * @var int
60 | */
61 | protected $client_timeout;
62 |
63 | protected $list_merge_array_map = [];
64 |
65 | /**
66 | * Email type subscribes wish to receive.
67 | *
68 | * Valid email types are class constants starting with EMAIL_TYPE_*
69 | *
70 | * @var string
71 | */
72 | protected $email_type = self::EMAIL_TYPE_HTML;
73 |
74 | /**
75 | * @var DeliveranceMailingListInterestWrapper
76 | */
77 | protected $interests;
78 |
79 | public function __construct(SiteApplication $app, $shortname = null)
80 | {
81 | parent::__construct($app, $shortname);
82 |
83 | $this->client = new MailChimp($this->getApiKey());
84 |
85 | // by default if the connection takes longer than 1s timeout. This will
86 | // prevent users from waiting too long when MailChimp is down - requests
87 | // will just get queued. Without setting this, the default timeout is
88 | // 10 seconds
89 | $this->setTimeout($app->config->deliverance->list_connection_timeout);
90 |
91 | if ($this->shortname === null) {
92 | $this->shortname = $app->config->mail_chimp->default_list;
93 | }
94 |
95 | $this->initListMergeArrayMap();
96 | }
97 |
98 | public function setEmailType($email_type)
99 | {
100 | $this->email_type = $email_type;
101 | }
102 |
103 | public function setTimeout($timeout)
104 | {
105 | $this->client_timeout = intval($timeout);
106 | }
107 |
108 | /**
109 | * Tests to make sure the service is available.
110 | *
111 | * Returns false if MailChimp returns an unexpected value or the
112 | * MailChimpAPI throws an exception. Unexpected values from MailChimp
113 | * get thrown in exceptions as well. Any exceptions thrown are not exited
114 | * on, so that we can queue requests based on service availability.
115 | *
116 | * @return bool whether or not the service is available
117 | */
118 | public function isAvailable()
119 | {
120 | $available = false;
121 |
122 | try {
123 | $result = $this->callClientMethod('GET', 'ping');
124 |
125 | // Endearing? Yes. But also annoying to have to check for a string.
126 | $available = ($result['health_status'] === "Everything's Chimpy!");
127 | } catch (DeliveranceMailChimpTimeoutException $e) {
128 | // exception is known, API is not available.
129 | }
130 |
131 | return $available;
132 | }
133 |
134 | protected function initListMergeArrayMap()
135 | {
136 | $this->list_merge_array_map = [
137 | 'email' => 'EMAIL', // only used for batch subscribes
138 | 'first_name' => 'FNAME',
139 | 'last_name' => 'LNAME',
140 | 'user_ip' => 'OPTIN_IP',
141 | ];
142 | }
143 |
144 | // subscriber methods
145 |
146 | public function subscribe($address, array $info = [])
147 | {
148 | $result = false;
149 | $queue_request = false;
150 |
151 | if ($this->isAvailable()) {
152 | $merges = $this->mergeInfo($info);
153 | $interests = $this->interestInfo($info);
154 |
155 | try {
156 | $result = $this->callClientMethod(
157 | 'PUT',
158 | sprintf(
159 | 'lists/%s/members/%s',
160 | $this->shortname,
161 | $this->client->subscriberHash($address)
162 | ),
163 | [
164 | 'email_address' => $address,
165 | 'email_type' => $this->email_type,
166 | 'status' => 'subscribed',
167 | 'merge_fields' => $merges,
168 | 'interests' => $interests,
169 | ]
170 | );
171 | } catch (DeliveranceMailChimpTimeoutException $e) {
172 | $queue_request = true;
173 | } catch (DeliveranceMailChimpServerException $e) {
174 | $queue_request = true;
175 | } catch (DeliveranceMailChimpClientException $e) {
176 | $e->processAndContinue();
177 |
178 | $result = DeliveranceList::FAILURE;
179 | } catch (Exception $e) {
180 | throw new DeliveranceException($e);
181 | }
182 | } else {
183 | $queue_request = true;
184 | }
185 |
186 | if ($queue_request && $this->app->hasModule('SiteDatabaseModule')) {
187 | $result = $this->queueSubscribe($address, $info);
188 | }
189 |
190 | if ($result === true) {
191 | $result = self::SUCCESS;
192 | } elseif ($result === false) {
193 | $result = self::FAILURE;
194 | }
195 |
196 | return $result;
197 | }
198 |
199 | public function batchSubscribe(array $addresses)
200 | {
201 | $success_ids = [];
202 |
203 | if ($this->isAvailable()) {
204 | $count = 0;
205 |
206 | $batch = new MailChimpBatch($this->client);
207 | foreach ($addresses as $info) {
208 | $count++;
209 |
210 | $merges = $this->mergeInfo($info);
211 | $interests = $this->interestInfo($info);
212 |
213 | $batch->put(
214 | strval($info['id']),
215 | sprintf(
216 | 'lists/%s/members/%s',
217 | $this->shortname,
218 | $this->client->subscriberHash($info['email'])
219 | ),
220 | [
221 | 'email_address' => $info['email'],
222 | 'email_type' => $this->email_type,
223 | 'status' => 'subscribed',
224 | 'merge_fields' => $merges,
225 | 'interests' => $interests,
226 | ]
227 | );
228 |
229 | $full_batch = ($count % self::BATCH_SIZE === 0);
230 | $last_entry = ($count === count($addresses));
231 |
232 | if (($full_batch || $last_entry) && ($count > 0)) {
233 | try {
234 | $batch->execute();
235 | $this->handleClientErrors();
236 |
237 | do {
238 | sleep(self::POLLING_INTERVAL);
239 |
240 | $result = $batch->check_status();
241 | $this->handleClientErrors();
242 | } while ($result['status'] !== 'finished');
243 |
244 | foreach ($batch->get_operations() as $operation) {
245 | $success_ids[] = intval($operation['operation_id']);
246 | }
247 |
248 | $batch = new MailChimpBatch($this->client);
249 | } catch (DeliveranceMailChimpTimeoutException $e) {
250 | // If we catch an exception we process it and break from
251 | // the loop. Any sucessfully processed IDs will be returned
252 | // and the rest will stay in the queue.
253 | break;
254 | } catch (DeliveranceException $e) {
255 | $e->processAndContinue();
256 | break;
257 | }
258 | }
259 | }
260 | }
261 |
262 | return $success_ids;
263 | }
264 |
265 | public function update($address, array $info = [])
266 | {
267 | $result = false;
268 | $queue_request = false;
269 |
270 | if ($this->isAvailable()) {
271 | $merges = $this->mergeInfo($info);
272 | $interests = $this->interestInfo($info);
273 |
274 | try {
275 | $result = $this->callClientMethod(
276 | 'PATCH',
277 | sprintf(
278 | 'lists/%s/members/%s',
279 | $this->shortname,
280 | $this->client->subscriberHash($address)
281 | ),
282 | [
283 | 'email_address' => $address,
284 | 'merge_fields' => $merges,
285 | 'interests' => $interests,
286 | ]
287 | );
288 | } catch (DeliveranceMailChimpTimeoutException $e) {
289 | $queue_request = true;
290 | } catch (DeliveranceMailChimpServerException $e) {
291 | $queue_request = true;
292 | } catch (DeliveranceMailChimpClientException $e) {
293 | $result = DeliveranceList::INVALID;
294 | } catch (Exception $e) {
295 | throw new DeliveranceException($e);
296 | }
297 | } else {
298 | $queue_request = true;
299 | }
300 |
301 | if ($queue_request && $this->app->hasModule('SiteDatabaseModule')) {
302 | $result = $this->queueUpdate($address, $info);
303 | }
304 |
305 | if ($result === true) {
306 | $result = self::SUCCESS;
307 | } elseif ($result === false) {
308 | $result = self::FAILURE;
309 | }
310 |
311 | return $result;
312 | }
313 |
314 | public function batchUpdate(array $addresses)
315 | {
316 | $success_ids = [];
317 |
318 | if ($this->isAvailable()) {
319 | $count = 0;
320 |
321 | $batch = new MailChimpBatch($this->client);
322 | foreach ($addresses as $info) {
323 | $count++;
324 |
325 | $merges = $this->mergeInfo($info);
326 | $interests = $this->interestInfo($info);
327 |
328 | $batch->patch(
329 | strval($info['id']),
330 | sprintf(
331 | 'lists/%s/members/%s',
332 | $this->shortname,
333 | $this->client->subscriberHash($info['email'])
334 | ),
335 | [
336 | 'email_address' => $info['email'],
337 | 'merge_fields' => $merges,
338 | 'interests' => $interests,
339 | ]
340 | );
341 |
342 | $full_batch = ($count % self::BATCH_SIZE === 0);
343 | $last_entry = ($count === count($addresses));
344 |
345 | if (($full_batch || $last_entry) && ($count > 0)) {
346 | try {
347 | $batch->execute();
348 | $this->handleClientErrors();
349 |
350 | do {
351 | sleep(self::POLLING_INTERVAL);
352 |
353 | $result = $batch->check_status();
354 | $this->handleClientErrors();
355 | } while ($result['status'] !== 'finished');
356 |
357 | foreach ($batch->get_operations() as $operation) {
358 | $success_ids[] = intval($operation['operation_id']);
359 | }
360 |
361 | $batch = new MailChimpBatch($this->client);
362 | } catch (DeliveranceMailChimpTimeoutException $e) {
363 | // If we catch an exception we process it and break from
364 | // the loop. Any sucessfully processed IDs will be returned
365 | // and the rest will stay in the queue.
366 | break;
367 | } catch (DeliveranceException $e) {
368 | $e->processAndContinue();
369 | break;
370 | }
371 | }
372 | }
373 | }
374 |
375 | return $success_ids;
376 | }
377 |
378 | public function unsubscribe($address)
379 | {
380 | $result = false;
381 | $queue_request = false;
382 |
383 | if ($this->isAvailable()) {
384 | try {
385 | $result = $this->callClientMethod(
386 | 'PATCH',
387 | sprintf(
388 | 'lists/%s/members/%s',
389 | $this->shortname,
390 | $this->client->subscriberHash($address)
391 | ),
392 | [
393 | 'email_address' => $address,
394 | 'status' => 'unsubscribed',
395 | ]
396 | );
397 | } catch (DeliveranceMailChimpTimeoutException $e) {
398 | $queue_request = true;
399 | } catch (DeliveranceMailChimpClientException $e) {
400 | // gracefully handle exceptions that we can provide nice
401 | // feedback about.
402 | switch ($e->getCode()) {
403 | case 404:
404 | $result = DeliveranceList::NOT_FOUND;
405 | break;
406 |
407 | default:
408 | throw $e;
409 | }
410 | } catch (Exception $e) {
411 | throw new DeliveranceException($e);
412 | }
413 | } else {
414 | $queue_request = true;
415 | }
416 |
417 | if ($queue_request && $this->app->hasModule('SiteDatabaseModule')) {
418 | $result = $this->queueUnsubscribe($address);
419 | }
420 |
421 | if ($result === true) {
422 | $result = self::SUCCESS;
423 | } elseif ($result === false) {
424 | $result = self::FAILURE;
425 | }
426 |
427 | return $result;
428 | }
429 |
430 | public function batchUnsubscribe(array $addresses)
431 | {
432 | $success_ids = [];
433 |
434 | if ($this->isAvailable()) {
435 | $count = 0;
436 |
437 | $batch = new MailChimpBatch($this->client);
438 | foreach ($addresses as $id => $email) {
439 | $count++;
440 |
441 | $batch->patch(
442 | strval($id),
443 | sprintf(
444 | 'lists/%s/members/%s',
445 | $this->shortname,
446 | $this->client->subscriberHash($email)
447 | ),
448 | [
449 | 'email_address' => $email,
450 | 'status' => 'unsubscribed',
451 | ]
452 | );
453 |
454 | $full_batch = ($count % self::BATCH_SIZE === 0);
455 | $last_entry = ($count === count($addresses));
456 |
457 | if (($full_batch || $last_entry) && ($count > 0)) {
458 | try {
459 | $batch->execute();
460 | $this->handleClientErrors();
461 |
462 | do {
463 | sleep(self::POLLING_INTERVAL);
464 |
465 | $result = $batch->check_status();
466 | $this->handleClientErrors();
467 | } while ($result['status'] !== 'finished');
468 |
469 | foreach ($batch->get_operations() as $operation) {
470 | $success_ids[] = intval($operation['operation_id']);
471 | }
472 |
473 | $batch = new MailChimpBatch($this->client);
474 | } catch (DeliveranceMailChimpTimeoutException $e) {
475 | // If we catch an exception we process it and break from
476 | // the loop. Any sucessfully processed IDs will be returned
477 | // and the rest will stay in the queue.
478 | break;
479 | } catch (DeliveranceException $e) {
480 | $e->processAndContinue();
481 | break;
482 | }
483 | }
484 | }
485 | }
486 |
487 | return $success_ids;
488 | }
489 |
490 | public function isMember($address)
491 | {
492 | // Status of subscribed is the only way we can validate a current member
493 | return $this->isSubscribedMember($this->getMemberInfo($address));
494 | }
495 |
496 | public function wasMember($address)
497 | {
498 | return $this->isUnsubscribedMember($this->getMemberInfo($address));
499 | }
500 |
501 | public function hasEverBeenMember($address)
502 | {
503 | $info = $this->getMemberInfo($address);
504 |
505 | return
506 | $this->isSubscribedMember($info)
507 | || $this->isUnsubscribedMember($info);
508 | }
509 |
510 | public function getMemberInfo($address)
511 | {
512 | $member_info = null;
513 |
514 | if ($this->isAvailable()) {
515 | try {
516 | $member_info = $this->callClientMethod(
517 | 'GET',
518 | sprintf(
519 | 'lists/%s/members/%s',
520 | $this->shortname,
521 | $this->client->subscriberHash($address)
522 | )
523 | );
524 | } catch (DeliveranceMailChimpTimeoutException $e) {
525 | // Ignore timeouts
526 | } catch (DeliveranceMailChimpClientException $e) {
527 | // Ignore 400 level server exceptions
528 | }
529 | }
530 |
531 | return $member_info;
532 | }
533 |
534 | protected function mergeInfo(array $info)
535 | {
536 | $array_map = $this->list_merge_array_map;
537 |
538 | $merges = new stdClass();
539 | foreach ($info as $id => $value) {
540 | if (array_key_exists($id, $array_map) && $value != null) {
541 | $merges->{$array_map[$id]} = $value;
542 | }
543 | }
544 |
545 | return $merges;
546 | }
547 |
548 | protected function interestInfo(array $info)
549 | {
550 | $interests = new stdClass();
551 |
552 | $selected_interests = array_key_exists('interests', $info) ?
553 | $info['interests'] : [];
554 |
555 | $deactivated_interests = array_key_exists('deactivated_interests', $info) ?
556 | $info['deactivated_interests'] : [];
557 |
558 | foreach ($deactivated_interests as $deactivated_interest) {
559 | $interests->{$deactivated_interest} = false;
560 | }
561 |
562 | foreach ($selected_interests as $interest) {
563 | $interests->{$interest} = true;
564 | }
565 |
566 | return $interests;
567 | }
568 |
569 | public function getDefaultAddress()
570 | {
571 | // TODO: do this better somehow
572 | return $this->default_address;
573 | }
574 |
575 | protected function isSubscribedMember($member_info)
576 | {
577 | return
578 | is_array($member_info)
579 | && isset($member_info['status'])
580 | && $member_info['status'] === 'subscribed';
581 | }
582 |
583 | protected function isUnsubscribedMember($member_info)
584 | {
585 | return
586 | is_array($member_info)
587 | && isset($member_info['status'])
588 | && $member_info['status'] === 'unsubscribed';
589 | }
590 |
591 | // interest methods
592 |
593 | public function getDefaultSubscriberInfo()
594 | {
595 | $info = ['user_ip' => $this->app->getRemoteIP()];
596 |
597 | $interests = $this->getInterests()->getDefaultShortnames();
598 | if (count($interests) > 0) {
599 | $info['interests'] = $interests;
600 | }
601 |
602 | return $info;
603 | }
604 |
605 | public function getInterests()
606 | {
607 | $class_name = SwatDBClassMap::get(
608 | DeliveranceMailingListInterestWrapper::class
609 | );
610 |
611 | if (
612 | $this->app->hasModule('SiteDatabaseModule')
613 | && !($this->interests instanceof $class_name)
614 | ) {
615 | $instance_id = $this->app->getInstanceId();
616 |
617 | $this->interests = SwatDB::query(
618 | $this->app->db,
619 | sprintf(
620 | 'select * from MailingListInterest
621 | where instance %s %s order by displayorder',
622 | SwatDB::equalityOperator($instance_id),
623 | $this->app->db->quote($instance_id, 'integer')
624 | ),
625 | $class_name
626 | );
627 | }
628 |
629 | return $this->interests;
630 | }
631 |
632 | // list setup helper methods
633 |
634 | public function getApiKey()
635 | {
636 | return $this->app->config->mail_chimp->api_key;
637 | }
638 |
639 | // exception throwing and handling
640 |
641 | private function callClientMethod($verb, $method, array $args = [])
642 | {
643 | switch ($verb) {
644 | case 'DELETE':
645 | $result = $this->client->delete(
646 | $method,
647 | $args,
648 | $this->client_timeout
649 | );
650 |
651 | break;
652 |
653 | case 'GET':
654 | $result = $this->client->get(
655 | $method,
656 | $args,
657 | $this->client_timeout
658 | );
659 |
660 | break;
661 |
662 | case 'PATCH':
663 | $result = $this->client->patch(
664 | $method,
665 | $args,
666 | $this->client_timeout
667 | );
668 |
669 | break;
670 |
671 | case 'POST':
672 | $result = $this->client->post(
673 | $method,
674 | $args,
675 | $this->client_timeout
676 | );
677 |
678 | break;
679 |
680 | case 'PUT':
681 | $result = $this->client->put(
682 | $method,
683 | $args,
684 | $this->client_timeout
685 | );
686 |
687 | break;
688 |
689 | default:
690 | throw new DeliveranceException(
691 | sprintf('Unknown HTTP verb ‘%s’ used.', $verb)
692 | );
693 | }
694 |
695 | $this->handleClientErrors();
696 |
697 | return $result;
698 | }
699 |
700 | private function handleClientErrors()
701 | {
702 | if (!$this->client->success()) {
703 | $last_response = $this->client->getLastResponse();
704 |
705 | if ($last_response['headers']['total_time'] > $this->client_timeout) {
706 | throw new DeliveranceMailChimpTimeoutException(
707 | sprintf(
708 | 'The connection to the MailChimp ' .
709 | 'API timed out after ‘%s’ seconds.',
710 | $this->client_timeout
711 | )
712 | );
713 | }
714 |
715 | $error = json_decode($last_response['body']);
716 | if ($error === null) {
717 | throw new DeliveranceException(
718 | sprintf(
719 | 'Unable to decode JSON received from MailChimp. ' .
720 | 'See the following response for more details: %s',
721 | print_r($last_response, true)
722 | )
723 | );
724 | }
725 |
726 | // Server exceptions
727 | if ($last_response['headers']['http_code'] >= 500) {
728 | throw new DeliveranceMailChimpServerException(
729 | sprintf('%s: %s', $error->title, $error->detail),
730 | $error->status
731 | );
732 | }
733 |
734 | // Client exceptions
735 | if ($last_response['headers']['http_code'] >= 400) {
736 | throw new DeliveranceMailChimpClientException(
737 | sprintf('%s: %s', $error->title, $error->detail),
738 | $error->status
739 | );
740 | }
741 |
742 | // Unknown exception - provide as much detail as possible.
743 | throw new DeliveranceException(
744 | sprintf(
745 | 'An unknown error occured when connecting to MailChimp. ' .
746 | 'See the following response for more details: %s',
747 | print_r($last_response, true)
748 | )
749 | );
750 | }
751 | }
752 | }
753 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 2.1, February 1999
3 |
4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | [This is the first released version of the Lesser GPL. It also counts
10 | as the successor of the GNU Library Public License, version 2, hence
11 | the version number 2.1.]
12 |
13 | Preamble
14 |
15 | The licenses for most software are designed to take away your
16 | freedom to share and change it. By contrast, the GNU General Public
17 | Licenses are intended to guarantee your freedom to share and change
18 | free software--to make sure the software is free for all its users.
19 |
20 | This license, the Lesser General Public License, applies to some
21 | specially designated software packages--typically libraries--of the
22 | Free Software Foundation and other authors who decide to use it. You
23 | can use it too, but we suggest you first think carefully about whether
24 | this license or the ordinary General Public License is the better
25 | strategy to use in any particular case, based on the explanations below.
26 |
27 | When we speak of free software, we are referring to freedom of use,
28 | not price. Our General Public Licenses are designed to make sure that
29 | you have the freedom to distribute copies of free software (and charge
30 | for this service if you wish); that you receive source code or can get
31 | it if you want it; that you can change the software and use pieces of
32 | it in new free programs; and that you are informed that you can do
33 | these things.
34 |
35 | To protect your rights, we need to make restrictions that forbid
36 | distributors to deny you these rights or to ask you to surrender these
37 | rights. These restrictions translate to certain responsibilities for
38 | you if you distribute copies of the library or if you modify it.
39 |
40 | For example, if you distribute copies of the library, whether gratis
41 | or for a fee, you must give the recipients all the rights that we gave
42 | you. You must make sure that they, too, receive or can get the source
43 | code. If you link other code with the library, you must provide
44 | complete object files to the recipients, so that they can relink them
45 | with the library after making changes to the library and recompiling
46 | it. And you must show them these terms so they know their rights.
47 |
48 | We protect your rights with a two-step method: (1) we copyright the
49 | library, and (2) we offer you this license, which gives you legal
50 | permission to copy, distribute and/or modify the library.
51 |
52 | To protect each distributor, we want to make it very clear that
53 | there is no warranty for the free library. Also, if the library is
54 | modified by someone else and passed on, the recipients should know
55 | that what they have is not the original version, so that the original
56 | author's reputation will not be affected by problems that might be
57 | introduced by others.
58 |
59 | Finally, software patents pose a constant threat to the existence of
60 | any free program. We wish to make sure that a company cannot
61 | effectively restrict the users of a free program by obtaining a
62 | restrictive license from a patent holder. Therefore, we insist that
63 | any patent license obtained for a version of the library must be
64 | consistent with the full freedom of use specified in this license.
65 |
66 | Most GNU software, including some libraries, is covered by the
67 | ordinary GNU General Public License. This license, the GNU Lesser
68 | General Public License, applies to certain designated libraries, and
69 | is quite different from the ordinary General Public License. We use
70 | this license for certain libraries in order to permit linking those
71 | libraries into non-free programs.
72 |
73 | When a program is linked with a library, whether statically or using
74 | a shared library, the combination of the two is legally speaking a
75 | combined work, a derivative of the original library. The ordinary
76 | General Public License therefore permits such linking only if the
77 | entire combination fits its criteria of freedom. The Lesser General
78 | Public License permits more lax criteria for linking other code with
79 | the library.
80 |
81 | We call this license the "Lesser" General Public License because it
82 | does Less to protect the user's freedom than the ordinary General
83 | Public License. It also provides other free software developers Less
84 | of an advantage over competing non-free programs. These disadvantages
85 | are the reason we use the ordinary General Public License for many
86 | libraries. However, the Lesser license provides advantages in certain
87 | special circumstances.
88 |
89 | For example, on rare occasions, there may be a special need to
90 | encourage the widest possible use of a certain library, so that it becomes
91 | a de-facto standard. To achieve this, non-free programs must be
92 | allowed to use the library. A more frequent case is that a free
93 | library does the same job as widely used non-free libraries. In this
94 | case, there is little to gain by limiting the free library to free
95 | software only, so we use the Lesser General Public License.
96 |
97 | In other cases, permission to use a particular library in non-free
98 | programs enables a greater number of people to use a large body of
99 | free software. For example, permission to use the GNU C Library in
100 | non-free programs enables many more people to use the whole GNU
101 | operating system, as well as its variant, the GNU/Linux operating
102 | system.
103 |
104 | Although the Lesser General Public License is Less protective of the
105 | users' freedom, it does ensure that the user of a program that is
106 | linked with the Library has the freedom and the wherewithal to run
107 | that program using a modified version of the Library.
108 |
109 | The precise terms and conditions for copying, distribution and
110 | modification follow. Pay close attention to the difference between a
111 | "work based on the library" and a "work that uses the library". The
112 | former contains code derived from the library, whereas the latter must
113 | be combined with the library in order to run.
114 |
115 | GNU LESSER GENERAL PUBLIC LICENSE
116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117 |
118 | 0. This License Agreement applies to any software library or other
119 | program which contains a notice placed by the copyright holder or
120 | other authorized party saying it may be distributed under the terms of
121 | this Lesser General Public License (also called "this License").
122 | Each licensee is addressed as "you".
123 |
124 | A "library" means a collection of software functions and/or data
125 | prepared so as to be conveniently linked with application programs
126 | (which use some of those functions and data) to form executables.
127 |
128 | The "Library", below, refers to any such software library or work
129 | which has been distributed under these terms. A "work based on the
130 | Library" means either the Library or any derivative work under
131 | copyright law: that is to say, a work containing the Library or a
132 | portion of it, either verbatim or with modifications and/or translated
133 | straightforwardly into another language. (Hereinafter, translation is
134 | included without limitation in the term "modification".)
135 |
136 | "Source code" for a work means the preferred form of the work for
137 | making modifications to it. For a library, complete source code means
138 | all the source code for all modules it contains, plus any associated
139 | interface definition files, plus the scripts used to control compilation
140 | and installation of the library.
141 |
142 | Activities other than copying, distribution and modification are not
143 | covered by this License; they are outside its scope. The act of
144 | running a program using the Library is not restricted, and output from
145 | such a program is covered only if its contents constitute a work based
146 | on the Library (independent of the use of the Library in a tool for
147 | writing it). Whether that is true depends on what the Library does
148 | and what the program that uses the Library does.
149 |
150 | 1. You may copy and distribute verbatim copies of the Library's
151 | complete source code as you receive it, in any medium, provided that
152 | you conspicuously and appropriately publish on each copy an
153 | appropriate copyright notice and disclaimer of warranty; keep intact
154 | all the notices that refer to this License and to the absence of any
155 | warranty; and distribute a copy of this License along with the
156 | Library.
157 |
158 | You may charge a fee for the physical act of transferring a copy,
159 | and you may at your option offer warranty protection in exchange for a
160 | fee.
161 |
162 | 2. You may modify your copy or copies of the Library or any portion
163 | of it, thus forming a work based on the Library, and copy and
164 | distribute such modifications or work under the terms of Section 1
165 | above, provided that you also meet all of these conditions:
166 |
167 | a) The modified work must itself be a software library.
168 |
169 | b) You must cause the files modified to carry prominent notices
170 | stating that you changed the files and the date of any change.
171 |
172 | c) You must cause the whole of the work to be licensed at no
173 | charge to all third parties under the terms of this License.
174 |
175 | d) If a facility in the modified Library refers to a function or a
176 | table of data to be supplied by an application program that uses
177 | the facility, other than as an argument passed when the facility
178 | is invoked, then you must make a good faith effort to ensure that,
179 | in the event an application does not supply such function or
180 | table, the facility still operates, and performs whatever part of
181 | its purpose remains meaningful.
182 |
183 | (For example, a function in a library to compute square roots has
184 | a purpose that is entirely well-defined independent of the
185 | application. Therefore, Subsection 2d requires that any
186 | application-supplied function or table used by this function must
187 | be optional: if the application does not supply it, the square
188 | root function must still compute square roots.)
189 |
190 | These requirements apply to the modified work as a whole. If
191 | identifiable sections of that work are not derived from the Library,
192 | and can be reasonably considered independent and separate works in
193 | themselves, then this License, and its terms, do not apply to those
194 | sections when you distribute them as separate works. But when you
195 | distribute the same sections as part of a whole which is a work based
196 | on the Library, the distribution of the whole must be on the terms of
197 | this License, whose permissions for other licensees extend to the
198 | entire whole, and thus to each and every part regardless of who wrote
199 | it.
200 |
201 | Thus, it is not the intent of this section to claim rights or contest
202 | your rights to work written entirely by you; rather, the intent is to
203 | exercise the right to control the distribution of derivative or
204 | collective works based on the Library.
205 |
206 | In addition, mere aggregation of another work not based on the Library
207 | with the Library (or with a work based on the Library) on a volume of
208 | a storage or distribution medium does not bring the other work under
209 | the scope of this License.
210 |
211 | 3. You may opt to apply the terms of the ordinary GNU General Public
212 | License instead of this License to a given copy of the Library. To do
213 | this, you must alter all the notices that refer to this License, so
214 | that they refer to the ordinary GNU General Public License, version 2,
215 | instead of to this License. (If a newer version than version 2 of the
216 | ordinary GNU General Public License has appeared, then you can specify
217 | that version instead if you wish.) Do not make any other change in
218 | these notices.
219 |
220 | Once this change is made in a given copy, it is irreversible for
221 | that copy, so the ordinary GNU General Public License applies to all
222 | subsequent copies and derivative works made from that copy.
223 |
224 | This option is useful when you wish to copy part of the code of
225 | the Library into a program that is not a library.
226 |
227 | 4. You may copy and distribute the Library (or a portion or
228 | derivative of it, under Section 2) in object code or executable form
229 | under the terms of Sections 1 and 2 above provided that you accompany
230 | it with the complete corresponding machine-readable source code, which
231 | must be distributed under the terms of Sections 1 and 2 above on a
232 | medium customarily used for software interchange.
233 |
234 | If distribution of object code is made by offering access to copy
235 | from a designated place, then offering equivalent access to copy the
236 | source code from the same place satisfies the requirement to
237 | distribute the source code, even though third parties are not
238 | compelled to copy the source along with the object code.
239 |
240 | 5. A program that contains no derivative of any portion of the
241 | Library, but is designed to work with the Library by being compiled or
242 | linked with it, is called a "work that uses the Library". Such a
243 | work, in isolation, is not a derivative work of the Library, and
244 | therefore falls outside the scope of this License.
245 |
246 | However, linking a "work that uses the Library" with the Library
247 | creates an executable that is a derivative of the Library (because it
248 | contains portions of the Library), rather than a "work that uses the
249 | library". The executable is therefore covered by this License.
250 | Section 6 states terms for distribution of such executables.
251 |
252 | When a "work that uses the Library" uses material from a header file
253 | that is part of the Library, the object code for the work may be a
254 | derivative work of the Library even though the source code is not.
255 | Whether this is true is especially significant if the work can be
256 | linked without the Library, or if the work is itself a library. The
257 | threshold for this to be true is not precisely defined by law.
258 |
259 | If such an object file uses only numerical parameters, data
260 | structure layouts and accessors, and small macros and small inline
261 | functions (ten lines or less in length), then the use of the object
262 | file is unrestricted, regardless of whether it is legally a derivative
263 | work. (Executables containing this object code plus portions of the
264 | Library will still fall under Section 6.)
265 |
266 | Otherwise, if the work is a derivative of the Library, you may
267 | distribute the object code for the work under the terms of Section 6.
268 | Any executables containing that work also fall under Section 6,
269 | whether or not they are linked directly with the Library itself.
270 |
271 | 6. As an exception to the Sections above, you may also combine or
272 | link a "work that uses the Library" with the Library to produce a
273 | work containing portions of the Library, and distribute that work
274 | under terms of your choice, provided that the terms permit
275 | modification of the work for the customer's own use and reverse
276 | engineering for debugging such modifications.
277 |
278 | You must give prominent notice with each copy of the work that the
279 | Library is used in it and that the Library and its use are covered by
280 | this License. You must supply a copy of this License. If the work
281 | during execution displays copyright notices, you must include the
282 | copyright notice for the Library among them, as well as a reference
283 | directing the user to the copy of this License. Also, you must do one
284 | of these things:
285 |
286 | a) Accompany the work with the complete corresponding
287 | machine-readable source code for the Library including whatever
288 | changes were used in the work (which must be distributed under
289 | Sections 1 and 2 above); and, if the work is an executable linked
290 | with the Library, with the complete machine-readable "work that
291 | uses the Library", as object code and/or source code, so that the
292 | user can modify the Library and then relink to produce a modified
293 | executable containing the modified Library. (It is understood
294 | that the user who changes the contents of definitions files in the
295 | Library will not necessarily be able to recompile the application
296 | to use the modified definitions.)
297 |
298 | b) Use a suitable shared library mechanism for linking with the
299 | Library. A suitable mechanism is one that (1) uses at run time a
300 | copy of the library already present on the user's computer system,
301 | rather than copying library functions into the executable, and (2)
302 | will operate properly with a modified version of the library, if
303 | the user installs one, as long as the modified version is
304 | interface-compatible with the version that the work was made with.
305 |
306 | c) Accompany the work with a written offer, valid for at
307 | least three years, to give the same user the materials
308 | specified in Subsection 6a, above, for a charge no more
309 | than the cost of performing this distribution.
310 |
311 | d) If distribution of the work is made by offering access to copy
312 | from a designated place, offer equivalent access to copy the above
313 | specified materials from the same place.
314 |
315 | e) Verify that the user has already received a copy of these
316 | materials or that you have already sent this user a copy.
317 |
318 | For an executable, the required form of the "work that uses the
319 | Library" must include any data and utility programs needed for
320 | reproducing the executable from it. However, as a special exception,
321 | the materials to be distributed need not include anything that is
322 | normally distributed (in either source or binary form) with the major
323 | components (compiler, kernel, and so on) of the operating system on
324 | which the executable runs, unless that component itself accompanies
325 | the executable.
326 |
327 | It may happen that this requirement contradicts the license
328 | restrictions of other proprietary libraries that do not normally
329 | accompany the operating system. Such a contradiction means you cannot
330 | use both them and the Library together in an executable that you
331 | distribute.
332 |
333 | 7. You may place library facilities that are a work based on the
334 | Library side-by-side in a single library together with other library
335 | facilities not covered by this License, and distribute such a combined
336 | library, provided that the separate distribution of the work based on
337 | the Library and of the other library facilities is otherwise
338 | permitted, and provided that you do these two things:
339 |
340 | a) Accompany the combined library with a copy of the same work
341 | based on the Library, uncombined with any other library
342 | facilities. This must be distributed under the terms of the
343 | Sections above.
344 |
345 | b) Give prominent notice with the combined library of the fact
346 | that part of it is a work based on the Library, and explaining
347 | where to find the accompanying uncombined form of the same work.
348 |
349 | 8. You may not copy, modify, sublicense, link with, or distribute
350 | the Library except as expressly provided under this License. Any
351 | attempt otherwise to copy, modify, sublicense, link with, or
352 | distribute the Library is void, and will automatically terminate your
353 | rights under this License. However, parties who have received copies,
354 | or rights, from you under this License will not have their licenses
355 | terminated so long as such parties remain in full compliance.
356 |
357 | 9. You are not required to accept this License, since you have not
358 | signed it. However, nothing else grants you permission to modify or
359 | distribute the Library or its derivative works. These actions are
360 | prohibited by law if you do not accept this License. Therefore, by
361 | modifying or distributing the Library (or any work based on the
362 | Library), you indicate your acceptance of this License to do so, and
363 | all its terms and conditions for copying, distributing or modifying
364 | the Library or works based on it.
365 |
366 | 10. Each time you redistribute the Library (or any work based on the
367 | Library), the recipient automatically receives a license from the
368 | original licensor to copy, distribute, link with or modify the Library
369 | subject to these terms and conditions. You may not impose any further
370 | restrictions on the recipients' exercise of the rights granted herein.
371 | You are not responsible for enforcing compliance by third parties with
372 | this License.
373 |
374 | 11. If, as a consequence of a court judgment or allegation of patent
375 | infringement or for any other reason (not limited to patent issues),
376 | conditions are imposed on you (whether by court order, agreement or
377 | otherwise) that contradict the conditions of this License, they do not
378 | excuse you from the conditions of this License. If you cannot
379 | distribute so as to satisfy simultaneously your obligations under this
380 | License and any other pertinent obligations, then as a consequence you
381 | may not distribute the Library at all. For example, if a patent
382 | license would not permit royalty-free redistribution of the Library by
383 | all those who receive copies directly or indirectly through you, then
384 | the only way you could satisfy both it and this License would be to
385 | refrain entirely from distribution of the Library.
386 |
387 | If any portion of this section is held invalid or unenforceable under any
388 | particular circumstance, the balance of the section is intended to apply,
389 | and the section as a whole is intended to apply in other circumstances.
390 |
391 | It is not the purpose of this section to induce you to infringe any
392 | patents or other property right claims or to contest validity of any
393 | such claims; this section has the sole purpose of protecting the
394 | integrity of the free software distribution system which is
395 | implemented by public license practices. Many people have made
396 | generous contributions to the wide range of software distributed
397 | through that system in reliance on consistent application of that
398 | system; it is up to the author/donor to decide if he or she is willing
399 | to distribute software through any other system and a licensee cannot
400 | impose that choice.
401 |
402 | This section is intended to make thoroughly clear what is believed to
403 | be a consequence of the rest of this License.
404 |
405 | 12. If the distribution and/or use of the Library is restricted in
406 | certain countries either by patents or by copyrighted interfaces, the
407 | original copyright holder who places the Library under this License may add
408 | an explicit geographical distribution limitation excluding those countries,
409 | so that distribution is permitted only in or among countries not thus
410 | excluded. In such case, this License incorporates the limitation as if
411 | written in the body of this License.
412 |
413 | 13. The Free Software Foundation may publish revised and/or new
414 | versions of the Lesser General Public License from time to time.
415 | Such new versions will be similar in spirit to the present version,
416 | but may differ in detail to address new problems or concerns.
417 |
418 | Each version is given a distinguishing version number. If the Library
419 | specifies a version number of this License which applies to it and
420 | "any later version", you have the option of following the terms and
421 | conditions either of that version or of any later version published by
422 | the Free Software Foundation. If the Library does not specify a
423 | license version number, you may choose any version ever published by
424 | the Free Software Foundation.
425 |
426 | 14. If you wish to incorporate parts of the Library into other free
427 | programs whose distribution conditions are incompatible with these,
428 | write to the author to ask for permission. For software which is
429 | copyrighted by the Free Software Foundation, write to the Free
430 | Software Foundation; we sometimes make exceptions for this. Our
431 | decision will be guided by the two goals of preserving the free status
432 | of all derivatives of our free software and of promoting the sharing
433 | and reuse of software generally.
434 |
435 | NO WARRANTY
436 |
437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446 |
447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456 | DAMAGES.
457 |
458 | END OF TERMS AND CONDITIONS
459 |
460 | How to Apply These Terms to Your New Libraries
461 |
462 | If you develop a new library, and you want it to be of the greatest
463 | possible use to the public, we recommend making it free software that
464 | everyone can redistribute and change. You can do so by permitting
465 | redistribution under these terms (or, alternatively, under the terms of the
466 | ordinary General Public License).
467 |
468 | To apply these terms, attach the following notices to the library. It is
469 | safest to attach them to the start of each source file to most effectively
470 | convey the exclusion of warranty; and each file should have at least the
471 | "copyright" line and a pointer to where the full notice is found.
472 |
473 |
474 | Copyright (C)
475 |
476 | This library is free software; you can redistribute it and/or
477 | modify it under the terms of the GNU Lesser General Public
478 | License as published by the Free Software Foundation; either
479 | version 2.1 of the License, or (at your option) any later version.
480 |
481 | This library is distributed in the hope that it will be useful,
482 | but WITHOUT ANY WARRANTY; without even the implied warranty of
483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
484 | Lesser General Public License for more details.
485 |
486 | You should have received a copy of the GNU Lesser General Public
487 | License along with this library; if not, write to the Free Software
488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
489 |
490 | Also add information on how to contact you by electronic and paper mail.
491 |
492 | You should also get your employer (if you work as a programmer) or your
493 | school, if any, to sign a "copyright disclaimer" for the library, if
494 | necessary. Here is a sample; alter the names:
495 |
496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the
497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker.
498 |
499 | , 1 April 1990
500 | Ty Coon, President of Vice
501 |
502 | That's all there is to it!
503 |
--------------------------------------------------------------------------------