Skip to content

Commit

Permalink
Blog sudah jadi
Browse files Browse the repository at this point in the history
  • Loading branch information
kevhnmay94 committed Oct 14, 2014
1 parent 975c060 commit 345f228
Show file tree
Hide file tree
Showing 12 changed files with 854 additions and 23 deletions.
94 changes: 94 additions & 0 deletions addcomment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

function formatDateDiff($start, $end=null) {
if(!($start instanceof DateTime)) {
$start = new DateTime($start);
}

if($end === null) {
$end = new DateTime();
}

if(!($end instanceof DateTime)) {
$end = new DateTime($start);
}

$interval = $end->diff($start);

$format = array();
if($interval->y !== 0) {
$format[] = "%y TAHUN";
}
if($interval->m !== 0) {
$format[] = "%m BULAN";
}
if($interval->d !== 0) {
$format[] = "%d HARI";
}
if($interval->h !== 0) {
$format[] = "%h JAM";
}
if($interval->i !== 0) {
$format[] = "%i MENIT";
}
if($interval->s !== 0) {
if(!count($format)) {
return "BARU SAJA";
} else {
$format[] = "%s DETIK";
}
}

if(count($format) > 1) {
$format = array_shift($format)." dan ".array_shift($format);
} else {
$format = array_pop($format);
}

return $interval->format($format." YANG LALU");
}
//creating connection to database
$link = mysqli_connect('localhost', 'kevhnmay94', "", 'simpleblog');
$nama = mysqli_escape_string($link, $_POST['nama']);
$email = mysqli_escape_string($link, $_POST['email']);
$id = mysqli_escape_string($link, $_POST['pid']);
$komentar = mysqli_escape_string($link, $_POST['komentar']);
date_default_timezone_set('Asia/Jakarta');
$tanggal = date("Y-m-d H:i:s");

$query = "INSERT INTO `comments`(`pid`, `name`, `date`, `comment`, `email`)
VALUES ($id,'$nama','$tanggal','$komentar','$email')";

//insert these data to database
if(!mysqli_query($link, $query))
{
die('Error ' + mysqli_errno($link));
}

//tampilkan data ke screen
$query = "SELECT * FROM `comments` WHERE pid=$id ORDER BY date DESC";
if(!($results = mysqli_query($link, $query)))
{
die('Error ' + mysqli_errno($link));
}

foreach($results as $result)
{
?>
<li class="art-list-item">
<div class="art-list-item-title-and-time">
<h2 class="art-list-title"><?php echo $result['name']; ?></h2>
<?php
//formatting tanggal
$date = date_create($result['date']);

?>
<div class="art-list-time"><?php
echo formatDateDiff($date);?></div>
</div>
<p><?php echo nl2br($result['comment']); ?></p>
</li>
<?php
}
mysqli_close($link);
?>
37 changes: 25 additions & 12 deletions assets/css/screen.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
@import url(http://fonts.googleapis.com/css?family=Open+Sans);
@import url(http://fonts.googleapis.com/css?family=Questrial);

/* Reset & Basics (Inspired by E. Meyers)
================================================== */
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, address, cite, code, em, img, small, strong, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, embed, figure, figcaption, footer, header, hgroup, menu, nav, section, summary, time, audio, video {
Expand Down Expand Up @@ -50,7 +47,7 @@ h1 {
}

h2 {
font-size: 45px;
font-size: 35px;
padding-bottom: 25px;
}

Expand Down Expand Up @@ -106,14 +103,14 @@ header#teaser h1 {
/* Links
================================================== */
a {
color: #F40034;
color: #3403F7;
text-decoration: none;
-webkit-transition: color .2s ease-in-out;
-moz-transition: color .2s ease-in-out;
transition: color .2s ease-in-out;
}
a:hover {
color: #F40034;
color: #FF0000;
}

/* Layout
Expand Down Expand Up @@ -161,6 +158,7 @@ a:hover {
}
#logo {
float: left;

}
.nav-primary {
float: right;
Expand Down Expand Up @@ -233,7 +231,7 @@ div.cover > img {
}
/* Contains the time, title and subtitle for an article */
.art-header-inner {
position: fixed;
position: relative;
top: 300px;
left: 50%;
margin-left: -490px;
Expand Down Expand Up @@ -292,7 +290,6 @@ div.cover > img {
line-height: 1.5;
}
.art-body-inner a:hover {
border-bottom: 1px solid #F40034;
padding-bottom:2px;
}
.art-body-inner ul,
Expand Down Expand Up @@ -375,6 +372,8 @@ div.cover > img {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
position: relative;
top: 40px;
}


Expand Down Expand Up @@ -410,14 +409,14 @@ div.cover > img {
font-size: 12px;
line-height: 20px;
letter-spacing: 2px;
text-transform: uppercase;
color: #999;
}
.art-list-title a {
color: #000;
cursor: pointer;
}
.art-list-title a:hover {
color: #F40034;
color: #3403F7;
}
.art-list-item p {
width: 65%;
Expand All @@ -426,6 +425,13 @@ div.cover > img {
margin-bottom: 0;
font-size: 16px;
line-height: 24px;
text-align: justify;
}

.art-list-item .editable {
position: relative;
left: 30%;
cursor: pointer;
}


Expand Down Expand Up @@ -840,18 +846,25 @@ hr.featured-article:after {
}

#contact-area textarea {
height: 90px;
height: 250px;
}

#contact-area textarea:focus, #contact-area input:focus {
border: 2px solid #900;
border: 2px solid #0084B4;
}

#contact-area input.submit-button {
width: 100px;

}

#contact-area #errormsg{
position:relative;
left:115px;
color: #FF0000;
font-size:medium;
}

label {
float: left;
text-align: right;
Expand Down
41 changes: 41 additions & 0 deletions assets/js/formValidation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function Validation()
{
var tanggal = document.getElementById('Tanggal').value;
document.getElementById('errormsg').innerHTML="";
var tanggal1 = parseDate(tanggal);
if(tanggal1 == null)
{
return false;
}
else
{
var tanggal2 = new Date();
var result = tanggal1 > tanggal2;
if(result)
{
var tanggal_reverse = tanggal.split("-").reverse().join("-");
document.getElementById('Tanggal').value=tanggal_reverse;
return true;
}
else
{
document.getElementById('errormsg').innerHTML="*Tanggal sudah lewat. Masukkan tanggal yang valid.";
return false;
}
}
}

function parseDate(str) {
var m = str.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/);
var tanggal3;
if(m)
{
var tanggal3 = new Date(m[3],m[2]-1,m[1]-(-1));
}
else
{
document.getElementById("errormsg").innerHTML="*format tanggal salah. (format:dd-mm-yyyy)";
var tanggal3 = null;
}
return tanggal3;
}
91 changes: 91 additions & 0 deletions assets/js/getdatabase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* function addcomment(id)
{
var content = document.getElementById('ajaxcontent');
var nama = document.getElementById('nama').value;
var komentar = document.getElementById('komentar').value;
var email = document.getElementById('email').value;
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
content.innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","addcomment.php?id="+id+"&nama="+nama+"&komentar="+komentar+"&email="+email,true);
xmlhttp.send();
} */

function ajaxRequest(){
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes[i])
}
catch(e){
//suppress error
}
}
}
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
return new XMLHttpRequest()
else
return false
}

function loadpost(id)
{
var xmlhttp = new ajaxRequest();
var content = document.getElementById('ajaxcontent');
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
content.innerHTML=xmlhttp.responseText;
}
};
xmlhttp.open("GET", "getdatabase.php?id=" + id, true);
xmlhttp.send();
}

function validatecomment()
{
var email = document.getElementById('email').value;
var regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(email != "")
{
var valid = regex.test(email);
var errormessage = document.getElementById('errormsg');

if(valid)
{
errormessage.innerHTML="";
var xmlhttp = new ajaxRequest();
var content = document.getElementById('ajaxcontent');
var nama = encodeURIComponent(document.getElementById('nama').value);
var komentar = encodeURIComponent(document.getElementById('komentar').value);
var id = encodeURIComponent(document.getElementById('pid').value);
console.log(id);
var email2 = encodeURIComponent(email);
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4 && ((xmlhttp.status == 200) || (window.location.href.indexOf("http")==-1)))
{
content.innerHTML = xmlhttp.responseText;
}
};

xmlhttp.open("POST","addcomment.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("nama="+nama+"&komentar="+komentar+"&email="+email+"&pid="+id);

}
else
{
errormessage.innerHTML="Format email tidak valid";
}
}
}

12 changes: 12 additions & 0 deletions assets/js/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function hapus(id)
{
var konfirmasi = confirm('Apakah anda yakin menghapus post ini?');
if(konfirmasi)
{
var formObjects = document.forms['post'];
var formElements = formObjects.elements['id'];
formElements.value = id.substring(1);
formObjects.action = "deletePost.php";
formObjects.submit();
}
}
21 changes: 21 additions & 0 deletions deletePost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

//establish connection to database
$con = mysqli_connect('localhost', 'kevhnmay94', "", 'simpleblog');
$id = mysqli_real_escape_string($con, $_POST['id']);

//query for deleting entry
$query = "DELETE FROM `posts`
WHERE `id` = $id";

if(!mysqli_query($con, $query))
{
die('Error ' . mysqli_errno($con));
}

echo "<br>entry has been deleted.";

//close connection with database
mysqli_close($con);
header('Location: index.php');
?>
Loading

0 comments on commit 345f228

Please sign in to comment.