From 168d5ad5a66fb2d4f5791788e187245b151dd23b Mon Sep 17 00:00:00 2001
From: Floorb <132411956+Neetpone@users.noreply.github.com>
Date: Sun, 11 Jul 2021 11:54:37 -0400
Subject: [PATCH] Make paste page kind of work. Barely. Definitely not done
yet.
---
api/ajax_pastes.php | 1 -
api/config.php | 72 ---------------------
config.php | 7 +-
includes/common.php | 4 ++
includes/functions.php | 2 +-
includes/geshi.php | 15 +++--
includes/geshi/green.php | 4 +-
includes/geshi/pastedown_old.php | 4 +-
paste.php | 108 ++++++++++++++-----------------
theme/bulma/archive.php | 2 +-
theme/bulma/view.php | 12 ++--
11 files changed, 77 insertions(+), 154 deletions(-)
delete mode 100644 api/config.php
diff --git a/api/ajax_pastes.php b/api/ajax_pastes.php
index 54f6b09..67337e3 100644
--- a/api/ajax_pastes.php
+++ b/api/ajax_pastes.php
@@ -40,7 +40,6 @@ $sql_details = array(
*/
require( 'ssp.pastes.php' );
-
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $columns2 )
);
diff --git a/api/config.php b/api/config.php
deleted file mode 100644
index ec600f2..0000000
--- a/api/config.php
+++ /dev/null
@@ -1,72 +0,0 @@
- 'Plain Text',
- 'green' => 'Green Text',
- 'pastedown' => 'pastedown',
- 'pastedown_old' => 'pastedown old',
-);
-
-// Popular formats that are listed first.
-$popular_formats=array(
- 'text',
- 'green',
- 'pastedown',
- 'pastedown_old'
-);
-
-
-//Cookie
-?>
\ No newline at end of file
diff --git a/config.php b/config.php
index 8503459..a7eb2f1 100644
--- a/config.php
+++ b/config.php
@@ -12,7 +12,12 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License in LIC.txt for more details.
*/
-
+
+if (gethostname() === 'thunderlane') {
+ error_reporting(E_ALL);
+ ini_set('display_errors', 1);
+}
+
$currentversion = 2.2;
// Max paste size in MB. This value should always be below the value of
diff --git a/includes/common.php b/includes/common.php
index 1a5c377..b1d4fe8 100644
--- a/includes/common.php
+++ b/includes/common.php
@@ -23,6 +23,10 @@ function getSiteAds($conn) {
return $conn->query('SELECT text_ads, ads_1, ads_2 FROM ads LIMIT 1')->fetch();
}
+function getSiteTotalPastes($conn) {
+ return intval($conn->query('SELECT COUNT(*) FROM pastes')->fetch(PDO::FETCH_NUM)[0]);
+}
+
function updatePageViews($conn) {
$ip = $_SERVER['REMOTE_ADDR'];
$date = date('jS F Y');
diff --git a/includes/functions.php b/includes/functions.php
index 958fbea..61f2f17 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -386,7 +386,7 @@ function truncate($input, $maxWords, $maxChars)
$truncated[] = $fragment;
}
- $result = implode($truncated, ' ');
+ $result = implode(' ', $truncated);
return $result . ($input == $result ? '' : '[...]');
}
diff --git a/includes/geshi.php b/includes/geshi.php
index 593aec2..c93102f 100644
--- a/includes/geshi.php
+++ b/includes/geshi.php
@@ -1,6 +1,6 @@
set_language($language);
}
+
$this->set_language_path($path);
}
@@ -3724,6 +3725,7 @@ class GeSHi {
//Load the language file
require $file_name;
+
// Perhaps some checking might be added here later to check that
// $language data is a valid thing but maybe not
$this->language_data = $language_data;
@@ -3734,6 +3736,7 @@ class GeSHi {
// Set permissions for all lexics to true
// so they'll be highlighted by default
foreach (array_keys($this->language_data['KEYWORDS']) as $key) {
+
if (!empty($this->language_data['KEYWORDS'][$key])) {
$this->lexic_permissions['KEYWORDS'][$key] = true;
} else {
@@ -4697,11 +4700,9 @@ class GeSHi {
$list = preg_replace('#\(\?\:(.)\)\?#', '\1?', $list);
// (?:a|b|c|d|...)? => [abcd...]?
// TODO: a|bb|c => [ac]|bb
- static $callback_2;
- if (!isset($callback_2)) {
- $callback_2 = create_function('$matches', 'return "[" . str_replace("|", "", $matches[1]) . "]";');
- }
- $list = preg_replace_callback('#\(\?\:((?:.\|)+.)\)#', $callback_2, $list);
+ $list = preg_replace_callback('#\(\?\:((?:.\|)+.)\)#', function($matches) {
+ return "[" . str_replace("|", "", $matches[1]) . "]";
+ }, $list);
}
// return $list without trailing pipe
return substr($list, 0, -1);
diff --git a/includes/geshi/green.php b/includes/geshi/green.php
index 7b0885f..7dc43b2 100644
--- a/includes/geshi/green.php
+++ b/includes/geshi/green.php
@@ -37,7 +37,7 @@ $language_data = array(
'HARDQUOTE' => array(),
'HARDESCAPE' => array(),
'HARDCHAR' => '',
- 'KEYWRODS' => array(
+ 'KEYWORDS' => array(
1 => array(
''
)
@@ -51,7 +51,7 @@ $language_data = array(
)
),
'STYLES' => array(
- 'KEYWRODS' => array(
+ 'KEYWORDS' => array(
1 => 'color: #0000FF; font-weight: bold;'
),
'COMMENTS' => array(
diff --git a/includes/geshi/pastedown_old.php b/includes/geshi/pastedown_old.php
index 1b55224..f78a4f0 100644
--- a/includes/geshi/pastedown_old.php
+++ b/includes/geshi/pastedown_old.php
@@ -71,7 +71,7 @@ $language_data = array(
'NUMBERS' =>
GESHI_NUMBER_INT_BASIC | GESHI_NUMBER_OCT_PREFIX | GESHI_NUMBER_HEX_PREFIX |
GESHI_NUMBER_FLT_SCI_ZERO,
- 'KEYWRODS' => array(
+ 'KEYWORDS' => array(
1 => array(
''
)
@@ -85,7 +85,7 @@ $language_data = array(
)
),
'STYLES' => array(
- 'KEYWRODS' => array(
+ 'KEYWORDS' => array(
1 => ''
),
'COMMENTS' => array(
diff --git a/paste.php b/paste.php
index 9f4fe11..df2a95d 100644
--- a/paste.php
+++ b/paste.php
@@ -22,6 +22,7 @@ session_start();
header('Content-Type: text/html; charset=utf-8');
// Required functions
+define('IN_PONEPASTE', 1);
require_once('includes/common.php');
require_once('includes/geshi.php');
require_once('includes/functions.php');
@@ -34,54 +35,42 @@ $parsedown_path = 'includes/Parsedown/Parsedown.php';
$parsedownextra_path = 'includes/Parsedown/ParsedownExtra.php';
$parsedownsec_path = 'includes/Parsedown/SecureParsedown.php';
-// GET Paste ID
-if (isset($_GET['id'])) {
- $paste_id = Trim(htmlspecialchars($_GET['id']));
- $paste_id = preg_replace( '/[^0-9]/', '', $paste_id );
- $paste_id = (int) filter_var($paste_id, FILTER_SANITIZE_NUMBER_INT);
-} elseif (isset($_POST['id'])) {
- $paste_id = Trim(htmlspecialchars($_POST['id']));
- $paste_id = preg_replace( '/[^0-9]/', '', $paste_id );
- $paste_id = (int) filter_var($paste_id, FILTER_SANITIZE_NUMBER_INT);
-}
-
-// Prevent SQLInjection
-settype($paste_id, 'integer');
+$paste_id = intval(trim($_REQUEST['id']));
updatePageViews($conn);
-//Get fav count
-$get_fav_count = $conn->prepare("SELECT count(f_paste) as total FROM pins WHERE f_paste=?");
-$get_fav_count->execute([$paste_id]);
-while ($row = $get_fav_count->fetch()) {
- $fav_count = $row['total'];
-}
-
+// Get paste favorite count
+$query = $conn->prepare('SELECT COUNT(*) FROM pins WHERE f_paste = ?');
+$query->execute([$paste_id]);
+$fav_count = intval($query->fetch(PDO::FETCH_NUM)[0]);
// Get paste info
-$get_paste_details = $conn->prepare("SELECT * FROM pastes WHERE id=?");
-$get_paste_details->execute([$paste_id]);
- if ($get_paste_details->fetchColumn() > 0) {
- $get_paste_details = $conn->prepare("SELECT * FROM pastes WHERE id=?");
- $get_paste_details->execute([$paste_id]);
- while ($row = $get_paste_details->fetch()) {
- $p_title = $row['title'];
- $p_content = $row['content'];
- $p_visible = $row['visible'];
- $p_code = $row['code'];
- $p_expiry = Trim($row['expiry']);
- $p_password = $row['password'];
- $p_member = $row['member'];
- $p_date = $row['date'];
- $now_time = $row['now_time'];
- $p_encrypt = $row['encrypt'];
- $p_views = $row['views'];
- $p_tagsys = $row['tagsys'];
- }
-
-
+$query = $conn->prepare('SELECT * FROM pastes WHERE id = ?');
+$query->execute([$paste_id]);
+$row = $query->fetch();
+
+// This is used in the theme files.
+$totalpastes = getSiteTotalPastes($conn);
+
+if (!$row) {
+ header('HTTP/1.1 404 Not Found');
+ $notfound = $lang['notfound']; // "Not found";
+} else {
+ $p_title = $row['title'];
+ $p_content = $row['content'];
+ $p_visible = $row['visible'];
+ $p_code = $row['code'];
+ $p_expiry = Trim($row['expiry']);
+ $p_password = $row['password'];
+ $p_member = $row['member'];
+ $p_date = $row['date'];
+ $now_time = $row['now_time'];
+ $p_encrypt = $row['encrypt'];
+ $p_views = $row['views'];
+ $p_tagsys = $row['tagsys'];
+
$mod_date = date("jS F Y h:i:s A", $now_time);
-
+
$p_private_error = '0';
if ($p_visible == "2") {
if (isset($_SESSION['username'])) {
@@ -97,8 +86,8 @@ $get_paste_details->execute([$paste_id]);
goto Not_Valid_Paste;
}
}
- if ($p_expiry == "NULL" || $p_expiry == "SELF") {
- } else {
+
+ if (!empty($p_expiry) && $p_expiry !== 'SELF') {
$input_time = $p_expiry;
$current_time = mktime(date("H"), date("i"), date("s"), date("n"), date("j"), date("Y"));
if ($input_time < $current_time) {
@@ -107,13 +96,14 @@ $get_paste_details->execute([$paste_id]);
goto Not_Valid_Paste;
}
}
- if ($p_encrypt == "" || $p_encrypt == null || $p_encrypt == '0') {
- } else {
+
+ if (!empty($p_encrypt)) {
$p_content = decrypt($p_content);
}
+
$op_content = Trim(htmlspecialchars_decode($p_content));
-
- // Download the paste
+
+ // Download the paste
if (isset($_GET['download'])) {
if ($p_password == "NONE") {
doDownload($paste_id, $p_title, $p_member, $op_content, $p_code);
@@ -131,8 +121,8 @@ $get_paste_details->execute([$paste_id]);
}
}
}
-
- // Raw view
+
+ // Raw view
if (isset($_GET['raw'])) {
if ($p_password == "NONE") {
rawView($paste_id, $p_title, $op_content, $p_code);
@@ -149,8 +139,8 @@ $get_paste_details->execute([$paste_id]);
$error = $lang['pwdprotected']; // 'Password protected paste';
}
}
- }
-
+ }
+
// Preprocess
$highlight = array();
$prefix_size = strlen('!highlight!');
@@ -165,8 +155,8 @@ $get_paste_details->execute([$paste_id]);
$p_content .= $line . "\n";
}
$p_content = rtrim($p_content);
- }
-
+ }
+
// Apply syntax highlight
$p_content = htmlspecialchars_decode($p_content);
if ( $p_code == "pastedown" ) {
@@ -178,6 +168,7 @@ $get_paste_details->execute([$paste_id]);
$p_content = $Parsedown->text( $p_content );
} else {
$geshi = new GeSHi($p_content, $p_code, $path);
+
$geshi->enable_classes();
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->set_line_style('color: #aaaaaa; width:auto;');
@@ -193,8 +184,8 @@ $get_paste_details->execute([$paste_id]);
$style = $geshi->get_stylesheet();
$ges_style = '';
}
-
- // Embed view after GeSHI is applied so that $p_code is syntax highlighted as it should be.
+
+ // Embed view after GeSHI is applied so that $p_code is syntax highlighted as it should be.
if (isset($_GET['embed'])) {
if ( $p_password == "NONE" ) {
embedView( $paste_id, $p_title, $p_content, $p_code, $title, $baseurl, $ges_style, $lang );
@@ -211,10 +202,7 @@ $get_paste_details->execute([$paste_id]);
$error = $lang['pwdprotected']; // 'Password protected paste';
}
}
- }
-} else {
- header("HTTP/1.1 404 Not Found");
- $notfound = $lang['notfound']; // "Not found";
+ }
}
require_once('theme/' . $default_theme . '/header.php');
diff --git a/theme/bulma/archive.php b/theme/bulma/archive.php
index 4e21aaa..72639fb 100644
--- a/theme/bulma/archive.php
+++ b/theme/bulma/archive.php
@@ -19,7 +19,7 @@ $(document).ready(function () {
$("#archive").dataTable({
processing: true,
autoWidth: false,
- ajax:"../api/ajax_pastes.php",
+ ajax:"api/ajax_pastes.php",
initComplete: function () {
var search = new URLSearchParams(window.location.search);
var query = search.get('q');
diff --git a/theme/bulma/view.php b/theme/bulma/view.php
index 5053d21..b948b73 100644
--- a/theme/bulma/view.php
+++ b/theme/bulma/view.php
@@ -255,14 +255,12 @@ overflow: hidden !important;
} else {
echo '' . ucfirst($title) . '';
}}
+
+
// Display a message if the pastebin is empty
- $query = "SELECT count(*) as count FROM pastes";
- $result = mysqli_query( $con, $query );
- while ($row = mysqli_fetch_array($result)) {
- $totalpastes = $row['count'];
- }
-
- if ($totalpastes == '0') { echo $lang['emptypastebin']; } ?>
+ if ($totalpastes === 0) {
+ echo $lang['emptypastebin'];
+ } ?>