Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ The project is ready for use but is still evolving. Work is ongoing to fix bugs

### Added
<!-- - Initial examples of added changelog entries. -->

`/public`
1 - cookies for users, db collects data for analytics
2 - tables for cookies added
3 - JS folder
4 - popout for cookies
.....

### Changed
<!-- - Improved existing changelog entries for consistency. -->

`/public`
1 - structure of /public fixes
.....

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions HOW_TO_RUN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) <!--(in XAMPP/MAMP)-->
- MySQL (or another compatible database) <!--(in XAMPP/MAMP)-->
- XAMPP / MAMP
- Git

## Installation
Expand Down
2 changes: 1 addition & 1 deletion admin/panel.connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

$host = "localhost";
$db_user = "root";
$db_password ="";
$db_password ="root";
$db_name = "blog";


Expand Down
17 changes: 3 additions & 14 deletions database_SQL/blog_DB_data.sql
Original file line number Diff line number Diff line change
@@ -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;
97 changes: 41 additions & 56 deletions database_SQL/blog_DB_structure.sql
Original file line number Diff line number Diff line change
@@ -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;
File renamed without changes.
41 changes: 41 additions & 0 deletions public/CSS/popout.css
Original file line number Diff line number Diff line change
@@ -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
}
File renamed without changes.
39 changes: 39 additions & 0 deletions public/JS/popout.js
Original file line number Diff line number Diff line change
@@ -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();
});
});


9 changes: 6 additions & 3 deletions public/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>Error page</title>

<!--== CSS FILE ==-->
<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="./CSS/main.css" />

<!--== CSS STYLES ==-->
<style>
Expand All @@ -19,7 +19,10 @@

</style>

<!--== JS ==-->
<!--== JS FILE ==-->
<script src="./JS/popout.js"></script>

<!--== JS SCRIPT ==-->
<script>
</script>
</head>
Expand All @@ -34,7 +37,7 @@ <h1><!--404-->Error page</h1>

<p>Something went wrong.<!--Don't worry, you didn't do anything wrong. We just couldn't find what you are looking for.--><br><br>Try to search what you have been looking for on main page:</p>

<a href="index.php">Link: Blog main page</a>
<p>Link: <a href="index.php">Blog main page</a></p>
</main>

</body>
Expand Down
20 changes: 15 additions & 5 deletions public/error_404.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@

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);


?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 error </title>

<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="single.css" />
<link rel="stylesheet" href="./CSS/main.css" />
<link rel="stylesheet" href="./CSS/single.css" />

<script src="./JS/popout.js"></script>

</head>
<body>
Expand Down Expand Up @@ -53,5 +59,9 @@
?>
</footer>

<?php
cookie_popout()
?>

</body>
</html>
2 changes: 1 addition & 1 deletion public/connect.php → public/handlers/connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

$host = "localhost";
$db_user = "root";
$db_password ="";
$db_password ="root";
$db_name = "blog";


21 changes: 21 additions & 0 deletions public/handlers/cookies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require 'visits.alg.php';

function cookie($page): void {
if (isset($_COOKIE['cookiesAccepted']) && $_COOKIE['cookiesAccepted'] === 'true') {
setcookie("cookiesAccepted", "true", time() + (3600 * 24 * 365), "/public/"); //path may need to be changed for client

if (!isset($_COOKIE['visitor_id'])) {
$cookie_id = bin2hex(random_bytes(16));
setcookie('visitor_id', $cookie_id, time() + (3600 * 24 * 365), "/public/");
} else {
$cookie_id = $_COOKIE['visitor_id'];
}

updateVisitCount($cookie_id, $page);
} else {
setcookie('visitor_id', "", time() - 3600, "/public/");
}
}

Loading