/
mcp.twitee.php
318 lines (248 loc) · 7.33 KB
/
mcp.twitee.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<?php
/**
* ExpressionEngine License
*
* ExpressionEngine by EllisLab is copyrighted software
* The licence agreement is available here http://expressionengine.com/docs/license.html
*
* Module Control Panel File for Twit-ee module
*
* Fetches data from Twitter for display in templates
*
* @version 1.3
* @author George Ornbo <george@shapeshed.com>
* @license http://opensource.org/licenses/bsd-license.php
*/
/**
* Twit-ee module
*
* @category Modules
* @package Twit-ee
*/
class Twitee_CP {
/**
* Version number of the module
* @var string
*/
var $version = '1.3';
/**
* Settings used in this module
* @var array
*/
var $settings = array();
/**
* Constructor - decides which function to show based on URL
*
*/
function Twitee_CP( $switch = TRUE )
{
global $IN;
if ($switch)
{
switch($IN->GBL('P'))
{
case 'account_details':
$this->settings_form();
break;
case 'update_account':
$this->update_account();
break;
default:
$this->settings_form();
break;
}
}
}
/**
* Gets settings from the database
*/
function get_settings()
{
global $DB, $PREFS;
$settings = FALSE;
$query = $DB->query("SELECT * FROM exp_twitee WHERE site_id = ".$PREFS->ini('site_id')." LIMIT 1");
if ($query->num_rows > 0)
{
$settings['username'] = $query->row['username'];
$settings['password'] = $query->row['password'];
}
else
{
$settings['username'] = "";
$settings['password'] = "";
}
return $settings;
}
/**
* Module homepage - not currently used but will be needed for OAuth
*
*/
function twitee_home()
{
global $DSP, $LANG;
$DSP->title = $LANG->line('twitee_module_name');
$DSP->crumb = $DSP->anchor(BASE.
AMP.'C=modules'.
AMP.'M=twitee',
$LANG->line('twitee_module_name'));
$DSP->crumb .= $DSP->crumb_item($LANG->line('twitee_home'));
$DSP->body .= $DSP->heading($LANG->line('twitee_module_name'));
$DSP->body .= $DSP->qdiv('itemWrapper', $DSP->heading($DSP->anchor(BASE.
AMP.'C=modules'.
AMP.'M=twitee'.
AMP.'P=account_details',
$LANG->line('twitee_account_details')),
5));
}
/**
* Settings form
*
*/
function settings_form($response="")
{
global $DB, $DSP, $LANG, $IN, $PREFS;
$settings = $this->get_settings();
$DSP->crumbline = TRUE;
$DSP->title = $LANG->line('twitee_account_details');
$DSP->crumb = $DSP->anchor(BASE.
AMP.'C=modules'.
AMP.'M=twitee',
$LANG->line('twitee_module_name'));
$DSP->crumb .= $DSP->crumb_item($LANG->line('twitee_account_details'));
$DSP->body = '';
$DSP->body .= $DSP->heading($LANG->line('twitee_account_details'));
if(!empty($response['success']))
{
$DSP->body .= $response['success'];
}
if(!empty($response['create_success']))
{
$DSP->body .= $response['create_success'];
}
$DSP->body .= $DSP->form_open(
array(
'action' => 'C=modules'.AMP.'M=twitee'.AMP.'P=update_account'
)
);
$DSP->body .= $DSP->table_open(array('class' => 'tableBorder', 'border' => '0', 'style' => 'margin-top:18px; width:100%'));
$DSP->body .= $DSP->tr()
. $DSP->td('tableHeading', '', '2')
. $LANG->line("twitee_account_details")
. $DSP->td_c()
. $DSP->tr_c();
$DSP->body .= $DSP->tr()
. $DSP->td('tableCellOne', '40%')
. $DSP->qdiv('defaultBold', $LANG->line('twitee_username_label'))
. $DSP->td_c();
$DSP->body .= $DSP->td('tableCellOne')
. $DSP->input_text('twitter_username', $settings['username'])
. $DSP->td_c()
. $DSP->tr_c();
$DSP->body .= $DSP->tr()
. $DSP->td('tableCellTwo', '40%')
. $DSP->qdiv('defaultBold', $LANG->line('twitee_password_label'))
. $DSP->td_c();
$DSP->body .= $DSP->td('tableCellTwo')
. $DSP->input_pass('twitter_password', str_rot13($settings['password']))
. $DSP->td_c()
. $DSP->tr_c();
$DSP->body .= $DSP->table_c();
$DSP->body .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit())
. $DSP->form_c();
}
/**
* Update account
*
*/
function update_account()
{
global $DB, $DSP, $IN, $LANG, $PREFS;
if ( ! $IN->GBL('twitter_username', 'POST') )
{
return $DSP->error_message($LANG->line('twitee_username_error'));
}
if ( ! $IN->GBL('twitter_password', 'POST') )
{
return $DSP->error_message($LANG->line('twitee_password_error'));
}
if ( $IN->GBL('twitter_username', 'POST') && $IN->GBL('twitter_password', 'POST') )
{
/*
Because of Twitter's use of the password anti-pattern we need to
get the password out as plain text. This means we can't use MD5 or SHA1
Crap! So provide some limited protection with str_rot13.
can haz OAuth plz? kthnxbai
*/
$data = array( 'username' => $IN->GBL('twitter_username', 'POST'),
'password' => str_rot13($IN->GBL('twitter_password', 'POST')),
'site_id' => $PREFS->ini('site_id'));
$query = $DB->query("SELECT * FROM exp_twitee WHERE site_id = ".$PREFS->ini('site_id')." LIMIT 0,1");
if ($query->num_rows == 0)
{
$DB->query($DB->insert_string('exp_twitee', $data));
$response['create_success'] = $DSP->qdiv('success', $LANG->line('twitee_account_added'));
return $this->settings_form($response);
}
else
{
$DB->query($DB->update_string('exp_twitee', $data, "account_id = ".$query->result[0]['account_id'].""));
$response['success'] = $DSP->qdiv('success', $LANG->line('twitee_account_updated'));
return $this->settings_form($response);
}
}
}
/**
* Module installer
*
*/
function twitee_module_install()
{
global $DB;
$sql[] = "INSERT INTO exp_modules (module_id,
module_name,
module_version,
has_cp_backend)
VALUES
('',
'Twitee',
'$this->version',
'y')";
$sql[] = "CREATE TABLE IF NOT EXISTS `exp_twitee` (
`account_id` int(10) unsigned NOT NULL auto_increment,
`site_id` int(10) unsigned NOT NULL,
`username` varchar(50) NOT NULL,
`password` varchar(40) NOT NULL,
PRIMARY KEY (`account_id`));";
foreach ($sql as $query)
{
$DB->query($query);
}
return true;
}
/**
* Module de-installer
*
*/
function twitee_module_deinstall()
{
global $DB;
$query = $DB->query("SELECT module_id
FROM exp_modules
WHERE module_name = 'Twitee'");
$sql[] = "DELETE FROM exp_module_member_groups
WHERE module_id = '".$query->row['module_id']."'";
$sql[] = "DELETE FROM exp_modules
WHERE module_name = 'Twitee'";
$sql[] = "DELETE FROM exp_actions
WHERE class = 'Twitee'";
$sql[] = "DELETE FROM exp_actions
WHERE class = 'Twitee_CP'";
$sql[] = "DROP TABLE IF EXISTS exp_twitee";
foreach ($sql as $query)
{
$DB->query($query);
}
return true;
}
}
?>