flexible blog + post page

This commit is contained in:
Patryk 2018-12-12 21:20:00 +01:00
parent 5b47c5999b
commit 6ac3f0108d
8 changed files with 188 additions and 148 deletions

13
admin/polacz.php Normal file
View File

@ -0,0 +1,13 @@
<?php
function wczytaj($zmienna)
{
if (!isset($_GET[$zmienna]) || $_GET[$zmienna]=="")
die( "Blad! brak zmiennej: ".$zmienna ); // nie podano marki w $
return $_GET[$zmienna];
}
$baza = new mysqli("localhost", "root", "", "tas");
if (mysqli_connect_errno()) die( "Blad: ".mysqli_connect_error() );
mysqli_set_charset( $baza, 'utf8');
?>

36
blog-post/404.php Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>404 PAGE NOT FOUND</title>
<!-- Google font -->
<link href="https://fonts.googleapis.com/css?family=Cabin:400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Montserrat:900" rel="stylesheet">
<!-- Custom stlylesheet -->
<link type="text/css" rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="notfound">
<div class="notfound">
<div class="notfound-404">
<h3>Oops! Page not found</h3>
<h1><span>4</span><span>0</span><span>4</span></h1>
</div>
<h2>we are sorry, but the page you requested was not found</h2>
</div>
</div>
</body>
</html>

View File

@ -1,3 +1,6 @@
<?php if( !isset( $_SESSION ) ) session_start();
$_SESSION['user_id']=$_GET['user_id'];
?>
<html lang="pl-PL"> <html lang="pl-PL">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
@ -23,20 +26,8 @@
<body> <body>
<?php include "menu.php" ?>
<div class="dropdown">
<div id="menuwrap">
<button class="btn btn-light dropdown-toggle btn-lg" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Menu
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li><a href="#about">O mnie</a></li>
<li><a href="#post">Posty</a></a></li>
<li class="divider"></li>
<li><a href="../index.html">Strona główa</a></li>
</div>
</div>
</div>
<div id="aboutdown"> <div id="aboutdown">
<section id="about" name="about"></section> <section id="about" name="about"></section>
@ -52,22 +43,29 @@
<?php <?php
include "../settings/db_connect.php"; include "../settings/db_connect.php";
if(isset($_GET['user_id'])){
$user_id = $_GET['user_id'];
if ($sql = $mysqli->prepare("SELECT * FROM user WHERE user_id = 2 ")) $checkIfExists = $mysqli->query("SELECT * FROM user WHERE user_id =$user_id");
if ($checkIfExists) {
if($checkIfExists->num_rows === 0)
{
include "404.php";
}
else
{
if ($sql = $mysqli->prepare("SELECT * FROM user WHERE user_id =$user_id "))
{ {
$sql->execute(); $sql->execute();
$sql->bind_result($user_id,$username,$email,$password,$avatar, $about_short, $about_me, $about_blog, $FB, $TW); $sql->bind_result($user_id,$username,$email,$password,$avatar, $about_short, $about_me, $about_blog, $FB, $TW);
while ($sql->fetch()) while ($sql->fetch())
{ { ?>
echo "<div class=\"col-lg-8 name-desc\"> <div class="col-lg-8 name-desc">
<h2>$about_short</h2> <h2><?php echo $about_short; ?></h2>
<div class=\"col-md-11\"> <div class="col-md-11">
<p>$about_me <p><?php echo $about_me; ?></p>
</p> <p><?php echo $about_blog; ?></p>
<p>$about_blog</p>
</div> </div>
@ -75,23 +73,25 @@ if ($sql = $mysqli->prepare("SELECT * FROM user WHERE user_id = 2 "))
<div class=\"col-lg-4 name foto cover foto1\"> <div class="col-lg-4 name foto cover foto1">
<img src=\"$avatar\" class=\"align-text-bottom\"> <img src="<?php echo $avatar; ?>" class="align-text-bottom">
<p>$username</p> <p><?php echo $username; ?></p>
<a href=\"https://www.facebook.com/$FB\"> <a href="https://www.facebook.com/<?php echo $FB; ?>">
<div class=\"col-md-6\"> <div class="col-md-6">
<div class=\"fa fa-facebook-official\" style=\"font-size:36px\"> <div class="fa fa-facebook-official" style="font-size:36px">
<div class=\"ikona\"> <i><p1> $FB </p1></i> </div> <div class="ikona"> <i><p1> <?php echo $FB; ?> </p1></i> </div>
</div> </div> </a> </div> </div> </a>
<a href=\"https://twitter.com/$TW\"> <a href="https://twitter.com/<?php echo $TW; ?>">
<div class=\"col-md-6\"> <div class="col-md-6">
<div class=\"fa fa-twitter-square\" style=\"font-size:36px\"\"> <div class="fa fa-twitter-square" style="font-size:36px">
<div class=\"ikona\"><i><p1> $TW </p1></i> </div> <div class="ikona"><i><p1> <?php echo $TW; ?> </p1></i> </div>
</div> </a> </div> </div>
</div>
</a>
</div> </div>
</div> </div>
@ -103,12 +103,12 @@ if ($sql = $mysqli->prepare("SELECT * FROM user WHERE user_id = 2 "))
<section id=\"post\" name=\"post\"></section> <section id="post" name="post"></section>
<div id=\"postwrap\"> <div id="postwrap">
<div class=\"container\"> <div class="container">
<div class=\"row\"> <div class="row">
<h2>NAJNOWSZE WPISY</h2>"; <h2>NAJNOWSZE WPISY</h2>
} <?php }
$sql->close(); $sql->close();
} }
else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." ); else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." );
@ -116,44 +116,39 @@ else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." );
$trash = ''; $trash = '';
if ($sql = $mysqli->prepare("SELECT * FROM post ORDER BY data_dodania")) if ($sql = $mysqli->prepare("SELECT * FROM post WHERE blog_id=$user_id ORDER BY data_dodania"))
{ {
$sql->execute(); $sql->execute();
$sql->bind_result($post_id,$trash,$title,$description,$main,$image,$date,$mod_date); $sql->bind_result($post_id,$trash,$title,$description,$main,$image,$date,$mod_date);
while ($sql->fetch()) while ($sql->fetch())
{ { ?>
echo " <div class=\"col-lg-4 col-md-6 col-sm-6 col-xs-12 desc\"> <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 desc">
<div class=\"project\"> <div class="project">
<div class=\"photo-wrapper\"> <div class="photo-wrapper">
<div class=\"photo foto cover\"> <div class="photo foto cover">
<a href=\"post.php\"><img class=\"img-responsive\" src=\"$image\" alt=\"\"> <a href="post.php?post=<?php echo $post_id; ?>"><img class="img-responsive" src="<?php echo $image; ?>" alt="">
<div class=\"text-block\"> <div class="text-block">
<p1>$date</p1> <p1><?php echo $date; ?></p1>
</div> </div>
</div> </div>
</div> </div>
</div> <h1> $title</h1></a> </div> <h1> <?php echo $title; ?></h1></a>
</div>"; </div>
} <?php }
$sql->close(); $sql->close();
} }
else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." ); else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." );
$mysqli->close(); $mysqli->close();
}
}
}
else{
include "404.php";
}
?> ?>
</body> </body>
</html> </html>

View File

@ -1,6 +1,7 @@
<?php <?php
include "../settings/db_connect.php"; include "../settings/db_connect.php";
$_SESSION['message'] = ''; $_SESSION['message'] = '';
$post=$_GET['post'];
if ($_SERVER['REQUEST_METHOD'] == "POST"){ if ($_SERVER['REQUEST_METHOD'] == "POST"){
$tekst = $mysqli->real_escape_string($_POST['tekst']); $tekst = $mysqli->real_escape_string($_POST['tekst']);
$_SESSION['tekst'] = $tekst; $_SESSION['tekst'] = $tekst;
@ -9,7 +10,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST"){
if($mysqli->query($sql) === true){ if($mysqli->query($sql) === true){
$_SESSION['message'] = "Dodanie komentarza się powiodło!"; $_SESSION['message'] = "Dodanie komentarza się powiodło!";
header("location:post.php"); header("location:post.php?post=$post");
} }
else{ else{
$_SESSION['message'] = "Nie udało się dodać komentarza!"; $_SESSION['message'] = "Nie udało się dodać komentarza!";

13
blog-post/menu.php Normal file
View File

@ -0,0 +1,13 @@
<div class="dropdown">
<div id="menuwrap">
<button class="btn btn-light dropdown-toggle btn-lg" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Menu
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li><a href="#about">O mnie</a></li>
<li><a href="#post">Posty</a></a></li>
<li class="divider"></li>
<li><a href="../index.html">Strona główna</a></li>
</div>
</div>
</div>

View File

@ -1,3 +1,6 @@
<?php if( !isset( $_SESSION ) ) session_start();
$user_id = $_SESSION['user_id'];
?>
<html lang="pl-PL"> <html lang="pl-PL">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
@ -22,22 +25,17 @@
</head> </head>
<body> <body>
<div class="dropdown">
<div id="menuwrap">
<div class="dropdown">
<div id="menuwrap">
<button class="btn btn-light dropdown-toggle btn-lg" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <button class="btn btn-light dropdown-toggle btn-lg" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Menu Menu
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2"> <div class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li><a href="blog.php#about">O mnie</a></li> <li><a href="blog.php?user_id=<?php echo $user_id; ?>">Wróć do bloga</a></li>
<li><a href="blog.php#post">Posty</a></a></li> <li><a href="../index.html">Strona główna</a></li>
<li class="divider"></li>
<li><a href="../index.html">Strona główa</a></li>
</div> </div>
</div> </div>
</div> </div>
<div id="aboutdown"> <div id="aboutdown">
<section id="about" name="about"></section> <section id="about" name="about"></section>
@ -53,59 +51,56 @@
<?php <?php
include "../settings/db_connect.php"; include "../settings/db_connect.php";
$post = $_GET['post'];
$trash = ''; $trash = '';
if ($sql = $mysqli->prepare("SELECT * FROM post WHERE post_id = 18")) if ($sql = $mysqli->prepare("SELECT * FROM post WHERE post_id =$post"))
{ {
$sql->execute(); $sql->execute();
$sql->bind_result($post_id,$trash,$title,$description,$main,$image,$date,$mod_date); $sql->bind_result($post_id,$trash,$title,$description,$main,$image,$date,$mod_date);
while ($sql->fetch()) while ($sql->fetch())
{ { ?>
echo " <div class="col-lg-12 name foto2 cover foto1">
<div class=\"col-lg-12 name foto2 cover foto1\"> <img class="align-text-bottom" src="<?php echo $image; ?>" alt="">
<img class=\"align-text-bottom\" src=\"$image\" alt=\"\"> <h1><?php echo $title; ?></h1>
<h1> $title</h1>
</div> </div>
<div class=\"col-lg-12 name-desc\"> <div class="col-lg-12 name-desc">
<h3>$description</h3> <h3><?php echo $description; ?></h3>
</div> </div>
<div class=\"col-lg-12 name-desc\"> <div class="col-lg-12 name-desc">
<post>$main</post> <post><?php echo $main; ?></post>
<br> <br>
</div> </div>
<div id=\"particles-js\"> <div id="particles-js">
<div class=\"container\"> <div class="container">
<form class=\"form\" action=\"rating.php\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\"> <form class="form" action="rating.php?post=<?php echo $post; ?>" method="post" enctype="multipart/form-data" autocomplete="off">
<div class=\"row registerMain\"> <div class="row registerMain">
<div class=\"col-lg-12 col-md-12 col-sm-12 col-xs-12 name-desc\"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 name-desc">
<h4>$date</h4> <h4><?php echo $date; ?></h4>
</div><br> </div><br>
<div class=\"col-lg-6 col-md-6 col-sm-6 col-xs-12 name-desc elementsOnRegisterMain\"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 name-desc elementsOnRegisterMain">
<div class=\"form-group inputmain\"> <div class="form-group inputmain">
<div class=\"form-group\"> <div class="form-group">
<div class=\"rate\"> <div class="rate">
<z>Ocena:</z> <z>Ocena:</z>
<input type=\"submit\" id=\"star5\" name=\"rating\" value=5 /> <input type="submit" id="star5" name="rating" value=5 />
<input type=\"submit\" id=\"star4\" name=\"rating\" value=4 /> <input type="submit" id="star4" name="rating" value=4 />
<input type=\"submit\" id=\"star3\" name=\"rating\" value=3 /> <input type="submit" id="star3" name="rating" value=3 />
<input type=\"submit\" id=\"star2\" name=\"rating\" value=2 /> <input type="submit" id="star2" name="rating" value=2 />
<input type=\"submit\" id=\"star1\" name=\"rating\" value=1 /> <input type="submit" id="star1" name="rating" value=1 />
<label for=\"star5\" title=\"5 gwiazdek\">5 stars</label> <label for="star5" title="5 gwiazdek">5 stars</label>
<label for=\"star4\" title=\"4 gwiazdki\">4 stars</label> <label for="star4" title="4 gwiazdki">4 stars</label>
<label for=\"star3\" title=\"3 gwiazdki\">3 stars</label> <label for="star3" title="3 gwiazdki">3 stars</label>
<label for=\"star2\" title=\"2 gwiazdki\">2 stars</label> <label for="star2" title="2 gwiazdki">2 stars</label>
<label for=\"star1\" title=\"1 gwiazdka\">1 star</label> <label for="star1" title="1 gwiazdka">1 star</label>
</div> </div>
</div> </div>
</div> </div>
@ -115,9 +110,9 @@ if ($sql = $mysqli->prepare("SELECT * FROM post WHERE post_id = 18"))
</div> </div>
</form> </form>
</div> </div>
</div>"; </div>
} <?php }
$sql->close(); $sql->close();
} }
else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." ); else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." );
@ -127,54 +122,40 @@ else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." );
if ($sql = $mysqli->prepare("SELECT * FROM comments ORDER BY comment_id")) if ($sql = $mysqli->prepare("SELECT * FROM comments ORDER BY comment_id"))
{ {
$sql->execute(); $sql->execute();
$sql->bind_result($comment_id,$post_id,$username,$tekst,$data_dodania, $data_modyfikacji); $sql->bind_result($comment_id,$post_id,$username,$tekst,$data_dodania, $data_modyfikacji); ?>
echo " <div class=\"name-desc\"> <h1> Komentarze</h1> </div> "; <div class="name-desc"> <h1> Komentarze</h1> </div>
while ($sql->fetch()) <?php while ($sql->fetch())
{ { ?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 name-desc">
echo " <a href="blog.php"><po><?php echo $username; ?></po></a>
<div class=\"col-lg-12 col-md-12 col-sm-12 col-xs-12 name-desc\"> <h6><?php echo $tekst; ?></h6>
<a href=\"blog.php\"><po> $username</po></a> <h5><?php echo $data_modyfikacji; ?></h5>
<h6>$tekst </h6> </div>
<h5>$data_modyfikacji</h5> <?php }
</div>";
}
$sql->close(); $sql->close();
} $mysqli->close();
else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." ); } ?>
<div class="name"> <h2> Dodaj komentarz:</h2> </div>
<div class="container">
echo " <div class=\"name\"> <h2> Dodaj komentarz:</h2> </div> <form class="form" action="comment.php?post=<?php echo $post; ?>" method="post" enctype="multipart/form-data" autocomplete="off">
<div class="row registerMain">
<div class="offset-3 col-6 offset-3 elementsOnRegisterMain">
<div class="form-group inputmain">
<div id=\"particles-js\"> <div class="form-group">
<div class=\"container\"> <textarea class="form-control" rows="4" id="tekst" name="tekst" required></textarea>
<form class=\"form\" action=\"comment.php\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">
<div class=\"row registerMain\">
<div class=\"offset-3 col-6 offset-3 elementsOnRegisterMain\">
<div class=\"form-group inputmain\">
<div class=\"form-group\">
<textarea class=\"form-control\" rows=\"4\" id=\"tekst\" name=\"tekst\" required></textarea>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class=\"row registerFooter\"> <div class="row registerFooter">
<div class=\"offset-3 col-6 offset-3 elementsOnRegisterFooter\"> <div class="offset-3 col-6 offset-3 elementsOnRegisterFooter">
<div> <div>
<input type=\"submit\" value=\"Dodaj\" name=\"register\" class=\"btn btn-block\" /> <input type="submit" value="Dodaj" name="register" class="btn btn-block" />
</div> </div>
</div> </div>
</div> </div>
</form> </form>
</div> </div>
</div>";
$mysqli->close();
?>
</body> </body>
</html> </html>

View File

@ -1,6 +1,7 @@
<?php <?php
include "../settings/db_connect.php"; include "../settings/db_connect.php";
$_SESSION['message'] = ''; $_SESSION['message'] = '';
$post=$_GET['post'];
if ($_SERVER['REQUEST_METHOD'] == "POST"){ if ($_SERVER['REQUEST_METHOD'] == "POST"){
$rating = $mysqli->real_escape_string($_POST['rating']); $rating = $mysqli->real_escape_string($_POST['rating']);
$_SESSION['rating'] = $rating; $_SESSION['rating'] = $rating;
@ -9,7 +10,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST"){
if($mysqli->query($sql) === true){ if($mysqli->query($sql) === true){
$_SESSION['message'] = "Dodanie oceny się powiodło!"; $_SESSION['message'] = "Dodanie oceny się powiodło!";
header("location:post.php"); header("location:post.php?post=$post");
} }
else{ else{
$_SESSION['message'] = "Nie udało się dodać ooceny!"; $_SESSION['message'] = "Nie udało się dodać ooceny!";

View File

@ -1,4 +1,4 @@
Ogółem: Ogółem:
• Zakładanie konta/bloga (wielu użytkowników) check • Zakładanie konta/bloga (wielu użytkowników) check
• Nagłówek bloga (Tytuł, krótki opis) check • Nagłówek bloga (Tytuł, krótki opis) check
• Kategoryzowanie wpisów nope • Kategoryzowanie wpisów nope