-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNews.php
More file actions
221 lines (196 loc) · 8.68 KB
/
News.php
File metadata and controls
221 lines (196 loc) · 8.68 KB
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
<?php require_once("include/NewsDB.php"); ?>
<?php require_once("include/Sessions.php"); ?>
<?php require_once("include/Functions.php"); ?>
<?php
if(!isset($_SESSION["Username"])){
$_SESSION["ErrorMessage"] = "Please Register/Login to view content.";
Redirect_to("Blog.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TechVents | Blog</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="js/search.js" ></script>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" integrity="sha256-h20CPZ0QyXlBuAw7A+KluUYx/3pK+c7lYEpqLTlxjYQ=" crossorigin="anonymous" />
</head>
<!-- <script>
$(document).ready(function(){
$.ajax({
type: "POST",
url: "Search.php",
data: {
Search: 'everything',
},
success: function (html) {
$("#display").html(html).show();
},
});
})
</script> -->
<body>
<?php require_once("include/Functions.php"); ?>
<div class="menu-btn">
<i class="fas fa-bars fa-2x"></i>
</div>
<div class="container" id="news">
<!-- NavBar -->
<nav class="nav-main">
<img src="images/icons8-bluestacks-240.png" alt="Techvents Logo" class="logo">
<img src="images/Techvents-text-removebg-preview.png" alt="Techvents Logo" class="logo-text">
<ul class="main-menu" style="margin-left: 36%;">
<li style="margin-right: 15px;"><a href="Blog.php">Blogs</a></li>
<li style="margin-right: 15px;"><a href="Events.php">Events</a></li>
<li style="margin-right: 15px;"><a href="News.php">News</a></li>
<?php
if(User_Login() || Login()){
echo '<li style="margin-right: 20px;"><a href="Logout.php">Logout</a></li>';
}
else{
echo '<li style="margin-right: 20px;"><a href="Login.php">Login</a></li>';
}
?>
<li></li>
</ul>
<ul class="right-menu">
</ul>
</nav>
</div>
<script>
document.querySelector('.menu-btn').addEventListener(
'click',()=> document.querySelector('.main-menu').classList.toggle('show')
);
</script>
<div class="body-container">
<div class="post-listing">
<?php echo Message(); echo SuccessMessage(); ?>
<?php
error_reporting(E_ERROR | E_PARSE);
$Events = array();
$eventsData;
if(isset($_GET["Category"])){
//Category
echo 'Category: <button style=" background-image: linear-gradient(to right top, #2ec771, #4dd163);; padding:8px; border-radius:20px; color:white; border:none; margin-bottom:10px"><b>'.$_GET['Category'].'</b></button>';
$SearchCategory = $_GET["Category"];
$url = "http://newsapi.org/v2/everything?q=".$SearchCategory."&sources=techcrunch&language=en&apiKey=".$NEWS_API_KEY;
$url = preg_replace("/ /", "%20", $url);
} else {
//Defualt
echo '<button style=" background-image: linear-gradient(to right top, #2ec771, #4dd163);; padding:8px; border-radius:20px; color:white; border:none; margin-bottom:10px"><b>Headlines</b></button>';
$url = "https://newsapi.org/v2/everything?domains=techcrunch.com,thenextweb.com&language=en&apiKey=".$NEWS_API_KEY;
}
$response = file_get_contents($url);
$newsData = json_decode($response);
foreach($newsData as $news){
foreach($news as $col){
?>
<!-- For loop idhar aayega -->
<div class="post-container">
<img src="<?php echo $col->urlToImage;?>" alt="">
<div class="post-text" id="events">
<div class="first-line">
<h3 class="post-title">
<?php
$Title;
if(strlen($col->title)>50){$Title = substr($col->title,0,50);}
else{$Title = $col->title;}
?>
<a target="_blank" href="<?php echo $col->url?>">
<?php echo $Title?>...
</a>
</h3>
<?php
$datePublished;
if(strlen($col->publishedAt)>11){$datePublished = substr($col->publishedAt,0,11);}
else{$datePublished = $col->publishedAt;}
?>
<p class="read-time"><?php echo $datePublished;?></p>
</div>
<div class="third-line">
<h4> <?php echo $col->source->name;?></h4>
</div>
<div class="second-line">
<p>
<?php echo $col->description; ?>
</p>
</div>
</div>
</div>
<?php } }?>
</div>
<!-- Right Panel -->
<div class="right-panel">
<!-- About Me -->
<div class="about-me">
<?php
if(isset($_SESSION["Username"])){ ?>
<img src="https://img.icons8.com/ios-filled/150/000000/user-male-circle.png" alt="user-img"/>
<p><b><?php echo $_SESSION["Username"] ?></b></p>
<hr>
<?php
if($_SESSION['Role']=="User"){
echo '<p><a href="dashboard_user.php"> My Dashboard </a></p>';
echo '<p><a href="AddNewPost_User.php"> Write a Post </a></p>';
}
if($_SESSION['Role']=="Admin"){
echo '<p><a href="dashboard.php"> My Dashboard </a></p>';
echo '<p><a href="AddNewPost.php"> Write a Post </a></p>';
}
?>
<?php }
?>
</div>
<!-- Categories -->
<div class="category-container">
<h4>Domains</h4>
<div class="category-content">
<?php
$ConnectingDB;
$ViewQuery = "SELECT * FROM category ORDER BY datetime desc";
$Execute = $Connection->query($ViewQuery);
while($DataRows = $Execute->fetch_assoc()){
$Id = $DataRows['id'];
$Category = $DataRows['name'];
?>
<span>
<button class="category">
<a href="News.php?Category=<?php echo $Category; ?>"><?php echo $Category; ?></a>
</button>
</span>
<?php } ?>
</div>
</div>
<!-- Recent Posts -->
<div class="recent-posts-container">
<h4>Recent Posts</h4>
<div class="recent-posts-content">
<?php
$ConnectingDB;
$ViewQuery = "SELECT * FROM admin_panel ORDER BY id desc LIMIT 0,5";
$Execute = $Connection->query($ViewQuery);
while($DataRows = $Execute->fetch_assoc()){
$Id = $DataRows["id"];
$Title = $DataRows["title"];
$DateTime = $DataRows["datetime"];
$Image = $DataRows["image"];
if(strlen($DateTime)>11){ $DateTime = substr($DateTime,0,17);}
if(strlen($Title)>11){ $Title = substr($Title,0,40).'...'; }
?>
<div class="recent-postt">
<img src="./uploads/<?php echo htmlentities($Image); ?>" alt="Post-Image">
<div class="recent-post">
<p><a href="FullPost.php?id=<?php echo $Id; ?>"><?php echo htmlentities($Title); ?></a></p>
<p id="time"><?php echo htmlentities($DateTime) ?></p>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</body>
</html>