mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
Improve paginator JS
This commit is contained in:
parent
b7a793699b
commit
d7e42772ea
7 changed files with 53 additions and 278 deletions
|
@ -8,8 +8,6 @@ use PonePaste\Models\PageView;
|
||||||
$today_users_count = 0;
|
$today_users_count = 0;
|
||||||
$today_pastes_count = 0;
|
$today_pastes_count = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$query = $conn->query("SELECT @last_id := MAX(id) FROM page_view");
|
$query = $conn->query("SELECT @last_id := MAX(id) FROM page_view");
|
||||||
$row = $query->fetch(PDO::FETCH_NUM);
|
$row = $query->fetch(PDO::FETCH_NUM);
|
||||||
$page_last_id = intval($row[0]);
|
$page_last_id = intval($row[0]);
|
||||||
|
|
|
@ -1,254 +0,0 @@
|
||||||
<?php
|
|
||||||
session_start();
|
|
||||||
|
|
||||||
if (!isset($_SESSION['login'])) {
|
|
||||||
header("Location: .");
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_GET['logout'])) {
|
|
||||||
if (isset($_SESSION['login']))
|
|
||||||
unset($_SESSION['login']);
|
|
||||||
|
|
||||||
session_destroy();
|
|
||||||
header("Location: .");
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
$date = date('jS F Y');
|
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
|
||||||
require_once('../includes/config.php');
|
|
||||||
$con = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
|
|
||||||
|
|
||||||
if (mysqli_connect_errno()) {
|
|
||||||
$sql_error = mysqli_connect_error();
|
|
||||||
die("Unable connect to database");
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT @last_id := MAX(id) FROM admin_history";
|
|
||||||
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$last_id = $row['@last_id := MAX(id)'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT * FROM admin_history WHERE id=" . Trim($last_id);
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$last_date = $row['last_date'];
|
|
||||||
$last_ip = $row['ip'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($last_ip == $ip) {
|
|
||||||
if ($last_date == $date) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$query = "INSERT INTO admin_history (last_date,ip) VALUES ('$date','$ip')";
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$query = "INSERT INTO admin_history (last_date,ip) VALUES ('$date','$ip')";
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title>Paste - Tasks</title>
|
|
||||||
<link rel="shortcut icon" href="favicon.ico">
|
|
||||||
<link href="css/paste.css" rel="stylesheet" type="text/css"/>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div id="top" class="clearfix">
|
|
||||||
<!-- Start App Logo -->
|
|
||||||
<div class="applogo">
|
|
||||||
<a href="../" class="logo">Paste</a>
|
|
||||||
</div>
|
|
||||||
<!-- End App Logo -->
|
|
||||||
|
|
||||||
<!-- Start Top Right -->
|
|
||||||
<ul class="top-right">
|
|
||||||
<li class="dropdown link">
|
|
||||||
<a href="#" data-toggle="dropdown" class="dropdown-toggle profilebox"><b>Admin</b><span
|
|
||||||
class="caret"></span></a>
|
|
||||||
<ul class="dropdown-menu dropdown-menu-list dropdown-menu-right">
|
|
||||||
<li><a href="admin.php">Settings</a></li>
|
|
||||||
<li><a href="?logout">Logout</a></li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<!-- End Top Right -->
|
|
||||||
</div>
|
|
||||||
<!-- END TOP -->
|
|
||||||
|
|
||||||
<div class="content">
|
|
||||||
<!-- START CONTAINER -->
|
|
||||||
<div class="container-widget">
|
|
||||||
<!-- Start Menu -->
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-12">
|
|
||||||
<ul class="panel quick-menu clearfix">
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="dashboard.php"><i class="fa fa-home"></i>Dashboard</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="configuration.php"><i class="fa fa-cogs"></i>Configuration</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="interface.php"><i class="fa fa-eye"></i>Interface</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="admin.php"><i class="fa fa-user"></i>Admin Account</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="pastes.php"><i class="fa fa-clipboard"></i>Pastes</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="users.php"><i class="fa fa-users"></i>Users</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="ipbans.php"><i class="fa fa-ban"></i>IP Bans</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="stats.php"><i class="fa fa-line-chart"></i>Statistics</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="ads.php"><i class="fa fa-gbp"></i>Ads</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1">
|
|
||||||
<a href="sitemap.php"><i class="fa fa-map-signs"></i>Sitemap</a>
|
|
||||||
</li>
|
|
||||||
<li class="col-xs-3 col-sm-2 col-md-1 menu-active">
|
|
||||||
<a href="tasks.php"><i class="fa fa-tasks"></i>Tasks</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- End Menu -->
|
|
||||||
|
|
||||||
<?php
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
||||||
//POST HANDLER
|
|
||||||
|
|
||||||
}
|
|
||||||
if (isset($_GET['expired'])) {
|
|
||||||
$query = "SELECT * FROM pastes";
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$p_expiry = Trim($row['expiry']);
|
|
||||||
$p_id = Trim($row['id']);
|
|
||||||
if ($p_expiry == "NULL" || $p_expiry == "SELF") {
|
|
||||||
} else {
|
|
||||||
$input_time = $p_expiry;
|
|
||||||
$current_time = mktime(date("H"), date("i"), date("s"), date("n"), date("j"), date("Y"));
|
|
||||||
if ($input_time < $current_time) {
|
|
||||||
$query = "DELETE FROM pastes where id='$p_id'";
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mysqli_errno($con)) {
|
|
||||||
$msg = '<div class="paste-alert alert6">
|
|
||||||
' . mysqli_error($con) . '
|
|
||||||
</div>';
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$msg = '<div class="paste-alert alert3">
|
|
||||||
All expired pastes have been deleted
|
|
||||||
</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($_GET['all_pastes'])) {
|
|
||||||
$query = "DELETE FROM pastes";
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
|
|
||||||
if (mysqli_errno($con)) {
|
|
||||||
$msg = '<div class="paste-alert alert6">
|
|
||||||
' . mysqli_error($con) . '
|
|
||||||
</div>';
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$msg = '<div class="paste-alert alert3">
|
|
||||||
All pastes have been deleted
|
|
||||||
</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (isset($_GET['not_verfied'])) {
|
|
||||||
$query = "DELETE FROM users where verified='0'";
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
|
|
||||||
if (mysqli_errno($con)) {
|
|
||||||
$msg = '<div class="paste-alert alert6">
|
|
||||||
' . mysqli_error($con) . '
|
|
||||||
</div>';
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$msg = '<div class="paste-alert alert3">
|
|
||||||
All unverified accounts have been deleted
|
|
||||||
</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($_GET['admin_history'])) {
|
|
||||||
$query = "DELETE FROM admin_history";
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
|
|
||||||
if (mysqli_errno($con)) {
|
|
||||||
$msg = '<div class="paste-alert alert6">
|
|
||||||
' . mysqli_error($con) . '
|
|
||||||
</div>';
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$msg = '<div class="paste-alert alert3">
|
|
||||||
Admin history has been cleared
|
|
||||||
</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
<!-- Start Tasks -->
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-12">
|
|
||||||
<div class="panel panel-widget">
|
|
||||||
<div class="panel-body">
|
|
||||||
<div class="panel-title">Maintenance tasks</a></div>
|
|
||||||
<?php if (isset($msg)) echo $msg; ?>
|
|
||||||
<a href="?expired" class="btn btn-default btn-block">Delete all expired pastes</a>
|
|
||||||
<br/>
|
|
||||||
<a href="?admin_history" class="btn btn-info btn-block">Clear admin history</a>
|
|
||||||
<br/>
|
|
||||||
<a href="?not_verfied" class="btn btn-warning btn-block">Delete unverified accounts</a>
|
|
||||||
<br/>
|
|
||||||
<a href="?all_pastes" class="btn btn-danger btn-block">Delete all pastes</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- End Tasks -->
|
|
||||||
</div>
|
|
||||||
<!-- END CONTAINER -->
|
|
||||||
|
|
||||||
<!-- Start Footer -->
|
|
||||||
<div class="row footer">
|
|
||||||
<div class="col-md-6 text-left">
|
|
||||||
<a href="https://github.com/jordansamuel/PASTE" target="_blank">Updates</a> — <a
|
|
||||||
href="https://github.com/jordansamuel/PASTE/issues" target="_blank">Bugs</a>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-6 text-right">
|
|
||||||
Powered by <a href="https://phpaste.sourceforge.io" target="_blank">Paste</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- End Footer -->
|
|
||||||
</div>
|
|
||||||
<!-- End content -->
|
|
||||||
|
|
||||||
<script type="text/javascript" src="js/jquery.min.js"></script>
|
|
||||||
<script type="text/javascript" src="js/bootstrap.min.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -144,21 +144,23 @@ class SimplePaginator {
|
||||||
|
|
||||||
/* First and last page in existence */
|
/* First and last page in existence */
|
||||||
const firstPage = 0;
|
const firstPage = 0;
|
||||||
const lastPage = Math.ceil(totalRecords / perPage); // ish?
|
const lastPage = Math.floor(totalRecords / perPage); // ish?
|
||||||
const numPagesToShow = 3;
|
const numPagesToShow = 2;
|
||||||
|
|
||||||
/* First and last page the main paginator will show */
|
/* First and last page the main paginator will show */
|
||||||
const firstPageShow = (currentPage - numPagesToShow < 0) ? currentPage : currentPage - numPagesToShow;
|
const firstPageShow = (currentPage - firstPage) < numPagesToShow ? firstPage : ((currentPage - numPagesToShow < 0) ? currentPage : currentPage - numPagesToShow);
|
||||||
const lastPageShow = (firstPageShow + numPagesToShow) > lastPage ? lastPage : (firstPageShow + numPagesToShow * 2);
|
const lastPageShow = (firstPageShow + numPagesToShow) > lastPage ? lastPage : (firstPageShow + numPagesToShow + numPagesToShow);
|
||||||
|
|
||||||
/* Whether to show the first and last pages in existence at the ends of the paginator */
|
/* Whether to show the first and last pages in existence at the ends of the paginator */
|
||||||
const showFirstPage = (Math.abs(firstPage - currentPage)) > (numPagesToShow * 2);
|
const showFirstPage = (Math.abs(firstPage - currentPage)) > (numPagesToShow);
|
||||||
const showLastPage = (Math.abs(lastPage - currentPage)) > (numPagesToShow * 2);
|
const showLastPage = (Math.abs(lastPage - currentPage)) > (numPagesToShow);
|
||||||
|
|
||||||
|
|
||||||
|
const prevButtonDisabled = currentPage === firstPage ? 'disabled' : '';
|
||||||
|
|
||||||
/* Previous button */
|
/* Previous button */
|
||||||
this.element.appendChild(makeEl(
|
this.element.appendChild(makeEl(
|
||||||
`<a class="paginator__button previous disabled" data-page="${currentPage - 1}">Previous</a>`
|
`<a class="paginator__button previous ${prevButtonDisabled}" data-page="${currentPage - 1}">Previous</a>`
|
||||||
));
|
));
|
||||||
|
|
||||||
/* First page button */
|
/* First page button */
|
||||||
|
@ -171,8 +173,9 @@ class SimplePaginator {
|
||||||
|
|
||||||
/* "window" buttons */
|
/* "window" buttons */
|
||||||
for (let i = firstPageShow; i <= lastPageShow; i++) {
|
for (let i = firstPageShow; i <= lastPageShow; i++) {
|
||||||
|
const selected = (i === currentPage ? 'paginator__button--selected' : '');
|
||||||
this.element.appendChild(makeEl(
|
this.element.appendChild(makeEl(
|
||||||
`<a class="paginator__button" data-page="${i}">${i}</a>`
|
`<a class="paginator__button ${selected}" data-page="${i}">${i}</a>`
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,9 +187,10 @@ class SimplePaginator {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nextButtonDisabled = currentPage === lastPage ? 'disabled' : '';
|
||||||
/* Next button */
|
/* Next button */
|
||||||
this.element.appendChild(makeEl(
|
this.element.appendChild(makeEl(
|
||||||
`<a class="paginator__button next" data-page="${currentPage + 1}">Next</a>`
|
`<a class="paginator__button next ${nextButtonDisabled}" data-page="${currentPage + 1}">Next</a>`
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,7 +205,7 @@ class DataTable {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
|
|
||||||
this.totalRecords = -1;
|
this.totalRecords = -1;
|
||||||
this.perPage = 10;
|
this.perPage = 20;
|
||||||
this.currentPage = 0;
|
this.currentPage = 0;
|
||||||
|
|
||||||
this.paginator = new SimplePaginator(this.container.querySelector('.paginator'));
|
this.paginator = new SimplePaginator(this.container.querySelector('.paginator'));
|
||||||
|
|
2
assets/bundle.min.js
vendored
2
assets/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -19,21 +19,23 @@ class SimplePaginator {
|
||||||
|
|
||||||
/* First and last page in existence */
|
/* First and last page in existence */
|
||||||
const firstPage = 0;
|
const firstPage = 0;
|
||||||
const lastPage = Math.ceil(totalRecords / perPage); // ish?
|
const lastPage = Math.floor(totalRecords / perPage); // ish?
|
||||||
const numPagesToShow = 3;
|
const numPagesToShow = 2;
|
||||||
|
|
||||||
/* First and last page the main paginator will show */
|
/* First and last page the main paginator will show */
|
||||||
const firstPageShow = (currentPage - numPagesToShow < 0) ? currentPage : currentPage - numPagesToShow;
|
const firstPageShow = (currentPage - firstPage) < numPagesToShow ? firstPage : ((currentPage - numPagesToShow < 0) ? currentPage : currentPage - numPagesToShow);
|
||||||
const lastPageShow = (firstPageShow + numPagesToShow) > lastPage ? lastPage : (firstPageShow + numPagesToShow * 2);
|
const lastPageShow = (firstPageShow + numPagesToShow) > lastPage ? lastPage : (firstPageShow + numPagesToShow + numPagesToShow);
|
||||||
|
|
||||||
/* Whether to show the first and last pages in existence at the ends of the paginator */
|
/* Whether to show the first and last pages in existence at the ends of the paginator */
|
||||||
const showFirstPage = (Math.abs(firstPage - currentPage)) > (numPagesToShow * 2);
|
const showFirstPage = (Math.abs(firstPage - currentPage)) > (numPagesToShow);
|
||||||
const showLastPage = (Math.abs(lastPage - currentPage)) > (numPagesToShow * 2);
|
const showLastPage = (Math.abs(lastPage - currentPage)) > (numPagesToShow);
|
||||||
|
|
||||||
|
|
||||||
|
const prevButtonDisabled = currentPage === firstPage ? 'disabled' : ''
|
||||||
|
|
||||||
/* Previous button */
|
/* Previous button */
|
||||||
this.element.appendChild(makeEl(
|
this.element.appendChild(makeEl(
|
||||||
`<a class="paginator__button previous disabled" data-page="${currentPage - 1}">Previous</a>`
|
`<a class="paginator__button previous ${prevButtonDisabled}" data-page="${currentPage - 1}">Previous</a>`
|
||||||
));
|
));
|
||||||
|
|
||||||
/* First page button */
|
/* First page button */
|
||||||
|
@ -46,8 +48,9 @@ class SimplePaginator {
|
||||||
|
|
||||||
/* "window" buttons */
|
/* "window" buttons */
|
||||||
for (let i = firstPageShow; i <= lastPageShow; i++) {
|
for (let i = firstPageShow; i <= lastPageShow; i++) {
|
||||||
|
const selected = (i === currentPage ? 'paginator__button--selected' : '');
|
||||||
this.element.appendChild(makeEl(
|
this.element.appendChild(makeEl(
|
||||||
`<a class="paginator__button" data-page="${i}">${i}</a>`
|
`<a class="paginator__button ${selected}" data-page="${i}">${i}</a>`
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +62,10 @@ class SimplePaginator {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nextButtonDisabled = currentPage === lastPage ? 'disabled' : ''
|
||||||
/* Next button */
|
/* Next button */
|
||||||
this.element.appendChild(makeEl(
|
this.element.appendChild(makeEl(
|
||||||
`<a class="paginator__button next" data-page="${currentPage + 1}">Next</a>`
|
`<a class="paginator__button next ${nextButtonDisabled}" data-page="${currentPage + 1}">Next</a>`
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +80,7 @@ class DataTable {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
|
|
||||||
this.totalRecords = -1;
|
this.totalRecords = -1;
|
||||||
this.perPage = 10;
|
this.perPage = 20;
|
||||||
this.currentPage = 0;
|
this.currentPage = 0;
|
||||||
|
|
||||||
this.paginator = new SimplePaginator(this.container.querySelector('.paginator'));
|
this.paginator = new SimplePaginator(this.container.querySelector('.paginator'));
|
||||||
|
|
|
@ -182,4 +182,27 @@ button.button--no-style {
|
||||||
|
|
||||||
.form--inline {
|
.form--inline {
|
||||||
display: inline;
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paginator {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paginator__button {
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: inline-block;
|
||||||
|
min-width: 1.5em;
|
||||||
|
padding: 0.2em 1em;
|
||||||
|
margin-left: 2px;
|
||||||
|
text-align: center;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #333;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paginator__button--selected {
|
||||||
|
background-color: #ddd;
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue