Skip to content

Commit 5228420

Browse files
Merge pull request #13 from Dominik-developer/user-cookies
User cookies & admin dark theme
2 parents 483762f + b70c8a6 commit 5228420

22 files changed

Lines changed: 295 additions & 111 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@ The project is ready for use but is still evolving. Work is ongoing to fix bugs
1010

1111
### Added
1212
<!-- - Initial examples of added changelog entries. -->
13+
14+
`/public`
15+
1 - cookies for users, db collects data for analytics
16+
2 - tables for cookies added
17+
3 - JS folder
18+
4 - popout for cookies
1319
.....
1420

1521
### Changed
1622
<!-- - Improved existing changelog entries for consistency. -->
23+
24+
`/public`
25+
1 - structure of /public fixes
1726
.....
1827

1928
### Fixed

HOW_TO_RUN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ CorelyPHP is a ready-to-deploy blogging platform designed for efficient web deve
88

99
Before you begin, ensure you have the following installed:
1010

11-
- PHP (>= 8.0)
12-
- MySQL (or another compatible database)
13-
- XAMPP
11+
- PHP (>= 8.0) <!--(in XAMPP/MAMP)-->
12+
- MySQL (or another compatible database) <!--(in XAMPP/MAMP)-->
13+
- XAMPP / MAMP
1414
- Git
1515

1616
## Installation

admin/panel.connect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$host = "localhost";
44
$db_user = "root";
5-
$db_password ="";
5+
$db_password ="root";
66
$db_name = "blog";
77

88

database_SQL/blog_DB_data.sql

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
21
START TRANSACTION;
3-
SET time_zone = "+00:00";
4-
5-
USE `blog`;
6-
7-
--
8-
-- Inserting data into table `admin`
9-
--
102

113
INSERT INTO `admin` (`id`, `login`, `password`) VALUES
12-
(1, 'admin', '$2y$10$L9fQlnPTTuYkNhLnXh68..F8R.bJdLaAJBJjXU8RjhiHUHFVVJyCe');
4+
(1, 'admin', '$2y$10$w9GkWVGXxSTjw4A9QyjasuqyeJyUPp2JlWYnFGFEen7e2..YUXxNC');
135

14-
--
15-
-- Inserting data into table `service`
16-
--
6+
-- --------------------------------------------------------
177

188
INSERT INTO `service` (`id`, `service_status`) VALUES
19-
(1, 1);
20-
9+
(1, 0);
2110

2211
COMMIT;

database_SQL/blog_DB_structure.sql

Lines changed: 41 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,64 @@
1+
-- Databse 'blog': structure
12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
23
START TRANSACTION;
34
SET time_zone = "+00:00";
45

5-
CREATE DATABASE IF NOT EXISTS `blog`;
6-
USE `blog`;
7-
8-
/*!40101 SET NAMES utf8mb4 */;
9-
10-
--
11-
-- Table structure for table `admin`
12-
--
6+
-- --------------------------------------------------------
137

148
CREATE TABLE `admin` (
15-
`id` int(11) NOT NULL,
16-
`login` varchar(25) NOT NULL,
17-
`password` varchar(25) NOT NULL
9+
`id` int NOT NULL AUTO_INCREMENT,
10+
`login` varchar(25) COLLATE utf8mb4_general_ci NOT NULL,
11+
`password` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
12+
PRIMARY KEY (`id`)
1813
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
1914

20-
--
21-
-- Table structure for table `articles`
22-
--
15+
-- --------------------------------------------------------
2316

2417
CREATE TABLE `articles` (
25-
`ID` int(11) NOT NULL,
26-
`title` varchar(255) NOT NULL,
27-
`text` text NOT NULL,
28-
`photo_path` varchar(255) NOT NULL,
29-
`date_of_publish` timestamp NOT NULL DEFAULT current_timestamp()
18+
`ID` int NOT NULL AUTO_INCREMENT,
19+
`title` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
20+
`text` text COLLATE utf8mb4_general_ci NOT NULL,
21+
`photo_path` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
22+
`date_of_publish` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
23+
PRIMARY KEY (`ID`)
3024
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
3125

32-
--
33-
-- Table structure for table `service`
34-
--
26+
-- --------------------------------------------------------
27+
28+
CREATE TABLE `page_views_daily` (
29+
`id` int NOT NULL AUTO_INCREMENT,
30+
`page` varchar(191) NOT NULL,
31+
`visit_date` date NOT NULL DEFAULT (curdate()),
32+
`visit_count` int NOT NULL DEFAULT '1',
33+
PRIMARY KEY (`id`),
34+
UNIQUE KEY `unique_page_date` (`page`,`visit_date`)
35+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
36+
37+
-- --------------------------------------------------------
3538

3639
CREATE TABLE `service` (
37-
`id` int(11) NOT NULL,
38-
`service_status` tinyint(1) NOT NULL
40+
`id` int NOT NULL AUTO_INCREMENT,
41+
`service_status` tinyint(1) NOT NULL,
42+
PRIMARY KEY (`id`)
3943
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
4044

41-
--
42-
-- Table structure for table `settings`
43-
--
45+
-- --------------------------------------------------------
4446

4547
CREATE TABLE `settings` (
46-
`id` int(11) NOT NULL,
47-
`is_active` tinyint(1) NOT NULL
48+
`id` int NOT NULL AUTO_INCREMENT,
49+
`is_active` tinyint(1) NOT NULL,
50+
PRIMARY KEY (`id`)
4851
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
4952

50-
--
51-
-- Indexes for tables
52-
--
53-
54-
ALTER TABLE `admin`
55-
ADD PRIMARY KEY (`id`);
56-
57-
ALTER TABLE `articles`
58-
ADD PRIMARY KEY (`ID`);
59-
60-
ALTER TABLE `service`
61-
ADD PRIMARY KEY (`id`);
62-
63-
ALTER TABLE `settings`
64-
ADD PRIMARY KEY (`id`);
65-
66-
--
67-
-- AUTO_INCREMENT for tables
68-
--
69-
70-
ALTER TABLE `admin`
71-
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
72-
73-
ALTER TABLE `articles`
74-
MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;
53+
-- --------------------------------------------------------
7554

76-
ALTER TABLE `settings`
77-
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
55+
CREATE TABLE `visitors` (
56+
`id` int NOT NULL AUTO_INCREMENT,
57+
`cookie_id` varchar(64) DEFAULT NULL,
58+
`visit_count` int DEFAULT '1',
59+
`first_visit` datetime DEFAULT CURRENT_TIMESTAMP,
60+
PRIMARY KEY (`id`),
61+
UNIQUE KEY `cookie_id` (`cookie_id`)
62+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
7863

7964
COMMIT;
File renamed without changes.

public/CSS/popout.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.cookie-popup {
2+
position: fixed;
3+
bottom: 20px;
4+
left: 50%;
5+
transform: translateX(-50%);
6+
background-color: #333;
7+
color: #fff;
8+
padding: 15px 20px;
9+
border-radius: 8px;
10+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
11+
display: none;
12+
}
13+
14+
.cookie-popup a {
15+
color: #fff;
16+
text-decoration: underline;
17+
}
18+
19+
.cookie-popup button {
20+
background-color: #fff;
21+
color: #333;
22+
border: none;
23+
padding: 8px 12px;
24+
margin-left: 10px;
25+
cursor: pointer;
26+
border-radius: 5px;
27+
font-weight: bold;
28+
}
29+
30+
.cookie-popup button:hover {
31+
background-color: #ddd;
32+
}
33+
34+
.cookie-popup button#reject-cookies {
35+
background-color: #ff4d4d; /* Czerwony dla opcji odrzucenia */
36+
color: white;
37+
}
38+
39+
.cookie-popup button#reject-cookies:hover {
40+
background-color: #cc0000
41+
}
File renamed without changes.

public/JS/popout.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
document.addEventListener("DOMContentLoaded", function () {
3+
const popup = document.getElementById("cookie-popup");
4+
const acceptButton = document.getElementById("accept-cookies");
5+
const rejectButton = document.getElementById("reject-cookies");
6+
7+
const cookiesAccepted = document.cookie.includes("cookiesAccepted=true");
8+
const cookiesRejected = document.cookie.includes("cookiesAccepted=false");
9+
10+
if (!cookiesAccepted && !cookiesRejected) {
11+
popup.style.display = "block";
12+
}
13+
14+
function setCookie(name, value, days) {
15+
let expires = "";
16+
if (days) {
17+
const date = new Date();
18+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
19+
expires = "; expires=" + date.toUTCString();
20+
}
21+
document.cookie = name + "=" + value + expires + "; path=/public/"; //path may need to be changed for client
22+
}
23+
24+
// Obsługa zgody na ciasteczka
25+
acceptButton.addEventListener("click", function () {
26+
setCookie("cookiesAccepted", "true", 365);
27+
popup.style.display = "none";
28+
location.reload();
29+
});
30+
31+
// Obsługa odrzucenia ciasteczek
32+
rejectButton.addEventListener("click", function () {
33+
setCookie("cookiesAccepted", "false", 365);
34+
popup.style.display = "none";
35+
location.reload();
36+
});
37+
});
38+
39+

public/error.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<title>Error page</title>
77

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

1111
<!--== CSS STYLES ==-->
1212
<style>
@@ -19,7 +19,10 @@
1919

2020
</style>
2121

22-
<!--== JS ==-->
22+
<!--== JS FILE ==-->
23+
<script src="./JS/popout.js"></script>
24+
25+
<!--== JS SCRIPT ==-->
2326
<script>
2427
</script>
2528
</head>
@@ -34,7 +37,7 @@ <h1><!--404-->Error page</h1>
3437

3538
<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>
3639

37-
<a href="index.php">Link: Blog main page</a>
40+
<p>Link: <a href="index.php">Blog main page</a></p>
3841
</main>
3942

4043
</body>

0 commit comments

Comments
 (0)