-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
172 lines (134 loc) · 5.41 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
<?php
session_start();
if (!isset($_SESSION['user']) || $_SESSION['authenticated'] == false) {
header("location: test.php");
}
$servername = "localhost";
$username = "root"; //Eneter Username for ESSCC Earthquake DB
$database="moose-pirates";
$password="MYPASSWORD123";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysqli_select_db( $conn, "moose-pirates") or die( "Unable to select database");
$query2 = "Select id from users where email = '". $_SESSION['user']."'";
$result2 = mysqli_query($conn, $query2);
$request = NULL;
while ($row = mysqli_fetch_assoc($result2)) {
$query = "Select keyword from user_keywords where id in (Select friend_id FROM friends where id = ". $row['id'].") OR id = ". $row['id']."
";
}
$result = mysqli_query($conn, $query);
?>
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="css/font-awesome.css" type="text/css">
<link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
<link href="css/docs.css" rel="stylesheet" >
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/bootstrap-social.css" type="text/css" />
<meta charset="UTF-8">
<title>Moose Pirates</title>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<div class="header_logo" id="logo">
<a href="index.php">
<img src="image/moose_news.png" class="img-responsive" alt="Moose Pirates" style="height:75px">
</a>
</div>
</div>
<div class="navbar-header navbar-right" >
<a class="navbar-brand" href="settings.php"><span class="glyphicon glyphicon glyphicon-cog" aria-hidden="true"></span></a>
</div>
</div>
</nav>
<div class="row" style="margin-left:10px">
<div class="col-md-11" >
<div>
<div class="row">
<?php
if(mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)) {
require_once 'HTTP/Request2.php';
$request = new Http_Request2('https://api.cognitive.microsoft.com/bing/v5.0/news/search');
$url = $request->getUrl();
$headers = array(
// Request headers
'Ocp-Apim-Subscription-Key' => '2d1dd243b2d14531a77d2655db73d8d4',
);
$request->setHeader($headers);
$parameters = array(
// Request parameters
'q' => $row['keyword'],
'count' => '8',
'offset' => '0',
'mkt' => 'en-us',
'safeSearch' => 'Moderate',
);
$url->setQueryVariables($parameters);
$request->setMethod(HTTP_Request2::METHOD_GET);
// Request body
$request->setBody("{body}");
try
{
$response = $request->send();
$news = json_decode ($response->getBody(), 1);
if (empty($news)){
echo "please set your keywords in settings to see articles that relate to your specific intrests";
}
else{
$news = json_decode ($response->getBody(), 1);
foreach ($news['value'] as $acc) {
if (isset($acc['image']['thumbnail']['contentUrl'])){
echo "<div class='col-md-3 col-sm-4 col-lg-2 col-xl-2 news_tile image'>";
echo "<img src='" . $acc['image']['thumbnail']['contentUrl'] . "' height='100%' width='100%'</img>";
echo "<h2 class='ban".
rand(1,3)."'><span><a href='". $acc['url'] ."' target='_blank'>" . $acc['name'] . "</a></span></h2>";
echo "</div>";
}
}
}
}
catch (HttpException $ex)
{
echo $ex;
}
}
} else{
echo "<h3>Please set your keywords in settings to see articles that relate to your specific intrests</h3>";
}
?>
</div>
</div>
</div>
<div class="col-md-1 center" style=" text-align:center">
<div class="sidebar-nav-fixed pull-right affix">
<p style="padding-right: 4px"> <b> Keywords </b></p>
<p style="padding-right: 4px"><span class="glyphicon glyphicon glyphicon glyphicon-duplicate" style="color: rgba(80, 48, 12, 1); " aria-hidden="true"></span> Yours </p>
<p style="padding-right: 4px"><span class="glyphicon glyphicon glyphicon glyphicon-duplicate" style="color: rgba(12, 48, 90, 1)" aria-hidden="true"></span> Friends </p>
<div class="well">
<ul class="nav ">
<li> <a href="http://www.facebook.com" target='_blank' class="btn btn-social-icon btn-lg btn-facebook"><span class="fa fa-facebook"></span></a>
</li>
<li><a href="http://www.reddit.com" target='_blank' class="btn btn-social-icon btn-lg btn-reddit"><span class="fa fa-reddit"></span></a>
</li>
<li><a href="http://www.google.com" target='_blank' class="btn btn-social-icon btn-lg btn-google"><span class="fa fa-google"></span></a>
</li>
<li><a href="http://www.twitter.com" target='_blank' class="btn btn-social-icon btn-lg btn-twitter"><span class="fa fa-twitter"></span></a>
</li>
<li><a href="http://www.instagram.com" target='_blank' class="btn btn-social-icon btn-lg btn-instagram"><span class="fa fa-instagram"></span></a>
</li>
</ul>
</div>
<!--/.well -->
</div>
</div>
</body>
</html>