/
api_support.php
executable file
·308 lines (258 loc) · 9.55 KB
/
api_support.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
<?php
if (session_id () == "") session_start ();
$docroot = $_SERVER ['DOCUMENT_ROOT'];
require_once $docroot . "/config.php";
require_once $docroot . "/models/twextra_model.php";
require_once $docroot . "/controllers/twextra_controller.php";
require_once $docroot . "/banner.php";
require_once $docroot . "/header_html.php";
$screen_name = $_SESSION['user'];
require_once $docroot . "/tw.lib.php";
//validate access;
validate_access_twetest();
$data = $_REQUEST;
display_api_support($screen_name, $data);
//.........................................................................................
function display_api_support($screen_name='', $data) {
//configuration parameters:
$config_params = Config::getConfigParams ();
$css = $config_params ['css'];
$tweet_size_max = $config_params ['tweet_size_max'];
$tweet_size_max_google = $config_params ['tweet_size_max_google'];
$hostname = $config_params ['hostname'];
$doctype = $config_params ['doctype'];
$html_attribute = $config_params ['html_attribute'];
$banner = banner('', 'banner'); //(user, banner_class)
$footer = $config_params ['footer']; //
$docroot = $config_params ['docroot'];
$godaddy_analytics = $config_params ['godaddy_analytics'];
$debug = $config_params ['debug'];
$enable_stats = $config_params ['enable_stats'];
$script_path = __FUNCTION__;
$email = '';
$firstname = '';
$lastname = '';
$application = '';
$company = '';
$web_site = '';
$twextra_key = '';
$error = '';
$error_email = '';
$error_firstname = '';
$error_lastname = '';
$error_application = '';
$error_company = '';
$error_web_site = '';
//save logs
if ($enable_stats) {
$model = new TwextraModel (); //
$model->saveStat ();
}
if($screen_name == '' && $data['submit'] == 'Submit'){
$error = "<h2 style='color: red' >In order to get Twextra key, please authenticate with Twitter by pressing
the 'Sign in with Twitter' button at the top right of this page. </h2>";
}
if($screen_name != '' && $data['submit'] == 'Submit'){
//store user data->get twextra key -> display key -> suppress the form
$email = $data ['email'];
$firstname = $data ['firstname'];
$lastname = $data ['lastname'];
$application = $data['application'];
$company = $data ['company'];
$web_site = $data ['web_site'];
}
if($data['clear']=='Clear'){
$email=$firstname=$lastname=$application=$company=$web_site='';
}
//validate user input
if ($data ['submit'] == 'Submit') {
$email_pattern = "/^.+@.+\..+/";
$email_validate = preg_match ( $email_pattern, $email );
if (! $email_validate) {
$error_email = 1;
}
if (empty($firstname)) {
$error_firstname = 1;
}
if (empty($lastname)) {
$error_lastname = 1;
}
if (empty($application)) {
$error_application = 1;
}
if (empty($company)) {
$error_company = 1;
}
if (empty($web_site)) {
$error_web_site = 1;
}
}
if($error_email){
$api_email = 'api_error';
}else{
$api_email = '';
}
if($error_firstname){
$api_firstname = 'api_error';
}else{
$api_firstname = '';
}
if($error_lastname){
$api_lastname = 'api_error';
}else{
$api_lastname = '';
}
if($error_application){
$api_application = 'api_error';
}else{
$api_application = '';
}
if($error_company){
$api_company = 'api_error';
}else{
$api_company = '';
}
if($error_web_site){
$api_web_site = 'api_error';
}else{
$api_web_site = '';
}
if(($api_email || $api_firstname || $api_lastname || $api_application || $api_company || $api_web_site)&& empty($error)){
$error = "<span class='api_error'>Please fill in info for the fields marked in red.</span>";
}
if(!$error_email && !empty($firstname) && !empty($lastname) && !empty($application) &&
!empty($company) && !empty($web_site) && $data['submit']=='Submit'){
$model = new TwextraModel();
$twextra_key = $model->get_twextra_key($email, $firstname, $lastname, $application, $company, $web_site, $screen_name);
$model->update_api_tables($email, $firstname, $lastname, $application, $company, $web_site, $screen_name, $twextra_key);
mail('contact@twextra.com', 'New Twextra Key generated', "A New Twextra Key has been generated.");
}
$header = header_html ( $prefix ); //
//..........................................................
header ( "Pragma: no-cache" );
header ( "cache-Control: no-cache, must-revalidate" ); // HTTP/1.1
header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); // Date in the past
$message = '';
$message .= $doctype;
$message .= "<html $html_attribute >\n";
$message .= $header;
$message .= "<body>\n";
$message .= "<div class='p5_wrapper'>\n";
$message .= "<div class='p5_page'>\n";
$message .= $banner;
$message .= "<div style='margin-left:auto;margin-right:auto;margin-bottom:20px;width:768px;font-size:0.8em;' >\n"; //p5_main
$message .="<h3>API Support</h3>";
$message .= "API support is available for posting messages to Twitter using Twextra's RESTful API.
Please fill out the following form to get your Twextra key.";
$message .= "<br /><br />";
if($twextra_key != ''){
//$email=$firstname=$lastname=$application=$company='';
}
$message .= "<div>
<form method='POST' action='api_support.php'>
<p>
<span class='$api_email'>Email:</span> <input type='text' name='email' value='$email' size='40' maxlength= '100' /></p>
<p> <span class='$api_firstname'>First Name:</span> <input type='text' name='firstname' value = '$firstname' size='40' maxlength= '100' /></p>
<p> <span class='$api_lastname'>Last Name:</span> <input type='text' name='lastname' value = '$lastname' size='40' maxlength= '100' /></p>
<p> <span class='$api_application'>Application:</span> <input type='text' name='application' value = '$application' size='40' maxlength= '100' /></p>
<p> <span class='$api_company'>Company:</span> <input type='text' name='company' value = '$company' size='40' maxlength= '100' /></p>
<p> <span class='$api_web_site'>Web-Site:</span> <input type='text' name='web_site' value = '$web_site' size='40' maxlength= '100' /></p>
<p>
<input type='submit' name='submit' value='Submit' />
<input type='submit' name='clear' value='Clear' /></p>
</form>
</div>";
if($error != ''){
$message .= $error;
}
if($twextra_key != ''){
$message .= "<h2 style='color: blue' >Thank you for registering your application. Your Twextra Key is: $twextra_key</h2>";
}
$message .= "<h3>Overview</h3>
The Twextra Twitter API lets you post large messages (upto 100,000 characters) to Twitter. It is used with normal HTTP POST
requests. The API uses Twitter's OAuth method to authenticate the identity of a Twitter user.</p>";
$message .= "<h3>Method: upload </h3>
<h3>URL: http://twextra.com/router.php </h3>
<h3 class='api_h3' >Fields</h3>
<pre style='font-size:15px;'>
route
editor
twextra_key
twitter_user_id
twitter_access_token
twitter_access_token_secret
social
</pre>";
$message .= "<h3>Format: json</h3>";
$message .='<h3>Sample json response</h3><pre style="font-size:12px;">
{
"place":null,
"in_reply_to_screen_name":null,
"retweeted":false,
"coordinates":null,
"geo":null,
"source":"http://twextra.com",
"retweet_count":null,
"favorited":false,
"in_reply_to_status_id":null,
"created_at":"Mon Oct 18 06:39:31 +0000 2010",
"in_reply_to_user_id":null,
"user":{
"listed_count":0,
"verified":false,
"description":null,
"follow_request_sent":false,
"profile_sidebar_fill_color":"DDEEF6",
"time_zone":"Pacific Time (US & Canada)",
"profile_sidebar_border_color":"C0DEED",
"followers_count":0,"url":null,
"show_all_inline_media":false,
"notifications":false,
"profile_use_background_image":true,
"friends_count":4,
"lang":"en",
"statuses_count":871,
"created_at":"Tue Aug 10 06:24:42 +0000 2010",
"profile_background_color":"C0DEED",
"profile_image_url":"http://s.twimg.com/a/1287010001/images/default_profile_5_normal.png",
"location":null,
"profile_background_image_url":"http://s.twimg.com/a/1287010001/images/themes/theme1/bg.png",
"favourites_count":1,"protected":true,"contributors_enabled":false,
"profile_text_color":"333333",
"screen_name":"your screen name",
"name":"your name",
"following":false,
"geo_enabled":false,
"profile_background_tile":false,
"id":nnnnnnnnn,"utc_offset":-28800,
"profile_link_color":"0084B4"
},
"contributors":null,
"id":nnnnnnnnnnn,
"truncated":false,
"text":"your message prefix... http://twextra.com/5252h3",
"success":"Your message was posted successfully."
}</pre>
';
$message .= '<h3>Sample curl command</h3><pre style="font-size:12px;">
curl http://twextra.com/router.php
-X POST
-d route="tweet_post"
-d editor1="message to be posted"
-d twextra_key="mmmmmmmm"
-d twitter_user_id="nnnnnnnn"
-d twitter_access_token="twitter access token value"
-d twitter_access_token_secret="twitter access token secret value"
-d social="twitter"</pre>';
$message .= "<br style='clear:both;' />";
$message .= "</div>\n"; //p5_main
$message .= $footer;
$message .= "</div>\n"; //page
$message .= "</div>\n"; //wrapper
$message .= $godaddy_analytics;
$message .= "</body>\n</html>\n";
echo $message;
}
?>