diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f10d9..d7d22a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,19 @@ The project is ready for use but is still evolving. Work is ongoing to fix bugs ### Added + +`/public` +1 - cookies for users, db collects data for analytics +2 - tables for cookies added +3 - JS folder +4 - popout for cookies ..... ### Changed + +`/public` +1 - structure of /public fixes ..... ### Fixed diff --git a/HOW_TO_RUN.md b/HOW_TO_RUN.md index d7890b3..6575289 100644 --- a/HOW_TO_RUN.md +++ b/HOW_TO_RUN.md @@ -8,9 +8,9 @@ CorelyPHP is a ready-to-deploy blogging platform designed for efficient web deve Before you begin, ensure you have the following installed: -- PHP (>= 8.0) -- MySQL (or another compatible database) -- XAMPP +- PHP (>= 8.0) +- MySQL (or another compatible database) +- XAMPP / MAMP - Git ## Installation diff --git a/admin/panel.connect.php b/admin/panel.connect.php index 8171e0b..c2727bb 100644 --- a/admin/panel.connect.php +++ b/admin/panel.connect.php @@ -2,7 +2,7 @@ $host = "localhost"; $db_user = "root"; - $db_password =""; + $db_password ="root"; $db_name = "blog"; diff --git a/database_SQL/blog_DB_data.sql b/database_SQL/blog_DB_data.sql index 55147d4..6d51d41 100644 --- a/database_SQL/blog_DB_data.sql +++ b/database_SQL/blog_DB_data.sql @@ -1,22 +1,11 @@ -SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; -SET time_zone = "+00:00"; - -USE `blog`; - --- --- Inserting data into table `admin` --- INSERT INTO `admin` (`id`, `login`, `password`) VALUES -(1, 'admin', '$2y$10$L9fQlnPTTuYkNhLnXh68..F8R.bJdLaAJBJjXU8RjhiHUHFVVJyCe'); +(1, 'admin', '$2y$10$w9GkWVGXxSTjw4A9QyjasuqyeJyUPp2JlWYnFGFEen7e2..YUXxNC'); --- --- Inserting data into table `service` --- +-- -------------------------------------------------------- INSERT INTO `service` (`id`, `service_status`) VALUES -(1, 1); - +(1, 0); COMMIT; diff --git a/database_SQL/blog_DB_structure.sql b/database_SQL/blog_DB_structure.sql index 20d0c42..77c857b 100644 --- a/database_SQL/blog_DB_structure.sql +++ b/database_SQL/blog_DB_structure.sql @@ -1,79 +1,64 @@ +-- Databse 'blog': structure SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; SET time_zone = "+00:00"; -CREATE DATABASE IF NOT EXISTS `blog`; -USE `blog`; - -/*!40101 SET NAMES utf8mb4 */; - --- --- Table structure for table `admin` --- +-- -------------------------------------------------------- CREATE TABLE `admin` ( - `id` int(11) NOT NULL, - `login` varchar(25) NOT NULL, - `password` varchar(25) NOT NULL + `id` int NOT NULL AUTO_INCREMENT, + `login` varchar(25) COLLATE utf8mb4_general_ci NOT NULL, + `password` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; --- --- Table structure for table `articles` --- +-- -------------------------------------------------------- CREATE TABLE `articles` ( - `ID` int(11) NOT NULL, - `title` varchar(255) NOT NULL, - `text` text NOT NULL, - `photo_path` varchar(255) NOT NULL, - `date_of_publish` timestamp NOT NULL DEFAULT current_timestamp() + `ID` int NOT NULL AUTO_INCREMENT, + `title` varchar(255) COLLATE utf8mb4_general_ci NOT NULL, + `text` text COLLATE utf8mb4_general_ci NOT NULL, + `photo_path` varchar(255) COLLATE utf8mb4_general_ci NOT NULL, + `date_of_publish` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; --- --- Table structure for table `service` --- +-- -------------------------------------------------------- + +CREATE TABLE `page_views_daily` ( + `id` int NOT NULL AUTO_INCREMENT, + `page` varchar(191) NOT NULL, + `visit_date` date NOT NULL DEFAULT (curdate()), + `visit_count` int NOT NULL DEFAULT '1', + PRIMARY KEY (`id`), + UNIQUE KEY `unique_page_date` (`page`,`visit_date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +-- -------------------------------------------------------- CREATE TABLE `service` ( - `id` int(11) NOT NULL, - `service_status` tinyint(1) NOT NULL + `id` int NOT NULL AUTO_INCREMENT, + `service_status` tinyint(1) NOT NULL, + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; --- --- Table structure for table `settings` --- +-- -------------------------------------------------------- CREATE TABLE `settings` ( - `id` int(11) NOT NULL, - `is_active` tinyint(1) NOT NULL + `id` int NOT NULL AUTO_INCREMENT, + `is_active` tinyint(1) NOT NULL, + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; --- --- Indexes for tables --- - -ALTER TABLE `admin` - ADD PRIMARY KEY (`id`); - -ALTER TABLE `articles` - ADD PRIMARY KEY (`ID`); - -ALTER TABLE `service` - ADD PRIMARY KEY (`id`); - -ALTER TABLE `settings` - ADD PRIMARY KEY (`id`); - --- --- AUTO_INCREMENT for tables --- - -ALTER TABLE `admin` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; - -ALTER TABLE `articles` - MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT; +-- -------------------------------------------------------- -ALTER TABLE `settings` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1; +CREATE TABLE `visitors` ( + `id` int NOT NULL AUTO_INCREMENT, + `cookie_id` varchar(64) DEFAULT NULL, + `visit_count` int DEFAULT '1', + `first_visit` datetime DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `cookie_id` (`cookie_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; COMMIT; diff --git a/public/main.css b/public/CSS/main.css similarity index 100% rename from public/main.css rename to public/CSS/main.css diff --git a/public/CSS/popout.css b/public/CSS/popout.css new file mode 100644 index 0000000..1b8da71 --- /dev/null +++ b/public/CSS/popout.css @@ -0,0 +1,41 @@ +.cookie-popup { + position: fixed; + bottom: 20px; + left: 50%; + transform: translateX(-50%); + background-color: #333; + color: #fff; + padding: 15px 20px; + border-radius: 8px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + display: none; +} + +.cookie-popup a { + color: #fff; + text-decoration: underline; +} + +.cookie-popup button { + background-color: #fff; + color: #333; + border: none; + padding: 8px 12px; + margin-left: 10px; + cursor: pointer; + border-radius: 5px; + font-weight: bold; +} + +.cookie-popup button:hover { + background-color: #ddd; +} + +.cookie-popup button#reject-cookies { + background-color: #ff4d4d; /* Czerwony dla opcji odrzucenia */ + color: white; +} + +.cookie-popup button#reject-cookies:hover { + background-color: #cc0000 +} \ No newline at end of file diff --git a/public/single.css b/public/CSS/single.css similarity index 100% rename from public/single.css rename to public/CSS/single.css diff --git a/public/JS/popout.js b/public/JS/popout.js new file mode 100644 index 0000000..4e03a48 --- /dev/null +++ b/public/JS/popout.js @@ -0,0 +1,39 @@ + +document.addEventListener("DOMContentLoaded", function () { + const popup = document.getElementById("cookie-popup"); + const acceptButton = document.getElementById("accept-cookies"); + const rejectButton = document.getElementById("reject-cookies"); + + const cookiesAccepted = document.cookie.includes("cookiesAccepted=true"); + const cookiesRejected = document.cookie.includes("cookiesAccepted=false"); + + if (!cookiesAccepted && !cookiesRejected) { + popup.style.display = "block"; + } + + function setCookie(name, value, days) { + let expires = ""; + if (days) { + const date = new Date(); + date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); + expires = "; expires=" + date.toUTCString(); + } + document.cookie = name + "=" + value + expires + "; path=/public/"; //path may need to be changed for client + } + + // Obsługa zgody na ciasteczka + acceptButton.addEventListener("click", function () { + setCookie("cookiesAccepted", "true", 365); + popup.style.display = "none"; + location.reload(); + }); + + // Obsługa odrzucenia ciasteczek + rejectButton.addEventListener("click", function () { + setCookie("cookiesAccepted", "false", 365); + popup.style.display = "none"; + location.reload(); + }); +}); + + diff --git a/public/error.html b/public/error.html index 81ed519..06c2f4c 100644 --- a/public/error.html +++ b/public/error.html @@ -6,7 +6,7 @@ Error page - + - + + + + @@ -34,7 +37,7 @@

Error page

Something went wrong.

Try to search what you have been looking for on main page:

- Link: Blog main page +

Link: Blog main page

diff --git a/public/error_404.php b/public/error_404.php index d0c8e59..3c4cee2 100644 --- a/public/error_404.php +++ b/public/error_404.php @@ -3,12 +3,16 @@ session_start(); -include_once 'functions.php'; -require_once 'service.alg.php'; -include 'connect.php'; +include_once './handlers/functions.php'; +require_once './handlers/service.alg.php'; +require_once './handlers/cookies.php'; service(); +$page = 'error_404.php'; +cookie($page); + + ?> @@ -16,8 +20,10 @@ 404 error - - + + + + @@ -53,5 +59,9 @@ ?> + + diff --git a/public/connect.php b/public/handlers/connect.php similarity index 76% rename from public/connect.php rename to public/handlers/connect.php index aaa1736..655b0af 100644 --- a/public/connect.php +++ b/public/handlers/connect.php @@ -3,7 +3,7 @@ $host = "localhost"; $db_user = "root"; - $db_password =""; + $db_password ="root"; $db_name = "blog"; \ No newline at end of file diff --git a/public/handlers/cookies.php b/public/handlers/cookies.php new file mode 100644 index 0000000..0a0f284 --- /dev/null +++ b/public/handlers/cookies.php @@ -0,0 +1,21 @@ + Blog '; + echo '

Blog

'; } // main @@ -11,14 +11,12 @@ function all_articles(): void{ require 'connect.php'; - $conn = @new mysqli($host, $db_user, $db_password, $db_name); - error_reporting(E_ALL); - ini_set('display_errors', 1); + //error_reporting(E_ALL); + //ini_set('display_errors', 1); if ($conn->connect_errno) { - //echo "Error: " . $conn->connect_error; - echo 'error'; + echo 'Error'; return; } else { @@ -56,7 +54,7 @@ function all_articles(): void{ } } else { - echo "0 results"; + echo "No results found."; } $conn->close(); @@ -65,13 +63,26 @@ function all_articles(): void{ //footer -function foot(): string{ +function foot(): void{ + + $date = date("Y"); - return ' + echo "
- © 2024 - Dominik-developer + © 2024 - {$date} Dominik-developer

Contact: www.blog@example.com -
'; + "; } + +function cookie_popout(): void { + + echo ' + diff --git a/public/service.html b/public/service.html index 502fbd8..eb593e5 100644 --- a/public/service.html +++ b/public/service.html @@ -11,7 +11,7 @@ - + - + + + + diff --git a/public/single.php b/public/single.php index 267eed8..e19bb97 100644 --- a/public/single.php +++ b/public/single.php @@ -3,10 +3,10 @@ session_start(); -include_once 'functions.php'; -require_once 'service.alg.php'; -include_once 'single.alg.php'; -include 'connect.php'; +include './handlers/functions.php'; +require_once './handlers/service.alg.php'; +require_once './handlers/cookies.php'; +include_once './handlers/single.alg.php'; service(); @@ -16,6 +16,10 @@ exit(); } +//$page = 'single.php?title='.$_GET['title']; +$page = 'single.php'; +cookie($page); + $restored_title = str_replace('_', ' ', filter_var($_GET['title'], FILTER_SANITIZE_SPECIAL_CHARS)); //optionally use - insted of _ ?> @@ -25,8 +29,10 @@ <?php echo htmlspecialchars($restored_title); ?> - - + + + + @@ -58,5 +64,9 @@ ?> + +