forms.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. // SSB - Simple Social Board
  3. // (C) Chris Dorman, 2012 - 2020
  4. // License: CC-BY-NC-SA version 3.0
  5. // http://github.com/Pentium44/SSB
  6. // get filesize for uploaded files
  7. function tomb($size, $precision = 2)
  8. {
  9. $base = log($size) / log(1024);
  10. $suffixes = array('', 'KB', 'MB', 'GB', 'TB');
  11. return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
  12. }
  13. function loginForm() {
  14. ?>
  15. <br />
  16. <div class="login">
  17. <a class="button" href="<?php echo $_SERVER['PHP_SELF']; ?>?forms=register">Register</a>
  18. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=login" method="post">
  19. <table><tr><td>
  20. Username:</td><td> <input class="text" type="text" name="username"></td></tr><tr><td>
  21. Password:</td><td> <input class="text" type="password" name="password"></td></tr></table>
  22. <input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Login">
  23. </form>
  24. </div>
  25. <?php
  26. }
  27. function changePassForm() {
  28. ?>
  29. <br />
  30. <div class="chgpass">
  31. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=changepass" method="post">
  32. <table><tr><td>
  33. Old password:</td><td> <input class="text" type="password" name="oldpass"></td></tr><tr><td>
  34. Password:</td><td> <input class="text" type="password" name="password"></td></tr><tr><td>
  35. Password Again:</td><td> <input class="text" type="password" name="password_again"></td></tr>
  36. </table>
  37. <input class="text" type="submit" name="submitBtn" value="Change">
  38. </form>
  39. </div>
  40. <?php
  41. }
  42. function uploadAvatarForm() {
  43. ?>
  44. <br />
  45. <div class="upload">
  46. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=avatarupload" method="post" enctype="multipart/form-data">
  47. Choose profile avatar: <br />
  48. <label class="input-upload">
  49. <input type="file" name="file[]" id="file" multiple>
  50. <i class="fa fa-cloud-upload"></i> Upload image
  51. </label>
  52. <input class="text" type="submit" name="submit" value="Set">
  53. </form>
  54. </div>
  55. <?php
  56. }
  57. /*function uploadForm() {
  58. print <<<EOD
  59. Upload
  60. <table style="margin:auto;">
  61. <form action="upload.php" method="post" enctype="multipart/form-data">
  62. <tr>
  63. <td>
  64. <input type="file" name="file[]" id="file" multiple><br>
  65. </td>
  66. <td>
  67. <input type="submit" name="submit" value="Upload">
  68. </td>
  69. </tr>
  70. </form>
  71. </table>
  72. EOD;
  73. }*/
  74. function registerForm() {
  75. ?>
  76. <br />
  77. <div class="login">
  78. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=register" method="post">
  79. <table><tr><td>
  80. Username:</td><td> <input class="text" type="text" name="username"></td></tr><tr><td>
  81. Full name:</td><td> <input class="text" type="text" name="fullname"></td></tr><tr><td>
  82. Password:</td><td> <input class="text" type="password" name="password"></td></tr><tr><td>
  83. Password Again:</td><td> <input class="text" type="password" name="password-again"></td></tr><tr><td>
  84. <label for="acct">Profile type:</label>
  85. <select id="acct" name="acct">
  86. <option value="private">Private</option>
  87. <option value="public">Public</option>
  88. </select></td><td>
  89. <input class="text" type="submit" name="submitBtn" value="Register">
  90. </td></tr></table>
  91. </form>
  92. </div>
  93. <?php
  94. }
  95. function postForm() {
  96. print <<<EOD
  97. <button onclick="javascript:wrapBBCode('i');">Italic</button>
  98. <button onclick="javascript:wrapBBCode('u');">Underline</button>
  99. <button onclick="javascript:wrapBBCode('b');">Bold</button>
  100. <button onclick="javascript:wrapBBCode('url');">URL</button>
  101. <form action="?do=post" method="post" enctype="multipart/form-data">
  102. <label class="input-upload">
  103. <input type="file" name="file[]" id="file" multiple>
  104. <i class="fa fa-cloud-upload"></i> Upload image
  105. </label>
  106. <br /><textarea rows="5" cols="60" id="msg" name="body"></textarea><br />
  107. <input type="submit" name="post" value="Post">
  108. </form>
  109. EOD;
  110. }
  111. function replyForm($id, $puser) {
  112. ?>
  113. <button onclick="javascript:wrapBBCode('i');">Italic</button>
  114. <button onclick="javascript:wrapBBCode('u');">Underline</button>
  115. <button onclick="javascript:wrapBBCode('b');">Bold</button>
  116. <button onclick="javascript:wrapBBCode('url');">URL</button>
  117. <form action="?do=reply&pid=<?php echo $id; ?>&user=<?php echo $puser; ?>" method="post">
  118. <textarea rows="7" cols="60" id="msg" name="body">Reply</textarea><br />
  119. <input type="submit" name="reply" value="Reply">
  120. </form>
  121. <?php
  122. }
  123. function cleanForm() {
  124. ?>
  125. <br />
  126. <form action="?do=clean" method="post">
  127. Password: <input type="password" name="password" id="password"> <br />
  128. <input type="submit" name="post" value="Post">
  129. </form>
  130. <?php
  131. }
  132. function friendReqForm() {
  133. ?>
  134. <h2>Request friendship!</h2>
  135. <form action="?do=sendfr" method="post">
  136. Username: <input type="text" name="user" id="user"> <br />
  137. <input type="submit" name="post" value="Send">
  138. </form>
  139. <?php
  140. }
  141. function sendFriendRequest($user, $friend) {
  142. $friendLocation = "ssb_db/friends/" . $friend . ".pending";
  143. $handle = fopen($friendLocation, "r");
  144. if ($handle) {
  145. while (($line = fgets($handle)) !== false) {
  146. if($line == $user) { break; } // request already pending
  147. }
  148. fclose($handle);
  149. }
  150. // Check if user is itself
  151. if($user == $friend) { header("Location: index.php?do=friends"); exit(1); } // dont request from self.
  152. $friendc = file_get_contents("ssb_db/friends/" . $user . ".count");
  153. $friendcount = file_get_contents("ssb_db/friends/" . $user . ".count");
  154. include "ssb_db/friends/" . $user . ".php";
  155. for($x = 1; $x <= $friendcount; $x++)
  156. {
  157. if(${"friend" . $x} == $friend) { header("Location: index.php?do=friends"); echo "Already following!"; exit(1); }
  158. }
  159. if(file_exists($friendLocation)) {
  160. $pending = file_get_contents("ssb_db/friends/" . $friend . ".pending");
  161. file_put_contents("ssb_db/friends/" . $friend . ".pending", $pending . "\n" . $user);
  162. } else {
  163. file_put_contents("ssb_db/friends/" . $friend . ".pending", $user);
  164. }
  165. }
  166. function acceptPublicFriendRequest($user, $friend) {
  167. $friendpending = "ssb_db/friends/" . $user . ".pending";
  168. $friendlist = file_get_contents("ssb_db/friends/" . $user . ".php");
  169. $frienddb = file_get_contents("ssb_db/friends/" . $friend . ".php");
  170. // check if already on friends list.
  171. $friendc = file_get_contents("ssb_db/friends/" . $user . ".count");
  172. $friendcount = file_get_contents("ssb_db/friends/" . $user . ".count");
  173. include "ssb_db/friends/" . $user . ".php";
  174. for($x = 1; $x <= $friendcount; $x++)
  175. {
  176. if(${"friend" . $x} == $friend) { echo "Already following!"; exit(1); }
  177. }
  178. // populate both users databases with each other.
  179. $friendcountFriend = file_get_contents("ssb_db/friends/" . $friend . ".count");
  180. $friendcountFriend = $friendcountFriend + 1;
  181. //echo $friendcountFriend;
  182. file_put_contents("ssb_db/friends/" . $friend . ".php", $frienddb . "\n <?php \$friend" . $friendcountFriend ." = \"" . $user . "\";\n\$friend_chat_db" . $friendcountFriend . " = \"" . $user . $friend . "\";?>");
  183. $friendcount = file_get_contents("ssb_db/friends/" . $user . ".count");
  184. $friendcount = $friendcount + 1;
  185. //echo $friendcount;
  186. file_put_contents("ssb_db/friends/" . $user . ".php", $friendlist . "\n <?php \$friend" . $friendcount . " = \"" . $friend . "\";\n\$friend_chat_db" . $friendcount . " = \"" . $user . $friend . "\";?>");
  187. file_put_contents("ssb_db/friends/" . $user . ".count", $friendcount);
  188. file_put_contents("ssb_db/friends/" . $friend . ".count", $friendcountFriend);
  189. file_put_contents("ssb_db/friends/" . $user . $friend . ".count", "1");
  190. file_put_contents("ssb_db/friends/" . $user . $friend . ".php", "<?php \$msg1 = \"" . $user . " and " . $friend . " are now friends!<br />\";?>");
  191. }
  192. function acceptFriendRequest($user, $friend) {
  193. $friendpending = "ssb_db/friends/" . $user . ".pending";
  194. $friendlist = file_get_contents("ssb_db/friends/" . $user . ".php");
  195. $frienddb = file_get_contents("ssb_db/friends/" . $friend . ".php");
  196. // check if friend request is really pending.
  197. $friendc = file_get_contents("ssb_db/friends/" . $user . ".count");
  198. include "ssb_db/friends/" . $user . ".php";
  199. for($x = 1; $x <= $friendc; $x++)
  200. {
  201. if(${"friend" . $x} == $friend) { echo "Already following!"; exit(1); }
  202. }
  203. $handle = fopen($friendpending, "r");
  204. if ($handle) {
  205. $xx = 0;
  206. while (($line = fgets($handle)) !== false) {
  207. if($xx >= "1") {
  208. $line = str_replace("\n","",$line);
  209. }
  210. $xx++;
  211. //echo $line . "<br />";
  212. //echo $friend . "<br />";
  213. if($friend == $line)
  214. {
  215. // populate both users databases with each other.
  216. $friendcountFriend = file_get_contents("ssb_db/friends/" . $friend . ".count");
  217. $friendcountFriend = $friendcountFriend + 1;
  218. //echo $friendcountFriend;
  219. file_put_contents("ssb_db/friends/" . $friend . ".php", $frienddb . "\n <?php \$friend" . $friendcountFriend ." = \"" . $user . "\";\n\$friend_chat_db" . $friendcountFriend . " = \"" . $user . $friend . "\";?>");
  220. $friendcount = file_get_contents("ssb_db/friends/" . $user . ".count");
  221. $friendcount = $friendcount + 1;
  222. //echo $friendcount;
  223. file_put_contents("ssb_db/friends/" . $user . ".php", $friendlist . "\n <?php \$friend" . $friendcount . " = \"" . $friend . "\";\n\$friend_chat_db" . $friendcount . " = \"" . $user . $friend . "\";?>");
  224. file_put_contents("ssb_db/friends/" . $user . ".count", $friendcount);
  225. file_put_contents("ssb_db/friends/" . $friend . ".count", $friendcountFriend);
  226. file_put_contents("ssb_db/friends/" . $user . $friend . ".count", "1");
  227. file_put_contents("ssb_db/friends/" . $user . $friend . ".php", "<?php \$msg1 = \"" . $user . " and " . $friend . " are now friends!<br />\";?>");
  228. }
  229. }
  230. fclose($handle);
  231. } else {
  232. echo "ERROR: Friend: " . $friend . " not found in friend pending database.<br />";
  233. }
  234. }
  235. ?>