diff --git a/_config.php b/_config.php index 30601c7..f1bf981 100644 --- a/_config.php +++ b/_config.php @@ -10,22 +10,19 @@ const BLOG_TITLE = "Kwiatowy Blog"; // Opis bloga - const BLOG_DESC = "sdf"; + const BLOG_DESC = "ef"; // Autor bloga/Nazwa wyświetlana dla głównego administratora bloga const BLOG_AUTHOR = "Krzysiek Smaga"; // Tagi bloga - const BLOG_TAGS = "nowy, pierwszy, super"; + const BLOG_TAGS = "kwiaty, rośliny"; // Domena bloga const BLOG_DOMAIN = "http://localhost"; // Ikona bloga (format .PNG) - const BLOG_ICON = "{BLOG_ICON}"; - - // Nazwa pliku strony głównej - const BLOG_INDEX = "{BLOG_INDEX}"; + const BLOG_ICON = ""; /* * KONFIGURACJA BAZY DANYCH @@ -43,6 +40,16 @@ // Baza danych dla bloga const DB_NAME = "blog"; + /* + * KONFIGURACJA NARZĘDZIA SERWEROWEGO + */ + + // Port, który ma używać PHP dla serwera publicznego + const PUB_PORT = "8085"; + + // Port, który ma używać PHP dla serwera deweloperskiego + const DEV_PORT = "8086"; + /* * KONFIGURACJA KONTA ADMINISTRATORA */ @@ -51,7 +58,7 @@ const ADMIN_USER = "admin"; // Adres mailowy kontaktowy do głównego administratora bloga - const ADMIN_EMAIL = "admin@blog.pl"; + const ADMIN_EMAIL = "krzysiek-smaga@outlook.com"; // Hasło dla głównego administratora bloga const ADMIN_PASS = "root"; diff --git a/be_firstrun.php b/be_firstrun.php index 1152678..d666fff 100644 --- a/be_firstrun.php +++ b/be_firstrun.php @@ -12,7 +12,7 @@

Jestem Twoim przyszłym blogiem! :D

Ale zanim do tego dojdzie, skonfiguruj mnie. Przeprowadzę Cię przez proces konfiguracji mnie, dzięki któremu będę żył! Nie potrzeba poświęcać mi dużo czasu. Wystarczy dosłownie maks 5 minut.


-
+
@@ -27,6 +27,8 @@ + +

@@ -49,6 +51,21 @@

+
+
+

Konfiguracja narzędziowego

+

Jeżeli chcesz korzystać z korzyści, jakie dają wbudowane narzędzia tego silnika, możesz ustawić pod siebie to, co chcesz.

+
+
+ + +
+
+ + +
+
+

Administrator bloga

diff --git a/be_login.php b/be_login.php index 6fa5f85..25ff9e9 100644 --- a/be_login.php +++ b/be_login.php @@ -16,8 +16,7 @@ header("location: be_panel.php"); else header("location: index.php"); - } else - header("location: index.php"); + } ?> diff --git a/be_panel.php b/be_panel.php index 82d6d4a..2d9edda 100644 --- a/be_panel.php +++ b/be_panel.php @@ -1,5 +1,33 @@ Connection(); + + if(!isset($_COOKIE['uToken_BE'])) + header("location: be_login.php"); + + $site = ($_POST['site'] ?? "home"); + + $elements = array(); + $dashboard_tabs_dir = "vendor/blog-engine/php/Dashboard/Tabs"; + $dashboard_tabs = scandir($dashboard_tabs_dir); + + foreach ($dashboard_tabs as $dashboard_tab){ + if(str_contains($dashboard_tab, ".php")) { + $file = "$dashboard_tabs_dir/$dashboard_tab"; + $name = fgets(fopen($file, 'r')); + $name = substr($name, strlen(""))); + $filename = basename($file, ".php"); + + array_push($elements, [ + "Nazwa" => $name, + "Plik" => $filename + ]); + } + } ?> @@ -10,6 +38,19 @@ - +
+

Zarządzanie

+ + + + +
diff --git a/blog_panel/be_post.php b/blog_panel/be_post.php new file mode 100644 index 0000000..4876494 --- /dev/null +++ b/blog_panel/be_post.php @@ -0,0 +1,66 @@ +Connection(); + + $post = null; + if(isset($_POST['edit'])){ + $get_post = "SELECT name, title, content, status, comments, added_at, updated_at FROM posts WHERE id_post = {$_POST['edit']}"; + $res_post = mysqli_fetch_row(mysqli_query($conn, $get_post)); + + $post = [ + "Nazwa" => $res_post[0], + "Tytuł" => $res_post[1], + "Treść" => $res_post[2], + "Status" => $res_post[3], + "Komentarze" => $res_post[4], + "Dodano" => $res_post[5], + "Zaktualizowano" => $res_post[6] + ]; + } +?> + + + + + Panel <?php echo BLOG_TITLE ?> + + + + +
+

Dodawanie posta

+
+
+
+
+ > + +
+
+
+ +
+
+
+ + + +
+
+
+
+ +
+
+
+ +
+
+
+
+ + diff --git a/compile.php b/compile.php index 9436bff..5e6640b 100644 --- a/compile.php +++ b/compile.php @@ -1,9 +1,12 @@ dictionary = new BlogEngine\Dictionary(); + public function __construct(public $src = __DIR__ . "/src/", public $htmls = [], public $csss = [], public $jss = [], public float $version = 0){ + if(file_exists("_config.php")) + $this->dictionary = new BlogEngine\Dictionary(); // POBIERANIE ZAWARTOŚCI FOLDERU src $this->src = __DIR__ . "/src/"; @@ -11,28 +14,77 @@ $this->csss = scandir($src . "css"); $this->jss = scandir($src . "js"); - //$this->version = + $this->version = floatval(file_get_contents("version")); } - public function main() : void{ - $this->checkFolders(); - $this->compileFiles(); - - echo "Done"; + public function main($argv, $argc) : void{ + if($argc > 1){ + switch($argv[1]){ + case "compile": + if($argv[2] != null) + switch($argv[2]) { + case "dev": + echo " +========================== += KOMPILOWANIE DO 'dev' +========================== +"; + $this->versionUp("dev"); + $this->addCustoms("dev"); + $this->checkFolders("dev"); + $this->compileFiles("dev"); + break; + default: + echo " +========================== += KOMPILOWANIE DO 'pub' +========================== +"; + $this->versionUp("pub"); + $this->addCustoms("pub"); + $this->checkFolders("public"); + $this->compileFiles("public"); + break; + } + else { + echo " +========================== += KOMPILOWANIE DO 'pub' +========================== +"; + $this->versionUp("pub"); + $this->addCustoms("pub"); + $this->checkFolders("public"); + $this->compileFiles("public"); + } + break; + case "start-server": + if($argv[2] != null) + $this->runServer($argv[2]); + else + $this->runServer("pub"); + break; + case "help": + $this->help(); + break; + } + } else { + echo "Brak parametru rozruchowego. Wpisz help, aby zobaczyć listę dostępnych komend. \n"; + } } /* * SPRAWDZANIE CZY SĄ FOLDERY css I js */ - function checkFolders() : void{ - if(!file_exists("public/css")) - mkdir("public/css"); + function checkFolders($folder) : void{ + if(!file_exists("$folder/css")) + mkdir("$folder/css"); - if(!file_exists("public/js")) - mkdir("public/js"); + if(!file_exists("$folder/js")) + mkdir("$folder/js"); } - function compileFiles() : void{ + function compileFiles($folder) : void{ // KOPIOWANIE PLIKÓW HTML DO PUBLICZNEGO FOLDERU foreach ($this->htmls as $html) { $file = $this->src . "views/" . $html; @@ -40,25 +92,26 @@ $name = basename($file); $site = file_get_contents($file); foreach (array_keys($this->dictionary->page_tags) as $page_tag) { - echo $page_tag; if ($page_tag == "{CSS}") { - $this->dictionary->page_tags[$page_tag] .= ""; for ($j = 2; $j < count($this->csss); $j++) - $this->dictionary->page_tags[$page_tag] .= "\n "; + $this->dictionary->page_tags[$page_tag] .= "\n "; } if ($page_tag == "{JS}") { - $this->dictionary->page_tags[$page_tag] .= ""; for ($j = 2; $j < count($this->jss); $j++) - $this->dictionary->page_tags[$page_tag] .= "\n "; + $this->dictionary->page_tags[$page_tag] .= "\n "; } $site = str_replace($page_tag, $this->dictionary->page_tags[$page_tag], $site); } - $site_file = fopen("public/" . $name, "w"); + $site = str_replace("", "\n", $site); + + $site_file = fopen("$folder/" . $name, "w"); fwrite($site_file, $site); fclose($site_file); + + echo "* Plik '$html' przetworzono do folderu '$folder'!\n"; } } @@ -69,9 +122,11 @@ $name = basename($file);; $style = file_get_contents($file); - $style_file = fopen("public/css/" . $name, "w"); + $style_file = fopen("$folder/css/" . $name, "w"); fwrite($style_file, $style); fclose($style_file); + + echo "* Plik '$css' przetworzono do folderu '$folder'!\n"; } } @@ -82,13 +137,91 @@ $name = basename($file); $script = file_get_contents($file); - $script_file = fopen("public/js/" . $name, "w"); + $script_file = fopen("$folder/js/" . $name, "w"); fwrite($script_file, $script); fclose($script_file); + + echo "* Plik '$js' przetworzono do folderu '$folder'!\n"; } } } + + public function versionUp($type) : void{ + switch($type){ + case "pub": + $this->version++; + break; + case "dev": + $this->version += 0.1; + break; + } + + $verfile = fopen("version", "w+"); + fwrite($verfile, $this->version); + fclose($verfile); + } + + public function addCustoms($type) : void { + $json = json_decode(file_get_contents("custom.json"), true); + switch($type){ + case "dev": + foreach ($json["dev"]["css"] as $css){ + $this->dictionary->page_tags["{CSS}"] .= "\n "; + echo "* Dodano '$css' do styli w '$type'!\n"; + } + foreach ($json["dev"]["js"] as $js){ + $this->dictionary->page_tags["{JS}"] .= "\n "; + echo "* Dodano '$js' do skryptów w '$type'!\n"; + } + break; + case "pub": + foreach ($json["pub"]["css"] as $css){ + $this->dictionary->page_tags["{CSS}"] .= "\n "; + echo "* Dodano '$css' do styli w '$type'!\n"; + } + foreach ($json["pub"]["js"] as $js){ + $this->dictionary->page_tags["{JS}"] .= "\n "; + echo "* Dodano '$js' do skryptów w '$type'!\n"; + } + break; + } + } + + public function runServer($type) : void{ + if(file_exists("_config.php")){ + + $port = match ($type) { + "dev" => DEV_PORT, + default => PUB_PORT, + }; + } else + $port = 14071; + + echo " +========================================= +Uruchamianie serwera na adresie: +* http://127.0.0.1:$port * +Aby zatrzymać serwer, naciśnij Ctrl+C +========================================= + +"; + exec("php -S 127.0.0.1:$port -t " . __DIR__); + } + + public function help() : void { + echo " +=============================== += BLOG ENGINE v0.1 += Krzysztof KrzysiekSiemv Smaga 2023 +=============================== +Dostępne komendy dla narzędzia: + +* start-server [pub/dev] - uruchom serwer dla projektu. Opcja 'dev' specjalna dla programisty, opcja 'pub' dla każdego użytkownika. Domyślnie 'pub' +* help - wyświetl listę komend +* compile [pub/dev] - skompiluj projekt strony z folderu 'src'. Opcja 'dev' specjalna dla programisty, opcja 'pub' dla każdego użytkownika. Domyślnie 'pub' +"; + } } $exec = new CompileIt(); - $exec->main(); \ No newline at end of file + $exec->main($argv, $argc); \ No newline at end of file diff --git a/custom.json b/custom.json new file mode 100644 index 0000000..199ecf9 --- /dev/null +++ b/custom.json @@ -0,0 +1,21 @@ +{ + "_comment": "Tutaj możesz dodawać linki do swoich styli zewnętrznych, bądź skryptów, które chcesz użyć na swoim blogu.", + "dev": { + "css": [ + "vendor/blog-engine/blog.css", + "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" + ], + "js": [ + "vendor/blog-engine/blog.js", + "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" + ] + }, + "pub": { + "css": [ + "vendor/blog-engine/blog.css" + ], + "js": [ + "vendor/blog-engine/blog.js" + ] + } +} \ No newline at end of file diff --git a/dev/css/style.css b/dev/css/style.css new file mode 100644 index 0000000..e69de29 diff --git a/dev/index.html b/dev/index.html new file mode 100644 index 0000000..b2dcd87 --- /dev/null +++ b/dev/index.html @@ -0,0 +1,25 @@ + + + + + Witaj świecie! - Kwiatowy Blog + + + + + + + + + + + +

Kwiatowy Blog

+

ef

+ Zaloguj się do panelu + + + + + + \ No newline at end of file diff --git a/dev/js/script.js b/dev/js/script.js new file mode 100644 index 0000000..e69de29 diff --git a/index.php b/index.php index 55cb8f3..1676de5 100644 --- a/index.php +++ b/index.php @@ -25,10 +25,22 @@ else $ssl = 0; + if(isset($_FILES['BLOG_ICON'])){ + if(strtolower(pathinfo(basename($_FILES['BLOG_ICON']['name']),PATHINFO_EXTENSION)) == "png") { + if (move_uploaded_file($_FILES['BLOG_ICON']['tmp_name'], "resources/favicon.png")) { + $file = "resources/favicon.png"; + } + $file = ""; + } + $file = ""; + } else + $file = ""; + // Wczytywanie danych do tablicy $data = [ - "BLOG_TITLE" => $_POST['BLOG_TITLE'], "BLOG_DESC" => $_POST['BLOG_DESC'], "BLOG_AUTHOR" => $_POST['BLOG_AUTHOR'], "BLOG_TAGS" => $_POST['BLOG_TAGS'], "BLOG_DOMAIN" => $_POST['BLOG_DOMAIN'], + "BLOG_TITLE" => $_POST['BLOG_TITLE'], "BLOG_DESC" => $_POST['BLOG_DESC'], "BLOG_AUTHOR" => $_POST['BLOG_AUTHOR'], "BLOG_TAGS" => $_POST['BLOG_TAGS'], "BLOG_DOMAIN" => $_POST['BLOG_DOMAIN'], "BLOG_ICON" => $file, "DB_HOST" => $_POST['DB_HOST'], "DB_USER" => $_POST['DB_USER'], "DB_PASS" => $_POST['DB_PASS'], "DB_NAME" => $_POST['DB_NAME'], + "PUB_PORT" => $_POST['PUB_PORT'], "DEV_PORT" => $_POST['DEV_PORT'], "ADMIN_USER" => $_POST['ADMIN_USER'], "ADMIN_EMAIL" => $_POST['ADMIN_EMAIL'], "ADMIN_PASS" => $_POST['ADMIN_PASS'], "MAIL_NAME" => $_POST['MAIL_NAME'], "MAIL_PASS" => $_POST['MAIL_PASS'], "MAIL_SRV" => $_POST['MAIL_SRV'], "MAIL_PORT" => $_POST['MAIL_PORT'], "MAIL_SSL" => $ssl ]; @@ -58,10 +70,20 @@ } if(file_exists("_config.php")){ - if(isset($_SESSION['uToken_BE'])){ - if($auth->CheckRole($_SESSION['uToken_BE']) == "administrator") - include "vendor/blog-engine/php/Sites/Views/be-topbar.php"; - } - require "public/index.html"; + $topbar = ""; + if($_SERVER['SERVER_PORT'] == DEV_PORT) { + if(isset($_SESSION['uToken_BE'])){ + if($auth->CheckRole($_SESSION['uToken_BE']) == "administrator") + $topbar = "vendor/blog-engine/php/Sites/Views/be-topbar.php"; + } + require "dev/index.html"; + } else if($_SERVER['SERVER_PORT'] == PUB_PORT) { + if(isset($_SESSION['uToken_BE'])){ + if($auth->CheckRole($_SESSION['uToken_BE']) == "administrator") + $topbar = "vendor/blog-engine/php/Sites/Views/be-topbar.php"; + } + require "public/index.html"; + } else + echo "

Uruchom ponownie serwer

"; } else require "be_firstrun.php"; \ No newline at end of file diff --git a/public/index.html b/public/index.html index b1baeda..3e7ea48 100644 --- a/public/index.html +++ b/public/index.html @@ -3,16 +3,19 @@ Witaj świecie! - Kwiatowy Blog + - + + - +

Kwiatowy Blog

-

sdf

+

ef

+ - + \ No newline at end of file diff --git a/resources/favicon.png b/resources/favicon.png new file mode 100644 index 0000000..a01e3e7 Binary files /dev/null and b/resources/favicon.png differ diff --git a/src/views/index.html b/src/views/index.html index 35cc510..895dfb1 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -4,6 +4,7 @@ Witaj świecie! - {TITLE} {CSS} + {FAVICON} @@ -11,6 +12,7 @@

{TITLE}

{DESCRIPTION}

+ Zaloguj się do panelu {JS} \ No newline at end of file diff --git a/vendor/blog-engine/blog.js b/vendor/blog-engine/blog.js index dca6904..da2234c 100644 --- a/vendor/blog-engine/blog.js +++ b/vendor/blog-engine/blog.js @@ -1,4 +1,7 @@ -import * as bootstrap from "../twbs/bootstrap/dist/js/bootstrap.min.js"; +(async() => { + const bootstrap = await import("../twbs/bootstrap/dist/js/bootstrap.min.js"); + +}); if(document.getElementById("testConn")) document.getElementById("testConn").addEventListener("click", () => testConnection()); @@ -17,3 +20,21 @@ function testConnection(){ xmlhttp.open("GET", "_checkdbconn.php?s=" + server + "&u=" + user + "&p=" + pass + "&d=" + name, true); xmlhttp.send(); } + +function insertAtCursor(field, text, mark) { + let sel = window.getSelection().getRangeAt(0); + if(sel != null){ + let startPos = sel.startOffset; + let endPos = sel.endOffset; + + 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); + + 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) + "
" + field.innerHTML.substring(endPos, field.innerHTML.length); + } + } else + field.innerHTML += text; +} \ No newline at end of file diff --git a/vendor/blog-engine/php/Authentication/AuthController.php b/vendor/blog-engine/php/Authentication/AuthController.php index 62082af..aab6016 100644 --- a/vendor/blog-engine/php/Authentication/AuthController.php +++ b/vendor/blog-engine/php/Authentication/AuthController.php @@ -1,6 +1,11 @@ + +
+
+
+

Ostatnie komentarze

+
+
+
+
+

Statystyki z 24 godzin

+
+
+
diff --git a/vendor/blog-engine/php/Dashboard/Tabs/posts.php b/vendor/blog-engine/php/Dashboard/Tabs/posts.php new file mode 100644 index 0000000..2c66d59 --- /dev/null +++ b/vendor/blog-engine/php/Dashboard/Tabs/posts.php @@ -0,0 +1,64 @@ + + $row['id_post'], + "Nazwa" => $row['name'], + "Tytuł" => $row['title'], + "Treść" => $row['content'], + "Wyswietlenia" => $row['views'], + "Dodano" => $row['added_at'] + ]); + } +?> + + + + + + + + + + + + + + + 256){ + $post['Treść'] = substr($post['Treść'], 0, 253) . "..."; + } + echo " + + + + + + + + + "; + } + ?> + +
IDTytułZawartośćWyświetleniaDodanoAkcja
{$post['Nazwa']}{$post['Tytuł']}{$post['Treść']}{$post['Wyswietlenia']}{$post['Dodano']} +
+
+ +
+
+
+ + +
+
+
+
diff --git a/vendor/blog-engine/php/Dictionary.php b/vendor/blog-engine/php/Dictionary.php index b063181..7371aa5 100644 --- a/vendor/blog-engine/php/Dictionary.php +++ b/vendor/blog-engine/php/Dictionary.php @@ -5,6 +5,7 @@ namespace BlogEngine { public $page_tags = [ "{POSTS}" => "", "{LINKS}" => "", + "{FAVICON}" => (BLOG_ICON != ""?"":""), "{KEYWORDS}" => BLOG_TAGS, "{TITLE}" => BLOG_TITLE, "{AUTHOR}" => BLOG_AUTHOR, diff --git a/vendor/blog-engine/php/Sites/Views/be-topbar.php b/vendor/blog-engine/php/Sites/Views/be-topbar.php index c167090..f3f64fc 100644 --- a/vendor/blog-engine/php/Sites/Views/be-topbar.php +++ b/vendor/blog-engine/php/Sites/Views/be-topbar.php @@ -15,7 +15,7 @@