-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_config.php
243 lines (168 loc) · 5.86 KB
/
admin_config.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
// Generated e107 Plugin Admin Area
require_once('../../class2.php');
if (!getperms('P'))
{
e107::redirect('admin');
exit;
}
// e107::lan('twilio',true);
class twilio_adminArea extends e_admin_dispatcher
{
protected $modes = array(
'main' => array(
'controller' => 'twilio_ui',
'path' => null,
'ui' => 'twilio_form_ui',
'uipath' => null
),
);
protected $adminMenu = array(
'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'P'),
// 'main/div0' => array('divider'=> true),
'main/test' => array('caption'=> 'Test', 'perm' => 'P'),
);
protected $adminMenuAliases = array(
'main/edit' => 'main/list'
);
protected $menuTitle = 'Twilio';
}
class twilio_ui extends e_admin_ui
{
protected $pluginTitle = 'Twilio';
protected $pluginName = 'twilio';
// protected $eventName = 'twilio-'; // remove comment to enable event triggers in admin.
protected $table = '';
protected $pid = '';
protected $perPage = 10;
protected $batchDelete = true;
protected $batchExport = true;
protected $batchCopy = true;
// protected $sortField = 'somefield_order';
// protected $sortParent = 'somefield_parent';
// protected $treePrefix = 'somefield_title';
// protected $tabs = array('tab1'=>'Tab 1', 'tab2'=>'Tab 2'); // Use 'tab'=>'tab1' OR 'tab'=>'tab2' in the $fields below to enable.
// protected $listQry = "SELECT * FROM `#tableName` WHERE field != '' "; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit.
protected $listOrder = ' DESC';
protected $fields = array (
);
protected $fieldpref = array();
// protected $preftabs = array('General', 'Other' );
protected $prefs = array(
'active' => array('title'=> 'Active', 'tab'=>0, 'type'=>'boolean', 'data' => 'str', 'help'=>'', 'writeParms' => []),
'phone' => array('title'=> 'Phone', 'tab'=>0, 'type'=>'text', 'data' => 'str', 'help'=>'Your SMS compatible Twilio phone number', 'writeParms' => ['placeholder'=>'+1-222-333-4444']),
'sid' => array('title'=> 'Apikey', 'tab'=>0, 'type'=>'text', 'data' => 'str', 'help'=>'', 'writeParms' => ['size'=>'xxlarge']),
'secret' => array('title'=> 'Token', 'tab'=>0, 'type'=>'method', 'data' => 'str', 'help'=>'', 'writeParms' => ['size'=>'xlarge']),
);
public function init()
{
// This code may be removed once plugin development is complete.
if(!e107::isInstalled('twilio'))
{
e107::getMessage()->addWarning("This plugin is not yet installed. Saving and loading of preference or table data will fail.");
}
// Set drop-down values (if any).
}
public function testPage()
{
if(!empty($_POST['testTwilio']) && !empty($_POST['to']) && !empty($_POST['message']))
{
$event = [];
if($result = e107::getEvent()->trigger('system_send_sms', $_POST))
{
e107::getMessage()->addInfo('SENT: '. print_a($result, true));
}
else
{
e107::getMessage()->addError('There was a problem. Check the number and make sure it begins with <b>+</b>.');
}
}
$frm = $this->getUI();
$text = $frm->open('testPage');
$text .= "<table class='table table-bordered' style='width:auto'>";
$text .= "<tr><td>";
$text .= $frm->text('to',varset($_POST['to']), 80, ['placeholder' => '+1-555-333-2222']);
$text .= "</td><tr><td>";
$text .= $frm->textarea('message', 'Hello from e107!', 3);
$text .= "</td></tr>";
$text .= "</table>";
$text .= $frm->submit('testTwilio','Send Test SMS');
$text .= $frm->close();
return $text;
}
// ------- Customize Create --------
public function beforeCreate($new_data,$old_data)
{
return $new_data;
}
public function afterCreate($new_data, $old_data, $id)
{
// do something
}
public function onCreateError($new_data, $old_data)
{
// do something
}
// ------- Customize Update --------
public function beforeUpdate($new_data, $old_data, $id)
{
return $new_data;
}
public function afterUpdate($new_data, $old_data, $id)
{
// do something
}
public function onUpdateError($new_data, $old_data, $id)
{
// do something
}
// left-panel help menu area. (replaces e_help.php used in old plugins)
public function renderHelp()
{
$caption = LAN_HELP;
$text = "<p>This plugins adds <a href='https://www.twilio.com/' target='_blank' title='Visit website'>Twilio</a> SMS capabilities to e107.</p>
<p>After saving your API details, as found on your Twilio dashboard, use the <b>Test</b> page to send yourself an SMS to check that is it functioning correctly.</p>
<p>You can also choose to have <a href='".e_ADMIN."notify.php'>system notifications</a> sent to you by SMS if you wish. </p>
<p>Plugin developers may send an SMS message using the following code example:</p>
<pre>e107::getEvent()->trigger(<br />'system_send_sms',<br />[<br /> 'to' => '+1-222-333-4444',<br /> 'message' => 'Your message'<br />]);</pre>
";
return array('caption'=>$caption,'text'=> $text);
}
/*
// optional - a custom page.
public function customPage()
{
$text = 'Hello World!';
$otherField = $this->getController()->getFieldVar('other_field_name');
return $text;
}
*/
}
class twilio_form_ui extends e_admin_form_ui
{
// Custom Method/Function (pref)
function apikey($curVal,$mode)
{
// Edit Page
if($mode == 'write')
{
return $this->text('apikey', $curVal, 255, 'size=large');
}
return null;
}
// Custom Method/Function (pref)
function secret($curVal,$mode)
{
// Edit Page
if($mode == 'write')
{
return $this->password('secret', $curVal, 255, 'size=xxlarge');
}
return null;
}
}
new twilio_adminArea();
require_once(e_ADMIN."auth.php");
e107::getAdminUI()->runPage();
require_once(e_ADMIN."footer.php");
exit;