forked from jordansamuel/PASTE
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpages.php
More file actions
executable file
·173 lines (156 loc) · 5.39 KB
/
pages.php
File metadata and controls
executable file
·173 lines (156 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/*
* Paste $v3.3 2025/10/24 https://github.com/boxlabss/PASTE
* demo: https://paste.boxlabs.uk/
*
* https://phpaste.sourceforge.io/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License in LICENCE for more details.
*/
require_once __DIR__ . '/includes/session.php';
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/includes/functions.php';
// UTF-8
header('Content-Type: text/html; charset=utf-8');
$date = date('Y-m-d');
$ip = $_SERVER['REMOTE_ADDR'];
$data_ip = @file_get_contents('tmp/temp.tdata') ?: '';
// Database Connection
global $pdo;
try {
// Get site info
$stmt = $pdo->query("SELECT * FROM site_info WHERE id = '1'");
$row = $stmt->fetch();
if (!$row) {
throw new Exception("Site configuration not found.");
}
$title = trim($row['title']);
$des = trim($row['des']);
$baseurl = rtrim(trim($row['baseurl']));
$keyword = trim($row['keyword']);
$site_name = trim($row['site_name']);
$email = trim($row['email']);
$twit = trim($row['twit']);
$face = trim($row['face']);
$gplus = trim($row['gplus']);
$ga = trim($row['ga']);
$additional_scripts = trim($row['additional_scripts']);
// Set theme and language
$stmt = $pdo->query("SELECT * FROM interface WHERE id = '1'");
$row = $stmt->fetch();
if (!$row) {
throw new Exception("Interface configuration not found.");
}
$default_lang = trim($row['lang']);
$default_theme = trim($row['theme']);
require_once("langs/$default_lang");
// Check if IP is banned
if (is_banned($pdo, $ip)) die($lang['banned']);
// Logout
if (isset($_GET['logout'])) {
header('Location: ' . ($_SERVER['HTTP_REFERER'] ?? $baseurl));
unset($_SESSION['token']);
unset($_SESSION['oauth_uid']);
unset($_SESSION['username']);
session_destroy();
exit;
}
// Page views
$date = date('Y-m-d');
$ip = $_SERVER['REMOTE_ADDR'];
try {
// Fetch or create the page_view record for today
$stmt = $pdo->prepare("SELECT id, tpage, tvisit FROM page_view WHERE date = ?");
$stmt->execute([$date]);
$row = $stmt->fetch();
if ($row) {
// Record exists for today
$page_view_id = $row['id'];
$tpage = (int)$row['tpage'] + 1; // Increment total page views
$tvisit = (int)$row['tvisit'];
// Check if this IP has visited today
$stmt = $pdo->prepare("SELECT COUNT(*) FROM visitor_ips WHERE ip = ? AND visit_date = ?");
$stmt->execute([$ip, $date]);
if ($stmt->fetchColumn() == 0) {
// New unique visitor
$tvisit += 1;
$stmt = $pdo->prepare("INSERT INTO visitor_ips (ip, visit_date) VALUES (?, ?)");
$stmt->execute([$ip, $date]);
}
// Update page_view with new counts
$stmt = $pdo->prepare("UPDATE page_view SET tpage = ?, tvisit = ? WHERE id = ?");
$stmt->execute([$tpage, $tvisit, $page_view_id]);
} else {
// No record for today: create one
$tpage = 1;
$tvisit = 1;
$stmt = $pdo->prepare("INSERT INTO page_view (date, tpage, tvisit) VALUES (?, ?, ?)");
$stmt->execute([$date, $tpage, $tvisit]);
// Log the visitor's IP
$stmt = $pdo->prepare("INSERT INTO visitor_ips (ip, visit_date) VALUES (?, ?)");
$stmt->execute([$ip, $date]);
}
} catch (PDOException $e) {
error_log("Page view tracking error: " . $e->getMessage());
}
// Ads
$stmt = $pdo->query("SELECT * FROM ads WHERE id = '1'");
$row = $stmt->fetch();
if (!$row) {
$text_ads = $ads_1 = $ads_2 = '';
} else {
$text_ads = trim($row['text_ads']);
$ads_1 = trim($row['ads_1']);
$ads_2 = trim($row['ads_2']);
}
// Accept both ?p=slug and ?page=slug (mod_rewrite typically maps to ?p=)
$page_name = isset($_GET['p']) ? trim($_GET['p']) : (isset($_GET['page']) ? trim($_GET['page']) : '');
if ($page_name !== '') {
$stmt = $pdo->prepare("
SELECT page_title, page_content, last_date, external_url
FROM pages
WHERE page_name = ? AND is_active = 1
LIMIT 1
");
$stmt->execute([$page_name]);
$row = $stmt->fetch();
if ($row) {
// Check for external URL redirect
if (!empty($row['external_url'])) {
$external = $row['external_url'];
// If relative URL, prepend baseurl
if (!preg_match('/^https?:\/\//', $external)) {
$external = rtrim($baseurl, '/') . '/' . ltrim($external, '/');
}
header('Location: ' . $external);
exit;
}
$page_title = $row['page_title'];
$page_content = $row['page_content'];
$last_date = $row['last_date'];
$stats = "OK";
$p_title = $page_title;
} else {
$page_title = "Error";
$page_content = "<div class='alert alert-danger text-center'>Page not found or inactive.</div>";
$last_date = $date;
$stats = null;
$p_title = "Error";
}
}
// Theme
require_once('theme/' . $default_theme . '/header.php');
require_once('theme/' . $default_theme . '/pages.php');
require_once('theme/' . $default_theme . '/footer.php');
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
?>