This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
546 lines (485 loc) · 26.6 KB
/
index.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'init.php';
use Abraham\TwitterOAuth\TwitterOAuth;
if (isset($_SESSION['error']) && !empty($_SESSION['error'])) {
$error = $_SESSION['error'];
unset($_SESSION['error']);
}
if (isset($_SESSION['success']) && !empty($_SESSION['success'])) {
$success = $_SESSION['success'];
unset($_SESSION['success']);
}
if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
$name = $_SESSION['name'];
$screen_name = $_SESSION['screen_name'];
$img = $_SESSION['img'];
$followers_count = $_SESSION['followers_count'];
$oauth_token = $_SESSION['oauth_token'];
$oauth_token_secret = $_SESSION['oauth_token_secret'];
if (count($_POST) > 0 && isset($_POST['action']) && $_POST['action'] === "Report'n'Block!") {
if (isset($_POST['follower_id']) && is_array($_POST['follower_id']) && count($_POST['follower_id']) > 0) {
$followers_id = $_POST['follower_id'];
try {
$twitter = new TwitterOAuth(
$config['consumer_key'],
$config['consumer_secret'],
$oauth_token,
$oauth_token_secret
);
$errors = array();
$success_count = 0;
foreach ($followers_id as $follower_id) {
$report = $twitter->post('users/report_spam', array(
'user_id' => $follower_id,
'perform_block' => true
));
if (isset($report->error)) {
$error[] = $report->error;
} else $success_count++;
}
$_SESSION['error'] = implode('<br/>', $errors);
$_SESSION['success'] = "You successfully reported " . $success_count . " followers!";
$_SESSION['last_refresh'] = NULL; // Let script reload amount of followers on next page load
} catch (Exception $e) {
$error = 'System Error: ' . $e->getMessage();
}
} else {
$_SESSION['error'] = "You must select at least one follower to report!";
}
header('Location: ' . $config['base_url']);
exit;
}
try {
$twitter = new TwitterOAuth(
$config['consumer_key'],
$config['consumer_secret'],
$oauth_token,
$oauth_token_secret
);
$followers_raw = $twitter->get('followers/list', array(
'user_id' => $user_id,
'screen_name' => $screen_name,
'count' => $config['max_at_once'],
'skip_status' => 'false'
));
if (isset($followers_raw->users) && is_array($followers_raw->users) && count($followers_raw->users))
$followers = $followers_raw->users;
elseif (isset($followers_raw->errors)) {
$error = $followers_raw->errors[0]->message;
if ($followers_raw->errors[0]->message === 'Rate limit exceeded') {
$error .= '. <strong>Cool down, wait few minutes, app will work again soon :)</strong>';
$xheaders = $twitter->getLastXHeaders();
$error .= '. Current available API requests: ' .
$xheaders['x_rate_limit_remaining'] .
'/' .
$xheaders['x_rate_limit_limit'] .
'. Estimate limit reset: ' .
date("H:i:s d/m/Y", $xheaders['x_rate_limit_reset']) .
', in ' .
($xheaders['x_rate_limit_reset'] - time()) . ' seconds!';
}
}
} catch (Exception $e) {
$error = 'System Error: ' . $e->getMessage();
}
if (!isset($_SESSION['last_refresh']) || !$_SESSION['last_refresh'] || (int)$_SESSION['last_refresh'] < (time() - 400)) {
try {
$me = $twitter->get('users/show', array(
'user_id' => $user_id,
'screen_name' => $screen_name
));
$_SESSION['followers_count'] = $followers_count = $me->followers_count;
$_SESSION['last_refresh'] = time();
} catch (Exception $e) {
$error = 'System Error: ' . $e->getMessage();
}
}
$today_only = isset($_GET['today_only']) && 1 === (int)$_GET['today_only'];
$true_bot_only = isset($_GET['true_bot_only']) && 1 === (int)$_GET['true_bot_only'];
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css"
integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<title>Report'n'Block <?php echo $config['app_owner'] ? '/ ' . $config['app_owner'] : ""; ?></title>
<style>
.table-header-row {
border-bottom: 2px solid #d3d3d3;
padding: 7px;
margin-bottom: 12px;
word-wrap: break-word;
}
.table-row {
border-bottom: 1px solid #d3d3d3;
padding: 7px;
margin-top: 5px;
margin-bottom: 5px;
}
.selected-row {
background-color: #a9cef880;
}
.table-row {
user-select: none; /* CSS3 (little to no support) */
-ms-user-select: none; /* IE 10+ */
-moz-user-select: none; /* Gecko (Firefox) */
-webkit-user-select: none; /* Webkit (Safari, Chrome) */
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark sticky-top bg-dark flex-md-nowrap">
<a class="navbar-brand" href="<?php echo $config['base_url']; ?>">
Report'n'Block
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#top-nav" aria-controls="top-nav"
aria-expanded="false" aria-label="Open Menu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="top-nav">
<ul class="navbar-nav">
<li class="nav-item text-nowrap">
<a href="https://github.com/mkbodanu4/php-twitter-followers-report-n-block" class="nav-link">
<i class="fab fa-github"></i> Source
</a>
</li>
<li class="nav-item text-nowrap">
<a href="<?php echo $config['base_url'] . 'policy.php'; ?>" class="nav-link">
<i class="fas fa-info-circle"></i> Privacy Policy
</a>
</li>
<li class="nav-item text-nowrap">
<a href="<?php echo $config['base_url'] . 'terms.php'; ?>" class="nav-link">
<i class="fas fa-info-circle"></i> Terms Of Service
</a>
</li>
<li class="nav-item text-nowrap">
<?php if (!isset($user_id) || !$user_id) { ?>
<a href="<?php echo $config['base_url'] . 'login.php'; ?>" class="nav-link">
<i class="fab fa-twitter"></i> Login
</a>
<?php } else { ?>
<a href="<?php echo $config['base_url'] . 'logout.php'; ?>" class="nav-link">
<i class="fas fa-sign-out-alt"></i> Logout
</a>
<?php } ?>
</li>
</ul>
</div>
</nav>
<div class="container-fluid">
<?php if (!isset($user_id) || !$user_id) { ?>
<div class="row">
<div class="col-md-12">
<div class="card mt-3 text-center">
<div class="card-header">
<i class="fa fa-info"></i> About App
</div>
<div class="card-body">
<strong>Report'n'Block</strong> is web-based tool to make easier blocking of followers that
could be bots.<br/>
Very easy to use - just log in via <i class="fab fa-twitter"></i> Twitter, select followers you
want to report (and block) and click on <b>"Report'n'Block!"</b> button.<br/>
<strong>Make sure that you reporting user on your own decision before performing any
action!</strong><br/>
We do not store on our side any of your data nor do any action with your account - we just
getting your username, followers list and sending reports back to Twitter.<br/>
Want to be sure (or check how it works) - app code available on
<a href="https://github.com/mkbodanu4/php-twitter-followers-report-n-block" target="_blank"><i
class="fab fa-github"></i> GitHub</a>.<br/>
<i>
By clicking below to log in, you’re agreeing to our
<a href="<?php echo $config['base_url'] . 'policy.php'; ?>">
Privacy Policy
</a> and
<a href="<?php echo $config['base_url'] . 'terms.php'; ?>">
Terms Of Service
</a>.
</i><br/>
<a class="btn btn-primary mt-3" href="<?php echo $config['base_url'] . 'login.php'; ?>">
Log In via <i class="fab fa-twitter"></i>
</a>
</div>
<div class="card-footer text-right">
© <?php echo date("Y"); ?> <?php echo $config['app_owner'] ? $config['app_owner'] : ""; ?>
</div>
</div>
</div>
</div>
<?php } else { ?>
<div class="row">
<div class="col-sm-12">
<div class="mt-3">
<?php if (isset($error) && $error) { ?>
<div class="alert alert-danger">
<?php echo $error; ?>
</div>
<?php } ?>
<?php if (isset($success) && $success) { ?>
<div class="alert alert-success">
<?php echo $success; ?>
</div>
<?php } ?>
<div>
<img src="<?php echo $img; ?>" alt="<?php echo $screen_name; ?>" class="img-thumbnail">
<span>
Hello, <strong><?php echo $screen_name; ?>!</strong>
</span>
You have <?php echo $followers_count; ?> followers,
first <?php echo $followers_count < $config['max_at_once'] ? $followers_count : $config['max_at_once']; ?>
of them shown, you can
select and report them as bots.
</div>
<div class="text-right pb-2">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#filters"
aria-expanded="false" aria-controls="filters">
Filters
</button>
</div>
<div class="collapse" id="filters">
<div class="card card-body">
<form action="<?php echo $config['base_url']; ?>" method="get">
<div class="form-group">
<input type="checkbox" title="Today Only" name="today_only" id="today_only"
<?php echo $today_only ? 'checked' : ''; ?>
value="1"/>
<label for="today_only">Created Time - Today Only</label>
</div>
<div class="form-group">
<input type="checkbox" title="true_bot_only" name="true_bot_only" id="true_bot_only"
<?php echo $true_bot_only ? 'checked' : ''; ?>
value="1"/>
<label for="true_bot_only">Possible Bot - 100% Only</label>
</div>
<input type="submit" class="btn btn-primary" value="Refresh List"/>
</form>
</div>
</div>
<form action="<?php echo $config['base_url']; ?>" method="post">
<div class="">
<div class="container-fluid">
<div class="row table-header-row d-none d-sm-flex">
<div class="col-md-1 col-sm-2 col-5">
<strong>UP</strong>
</div>
<div class="col-md-5 col-sm-7 col-5">
<strong>Name</strong>
</div>
<div class="col-md-1 col-sm-2 col-12">
<strong>Created Time</strong>
</div>
<div class="col-md-1 col-sm-3 col-12">
<strong>You Follow</strong>
</div>
<div class="col-md-1 col-sm-3 col-12">
<strong>Following/Followers</strong>
</div>
<div class="col-md-1 col-sm-3 col-12">
<strong>Tweets Count</strong>
</div>
<div class="col-md-1 col-sm-3 col-12">
<strong>Possible bot?</strong>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<input type="submit" class="btn btn-danger" name="action"
value="Report'n'Block!">
<a href="<?php echo $config['base_url'] . '?' . http_build_query(array("_t" => time())); ?>"
class="btn btn-success">Refresh List</a>
</div>
</div>
<?php if (isset($followers) && is_array($followers) && count($followers)) { ?>
<?php foreach ($followers as $follower) { ?>
<?php
/* Created Time Calculation */
$created_time = ceil((time() - strtotime($follower->created_at)) / 86400);
/* Possible Bot Index Calculation */
$bot_value = 0;
/* 1. Most of bots were created less than 3 days ago */
if (ceil((time() - strtotime($follower->created_at)) / 86400) <= 3)
$bot_value++;
/* 2. Most of bots follow many account with low follow-back rate */
if ($follower->friends_count > $follower->followers_count)
$bot_value++;
/* 3. Most of bots have only few followers */
if ($follower->followers_count < 5)
$bot_value++;
/* 4. Most of bots have no tweets at all */
if ((int)$follower->statuses_count === 0)
$bot_value++;
else {
/* 5. Most of bots have only retweets, so last status 100% retweet */
if (isset($follower->status) && isset($follower->status->retweeted_status)) {
$bot_value++;
}
}
/* 6. Most of bots have default profile picture */
if ("https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png" === $follower->profile_image_url_https)
$bot_value++;
/* 7. Most of bots have no profile background */
if (NULL === $follower->profile_background_image_url_https)
$bot_value++;
/* Filters */
if ($today_only && $created_time > 1)
continue;
if ($true_bot_only && $bot_value < 6)
continue;
?>
<div class="row table-row">
<input type="checkbox" class="d-none"
title="<?php echo $follower->screen_name; ?>"
name="follower_id[]" value="<?php echo $follower->id; ?>">
<div class="col-md-1 col-sm-2 col-5">
<img src="<?php echo $follower->profile_image_url_https; ?>"
alt="<?php echo $follower->screen_name; ?>" class="img-thumbnail">
</div>
<div class="col-md-5 col-sm-7 col-5">
<?php echo $follower->name; ?> <a
href="https://twitter.com/<?php echo $follower->screen_name; ?>"
target="_blank">(@<?php echo $follower->screen_name; ?>)</a>
</div>
<div class="col-md-1 col-sm-2 col-12">
<span class="d-xs-block d-sm-none">
<strong>Created Time:</strong>
</span>
<?php echo $created_time . " day(s) ago"; ?>
</div>
<div class="col-md-1 col-sm-3 col-12">
<span class="d-xs-block d-sm-none">
<strong>You Follow:</strong>
</span>
<?php echo $follower->following ? '<strong class="btn btn-success">Yes</strong>' : "No"; ?>
</div>
<div class="col-md-1 col-sm-3 col-12">
<span class="d-xs-block d-sm-none">
<strong>Following/Followers:</strong>
</span>
<?php echo $follower->friends_count; ?>
/
<?php echo $follower->followers_count; ?>
</div>
<div class="col-md-1 col-sm-3 col-12">
<span class="d-xs-block d-sm-none">
<strong>Tweets Count</strong>
</span>
<?php echo $follower->statuses_count; ?>
</div>
<div class="col-md-1 col-sm-3 col-12">
<span class="d-xs-block d-sm-none">
<strong>Possible bot? -</strong>
</span>
<?php
switch ($bot_value) {
case 7:
case 6:
echo '<strong class="btn btn-danger">100%</strong>';
break;
case 5:
echo '<strong class="btn btn-primary">70%</strong>';
break;
case 4:
case 3:
echo '<strong class="btn btn-info">50%</strong>';
break;
case 2:
echo '<strong class="btn btn-success">20%</strong>';
break;
case 1:
case 0:
default:
echo "0%";
}
?>
</div>
</div>
<?php } ?>
<?php } else { ?>
<div class="row">
<div class="col-md-1 col-sm-12">Nothing found.</div>
</div>
<?php } ?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
<?php } ?>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<script>
var row_start = null, row_end, checkbox, rows;
$(function () {
$('.table-row').click(function (e) {
if (e.target.tagName === "A") return;
row_start = $(this).toArray()[0];
checkbox = $(this).find('input[type=checkbox]');
if (checkbox.length) {
checkbox.prop('checked', !checkbox.prop('checked'));
if (checkbox.prop('checked')) {
$(this).addClass('selected-row');
} else {
$(this).removeClass('selected-row');
}
}
});
$('.table-row').mousedown(function (e) {
if (e.target.tagName === "A") return;
if (row_start !== null && e.shiftKey) {
row_end = $(this).toArray()[0];
rows = $('.table-row').toArray();
if (row_start !== row_end && rows.indexOf(row_start) !== -1 && rows.indexOf(row_end) !== -1) {
if (rows.indexOf(row_start) > rows.indexOf(row_end)) {
for (var i = (rows.indexOf(row_end) + 1); i < rows.indexOf(row_start); i++) {
checkbox = $(rows[i]).find('input[type=checkbox]');
if (checkbox.length) {
checkbox.prop('checked', !checkbox.prop('checked'));
if (checkbox.prop('checked')) {
$(rows[i]).addClass('selected-row');
} else {
$(rows[i]).removeClass('selected-row');
}
}
}
} else {
for (var i = (rows.indexOf(row_start) + 1); i < rows.indexOf(row_end); i++) {
checkbox = $(rows[i]).find('input[type=checkbox]');
if (checkbox.length) {
checkbox.prop('checked', !checkbox.prop('checked'));
if (checkbox.prop('checked')) {
$(rows[i]).addClass('selected-row');
} else {
$(rows[i]).removeClass('selected-row');
}
}
}
}
}
row_start = null;
row_end = null;
}
});
});
</script>
<?php
// Create footer.php and put Google Analytics code there if you want any
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'footer.php')) include_once __DIR__ . DIRECTORY_SEPARATOR . 'footer.php';
?>
</body>
</html>