Make paste page kind of work. Barely. Definitely not done yet.

This commit is contained in:
Floorb 2021-07-11 11:54:37 -04:00
parent 943c392508
commit 168d5ad5a6
11 changed files with 77 additions and 154 deletions

View file

@ -40,7 +40,6 @@ $sql_details = array(
*/
require( 'ssp.pastes.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $columns2 )
);

View file

@ -1,72 +0,0 @@
<?php
/*
* $ID Project: Paste 2.0 - J.Samuel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License in LIC.txt for more details.
*/
$currentversion = 2.2;
// Max paste size in MB. This value should always be below the value of
// post_max_size in your PHP configuration settings (php.ini) or empty errors will occur.
// The value we got on installation of Paste was: post_max_size = 128M
// Otherwise, the maximum value that can be set is 4000 (4GB)
$pastelimit = "0.5"; // 0.5 = 512 kilobytes, 1 = 1MB
// OAUTH (to enable, change to yes and edit)
$enablefb = "no";
$enablegoog = "no";
// "CHANGE THIS" = Replace with your details
// Facebook
define('FB_APP_ID', 'CHANGE THIS'); // Your application ID, see https://developers.facebook.com/docs/apps/register
define('FB_APP_SECRET', 'CHANGE THIS'); // What's your Secret key
// Google
define('G_Client_ID', 'CHANGE THIS'); // Get a Client ID from https://console.developers.google.com/projectselector/apis/library
define('G_Client_Secret', 'CHANGE THIS'); // What's your Secret key
define('G_Redirect_Uri', 'http://ponepaste.org//oauth/google.php'); // Leave this as is
define('G_Application_Name', 'Paste'); // Make sure this matches the name of your application
// Database information
$dbhost = "localhost";
$dbuser = "P0nedbAcc0unt";
$dbpassword = "1NWO6Tp17IFz9lbl";
$dbname = "p0nepast3s";
// Secret key for paste encryption
$sec_key = "8ac67343e7980b16b31e8311d4377bbb";
define('SECRET',md5($sec_key));
// Set to 1 to enable Apache's mod_rewrite
$mod_rewrite = "1";
// Available GeSHi formats
$geshiformats =array(
'text' => '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
?>

View file

@ -13,6 +13,11 @@
* 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

View file

@ -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');

View file

@ -386,7 +386,7 @@ function truncate($input, $maxWords, $maxChars)
$truncated[] = $fragment;
}
$result = implode($truncated, ' ');
$result = implode(' ', $truncated);
return $result . ($input == $result ? '' : '[...]');
}

View file

@ -1,6 +1,6 @@
<?php
// Turn off all error reporting
error_reporting(0);
// Turn off all error reporting - uh no?
//error_reporting(0);
?>
<?php
/**
@ -568,6 +568,7 @@ class GeSHi {
if ( is_string($language) && ($language !== '') ) {
$this->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);

View file

@ -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(

View file

@ -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(

View file

@ -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,51 +35,39 @@ $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);
@ -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,10 +96,11 @@ $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
@ -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;');
@ -212,9 +203,6 @@ $get_paste_details->execute([$paste_id]);
}
}
}
} else {
header("HTTP/1.1 404 Not Found");
$notfound = $lang['notfound']; // "Not found";
}
require_once('theme/' . $default_theme . '/header.php');

View file

@ -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');

View file

@ -255,14 +255,12 @@ overflow: hidden !important;
} else {
echo '<a href="' . $p_id . '" title="' . $titlehov . '">' . ucfirst($title) . '</a>';
}}
// 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']; } ?>
// Display a message if the pastebin is empty
if ($totalpastes === 0) {
echo $lang['emptypastebin'];
} ?>
</p>
<?php } else { ?>