-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.driver.php
145 lines (115 loc) · 3.5 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
<?php
require_once(dirname(__FILE__) . '/lib/class.smsmanager.php');
require_once(dirname(__FILE__) . '/lib/class.smsentry.php');
require_once(dirname(__FILE__) . '/lib/class.smscallbacks.php');
Class extension_twilio_sms extends Extension {
/********************************
SETUP
********************************/
// extension description
public function about() {
return array(
'name' => 'Twilio SMS',
'version' => '1.0',
'release-date' => '2014-10-14',
'author' => array(
'name' => 'Dan Henderson',
'website' => 'http://danhenderson.com.au'
),
'description' => 'Attach SMS to events.'
);
}
// uninstall
public function uninstall() {
return true;
}
// install
public function install() {
return true;
}
// setup delegates
public function getSubscribedDelegates() {
return array(
array(
'page' => '/blueprints/events/edit/',
'delegate' => 'AppendEventFilter',
'callback' => 'appendEventFilter'
),
array(
'page' => '/blueprints/events/new/',
'delegate' => 'AppendEventFilter',
'callback' => 'appendEventFilter'
),
array(
'page' => '/frontend/',
'delegate' => 'EventPostSaveFilter',
'callback' => 'eventPostSaveFilter'
),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'addCustomPreferenceFieldsets'
)
);
}
/********************************
UTILITIES
********************************/
// get the account id
public function getAccountID() {
return Symphony::Configuration()->get('account-id', 'twilio');
}
// get the auth token
public function getAuthToken() {
return Symphony::Configuration()->get('auth-token', 'twilio');
}
/********************************
DELEGATES
********************************/
// setup the filters
public function appendEventFilter($context) {
// get each sms and iterate over them
$sms = SMSManager::listAll();
foreach($sms as $msg) {
$handle = 'sms-' . Lang::createHandle($msg['name']);
$selected = in_array($handle, $context['selected']);
$context['options'][] = array(
$handle, $selected, General::sanitize("Send SMS: ".$msg['name'])
);
}
}
// check if any sms needs to be sent
public function eventPostSaveFilter($context) {
// get each sms and iterate over them
$sms = SMSManager::listAll();
foreach($sms as $msg) {
$handle = 'sms-' . Lang::createHandle($msg['name']);
if (in_array($handle, (array)$context['event']->eParamFILTERS)) {
$sms_entry = new SMSEntry($msg, $context);
}
}
}
// add custom preferences
public function addCustomPreferenceFieldsets($context) {
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings');
$fieldset->appendChild(
new XMLElement('legend', 'Twilio SMS')
);
$group = new XMLElement('div');
$group->setAttribute('class', 'group');
$acc = Widget::Label('Account ID');
$acc->appendChild(Widget::Input(
'settings[twilio][account-id]', General::Sanitize($this->getAccountID())
));
$group->appendChild($acc);
$tok = Widget::Label('Auth Token');
$tok->appendChild(Widget::Input(
'settings[twilio][auth-token]', General::Sanitize($this->getAuthToken())
));
$group->appendChild($tok);
$fieldset->appendChild($group);
$context['wrapper']->appendChild($fieldset);
}
}
?>