mirror of
https://github.com/pikami/palm-paste.git
synced 2025-12-21 17:59:48 +00:00
Reorganize file structure
This commit is contained in:
44
src/views/_layout.php
Normal file
44
src/views/_layout.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
if (!isset($content)) {
|
||||
$content = '<p>no content</p>';
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Palm-Paste Index</title>
|
||||
<meta charset="utf-8">
|
||||
<?php
|
||||
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
|
||||
$dir = "";
|
||||
if (isset($_GET["user"]) || isset($_GET["page"]) && $_GET["page"] == "edit") $dir = "../";
|
||||
|
||||
echo '<link rel="stylesheet" href="' . $dir . 'public/css/bootstrap.min.css">';
|
||||
echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>';
|
||||
|
||||
echo '<script src="' . $dir . 'public/js/bootstrap.min.js"></script>';
|
||||
echo '<script type="text/javascript" src="' . $dir . 'public/js/jquery.dynatable.js"></script>';
|
||||
echo '<link href="' . $dir . 'public/css/jquery.dynatable.css" rel="stylesheet">';
|
||||
|
||||
echo '<link href="' . $dir . 'public/css/chosen.css" rel="stylesheet">';
|
||||
echo '<script src="' . $dir . 'public/js/chosen.jquery.js" type="text/javascript"></script>';
|
||||
echo '<script src="' . $dir . 'public/js/chosen.proto.js" type="text/javascript"></script>';
|
||||
|
||||
echo "<script>$(document).ready(function(){
|
||||
$('#tablepastes').dynatable();
|
||||
$('.chosen-select').chosen();
|
||||
});</script>";
|
||||
|
||||
?>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- NavBar -->
|
||||
<?php include_once "views/_navbar.php" ?>
|
||||
<!-- Content -->
|
||||
<?php echo $content; ?>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
79
src/views/_navbar.php
Normal file
79
src/views/_navbar.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<nav class="navbar navbar-inverse">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<?php
|
||||
$dir = "";
|
||||
if (isset($_GET["user"]) || isset($_GET["page"]) && $_GET["page"] == "edit") $dir = "../";
|
||||
echo '<a class="navbar-brand" href="' . $dir . '.">Palm-Paste</a>';
|
||||
?>
|
||||
</div>
|
||||
<ul class="nav navbar-nav">
|
||||
<li class="active"><a href="index.php">Home</a></li>
|
||||
<li><a href="#">Page 1</a></li>
|
||||
<li><a href="#">Page 2</a></li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<?php
|
||||
include_once "includes/user.php";
|
||||
$dir = "";
|
||||
if (isset($_GET["user"]) || isset($_GET["page"]) && $_GET["page"] == "edit") $dir = "../";
|
||||
$userID = -1;
|
||||
if (isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]))
|
||||
$userID = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
|
||||
if ($userID == -1) {
|
||||
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>";
|
||||
} else {
|
||||
$user = GetUserByID($userID);
|
||||
echo '
|
||||
<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>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="' . $dir . 'mypastes">My pastes</a></li>
|
||||
<li><a href="' . $dir . 'logout">Logout</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- LoginPopup -->
|
||||
<div id="LoginPopup" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title">Login</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<!-- Login form -->
|
||||
<?php
|
||||
echo '<form role="form" method="POST" action="' . $dir . 'login">';
|
||||
?>
|
||||
<div class="form-group">
|
||||
<label for="user">Username:</label>
|
||||
<input type="user" class="form-control" id="user" name="user">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pwd">Password:</label>
|
||||
<input type="password" class="form-control" id="pwd" name="pwd">
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" name="remember"> Remember me</label>
|
||||
</div>
|
||||
<input type='hidden' name='type' value='login'></input>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</form>
|
||||
<!-- END Login form -->
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
119
src/views/_new-paste.php
Normal file
119
src/views/_new-paste.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
$edit_mode = false;
|
||||
if (isset($_GET['page']) && $_GET['page'] == 'edit') {
|
||||
$edit_mode = true;
|
||||
printf('You are editing paste ' . $_GET['id']);
|
||||
printf('<form role="form" method="post" action="../post.php" onsubmit="document.getElementById(\'submit\').disabled=true;document.getElementById(\'submit\').value=\'Please wait...\';">');
|
||||
} else printf('<form role="form" method="post" action="post.php" onsubmit="document.getElementById(\'submit\').disabled=true;document.getElementById(\'submit\').value=\'Please wait...\';">');
|
||||
?>
|
||||
<div class="form-group">
|
||||
<label for="title">Paste title:</label>
|
||||
<?php
|
||||
if ($edit_mode == true) {
|
||||
printf('<input type="title" class="form-control" value="' . $row['title'] . '" id="title" name="title">');
|
||||
} else printf('<input type="title" class="form-control" id="title" name="title">');
|
||||
?>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="text">New paste:</label>
|
||||
<?php
|
||||
if ($edit_mode == true) {
|
||||
echo '<textarea class="form-control" rows="5" id="text" name="text">' . $row['text'] . '</textarea>';
|
||||
} else printf('<textarea class="form-control" rows="5" id="text" name="text"></textarea>');
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
if ($edit_mode == true) {
|
||||
printf("<input type='hidden' name='type' value='edit_paste'></input>");
|
||||
printf("<input type='hidden' name='uid' value='" . $row['uid'] . "'></input>");
|
||||
} else printf("<input type='hidden' name='type' value='paste'></input>");
|
||||
?>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<!-- Posting as guest -->
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" name="asguest">Post as guest</label>
|
||||
</div>
|
||||
<!-- Submit -->
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<!-- Expiry -->
|
||||
<div class="form-group">
|
||||
<label for="expire">Expiration:</label>
|
||||
<select class="form-control" id="expire" name="expire">
|
||||
<option>Never</option>
|
||||
<option value="600">10 Minutes</option>
|
||||
<option value="3600">1 Hour</option>
|
||||
<option value="86400">1 Day</option>
|
||||
<option value="2592000">1 Month</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Syntax Highlight -->
|
||||
<div class="form-group">
|
||||
<label for="syntax">Syntax Highlight:</label>
|
||||
<select data-placeholder="None" class="form-control chosen-select" id="syntax" name="syntax">
|
||||
<?php
|
||||
if ($edit_mode == true)
|
||||
print '<option value="' . $row['highlight'] . '">Current (' . $row['highlight'] . ')</option>';
|
||||
?>
|
||||
<option value="plain">Plain</option>
|
||||
<option value="applescript">AppleScript</option>
|
||||
<option value="as3">ActionScript3 (AS3)</option>
|
||||
<option value="bash">Bash</option>
|
||||
<option value="cf">ColdFusion</option>
|
||||
<option value="cpp">C++</option>
|
||||
<option value="csharp">C#</option>
|
||||
<option value="css">CSS</option>
|
||||
<option value="delphi">Delphi</option>
|
||||
<option value="diff">Diff</option>
|
||||
<option value="erlang">Erlang</option>
|
||||
<option value="groovy">Groovy</option>
|
||||
<option value="java">Java</option>
|
||||
<option value="javafx">JavaFX</option>
|
||||
<option value="jscript">JScript</option>
|
||||
<option value="perl">Perl</option>
|
||||
<option value="php">Php</option>
|
||||
<option value="powershell">PowerShell</option>
|
||||
<option value="python">Python</option>
|
||||
<option value="ruby">Ruby</option>
|
||||
<option value="sass">Sass</option>
|
||||
<option value="scala">Scala</option>
|
||||
<option value="sql">Sql</option>
|
||||
<option value="vb">VB</option>
|
||||
<option value="xml">Xml</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Type -->
|
||||
<div class="form-group">
|
||||
<label for="exposure">Type:</label>
|
||||
<select class="form-control" id="exposure" name="exposure">
|
||||
<?php
|
||||
print '<option value="0">Public</option>';
|
||||
if ($edit_mode == true && $row['exposure'] == 1)
|
||||
print '<option selected="selected" value="1">Unlisted</option>';
|
||||
else print '<option value="1">Unlisted</option>';
|
||||
include_once "includes/user.php";
|
||||
$userID = -1;
|
||||
if (isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]))
|
||||
$userID = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
|
||||
if ($userID == -1)
|
||||
print '<option value="2" disabled>Private (Members only)</option>';
|
||||
else {
|
||||
if ($edit_mode === true && $row['exposure'] === 2)
|
||||
print '<option selected="selected" value="2" >Private</option>';
|
||||
else print '<option value="2" >Private</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<!-- END Type -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
18
src/views/_recent-pastes.php
Normal file
18
src/views/_recent-pastes.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<h4>Newest pastes:</h4>
|
||||
<div class="list-group">
|
||||
<?php
|
||||
include_once "includes/config.php";
|
||||
$conn = GetConnectionToDB();
|
||||
$stmt = $conn->query('SELECT * FROM pastes WHERE exposure=0 ORDER BY id DESC LIMIT 5');
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$title = htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8');
|
||||
if (strlen($title) > 25) $title = substr($title, 0, 25) . "...";
|
||||
echo "<a href=\"" . htmlspecialchars($row['uid'], ENT_QUOTES, 'UTF-8') . "\" class=\"list-group-item\">" . $title . "</a>";
|
||||
}
|
||||
$conn = null;
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
35
src/views/edit.php
Normal file
35
src/views/edit.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<div class="container">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
if (isset($_GET['id']) && isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"])) {
|
||||
include_once "includes/user.php";
|
||||
$uid = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
|
||||
$paste = $_GET['id'];
|
||||
//connect to db and get paste info
|
||||
$conn = GetConnectionToDB();
|
||||
$stmt = $conn->prepare('SELECT * FROM pastes WHERE uid=:uid');
|
||||
$stmt->bindParam(':uid', $paste);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
if ($row['owner'] === $uid) {
|
||||
include "views/_new-paste.php";
|
||||
} else {
|
||||
$conn = null;
|
||||
echo '<center><h4>You are not the owner of the paste ' . $row["uid"] . '</h4></center>';
|
||||
echo '<meta http-equiv="refresh" content="2;url=../index.php">';
|
||||
die();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$conn = null;
|
||||
echo '<center><h4>The paste ' . $row["uid"] . ' does not exist</h4></center>';
|
||||
echo '<meta http-equiv="refresh" content="2;url=../index.php">';
|
||||
}
|
||||
$conn = null;
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
119
src/views/login.php
Normal file
119
src/views/login.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
function generate_skey()
|
||||
{
|
||||
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
$key = '';
|
||||
for ($i = 0; $i < 32; $i++) {
|
||||
$key .= $chars[mt_rand(0, 61)];
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
if (isset($_GET["logout"])) {
|
||||
include_once "includes/user.php";
|
||||
if (isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"])) {
|
||||
LogOutUserBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
|
||||
UnsetBrowserCookies();
|
||||
}
|
||||
echo '<center><h4>Please wait...</h4></center>';
|
||||
echo '<meta http-equiv="refresh" content="2;url=index.php">';
|
||||
} else if (isset($_POST["type"])) {
|
||||
if ($_POST["type"] == "login" && isset($_POST["user"]) && isset($_POST["pwd"])) {
|
||||
//Get options
|
||||
$user = $_POST["user"];
|
||||
$pwd = $_POST["pwd"];
|
||||
$remember = 0;
|
||||
if (isset($_POST["remember"]) && $_POST["remember"] == "on")
|
||||
$remember = 1;
|
||||
//Try to login
|
||||
include_once "includes/config.php";
|
||||
$conn = GetConnectionToDB();
|
||||
$stmt = $conn->prepare('SELECT * FROM users WHERE user=?');
|
||||
$stmt->execute(array($user));
|
||||
if ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
if (password_verify($pwd, $result["password"])) {
|
||||
$skey = generate_skey();
|
||||
$stmt = $conn->prepare("INSERT INTO sessions (skey, uid)
|
||||
VALUES (:skey, :uid)");
|
||||
$stmt->bindParam(':skey', $skey);
|
||||
$stmt->bindParam(':uid', $result["id"]);
|
||||
$stmt->execute();
|
||||
$sid = $conn->lastInsertId();
|
||||
$conn = null;
|
||||
if ($remember == 1) {
|
||||
setcookie("pp_sid", $sid, time() + 63072000); //Dies in 2 years
|
||||
setcookie("pp_skey", $skey, time() + 63072000); //Dies in 2 years
|
||||
} else {
|
||||
setcookie("pp_sid", $sid); //Dies when browser closes
|
||||
setcookie("pp_skey", $skey); //Dies when browser closes
|
||||
}
|
||||
echo '<center><h4>Please wait...</h4></center>';
|
||||
echo '<meta http-equiv="refresh" content="2;url=index.php">';
|
||||
die();
|
||||
} else echo "No!"; //TODO: Wrong password
|
||||
} else echo "Fail!"; //TODO: No user or SQL fail.
|
||||
$conn = null;
|
||||
}
|
||||
if ($_POST["type"] == "register" && isset($_POST["user"]) && isset($_POST["pwd"])) {
|
||||
//Get options
|
||||
$user = $_POST["user"];
|
||||
$pwd = $_POST["pwd"];
|
||||
$hash = password_hash($pwd, CRYPT_BLOWFISH);
|
||||
//Does this user exist
|
||||
include_once "includes/config.php";
|
||||
$conn = GetConnectionToDB();
|
||||
$stmt = $conn->prepare('SELECT * FROM users WHERE user=?');
|
||||
$stmt->execute(array($user));
|
||||
if ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
echo "<div class=\"container\"><h2>User allready exists!</h2></div>";
|
||||
$conn = null;
|
||||
die();
|
||||
}
|
||||
//Did the person enter a password
|
||||
if ($pwd == "") {
|
||||
echo "<div class=\"container\"><h2>You need a password to singup!</h2></div>";
|
||||
$conn = null;
|
||||
die();
|
||||
}
|
||||
//Register the user
|
||||
$stmt = $conn->prepare("INSERT INTO users (user,password)
|
||||
VALUES (:user, :pwd)");
|
||||
$stmt->bindParam(':user', $user);
|
||||
$stmt->bindParam(':pwd', $hash);
|
||||
if ($stmt->execute()) {
|
||||
echo '<center><h4>Please wait...</h4></center>';
|
||||
echo '<meta http-equiv="refresh" content="2;url=login">';
|
||||
} else {
|
||||
echo "Fail!";
|
||||
}
|
||||
$conn = null;
|
||||
}
|
||||
} else {
|
||||
echo '
|
||||
<div class="container">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Login</div>
|
||||
<div class="panel-body">
|
||||
';
|
||||
echo '
|
||||
<form role="form" method="POST" action="login">
|
||||
<div class="form-group">
|
||||
<label for="user">Username:</label>
|
||||
<input type="user" class="form-control" id="user" name="user">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pwd">Password:</label>
|
||||
<input type="password" class="form-control" id="pwd" name="pwd">
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" name="remember"> Remember me</label>
|
||||
</div>
|
||||
<input type=\'hidden\' name=\'type\' value=\'login\'></input>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</form>
|
||||
';
|
||||
echo '
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
60
src/views/my-pastes.php
Normal file
60
src/views/my-pastes.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<div class="container">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
include_once "includes/config.php";
|
||||
include_once "includes/user.php";
|
||||
$conn = GetConnectionToDB();
|
||||
if (GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]) == -1) {
|
||||
printf('<h2>You must be loged in to see your pastes!</h2>');
|
||||
$conn = null;
|
||||
echo '</div></div></div>';
|
||||
die();
|
||||
}
|
||||
$stmt = $conn->prepare('SELECT * FROM pastes WHERE owner=:own');
|
||||
$own = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]);
|
||||
$stmt->bindParam(':own', $own);
|
||||
$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>
|
||||
<th style="text-align: left;">Actions</th></thead>');
|
||||
printf('<tbody>');
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$title = $row['title'];
|
||||
//Paste title
|
||||
printf('<tr><td style="text-align: left;">' . htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8') . '</td>');
|
||||
//Creation date
|
||||
printf('<td style="text-align: left;">' . date('Y-m-d', $row["created"]) . '</td>');
|
||||
//Expire date
|
||||
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>');
|
||||
}
|
||||
//Paste url
|
||||
printf('<td style="text-align: right;"><a href="' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '">' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '</a></td>');
|
||||
//Actions
|
||||
printf('<td style="text-align: right;">');
|
||||
//delete paste
|
||||
printf('<a href="delete/' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '"><span class="glyphicon glyphicon-trash" title="Delete paste" aria-hidden="true"></span>');
|
||||
//edit paste
|
||||
printf('<a href="edit/' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '"><span class="glyphicon glyphicon-edit" title="Edit paste" aria-hidden="true"></span>');
|
||||
printf('</td></tr>');
|
||||
}
|
||||
printf('</tbody></talbe>');
|
||||
} else {
|
||||
printf('<h2>You havent made any pastes yet!</h2>');
|
||||
}
|
||||
$conn = null;
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
12
src/views/new-paste.php
Normal file
12
src/views/new-paste.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<div class="container">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-9">
|
||||
<?php include "views/_new-paste.php"; ?>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<?php include "views/_recent-pastes.php"; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
29
src/views/signup.php
Normal file
29
src/views/signup.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<div class="container">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Register</div>
|
||||
<div class="panel-body">
|
||||
<!-- Panel Content -->
|
||||
<form class="form-horizontal" role="form" method="POST" action="login">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2" for="user">Username:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="user" class="form-control" id="user" placeholder="Enter username" name="user">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2" for="pwd">Password:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pwd">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<input type='hidden' name='type' value='register'></input>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- END Panel Content -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
52
src/views/user.php
Normal file
52
src/views/user.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<div class="container">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
include_once "includes/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>
|
||||
55
src/views/view-paste.php
Normal file
55
src/views/view-paste.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<div class="container">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
if (isset($uid)) {
|
||||
include_once "includes/config.php";
|
||||
include_once "includes/user.php";
|
||||
$conn = GetConnectionToDB();
|
||||
$stmt = $conn->query('SELECT * FROM pastes WHERE uid="' . $uid . '"');
|
||||
if ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$conn = null;
|
||||
if ($result["expire"] != 0 && $result["expire"] < time()) {
|
||||
//This paste is expired but not removed
|
||||
echo "<h1>This paste just expired</h1>";
|
||||
include_once "cronjob.php";
|
||||
RemoveExpiredPastes();
|
||||
die();
|
||||
}
|
||||
if ($result["exposure"] == 2 && $result["owner"] != 0 && isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]) && $result["owner"] != GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"])) {
|
||||
echo "<h1>This paste is private</h1>";
|
||||
die();
|
||||
}
|
||||
echo "<h1>" . htmlspecialchars($result["title"], ENT_QUOTES, 'UTF-8') . "</h1>";
|
||||
//
|
||||
$owner = GetUserByID($result["owner"]);
|
||||
echo "<h5>";
|
||||
if ($owner[1] == -1)
|
||||
echo "Posted by: <b>Guest</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>";
|
||||
if ($result["expire"] == 0) printf('Never');
|
||||
else {
|
||||
$expire = ($result["expire"] - time()) / 3600;
|
||||
if ($expire > 24) {
|
||||
printf(round($expire / 24) . ' days from now');
|
||||
} else if ($expire >= 1)
|
||||
printf(round($expire) . ' hours from now');
|
||||
else printf(round($expire * 60) . ' minutes from now');
|
||||
}
|
||||
echo "</b></h5>";
|
||||
//
|
||||
echo "<pre class=\"brush: " . $_HL . "\">";
|
||||
echo htmlspecialchars($result["text"], ENT_QUOTES, 'UTF-8') . "</pre><pb>";
|
||||
echo "<label for=\"rawtext\">Raw text:</label>";
|
||||
echo "<textarea id=\"rawtext\" class=\"form-control\" rows=\"10\">" . htmlspecialchars($result["text"], ENT_QUOTES, 'UTF-8') . "</textarea>";
|
||||
} else echo "Paste does not exist";
|
||||
$conn = null;
|
||||
} else echo "Error: id not set";
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
SyntaxHighlighter.all()
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user