
<?php
session_set_cookie_params(['secure' => true,'httponly' => true,'samesite' => 'Strict']);
session_start();
$session_lifetime = 3 * 60; // Session timeout
$correct_username = "admin";
$correct_password_hash = '$2y$10$S9naYnE6MqP14zVRfIsig.A98jBGzEImaGLgKVuiSGKpI7yr7XeGG'; // password: 4869
//echo password_hash("pass", PASSWORD_DEFAULT); //generate
if (isset($_GET['logout'])) {
session_unset();
session_destroy();
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['heartbeat'])) {
$_SESSION['last_activity'] = time();
exit;
}
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if ($username === $correct_username && password_verify($password, $correct_password_hash)) {
session_regenerate_id(true);
$_SESSION['logged_in'] = true;
$_SESSION['last_activity'] = time();
header("Location: " . $_SERVER['PHP_SELF']);
exit;
} else {
$error = "Invalid username or password.";
}
}
?>
<?php if (isset($error)) echo "<p style='color:red;'>$error</p>"; ?>
<form method="post">
<label>Username: <input name="username" required></label><br>
<label>Password: <input type="password" name="password" required></label><br>
<button type="submit">Login</button>
</form>

<?php
exit;
}
if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity']) > $session_lifetime) {
session_unset();
session_destroy();
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
$_SESSION['last_activity'] = time(); // Refresh session activity
$remaining_time = ($_SESSION['last_activity'] + $session_lifetime) - time();
?>
Welcome, you are logged in! <span id="countdown"></span><hr>
<a href="?logout=1">Logout</a>
<script>
let remaining = <?php echo $remaining_time; ?>;
function updateCountdown() {
if (remaining <= 0) {
clearInterval(timer);
alert("Session expired due to inactivity.");
location.reload();
return;
}
const minutes = Math.floor(remaining / 60);
const seconds = remaining % 60;
document.getElementById('countdown').textContent =
minutes + "m " + (seconds < 10 ? "0" : "") + seconds + "s";
remaining--;
}
updateCountdown();
const timer = setInterval(updateCountdown, 1000);
setInterval(() => {
fetch("", {
method: "POST",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: "heartbeat=1"
});
}, 30000);
</script>


<script>window.onload = () => {
    const params = new URLSearchParams(window.location.search);
    if (params.get('user') !== 'alcea') {
        if (!params.has('user')) {
            params.set('user', 'alcea');
            window.location.search = params.toString();  // Reload with 'user=alcea'
        } else {
            window.location.reload();  // If 'user' exists but is incorrect, reload
        }
    }
};

</script>

<iframe src="lastshorthands.html" id="iframe" width="600" height="100"></iframe> <br><hr>
    <script src="/other/extra/scripts/libraries/crypto-js.min.js"></script>
<script>
    window.addEventListener('message', (event) => {
        if (event.origin !== window.location.origin) {
            return; // Ensure the message is from the same origin
        }
        if (event.data.type === 'shorthandSelected') {
            // Append the selected shorthand to the textarea
            const textbox = document.getElementById('textbox');
            textbox.value += event.data.shorthand + " ";
        }
    });
    document.getElementById('parentBtn').addEventListener('click', () => {
        const iframe = document.getElementById('iframe');
        iframe.contentWindow.postMessage({
            type: 'changeBackgroundColor',
            color: 'lightgreen'
        }, '*');
    });
</script>
    <script>
        function pasteCharacter() {
            const textbox = document.getElementById('textbox');
            const cursorPos = textbox.selectionStart;
            textbox.value = textbox.value.slice(0, cursorPos) + '𒐫' + textbox.value.slice(cursorPos);
            textbox.selectionStart = textbox.selectionEnd = cursorPos + 1;
        }
    </script>
    <button onclick="pasteCharacter()">QUOTE</button>
&nbsp;<button onclick="const url=document.getElementById('urlInput').value.trim();if(url && new RegExp('^(https?|ftp)://').test(url))document.getElementById('textbox').value='💬'+url+'💬 \n•acws #acws\n'+document.getElementById('textbox').value;else alert('Invalid Fediverse Post URL')">💬</button><input id="urlInput" style="border:none;width:250px;padding:5px" placeholder="Enter URL"/>
<br>
<a href="#" id="pasteLink">#CurrListeningAlcea</a>
<script>document.getElementById('pasteLink').addEventListener('click', e => { e.preventDefault(); const t = document.getElementById('textbox'), p = t.selectionStart; t.value = t.value.slice(0, p) + '#CurrListeningAlcea' + t.value.slice(p); t.selectionStart = t.selectionEnd = p + '#CurrListeningAlcea'.length; });</script>
<!-- [<a target="_blank" href="https://alceawis.com/updatejson.php" style=color:lightpink>updt</a>]-->

<br>
<?php
error_reporting(0);
?>
<script src="/jquery.min.js"></script>
<style>.hidden-image {display: none;}</style>
<input type="text" id="imageKeyword" placeholder="Enter image keyword">
<script>
document.addEventListener("DOMContentLoaded", function() {
// Get all the images on the page
var images = document.getElementsByTagName("img");
function handleKeywordChange() {
var keyword = document.getElementById('imageKeyword').value.toLowerCase();
for (var i = 0; i < images.length; i++) {
var img = images[i];
var imgUrl = img.getAttribute("src");
if (imgUrl && imgUrl.toLowerCase().includes(keyword)) {
img.classList.remove("hidden-image");
} else {
img.classList.add("hidden-image");}}}
document.getElementById('imageKeyword').addEventListener('input', handleKeywordChange);
handleKeywordChange();
});
</script><hr>
<!----FetchEmoji--->
<?php
if (isset($_POST['button_pressed'])) {
    $url = "https://alcea-wisteria.de/z_files/emoji/";
    $html = file_get_contents($url);
    preg_match_all('/<a href=[\'"](.*?\.gif)[\'"]/i', $html, $matches);
    $gifUrls = $matches[1];
    $gridSize = 35; // Number of columns in the grid
    $count = 0;
    echo "<table>";
    echo "<tr>";
    foreach ($gifUrls as $gifUrl) {
        $filename = basename($gifUrl);
        echo '<td><a href="javascript:void(0);" onclick="insertEmoji(\'' . $filename . '\');"><img src="https://alcea-wisteria.de/z_files/emoji/' . $filename . '" width=30></a></td>';
        $count++;
        if ($count % $gridSize == 0) {
            echo "</tr><tr>";
        }
    }
    echo "</tr>";
    echo "</table>";
}
?>
<form method="post">
    <input type="submit" name="button_pressed" value="LoadEmoji">
</form>
<script>
function insertEmoji(emoji) {
    var textarea = document.getElementById('textbox');
    textarea.value += ':' + emoji.split('.')[0] + ': ';
}
</script>
<button id="writeBtn" style="background-color: white; border: 1px solid black; padding: 1px 20px; font-size: 16px; cursor: pointer;">💾WRITE</button>
<button id="readBtn" style="background-color: white; border: 1px solid black; padding: 1px 20px; font-size: 16px; cursor: pointer;">📥READ</button>


<!--<a href="#" id="loadDataLink">Load</a>
<input type="number" id="entryNumber" min="1" value="1" style="width: 40px; margin-left: 5px;">|
<a href="#" id="submitEditLink">Submit Edit</a>
 <a target="_blank" href="https://mas.to/search?q=%40alceawis%40alceawis.com&type=accounts" style=color:lightpink>check</a>
<textarea id="originalTextbox" style="display:none;"></textarea>
<script>
function loadEntryByReversedNumber(entryNum) {
    fetch('/other/extra/scripts/fakesocialmedia/data_alcea.json', { cache: 'no-cache' })
      .then(response => response.json())
      .then(data => {
        const reversedIndex = data.length - entryNum;

        if (reversedIndex < 0 || reversedIndex >= data.length) {
          alert('Entry number exceeds data length');
          return;
        }

        const entry = data[reversedIndex];
        const innerKey = Object.keys(entry)[0];
        const value = entry[innerKey].value;

        document.getElementById('textbox').value = value;
        document.getElementById('originalTextbox').value = value;
      })
      .catch(error => {
        console.error('Error loading data:', error);
      });
  }

  // Handle Load click
  document.getElementById('loadDataLink').addEventListener('click', function(e) {
    e.preventDefault();
    const userEntry = parseInt(document.getElementById('entryNumber').value, 10);

    if (userEntry < 1) {
      alert('Please enter a number 1 or greater');
      return;
    }

    loadEntryByReversedNumber(userEntry);
  });

  // Handle Submit Edit
  document.getElementById('submitEditLink').addEventListener('click', function(e) {
    e.preventDefault();
    const newText = document.getElementById('textbox').value;
    const originalText = document.getElementById('originalTextbox').value;
    const params = new URLSearchParams({
      new: newText,
      original: originalText
    });
    window.location.href = 'edit.php?' + params.toString();
  });

  // Prefill entryNumber with the last entry number on page load (reversed numbering)
  window.addEventListener('DOMContentLoaded', function() {
    fetch('/other/extra/scripts/fakesocialmedia/data_alcea.json', { cache: 'no-cache' })
      .then(response => response.json())
      .then(data => {
        document.getElementById('entryNumber').value = data.length;
      })
      .catch(error => {
        console.error('Error preloading entry number:', error);
      });
  });
</script>-->








<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["specificButton"])) {
    $value = $_POST["textbox"];
    $user = $_GET["user"];
    $date = date("Ymd");
    $newData = array($date => array("value" => $value));
    $hashtags = array();
    preg_match_all('/#(\w+)/', $value, $matches);
    if (!empty($matches[1])) {
        $hashtags = $matches[1];
    }
    if (!empty($hashtags)) {
        $newData[$date]["hashtags"] = implode(", ", $hashtags);
    }

    $fullFilename = "data_" . $user . ".json";
    $partFilename = "data_" . $user . ".json";

    // Save all data to data_$user.json
    if (file_exists($fullFilename)) {
        $existingData = json_decode(file_get_contents($fullFilename), true);
    } else {
        $existingData = array();
    }
    array_unshift($existingData, $newData);
    file_put_contents($fullFilename, json_encode($existingData, JSON_PRETTY_PRINT));

    // Overwrite data_part_$user.json with the latest 60 entries
    $partialData = array($newData);
    if (file_exists($fullFilename)) {
        $fullData = json_decode(file_get_contents($fullFilename), true);
        $partialData = array_slice($fullData, 0, 60);
    }
    //file_put_contents($partFilename, json_encode($partialData, JSON_PRETTY_PRINT));
}
?>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"] . "?user=" . $_GET["user"]; ?>">
    <textarea id="textbox" name="textbox" rows="4" cols="50"></textarea>
    <input type="submit" name="specificButton" value="Submit">
</form>



<!----Text-Clip--handler--->
    <script> document.getElementById('writeBtn').addEventListener('click', function () {
            const text = document.getElementById('textbox').value;
            fetch('clip.php', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: 'send=' + encodeURIComponent(text)
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error('Write failed');
                }
                console.log('Text saved successfully');
            })
            .catch(error => console.error(error));
        }); document.getElementById('readBtn').addEventListener('click', function () {
            fetch('clip.txt', { cache: 'no-cache' })
                .then(response => response.text())
                .then(data => {
                    document.getElementById('textbox').value = data;
                });
        });
    </script>


<!--------------Info----------->
    <br>
      <!-- <button type="submit" name="specificButton">save</button>-->
</form>
<!--<a target="_blank" href="post2mtd.html" style=color:blue>Post2Mtd</a> <a target="_blank" href="https://alcea-wisteria.de/PHP//0demo/2023-08-15-JSFiddle-Clone/htmls/2023-11-04-Advanced-mtd-tl-renderer-w-Query-string-support.html?instance=mas.to&userid=111958546062297646" style=color:blue>TimeLine</a>
<a target="_blank" href="https://mas.to/@arusea.rss" style=color:blue>RSS</a> [<a target="_blank" href="https://alceawis.de/other/extra/scripts/fakesocialmedia/post.php?user=alcea&mode=lowbandwidth" style=color:blue>Lowbandwidth</a>]<a target="_blank" href="del.php?user=alcea" style=color:blue>del</a>-->
<?php
$user = $_GET['user'];
$uniqueId = uniqid();
$iframeSrc = "data_{$user}.json?v={$uniqueId}";
echo '<iframe src="' . $iframeSrc . '" style="border:0px #ffffff none;" name="statusit" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="250px" width="800" allowfullscreen></iframe>';
?>
<br><iframe src="
/other/extra/scripts/fakesocialmedia/check.php
" style="border:0px #ffffff none;" name="statusit" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="25px" width="100%" allowfullscreen></iframe>
<!--<iframe src="
/fakesocialrender_limited.html?user=alcea
" style="border:0px #ffffff none;" name="statusit" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="6000px" width="100%" allowfullscreen></iframe>-->




<!--
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var baseUrl = "/fakesocialrender_limited.html";
$("#mtdcomm").load(baseUrl + "");
});
</script>
<div class="formClass">
<div id="mtdcomm">
</div>
</div>-->


