Anda di halaman 1dari 7

<?

php
session_start();
// UNTUK KONEKSI TANPA HARUS LOGIN
include "connect2.php";
$get = $_GET;

// MENGATUR VARIABEL $_GET["PG"] YANG DIPEROLEH


if (isset($_GET['pg'])) {
if($_GET['pg'] == "" or $_GET['pg'] <= 0) {
header("Location: ?pg=1");
}
}

if(isset($_SESSION['user'])) {
$username = $_SESSION['user'];
}

$halaman = 5;
$batas = 550;
?>
<html>
<head>
<title>Bloguki</title>
<link href='favicon.png' rel='icon' type='image/x-icon'/>
<link rel="stylesheet" href="style/paging.css">
</head>
<body>
<div id="wrapper">
<div id="header-wrapper">
<div class="header">
<a>Bloguki</a><small>A blog for Web Project</small>
<?php
if(!isset($_SESSION['user'])) {
$text = "Login";
} else {
$text = "Archive";
}
echo "<div class='account'><a
href='admin'>$text</a></div>";
?>
</div>
</div>
<div id="content-wrapper">
<div id="search-box">
<form method="get" action="search.php">
<input type="text" name="s" placeholder="Search
here..."/>
<input type="submit" value="Search"/>
</form>
</div>
<div id="content">
<?php
// JIKA BELUM LOGIN
if(!isset($_SESSION['user'])){
// === PAGING START ====
$a = mysql_query("SELECT * FROM
posts".mysql_error());
$b = mysql_num_rows($a);
// MEMBUAT VARIABEL UNTUK PAGING
$page = isset($_GET['pg']) ? (int)
$_GET['pg'] : 1;
$mulai = ($page>1) ? ($page * $halaman) -
$halaman : 0;
$pages = ceil($b/$halaman);
$no =$mulai+1;
// === PAGING END ===

// MEMBANGUN QUERY
$query = mysql_query("SELECT * FROM posts ORDER
BY post_id DESC LIMIT $mulai,$halaman");

// MEMBUAT PERULANGAN
while ($hasil = mysql_fetch_array($query)) {
// MENDEFINISIKAN VARIABEL DARI QUERY
$post_id = $hasil['post_id'];
$title = stripslashes($hasil['title']);
$tag = stripslashes($hasil['tag']);
$content =
stripslashes($hasil['content']);
$date = stripslashes($hasil['date']);
$writer = stripslashes($hasil['writer']);

// MENAMPILKAN POSTING
echo "<h2><a href='post.php?
id=$post_id'>$title</a></h2>";
echo "On <a href='post.php?
id=$post_id'>$date</a> with tag <a href='tag?tag=$tag'>$tag</a>, writed by : <a
href='tag?w=$writer'>$writer</a>";
echo
"<p>".substr(strip_tags($content),0,$batas)."</p>";
echo "<a href='post.php?id=$post_id'
id='read-more'>Read more</a>";
echo "<hr>";
}
// JIKA SUDAH LOGIN
} else {
// === PAGING START ====
$a = mysql_query("SELECT * FROM posts
WHERE user_id='$username'".mysql_error());
$b = mysql_num_rows($a);

// MEMBUAT VARIABEL UNTUK PAGING


$page = isset($_GET['pg']) ? (int)
$_GET['pg'] : 1;
$mulai = ($page>1) ? ($page * $halaman) -
$halaman : 0;
$pages = ceil($b/$halaman);
$no =$mulai+1;
// === PAGING END ===

$query = mysql_query("SELECT * FROM posts WHERE


user_id='$username' ORDER BY post_id DESC LIMIT $mulai,$halaman");

// MEMBUAT PERULANGAN
while ($hasil = mysql_fetch_array($query)) {
// MENDEFINISIKAN VARIABEL DARI QUERY
$post_id = $hasil['post_id'];
$title = stripslashes($hasil['title']);
$tag = stripslashes($hasil['tag']);
$content =
stripslashes($hasil['content']);
$date = stripslashes($hasil['date']);
$writer = stripslashes($hasil['writer']);

// MENAMPILKAN POSTING
echo "<h2><a href='post.php?
id=$post_id'>$title</a></h2>";
echo "On <a href='post.php?
id=$post_id'>$date</a> with tag <a href='tag?tag=$tag'>$tag</a>, writed by : <a
href='tag?w=$writer'>$writer</a>";
echo
"<p>".substr(strip_tags($content),0,$batas)."</p>";
echo "<a href='post.php?id=$post_id'
id='read-more'>Read more</a>";
echo "<hr>";
}
}
if($b > $halaman) {
?>
<ul class='paging'>
<?php
// Previous Button
if (isset($_GET['pg'])) {
$pg = $_GET['pg'];
if($pg>$pages){header("Location:
../bloguki");}
if ($pg == 1) {
echo "<li><span class='page-
link'>First</span></li>";
echo "<li><span class='page-
link'>Previous</span></li>";
} else {
$get['pg'] = 1;
$url = http_build_query($get);
echo "<li><a class='page-link'
href='".$_SERVER['PHP_SELF']."?".$url."'>First</a></li>";
$get['pg'] = ($pg-1);
$url = http_build_query($get);
echo "<li><a class='page-link'
href='".$_SERVER['PHP_SELF']."?".$url."'>Previous</a></li>";
}
} else {
echo "<li><span class='page-
link'>First</span></li>";
echo "<li><span class='page-
link'>Previous</span></li>";
}
// Numbered Button
for ($i=1; $i<=$pages ; $i++){
if (isset($_GET['pg'])) {
$pg = $_GET['pg'];
if ($pages != 1) {
if ($i == $pg) {
echo "<li><span
class='page-link active'>$i</span></li>";
} else {
$get['pg'] = $i;
$url =
http_build_query($get);
echo "<li><a href='".
$_SERVER['PHP_SELF']."?".$url."' class='page-link'>$i</a></li>";
}
} else {
echo "<li><span class='page-
link'>$i</span></li>";
}
} else {
if ($i == 1) {
$kelas = "active";
} else {
$kelas = "";
}
if ($pages <> 1) {
$get['pg'] = $i;
$url =
http_build_query($get);
echo "<li><a href='".
$_SERVER['PHP_SELF']."?".$url."' class='$kelas page-link'>$i</a></li>";
} else {
echo "<li><span class='page-
link'>$i</span></li>";
}
}
}
// Next Button
if (isset($_GET['pg'])) {
$pg = $_GET['pg'];
if ($pg == $pages) {
echo "<li><span class='page-
link'>Next</span></li>";
echo "<li><span class='page-
link'>End</span></li>";
} else {
$get['pg'] = ($pg+1);
$url = http_build_query($get);
echo "<li><a class='page-link'
href='".$_SERVER['PHP_SELF']."?".$url."'>Next</a></li>";
$get['pg'] = $pages;
$url = http_build_query($get);
echo "<li><a class='page-link'
href='".$_SERVER['PHP_SELF']."?".$url."'>End</a></li>";
}
} else {
if ($pages == 1) {
echo "<li><span class='page-
link'>Next</span></li>";
echo "<li><span class='page-
link'>End</span></li>";
} else {
$get['pg'] = 2;
$url = http_build_query($get);
echo "<li><a class='page-link'
href='".$_SERVER['PHP_SELF']."?".$url."'>Next</a></li>";
$get['pg'] = $pages;
$url = http_build_query($get);
echo "<li><a class='page-link'
href='".$_SERVER['PHP_SELF']."?".$url."'>End</a></li>";
}
}
?>
</ul>
<?php } ?>
</div>
<div class="sidebar">
<div class="widget">

</div>
<div class="widget">
<h2>Recent Posts</h2>
<?php
$batas = 150;
if(isset($_SESSION['user'])){
$query = mysql_query("SELECT * FROM posts
WHERE user_id='$username' ORDER BY post_id DESC LIMIT 0,5");

// MEMBUAT PERULANGAN
while ($hasil =
mysql_fetch_array($query)) {
// MENDEFINISIKAN VARIABEL DARI
QUERY
$post_id = $hasil['post_id'];
$title =
stripslashes($hasil['title']);
$tag = stripslashes($hasil['tag']);
$content =
stripslashes($hasil['content']);
$date =
stripslashes($hasil['date']);
$writer =
stripslashes($hasil['writer']);

// MENAMPILKAN POSTING
echo "<h3><a href='post.php?
id=$post_id'>$title</a></h3>";
echo "On <a href='post.php?
id=$post_id'>$date</a> with tag <a href='tag?tag=$tag'>$tag</a>, writed by : <a
href='tag?w=$writer'>$writer</a>";
echo
"<p>".substr(strip_tags($content),0,$batas)."</p>";
}
} else {
// MEMBANGUN QUERY
$query = mysql_query("SELECT * FROM posts
ORDER BY post_id DESC LIMIT 0,5");

// MEMBUAT PERULANGAN
while ($hasil =
mysql_fetch_array($query)) {
// MENDEFINISIKAN VARIABEL DARI
QUERY
$post_id = $hasil['post_id'];
$title =
stripslashes($hasil['title']);
$tag = stripslashes($hasil['tag']);
$content =
stripslashes($hasil['content']);
$date =
stripslashes($hasil['date']);
$writer =
stripslashes($hasil['writer']);

// MENAMPILKAN POSTING
echo "<h3><a href='post.php?
id=$post_id'>$title</a></h3>";
echo "On <a href='post.php?
id=$post_id'>$date</a> with tag <a href='tag?tag=$tag'>$tag</a>, writed by : <a
href='tag?w=$writer'>$writer</a>";
echo
"<p>".substr(strip_tags($content),0,$batas)."</p>";
}
}
?>
</div>
<div class="widget">

</div>
</div>
</div>
<div id="footer-wrapper">
<div class="widget">
<h2>About</h2>
<p class="about">Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna
sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros
quis urna.</p>
<ul>
<li>https://www.maringngerrang.com/</li>
<li>http://localhost/www.w3schools.com/</li>
<li>http://localhost/bloguki/</li>
</ul>
</div>
<div class="widget">
<h2>Label</h2>
<ul>
<?php
if(isset($_SESSION['user'])) {
$query = mysql_query("SELECT DISTINCT tag
FROM posts WHERE user_id='$username'");
while ($hasil =
mysql_fetch_assoc($query)) {
$tag = stripslashes($hasil['tag']);
echo "<li> <a href='tag?
tag=$tag'>$tag</a></li>";
}
} else {
$query = mysql_query("SELECT DISTINCT tag
FROM posts");
while ($hasil =
mysql_fetch_assoc($query)) {
$tag = stripslashes($hasil['tag']);
echo "<li> <a href='tag?
tag=$tag'>$tag</a></li>";
}
}
?>
</ul>
</div>
<div class="widget">
<h2>Writer</h2>
<ul>
<?php
if(isset($_SESSION['user'])) {
$query = mysql_query("SELECT DISTINCT
writer FROM posts WHERE user_id='$username'");
while ($hasil =
mysql_fetch_assoc($query)) {
$writer =
stripslashes($hasil['writer']);
echo "<li> <a href='tag?
w=$writer'>$writer</a></li>";
}
} else {
$query = mysql_query("SELECT DISTINCT
writer FROM posts");
while ($hasil =
mysql_fetch_assoc($query)) {
$writer =
stripslashes($hasil['writer']);
echo "<li> <a href='tag?
w=$writer'>$writer</a></li>";
}
}
?>
</ul>
</div>
<div class='copyright'>Copyright &copy; <a
href="http://www.maringngerrang.com/" target="_blank">Maringngerrang Blog</a> - All
Rights Reserved</div>
</div>
</div>
</body>
</html>