diff options
author | Minteck <contact@minteck.org> | 2022-05-22 18:16:34 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-05-22 18:16:34 +0200 |
commit | bc4d21ddbc50a4295ad1be0f4797b09895a65fea (patch) | |
tree | f915c08fba577daf766628657558ce480790b06f /profile | |
download | multisocial-mane.tar.gz multisocial-mane.tar.bz2 multisocial-mane.zip |
Diffstat (limited to 'profile')
-rw-r--r-- | profile/index.php | 300 |
1 files changed, 300 insertions, 0 deletions
diff --git a/profile/index.php b/profile/index.php new file mode 100644 index 0000000..d1c8469 --- /dev/null +++ b/profile/index.php @@ -0,0 +1,300 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $_PROFILE; global $_AUTH; + +if (!isset($_GET['_'])) { + if ($_PROFILE['mmsp_username'] === "system") { + header("Location: /") and die(); + } else { + header("Location: ?_=" . $_PROFILE['mmsp_username']) and die(); + } +} else { + $search = preg_replace("/\.+/mi", ".", preg_replace("/[^a-z\d]+/mi", ".", substr(str_replace("\"", "''", strip_tags($_GET['_'])), 0, 30))); + if ($search === ".") header("Location: /profile") and die; + if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/" . $search) || $search === "system" || $search === "users.json" || str_contains($search, "multisocial")) header("Location: /profile") and die; +} + +if ($_PROFILE['mmsp_username'] !== "system") { + if (isset($_POST['post']) && $_POST['post'] === "1" && !isset($_POST['edit'])) { + if (isset($_POST['post-member']) && is_string($_POST['post-member']) && isset($_POST['post-text']) && is_string($_POST['post-text'])) { + $plurality = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/" . $_PROFILE['mmsp_username'] . "/settings/plurality.json"), true); + $date = date('c'); + $author = $plurality['members'][0]; + foreach ($plurality['members'] as $member) { + if ($member['name'] === $_POST['post-member']) { + $author = $member; + } + } + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/" . $_PROFILE['mmsp_username'] . "/posts/" . $date . ".json", json_encode([ + 'author' => $author, + 'contents' => substr($_POST['post-text'], 0, 500), + 'date' => $date, + 'image' => null, + 'audio' => null, + 'comments' => [], + 'edits' => [] + ])); + } + header("Location: /profile") and die(); + } else if (isset($_POST['post']) && $_POST['post'] === "1" && isset($_POST['edit']) && $_POST['edit'] === "1" && isset($_POST['edit-post'])) { + $posts = array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/data/" . $_PROFILE['mmsp_username'] . "/posts"), function ($item) { + return str_ends_with($item, ".json"); + }); + + if (!in_array($_POST['edit-post'] . ".json", $posts)) header("Location: /profile") and die(); + $id = $_POST['edit-post']; + $post = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/" . $_PROFILE['mmsp_username'] . "/posts/" . $id . ".json"), true); + + $plurality = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/" . $_PROFILE['mmsp_username'] . "/settings/plurality.json"), true); + $date = date('c'); + $author = $plurality['members'][0]; + foreach ($plurality['members'] as $member) { + if ($member['name'] === $_POST['post-member']) { + $author = $member; + } + } + + $post['author'] = $author; + $post['contents'] = substr($_POST['post-text'], 0, 500); + $post['edits'][] = [ + "date" => $date, + "before" => $post['contents'] + ]; + + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/" . $_PROFILE['mmsp_username'] . "/posts/" . $id . ".json", json_encode($post)); + + header("Location: /profile") and die(); + } +} + +$plurality = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/" . $search . "/settings/plurality.json"), true); +if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/" . $_PROFILE['mmsp_username'] . "/settings/favorites.json")) { + $favorites = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/" . $_PROFILE['mmsp_username'] . "/settings/favorites.json"), true); +} else { + $favorites = []; +} +$titlec = $plurality['displayname'] . " (@" . $search . ")"; + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/gui/header.app.php"; global $lang; global $Parsedown; + +?> + +<div class="container"> + <br> + <h1><img id="profile-picture" src="<?= $plurality['picture'] ?? '/assets/img/default.png' ?>" alt=""> <span id="profile-name"><?= $plurality['displayname'] ?></span> <?php if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/" . $search . "/verified")): ?><a title="<?= $lang['profile']['verified'] ?>"><img id="profile-verified" src="/assets/icons/profile/verified.svg"></a> + <?php endif; ?> + + <?php if ($search === $_PROFILE['mmsp_username']): ?> + <button type="button" class="btn btn-outline-primary" id="profile-add" data-bs-toggle="modal" data-bs-target="#post"><?= $lang['profile']['post']['button'] ?></button> + <?php endif; ?></h1> + <div class="small text-muted" id="profile-status"> + @<?= $search ?> + · + <?php if ($plurality['plural']): $count = count($plurality['members']); ?> + <?= $count ?> <?= $count > 1 ? $lang['profile']['plural.2'] : $lang['profile']['plural.1'] ?> + <?php foreach ($plurality['members'] as $member): ?> + <a title="<?= $member['name'] ?>"><img class="member-small-pp" src="<?= $member['picture'] ?? '/assets/img/default.png' ?>"></a> + <?php endforeach; ?> + · + <?php endif; + $posts = array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/data/" . $search . "/posts"), function ($item) { + return str_ends_with($item, ".json"); + }); + if (count($posts) === 0) echo($lang['profile']['posts.3']); + if (count($posts) === 1) echo("1 " . $lang['profile']['posts.1']); + if (count($posts) > 1) echo(count($posts) . " " . $lang['profile']['posts.2']); + ?> + </div> + + <br> + + <div id="profile-posts" class="container"> + <?php + $posts = array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/data/" . $search . "/posts"), function ($item) { + return str_ends_with($item, ".json"); + }); + $posts = array_reverse($posts); + foreach ($posts as $file): $post = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/" . $search . "/posts/" . $file), true); $id = substr($file, 0, -5); + ?> + <div class="profile-post card" id="profile-post-<?= $search ?>-<?= substr($file, 0, -5) ?>"> + <div class="card-header"> + <h5><img class="member-small-pp" src="<?= $post['author']['picture'] ?? '/assets/img/default.png' ?>"> <span class="post-author"><?= $post['author']['name'] ?></span></h5> + </div> + <div class="card-body"> + <?php $Parsedown->setSafeMode(true); $Parsedown->setMarkupEscaped(true); echo $Parsedown->line($post['contents']) ?> + </div> + <div class="card-footer"> + <a title="<?= $lang['profile']['comments'] ?>" data-bs-toggle="modal" data-bs-target="#comments" class="comments"> + <img src="/assets/icons/profile/comments.off.svg"> + </a> + <?php if ($_AUTH): ?> + <a onclick="favorite('<?= $search ?>', '<?= $id ?>');" title="<?= $lang['profile']['favorite'] ?>" class="favorite"<?php if (in_array($search . "/" . $id, $favorites)): ?> style="display:none;"<?php endif; ?> id="profile-post-<?= $_PROFILE['mmsp_username'] ?>-<?= substr($file, 0, -5) ?>-favorite"> + <img src="/assets/icons/profile/favorite.off.svg"> + </a> + <a onclick="unfavorite('<?= $search ?>', '<?= $id ?>');" title="<?= $lang['profile']['unfavorite'] ?>" class="unfavorite"<?php if (in_array($search . "/" . $id, $favorites)): ?> style="display:inline;"<?php endif; ?> id="profile-post-<?= $_PROFILE['mmsp_username'] ?>-<?= substr($file, 0, -5) ?>-unfavorite"> + <img src="/assets/icons/profile/favorite.on.svg"> + </a> + <?php endif; ?> + <div class="manage-post"> + <span class="text-muted"><?php if (count($post['edits']) > 0): ?><?= $lang["profile"]["edit"] ?> · <?php endif; ?><?= timeAgo($post['date']) ?><?php if ($search === $_PROFILE['mmsp_username']): ?> · </span><a class="cursor-pointer" onclick="managePost('profile-post-<?= $search ?>-<?= substr($file, 0, -5) ?>');" data-bs-toggle="modal" data-bs-target="#manage"><?= $lang['profile']['manage'] ?></a><?php else: ?></span><?php endif; ?> + </div> + </div> + </div> + <br> + <?php endforeach; ?> + </div> +</div> + +<div class="modal fade" id="post"> + <div class="modal-dialog"> + <div class="modal-content"> + + <div class="modal-header"> + <h4 class="modal-title"><?= $lang['profile']['post']['title'] ?></h4> + <button type="button" class="btn-close" data-bs-dismiss="modal"></button> + </div> + + <div class="modal-body"> + <form action="" method="post"> + <select autocomplete="off" name="post-member" class="form-select"> + <optgroup label="<?= $lang['profile']['post']['system.1'] ?>" style="font-style: normal;"> + <?php foreach ($plurality['members'] as $member): if ($member['fronting']): ?> + <option value="<?= $member['name'] ?>" selected="selected" class="text-primary select-fronter"><?= $member['name'] ?></option> + <?php endif; endforeach; ?> + </optgroup> + <optgroup label="<?= $lang['profile']['post']['system.2'] ?>" style="font-style: normal;"> + <?php foreach ($plurality['members'] as $member): if (!$member['fronting']): ?> + <option value="<?= $member['name'] ?>"><?= $member['name'] ?></option> + <?php endif; endforeach; ?> + </optgroup> + </select><br> + + <textarea maxlength="500" class="form-control" id="post-modal-text" rows="5" name="post-text" placeholder="<?= $lang['profile']['post']['disclaimer'] ?>"></textarea> + + <input type="hidden" name="post" value="1"> + + <br> + <div id="post-modal-actions"> + <input type="submit" value="<?= $lang["profile"]["post"]["done"] ?>" class="btn btn-success"> + <button type="button" class="btn btn-danger" data-bs-dismiss="modal"><?= $lang["profile"]["post"]["cancel"] ?></button> + </div> + </form> + </div> + + </div> + </div> +</div> + +<div class="modal fade" id="manage"> + <div class="modal-dialog"> + <div class="modal-content"> + + <div class="modal-header"> + <h4 class="modal-title"><?= $lang['profile']['tools']['title'] ?></h4> + <button type="button" class="btn-close" data-bs-dismiss="modal"></button> + </div> + + <div class="modal-body"> + <form action="" method="post"> + <select disabled autocomplete="off" name="post-member" class="form-select editor-disable" id="editor-member"> + <optgroup label="Fronters" style="font-style: normal;"> + <?php foreach ($plurality['members'] as $member): if ($member['fronting']): ?> + <option value="<?= $member['name'] ?>" selected="selected" class="text-primary select-fronter"><?= $member['name'] ?></option> + <?php endif; endforeach; ?> + </optgroup> + <optgroup label="Other members" style="font-style: normal;"> + <?php foreach ($plurality['members'] as $member): if (!$member['fronting']): ?> + <option value="<?= $member['name'] ?>"><?= $member['name'] ?></option> + <?php endif; endforeach; ?> + </optgroup> + </select><br> + + <textarea disabled maxlength="500" class="form-control editor-disable" id="editor-text" rows="5" name="post-text" placeholder="<?= $lang['profile']['post']['disclaimer'] ?>"></textarea> + + <input type="hidden" name="post" value="1"> + <input type="hidden" name="edit" value="1"> + <input type="hidden" name="edit-post" value="null"> + + <br> + <div id="post-modal-actions"> + <input disabled type="submit" value="<?= $lang["profile"]["tools"]["done"] ?>" class="btn btn-success editor-disable"> + <button disabled type="button" class="btn btn-secondary editor-disable" data-bs-dismiss="modal"><?= $lang["profile"]["tools"]["delete"] ?></button> + <button type="button" class="btn btn-danger" data-bs-dismiss="modal"><?= $lang["profile"]["post"]["cancel"] ?></button> + </div> + </form> + </div> + + </div> + </div> +</div> + +<div class="modal fade" id="comments"> + <div class="modal-dialog"> + <div class="modal-content"> + + <div class="modal-header"> + <h4 class="modal-title"><?= $lang['profile']['comments-modal']['title'] ?></h4> + <button type="button" class="btn-close" data-bs-dismiss="modal"></button> + </div> + + <div class="modal-body"> + <?= $lang["profile"]["comments-modal"]["load"] ?> + </div> + + </div> + </div> +</div> + +<style> + .select-fronter:after, .select-fronter::after { + content: " (<?= $lang['profile']['post']['fronter'] ?>)"; + display: block; + } +</style> + +<script> + function favorite(user, post) { + requser = encodeURI(user).replaceAll("+", "%2B"); + reqpost = encodeURI(post).replaceAll("+", "%2B"); + + document.getElementById("profile-post-" + user + "-" + post + "-unfavorite").style.display = "initial"; + document.getElementById("profile-post-" + user + "-" + post + "-favorite").style.display = "none"; + window.fetch("/ajax/favorite/?u=" + requser + "&p=" + reqpost + "&s=1").then((a) => { + a.text().then((b) => { + if (b !== "1") { + document.getElementById("profile-post-" + user + "-" + post + "-unfavorite").style.display = "none"; + document.getElementById("profile-post-" + user + "-" + post + "-favorite").style.display = "initial"; + } + }) + }) + } + + function unfavorite(user, post) { + requser = encodeURI(user).replaceAll("+", "%2B"); + reqpost = encodeURI(post).replaceAll("+", "%2B"); + + document.getElementById("profile-post-" + user + "-" + post + "-favorite").style.display = "initial"; + document.getElementById("profile-post-" + user + "-" + post + "-unfavorite").style.display = "none"; + window.fetch("/ajax/favorite/?u=" + requser + "&p=" + reqpost + "&s=0").then((a) => { + a.text().then((b) => { + if (b !== "1") { + document.getElementById("profile-post-" + user + "-" + post + "-favorite").style.display = "none"; + document.getElementById("profile-post-" + user + "-" + post + "-unfavorite").style.display = "initial"; + } + }) + }) + } + + function managePost(post) { + document.getElementById("editor-text").value = ""; + document.getElementById("editor-member").value = document.querySelector("#" + post.replaceAll("+", "\\+").replaceAll(":", "\\:") + " .post-author").innerText; + Array.from(document.getElementsByClassName("editor-disable")).forEach((e) => { e.disabled = true; }); + window.fetch("/ajax/original/?p=" + encodeURI(post.split("-").filter((e, i) => i > 2).join("-")).replaceAll("+", "%2B")).then((a) => { + a.text().then((b) => { + document.getElementById("editor-text").value = b; + document.getElementsByName("edit-post")[0].value = post.split("-").filter((e, i) => i > 2).join("-"); + Array.from(document.getElementsByClassName("editor-disable")).forEach((e) => { e.disabled = false; }); + }) + }) + } +</script>
\ No newline at end of file |