home.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <?php
  2. include_once 'auth.php';
  3. //Get information of local data storage from auth.php
  4. $userAccountName = $_SESSION['login'];
  5. $dataStorage = $sysConfigDir . '/userdata/' . $_SESSION['login'] . "/";
  6. if (!file_exists($dataStorage)){
  7. //如果使用者是第一次使用 TeaBag,幫他開個新資料夾,並創建用家資料檔
  8. mkdir($dataStorage,0777,true);
  9. file_put_contents($dataStorage . "userdata.json",'{"username":"' . $userAccountName .'",
  10. "accountCreationTime":"' . time() . '",
  11. "invitedByUser":"Admin",
  12. "permissionLevel":3,
  13. "banned":false
  14. }');
  15. include_once("functions/createUserDirectories.php");
  16. }
  17. date_default_timezone_set("Asia/Hong_Kong");
  18. $time = date("Y-m-d H:m:s");
  19. include_once("getUserImage.php"); //Handle user image location. Call with getUserIconpath()
  20. $userIcon = getUserIconPath();
  21. ?>
  22. <html>
  23. <head>
  24. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  25. <title>TeaBag.tw</title>
  26. <link rel="stylesheet" href="script/tocas/tocas.css">
  27. <script src="script/tocas/tocas.js"></script>
  28. <script src="script/jquery.min.js"></script>
  29. <script>
  30. var activeChat = "";
  31. function showChat(id) {
  32. //alert(id + "," + activeChat);
  33. if (activeChat == id){
  34. $("#chatPop").hide();
  35. activeChat = "";
  36. }else{
  37. $("#chatPop").show();
  38. activeChat = id;
  39. }
  40. refresh();
  41. document.getElementById("chatTarget").innerHTML = activeChat;
  42. //Scroll to the bottom of the chat record
  43. setTimeout(function(){
  44. $('#chatHistory').scrollTop($('#chatHistory')[0].scrollHeight);
  45. },500);
  46. }
  47. function update() {
  48. var xhttp = new XMLHttpRequest();
  49. xhttp.onreadystatechange = function() {
  50. if (this.readyState == 4 && this.status == 200) {
  51. document.getElementById("chatHistory").innerHTML = this.responseText;
  52. }
  53. };
  54. var touser = activeChat;
  55. var fromuser = "<?php echo $_SESSION['login'];?>";
  56. var myText = document.getElementById("message").value;
  57. if(myText != "" && myText != null)
  58. {
  59. xhttp.open("POST", "getChatHistory.php", true);
  60. xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  61. xhttp.send("touser="+touser+"&fromuser="+fromuser+"&message="+myText);
  62. //Scroll to the bottom of the chat record
  63. setTimeout(function(){
  64. $('#chatHistory').scrollTop($('#chatHistory')[0].scrollHeight);
  65. },500);
  66. }
  67. document.getElementById("message").value = "";
  68. var objDiv = document.getElementById("chatHistory");
  69. objDiv.scrollTop = objDiv.scrollHeight;
  70. }
  71. function refresh() {
  72. var xhttp = new XMLHttpRequest();
  73. xhttp.onreadystatechange = function() {
  74. if (this.readyState == 4 && this.status == 200) {
  75. document.getElementById("chatHistory").innerHTML = this.responseText;
  76. }
  77. };
  78. var touser = activeChat;
  79. var fromuser = "<?php echo $_SESSION['login']; ?>";
  80. xhttp.open("POST", "getChatHistory.php", true);
  81. xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  82. xhttp.send("touser="+touser+"&fromuser="+fromuser);
  83. }
  84. setInterval(refresh,1000);
  85. </script>
  86. <style>
  87. .extrapadding{
  88. padding-left:10%;
  89. padding-right:10%;
  90. }
  91. .removePadding{
  92. padding:0px !important;
  93. }
  94. .active.item{
  95. color:#4287f5 !important;
  96. font-weight: bold !important;
  97. }
  98. .postAvator{
  99. height:50px !important;
  100. padding-right:25px;
  101. }
  102. .teabag.card{
  103. max-width:350px;
  104. }
  105. .nopadding{
  106. padding:0px !important;
  107. }
  108. .selectable{
  109. cursor:pointer;
  110. padding:5px !important;
  111. }
  112. .selectable:hover{
  113. background-color:#f2f2f2 !important;
  114. }
  115. .online{
  116. color: #88db99;
  117. }
  118. .linebreak{
  119. white-space: pre-wrap;
  120. }
  121. .chatroomWindow{
  122. display:none;
  123. width:320px !important;
  124. height:500px !important;
  125. padding:5px !important;
  126. position:fixed;
  127. bottom:0;
  128. right:0;
  129. z-index: 99 !important;
  130. border-style: solid;
  131. border-width: 1px;
  132. background-color: white;
  133. }
  134. .chathistory{
  135. width:305px !important;
  136. height:300px !important;
  137. padding:5px !important;
  138. border: 1px solid #000;
  139. overflow-y: scroll;
  140. }
  141. .typing {
  142. border: 1px solid #000;
  143. padding:5px !important;
  144. width:305px !important;
  145. }
  146. </style>
  147. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  148. <meta name="viewport" content="width=device-width, initial-scale=1">
  149. <meta name="description" content="">
  150. <meta name="author" content="">
  151. <link rel="shortcut icon" href="favicon.png">
  152. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  153. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
  154. <!-- Begin emoji-picker Stylesheets -->
  155. <link href="script/css/emoji.css" rel="stylesheet">
  156. <!-- End emoji-picker Stylesheets -->
  157. </head>
  158. <body>
  159. <div class="ts tabbed menu extrapadding">
  160. <a class="item" href="index.php"><img src="img/minilogo.png" style="height:25px;"></a>
  161. <a class="active item" href="home.php"><i class="home icon"></i> Following</a>
  162. <a class="item" href="index.php"><i class="user outline icon"></i>Timeline</a>
  163. <a class="item" href="fdList.php"><i class="users outline icon"></i>Friend List</a>
  164. <div class="right item removePadding">
  165. <a class="item" href="logout.php"><i class="log out icon"></i>Logout</a>
  166. </div>
  167. </div>
  168. <div class="ts container">
  169. <div class="ts grid">
  170. <div class="four wide column">
  171. <div class="ts teabag card">
  172. <div class="image">
  173. <img src="<?php echo $userIcon;?>" style="max-width:300px;">
  174. </div>
  175. <div class="content">
  176. <div class="ts comments">
  177. <div class="comment">
  178. <div class="avatar">
  179. <img src="<?php echo $userIcon; ?>">
  180. </div>
  181. <div class="content">
  182. <a class="author"><?php include_once("functions/getUserName.php");?></a>
  183. <div class="text">@<?php echo $_SESSION['login']; ?></div>
  184. </div>
  185. </div>
  186. </div>
  187. <button class="ts basic mini button" onClick='$("#changeIconDiv").slideToggle();'>Change Icon</button>
  188. <div id="changeIconDiv" style="display:none;">
  189. <iframe src="uploadIcon.php">
  190. </iframe>
  191. </div>
  192. </div>
  193. </div>
  194. <!-- Advertisment -->
  195. <div class="ts segment" style='height:300px; overflow-y:auto;'>
  196. <?php
  197. include_once("loadads.php");
  198. $adspath = initAds();
  199. echo '<img class="ts fluid image" src="'. $adspath .'"/>';
  200. ?>
  201. </div>
  202. <!-- Chatroom List-->
  203. <div class="ts segment" style='height:300px; overflow-y:auto;'>
  204. <?php
  205. $query = "select * from following where followerName = '".$_SESSION['login']. "'";
  206. include_once("requestDB.php"); //Handle all Database access, see the query command below
  207. $followerResult = query($query,"teabag");
  208. foreach ($followerResult as $chat){
  209. echo '
  210. <div class="ts nopadding comments">
  211. <div class="comment selectable">
  212. <a class="avatar">
  213. <img src="img/dummy.png">
  214. </a>
  215. <div class="content">
  216. <a class="author">'.$chat["targetName"].'</a>
  217. <div class="inline text">
  218. 現時在線
  219. </div>
  220. <div class="middoted actions">
  221. <a id="'.$chat["targetName"].'" onClick="showChat(this.id);">
  222. <i class="comment online icon"></i> 打開聊天室
  223. </a>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. ';
  229. }
  230. ?>
  231. <!--
  232. <div class="ts nopadding comments">
  233. <div class="comment selectable">
  234. <a class="avatar">
  235. <img src="img/dummy.png">
  236. </a>
  237. <div class="content">
  238. <a class="author">小白</a>
  239. <div class="inline text">
  240. 現時在線
  241. </div>
  242. <div class="middoted actions">
  243. <a>
  244. <i class="comment online icon"></i> 打開聊天室
  245. </a>
  246. </div>
  247. </div>
  248. </div>
  249. <div class="comment selectable">
  250. <a class="avatar">
  251. <img src="img/dummy.png">
  252. </a>
  253. <div class="content">
  254. <a class="author">小綠</a>
  255. <div class="inline text">
  256. 10分鐘前在線
  257. </div>
  258. <div class="middoted actions">
  259. <a>
  260. <i class="comment icon"></i> 留言
  261. </a>
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. -->
  267. </div>
  268. </div>
  269. <div class="twelve wide column">
  270. <?php
  271. //Show all the other's post in this page
  272. include_once("requestDB.php"); //Handle all Database access, see the query command below
  273. $username = $_SESSION['login'];
  274. $postData = query("select * from post where (username IN (SELECT `targetName` FROM `following` WHERE `followerName`='" . $username . "')) OR username='" . $username . "' ORDER BY postid DESC","teabag");
  275. include_once("getUserImage.php");
  276. foreach ($postData as $post){
  277. //Get the number of comments on this object
  278. $pid = $post["postid"];
  279. $commentLength = query("SELECT COUNT(*) FROM comments WHERE postid='" . $pid . "'","teabag");
  280. $commentNumber = $commentLength[0]["COUNT(*)"];
  281. echo '
  282. <div class="ts card" style="margin-bottom:0px; !important">
  283. <div class="content">
  284. <div class="header"><img class="ts image postAvator" src="' . getUserIconPathByUsername($post["username"]) .'" style="margin-right:-20px;width:80px;height:80px;">' . $post["username"] . '</div>
  285. <div class="meta">
  286. <a>@ '.$post["posttime"].'</a>
  287. </div>
  288. <div class="description">
  289. <p>'.$post["content"].'</p>
  290. </div>
  291. </div>
  292. </div>
  293. ';
  294. if ($commentNumber > 0){
  295. //There is comment on this post
  296. echo '<div class="ts primary attached message" style="margin-top:0px; !important">
  297. <p>' . $commentNumber . ' people has commented this post. <a href="comment.php?post=' . $pid . '">CLICK HERE to share yours?</a></p>
  298. </div>';
  299. }else{
  300. echo '<div class="ts attached message" style="margin-top:0px; !important">
  301. <a href="comment.php?post=' . $pid . '">Leave a comment</a>
  302. </div>';
  303. }
  304. }
  305. ?>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. <div class="chatroomWindow" id="chatPop" style="position:fixed;right:0px;bottom:0px;z-index:999;">
  311. <script>
  312. refresh();
  313. </script>
  314. <div id="chatHistory" class="chathistory"></div>
  315. <form name="message" method="post">
  316. <a id="chatTarget" class="author"></a><br/>
  317. <p class="lead emoji-picker-container"><textarea rows="4" placeholder="Write something here to chat!" name="message" cols="40" class="typing" id="message" data-emojiable="true"></textarea></p>
  318. <input type="button" onclick="update()" class="ts primary fluid button" value="Send">
  319. </form>
  320. </div>
  321. </body>
  322. </html>