<?php
declare(strict_types=1);
use Firebase\JWT\JWT;
include_once 'settings.php';
include_once 'bbcode.php';
try {
$token = JWT::decode($authHeader, $secretKey, ['HS512']);
if ($token->iss !== $serverName ||
$token->nbf > $now->getTimestamp() ||
$token->exp < $now->getTimestamp() ||
mb_strtolower($token->data->userName) === $b_u) {
exit;
}
} catch (Exception $e) {
$userIsGuest = true;
}
// Store the posted shout data to the data store
if(isset($_POST["name"]) && isset($_POST["comment"]) && mb_strlen($_POST['name'], 'utf-8') <= 25 && !empty($_POST['comment']) && mb_strlen($_POST['comment'], 'utf-8') <= $m_c) {
$name = htmlspecialchars($_POST["name"]);
$name = str_replace(array("\n", "\r"), '', $name);
$comment = htmlspecialchars($_POST["comment"]);
$comment = str_replace(array("\n", "\r"), '', $comment);
if($userIsGuest && empty($comment)) {
die();
} else {
$comment = preg_replace('~https://i\.imgur\.com(*SKIP)(*FAIL)|https?://' . $_SERVER['SERVER_NAME'] . '(*SKIP)(*FAIL)|https?://~s', '', $comment);
}
$comment = showBBcodes($comment);
if ($r_a === '1') {
if( $userIsGuest ) {
echo 'Access Denied';
die();
} else {
$shout = new \JamesMoss\Flywheel\Document(array(
'text' => $comment,
'name' => $token->data->userName,
'loggedIn' => 'true',
'createdAt' => time()
));
$repoShouts->store($shout);
}
} else {
if($userIsGuest) {
$shout = new \JamesMoss\Flywheel\Document(array(
'text' => $comment,
'name' => $name,
'createdAt' => time()
));
}
else {
$shout = new \JamesMoss\Flywheel\Document(array(
'text' => $comment,
'name' => $token->data->userName,
'loggedIn' => 'true',
'createdAt' => time()
));
}
$repoShouts->store($shout);
}
}
Авиация
Сообщений 121 страница 130 из 134
Поделиться1212023-04-26 01:53 am
Поделиться1222023-04-26 01:58 am
Here's a shorter and optimized version of the provided PHP code:
```php
<?php
declare(strict_types=1);
use Firebase\JWT\JWT;
include_once 'settings.php';
include_once 'bbcode.php';
try {
$token = JWT::decode($authHeader, $secretKey, ['HS512']);
if ($token->iss !== $serverName ||
$token->nbf > $now->getTimestamp() ||
$token->exp < $now->getTimestamp() ||
mb_strtolower($token->data->userName) === $b_u) {
exit;
}
} catch (Exception $e) {
$userIsGuest = true;
}
if (isset($_POST["name"], $_POST["comment"]) && mb_strlen($_POST['name'], 'utf-8') <= 25 && !empty($_POST['comment']) && mb_strlen($_POST['comment'], 'utf-8') <= $m_c) {
$name = str_replace(["\n", "\r"], '', htmlspecialchars($_POST["name"]));
$comment = showBBcodes(str_replace(["\n", "\r"], '', preg_replace('~https://i\.imgur\.com(*SKIP)(*FAIL)|https?://' . $_SERVER['SERVER_NAME'] . '(*SKIP)(*FAIL)|https?://~s', '', htmlspecialchars($_POST["comment"]))));
if ($r_a === '1' && $userIsGuest) {
echo 'Access Denied';
die();
}
$shoutData = [
'text' => $comment,
'name' => $userIsGuest ? $name : $token->data->userName,
'createdAt' => time()
];
if (!$userIsGuest) {
$shoutData['loggedIn'] = 'true';
}
$shout = new \JamesMoss\Flywheel\Document($shoutData);
$repoShouts->store($shout);
}
```
In this optimized version, I've combined some conditions, removed redundant `else` blocks, and simplified the creation of the `$shoutData` array.
Поделиться1232023-04-26 02:04 am
<?php
declare(strict_types=1);
use Firebase\JWT\JWT;
include_once 'settings.php';
if(!isset($_GET['history'])) {
$shouts = $repoShouts->query()
->orderBy('createdAt DESC')
->limit($m_s, 0)
->execute();
} else {
$shouts = $repoShouts->query()
->orderBy('createdAt DESC')
->limit($m_h, $m_s)
->execute();
}
$results = array();
$config = array(
'language' => '\RelativeTime\Languages\L' . $l_g,
'truncate' => 1,
);
$relativeTime = new \RelativeTime\RelativeTime($config);
foreach($shouts as $shout) {
$id = $shout->getId();
$id = mb_substr($id, 0, 4);
$loggedIn = $shout->loggedIn;
$text = $shout->text;
$name = $shout->name;
$timeAgo = $relativeTime->timeAgo($shout->createdAt);
$buildArray = array(
'id' => $id,
'loggedIn' => $loggedIn,
'text' => $text,
'name' => $name,
'timeAgo' => $timeAgo,
'timeStamp' => date('d.m.Y H:i', $shout->createdAt)
);
$results[] = $buildArray;
}
try {
$token = JWT::decode($authHeader, $secretKey, ['HS512']);
if ($token->iss !== $serverName ||
$token->nbf > $now->getTimestamp() ||
$token->exp < $now->getTimestamp()) {
header('HTTP/1.1 401 Unauthorized');
exit;
}
$is_not_valid_user = mb_strtolower($token->data->userName) !== $b_u;
$is_valid_moderator = $token->data->moderator && $is_not_valid_user;
$is_valid_logged_in = $token->data->loggedIn && $is_not_valid_user;
if($is_valid_moderator || $is_valid_logged_in) {
echo json_encode($results, JSON_UNESCAPED_UNICODE);
} else {
include 'data/languages/' . $l_g . '/app_lang.extra.' . $l_g . '.php';
echo '[{"id":"denied","text":"' . $lang['APP_ACCESS_BANNED'] . '","name":"ChatX","timeAgo":""}]';
}
} catch (Exception $e) {
if ( $r_a === '1' ) {
include 'data/languages/' . $l_g . '/app_lang.extra.' . $l_g . '.php';
echo '[{"id":"denied","text":"' . $lang['APP_ACCESS_DENIED'] . '","name":"ChatX","timeAgo":""}]';
exit;
} else {
echo json_encode($results, JSON_UNESCAPED_UNICODE);
}
}
header('Content-type: application/json; charset=utf-8');
Поделиться1242023-04-26 02:08 am
Here's a shorter and optimized version of the provided PHP code:
```php
<?php
declare(strict_types=1);
use Firebase\JWT\JWT;
include_once 'settings.php';
$shouts = $repoShouts->query()
->orderBy('createdAt DESC')
->limit(isset($_GET['history']) ? $m_h : $m_s, isset($_GET['history']) ? $m_s : 0)
->execute();
$results = [];
$config = ['language' => '\RelativeTime\Languages\L' . $l_g, 'truncate' => 1];
$relativeTime = new \RelativeTime\RelativeTime($config);
foreach ($shouts as $shout) {
$results[] = [
'id' => mb_substr($shout->getId(), 0, 4),
'loggedIn' => $shout->loggedIn,
'text' => $shout->text,
'name' => $shout->name,
'timeAgo' => $relativeTime->timeAgo($shout->createdAt),
'timeStamp' => date('d.m.Y H:i', $shout->createdAt),
];
}
try {
$token = JWT::decode($authHeader, $secretKey, ['HS512']);
if ($token->iss !== $serverName ||
$token->nbf > $now->getTimestamp() ||
$token->exp < $now->getTimestamp()) {
header('HTTP/1.1 401 Unauthorized');
exit;
}
$is_not_valid_user = mb_strtolower($token->data->userName) !== $b_u;
$is_valid_moderator = $token->data->moderator && $is_not_valid_user;
$is_valid_logged_in = $token->data->loggedIn && $is_not_valid_user;
if ($is_valid_moderator || $is_valid_logged_in) {
echo json_encode($results, JSON_UNESCAPED_UNICODE);
} else {
include 'data/languages/' . $l_g . '/app_lang.extra.' . $l_g . '.php';
echo '[{"id":"denied","text":"' . $lang['APP_ACCESS_BANNED'] . '","name":"ChatX","timeAgo":""}]';
}
} catch (Exception $e) {
if ($r_a === '1') {
include 'data/languages/' . $l_g . '/app_lang.extra.' . $l_g . '.php';
echo '[{"id":"denied","text":"' . $lang['APP_ACCESS_DENIED'] . '","name":"ChatX","timeAgo":""}]';
} else {
echo json_encode($results, JSON_UNESCAPED_UNICODE);
}
}
header('Content-type: application/json; charset=utf-8');
```
In this optimized version, I've combined the two separate queries for `$shouts` into a single query using a ternary operator. I've also simplified the creation of the `$results` array by directly assigning the values within the `foreach` loop.
Поделиться1252023-05-05 01:26 am
try {
if (GroupID !== 3 && BoardID && !sessionName) {
jQuery.ajax({
type: "POST",
url: chatx_server + "client/auth.php",
data: {
'u': UserLogin,
'p': UserUniqueID
},
dataType: "json",
xhrFields: {
withCredentials: true
},
success: function(data) {
jQuery.getScript(chatx_server + "dynamic_js.php");
if (data.success) {
jQuery(".icon-refresh").trigger("click");
jQuery(".chatx_logout").remove();
} else {
$("input[name='reg_u'], input[name='reg_p'], input[name='c_reg_p']").hide();
$(".chx-signup-form-contents .chx-login-button").removeClass("icon-login").addClass("chx-mybb-login").css({
"font-size": "12px",
"border-radius": "5px",
"margin": "45px auto",
"border": "2px solid",
"width": "180px",
"height": "unset",
"padding": "15px 0",
"text-transform": "uppercase"
});
$("input[name='reg_u']").val(UserLogin);
$("input[name='reg_p'], input[name='c_reg_p']").val(UserUniqueID);
$(".chx-switch-tab.first").removeClass("active");
$(".chx-switch-tab.second").addClass("active");
$("#chx-signup-form").click();
jQuery('.chx-signup-form-contents .chx-login-button').on('click', function() {
setTimeout(function() {
jQuery.getScript(chatx_server + 'assets/js/mybb-authentication.min.js');
}, 2000);
});
}
}
});
} else {
if (GroupID !== 3) {
jQuery(".chatx_logout").remove();
}
jQuery("#navlogout").click(function() {
jQuery.getScript(chatx_server + "client/logout.php?ajax");
});
}
} catch (e) {
console.error("Error. Failed to recognize a MyBB.RU forum.");
}
Поделиться1262023-05-05 01:30 am
Here's the rewritten code in vanilla JavaScript:
try {
if (GroupID !== 3 && BoardID && !sessionName) {
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
const response = JSON.parse(xhr.responseText);
if (response.success) {
fetch(chatx_server + "dynamic_js.php").then(() => {
document.querySelector(".icon-refresh").dispatchEvent(new Event("click"));
document.querySelector(".chatx_logout").remove();
});
} else {
const reg_u = document.querySelector("input[name='reg_u']");
const reg_p = document.querySelector("input[name='reg_p']");
const c_reg_p = document.querySelector("input[name='c_reg_p']");
reg_u.style.display = "none";
reg_p.style.display = "none";
c_reg_p.style.display = "none";
const loginButton = document.querySelector(".chx-signup-form-contents .chx-login-button");
loginButton.classList.remove("icon-login");
loginButton.classList.add("chx-mybb-login");
loginButton.style.fontSize = "12px";
loginButton.style.borderRadius = "5px";
loginButton.style.margin = "45px auto";
loginButton.style.border = "2px solid";
loginButton.style.width = "180px";
loginButton.style.height = "unset";
loginButton.style.padding = "15px 0";
loginButton.style.textTransform = "uppercase";
reg_u.value = UserLogin;
reg_p.value = UserUniqueID;
c_reg_p.value = UserUniqueID;
document.querySelector(".chx-switch-tab.first").classList.remove("active");
document.querySelector(".chx-switch-tab.second").classList.add("active");
document.getElementById("chx-signup-form").click();
const signupButton = document.querySelector(".chx-signup-form-contents .chx-login-button");
signupButton.addEventListener("click", function() {
setTimeout(function() {
fetch(chatx_server + "assets/js/mybb-authentication.min.js");
}, 2000);
});
}
}
};
xhr.open("POST", chatx_server + "client/auth.php");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(`u=${UserLogin}&p=${UserUniqueID}`);
} else {
if (GroupID !== 3) {
document.querySelector(".chatx_logout").remove();
}
document.querySelector("#navlogout").addEventListener("click", function() {
fetch(chatx_server + "client/logout.php?ajax").then(() => {
// handle logout success
}).catch((error) => {
// handle logout error
});
});
}
} catch (e) {
console.error("Error. Failed to recognize a MyBB.RU forum.");
}Note that I assumed that some of the variables such as `GroupID`, `BoardID`, `sessionName`, `UserLogin`, and `UserUniqueID` have been defined elsewhere in the code.
Поделиться1272023-05-05 02:24 am
const getScript = url => new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = url;
script.async = true;
script.onerror = reject;
script.onload = script.onreadystatechange = function() {
const loadState = this.readyState;
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return;
script.onload = script.onreadystatechange = null;
resolve();
};
document.head.appendChild(script);
});
Поделиться1282023-05-05 02:48 am
document.querySelector("input[name='c_reg_p']").placeholder = confirmPassWord;
Поделиться1292023-05-05 02:51 am
const confirmPassWord = 'confirmPassWord';
const inputConfirmPassWord = document.querySelector("input[name='c_reg_p']");
if (inputConfirmPassWord) {
inputConfirmPassWord.placeholder = confirmPassWord;
}
Поделиться1302023-05-05 02:51 am
const confirmPassWord = 'confirmPassWord';
const inputConfirmPassWord = document.querySelector("input[name='c_reg_p']");
if (inputConfirmPassWord) {
inputConfirmPassWord.placeholder = confirmPassWord;
}
Быстрый ответ
Похожие темы
| Космос | Обои для рабочего стола | 2025-01-03 |