|
@@ -69,18 +69,18 @@ function escape($value)
|
|
|
*/
|
|
*/
|
|
|
function generateCsrfToken()
|
|
function generateCsrfToken()
|
|
|
{
|
|
{
|
|
|
- if (empty($_SESSION["csrf_token"])) {
|
|
|
|
|
- $_SESSION["csrf_token"] = bin2hex(random_bytes(32));
|
|
|
|
|
|
|
+ if (empty($_SESSION['csrf_token'])) {
|
|
|
|
|
+ $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
|
}
|
|
}
|
|
|
- return $_SESSION["csrf_token"];
|
|
|
|
|
|
|
+ return $_SESSION['csrf_token'];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function validateCsrfToken($token)
|
|
function validateCsrfToken($token)
|
|
|
{
|
|
{
|
|
|
- if (empty($_SESSION["csrf_token"])) {
|
|
|
|
|
|
|
+ if (empty($_SESSION['csrf_token'])) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- return hash_equals($_SESSION["csrf_token"], $token);
|
|
|
|
|
|
|
+ return hash_equals($_SESSION['csrf_token'], $token);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function csrfField()
|
|
function csrfField()
|
|
@@ -130,7 +130,7 @@ function setFlashMessage($key, $type, $message)
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $_SESSION["flash_messages"][$key] = [
|
|
|
|
|
|
|
+ $_SESSION['flash_messages'][$key] = [
|
|
|
"type" => $type,
|
|
"type" => $type,
|
|
|
"message" => $message,
|
|
"message" => $message,
|
|
|
];
|
|
];
|
|
@@ -143,7 +143,7 @@ function consumeFlashMessage($key)
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $messages = $_SESSION["flash_messages"] ?? [];
|
|
|
|
|
|
|
+ $messages = $_SESSION['flash_messages'] ?? [];
|
|
|
if (
|
|
if (
|
|
|
!is_array($messages) ||
|
|
!is_array($messages) ||
|
|
|
!isset($messages[$key]) ||
|
|
!isset($messages[$key]) ||
|
|
@@ -153,7 +153,7 @@ function consumeFlashMessage($key)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$message = $messages[$key];
|
|
$message = $messages[$key];
|
|
|
- unset($_SESSION["flash_messages"][$key]);
|
|
|
|
|
|
|
+ unset($_SESSION['flash_messages'][$key]);
|
|
|
|
|
|
|
|
$type = trim((string) ($message["type"] ?? ""));
|
|
$type = trim((string) ($message["type"] ?? ""));
|
|
|
$text = trim((string) ($message["message"] ?? ""));
|
|
$text = trim((string) ($message["message"] ?? ""));
|
|
@@ -325,7 +325,7 @@ function saveAdminAccounts($accounts)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ksort($result);
|
|
ksort($result);
|
|
|
- writeJsonFile(ADMINS_FILE, ["admins" => $result]);
|
|
|
|
|
|
|
+ return writeJsonFile(ADMINS_FILE, ["admins" => $result]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getDefaultCategories()
|
|
function getDefaultCategories()
|
|
@@ -413,7 +413,7 @@ function getCategories()
|
|
|
|
|
|
|
|
function saveCategories($categories)
|
|
function saveCategories($categories)
|
|
|
{
|
|
{
|
|
|
- writeJsonFile(CATEGORIES_FILE, [
|
|
|
|
|
|
|
+ return writeJsonFile(CATEGORIES_FILE, [
|
|
|
"categories" => normalizeCategories($categories),
|
|
"categories" => normalizeCategories($categories),
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
@@ -658,7 +658,7 @@ function saveProducts($products)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- writeJsonFile(PRODUCTS_FILE, ["products" => array_values($normalized)]);
|
|
|
|
|
|
|
+ return writeJsonFile(PRODUCTS_FILE, ["products" => array_values($normalized)]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getFaqFilePath(): string
|
|
function getFaqFilePath(): string
|
|
@@ -694,9 +694,9 @@ function getFaqContent(): string
|
|
|
return $data["content"];
|
|
return $data["content"];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function saveFaqContent(string $markdown): void
|
|
|
|
|
|
|
+function saveFaqContent(string $markdown): bool
|
|
|
{
|
|
{
|
|
|
- writeJsonFile(getFaqFilePath(), ["content" => (string) $markdown]);
|
|
|
|
|
|
|
+ return writeJsonFile(getFaqFilePath(), ["content" => (string) $markdown]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function renderFaqInlineMarkdown(string $text): string
|
|
function renderFaqInlineMarkdown(string $text): string
|
|
@@ -904,7 +904,7 @@ function getOrganizations($onlyActive = false)
|
|
|
|
|
|
|
|
function saveOrganizations($organizations)
|
|
function saveOrganizations($organizations)
|
|
|
{
|
|
{
|
|
|
- writeJsonFile(ORGANIZATIONS_FILE, [
|
|
|
|
|
|
|
+ return writeJsonFile(ORGANIZATIONS_FILE, [
|
|
|
"organizations" => normalizeOrganizations($organizations),
|
|
"organizations" => normalizeOrganizations($organizations),
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
@@ -1006,7 +1006,7 @@ function getSystemSettings()
|
|
|
|
|
|
|
|
function saveSystemSettings($settings)
|
|
function saveSystemSettings($settings)
|
|
|
{
|
|
{
|
|
|
- writeJsonFile(SETTINGS_FILE, [
|
|
|
|
|
|
|
+ return writeJsonFile(SETTINGS_FILE, [
|
|
|
"settings" => normalizeSystemSettings($settings),
|
|
"settings" => normalizeSystemSettings($settings),
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
@@ -1137,6 +1137,7 @@ function saveOrders($orders)
|
|
|
"order_count" => count($normalized),
|
|
"order_count" => count($normalized),
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
|
|
+ return (bool) $result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function generateOrderId()
|
|
function generateOrderId()
|
|
@@ -1349,7 +1350,7 @@ function buildAbsoluteUrl($path)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$scheme = isHttpsRequest() ? "https" : "http";
|
|
$scheme = isHttpsRequest() ? "https" : "http";
|
|
|
- $host = $_SERVER["HTTP_HOST"] ?? "";
|
|
|
|
|
|
|
+ $host = $_SERVER['HTTP_HOST'] ?? "";
|
|
|
if ($host === "") {
|
|
if ($host === "") {
|
|
|
return $path;
|
|
return $path;
|
|
|
}
|
|
}
|
|
@@ -1360,20 +1361,20 @@ function buildAbsoluteUrl($path)
|
|
|
function isHttpsRequest(): bool
|
|
function isHttpsRequest(): bool
|
|
|
{
|
|
{
|
|
|
if (
|
|
if (
|
|
|
- !empty($_SERVER["HTTPS"]) &&
|
|
|
|
|
- strtolower((string) $_SERVER["HTTPS"]) !== "off"
|
|
|
|
|
|
|
+ !empty($_SERVER['HTTPS']) &&
|
|
|
|
|
+ strtolower((string) $_SERVER['HTTPS']) !== "off"
|
|
|
) {
|
|
) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
if (
|
|
if (
|
|
|
- !empty($_SERVER["HTTP_X_FORWARDED_PROTO"]) &&
|
|
|
|
|
- strtolower((string) $_SERVER["HTTP_X_FORWARDED_PROTO"]) === "https"
|
|
|
|
|
|
|
+ !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
|
|
|
|
|
+ strtolower((string) $_SERVER['HTTP_X_FORWARDED_PROTO']) === "https"
|
|
|
) {
|
|
) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
if (
|
|
if (
|
|
|
- !empty($_SERVER["SERVER_PORT"]) &&
|
|
|
|
|
- (int) $_SERVER["SERVER_PORT"] === 443
|
|
|
|
|
|
|
+ !empty($_SERVER['SERVER_PORT']) &&
|
|
|
|
|
+ (int) $_SERVER['SERVER_PORT'] === 443
|
|
|
) {
|
|
) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -1707,7 +1708,7 @@ function formatDate($dateString)
|
|
|
|
|
|
|
|
function getCart()
|
|
function getCart()
|
|
|
{
|
|
{
|
|
|
- $cart = $_SESSION["cart"] ?? [];
|
|
|
|
|
|
|
+ $cart = $_SESSION['cart'] ?? [];
|
|
|
if (!is_array($cart)) {
|
|
if (!is_array($cart)) {
|
|
|
$cart = [];
|
|
$cart = [];
|
|
|
}
|
|
}
|
|
@@ -1741,8 +1742,8 @@ function getCart()
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $_SESSION["cart"] = array_values($normalized);
|
|
|
|
|
- return $_SESSION["cart"];
|
|
|
|
|
|
|
+ $_SESSION['cart'] = array_values($normalized);
|
|
|
|
|
+ return $_SESSION['cart'];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function addCartItem($productId, $size = "")
|
|
function addCartItem($productId, $size = "")
|
|
@@ -1785,7 +1786,7 @@ function addCartItem($productId, $size = "")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$cart[$index]["size"] = $size;
|
|
$cart[$index]["size"] = $size;
|
|
|
- $_SESSION["cart"] = array_values($cart);
|
|
|
|
|
|
|
+ $_SESSION['cart'] = array_values($cart);
|
|
|
|
|
|
|
|
return [
|
|
return [
|
|
|
"success" => true,
|
|
"success" => true,
|
|
@@ -1800,7 +1801,7 @@ function addCartItem($productId, $size = "")
|
|
|
"size" => $size,
|
|
"size" => $size,
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- $_SESSION["cart"] = array_values($cart);
|
|
|
|
|
|
|
+ $_SESSION['cart'] = array_values($cart);
|
|
|
return [
|
|
return [
|
|
|
"success" => true,
|
|
"success" => true,
|
|
|
"status" => "added",
|
|
"status" => "added",
|
|
@@ -1813,13 +1814,13 @@ function removeCartItemByIndex($index)
|
|
|
$cart = getCart();
|
|
$cart = getCart();
|
|
|
if (isset($cart[$index])) {
|
|
if (isset($cart[$index])) {
|
|
|
unset($cart[$index]);
|
|
unset($cart[$index]);
|
|
|
- $_SESSION["cart"] = array_values($cart);
|
|
|
|
|
|
|
+ $_SESSION['cart'] = array_values($cart);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function clearCart()
|
|
function clearCart()
|
|
|
{
|
|
{
|
|
|
- $_SESSION["cart"] = [];
|
|
|
|
|
|
|
+ $_SESSION['cart'] = [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getCartItemsDetailed()
|
|
function getCartItemsDetailed()
|
|
@@ -2340,9 +2341,9 @@ function logError($message, $context = [], $level = "ERROR")
|
|
|
"level" => $level,
|
|
"level" => $level,
|
|
|
"message" => $message,
|
|
"message" => $message,
|
|
|
"context" => $context,
|
|
"context" => $context,
|
|
|
- "ip" => $_SERVER["REMOTE_ADDR"] ?? "unknown",
|
|
|
|
|
- "user_agent" => $_SERVER["HTTP_USER_AGENT"] ?? "unknown",
|
|
|
|
|
- "request_uri" => $_SERVER["REQUEST_URI"] ?? "unknown",
|
|
|
|
|
|
|
+ "ip" => $_SERVER['REMOTE_ADDR'] ?? "unknown",
|
|
|
|
|
+ "user_agent" => $_SERVER['HTTP_USER_AGENT'] ?? "unknown",
|
|
|
|
|
+ "request_uri" => $_SERVER['REQUEST_URI'] ?? "unknown",
|
|
|
"session_id" => session_id()
|
|
"session_id" => session_id()
|
|
|
? substr(session_id(), 0, 8) . "..."
|
|
? substr(session_id(), 0, 8) . "..."
|
|
|
: "none",
|
|
: "none",
|
|
@@ -2367,9 +2368,9 @@ function logAccess($message, $context = [])
|
|
|
"timestamp" => date("Y-m-d H:i:s.u"),
|
|
"timestamp" => date("Y-m-d H:i:s.u"),
|
|
|
"message" => $message,
|
|
"message" => $message,
|
|
|
"context" => $context,
|
|
"context" => $context,
|
|
|
- "ip" => $_SERVER["REMOTE_ADDR"] ?? "unknown",
|
|
|
|
|
- "request_method" => $_SERVER["REQUEST_METHOD"] ?? "unknown",
|
|
|
|
|
- "request_uri" => $_SERVER["REQUEST_URI"] ?? "unknown",
|
|
|
|
|
|
|
+ "ip" => $_SERVER['REMOTE_ADDR'] ?? "unknown",
|
|
|
|
|
+ "request_method" => $_SERVER['REQUEST_METHOD'] ?? "unknown",
|
|
|
|
|
+ "request_uri" => $_SERVER['REQUEST_URI'] ?? "unknown",
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
$logLine = json_encode($entry, JSON_UNESCAPED_UNICODE) . PHP_EOL;
|
|
$logLine = json_encode($entry, JSON_UNESCAPED_UNICODE) . PHP_EOL;
|