This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
/
twitter.php
72 lines (57 loc) · 1.91 KB
/
twitter.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
<?php
function string_sanitize($s) {
$result = preg_replace("/['\"\"'#]+/", "", $s); //remove useless punctuations
$result = preg_replace("/http[s]*:\/\/t.co\/[a-z0-9A-Z]*/", "", $result); //remove t.co links to images and wensites
$result = preg_replace("/@[a-z0-9A-Z]*/", "", $result); //remove mentions
$result = preg_replace("/[ ]{2,}/", "", $result); //remove extra spaces
$result = preg_replace("/[\r\n]{2,}/", "", $result); //remove extra line breaks
return $result;
}
require_once 'twitteroauth/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', 'CIIXyY3gpNhRw7OJE1CpKgMvq');
define('CONSUMER_SECRET', 'xFUZkICzoaNBicJgGvxyXZCk9CRMJRwNNlKYbAtVXoX50CHpac');
$toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$q=$_POST['queryt'];
$type=$_POST['typ'];
$sql= new mysqli("localhost","DBUSER","PASSWORD","DATABASE");
if($sql->connect_error)
die("Coudn't connect");
$del="delete from twitter;";
if(!($sql->query($del)))
echo $sql->error;
if($type==="hashtag"){
$query = array(
"q" => "#$q -filter:retweets",
"count" => "100",
"result_type" => "recent",
"lang" => "en",
);
$results = $toa->get('search/tweets', $query);
foreach ($results->statuses as $key=>$result) {
$tweet=string_sanitize($result->text);
$qp="insert into twitter values('$tweet','$q');";
if(!($sql->query($qp)))
echo $sql->error."<br/>";
}
}
if($type==="username"){
$query = array(
"screen_name" => "$q",
"count" => "500",
"result_type" => "recent",
"lang" => "en"
);
$results = $toa->get('statuses/user_timeline', $query);
foreach ($results as $key=>$result) {
$tweet=string_sanitize($result->text);
$qp="insert into twitter values('$tweet','$q');";
if(!($sql->query($qp)))
{
echo $sql->error."<br/>"; exit();
}
}
}
$sql->close();
header("location:index.php?upload=true");
?>