From 6f40bebfc2dd88787525cfe5e5280a2fd1b2f992 Mon Sep 17 00:00:00 2001 From: Floorb <132411956+Neetpone@users.noreply.github.com> Date: Sun, 22 Aug 2021 21:45:26 -0400 Subject: [PATCH] New page template system kinda. --- archive.php | 5 +- composer.json | 3 +- discover.php | 6 +- event.php | 7 +- includes/ViewBag.class.php | 34 +++ includes/captcha.php | 25 ++- includes/common.php | 13 +- includes/config.php | 11 +- includes/functions.php | 13 +- index.php | 6 +- login.php | 7 +- pages.php | 6 +- paste.php | 12 +- profile.php | 7 +- rules.php | 6 +- theme/bulma/common.php | 439 +++++++++++++++++++++++++++++++++++++ theme/bulma/event.php | 2 +- theme/bulma/main.php | 18 +- theme/bulma/view.php | 12 +- user.php | 5 +- 20 files changed, 532 insertions(+), 105 deletions(-) create mode 100644 includes/ViewBag.class.php create mode 100644 theme/bulma/common.php diff --git a/archive.php b/archive.php index deb8c91..7205e2d 100644 --- a/archive.php +++ b/archive.php @@ -30,6 +30,5 @@ updatePageViews($conn); $p_title = $lang['archive']; // "Pastes Archive"; // Theme -require_once('theme/' . $default_theme . '/header.php'); -require_once('theme/' . $default_theme . '/archive.php'); -require_once('theme/' . $default_theme . '/footer.php'); +$page_template = 'archive'; +require_once('theme/' . $default_theme . '/common.php'); diff --git a/composer.json b/composer.json index c387c14..595d01b 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "scrivo/highlight.php": "v9.18.1.7", "ext-pdo": "*", "ext-openssl": "*", - "erusev/parsedown": "^1.7" + "erusev/parsedown": "^1.7", + "ext-gd": "*" } } diff --git a/discover.php b/discover.php index 0e9c5c7..c20cce8 100644 --- a/discover.php +++ b/discover.php @@ -99,6 +99,6 @@ $random_pastes = array_map('transformPasteRow', getRandomPastes($conn, 10)); // Theme $p_title = $lang['archive']; // "Pastes Archive"; -require_once('theme/' . $default_theme . '/header.php'); -require_once('theme/' . $default_theme . '/discover.php'); -require_once('theme/' . $default_theme . '/footer.php'); +$page_template = 'discover'; +require_once('theme/' . $default_theme . '/common.php'); + diff --git a/event.php b/event.php index 3fa02b0..c9d904f 100644 --- a/event.php +++ b/event.php @@ -20,12 +20,9 @@ require_once('includes/functions.php'); // UTF-8 header('Content-Type: text/html; charset=utf-8'); -$date = date('jS F Y'); -$ip = $_SERVER['REMOTE_ADDR']; $p_title = $lang['archive']; // "Pastes Archive"; // Theme -require_once('theme/' . $default_theme . '/header.php'); -require_once('theme/' . $default_theme . '/event.php'); -require_once('theme/' . $default_theme . '/footer.php'); +$page_template = 'event'; +require_once('theme/' . $default_theme . '/common.php'); \ No newline at end of file diff --git a/includes/ViewBag.class.php b/includes/ViewBag.class.php new file mode 100644 index 0000000..e4f4d6e --- /dev/null +++ b/includes/ViewBag.class.php @@ -0,0 +1,34 @@ +> 0x10); - $rgb_array['g'] = 0xFF & ($color_val >> 0x8); - $rgb_array['b'] = 0xFF & $color_val; + return [ + 'r' => 0xFF & ($color_val >> 0x10), + 'g' => 0xFF & ($color_val >> 0x8), + 'b' => 0xFF & $color_val + ]; } elseif (strlen($hex_str) == 3) { - $rgb_array['r'] = hexdec(str_repeat(substr($hex_str, 0, 1), 2)); - $rgb_array['g'] = hexdec(str_repeat(substr($hex_str, 1, 1), 2)); - $rgb_array['b'] = hexdec(str_repeat(substr($hex_str, 2, 1), 2)); - } else { - return false; + return [ + 'r' => hexdec(str_repeat(substr($hex_str, 0, 1), 2)), + 'g' => hexdec(str_repeat(substr($hex_str, 1, 1), 2)), + 'b' => hexdec(str_repeat(substr($hex_str, 2, 1), 2)) + ]; } - return $return_string ? implode($separator, $rgb_array) : $rgb_array; + + return null; } } diff --git a/includes/common.php b/includes/common.php index a5b1993..4af5570 100644 --- a/includes/common.php +++ b/includes/common.php @@ -7,6 +7,7 @@ require_once(__DIR__ . '/config.php'); require_once(__DIR__ . '/functions.php'); require_once(__DIR__ . '/DatabaseHandle.class.php'); require_once(__DIR__ . '/User.class.php'); +require_once(__DIR__ . '/ViewBag.class.php'); /* View functions */ function urlForPaste($paste_id) : string { @@ -98,11 +99,10 @@ $conn = new DatabaseHandle("mysql:host=$db_host;dbname=$db_schema;charset=utf8mb // Setup site info $site_info = getSiteInfo(); +$global_site_info = $site_info['site_info']; $row = $site_info['site_info']; $title = Trim($row['title']); -$des = Trim($row['description']); $baseurl = Trim($row['baseurl']); -$keyword = Trim($row['keywords']); $site_name = Trim($row['site_name']); $email = Trim($row['email']); $ga = Trim($row['google_analytics']); @@ -125,9 +125,6 @@ if ($site_permissions) { $disableguest = 'off'; } -$privatesite = $siteprivate; -$noguests = $disableguest; - // CAPTCHA configuration $captcha_config = $site_info['captcha']; $captcha_enabled = (bool)$captcha_config['enabled']; @@ -151,10 +148,8 @@ $total_unique_views = getSiteTotal_unique_views($conn); $current_user = User::current($conn); -if ($current_user) { - $noguests = "off"; -} - /* Security headers */ header('X-Frame-Options: SAMEORIGIN'); header('X-Content-Type-Options: nosniff'); + +//ob_start(); diff --git a/includes/config.php b/includes/config.php index ed66d85..340bee8 100644 --- a/includes/config.php +++ b/includes/config.php @@ -45,21 +45,12 @@ if (gethostname() === 'thunderlane') { const PP_ENCRYPTION_ALGO = 'AES-256-CBC'; const PP_ENCRYPTION_KEY = ''; - -// Available GeSHi formats -$geshiformats = [ +const PP_HIGHLIGHT_FORMATS = [ 'green' => 'Green Text', 'text' => 'Plain Text', 'pastedown' => 'pastedown', 'pastedown_old' => 'pastedown old' ]; -// Popular formats that are listed first. -$popular_formats = [ - 'green', - 'text', - 'pastedown', - 'pastedown_old' -]; // Cookie - I want a cookie, can I have one? diff --git a/includes/functions.php b/includes/functions.php index f7f471e..829bb80 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -232,9 +232,9 @@ function doDownload($paste_id, $p_title, $p_member, $p_conntent, $p_code) { return $stats; } -function embedView($paste_id, $p_title, $p_conntent, $p_code, $title, $baseurl, $ges_style, $lang) { +function embedView($paste_id, $p_title, $content, $p_code, $title, $baseurl, $lang) { $stats = false; - if ($p_conntent) { + if ($content) { // Build the output $output = "
"; $output .= ""; - $output .= "$ges_style"; // Dynamic GeSHI Style - $output .= $p_conntent; // Paste content + $output .= $content; // Paste content $output .= ""; @@ -291,7 +290,7 @@ function embedView($paste_id, $p_title, $p_conntent, $p_code, $title, $baseurl, // Display embed conntent using json_encode since that escapes // characters well enough to satisfy javascript. http://stackoverflow.com/a/169035 - header('conntent-type: text/javascript; charset=utf-8;'); + header('Content-Type: text/javascript; charset=utf-8;'); echo 'document.write(' . json_encode($output) . ')'; $stats = true; } else { @@ -328,7 +327,5 @@ function addToSitemap($paste_id, $priority, $changefreq, $mod_rewrite) { } function paste_protocol() : string { - return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? 'https://' : 'http://'; + return !empty($_SERVER['HTTPS']) ? 'https://' : 'http://'; } - - diff --git a/index.php b/index.php index 10866f8..ded2b82 100644 --- a/index.php +++ b/index.php @@ -192,7 +192,5 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } OutPut: -// Theme -require_once('theme/' . $default_theme . '/header.php'); -require_once('theme/' . $default_theme . '/main.php'); -require_once('theme/' . $default_theme . '/footer.php'); +$page_template = 'main'; +require_once('theme/' . $default_theme . '/common.php'); diff --git a/login.php b/login.php index 41d9151..f096b56 100644 --- a/login.php +++ b/login.php @@ -140,6 +140,7 @@ if (isset($_POST['forgot'])) { } } // Theme -require_once('theme/' . $default_theme . '/header.php'); -require_once('theme/' . $default_theme . '/login.php'); -require_once('theme/' . $default_theme . '/footer.php'); +$page_template = 'login'; +require_once('theme/' . $default_theme . '/common.php'); + + diff --git a/pages.php b/pages.php index ba003d6..2482223 100644 --- a/pages.php +++ b/pages.php @@ -38,7 +38,7 @@ if (isset($_GET['page'])) { } } // Theme -require_once('theme/' . $default_theme . '/header.php'); -require_once('theme/' . $default_theme . '/pages.php'); -require_once('theme/' . $default_theme . '/footer.php'); +$page_template = 'pages'; +require_once('theme/' . $default_theme . '/common.php'); + diff --git a/paste.php b/paste.php index 52f8ab9..b5b1f78 100644 --- a/paste.php +++ b/paste.php @@ -172,11 +172,10 @@ if ($paste_code === "pastedown") { // Embed view after highlighting is applied so that $p_code is syntax highlighted as it should be. if (isset($_GET['embed'])) { - embedView($paste_id, $paste_title, $p_content, $paste_code, $title, $baseurl, $ges_style, $lang); + embedView($paste_id, $paste_title, $p_content, $paste_code, $title, $baseurl, $lang); exit(); } -require_once('theme/' . $default_theme . '/header.php'); if ($password_required && $password_valid) { /* base64 here means that the password is exposed in the URL, technically - how to handle this better? */ $p_download = "paste.php?download&id=$paste_id&password=" . base64_encode($password_candidate); @@ -201,16 +200,15 @@ if (@$_SESSION['not_unique'] !== $paste_id) { $conn->query("UPDATE pastes SET views = (views + 1) where id = ?", [$paste_id]); } -require_once('theme/' . $default_theme . '/view.php'); +$page_template = 'view'; Not_Valid_Paste: if ($is_private || $notfound || !$password_valid) { + // FIXME // Display errors - require_once('theme/' . $default_theme . '/header.php'); - require_once('theme/' . $default_theme . '/errors.php'); + $page_template = 'errors'; } -// Footer - require_once('theme/' . $default_theme . '/footer.php'); +require_once('theme/' . $default_theme . '/common.php'); diff --git a/profile.php b/profile.php index 6f8e116..67a042f 100644 --- a/profile.php +++ b/profile.php @@ -27,7 +27,6 @@ $ip = $_SERVER['REMOTE_ADDR']; $p_title = $lang['myprofile']; //"My Profile"; - // Check if already logged in if ($current_user === null) { header("Location: ./login.php"); @@ -68,6 +67,6 @@ updatePageViews($conn); $total_user_pastes = getTotalPastes($conn, $current_user->user_id); // Theme -require_once('theme/' . $default_theme . '/header.php'); -require_once('theme/' . $default_theme . '/profile.php'); -require_once('theme/' . $default_theme . '/footer.php'); +$page_template = 'profile'; +require_once('theme/' . $default_theme . '/common.php'); + diff --git a/rules.php b/rules.php index e914e72..f8b18fa 100644 --- a/rules.php +++ b/rules.php @@ -9,6 +9,6 @@ header('Content-Type: text/html; charset=utf-8'); $p_title = $lang['archive']; // "Pastes Archive"; // Theme -require_once('theme/' . $default_theme . '/header.php'); -require_once('theme/' . $default_theme . '/rules.php'); -require_once('theme/' . $default_theme . '/footer.php'); +$page_template = 'rules'; +require_once('theme/' . $default_theme . '/common.php'); + diff --git a/theme/bulma/common.php b/theme/bulma/common.php new file mode 100644 index 0000000..0f8849b --- /dev/null +++ b/theme/bulma/common.php @@ -0,0 +1,439 @@ + + + +"> + + + + + + <?php + $title = $global_site_info['title']; + + if (isset($paste_title)) { + $title = $paste_title . ' - ' . $title; + } + + echo pp_html_escape($title); + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/theme/bulma/event.php b/theme/bulma/event.php index 56daaf9..2011f7d 100644 --- a/theme/bulma/event.php +++ b/theme/bulma/event.php @@ -152,7 +152,7 @@
diff --git a/theme/bulma/view.php b/theme/bulma/view.php index bb1e052..dfce860 100644 --- a/theme/bulma/view.php +++ b/theme/bulma/view.php @@ -307,19 +307,9 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
diff --git a/user.php b/user.php index 4cdd5ae..67b8dc8 100644 --- a/user.php +++ b/user.php @@ -116,6 +116,5 @@ if (isset($_GET['del'])) { } // Theme -require_once('theme/' . $default_theme . '/header.php'); -require_once('theme/' . $default_theme . '/user_profile.php'); -require_once('theme/' . $default_theme . '/footer.php'); +$page_template = 'user_profile'; +require_once('theme/' . $default_theme . '/common.php');