123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <?php
- // SSB - Simple Social Board
- // (C) Chris Dorman, 2012 - 2020
- // License: CC-BY-NC-SA version 3.0
- // http://github.com/Pentium44/SSB
- // get filesize for uploaded files
- session_start();
- function tomb($size, $precision = 2)
- {
- $base = log($size) / log(1024);
- $suffixes = array('', 'KB', 'MB', 'GB', 'TB');
- return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
- }
- function getRandString($n) {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
- $randomString = '';
-
- for ($i = 0; $i < $n; $i++) {
- $index = rand(0, strlen($characters) - 1);
- $randomString .= $characters[$index];
- }
-
- return $randomString;
- }
- function searchForUserTag($str) {
- if(preg_match("/\s*@(.+?)\s/", $str, $matches)) {
- return $matches["0"];
- } else {
- return false;
- }
- }
- function checkLogin() {
- $username = $_SESSION['ssb-user'];
- $passSession = $_SESSION['ssb-pass'];
- if(!isset($username) || !isset($passSession)) { return false; }
- include "ssb_db/users/" . $username . ".php";
-
- if($user_password === $passSession) {
- return true;
- } else {
- return false;
- }
- }
- function loginForm() {
- ?>
- <br />
- <div class="login">
- <h3>Login</h3>
- New to <?php echo $ssbtitle; ?>? No problem,
- <a href="<?php echo $_SERVER['PHP_SELF']; ?>?forms=register">register</a>
- here and get started!<br /><br />
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=login" method="post">
- <table><tr><td>
- Username:</td><td> <input class="text" type="text" name="username"></td></tr><tr><td>
- Password:</td><td> <input class="text" type="password" name="password"></td></tr></table>
- <input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Login">
- </form>
- </div>
- <?php
- }
- function changePassForm() {
- ?>
- <br />
- <div class="chgpass">
- <h3>Change password</h3>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=changepass" method="post">
- <table><tr><td>
- Old password:</td><td> <input class="text" type="password" name="oldpass"></td></tr><tr><td>
- Password:</td><td> <input class="text" type="password" name="password"></td></tr><tr><td>
- Password Again:</td><td> <input class="text" type="password" name="password_again"></td></tr>
- </table>
- <input class="text" type="submit" name="submitBtn" value="Change">
- </form>
- </div>
- <?php
- }
- function getUserCount() {
- $user_count = "0";
- foreach(array_reverse(glob("ssb_db/users/*.name")) as $postfile) {
- $user_count++;
- }
-
- echo "$user_count users";
- }
- function getPostCount() {
- $post_count = "0";
- foreach(array_reverse(glob("ssb_db/posts/*.post")) as $postfile) {
- $post_count++;
- }
-
- echo "$post_count posts";
- }
- function getUploadFileCount() {
- $file_count = "0";
- foreach(array_reverse(glob("ssb_db/uploads/*")) as $postfile) {
- $file_count++;
- }
-
- echo "$file_count uploads";
- }
- function uploadAvatarForm() {
- ?>
- <br />
- <div class="upload">
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=avatarupload" method="post" enctype="multipart/form-data">
- Choose profile avatar: <br />
- <label class="input-upload">
- <input type="file" name="file[]" id="file" multiple>
- <i class="fa fa-cloud-upload"></i> Upload image
- </label>
- <input class="text" type="submit" name="submit" value="Set">
- </form>
- </div>
- <?php
- }
- /*function uploadForm() {
- print <<<EOD
- Upload
- <table style="margin:auto;">
-
- <form action="upload.php" method="post" enctype="multipart/form-data">
- <tr>
- <td>
- <input type="file" name="file[]" id="file" multiple><br>
- </td>
- <td>
- <input type="submit" name="submit" value="Upload">
- </td>
- </tr>
- </form>
-
- </table>
- EOD;
- }*/
- function registerForm() {
- ?>
- <br />
- <div class="login">
- <h3>Register</h3>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=register" method="post">
- <table><tr><td>
- Username:</td><td> <input class="text" type="text" name="username"></td></tr><tr><td>
- Full name:</td><td> <input class="text" type="text" name="fullname"></td></tr><tr><td>
- Password:</td><td> <input class="text" type="password" name="password"></td></tr><tr><td>
- Password Again:</td><td> <input class="text" type="password" name="password-again"></td></tr><tr><td>
- <label for="acct">Profile type:</label>
- <select id="acct" name="acct">
- <option value="private">Private</option>
- <option value="public">Public</option>
- </select></td><td>
- <input class="text" type="submit" name="submitBtn" value="Register">
- </td></tr></table>
- </form>
- </div>
- <?php
- }
- function postForm() {
- print <<<EOD
- <h3>Create a post</h3>
- <button onclick="javascript:wrapBBCode('i');">Italic</button>
- <button onclick="javascript:wrapBBCode('u');">Underline</button>
- <button onclick="javascript:wrapBBCode('b');">Bold</button>
- <button onclick="javascript:wrapBBCode('url');">URL</button>
- <button onclick="javascript:wrapBBCode('youtube');">Youtube</button>
- <form action="?do=post" method="post" enctype="multipart/form-data">
- <label class="input-upload">
- <input type="file" name="file[]" id="file" multiple>
- <i class="fa fa-cloud-upload"></i> Upload photo / video
- </label>
- <br /><textarea rows="5" cols="60" id="msg" name="body"></textarea><br />
- <input type="submit" name="post" value="Post">
- </form>
- EOD;
- }
- function replyForm($id, $puser) {
- ?>
- <button onclick="javascript:wrapBBCode('i');">Italic</button>
- <button onclick="javascript:wrapBBCode('u');">Underline</button>
- <button onclick="javascript:wrapBBCode('b');">Bold</button>
- <button onclick="javascript:wrapBBCode('url');">URL</button>
- <button onclick="javascript:wrapBBCode('youtube');">Youtube</button>
- <form action="?do=reply&pid=<?php echo $id; ?>&user=<?php echo $puser; ?>" method="post">
- <textarea rows="7" cols="60" id="msg" name="body"></textarea><br />
- <input type="submit" name="reply" value="Reply">
- </form>
- <?php
- }
- function cleanForm() {
- ?>
- <br />
- <form action="?do=clean" method="post">
- Password: <input type="password" name="password" id="password"> <br />
- <input type="submit" name="post" value="Post">
- </form>
- <?php
- }
- function friendReqForm() {
- ?>
- <h3>Send a friend request</h3>
- <form action="?do=sendfr" method="post">
- Username: <input type="text" name="user" id="user"> <br />
- <input type="submit" name="post" value="Send">
- </form>
- <?php
- }
- function sendFriendRequest($user, $friend) {
- $friendLocation = "ssb_db/friends/" . $friend . ".notifications";
- $friendPending = "ssb_db/friends/" . $friend . ".pending";
- $handle = file_get_contents($friendLocation);
- if (strpos($handle, $user) !== FALSE) {
- echo "Friend request is send already and pending accept!<br />";
- exit(1);
- }
-
- // Check if user is itself
- if($user == $friend) { header("Location: index.php?do=friends"); exit(1); } // dont request from self.
-
- $friendc = file_get_contents("ssb_db/friends/" . $user . ".count");
- $friendcount = file_get_contents("ssb_db/friends/" . $user . ".count");
- include "ssb_db/friends/" . $user . ".php";
- for($x = 1; $x <= $friendcount; $x++)
- {
- if(${"friend" . $x} == $friend) { header("Location: index.php?do=friends"); echo "Already following!"; exit(1); }
- }
-
- if(file_exists($friendLocation)) {
- $notifications = file_get_contents($friendLocation);
- file_put_contents("ssb_db/friends/" . $friend . ".notifications", "Friend request from " . $user . "! <a class='button' href='?do=accfr&friend=" . $user . "&user=" . $friend . "'>Accept?</a>" . "\n" . $notifications);
- } else {
- file_put_contents("ssb_db/friends/" . $friend . ".notifications", "Friend request from " . $user . "! <a class='button' href='?do=accfr&friend=" . $user . "&user=" . $friend . "'>Accept?</a>");
- }
-
- if(file_exists($friendPending)) {
- $pending = file_get_contents($friendPending);
- file_put_contents("ssb_db/friends/" . $friend . ".pending", $user . "\n" . $pending);
- } else {
- file_put_contents("ssb_db/friends/" . $friend . ".pending", $user);
- }
- }
- function acceptPublicFriendRequest($user, $friend) {
- $friendpending = "ssb_db/friends/" . $user . ".pending";
- $friendlist = file_get_contents("ssb_db/friends/" . $user . ".php");
- $frienddb = file_get_contents("ssb_db/friends/" . $friend . ".php");
- // check if already on friends list.
- $friendc = file_get_contents("ssb_db/friends/" . $user . ".count");
- $friendcount = file_get_contents("ssb_db/friends/" . $user . ".count");
- include "ssb_db/friends/" . $user . ".php";
- for($x = 1; $x <= $friendcount; $x++)
- {
- if(${"friend" . $x} == $friend) { echo "Already following!"; exit(1); }
- }
- // populate both users databases with each other.
- $friendcountFriend = file_get_contents("ssb_db/friends/" . $friend . ".count");
- $friendcountFriend = $friendcountFriend + 1;
- //echo $friendcountFriend;
- file_put_contents("ssb_db/friends/" . $friend . ".php", $frienddb . "\n <?php \$friend" . $friendcountFriend ." = \"" . $user . "\";\n\$friend_chat_db" . $friendcountFriend . " = \"" . $user . $friend . "\";?>");
- $friendcount = file_get_contents("ssb_db/friends/" . $user . ".count");
- $friendcount = $friendcount + 1;
- //echo $friendcount;
- file_put_contents("ssb_db/friends/" . $user . ".php", $friendlist . "\n <?php \$friend" . $friendcount . " = \"" . $friend . "\";\n\$friend_chat_db" . $friendcount . " = \"" . $user . $friend . "\";?>");
- file_put_contents("ssb_db/friends/" . $user . ".count", $friendcount);
- file_put_contents("ssb_db/friends/" . $friend . ".count", $friendcountFriend);
- file_put_contents("ssb_db/friends/" . $user . $friend . ".count", "1");
- file_put_contents("ssb_db/friends/" . $user . $friend . ".php", "<?php \$msg1 = \"" . $user . " and " . $friend . " are now friends!<br />\";?>");
- }
- function acceptFriendRequest($user, $friend) {
- $friendpending = "ssb_db/friends/" . $user . ".pending";
- $friendlist = file_get_contents("ssb_db/friends/" . $user . ".php");
- $frienddb = file_get_contents("ssb_db/friends/" . $friend . ".php");
- // check if friend request is really pending.
- $friendc = file_get_contents("ssb_db/friends/" . $user . ".count");
- include "ssb_db/friends/" . $user . ".php";
- for($x = 1; $x <= $friendc; $x++)
- {
- if(${"friend" . $x} == $friend) { echo "Already following!"; exit(1); }
- }
- $handle = fopen($friendpending, "r");
- if ($handle) {
- $xx = 0;
- while (($line = fgets($handle)) !== false) {
- if($xx >= "1") {
- $line = str_replace("\n","",$line);
- }
- $xx++;
- //echo $line . "<br />";
- //echo $friend . "<br />";
- if($friend == $line)
- {
- // populate both users databases with each other.
- $friendcountFriend = file_get_contents("ssb_db/friends/" . $friend . ".count");
- $friendcountFriend = $friendcountFriend + 1;
- //echo $friendcountFriend;
- file_put_contents("ssb_db/friends/" . $friend . ".php", $frienddb . "\n <?php \$friend" . $friendcountFriend ." = \"" . $user . "\";\n\$friend_chat_db" . $friendcountFriend . " = \"" . $user . $friend . "\";?>");
- $friendcount = file_get_contents("ssb_db/friends/" . $user . ".count");
- $friendcount = $friendcount + 1;
- //echo $friendcount;
- file_put_contents("ssb_db/friends/" . $user . ".php", $friendlist . "\n <?php \$friend" . $friendcount . " = \"" . $friend . "\";\n\$friend_chat_db" . $friendcount . " = \"" . $user . $friend . "\";?>");
- file_put_contents("ssb_db/friends/" . $user . ".count", $friendcount);
- file_put_contents("ssb_db/friends/" . $friend . ".count", $friendcountFriend);
- file_put_contents("ssb_db/friends/" . $user . $friend . ".count", "1");
- file_put_contents("ssb_db/friends/" . $user . $friend . ".php", "<?php \$msg1 = \"" . $user . " and " . $friend . " are now friends!<br />\";?>");
- }
- }
- fclose($handle);
- } else {
- echo "ERROR: Friend: " . $friend . " not found in friend pending database.<br />";
- }
- }
- ?>
|