-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.driver.php
200 lines (152 loc) · 7.4 KB
/
extension.driver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
Class extension_campaign_monitor extends Extension{
public function about(){
return array(
'name' => 'Campaign Monitor',
'version' => '0.1',
'release-date' => '2010-07-05',
'author' => array(
'name' => 'Neil Albrock',
'website' => 'http://atomised.coop',
'email' => 'neil@atomised.coop')
);
}
public function fetchNavigation() {
return array(
array(
'location' => 'System',
'name' => __('Campaign Monitor'),
'link' => '/cmadmin/'
)
);
}
public function getSubscribedDelegates(){
return array(
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
array(
'page' => '/blueprints/events/new/',
'delegate' => 'AppendEventFilter',
'callback' => 'addFilterToEventEditor'
),
array(
'page' => '/blueprints/events/edit/',
'delegate' => 'AppendEventFilter',
'callback' => 'addFilterToEventEditor'
),
array(
'page' => '/blueprints/events/new/',
'delegate' => 'AppendEventFilterDocumentation',
'callback' => 'appendEventFilterDocumentation'
),
array(
'page' => '/blueprints/events/edit/',
'delegate' => 'AppendEventFilterDocumentation',
'callback' => 'appendEventFilterDocumentation'
),
array(
'page' => '/frontend/',
'delegate' => 'EventPostSaveFilter',
'callback' => 'createNewCampaign'
)
);
}
public function appendPreferences($context){
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('Campaign Monitor')));
$div = new XMLElement('div');
$div->setAttribute('class', 'group');
$label = Widget::Label(__('API Key'));
$label->appendChild(Widget::Input('settings[campaign_monitor][api_key]', Symphony::Configuration()->get('api_key', 'campaign_monitor')));
$div->appendChild($label);
$label = Widget::Label(__('Client ID'));
$label->appendChild(Widget::Input('settings[campaign_monitor][client_id]', Symphony::Configuration()->get('client_id', 'campaign_monitor')));
$div->appendChild($label);
$group->appendChild($div);
$div = new XMLElement('div');
$div->setAttribute('class', 'group');
$label = Widget::Label(__('List ID'));
$label->appendChild(Widget::Input('settings[campaign_monitor][list_id]', Symphony::Configuration()->get('list_id', 'campaign_monitor')));
$div->appendChild($label);
$group->appendChild($div);
$div = new XMLElement('div');
$div->setAttribute('class', 'group');
$label = Widget::Label(__('Campaign Name Prefix'));
$label->appendChild(Widget::Input('settings[campaign_monitor][campaign_name]', Symphony::Configuration()->get('campaign_name', 'campaign_monitor')));
$div->appendChild($label);
$label = Widget::Label(__('Sender'));
$label->appendChild(Widget::Input('settings[campaign_monitor][sender_name]', Symphony::Configuration()->get('sender_name', 'campaign_monitor')));
$div->appendChild($label);
$group->appendChild($div);
$div = new XMLElement('div');
$div->setAttribute('class', 'group');
$label = Widget::Label(__('Sender Email'));
$label->appendChild(Widget::Input('settings[campaign_monitor][sender_email]', Symphony::Configuration()->get('sender_email', 'campaign_monitor')));
$div->appendChild($label);
$label = Widget::Label(__('Reply To Email'));
$label->appendChild(Widget::Input('settings[campaign_monitor][reply_email]', Symphony::Configuration()->get('reply_email', 'campaign_monitor')));
$div->appendChild($label);
$group->appendChild($div);
$div = new XMLElement('div');
$div->setAttribute('class', 'group');
$label = Widget::Label(__('HTML Content'));
$label->appendChild(Widget::Input('settings[campaign_monitor][html_content]', Symphony::Configuration()->get('html_content', 'campaign_monitor')));
$div->appendChild($label);
$label = Widget::Label(__('Plain Text Content'));
$label->appendChild(Widget::Input('settings[campaign_monitor][text_content]', Symphony::Configuration()->get('text_content', 'campaign_monitor')));
$div->appendChild($label);
$group->appendChild($div);
$context['wrapper']->appendChild($group);
}
public function addFilterToEventEditor($context){
$context['options'][] = array(
'campaign_monitor-create-campaign-filter', @in_array('campaign_monitor-create-campaign-filter', $context['selected']), 'Campaign Monitor: Create campaign'
);
}
public function appendEventFilterDocumentation(array $context=array()){
if(!@in_array('campaign_monitor-create-campaign-filter', $context['selected'])) return;
$context['documentation'][] = new XMLElement('h3', __('Campaign Monitor: Create campaign'));
$context['documentation'][] = new XMLElement('p', __('The Create campaign filter, upon the event successfully saving the entry, creates a new campaign via the Campaign Monitor API'));
}
private function __sendEmailFindFormValue($needle, $haystack, $discard_field_name=true, $default=NULL, $collapse=true){
if(preg_match('/^(fields\[[^\]]+\],?)+$/i', $needle)){
$parts = preg_split('/\,/i', $needle, -1, PREG_SPLIT_NO_EMPTY);
$parts = array_map('trim', $parts);
$stack = array();
foreach($parts as $p){
$field = str_replace(array('fields[', ']'), '', $p);
($discard_field_name ? $stack[] = $haystack[$field] : $stack[$field] = $haystack[$field]);
}
if(is_array($stack) && !empty($stack)) return ($collapse ? implode(' ', $stack) : $stack);
else $needle = NULL;
}
$needle = trim($needle);
if(empty($needle)) return $default;
return $needle;
}
public function createNewCampaign(array $context=array()){
if(!@in_array('campaign_monitor-create-campaign-filter', $context['event']->eParamFILTERS)) return;
require_once(EXTENSIONS . '/campaign_monitor/lib/cmapi/CMBase.php');
//Options from Preferences
$api_key = $context['parent']->Configuration->get('api_key', 'campaign_monitor');
$client_id = $context['parent']->Configuration->get('client_id', 'campaign_monitor');
$list_id = array($context['parent']->Configuration->get('list_id', 'campaign_monitor'));
$from_name = $context['parent']->Configuration->get('sender_name', 'campaign_monitor');
$from_email = $context['parent']->Configuration->get('sender_email', 'campaign_monitor');
$reply_email = $context['parent']->Configuration->get('reply_email', 'campaign_monitor');
//Options from Prefs + Event
$campaign_name = $context['parent']->Configuration->get('campaign_name', 'campaign_monitor') . $_POST['fields']['issue'];
$subject = $context['parent']->Configuration->get('campaign_name', 'campaign_monitor') . $_POST['fields']['issue'];
$html_content = $context['parent']->Configuration->get('html_content', 'campaign_monitor') . $_POST['fields']['issue'];
$text_content = $context['parent']->Configuration->get('text_content', 'campaign_monitor'). $_POST['fields']['issue'];
$cm = new CampaignMonitor($api_key);
//Create the new campaign
$campaignid = $cm->campaignCreate($client_id,$campaign_name,$subject,$from_name,$from_email,$reply_email,$html_content,$text_content,$list_id,'');
$result = $cm->campaignSend($campaignid,$from_email,date("Y-m-d H:i:s"));
}
}
?>