-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
192 lines (162 loc) · 8.29 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
<?php
/**
* Created by PhpStorm.
* User: bunny
* Date: 22/08/17
* Time: 5:28 PM
*/
require_once "twitteroauth-master/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
require('twitterKey.php');
if (isset($_GET['q']) && !empty($_GET['q'])) {
$query = $_GET['q'];
$homePage = false;
$conn = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$conn->setTimeouts(10, 15);
$search = $conn->get("search/tweets", ["q" => $query,"count"=>10]);
//echo print_r($search);
} else {
if(isset($_GET['re']) && !empty($_GET['re'])){
$conn = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$conn->setTimeouts(10, 15);
$search = $conn->post("statuses/update", ["status" => "hello world"]);
echo json_encode($search);
}
$homePage = true;
}
?>
<html>
<head>
<title>Twitter Search</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="css/main.css" rel="stylesheet"/>
</head>
<body>
<div class="container">
<div class="row">
<?php if ($homePage == true) { ?>
<div class=" jumbotron col-md-12"
style="color:white;background: url('./images/meteor.jpg');background-size: cover">
<h1 class=" text-center text-success ">Twitter Search</h1>
</div>
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
<hr class="colorgraph">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-md-offset-3">
<a type="submit" href="#search" class="btn btn-lg btn-success btn-block">Start Search</a>
</div>
</div>
<hr class="colorgraph">
</div>
<?php } else {
?>
<div class="row">
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
<hr class="colorgraph">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-md-offset-3">
<a type="submit" href="#search" class="btn btn-lg btn-success btn-block">Search More</a>
</div>
</div>
<hr class="colorgraph">
</div>
</div>
<div class="panel">
<div class="panel-body">
<h1> > <?php echo $query; ?></h1>
<hr/>
<ul class="timeline">
<?php
foreach ($search->statuses as $tweet) {
// echo json_encode($tweet, JSON_PRETTY_PRINT);
?>
<li>
<div class="timeline-badge">11<i class="fa fa-twitter"></i></div>
<div class="timeline-panel">
<div class="media">
<div class="media-left">
<img src="<?php echo $tweet->user->profile_image_url; ?>" class="media-object img-circle" style="width:60px">
</div>
<div class="media-body">
<h4 class="media-heading">
<a target="_blank" href="https://www.twitter.com/<?php echo $tweet->user->screen_name; ?>"><?php echo $tweet->user->name; ?>
</a>
<small> @<a target="_blank" href="https://www.twitter.com/<?php echo $tweet->user->screen_name; ?>"><?php echo $tweet->user->screen_name; ?>
</a>
</small>
</h4>
<p>
<small class="text-muted"><i class="glyphicon glyphicon-time"></i> <?php echo $tweet->created_at; ?>
via Twitter
</small>
</p>
<p><br>
<?php
$strLen=strlen($tweet->text);
$newText='';
$i=0;
// for($i=0;$i<$strLen;$i=$strLen){
foreach ($tweet->entities->urls as $URL){
$newText=$newText.substr($tweet->text,$i,$URL->indices[0]-$i).'<a target="_blank" href="'.$URL->expanded_url.'">'.substr($tweet->text,$URL->indices[0],$URL->indices[1]-$URL->indices[0]).'</a> ';
$i=$URL->indices[1]+1;
}
$newText=$newText.substr($tweet->text,$i,$strLen-$i);
// }
echo preg_replace("/#([^@
]*)/", "<a target=\"_new\" href=\"index.php?q=$1\">#$1</a>", $newText); ?></p>
<?php if (isset($tweet->entities->media)){
foreach($tweet->entities->media as $MEDIA){
?>
<a href="<?php echo $MEDIA->url; ?>" class="img img-responsive" target="_blank"> <img width="100%" src="<?php echo $MEDIA->media_url; ?>"/></a>
<?php
}
?>
<?php
}
?>
<hr/>
<div class="row" style="text-align:center">
<div class="col-md-6">Retweet : <?php echo $tweet->retweet_count; ?></div>
<div class="col-md-6">Favaorite :<?php echo $tweet->favorite_count; ?></div>
</div>
</div>
</div>
</div>
</li>
<?php } ?>
</ul>
</div>
</div>
<?php
} ?>
</div>
</div>
<div id="search">
<button type="button" class="close">×</button>
<form action="#">
<input type="search" name="q" value="" placeholder="type keyword(s) here"/>
<input type="submit" class="btn btn-primary btn-lg" value="Search Twitter"/>
</form>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script>
$(function () {
$('a[href="#search"]').on('click', function (event) {
event.preventDefault();
$('#search').addClass('open');
$('#search > form > input[type="search"]').focus();
});
$('#search, #search button.close').on('click keyup', function (event) {
if (event.target == this || event.target.className == 'close' || event.keyCode == 27) {
$(this).removeClass('open');
}
});
});
</script>
</html>