Praca nad kontrolerem postów; Zmianki w zakładce 'Posty'; Budowa kreatora postów; Zmianki w kontrolerze autoryzacji; Nowe, puste zakładki.

Took 3 hours 31 minutes
This commit is contained in:
Krzysztof 'KrzysiekSiemv' Smaga
2023-05-16 01:28:08 +02:00
parent 1bb536cd12
commit e7dd0b2fd6
175 changed files with 44439 additions and 46 deletions
+31 -1
View File
@@ -3,12 +3,15 @@ namespace BlogEngine\Authentication {
$file = "vendor/blog-engine/php/Database/DatabaseController.php";
if(file_exists($file))
require $file;
else
else if(file_exists("../$file"))
require "../$file";
else if(file_exists("../../Database/DatabaseController.php"))
require "../../Database/DatabaseController.php";
use BlogEngine\Database\DatabaseController;
class AuthController extends DatabaseController{
public function Authenticate($login, $password, $remember) : bool|string {
$status = false;
$srv = $this->Connection();
@@ -49,10 +52,37 @@ namespace BlogEngine\Authentication {
$this->Close($srv);
}
public function GetID($login_token) : int|string {
$srv = $this->Connection();
$check_id = "SELECT id_user FROM users WHERE login_token = '$login_token';";
$res = mysqli_query($srv, $check_id);
if(mysqli_num_rows($res) > 0){
if($row = mysqli_fetch_row($res)){
return intval($row[0]);
} else
return mysqli_error($res);
} else
return "Nie ma użytkownika o takim tokenie";
$this->Close($srv);
}
public function NewUser($login, $password, $email, $role = 'user', $display_name = 'Użytkownik', $fname = '', $lname = '') : bool|string{
$status = false;
$srv = $this->Connection();
}
public function Valid($tekst) : string {
$srv = $this->Connection();
$tekst = htmlspecialchars($tekst);
return mysqli_real_escape_string($srv, $tekst);
$this->Close($srv);
}
public function ToHTML($tekst) : string {
return htmlspecialchars_decode($tekst);
}
}
}
+2
View File
@@ -0,0 +1,2 @@
<!-- Komentarze -->
<?php
+8 -5
View File
@@ -3,7 +3,7 @@
$posts = array();
// Pobierz posty
$get_posts_query = "SELECT * FROM posts";
$get_posts_query = "SELECT id_post, name, title, content, views, added_at, updated_at, CASE WHEN status = 'public' THEN '<b>Publiczny</b>' WHEN status = 'archive' THEN '<i>Schowany</i>' ELSE '<i>Wersja robocza</i>' END AS widocznosc FROM posts";
$get_posts_res = mysqli_query($conn, $get_posts_query);
while($row = mysqli_fetch_assoc($get_posts_res)){
@@ -11,14 +11,15 @@
"ID" => $row['id_post'],
"Nazwa" => $row['name'],
"Tytuł" => $row['title'],
"Treść" => $row['content'],
"Treść" => $row['content'], 0, 120,
"Wyswietlenia" => $row['views'],
"Dodano" => $row['added_at']
"Dodano" => $row['added_at'],
"Widoczność" => $row['widocznosc']
]);
}
?>
<button type="button" name="add_post" class="btn btn-success" onclick="location.href='blog_panel/be_post.php';">Dodaj nowy post</button>
<button type="button" name="add_post" class="btn btn-success mb-3" onclick="location.href='blog_panel/be_post.php';">Dodaj nowy post</button>
<table class="table table-stripped">
<thead>
<tr>
@@ -26,6 +27,7 @@
<th>Tytuł</th>
<th>Zawartość</th>
<th>Wyświetlenia</th>
<th>Widoczność</th>
<th>Dodano</th>
<th>Akcja</th>
</tr>
@@ -34,7 +36,7 @@
<?php
foreach ($posts as $post){
if(strlen($post['Treść']) > 256){
$post['Treść'] = substr($post['Treść'], 0, 253) . "...";
$post['Treść'] = $auth->ToHTML(substr($post['Treść'], 0, 253) . "...");
}
echo "
<tr>
@@ -42,6 +44,7 @@
<td>{$post['Tytuł']}</td>
<td>{$post['Treść']}</td>
<td>{$post['Wyswietlenia']}</td>
<td>{$post['Widoczność']}</td>
<td>{$post['Dodano']}</td>
<td>
<div class='d-flex'>
+2
View File
@@ -0,0 +1,2 @@
<!-- Ustawienia -->
<?php
+1 -1
View File
@@ -121,7 +121,7 @@
{
"column_name": "status",
"datatype": "ENUM",
"enum_data": ["public", "draft"],
"enum_data": ["public", "draft", "archive"],
"not_null": true,
"default": {
"value": "draft",
+13
View File
@@ -0,0 +1,13 @@
<?php
require "../../../../_config.php";
require "../Authentication/AuthController.php";
use BlogEngine\Authentication\AuthController;
$auth = new AuthController();
$conn = $auth->Connection();
if(isset($_POST['title']) && isset($_POST['content']) && isset($_POST['name'])){
}
$conn->close();
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace BlogEngine\Posts {
use BlogEngine\Authentication\AuthController;
class PostController {
public AuthController $auth;
public function __construct($auth)
{
$this->auth = $auth;
}
public function CreatePost($title, $content, $name, $tags, $commentStatus, $add_time, $status){
$srv = $this->auth->Connection();
$date = (is_bool($add_time)?"NOW()":Date("'y-m-d H:i:s'", strtotime($add_time)));
$status = ($status == "public"?"public":"draft");
$id_user = $this->auth->GetID($_SESSION['uToken_BE']);
$last_id_post = mysqli_fetch_row(mysqli_query($srv, "SELECT MAX(id_post) FROM posts;"))[0] + 1;
$insert_post = "INSERT INTO posts VALUES($last_id_post, $id_user, '$name', '$title', '$content', '$status', '$commentStatus', 0, $date, null);";
mysqli_query($srv, $insert_post);
foreach ($tags as $tag){
mysqli_query($srv, "INSERT INTO tag_to_post VALUES($tag, $last_id_post)");
}
header("location: ../../../be_panel.php?s=posts");
}
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
require "../../../../../_config.php";
require "../../Authentication/AuthController.php";
use BlogEngine\Authentication\AuthController;
$auth = new AuthController();
$conn = $auth->Connection();
if(isset($_POST['show_name']) && isset($_POST['slug'])){
$check_if_exists = mysqli_query($conn, "SELECT id_tag FROM tags WHERE show_name = '{$_POST['show_name']}' AND slug = '{$_POST['slug']}'");
if(mysqli_num_rows($check_if_exists) == 0){
// Add a tag
mysqli_query($conn, "INSERT INTO tags VALUES(NULL, '{$_POST['show_name']}', '{$_POST['slug']}')");
// Podaj ID Taga
$get_tag = mysqli_query($conn, "SELECT * FROM tags WHERE show_name = '{$_POST['show_name']}' AND slug = '{$_POST['slug']}'");
if($row = mysqli_fetch_row($get_tag)){
$value = [
"id" => $row[0],
"show_name" => $row[1],
"slug" => $row[2]
];
echo json_encode($value);
}
} else {
echo mysqli_fetch_row($check_if_exists)[0];
}
}
$conn->close();