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:
Vendored
+32
-14
@@ -1,6 +1,5 @@
|
||||
(async() => {
|
||||
const bootstrap = await import("../twbs/bootstrap/dist/js/bootstrap.min.js");
|
||||
|
||||
});
|
||||
|
||||
if(document.getElementById("testConn"))
|
||||
@@ -21,20 +20,39 @@ function testConnection(){
|
||||
xmlhttp.send();
|
||||
}
|
||||
|
||||
function insertAtCursor(field, text, mark) {
|
||||
let sel = window.getSelection().getRangeAt(0);
|
||||
if(sel != null){
|
||||
let startPos = sel.startOffset;
|
||||
let endPos = sel.endOffset;
|
||||
function createTag(show_name, slug, tags){
|
||||
let xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.open("POST", "/vendor/blog-engine/php/Posts/Tags/AddTags.php", true);
|
||||
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xmlhttp.onreadystatechange = function (){
|
||||
if(this.readyState === 4 && this.status === 200){
|
||||
console.log(this.responseText);
|
||||
let data = JSON.parse(this.responseText);
|
||||
|
||||
if(mark === true){
|
||||
let start_tag = text.substring(0, (text.length % 2 === 0 ? Math.ceil(text.length / 2) : Math.ceil(text.length / 2) - 1));
|
||||
let end_tag = text.substring((text.length % 2 === 0 ? Math.ceil(text.length / 2) : Math.ceil(text.length / 2) - 1), text.length);
|
||||
let div = document.createElement("div");
|
||||
div.classList.add("form-check");
|
||||
|
||||
field.innerHTML = field.innerHTML.substring(0, startPos) + start_tag + field.innerHTML.substring(startPos, endPos) + end_tag + field.innerHTML.substring(endPos, field.innerHTML.length);
|
||||
} else {
|
||||
field.innerHTML = field.innerHTML.substring(0, startPos) + text + field.innerHTML.substring(startPos, endPos) + "<br>" + field.innerHTML.substring(endPos, field.innerHTML.length);
|
||||
let checkbox = document.createElement('input');
|
||||
checkbox.setAttribute("type", "checkbox");
|
||||
checkbox.setAttribute("name", "tags[]");
|
||||
checkbox.setAttribute("value", data.id);
|
||||
checkbox.setAttribute("id", "tag" + data.id);
|
||||
checkbox.classList.add("form-check-input");
|
||||
|
||||
let label = document.createElement("label");
|
||||
label.setAttribute("for", "tag" + data.id);
|
||||
label.classList.add("form-check-label");
|
||||
label.innerText = data.show_name;
|
||||
|
||||
div.appendChild(checkbox);
|
||||
div.appendChild(label);
|
||||
|
||||
tags.appendChild(div);
|
||||
}
|
||||
} else
|
||||
field.innerHTML += text;
|
||||
};
|
||||
xmlhttp.send("show_name=" + show_name + "&slug=" + slug);
|
||||
}
|
||||
|
||||
function saveToDraft(title, content, name, tags, comments_status){
|
||||
|
||||
}
|
||||
+2
File diff suppressed because one or more lines are too long
+31
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<!-- Komentarze -->
|
||||
<?php
|
||||
+8
-5
@@ -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'>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<!-- Ustawienia -->
|
||||
<?php
|
||||
+1
-1
@@ -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
@@ -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
@@ -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
@@ -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();
|
||||
Reference in New Issue
Block a user