-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
68 lines (65 loc) · 2.17 KB
/
functions.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
<?php
// DUPLICATES TWEETS
function tw_duplicate($mysqli, $out) {
if ( $result = $mysqli->query('SELECT * FROM `twbot_tw` WHERE id = '.$out->id.';') ) {
while ( $obj = $result->fetch_object() ) {
return true;
}
}
if ( $result = $mysqli->query('SELECT * FROM `twbot_ban` WHERE user_id = '.$out->sender->id.';') ) {
while ( $obj = $result->fetch_object() ) {
return true;
}
}
}
function entry_duplicate($mysqli, $query) {
$duplicate = 0;
if ( $result = $mysqli->query($query) ) {
while ( $obj = $result->fetch_object() ) {
$duplicate = 1;
}
}
return $duplicate;
}
// ACCESS MySQL and return ARRAY or FALSE
function sqlarray($mysqli, $query) {
if ( $result = $mysqli->query($query) ) {
if ( is_object( $result ) ) {
while ( $obj = $result->fetch_object() ) {
$array[] = $obj;
}
}
}
return $array;
}
// ACCESS TWITTER
function twitteraccess($mysqli, $config, $method, $url, $data) {
if ($method == 'POST') {
$twitter = new TwitterAPIExchange($config);
$return = json_decode($twitter->buildOauth($url, $method)->setPostfields($data)->performRequest());
if (!is_string($return->text) || is_array($return->errors) || is_string($return->errors)) {
return 'error';
if (is_array($return->errors)) {
$mysqli->query("INSERT INTO `".$config['database']."`.`twbot_err` (`type`, `message`, `code`) VALUES ('POST', '".$return->errors->message."', '".$return->errors->code."',);");
} elseif (is_string($return->errors)) {
$mysqli->query("INSERT INTO `".$config['database']."`.`twbot_err` (`type`, `message`) VALUES ('POST', '".$return->errors."');");
} else {
$mysqli->query("INSERT INTO `".$config['database']."`.`twbot_err` (`type`) VALUES ('POST');");
}
} else {
return $return;
}
}
if ($method == "GET") {
$twitter = new TwitterAPIExchange($config);
$return = json_decode($twitter->setGetfield($data)->buildOauth($url, $method)->performRequest());
if ( $url == 'https://api.twitter.com/1.1/search/tweets.json' || $url == 'https://api.twitter.com/1.1/users/show.json' ) {
foreach ($return as $tweets) {
return $tweets;
}
} else {
return $return;
}
}
}
?>