mirror of https://github.com/pikami/palm-paste.git
Users now have their own profile pages
This commit is contained in:
parent
8690bd730c
commit
713198629c
|
@ -1,3 +1,5 @@
|
||||||
Options +FollowSymlinks
|
Options +FollowSymlinks
|
||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
|
RewriteBase "/paste/"
|
||||||
|
RewriteRule ^u/([A-Za-z0-9-]+)/?$ index.php?user=$1
|
||||||
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1
|
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
<div class="container">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-body">
|
||||||
|
<?php
|
||||||
|
include_once "config/config.php";
|
||||||
|
include_once "includes/user.php";
|
||||||
|
$conn = GetConnectionToDB();
|
||||||
|
|
||||||
|
$ownerID = GetUserIDByName($_GET["user"]);
|
||||||
|
if($ownerID!=-1){
|
||||||
|
//== Print user info ==//
|
||||||
|
$owner = GetUserByID($ownerID);
|
||||||
|
printf('<h2>'.$owner["user"].'\'s profile</h2>');
|
||||||
|
//== Print pastes ==//
|
||||||
|
$query = "SELECT * FROM pastes WHERE owner=:own AND exposure=0";
|
||||||
|
if(GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"]) == $ownerID)$query = "SELECT * FROM pastes WHERE owner=:own";
|
||||||
|
$stmt = $conn->prepare($query);
|
||||||
|
$stmt->bindParam(':own', $ownerID);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
if($stmt->rowCount()>0){
|
||||||
|
echo "<table id=\"tablepastes\" class=\"table table-striped\" style=\"width:100%\">";
|
||||||
|
printf('<thead><th data-dynatable-column="name" style="text-align: left;">Title</th>
|
||||||
|
<th style="text-align: left;">Added</th>
|
||||||
|
<th style="text-align: left;">Expires</th>
|
||||||
|
<th style="text-align: left;">ID</th></thead>');
|
||||||
|
printf('<tbody>');
|
||||||
|
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
$title = $row['title'];
|
||||||
|
printf('<tr><td style="text-align: left;">'.htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8').'</td>');
|
||||||
|
printf('<td style="text-align: left;">'.date('Y-m-d',$row["created"]).'</td>');
|
||||||
|
if($row["expire"]==0) printf('<td style="text-align: left;">Never</td>');
|
||||||
|
else{
|
||||||
|
$expire = ($row["expire"]-time())/3600;
|
||||||
|
if($expire>24){
|
||||||
|
printf('<td style="text-align: left;">'.round($expire/24).' days from now</td>');
|
||||||
|
} else if($expire>=1)
|
||||||
|
printf('<td style="text-align: left;">'.round($expire).' hours from now</td>');
|
||||||
|
else printf('<td style="text-align: left;">'.round($expire*60).' minutes from now</td>');
|
||||||
|
}
|
||||||
|
printf('<td style="text-align: right;"><a href="../'.htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8').'">'.htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8').'</a></td></tr>');
|
||||||
|
}
|
||||||
|
printf('</tbody></talbe>');
|
||||||
|
} else {
|
||||||
|
printf('<h2>This user has no public pastes!</h2>');
|
||||||
|
}
|
||||||
|
} else printf('<h2>User does not exist!</h2>');
|
||||||
|
$conn = null;
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -26,7 +26,7 @@ if(isset($uid)){
|
||||||
echo "<h5>";
|
echo "<h5>";
|
||||||
if($owner[1] == -1)
|
if($owner[1] == -1)
|
||||||
echo "Posted by: <b>Guest</b>";
|
echo "Posted by: <b>Guest</b>";
|
||||||
else echo "Posted by: <b>".htmlspecialchars($owner[1])."</b>";
|
else echo "Posted by: <b><a href=\"u/".htmlspecialchars($owner[1])."\">".htmlspecialchars($owner[1])."</a></b>";
|
||||||
echo ", at ".date('Y-m-d',$result["created"]).", it will expire <b>";
|
echo ", at ".date('Y-m-d',$result["created"]).", it will expire <b>";
|
||||||
if($result["expire"]==0) printf('Never');
|
if($result["expire"]==0) printf('Never');
|
||||||
else{
|
else{
|
||||||
|
|
|
@ -42,4 +42,18 @@ function GetUserByID($id){
|
||||||
return array(-1,-1,-1,-1);
|
return array(-1,-1,-1,-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function GetUserIDByName($name){
|
||||||
|
include_once "config/config.php";
|
||||||
|
$conn = GetConnectionToDB();
|
||||||
|
$stmt = $conn->prepare("SELECT * FROM users WHERE user=:name");
|
||||||
|
$stmt->bindParam(':name', $name);
|
||||||
|
$stmt->execute();
|
||||||
|
if($result = $stmt->fetch()){
|
||||||
|
$conn = null;
|
||||||
|
return $result[0];
|
||||||
|
} else {
|
||||||
|
$conn = null;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
54
index.php
54
index.php
|
@ -3,31 +3,41 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Palm-Paste Index</title>
|
<title>Palm-Paste Index</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<?php
|
||||||
<link rel="stylesheet" href="css/bootstrap.min.css">
|
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
|
$dir = "";
|
||||||
<script src="js/bootstrap.min.js"></script>
|
if (isset($_GET["user"]))$dir="../";
|
||||||
<script type="text/javascript" src="js/jquery.dynatable.js"></script>
|
|
||||||
<link href="css/jquery.dynatable.css" rel="stylesheet">
|
|
||||||
|
|
||||||
<link href="css/chosen.css" rel="stylesheet">
|
echo '<link rel="stylesheet" href="'.$dir.'css/bootstrap.min.css">';
|
||||||
<script src="js/chosen.jquery.js" type="text/javascript"></script>
|
echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>';
|
||||||
<script src="js/chosen.proto.js" type="text/javascript"></script>
|
|
||||||
|
|
||||||
<script>$(document).ready(function(){
|
echo '<script src="'.$dir.'js/bootstrap.min.js"></script>';
|
||||||
|
echo '<script type="text/javascript" src="'.$dir.'js/jquery.dynatable.js"></script>';
|
||||||
|
echo '<link href="'.$dir.'css/jquery.dynatable.css" rel="stylesheet">';
|
||||||
|
|
||||||
|
echo '<link href="'.$dir.'css/chosen.css" rel="stylesheet">';
|
||||||
|
echo '<script src="'.$dir.'js/chosen.jquery.js" type="text/javascript"></script>';
|
||||||
|
echo '<script src="'.$dir.'js/chosen.proto.js" type="text/javascript"></script>';
|
||||||
|
|
||||||
|
echo "<script>$(document).ready(function(){
|
||||||
$('#tablepastes').dynatable();
|
$('#tablepastes').dynatable();
|
||||||
$(".chosen-select").chosen();
|
$('.chosen-select').chosen();
|
||||||
});</script>
|
});</script>";
|
||||||
|
|
||||||
<!-- Highlight scripts -->
|
//<!-- Highlight scripts -->
|
||||||
<?php include_once "includes/highlight.php"; ?>
|
include_once "includes/highlight.php";
|
||||||
|
?>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- NavBar -->
|
<!-- NavBar -->
|
||||||
<nav class="navbar navbar-inverse">
|
<nav class="navbar navbar-inverse">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="navbar-header">
|
<div class="navbar-header">
|
||||||
<a class="navbar-brand" href="index.php">Palm-Paste</a>
|
<?php
|
||||||
|
$dir = "";
|
||||||
|
if (isset($_GET["user"]))$dir="../";
|
||||||
|
echo '<a class="navbar-brand" href="'.$dir.'index.php">Palm-Paste</a>';
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li class="active"><a href="index.php">Home</a></li>
|
<li class="active"><a href="index.php">Home</a></li>
|
||||||
|
@ -37,11 +47,13 @@
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<?php
|
<?php
|
||||||
include_once "includes/user.php";
|
include_once "includes/user.php";
|
||||||
|
$dir = "";
|
||||||
|
if (isset($_GET["user"]))$dir="../";
|
||||||
$userID = -1;
|
$userID = -1;
|
||||||
if(isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]))
|
if(isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]))
|
||||||
$userID = GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"]);
|
$userID = GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"]);
|
||||||
if($userID == -1){
|
if($userID == -1){
|
||||||
echo "<li><a href=\"signup\"><span class=\"glyphicon glyphicon-user\"></span> Sign Up</a></li>";
|
echo "<li><a href=\"".$dir."signup\"><span class=\"glyphicon glyphicon-user\"></span> Sign Up</a></li>";
|
||||||
echo "<li><a data-toggle=\"modal\" data-target=\"#LoginPopup\" href=\"#\"><span class=\"glyphicon glyphicon-log-in\"></span> Login</a></li>";
|
echo "<li><a data-toggle=\"modal\" data-target=\"#LoginPopup\" href=\"#\"><span class=\"glyphicon glyphicon-log-in\"></span> Login</a></li>";
|
||||||
} else {
|
} else {
|
||||||
$user = GetUserByID($userID);
|
$user = GetUserByID($userID);
|
||||||
|
@ -49,8 +61,8 @@
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a class="dropdown-toggle glyphicon glyphicon-user" data-toggle="dropdown" href="#"> '.htmlspecialchars($user[1], ENT_QUOTES, 'UTF-8').'<span class="caret"></span></a>
|
<a class="dropdown-toggle glyphicon glyphicon-user" data-toggle="dropdown" href="#"> '.htmlspecialchars($user[1], ENT_QUOTES, 'UTF-8').'<span class="caret"></span></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="mypastes">My pastes</a></li>
|
<li><a href="'.$dir.'mypastes">My pastes</a></li>
|
||||||
<li><a href="logout">Logout</a></li>
|
<li><a href="'.$dir.'logout">Logout</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
';
|
';
|
||||||
|
@ -70,7 +82,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<!-- Login form -->
|
<!-- Login form -->
|
||||||
<form role="form" method="POST" action="login">
|
<?php
|
||||||
|
echo'<form role="form" method="POST" action="'.$dir.'login">';
|
||||||
|
?>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="user">Username:</label>
|
<label for="user">Username:</label>
|
||||||
<input type="user" class="form-control" id="user" name="user">
|
<input type="user" class="form-control" id="user" name="user">
|
||||||
|
@ -112,6 +126,8 @@ if (isset($_GET["page"])){
|
||||||
$uid = $_GET["page"];
|
$uid = $_GET["page"];
|
||||||
include_once "ViewPaste.php";
|
include_once "ViewPaste.php";
|
||||||
}
|
}
|
||||||
|
} else if (isset($_GET["user"])){
|
||||||
|
include_once "UserPage.php";
|
||||||
} else {
|
} else {
|
||||||
include_once "NewPaste.php";
|
include_once "NewPaste.php";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue