Преглед изворни кода

TC:Added improvement on post read and OOP of db access

Toby Chui пре 5 година
родитељ
комит
3daebe5ded

+ 108 - 0
db/teabag-4-11-2019.sql

@@ -0,0 +1,108 @@
+-- phpMyAdmin SQL Dump
+-- version 4.5.5.1
+-- http://www.phpmyadmin.net
+--
+-- 主機: 127.0.0.1
+-- 產生時間: 2019-11-04 05:41:42
+-- 伺服器版本: 5.7.11
+-- PHP 版本: 5.6.19
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- 資料庫: `teabag`
+--
+
+-- --------------------------------------------------------
+
+--
+-- 資料表結構 `chat`
+--
+
+CREATE TABLE `chat` (
+  `fromuser` varchar(20) NOT NULL,
+  `touser` varchar(20) NOT NULL,
+  `content` varchar(200) NOT NULL,
+  `sendtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+--
+-- 資料表的匯出資料 `chat`
+--
+
+INSERT INTO `chat` (`fromuser`, `touser`, `content`, `sendtime`) VALUES
+('admin', 'kent', 'Hi Kent, how are you doing?', '2019-11-04 05:39:35');
+
+-- --------------------------------------------------------
+
+--
+-- 資料表結構 `following`
+--
+
+CREATE TABLE `following` (
+  `followerName` varchar(20) NOT NULL,
+  `targetName` varchar(20) NOT NULL,
+  `banned` tinyint(1) NOT NULL DEFAULT '0',
+  `followDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+--
+-- 資料表的匯出資料 `following`
+--
+
+INSERT INTO `following` (`followerName`, `targetName`, `banned`, `followDate`) VALUES
+('admin', 'kent', 0, '2019-11-04 05:39:50'),
+('kent', 'admin', 0, '2019-11-04 05:39:57');
+
+-- --------------------------------------------------------
+
+--
+-- 資料表結構 `post`
+--
+
+CREATE TABLE `post` (
+  `postid` int(11) NOT NULL,
+  `username` varchar(20) NOT NULL,
+  `content` varchar(200) NOT NULL,
+  `posttime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+--
+-- 資料表的匯出資料 `post`
+--
+
+INSERT INTO `post` (`postid`, `username`, `content`, `posttime`) VALUES
+(2, 'admin', 'Hello World Welcome to Teabag!', '2019-11-04 05:17:32'),
+(3, 'admin', 'This is my 2nd meme post haha!', '2019-11-04 05:17:44');
+
+--
+-- 已匯出資料表的索引
+--
+
+--
+-- 資料表索引 `post`
+--
+ALTER TABLE `post`
+  ADD PRIMARY KEY (`postid`),
+  ADD UNIQUE KEY `postid` (`postid`),
+  ADD KEY `postid_2` (`postid`);
+
+--
+-- 在匯出的資料表使用 AUTO_INCREMENT
+--
+
+--
+-- 使用資料表 AUTO_INCREMENT `post`
+--
+ALTER TABLE `post`
+  MODIFY `postid` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

+ 0 - 8
src/auth.php

@@ -1,12 +1,4 @@
 <?php
-/*
-ArOZ Online Auth Script
-This script is designed to provide all auth function for the whole ArOZ Online System
-Please do not modify this script unless you know what you are doing.
-
-CopyRight ArOZ Online Project feat. IMUS Laboratory, All right reserved.
-Developed by Toby Chui since 2016
-*/
 
 //Uncomment the following line for emergency terminating all services on ArOZ Online System
 //header("HTTP/1.0 503 Service Unavailable"); echo "<p>ArOZ Online System on this site has been emergency shut down by system administrator.</p>"; exit(0);

+ 13 - 0
src/getUserImage.php

@@ -0,0 +1,13 @@
+<?php
+include_once(__DIR__ . "/auth.php");
+function getUserIconPath(){
+	global $sysConfigDir;
+	$username = $_SESSION['login'];
+	if (file_exists("$sysConfigDir/userdata/$username/files/image/usericon.png")){
+		return "$sysConfigDir/userdata/$username/files/image/usericon.png";
+	}else{
+		return "img/user.jpg";
+	}
+}
+
+?>

BIN
src/img/auth_icon.png



+ 25 - 48
src/index.php

@@ -16,6 +16,9 @@ if (!file_exists($dataStorage)){
 }
 date_default_timezone_set("Asia/Hong_Kong");
 $time = date("Y-m-d H:m:s");
+
+include_once("getUserImage.php"); //Handle user image location. Call with getUserIconpath()
+$userIcon = getUserIconPath();
 ?>
 <html>
 <head>
@@ -65,15 +68,15 @@ $time = date("Y-m-d H:m:s");
 <body>
 <div class="ts tabbed menu extrapadding">
 	<a class="item" href="index.php"><img src="img/minilogo.png" style="height:25px;"></a>
-    <a class="active item" href="index.php"><i class="home icon"></i> 主頁</a>
-    <a class="item"><i class="user outline icon"></i>個人檔案</a>
-	<a class="item"><i class="mail outline icon"></i>通知</a>
+    <a class="active item" href="index.php"><i class="home icon"></i> Home</a>
+    <a class="item"><i class="user outline icon"></i>Timeline</a>
+	<a class="item"><i class="mail outline icon"></i>Notification</a>
 	<div class="right item removePadding">
 	<div class="ts icon tiny input">
-		<input type="text" placeholder="搜尋...">
+		<input type="text" placeholder="Search...">
 		<i class="circular search link icon"></i>
 	</div>
-	<a class="item" href="logout.php"><i class="log out icon"></i>登出</a>
+	<a class="item" href="logout.php"><i class="log out icon"></i>Logout</a>
 	</div>
 </div>
 <div class="ts container">
@@ -82,13 +85,13 @@ $time = date("Y-m-d H:m:s");
 		<!-- 個人檔案卡 -->
 		<div class="ts teabag card">
 			<div class="image">
-				<img src="functions/contentDelivery.php?filename=user/profile/banner.png&time=<?php echo time();?>" style="max-width:300px;">
+				<img src="<?php echo $userIcon;?>" style="max-width:300px;">
 			</div>
 			<div class="content">
 				<div class="ts comments">
 					<div class="comment">
 						<div class="avatar">
-							<img src="img/dummy.png">
+							<img src="<?php echo $userIcon; ?>">
 						</div>
 						<div class="content">
 							<a class="author"><?php include_once("functions/getUserName.php");?></a>
@@ -137,62 +140,36 @@ $time = date("Y-m-d H:m:s");
 		</div>
 	</div>
     <div class="twelve wide column">
-		<!-- 帖子 -->
 		<div class="ts text container">
 		<div class="ts segment">
 			<div class="ts form">
 				<form name="message" action="updateSql.php" method="post">
 				<div class="field">
-					<label>分享帖子</label>
-					<textarea rows="4" placeholder="要說點甚麼嗎?" name="message" cols="40"></textarea>
+					<label>Share Post</label>
+					<textarea rows="4" placeholder="Want to share something?" name="message" cols="40"></textarea>
 				</div>
-				<input type="submit" class="ts primary fluid button" value="發帖">
+				<input type="submit" class="ts primary fluid button" value="Post">
 				</form>
 			</div>
 		</div>
-		<!--
-		<div class="ts card">
-			<div class="content">
-				<div class="header"><img class="ts circular image postAvator" src="img/dummy.png">不是小安</div>
-				<div class="meta">
-					<a>@not-yami</a>
-					<a>30/6/2019 15:24:00</a>
-				</div>
-				<div class="description">
-					<p>你將會在這裡看見一個魔法師的日常生活,</p>
-					<p>沒錯,只要你能夠單身三十年,</p>
-					<p>你也可以跟我一樣成為魔法師。</p>
-				</div>
-			</div>
-		</div>
-		-->
 		<?php
-			$conn = mysqli_connect("localhost","root","","message");
-			if($conn->connect_error)
-			{
-				echo "Unable to connect to database";
-				exit;
-			}
-			$result = $conn->query("select * from message");
-			if(!$result) die("No message");
-			$result->data_seek(0);
-			while($row=$result->fetch_assoc())
-			{
+			include_once("requestDB.php"); //Handle all Database access, see the query command below
+			$postData = query("select * from post where username='" . $_SESSION['login'] . "' ORDER BY postid DESC","teabag");
+			foreach ($postData as $post){
 				echo '
 				<div class="ts card">
-				<div class="content">
-				<div class="header"><img class="ts circular image postAvator" src="img/dummy.png"></div>
-				<div class="meta">
-					<a>'.$row["user"].'</a>
-					<a>'.$row["datetime"].'</a>
-				</div>
-				<div class="linebreak" >'.$row["messgae"].'
-				</div>
-				</div>
+					<div class="content">
+						<div class="header"><img class="ts circular image postAvator" src="' . $userIcon .'" style="margin-right:-20px;">' . $post["username"] . '</div>
+						<div class="meta">
+							<a>@ '.$post["posttime"].'</a>
+						</div>
+						<div class="description">
+							<p>'.$post["content"].'</p>
+						</div>
+					</div>
 				</div>
 				';
 			}
-			$conn->close();
 		?>
 	   </div>
 	</div>

+ 10 - 19
src/login.php

@@ -1,7 +1,7 @@
 <!DOCTYPE HTML>
 <head>
 <meta name="viewport" content="width=device-width, initial-scale=0.7, shrink-to-fit=no">
-<title>TeagBag 歡迎回來</title>
+<title>TeagBag Welcome back</title>
 <link rel="stylesheet" href="script/tocas/tocas.css">
 <script src="script/paperjs/paper-full.min.js"></script>
 <script src="script/tocas/tocas.js"></script>
@@ -88,13 +88,13 @@ if (file_exists("SystemAOB/functions/personalization/sysconf/login.config")){
 	<br><br><br>
 		<img class="ts medium image" src="<?php echo $titleImg;?>">
 		<br><br>
-		<p><i class="privacy icon"></i>使用你的 TeaBag 帳戶和密碼來登入:</p>
+		<p><i class="privacy icon"></i>Please login with your TeaBag account</p>
 		<?php //print_r($_COOKIE); //Debug only
 			$autoLogin = true;
 		?>
 		<br>
 		<div class="ts fluid input textbox">
-			<input id="username" type="text" placeholder="帳戶名稱" style="border-radius: 0px !important;" value="<?php 
+			<input id="username" type="text" placeholder="Username" style="border-radius: 0px !important;" value="<?php 
 			if (isset($_COOKIE['username']) && $_COOKIE['username'] != ""){
 				echo $_COOKIE['username'];
 			}else{
@@ -104,7 +104,7 @@ if (file_exists("SystemAOB/functions/personalization/sysconf/login.config")){
 		</div>
 		<br><br>
 		<div class="ts fluid input textbox">
-			<input id="password" type="password" placeholder="密碼" style="border-radius: 0px !important;" value="<?php 
+			<input id="password" type="password" placeholder="Password" style="border-radius: 0px !important;" value="<?php 
 			if (isset($_COOKIE['password']) && $_COOKIE['password'] != ""){
 				echo $_COOKIE['password'];
 			}else{
@@ -123,30 +123,21 @@ if (file_exists("SystemAOB/functions/personalization/sysconf/login.config")){
 			}
 		?>
             
-            <label for="rmbme">保持登入狀態</label>
+            <label for="rmbme">Remember Me</label>
         </div><br><br>
 		<div id="errmsg" style="color:#4287f5;"></div>
 		<br>
-		<button class="ts primary button" style="background-color:#4287f5;border-width: 0px;" onClick="postLogin();">登入</button><br><br>
-		<small>沒有帳號? 按<a href="how2regi.html">這裡</a>了解如何注冊一個!</small>
+		<button class="ts primary button" style="background-color:#4287f5;border-width: 0px;" onClick="postLogin();">Login</button><br><br>
+		
 		<?php
 		$template = '<div class="ts outlined message">
-			<div id="logoutmsg" style="color:#3fb7e2;"><i class="log out icon"></i>你已經成功登出。</div>
+			<div id="logoutmsg" style="color:#3fb7e2;"><i class="log out icon"></i>You have been logged out。</div>
 		</div>';
 		if (isset($_GET['logout'])){
 			echo $template;
 		}
 		?>
 		
-		<div class="bottombar">
-		© 系統底層基於 ArOZ Online 計劃 2019 feat. <a href="http://imuslab.com/" target="_blacnk">IMUS Laboratory</a><br>
-		<div style="display:inline;font-size:80%;"><?php 
-		if ($ipdebug){
-		    echo "<i class='disk outline icon'></i> " . $_SERVER['SERVER_NAME'] . ' ⇄ <i class="laptop icon"></i>' . $_SERVER['REMOTE_ADDR'];
-		}
-		?></div>
-		<br><br>
-		</div>
 	</div>
 	
 <script>
@@ -177,11 +168,11 @@ function postLogin(){
 			if (data.includes("Username not find")){
 				$("#username").parent().addClass("error");
 				$("#password").parent().removeClass("error");
-				showErrorMsg("<i class='close icon'></i> 找不到此帳戶。");
+				showErrorMsg("<i class='close icon'></i> Account not found.");
 			}else if (data.includes("Password incorrect")){
 				$("#password").parent().addClass("error");
 				$("#username").parent().removeClass("error");
-				showErrorMsg("<i class='close icon'></i> 密碼輸入錯誤。");
+				showErrorMsg("<i class='close icon'></i> Password Incorrect.");
 			}
 		}
 		if (data.includes("DONE")){

+ 30 - 0
src/requestDB.php

@@ -0,0 +1,30 @@
+<?php
+
+function query($query,$table){
+	$conn = mysqli_connect("localhost","teabag","teabagpassword",$table);
+	if($conn->connect_error)
+	{
+		echo "Unable to connect to database";
+		exit;
+	}
+	$result = $conn->query($query);
+	if(!$result) die("ERROR");
+	$result->data_seek(0);
+	//header('Content-Type: application/json');
+	$data = [];
+	while($row=$result->fetch_assoc())
+	{
+		array_push($data,$row);
+	}
+	//echo json_encode($data);
+	return $data;
+	$conn->close();
+} 
+
+//Test Code, uncomment this section if you want to test query function with javascript, not recommended
+/*
+if (isset($_GET['query']) && isset($_GET['table'])){
+	query($_GET['query'],$_GET['table']);
+}
+*/
+?>

+ 1 - 0
src/userdata/cookieseeds/1573016367.auth

@@ -0,0 +1 @@
+68c9b7876528a35fb7e10beb828a21ca193941eb5aad37bb978d12e1730310264235a40c05a15df8822cf7c6f4ef38296e2ca092ea0d811e65136a760a10d574

+ 1 - 0
src/userdata/cookieseeds/1573016549.auth

@@ -0,0 +1 @@
+1e60459c3471fafac155c1b59c0d9917b2391a6a4b81b7f28bd057b554e58102b3cfad888f5b14cc6fafca069a0c89da8b705084dccaaeb267780b646ecd2a01

+ 1 - 0
src/userdata/userdata/admin/user/profile/displayname.inf

@@ -0,0 +1 @@
+admin

+ 6 - 0
src/userdata/userdata/admin/userdata.json

@@ -0,0 +1,6 @@
+{"username":"admin",
+	  "accountCreationTime":"1572843567",
+	  "invitedByUser":"Admin",
+	  "permissionLevel":3,
+	  "banned":false
+	}

+ 1 - 0
src/userdata/whitelist.config

@@ -1 +1,2 @@
 kent,D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB
+admin,C7AD44CBAD762A5DA0A452F9E854FDC1E0E7A52A38015F23F3EAB1D80B931DD472634DFAC71CD34EBC35D16AB7FB8A90C81F975113D6C7538DC69DD8DE9077EC