index.php 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  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. //error_reporting(E_ALL);
  7. //ini_set('display_errors', 1);
  8. session_start();
  9. include "config.php";
  10. include "functions.php";
  11. include "bbcode.php";
  12. // check if flatfile database location is populated
  13. if(!file_exists("ssb_db"))
  14. {
  15. mkdir("ssb_db", 0777);
  16. }
  17. if(!file_exists("ssb_db/users"))
  18. {
  19. mkdir("ssb_db/users", 0777);
  20. }
  21. if(!file_exists("ssb_db/posts"))
  22. {
  23. mkdir("ssb_db/posts", 0777);
  24. }
  25. if(!file_exists("ssb_db/uploads"))
  26. {
  27. mkdir("ssb_db/uploads", 0777);
  28. }
  29. if(!file_exists("ssb_db/friends"))
  30. {
  31. mkdir("ssb_db/friends", 0777);
  32. }
  33. $username = $_SESSION['ssb-user'];
  34. //$_SESSION['ssb-topic'] = $ssbtopic;
  35. ?>
  36. <!DOCTYPE html>
  37. <html lang="en-us">
  38. <head>
  39. <title><?php echo htmlentities(stripslashes($ssbtitle)); ?></title>
  40. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  41. <meta name="viewport" content="width=device-width, initial-scale=.55, shrink-to-fit=yes"><meta name="description" content="<?php echo htmlentities($ssbtitle) . " - " . $desc; ?>">
  42. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  43. <link rel="stylesheet" type="text/css" href="style.css">
  44. </head>
  45. <body <?php if($_GET['do']=="pubmsg" || $_GET['do']=="privmsg") { echo "onload=\"UpdateTimer();\""; } ?>>
  46. <script type="text/javascript">
  47. var elems = document.body.getElementsByTagName("video");
  48. for(var i = 0; i < elems.length; i++)
  49. {
  50. elems[i].setAttribute("preload","none");
  51. }
  52. // Get the HTTP Object
  53. function getHTTPObject() {
  54. if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
  55. else if (window.XMLHttpRequest) return new XMLHttpRequest();
  56. else {
  57. alert("Your browser does not support AJAX.");
  58. return null;
  59. }
  60. }
  61. function wrapBBCode(tag) {
  62. var msgInput = document.getElementById('msg');
  63. var content = msgInput.value;
  64. var selectedContent = content.substring(msgInput.selectionStart, msgInput.selectionEnd);
  65. var beforeContent = content.substring(0, msgInput.selectionStart);
  66. var afterContent = content.substring(msgInput.selectionEnd, content.length);
  67. msgInput.value = beforeContent + '[' + tag + ']' + selectedContent + '[/' + tag + ']' + afterContent;
  68. }
  69. function userTag(tag) {
  70. var msgInput = document.getElementById('msg');
  71. var content = msgInput.value;
  72. var beforeContent = content.substring(0, msgInput.selectionStart);
  73. var afterContent = content.substring(msgInput.selectionEnd, content.length);
  74. msgInput.value = beforeContent + '@' + tag + afterContent;
  75. }
  76. // For dynamic reacting without leaving page.
  77. function userReact(user, postid) {
  78. ajaxGet = getHTTPObject();
  79. if (ajaxGet != null) {
  80. link = "index.php?do=react&user="+user+"&pid="+postid;
  81. ajaxGet.open("GET", link , true);
  82. ajaxGet.send(null);
  83. window.location.reload()
  84. }
  85. }
  86. // For dynamic reacting without leaving page.
  87. function userClrNotifications() {
  88. ajaxGet = getHTTPObject();
  89. if (ajaxGet != null) {
  90. link = "index.php?do=clrnote";
  91. ajaxGet.open("GET", link , true);
  92. ajaxGet.send(null);
  93. window.location.reload()
  94. }
  95. }
  96. </script>
  97. <div class="maincontain">
  98. <div id="navcontainer">
  99. <div id="navbar"><!--
  100. <?php if(isset($_SESSION['ssb-user']) && isset($_SESSION['ssb-pass'])) { ?>
  101. --><a style="width:50px;" href="?forms=post" title="Post on your feed!"><i style="padding:2px 2px 2px 2px;" class="fa fa-plus-square"></i></a><!--
  102. --><a style="width:50px;" href="?do=pubmsg" title="Public chat!"><i style="padding:2px 2px 2px 2px;" class="fa fa-comments-o"></i></a><!--
  103. --><a style="width:50px;" href="?userfeed=<?php echo $username; ?>" title="Your profile!"><i style="padding:2px 2px 2px 2px;" class="fa fa-user"></i></a><!--
  104. --><a href="index.php">Feed</a><!--
  105. --><a href="?do=friends">Friends</a><!--
  106. --><a href="?do=about">About</a><!--
  107. --><a style="width:50px;" href="?do=users" title="Public users!"><i style="padding:2px 2px 2px 2px;" class="fa fa-users"></i></a><!--
  108. --><a style="width:50px;" href="?do=userctrl"><i style="padding:2px 2px 2px 2px;" class="fa fa-cog"></i></a><!--
  109. --><a style="width:50px;" href="?do=logout"><i style="padding:2px 2px 2px 2px;" class="fa fa-sign-out"></i></a><!--
  110. <?php } else { ?>
  111. --><a href="?forms=login">Login</a><!--
  112. --><a href="?do=about">About</a><!--
  113. <?php } ?>
  114. --></div>
  115. </div>
  116. <div class='contain'>
  117. <div class='title'><?php echo $ssbtitle; ?></div>
  118. <?php
  119. if(isset($username) && isset($_SESSION['ssb-pass']) && $_GET['do']!="avatarlocation") {
  120. // PM notifications
  121. $notifications = "ssb_db/friends/" . $username . ".notifications";
  122. $handle = fopen($notifications, "r");
  123. echo "<div class='notifications'>";
  124. echo "<table><tr><td><a class='button' onclick=\"userClrNotifications();\">Clear notifications</a></td></tr>";
  125. if ($handle) {
  126. while (($line = fgets($handle)) !== false) {
  127. echo "<tr><td><i class='fa fa-exclamation' aria-hidden='true'></i> " . $line . "</td></tr>";
  128. }
  129. fclose($handle);
  130. } else {
  131. echo "<tr><td>No notifications</td></tr>";
  132. }
  133. echo "</table></div><br />";
  134. }
  135. if(isset($_GET['forms']))
  136. {
  137. $forms = $_GET['forms'];
  138. $id = $_GET['pid'];
  139. if($forms=="register") {
  140. registerForm();
  141. }
  142. else if($forms=="login") {
  143. loginForm();
  144. }
  145. else if($forms=="friendreq") {
  146. friendReqForm();
  147. }
  148. else if($forms=="changepass") {
  149. changePassForm();
  150. }
  151. else if($forms=="deleteacct") {
  152. deleteAcctForm();
  153. }
  154. else if($forms=="avatarupload") {
  155. uploadAvatarForm();
  156. }
  157. else if($forms=="post") {
  158. postForm();
  159. }
  160. else if($forms=="clean") {
  161. cleanForm();
  162. }
  163. else {
  164. echo "ERROR: Unknown form-name<br>";
  165. }
  166. }
  167. else if(isset($_GET['notify']))
  168. {
  169. $notify = $_GET['notify'];
  170. if($notify=="1") { echo "Error: User not found"; }
  171. else if($notify=="2") { echo "Error: Incorrect password provided"; }
  172. else if($notify=="3") { echo "Error: Please fill out all the text boxes"; }
  173. else if($notify=="4") { echo "Error: The provided passwords did not match"; }
  174. else if($notify=="5") { echo "Error: Special characters cannot be used in your username"; }
  175. else if($notify=="6") { echo "Error: This username is already in use"; }
  176. else { echo "Error: unknown error... this is quite unusual..."; }
  177. }
  178. else if(isset($_GET['userfeed']))
  179. {
  180. $userid = $_GET['userfeed'];
  181. // Make sure we're friends or is my account.
  182. include "ssb_db/users/" . $userid . ".php";
  183. if ($accttype == "private") {
  184. if (isset($_SESSION['ssb-user']) || isset($_SESSION['ssb-pass'])) {
  185. $friendcount = file_get_contents("ssb_db/friends/" . $username . ".count");
  186. include "ssb_db/friends/" . $username . ".php";
  187. for($x = 1; $x <= $friendcount; $x++)
  188. {
  189. // If private, and user is following. Allow
  190. if($userid == ${"friend" . $x}) {
  191. echo "<table><tr><td>";
  192. echo "<div class='avatar' style=\"background-image: url('index.php?do=avatarlocation&user=" . $userid . "');\" title='User Avatar'></div><br />";
  193. // DONE
  194. echo "</td><td>";
  195. echo "<h3>User information</h3>";
  196. echo "Username: " . $userid . "@" . $domain . "<br />";
  197. echo "Full name: " . $user_fullname . "<br />";
  198. echo "<h3>User posts</h3>";
  199. echo "</td></tr></table>";
  200. }
  201. }
  202. // Check if viewing your own profile
  203. if($userid == $username)
  204. {
  205. echo "<table><tr><td>";
  206. // Get user avatar if set
  207. echo "<div class='avatar' style=\"background-image: url('index.php?do=avatarlocation&user=" . $userid . "');\" title='User Avatar'></div><br />";
  208. // DONE
  209. echo "</td><td>";
  210. echo "<h3>User information</h3>";
  211. echo "Username: " . $userid . "@" . $domain . "<br />";
  212. echo "Full name: " . $user_fullname . "<br />";
  213. echo "<h3>User posts</h3>";
  214. echo "</td></tr></table>";
  215. }
  216. // Lets generate the users feed now.
  217. foreach(array_reverse(glob("ssb_db/posts/post_" . $userid . "_" . "*.php")) as $postfile) {
  218. //echo $postfile;
  219. include $postfile;
  220. for($x = 1; $x <= $friendcount; $x++)
  221. {
  222. if($postowner == ${"friend" . $x}) {
  223. echo "<div class='post'><table><tr><td><div class='avatar_small' style=\"background-image: url('index.php?do=avatarlocation&user=$postowner');\" title='User Avatar'></div></td><td><h3>$postowner<span class='date'>$postdate &nbsp;&nbsp;";
  224. if(file_exists("ssb_db/posts/$postid.reactcount")) {
  225. $reacts = file_get_contents("ssb_db/posts/$postid.reactcount");
  226. echo "<div class='reacts'><i class='fa fa-heart' style='color: red;'></i> $reacts <div class='react-list'>";
  227. // Pull up users who reacted, and generate dropdown list.
  228. $reactlist = fopen("ssb_db/posts/$postid.reacted", "r");
  229. if($reactlist) {
  230. while (($reactor = fgets($reactlist)) !== false) {
  231. echo "<b>$reactor</b>";
  232. }
  233. fclose($reactlist);
  234. }
  235. echo "</div></div>";
  236. }
  237. echo "</span><br /><a onclick=\"userReact('" . $postowner . "', '" . $postid . "');\"><i class='fa fa-heart'></i></a> <a href='index.php?view=$postid&user=$postowner'><i class='fa fa-reply'></i></a></h3></td></tr></table>";
  238. echo "" . bbcode_format($postcontent) . "";
  239. // Footer
  240. echo "<div class='post-footer'>";
  241. echo "<a style='padding-top: 6px;' href='index.php?view=$postid&user=$postowner' class='button'><i class='fa fa-reply'></i>&nbsp;Comment</a>";
  242. echo "<a style='padding-top: 6px;' onclick=\"userReact('" . $postowner . "','" . $postid . "');\" class='button'><i class='fa fa-heart'></i>&nbsp;React</a>";
  243. echo "<br />"; // line break
  244. if(file_exists("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count")) {
  245. $postcount = file_get_contents("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count");
  246. // If there's a reply, show them.
  247. if($postcount == 0) {
  248. echo "no replies";
  249. } else if($postcount == 1) {
  250. echo "$postcount reply";
  251. } else if ($postcount > 0) {
  252. echo "$postcount replies";
  253. }
  254. }
  255. echo " &bull; ";
  256. // Show reaction count in footer as well.
  257. if(file_exists("ssb_db/posts/" . $postid . ".reactcount")) {
  258. $reactcount = file_get_contents("ssb_db/posts/" . $postid . ".reactcount");
  259. if($reactcount == 1) {
  260. echo "$reactcount reaction";
  261. } else if ($reactcount > 0) {
  262. echo "$reactcount reactions";
  263. }
  264. } else {
  265. echo "no reactions";
  266. }
  267. echo "</div></div><br />\n";
  268. }
  269. }
  270. if($postowner == $username)
  271. {
  272. echo "<div class='post'><table><tr><td><div class='avatar_small' style=\"background-image: url('index.php?do=avatarlocation&user=$postowner');\" title='User Avatar'></div></td><td><h3>$postowner<span class='date'>$postdate &nbsp;&nbsp;";
  273. if(file_exists("ssb_db/posts/$postid.reactcount")) {
  274. $reacts = file_get_contents("ssb_db/posts/$postid.reactcount");
  275. echo "<div class='reacts'><i class='fa fa-heart' style='color: red;'></i> $reacts <div class='react-list'>";
  276. // Pull up users who reacted, and generate dropdown list.
  277. $reactlist = fopen("ssb_db/posts/$postid.reacted", "r");
  278. if($reactlist) {
  279. while (($reactor = fgets($reactlist)) !== false) {
  280. echo "<b>$reactor</b>";
  281. }
  282. fclose($reactlist);
  283. }
  284. echo "</div></div>";
  285. }
  286. echo "</span><br /><a onclick=\"userReact('" . $postowner . "', '" . $postid ."');\"><i class='fa fa-heart'></i></a> <a href='index.php?view=$postid&user=$postowner'><i class='fa fa-reply'></i></a> <a href='index.php?do=delpost&user=$username&pid=$postid'><i class='fa fa-trash-o'></i></a></h3></td></tr></table>";
  287. echo "" . bbcode_format($postcontent) . "";
  288. // Footer
  289. echo "<div class='post-footer'>";
  290. echo "<a style='padding-top: 6px;' href='index.php?view=$postid&user=$postowner' class='button'><i class='fa fa-reply'></i>&nbsp;Comment</a>";
  291. echo "<a style='padding-top: 6px;' onclick=\"userReact('" . $postowner . "','" . $postid . "');\" class='button'><i class='fa fa-heart'></i>&nbsp;React</a>";
  292. echo "<br />"; // line break
  293. if(file_exists("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count")) {
  294. $postcount = file_get_contents("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count");
  295. // If there's a reply, show them.
  296. if($postcount == 0) {
  297. echo "no replies";
  298. } else if($postcount == 1) {
  299. echo "$postcount reply";
  300. } else if ($postcount > 0) {
  301. echo "$postcount replies";
  302. }
  303. }
  304. echo " &bull; ";
  305. // Show reaction count in footer as well.
  306. if(file_exists("ssb_db/posts/" . $postid . ".reactcount")) {
  307. $reactcount = file_get_contents("ssb_db/posts/" . $postid . ".reactcount");
  308. if($reactcount == 1) {
  309. echo "$reactcount reaction";
  310. } else if ($reactcount > 0) {
  311. echo "$reactcount reactions";
  312. }
  313. } else {
  314. echo "no reactions";
  315. }
  316. echo "</div></div><br />\n";
  317. }
  318. }
  319. echo "<!-- Gen done...-->";
  320. }
  321. }
  322. else
  323. {
  324. echo "<h3>User information</h3>";
  325. echo "<table><tr><td>";
  326. // Get user avatar if set
  327. if(isset($user_avatar)) { echo "<img class='avatar' src='ssb_db/uploads/" . $user_avatar . "' title='User Avatar'><br />"; }
  328. // DONE
  329. echo "</td><td>";
  330. // If not friend, allow to send friend request from right here!
  331. $friend = 0;
  332. $friendcount = file_get_contents("ssb_db/friends/" . $username . ".count");
  333. include "ssb_db/friends/" . $username . ".php";
  334. for($x = 1; $x <= $friendcount; $x++)
  335. {
  336. // If private, and user is following. Allow
  337. if($userid == ${"friend" . $x}) {
  338. $friend = 1;
  339. }
  340. }
  341. if($friend!=1) {
  342. echo "<a class='button' href='index.php?do=sendfr&user=$userid'>Send friend request</a><br /><br />";
  343. }
  344. echo "Username: " . $userid . "@" . $domain . "<br />";
  345. echo "Full name: " . $user_fullname;
  346. echo "</td></tr></table>";
  347. foreach(array_reverse(glob("ssb_db/posts/post_" . $userid . "_" . "*.php")) as $postfile) {
  348. include $postfile;
  349. echo "<div class='post'><table><tr><td><div class='avatar_small' style=\"background-image: url('index.php?do=avatarlocation&user=$postowner');\" title='User Avatar'></div></td><td><h3>$postowner<span class='date'>$postdate &nbsp;&nbsp;";
  350. if(file_exists("ssb_db/posts/$postid.reactcount")) {
  351. $reacts = file_get_contents("ssb_db/posts/$postid.reactcount");
  352. echo "<div class='reacts'><i class='fa fa-heart' style='color: red;'></i> $reacts <div class='react-list'>";
  353. // Pull up users who reacted, and generate dropdown list.
  354. $reactlist = fopen("ssb_db/posts/$postid.reacted", "r");
  355. if($reactlist) {
  356. while (($reactor = fgets($reactlist)) !== false) {
  357. echo "<b>$reactor</b>";
  358. }
  359. fclose($reactlist);
  360. }
  361. echo "</div></div>";
  362. }
  363. echo "</span><br /><a onclick=\"userReact('" . $postowner . "', '" . $postid . "');\"><i class='fa fa-heart'></i></a> <a href='index.php?view=$postid&user=$postowner'><i class='fa fa-reply'></i></a></h3></td></tr></table>";
  364. echo "" . bbcode_format($postcontent) . "";
  365. // Footer
  366. echo "<div class='post-footer'>";
  367. echo "<a style='padding-top: 6px;' href='index.php?view=$postid&user=$postowner' class='button'><i class='fa fa-reply'></i>&nbsp;Comment</a>";
  368. echo "<a style='padding-top: 6px;' onclick=\"userReact('" . $postowner . "','" . $postid . "');\" class='button'><i class='fa fa-heart'></i>&nbsp;React</a>";
  369. echo "<br />"; // line break
  370. if(file_exists("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count")) {
  371. $postcount = file_get_contents("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count");
  372. // If there's a reply, show them.
  373. if($postcount == 0) {
  374. echo "no replies";
  375. } else if($postcount == 1) {
  376. echo "$postcount reply";
  377. } else if ($postcount > 0) {
  378. echo "$postcount replies";
  379. }
  380. }
  381. echo " &bull; ";
  382. // Show reaction count in footer as well.
  383. if(file_exists("ssb_db/posts/" . $postid . ".reactcount")) {
  384. $reactcount = file_get_contents("ssb_db/posts/" . $postid . ".reactcount");
  385. if($reactcount == 1) {
  386. echo "$reactcount reaction";
  387. } else if ($reactcount > 0) {
  388. echo "$reactcount reactions";
  389. }
  390. } else {
  391. echo "no reactions";
  392. }
  393. echo "</div></div><br />\n";
  394. }
  395. echo "<!-- Gen done...-->";
  396. }
  397. }
  398. else if(isset($_GET['view']) && isset($_GET['user']))
  399. {
  400. $puser = $_GET['user'];
  401. $id = $_GET['view'];
  402. $postc = file_get_contents("ssb_db/posts/reply_" . $puser . "_" . $id . ".count");
  403. include "ssb_db/posts/post_" . $puser . "_" . $id . ".php";
  404. echo "<div class='post'><table><tr><td><div class='avatar_small' style=\"background-image: url('index.php?do=avatarlocation&user=$postowner');\" title='User Avatar'></div></td><td><h3>$postowner<span class='date'>$postdate &nbsp;&nbsp;";
  405. if(file_exists("ssb_db/posts/$postid.reactcount")) {
  406. $reacts = file_get_contents("ssb_db/posts/$postid.reactcount");
  407. echo "<div class='reacts'><i class='fa fa-heart' style='color: red;'></i> $reacts <div class='react-list'>";
  408. // Pull up users who reacted, and generate dropdown list.
  409. $reactlist = fopen("ssb_db/posts/$postid.reacted", "r");
  410. if($reactlist) {
  411. while (($reactor = fgets($reactlist)) !== false) {
  412. echo "<b>$reactor</b>";
  413. }
  414. fclose($reactlist);
  415. }
  416. echo "</div></div>";
  417. }
  418. echo "</span><br /><a onclick=\"userReact('" . $postowner . "', '" . $postid . "');\" class='reacts'><i class='fa fa-heart'></i></a></h3></td></tr></table>";
  419. echo "" . bbcode_format($postcontent) . "";
  420. // Footer
  421. echo "</div><br />\n";
  422. for($x = 1; $x <= $postc; $x++) {
  423. $reply_content = ${"reply" . $x};
  424. $reply_user = ${"reply" . $x . "_user"};
  425. $reply_date = ${"reply" . $x . "_date"};
  426. echo "<div class='reply'>";
  427. echo "<table><tr><td><div class='avatar_small' style='background-image: url(\"index.php?do=avatarlocation&user=$reply_user\");' title='User Avatar'></div></td><td><h4>$reply_user <a onclick=\"userTag('$reply_user');\"><i class='fa fa-tag'></i></a> <span style='font-size: 8px; padding-left: 6px; color: #808080;'>$reply_date</span></h4></td></tr></table>";
  428. echo "<div class='reply_content'>" . bbcode_format($reply_content) . "</div>";
  429. echo "</div>\n";
  430. }
  431. echo "<br />";
  432. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) {
  433. echo "Login to reply...";
  434. } else {
  435. $friendcount = file_get_contents("ssb_db/friends/" . $username . ".count");
  436. include "ssb_db/friends/" . $username . ".php";
  437. for($x = 1; $x <= $friendcount; $x++)
  438. {
  439. if($puser == ${"friend" . $x}) {
  440. $z = "1";
  441. replyForm($id, $puser);
  442. }
  443. }
  444. // Its you dummy
  445. if($puser == $username) {
  446. $z = "1";
  447. replyForm($id, $puser);
  448. }
  449. if(!isset($z))
  450. {
  451. echo "Not following! Follow to reply...<br />";
  452. }
  453. }
  454. }
  455. else if(isset($_GET['do']))
  456. {
  457. $do = $_GET['do'];
  458. if($do=="post")
  459. {
  460. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  461. $date = date("YmdHis"); // timestamp in year, month, date, hour, minute, and second.
  462. $titledate = date("m-d-Y h:i:sa"); // time stamp for people to read xD
  463. if(isset($_FILES["file"]["name"]) && isset($username)) {
  464. $uploaded = array(); // empty array for upload file names
  465. $uploaded_name = array(); // empty array for upload names
  466. // File selected, upload!
  467. for($i=0; $i<count($_FILES["file"]["name"]); $i++)
  468. {
  469. $allowedExts = array("gif", "jpeg", "jpg", "png", "bmp", "ico", "GIF", "JPEG", "JPG", "PNG", "BMP", "ICO", "mp4", "MP4");
  470. $temp = explode(".", $_FILES["file"]["name"][$i]);
  471. $extension = end($temp);
  472. if ((($_FILES["file"]["type"][$i] == "image/gif")
  473. || ($_FILES["file"]["type"][$i] == "image/x-gif")
  474. || ($_FILES["file"]["type"][$i] == "image/jpeg")
  475. || ($_FILES["file"]["type"][$i] == "image/x-jpeg")
  476. || ($_FILES["file"]["type"][$i] == "image/x-jpg")
  477. || ($_FILES["file"]["type"][$i] == "image/jpg")
  478. || ($_FILES["file"]["type"][$i] == "image/pjpeg")
  479. || ($_FILES["file"]["type"][$i] == "image/x-png")
  480. || ($_FILES["file"]["type"][$i] == "image/bmp")
  481. || ($_FILES["file"]["type"][$i] == "image/x-icon")
  482. || ($_FILES["file"]["type"][$i] == "application/octet-stream")
  483. || ($_FILES["file"]["type"][$i] == "video/mp4")
  484. // || ($_FILES["file"]["type"][$i] == "video/ogg")
  485. // || ($_FILES["file"]["type"][$i] == "video/webm")
  486. // || ($_FILES["file"]["type"][$i] == "video/x-flv")
  487. // || ($_FILES["file"]["type"][$i] == "video/mp4v-es")
  488. || ($_FILES["file"]["type"][$i] == "image/png")
  489. || ($_FILES["file"]["type"][$i] == ""))
  490. && ($_FILES["file"]["size"][$i] < $user_max_upload)
  491. && in_array($extension, $allowedExts))
  492. {
  493. if ($_FILES["file"]["error"][$i] > 0)
  494. {
  495. echo $_FILES["file"]["name"][$i] . " - Return Code: " . $_FILES["file"]["error"][$i] . "<br />";
  496. }
  497. else
  498. {
  499. if(file_exists("ssb_db/uploads/" . $_FILES["file"]["name"][$i]))
  500. {
  501. echo "Error: " . $_FILES["file"]["name"][$i] . " exists.<br />";
  502. }
  503. else
  504. {
  505. $randstring = getRandString("32");
  506. move_uploaded_file($_FILES["file"]["tmp_name"][$i],
  507. "ssb_db/uploads/" . $randstring . "." . $extension);
  508. array_push($uploaded, $randstring . "." . $extension);
  509. array_push($uploaded_name, pathinfo($_FILES["file"]["name"][$i], PATHINFO_FILENAME));
  510. echo "Success: " . $_FILES["file"]["name"][$i] . " (" . tomb($_FILES["file"]["size"][$i]) . ") uploaded...<br />";
  511. //rename("ssb_db/uploads/" . $FILES["file"]["name"][$i], "ssb_db/uploads/" . $username . "_" . $date . $extension);
  512. }
  513. }
  514. }
  515. else
  516. {
  517. // Check if there was actually an issue
  518. if($_FILES["file"]["size"] == "0") {
  519. echo "Error: " . $_FILES["file"]["name"][$i] . " is too large, or is a invalid filetype";
  520. }
  521. }
  522. } // end of for loop
  523. $srchcont = stripslashes(htmlentities($_POST['body']));
  524. $srchcont .= " "; // doesn't find tag if there's not a fucking whitespace
  525. $checkForUserTag = searchForUserTag($srchcont);
  526. $taggedUser = substr($checkForUserTag, 1, -1);
  527. if(file_exists("ssb_db/users/" . $taggedUser . ".name")) {
  528. if($taggedUser!=$postowner) {
  529. $tagged_notifications = file_get_contents("ssb_db/friends/" . $taggedUser . ".notifications");
  530. file_put_contents("ssb_db/friends/" . $taggedUser . ".notifications", "<b>$username</b> <a href='index.php?view=$date&user=$username'>tagged you in a post</a>\n" . $tagged_notifications);
  531. }
  532. }
  533. $body = nl2br(htmlentities(stripcslashes($_POST['body'])));
  534. //$username = stripcslashes(htmlentities($username));
  535. include "ssb_db/users/" . $username . ".php";
  536. $post_file = "ssb_db/posts/post_" . $username . "_" . $date . ".php";
  537. $post_attachments = "<br />";
  538. $post_string = "<?php\n\$postowner = \"" . $username . "\";\$postid=\"" . $date . "\";\$postdate=\"" . $titledate . "\";\$postcontent = \"" . $body . "<br />";
  539. $attachments = array();
  540. $fileCount = 0;
  541. foreach($uploaded as &$upload)
  542. {
  543. if(file_exists("ssb_db/uploads/" . $upload)) {
  544. $ext = pathinfo("ssb_db/uploads/ . $upload", PATHINFO_EXTENSION);
  545. if($ext == "mp4" || $ext == "MP4") {
  546. array_push($attachments, "<div class='attachment'>" . $uploaded_name[$fileCount] . "<video width='560' height='315' controls><source src='ssb_db/uploads/$upload' type='video/mp4'>HTML5 video not supported :(</video></div>");
  547. }
  548. else
  549. {
  550. array_push($attachments, "<div class='attachment'><a href='ssb_db/uploads/" . $upload . "'><img src='ssb_db/uploads/" . $upload . "'></a></div>");
  551. }
  552. }
  553. $fileCount++; // Add it up
  554. }
  555. foreach($attachments as &$attachvar)
  556. {
  557. $post_attachments .= $attachvar;
  558. }
  559. $post_string_end = "\";\n?>\n";
  560. file_put_contents($post_file, $post_string . $post_attachments . $post_string_end);
  561. file_put_contents("ssb_db/posts/" . $date . ".post", "post_" . $username . "_" . $date . ".php");
  562. file_put_contents("ssb_db/posts/reply_" . $username . "_" . $date . ".count", "0");
  563. echo "Post processed... if redirection fails, <a href=\"?view=$date&user=$username\">Click Here</a><br />";
  564. header( "refresh: 1;url=?view=$date&user=$username" );
  565. }
  566. else
  567. {
  568. echo "ERROR: Missing post data! Select an image to upload or let us know whats up!<br />";
  569. }
  570. }
  571. }
  572. if($do=="avatarupload")
  573. {
  574. if(isset($_FILES["file"]["name"]) && isset($username)) {
  575. $date = date("YmdHis"); // timestamp in year, month, date, hour, minute, and second.
  576. for($i=0; $i<count($_FILES["file"]["name"]); $i++)
  577. {
  578. $allowedExts = array("gif", "jpeg", "jpg", "png", "bmp", "ico", "png");
  579. $temp = explode(".", $_FILES["file"]["name"][$i]);
  580. $extension = end($temp);
  581. if ((($_FILES["file"]["type"][$i] == "image/gif")
  582. || ($_FILES["file"]["type"][$i] == "image/x-gif")
  583. || ($_FILES["file"]["type"][$i] == "image/jpeg")
  584. || ($_FILES["file"]["type"][$i] == "image/x-jpeg")
  585. || ($_FILES["file"]["type"][$i] == "image/x-jpg")
  586. || ($_FILES["file"]["type"][$i] == "image/jpg")
  587. || ($_FILES["file"]["type"][$i] == "image/pjpeg")
  588. || ($_FILES["file"]["type"][$i] == "image/x-png")
  589. || ($_FILES["file"]["type"][$i] == "image/bmp")
  590. || ($_FILES["file"]["type"][$i] == "image/x-icon")
  591. || ($_FILES["file"]["type"][$i] == "image/png")
  592. || ($_FILES["file"]["type"][$i] == ""))
  593. && ($_FILES["file"]["size"][$i] < $user_max_upload)
  594. && in_array($extension, $allowedExts))
  595. {
  596. if ($_FILES["file"]["error"][$i] > 0)
  597. {
  598. echo $_FILES["file"]["name"][$i] . " - Return Code: " . $_FILES["file"]["error"][$i] . "<br>";
  599. }
  600. else
  601. {
  602. if(file_exists("ssb_db/uploads/" . $_FILES["file"]["name"][$i]))
  603. {
  604. echo "Error: " . $_FILES["file"]["name"][$i] . " exists.<br>";
  605. }
  606. else
  607. {
  608. move_uploaded_file($_FILES["file"]["tmp_name"][$i],
  609. "ssb_db/uploads/" . $username . "_" . $date . "." . $extension);
  610. $oldcontent = file_get_contents("ssb_db/users/" . $username . ".php");
  611. file_put_contents("ssb_db/users/" . $username . ".php", $oldcontent . "<?php \$user_avatar = \"" . $username . "_" . $date . "." . $extension . "\"; ?>\n");
  612. echo "Avatar uploaded and set! <a href='index.php'>Redirecting</a> in 3 seconds...";
  613. header("refresh: 3;url=index.php");
  614. }
  615. }
  616. } else {
  617. echo "Error: " . $_FILES["file"]["name"][$i] . " is too large, or is a invalid filetype";
  618. }
  619. }
  620. }
  621. }
  622. if($do=="users")
  623. {
  624. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  625. include "ssb_db/users/" . $username . ".php";
  626. echo "<h2>Community</h2>";
  627. foreach(array_reverse(glob("ssb_db/users/"."*.name")) as $userfile) {
  628. $userhandle = file_get_contents($userfile);
  629. include "ssb_db/users/" . $userhandle . ".php";
  630. if($accttype == "public") {
  631. echo "<div class='attachment'>";
  632. echo "<a href='index.php?userfeed=$userhandle'>$userhandle</a>";
  633. echo "</div>";
  634. }
  635. }
  636. }
  637. }
  638. if($do=="reply")
  639. {
  640. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  641. if(!isset($_GET['pid']) or !file_exists("ssb_db/posts/" . $_GET['pid'] . ".post")) { echo "ERROR: Post ID is not set, or invalid"; } else {
  642. if(isset($_POST['reply']) && isset($username) && $_POST['body']!="")
  643. {
  644. $pid = $_GET['pid'];
  645. $post_file_name = file_get_contents("ssb_db/posts/$pid.post");
  646. include "ssb_db/posts/" . $post_file_name;
  647. $srchcont = stripslashes(htmlentities($_POST['body']));
  648. $srchcont .= " ";
  649. $checkForUserTag = searchForUserTag($srchcont);
  650. $taggedUser = substr($checkForUserTag, 1, -1);
  651. if(file_exists("ssb_db/users/" . $taggedUser . ".name")) {
  652. if($taggedUser!=$postowner) {
  653. $tagged_notifications = file_get_contents("ssb_db/friends/" . $taggedUser . ".notifications");
  654. file_put_contents("ssb_db/friends/" . $taggedUser . ".notifications", "<b>$username</b> <a href='index.php?view=$pid&user=$postowner'>tagged you in a comment</a>\n" . $tagged_notifications);
  655. }
  656. }
  657. $replydate = date("m-d-Y h:i:sa"); // time stamp for people to read xD
  658. $body = nl2br(htmlentities(stripcslashes($_POST['body'])));
  659. //$username = stripcslashes(htmlentities($username));
  660. $old_content = file_get_contents("ssb_db/posts/" . $post_file_name);
  661. $reply_count = file_get_contents("ssb_db/posts/reply_" . $postowner . "_" . $pid . ".count");
  662. $reply_count = $reply_count+1;
  663. $post_string = "<?php \n\$reply" . $reply_count . " = \"" . $body . "\";\$reply" . $reply_count . "_user = \"" . $username . "\"; \$reply" . $reply_count . "_date = \"" . $replydate . "\";\n?>\n";
  664. file_put_contents("ssb_db/posts/" . $post_file_name, $old_content . $post_string);
  665. file_put_contents("ssb_db/posts/reply_" . $postowner . "_" . $pid . ".count", $reply_count);
  666. if($username!=$postowner) {
  667. $owner_notifications = file_get_contents("ssb_db/friends/" . $postowner . ".notifications");
  668. file_put_contents("ssb_db/friends/" . $postowner . ".notifications", "<b>$username</b> <a href='index.php?view=$pid&user=$postowner'>replied to your post</a>\n" . $owner_notifications);
  669. }
  670. echo "If you're seeing this; redirection failed: <a href=\"?view=$pid&user=$postowner\">Click Here</a><br>";
  671. header( "refresh: 1;url=index.php?view=$pid&user=$postowner" );
  672. }
  673. else
  674. {
  675. echo "ERROR: Missing form data<br>";
  676. }
  677. }
  678. }
  679. }
  680. if($do=="delpost")
  681. {
  682. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  683. include "ssb_db/users/" . $username . ".php";
  684. if($user_password === $_SESSION['ssb-pass']) {
  685. if(isset($_GET['user']) && $_GET['user']!="" && isset($_GET['pid']) && $_GET['pid']!="") {
  686. if(file_exists("ssb_db/posts/post_" . stripslashes($_GET['user']) . "_" . stripslashes($_GET['pid']) . ".php") && $username == stripslashes($_GET['user'])) {
  687. $postuser = $_GET['user'];
  688. $pid = $_GET['pid'];
  689. unlink("ssb_db/posts/" . $pid . ".post");
  690. unlink("ssb_db/posts/post_" . $postuser . "_" . $pid . ".php");
  691. unlink("ssb_db/posts/reply_" . $postuser . "_" . $pid . ".count");
  692. echo "Post successfully deleted! <a href='index.php'>redirecting</a> in 3 seconds...<br />";
  693. header("refresh: 3;url=index.php");
  694. exit;
  695. } else { echo "ERROR: post doesn't exist or YOU ARE NOT THE OWNER OF SAID POST... THIS incident has been recorded!"; file_put_contents("ssb_db/log.txt", "Post deletion error: IP <" . $_SERVER['REMOTE_ADDR'] . "> post not found or not users post: post_" . $postuser . "_" . $pid . ".php\n"); }
  696. } else { echo "ERROR: USER and PID variables not set!"; }
  697. } else { echo "ERROR: PASSWORD FOR USER INCORRECT! IP LOGGED!"; file_put_contents("ssb_db/log.txt", "PASS MISMATCH: IP <" . $_SERVER['REMOTE_ADDR'] . "> Cookie spoofing detected from remote client!!!\n"); }
  698. }
  699. }
  700. if($do=="react")
  701. {
  702. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  703. include "ssb_db/users/" . $username . ".php";
  704. if($user_password === $_SESSION['ssb-pass']) {
  705. if(isset($_GET['user']) && $_GET['user']!="" && isset($_GET['pid']) && $_GET['pid']!="") {
  706. if(file_exists("ssb_db/posts/post_" . stripslashes($_GET['user']) . "_" . stripslashes($_GET['pid']) . ".php")) {
  707. $postuser = $_GET['user'];
  708. $pid = $_GET['pid'];
  709. $handle = fopen("ssb_db/posts/$pid.reacted", "r");
  710. if ($handle) {
  711. while (($line = fgets($handle)) !== false) {
  712. $line = str_replace(array("\n", "\r"), '', $line);
  713. if($line == $username) {
  714. echo "You've already reacted to this post... <a href='index.php?view=$pid&user=$postuser'>redirecting</a>";
  715. header("refresh: 3;url=index.php?view=$pid&user=$postuser");
  716. exit;
  717. }
  718. }
  719. fclose($handle);
  720. } else {
  721. echo "<!-- Haven't reacted, continuing -->";
  722. }
  723. if(file_exists("ssb_db/posts/$pid.reacted")) {
  724. $reactedPrev = file_get_contents("ssb_db/posts/$pid.reacted");
  725. file_put_contents("ssb_db/posts/$pid.reacted", $reactedPrev . $username . "\n"); // You reacted
  726. } else {
  727. file_put_contents("ssb_db/posts/$pid.reacted", $username . "\n"); // First react
  728. }
  729. if(file_exists("ssb_db/posts/$pid.reactcount")) {
  730. $reactCount = file_get_contents("ssb_db/posts/$pid.reactcount");
  731. $reactCurrent = $reactCount + 1;
  732. file_put_contents("ssb_db/posts/$pid.reactcount", $reactCurrent); // You reacted
  733. } else {
  734. file_put_contents("ssb_db/posts/$pid.reactcount", "1"); // First react
  735. }
  736. // Don't send yourself a notification, you know you liked your own post ;)
  737. if($postuser != $username) {
  738. $owner_notifications = file_get_contents("ssb_db/friends/" . $postuser . ".notifications");
  739. file_put_contents("ssb_db/friends/" . $postuser . ".notifications", "<b>$username</b> loved your <a href='index.php?view=$pid&user=$postuser'>post</a>\n" . $owner_notifications);
  740. }
  741. echo "Reacted! <a href='index.php'>Redirecting</a> in 1 second...";
  742. header("refresh: 1;url=index.php");
  743. exit;
  744. } else { echo "ERROR: post doesn't exist..."; }
  745. } else { echo "ERROR: USER and PID variables not set!"; }
  746. } else { echo "ERROR: PASSWORD FOR USER INCORRECT! IP LOGGED!"; file_put_contents("ssb_db/log.txt", "PASS MISMATCH: IP <" . $_SERVER['REMOTE_ADDR'] . "> Cookie spoofing detected from remote client!!!\n"); }
  747. }
  748. }
  749. if($do=="clrnote")
  750. {
  751. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  752. include "ssb_db/users/" . $username . ".php";
  753. if($user_password === $_SESSION['ssb-pass']) {
  754. unlink("ssb_db/friends/" . $username . ".notifications");
  755. header("Location: index.php");
  756. exit;
  757. } else { echo "ERROR: PASSWORD FROM COOKIE INCORRECT! IP RECORDED!"; file_put_contents("ssb_db/log.txt", "PASS MISMATCH: IP <" . $_SERVER['REMOTE_ADDR'] . "> Cookie spoofing detected from remote client!!!\n"); }
  758. }
  759. }
  760. if($do=="clrpending")
  761. {
  762. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  763. include "ssb_db/users/" . $username . ".php";
  764. if($user_password === $_SESSION['ssb-pass']) {
  765. unlink("ssb_db/friends/" . $username . ".pending");
  766. header("Location: index.php?do=friends");
  767. exit;
  768. } else { echo "ERROR: PASSWORD FROM COOKIE INCORRECT! IP RECORDED!"; file_put_contents("ssb_db/log.txt", "PASS MISMATCH: IP <" . $_SERVER['REMOTE_ADDR'] . "> Cookie spoofing detected from remote client!!!\n"); }
  769. }
  770. }
  771. // Server admin can just delete ssb_db
  772. /*if($do=="clean")
  773. {
  774. if($_POST['password']!="" && $_POST['password']==$pw)
  775. {
  776. $db_content = glob("ssb_db/" . '*', GLOB_MARK);
  777. foreach($db_content as $file)
  778. {
  779. unlink($file);
  780. }
  781. rmdir("ssb_db");
  782. echo "Database Cleaned<br>";
  783. }
  784. else
  785. {
  786. echo "ERROR: Wrong Password<br>";
  787. }
  788. }*/
  789. // grab session values and send friend request functions.
  790. if($do=="sendfr") {
  791. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  792. if(isset($_POST['user']) || isset($_GET['user'])) {
  793. //check if user exists first lol
  794. if(isset($_POST['user'])) {
  795. $givenUser = htmlentities(stripcslashes($_POST['user']));
  796. } else {
  797. $givenUser = htmlentities(stripcslashes($_GET['user']));
  798. }
  799. //check if user exists first lol
  800. if(file_exists("ssb_db/users/" . $givenUser . ".php")) {
  801. include "ssb_db/users/" . $givenUser . ".php";
  802. if($accttype == "private") {
  803. sendFriendRequest($_SESSION['ssb-user'], $givenUser);
  804. echo "Follow request sent to " . $givenUser . " <a href='?do=friends'>redirecting</a> in 3 seconds";
  805. header("refresh: 3;url=?do=friends");
  806. } else if($accttype == "public") {
  807. acceptPublicFriendRequest($username, $givenUser);
  808. header("Location: ?do=friends");
  809. } else {
  810. echo "ERROR: Issues parsing account type...";
  811. }
  812. } else {
  813. echo "Error: Provided username does not exist in the database!";
  814. }
  815. } else {
  816. echo "Error: users not set in GET value...";
  817. }
  818. }
  819. }
  820. if($do=="accfr") {
  821. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  822. if(isset($_GET['user']) && isset($_GET['friend'])) {
  823. acceptFriendRequest(stripslashes($_GET['user']), stripslashes($_GET['friend']));
  824. echo "Accepted friend request from " . htmlentities(stripslashes($_GET['friend'])) . " <a href='?do=friends'>redirecting</a> in 3 seconds";
  825. header("refresh: 3;url=?do=friends");
  826. } else {
  827. echo "Error: users not set in GET &amp; SESSION value...";
  828. }
  829. }
  830. }
  831. if($do=="userctrl")
  832. {
  833. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  834. // Beginning of user control panel
  835. echo "<h3>User control panel</h3>";
  836. echo "<a class='button' href='?forms=changepass'>Change password</a><br />";
  837. echo "<a class='button' href='?forms=avatarupload'>Upload avatar</a><br />";
  838. }
  839. }
  840. if($do=="changepass")
  841. {
  842. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  843. // Beginning password change
  844. // inputs
  845. $oldPassInput = htmlentities(stripslashes($_POST['oldpass']));
  846. $newPassInput = htmlentities(stripslashes($_POST['password']));
  847. $passwordAgainInput = htmlentities(stripslashes($_POST['password_again']));
  848. include "ssb_db/users/" . $username . ".php";
  849. if(sha1(md5($oldPassInput)) == $user_password) {
  850. if($newPassInput == $passwordAgainInput) {
  851. $oldcontent = file_get_contents("ssb_db/users/" . $username . ".php");
  852. $passString = "<?php \$user_password = \"" . sha1(md5($newPassInput)) . "\"; ?>\n";
  853. file_put_contents("ssb_db/users/" . $username . ".php", $oldcontent . $passString);
  854. echo "Password changed, <a href='index.php'>redirecting</a> in 3 seconds";
  855. $_SESSION['ssb-user'] = null;
  856. $_SESSION['ssb-pass'] = null;
  857. header("refresh: 3;url=index.php");
  858. }
  859. } else { echo "ERROR: password incorrect! IP recorded for constant monitoring of possible bots!"; file_put_contents("ssb_db/log.txt", "PASS MISMATCH: IP <" . $_SERVER['REMOTE_ADDR'] . "> Cookie spoofing detected from remote client!!!\n"); }
  860. }
  861. }
  862. if($do=="pubmsg")
  863. {
  864. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  865. ?>
  866. <script language="javascript" type="text/javascript">
  867. <!--
  868. var httpObject = null;
  869. var link = "";
  870. var timerID = 0;
  871. var nickName = "<?php echo $_SESSION['ssb-user']; ?>";
  872. var userColor = "<?php echo $_SESSION['ssb-color'];; ?>";
  873. // Change the value of the outputText field
  874. function setHtml() {
  875. if(ajaxVar.readyState == 4){
  876. var response = ajaxVar.responseText;
  877. var msgBox = document.getElementById("msgs");
  878. msgBox.innerHTML += response;
  879. msgBox.scrollTop = msgBox.scrollHeight;
  880. }
  881. }
  882. // Change the value of the outputText field
  883. function setAll() {
  884. if(ajaxVar.readyState == 4){
  885. var response = ajaxVar.responseText;
  886. var msgBox = document.getElementById("msgs");
  887. msgBox.innerHTML = response;
  888. msgBox.scrollTop = msgBox.scrollHeight;
  889. }
  890. }
  891. // Implement business logic
  892. function serverWrite() {
  893. ajaxVar = getHTTPObject();
  894. if (ajaxVar != null) {
  895. link = "chatserver.php?nick="+nickName+"&msg="+document.getElementById('msg').value;
  896. ajaxVar.open("GET", link , true);
  897. ajaxVar.onreadystatechange = setHtml;
  898. ajaxVar.send(null);
  899. }
  900. }
  901. function getInput() {
  902. // Send the server function the input
  903. var userInput = document.getElementById('msg');
  904. serverWrite(userInput.value);
  905. // Clean out the input values
  906. var msgBar = document.getElementById("msg");
  907. msgBar.value = "";
  908. msgBar.focus();
  909. }
  910. // Implement business logic
  911. function serverReload() {
  912. ajaxVar = getHTTPObject();
  913. //var randomnumber=Math.floor(Math.random()*10000);
  914. if (ajaxVar != null) {
  915. link = "chatserver.php?all=1";
  916. ajaxVar.open("GET", link , true);
  917. ajaxVar.onreadystatechange = setAll;
  918. ajaxVar.send(null);
  919. }
  920. }
  921. function UpdateTimer() {
  922. serverReload();
  923. setTimeout(UpdateTimer, 1000);
  924. }
  925. function keypressed(e) {
  926. if(e.keyCode=='13'){
  927. getInput();
  928. }
  929. }
  930. //-->
  931. </script>
  932. <div class="replycontain">
  933. <div id="msgs">
  934. <?php
  935. echo "<div class=\"msgbox\">";
  936. $get = file_get_contents($chat_db);
  937. echo $get;
  938. echo "</div>";
  939. ?>
  940. </div>
  941. <div id="msgbox" onkeyup="keypressed(event);">
  942. <button onclick="javascript:wrapBBCode('i');">Italic</button>
  943. <button onclick="javascript:wrapBBCode('u');">Underline</button>
  944. <button onclick="javascript:wrapBBCode('b');">Bold</button>
  945. <button onclick="javascript:wrapBBCode('url');">URL</button><br />
  946. <textarea style="width: 98%;" name="msg" id="msg"></textarea>
  947. <button style="width: 50px;" onclick="getInput();">Send</button>
  948. </div>
  949. </div>
  950. <?php
  951. }
  952. }
  953. if($do=="privmsg")
  954. {
  955. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  956. //check if friend is set
  957. if(!isset($_GET['friend'])) { echo "ERROR: No username defined!"; exit(1); } else {
  958. // set friend username
  959. $friendNick = htmlentities(stripslashes($_GET['friend']));
  960. $friendcount = file_get_contents("ssb_db/friends/" . $username . ".count");
  961. include "ssb_db/friends/" . $username . ".php";
  962. for($x = 1; $x <= $friendcount; $x++)
  963. {
  964. if($friendNick == ${"friend" . $x}) {
  965. ?>
  966. <script language="javascript" type="text/javascript">
  967. <!--
  968. var httpObject = null;
  969. var link = "";
  970. var timerID = 0;
  971. var friendNick = "<?php echo $friendNick; ?>";
  972. var nickName = "<?php echo $_SESSION['ssb-user']; ?>";
  973. var userColor = "<?php echo $_SESSION['ssb-color'];; ?>";
  974. // Change the value of the outputText field
  975. function setHtml() {
  976. if(ajaxVar.readyState == 4){
  977. var response = ajaxVar.responseText;
  978. var msgBox = document.getElementById("msgs");
  979. msgBox.innerHTML += response;
  980. msgBox.scrollTop = msgBox.scrollHeight;
  981. }
  982. }
  983. // Change the value of the outputText field
  984. function setAll() {
  985. if(ajaxVar.readyState == 4){
  986. var response = ajaxVar.responseText;
  987. var msgBox = document.getElementById("msgs");
  988. msgBox.innerHTML = response;
  989. msgBox.scrollTop = msgBox.scrollHeight;
  990. }
  991. }
  992. // Implement business logic
  993. function serverWrite() {
  994. ajaxVar = getHTTPObject();
  995. if (ajaxVar != null) {
  996. link = "chatserver.php?nick="+nickName+"&friend="+friendNick+"&msg="+document.getElementById('msg').value;
  997. ajaxVar.open("GET", link , true);
  998. ajaxVar.onreadystatechange = setHtml;
  999. ajaxVar.send(null);
  1000. }
  1001. }
  1002. function getInput() {
  1003. // Send the server function the input
  1004. var userInput = document.getElementById('msg');
  1005. serverWrite(userInput.value);
  1006. // Clean out the input values
  1007. var msgBar = document.getElementById("msg");
  1008. msgBar.value = "";
  1009. msgBar.focus();
  1010. }
  1011. // Implement business logic
  1012. function serverReload() {
  1013. ajaxVar = getHTTPObject();
  1014. //var randomnumber=Math.floor(Math.random()*10000);
  1015. if (ajaxVar != null) {
  1016. link = "chatserver.php?get=<?php echo $friendNick; ?>";
  1017. ajaxVar.open("GET", link , true);
  1018. ajaxVar.onreadystatechange = setAll;
  1019. ajaxVar.send(null);
  1020. }
  1021. }
  1022. function UpdateTimer() {
  1023. serverReload();
  1024. setTimeout(UpdateTimer, 1000);
  1025. }
  1026. function keypressed(e) {
  1027. if(e.keyCode=='13'){
  1028. getInput();
  1029. }
  1030. }
  1031. //-->
  1032. </script>
  1033. <div class="replycontain">
  1034. <?php
  1035. // Header
  1036. include "ssb_db/users/" . $friendNick . ".php";
  1037. echo "<h3><a href='?userfeed=" . $friendNick . "'>" . $friendNick . ": " . $user_fullname . "</a></h3>";
  1038. ?>
  1039. <div id="msgs">
  1040. <?php
  1041. echo "<div class=\"msgbox\">";
  1042. echo "</div>";
  1043. ?>
  1044. </div>
  1045. <div id="msgbox" onkeyup="keypressed(event);">
  1046. <button onclick="javascript:wrapBBCode('i');">Italic</button>
  1047. <button onclick="javascript:wrapBBCode('u');">Underline</button>
  1048. <button onclick="javascript:wrapBBCode('b');">Bold</button>
  1049. <button onclick="javascript:wrapBBCode('img');">Image</button>
  1050. <button onclick="javascript:wrapBBCode('url');">URL</button><br />
  1051. <textarea style="width: 98%;" name="msg" id="msg"></textarea>
  1052. <button style="width: 50px;" onclick="getInput();">Send</button>
  1053. </div>
  1054. </div>
  1055. <?php
  1056. } // Check friend end
  1057. } // Check loop end
  1058. } // GET friend set end
  1059. } // session check end
  1060. } // function end
  1061. // Push user avatar to specific avatar image location
  1062. if($do=="avatarlocation")
  1063. {
  1064. if(isset($_GET['user'])) {
  1065. $user = htmlentities(stripslashes($_GET['user']));
  1066. include "ssb_db/users/" . $user . ".php";
  1067. if(file_exists("ssb_db/uploads/" . $user_avatar)) {
  1068. echo "Direct to: ssb_db/uploads/" . $user_avatar;
  1069. header("Location: ssb_db/uploads/" . $user_avatar . "");
  1070. exit;
  1071. } else {
  1072. echo "Direct to: data/defaultprofile.png";
  1073. header("Location: data/defaultprofile.png");
  1074. exit;
  1075. }
  1076. } else {
  1077. echo "User is NOT set!";
  1078. }
  1079. }
  1080. if($do=="about")
  1081. {
  1082. echo "<h2>About</h2>";
  1083. echo "<div class='dllink'><a class='button' href='download/secure-space-v1.0.0.apk'>Download for Android!</a></div>";
  1084. echo "<p>" . $desc;
  1085. echo "<br /><br />";
  1086. echo "$ssbtitle statistics: ";
  1087. getUserCount();
  1088. echo "; ";
  1089. getPostCount();
  1090. echo "; ";
  1091. getUploadFileCount();
  1092. echo "</p>";
  1093. }
  1094. if($do=="friends")
  1095. {
  1096. if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass'])) { loginForm(); } else {
  1097. $friendpend = "ssb_db/friends/" . $username . ".pending";
  1098. $handle = fopen($friendpend, "r");
  1099. echo "<h3>Friend requests</h3> <a class='button' href='?do=clrpending'>Clear history</a> <a class='button' href='?forms=friendreq'>Send friend request</a>";
  1100. echo "<div class='notifications'>";
  1101. if ($handle) {
  1102. while (($line = fgets($handle)) !== false) {
  1103. echo "Pending friend request from " . $line . "! <a class='button' href='?do=accfr&friend=" . $line . "&user=" . $username . "'>Accept</a><br />";
  1104. }
  1105. fclose($handle);
  1106. } else {
  1107. echo "No pending friend requests<br />";
  1108. }
  1109. echo "</div>";
  1110. // Friends list if you have any.
  1111. echo "<h3>Friends list</h3><br />";
  1112. $friendc = file_get_contents("ssb_db/friends/" . $username . ".count");
  1113. if($friendc == "0")
  1114. {
  1115. echo "<b style='color:red;'>We're sorry... no friends found on your user account...</b>";
  1116. }
  1117. else
  1118. {
  1119. $friendcount = file_get_contents("ssb_db/friends/" . $username . ".count");
  1120. include "ssb_db/friends/" . $username . ".php";
  1121. echo "<table class='friendslist'>";
  1122. for($x = 1; $x <= $friendcount; $x++)
  1123. {
  1124. if(isset(${"friend" . $x})) {
  1125. echo "<tr><td><div class='avatar_small' style=\"background-image: url('index.php?do=avatarlocation&user=" . ${"friend" . $x} . "');\" title='User Avatar'></div></td><td><a class='button' href='index.php?userfeed=" . ${"friend" . $x} . "'>" . ${"friend" . $x} . "</a></td><td><a class='button' href='?do=privmsg&friend=" . ${"friend" . $x} . "'>Private message</a></td></tr>";
  1126. }
  1127. }
  1128. echo "</table>";
  1129. }
  1130. }
  1131. }
  1132. if($do=="login")
  1133. {
  1134. $username = $_POST['username'];
  1135. if(file_exists("ssb_db/users/$username.php")) {
  1136. include_once("ssb_db/users/$username.php");
  1137. if($user_password==sha1(md5($_POST['password']))) {
  1138. $pass = $user_password;
  1139. $user = $username;
  1140. $color = $user_color;
  1141. $_SESSION['ssb-user'] = $user;
  1142. $_SESSION['ssb-pass'] = $pass;
  1143. $_SESSION['ssb-color'] = $color;
  1144. header("Location: index.php");
  1145. } else {
  1146. echo "Wrong password!";
  1147. }
  1148. } else {
  1149. echo "User $username not found!";
  1150. }
  1151. }
  1152. if($do=="logout")
  1153. {
  1154. $_SESSION['ssb-user'] = null;
  1155. $_SESSION['ssb-pass'] = null;
  1156. header("Location: index.php?forms=login");
  1157. }
  1158. if($do=="register")
  1159. {
  1160. if($_POST['username']!="" && $_POST['password']!="" && $_POST['password-again']!="" && $_POST['fullname']!="" && isset($_POST['acct'])) {
  1161. if($_POST['password']==$_POST['password-again']) {
  1162. if(!preg_match('/[^a-z0-9]/i', $_POST['username'])) {
  1163. if(!file_exists("ssb_db/users/" . $_POST['username'] . ".php")) {
  1164. $colors = array("0000ff", "9900cc", "0080ff", "008000", "ededed");
  1165. $acct = $_POST['acct'];
  1166. file_put_contents("ssb_db/users/" . stripslashes(htmlentities($_POST['username'])) . ".php", "<?php\n\$accttype = \"" . $acct . "\";\n\$user_password = \"" . sha1(md5($_POST['password'])) . "\";\n \$user_color = \"" . $colors[array_rand($colors)] . "\"; \$user_fullname = \"" . stripslashes(htmlentities($_POST['fullname'])) . "\"; \$user_avatar = \"../../data/defaultprofile.png\"; \n?>");
  1167. file_put_contents("ssb_db/users/" . stripslashes(htmlentities($_POST['username'])) . ".name", stripslashes(htmlentities($_POST['username'])));
  1168. file_put_contents("ssb_db/users/" . stripslashes(htmlentities($_POST['username'])) . ".postnumber", "0");
  1169. file_put_contents("ssb_db/friends/" . stripslashes(htmlentities($_POST['username'])) . ".count", "0");
  1170. file_put_contents("ssb_db/friends/" . stripslashes(htmlentities($_POST['username'])) . ".php", "<?php ?>\n");
  1171. header("Location: index.php");
  1172. } else {
  1173. header("Location: index.php?notify=6");
  1174. }
  1175. } else {
  1176. header("Location: index.php?notify=5");
  1177. }
  1178. } else {
  1179. header("Location: index.php?notify=4");
  1180. }
  1181. } else {
  1182. header("Location: index.php?notify=3");
  1183. }
  1184. header("Location: index.php");
  1185. }
  1186. }
  1187. else if (!isset($_SESSION['ssb-user']) || !isset($_SESSION['ssb-pass']))
  1188. {
  1189. loginForm();
  1190. }
  1191. else
  1192. {
  1193. // Watch feed, lets generate pages while we're at it
  1194. $pagecall = $_GET['page'];
  1195. $postcount = 1;
  1196. if(isset($pagecall) && $pagecall!="")
  1197. {
  1198. if($pagecall == "1")
  1199. {
  1200. $poststart = $postcount;
  1201. }
  1202. else
  1203. {
  1204. $poststart = ($pagecall - 1) * 15; // 15 posts per page
  1205. }
  1206. }
  1207. else
  1208. {
  1209. $poststart = $postcount;
  1210. }
  1211. // Lets actually generate some feed now.
  1212. foreach(array_reverse(glob("ssb_db/posts/*.post")) as $postfile) {
  1213. $postphp = file_get_contents($postfile);
  1214. include "ssb_db/posts/$postphp";
  1215. $friendcount = file_get_contents("ssb_db/friends/" . $username . ".count");
  1216. include "ssb_db/friends/" . $username . ".php";
  1217. for($x = 1; $x <= $friendcount; $x++)
  1218. {
  1219. if($postowner == ${"friend" . $x}) {
  1220. // Found a post, post count goes up!
  1221. $postcount++;
  1222. if($poststart == "1" && $postcount < ($poststart + 15)) {
  1223. echo "<div class='post'><table><tr><td><div class='avatar_small' style=\"background-image: url('index.php?do=avatarlocation&user=$postowner');\" title='User Avatar'></div></td><td><h3>$postowner<span class='date'>$postdate &nbsp;&nbsp;";
  1224. if(file_exists("ssb_db/posts/$postid.reactcount")) {
  1225. $reacts = file_get_contents("ssb_db/posts/$postid.reactcount");
  1226. echo "<div class='reacts'><i class='fa fa-heart' style='color: red;'></i> $reacts <div class='react-list'>";
  1227. // Pull up users who reacted, and generate dropdown list.
  1228. $reactlist = fopen("ssb_db/posts/$postid.reacted", "r");
  1229. if($reactlist) {
  1230. while (($reactor = fgets($reactlist)) !== false) {
  1231. echo "<b>$reactor</b>";
  1232. }
  1233. fclose($reactlist);
  1234. }
  1235. echo "</div></div>";
  1236. }
  1237. echo "</span><br /><a onclick=\"userReact('" . $postowner . "', '" . $postid . "');\"><i class='fa fa-heart'></i></a> <a href='index.php?view=$postid&user=$postowner'><i class='fa fa-reply'></i></a></h3></td></tr></table>";
  1238. echo "" . bbcode_format($postcontent) . "";
  1239. // Footer
  1240. echo "<div class='post-footer'>";
  1241. echo "<a style='padding-top: 6px;' href='index.php?view=$postid&user=$postowner' class='button'><i class='fa fa-reply'></i>&nbsp;Comment</a>";
  1242. echo "<a style='padding-top: 6px;' onclick=\"userReact('" . $postowner . "','" . $postid . "');\" class='button'><i class='fa fa-heart'></i>&nbsp;React</a>";
  1243. echo "<br />"; // line break
  1244. if(file_exists("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count")) {
  1245. $pcount = file_get_contents("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count");
  1246. // If there's a reply, show them.
  1247. if($pcount == 0) {
  1248. echo "no replies";
  1249. } else if($pcount == 1) {
  1250. echo "$pcount reply";
  1251. } else if ($pcount > 0) {
  1252. echo "$pcount replies";
  1253. }
  1254. }
  1255. echo " &bull; ";
  1256. // Show reaction count in footer as well.
  1257. if(file_exists("ssb_db/posts/" . $postid . ".reactcount")) {
  1258. $reactcount = file_get_contents("ssb_db/posts/" . $postid . ".reactcount");
  1259. if($reactcount == 1) {
  1260. echo "$reactcount reaction";
  1261. } else if ($reactcount > 0) {
  1262. echo "$reactcount reactions";
  1263. }
  1264. } else {
  1265. echo "no reactions";
  1266. }
  1267. echo "</div></div><br />\n";
  1268. }
  1269. if($poststart > "1" && $postcount > $poststart && $postcount < ($poststart + 15)) {
  1270. echo "<div class='post'><table><tr><td><div class='avatar_small' style=\"background-image: url('index.php?do=avatarlocation&user=$postowner');\" title='User Avatar'></div></td><td><h3>$postowner<span class='date'>$postdate &nbsp;&nbsp;";
  1271. if(file_exists("ssb_db/posts/$postid.reactcount")) {
  1272. $reacts = file_get_contents("ssb_db/posts/$postid.reactcount");
  1273. echo "<div class='reacts'><i class='fa fa-heart' style='color: red;'></i> $reacts <div class='react-list'>";
  1274. // Pull up users who reacted, and generate dropdown list.
  1275. $reactlist = fopen("ssb_db/posts/$postid.reacted", "r");
  1276. if($reactlist) {
  1277. while (($reactor = fgets($reactlist)) !== false) {
  1278. echo "<b>$reactor</b>";
  1279. }
  1280. fclose($reactlist);
  1281. }
  1282. echo "</div></div>";
  1283. }
  1284. echo "</span><br /><a onclick=\"userReact('" . $postowner . "', '" . $postid . "');\"><i class='fa fa-heart'></i></a> <a href='index.php?view=$postid&user=$postowner'><i class='fa fa-reply'></i></a></h3></td></tr></table>";
  1285. echo "" . bbcode_format($postcontent) . "";
  1286. // Footer
  1287. echo "<div class='post-footer'>";
  1288. echo "<a style='padding-top: 6px;' href='index.php?view=$postid&user=$postowner' class='button'><i class='fa fa-reply'></i>&nbsp;Comment</a>";
  1289. echo "<a style='padding-top: 6px;' onclick=\"userReact('" . $postowner . "','" . $postid . "');\" class='button'><i class='fa fa-heart'></i>&nbsp;React</a>";
  1290. echo "<br />"; // line break
  1291. if(file_exists("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count")) {
  1292. $pcount = file_get_contents("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count");
  1293. // If there's a reply, show them.
  1294. if($pcount == 0) {
  1295. echo "no replies";
  1296. } else if($pcount == 1) {
  1297. echo "$pcount reply";
  1298. } else if ($pcount > 0) {
  1299. echo "$pcount replies";
  1300. }
  1301. }
  1302. echo " &bull; ";
  1303. // Show reaction count in footer as well.
  1304. if(file_exists("ssb_db/posts/" . $postid . ".reactcount")) {
  1305. $reactcount = file_get_contents("ssb_db/posts/" . $postid . ".reactcount");
  1306. if($reactcount == 1) {
  1307. echo "$reactcount reaction";
  1308. } else if ($reactcount > 0) {
  1309. echo "$reactcount reactions";
  1310. }
  1311. } else {
  1312. echo "no reactions";
  1313. }
  1314. echo "</div></div><br />\n";
  1315. }
  1316. }
  1317. }
  1318. if($postowner == $username)
  1319. {
  1320. // Found a post, post count goes up!
  1321. $postcount++;
  1322. if($poststart == "1" && $postcount < ($poststart + 15)) {
  1323. echo "<div class='post'><table><tr><td><div class='avatar_small' style=\"background-image: url('index.php?do=avatarlocation&user=$postowner');\" title='User Avatar'></div></td><td><h3>$postowner<span class='date'>$postdate &nbsp;&nbsp;";
  1324. if(file_exists("ssb_db/posts/$postid.reactcount")) {
  1325. $reacts = file_get_contents("ssb_db/posts/$postid.reactcount");
  1326. echo "<div class='reacts'><i class='fa fa-heart' style='color: red;'></i> $reacts <div class='react-list'>";
  1327. // Pull up users who reacted, and generate dropdown list.
  1328. $reactlist = fopen("ssb_db/posts/$postid.reacted", "r");
  1329. if($reactlist) {
  1330. while (($reactor = fgets($reactlist)) !== false) {
  1331. echo "<b>$reactor</b>";
  1332. }
  1333. fclose($reactlist);
  1334. }
  1335. echo "</div></div>";
  1336. }
  1337. echo "</span><br /><a onclick=\"userReact('" . $postowner . "', '" . $postid . "');\"><i class='fa fa-heart'></i></a> <a href='index.php?view=$postid&user=$postowner'><i class='fa fa-reply'></i></a> <a href='index.php?do=delpost&user=$username&pid=$postid'><i class='fa fa-trash-o'></i></a></h3></td></tr></table>";
  1338. echo "" . bbcode_format($postcontent) . "";
  1339. // Footer
  1340. echo "<div class='post-footer'>";
  1341. echo "<a style='padding-top: 6px;' href='index.php?view=$postid&user=$postowner' class='button'><i class='fa fa-reply'></i>&nbsp;Comment</a>";
  1342. echo "<a style='padding-top: 6px;' onclick=\"userReact('" . $postowner . "','" . $postid . "');\" class='button'><i class='fa fa-heart'></i>&nbsp;React</a>";
  1343. echo "<br />"; // line break
  1344. if(file_exists("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count")) {
  1345. $pcount = file_get_contents("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count");
  1346. // If there's a reply, show them.
  1347. if($pcount == 0) {
  1348. echo "no replies";
  1349. } else if($pcount == 1) {
  1350. echo "$pcount reply";
  1351. } else if ($pcount > 0) {
  1352. echo "$pcount replies";
  1353. }
  1354. }
  1355. echo " &bull; ";
  1356. // Show reaction count in footer as well.
  1357. if(file_exists("ssb_db/posts/" . $postid . ".reactcount")) {
  1358. $reactcount = file_get_contents("ssb_db/posts/" . $postid . ".reactcount");
  1359. if($reactcount == 1) {
  1360. echo "$reactcount reaction";
  1361. } else if ($reactcount > 0) {
  1362. echo "$reactcount reactions";
  1363. }
  1364. } else {
  1365. echo "no reactions";
  1366. }
  1367. echo "</div></div><br />\n";
  1368. }
  1369. if($poststart > "1" && $postcount > $poststart && $postcount < ($poststart + 15)) {
  1370. echo "<div class='post'><table><tr><td><div class='avatar_small' style=\"background-image: url('index.php?do=avatarlocation&user=$postowner');\" title='User Avatar'></div></td><td><h3>$postowner<span class='date'>$postdate &nbsp;&nbsp;";
  1371. if(file_exists("ssb_db/posts/$postid.reactcount")) {
  1372. $reacts = file_get_contents("ssb_db/posts/$postid.reactcount");
  1373. echo "<div class='reacts'><i class='fa fa-heart' style='color: red;'></i> $reacts <div class='react-list'>";
  1374. // Pull up users who reacted, and generate dropdown list.
  1375. $reactlist = fopen("ssb_db/posts/$postid.reacted", "r");
  1376. if($reactlist) {
  1377. while (($reactor = fgets($reactlist)) !== false) {
  1378. echo "<b>$reactor</b>";
  1379. }
  1380. fclose($reactlist);
  1381. }
  1382. echo "</div></div>";
  1383. }
  1384. echo "</span><br /><a onclick=\"userReact('" . $postowner . "', '" . $postid . "');\"><i class='fa fa-heart'></i></a> <a href='index.php?view=$postid&user=$postowner'><i class='fa fa-reply'></i></a> <a href='index.php?do=delpost&user=$username&pid=$postid'><i class='fa fa-trash-o'></i> </a></h3></td></tr></table>";
  1385. echo "" . bbcode_format($postcontent) . "";
  1386. // Footer
  1387. echo "<div class='post-footer'>";
  1388. echo "<a style='padding-top: 6px;' href='index.php?view=$postid&user=$postowner' class='button'><i class='fa fa-reply'></i>&nbsp;Comment</a>";
  1389. echo "<a style='padding-top: 6px;' onclick=\"userReact('" . $postowner . "','" . $postid . "');\" class='button'><i class='fa fa-heart'></i>&nbsp;React</a>";
  1390. echo "<br />"; // line break
  1391. if(file_exists("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count")) {
  1392. $pcount = file_get_contents("ssb_db/posts/reply_" . $postowner . "_" . $postid . ".count");
  1393. // If there's a reply, show them.
  1394. if($pcount == 0) {
  1395. echo "no replies";
  1396. } else if($pcount == 1) {
  1397. echo "$pcount reply";
  1398. } else if ($pcount > 0) {
  1399. echo "$pcount replies";
  1400. }
  1401. }
  1402. echo " &bull; ";
  1403. // Show reaction count in footer as well.
  1404. if(file_exists("ssb_db/posts/" . $postid . ".reactcount")) {
  1405. $reactcount = file_get_contents("ssb_db/posts/" . $postid . ".reactcount");
  1406. if($reactcount == 1) {
  1407. echo "$reactcount reaction";
  1408. } else if ($reactcount > 0) {
  1409. echo "$reactcount reactions";
  1410. }
  1411. } else {
  1412. echo "no reactions";
  1413. }
  1414. echo "</div></div><br />\n";
  1415. }
  1416. }
  1417. }
  1418. // Page button generation
  1419. echo "<div class='page-controls'>";
  1420. if($poststart > "1") {
  1421. $prevpage = $poststart / 15;
  1422. echo "<a href='index.php?page=$prevpage'><i class='fa fa-arrow-left'></i> &nbsp; Prev page</a>";
  1423. }
  1424. echo "&nbsp;&nbsp;&nbsp;";
  1425. if($poststart == "1" && $postcount > ($poststart + 15)) {
  1426. echo "<a href='index.php?page=2'>Next page &nbsp; <i class='fa fa-arrow-right'></i></a>";
  1427. }
  1428. if($poststart > "1" && $postcount > ($poststart + 15)) {
  1429. $nextpage = ($poststart / 15) + 2;
  1430. echo "<a href='index.php?page=$nextpage'>Next page &nbsp; <i class='fa fa-arrow-right'></i></a>";
  1431. }
  1432. echo "</div>";
  1433. }
  1434. ?>
  1435. <br /><br />
  1436. <center style="background-color: #555555; padding 3px;">Powered By SSB <?php echo $version; ?></center>
  1437. </div>
  1438. </div> <!-- main contain -->
  1439. </body>
  1440. </html>