Spoiler
Code:
<?php
// Prevent direct access to the file
if (!defined("IN_MYBB")) {
die("Direct initialization of this file is not allowed.");
}
function partialthreadviewforguests_info()
{
return array(
"name" => "Partial Thread View for Guests",
"description" => "Limits thread viewing to a preview for guests, prompting registration to view full content.Option for later and Right Mouse Button and Dev Option Lock",
"website" => "https://cheattables.net",
"author" => "Do0ks",
"authorsite" => "https://cheattables.net",
"version" => "1.3",
"compatibility" => "18*"
);
}
$plugins->add_hook("showthread_start", "partialthreadviewforguests_limit_content");
function partialthreadviewforguests_limit_content() {
global $mybb, $templates, $session;
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
$bots = [
'googlebot', 'bingbot', 'slurp', 'duckduckbot', 'baiduspider',
'yandexbot', 'sogou', 'exabot', 'facebookexternalhit',
'twitterbot', 'linkedinbot', 'pinterest', 'instagram',
'whatsapp', 'snapchat', 'discordbot', 'telegrambot',
'applebot', 'pingdom', 'tumblr'
];
foreach ($bots as $bot) {
if (strpos($userAgent, $bot) !== false) {
return;
}
}
if ($mybb->user['uid'] == 0) {
add_partial_view_modal();
}
}
function add_partial_view_modal() {
$modalStyles = '<style>
#partialContentModal {
display: none;
position: fixed;
z-index: 1001;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.7);
backdrop-filter: blur(10px);
}
#modalContent {
background: #181818 no-repeat;
background-size: cover;
color: #fff;
font-family: Arial, sans-serif;
margin: 15% auto;
padding: 20px;
width: 40%;
text-align: center;
border: 1px solid #444;
box-shadow: 0 5px 25px #21042E;
}
#modalContent h2, #modalContent p {
margin-bottom: 20px;
}
#modalContent button {
background-color: #222;
border: 1px solid #555;
color: #ddd;
padding: 10px 20px;
margin: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
#modalContent button:hover {
background-color: #333;
}
body.noScroll {
overflow: hidden;
}
</style>';
$modalScript = '<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
var lastScrollTop = 0;
var scrollCount = 0;
var showModalFlag = localStorage.getItem("hasScrolled") === "true";
function showModal() {
document.getElementById("partialContentModal").style.display = "block";
document.body.classList.add("noScroll");
}
function resetModal() {
document.getElementById("partialContentModal").style.display = "none";
document.body.classList.remove("noScroll");
localStorage.removeItem("hasScrolled");
scrollCount = 0;
}
document.getElementById("closeModal").addEventListener("click", resetModal);
window.onscroll = function() {
var st = window.pageYOffset || document.documentElement.scrollTop;
if (Math.abs(lastScrollTop - st) <= 50) return; // Ignore minor scrolls
lastScrollTop = st;
scrollCount++;
if (scrollCount >= 40 && !showModalFlag) {
showModal();
localStorage.setItem("hasScrolled", "true");
}
};
// Disable right-click
document.addEventListener("contextmenu", function(e) {
e.preventDefault();
alert("Rechtsklick ist deaktiviert.");
});
// Prevent F12 and other developer tools shortcuts
document.addEventListener("keydown", function(e) {
if (e.key === "F12" || (e.ctrlKey && e.shiftKey && e.key === "I") ||
(e.ctrlKey && e.shiftKey && e.key === "C") ||
(e.ctrlKey && e.shiftKey && e.key === "J") ||
(e.ctrlKey && e.key === "U")) {
e.preventDefault();
alert("Entwickleroptionen sind deaktiviert.");
}
});
});
</script>';
echo $modalStyles . '
<div id="partialContentModal">
<div id="modalContent">
<h2><strong>Enjoying the Content?</strong></h2>
<p>Please login or register to gain full access.</p>
<button style="color: magenta;" onclick="window.location.href=\'member.php?action=login\'"><i class="fa-solid fa-key"></i>Login</button>
<button style="color: magenta;" onclick="window.location.href=\'member.php?action=register\'"><i class="fa-solid fa-user-plus"></i> Register</button><br>
<button style="color: magenta;" id="closeModal">Jetzt nicht</button>
</div>
</div>' . $modalScript;
}
?>