From 16b70202bdce33a1e28a1ba9ac196f679e37a893 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Sat, 12 Oct 2024 16:16:37 +0200
Subject: [PATCH 001/290] style.css: add diceroll styling
---
stylesheets/style.css | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/stylesheets/style.css b/stylesheets/style.css
index b96755e8..5d8cb2d4 100644
--- a/stylesheets/style.css
+++ b/stylesheets/style.css
@@ -1486,6 +1486,12 @@ li.mix {
display: inline-block;
}
+/* Dice roll support */
+.inline-dice {
+ width: 1em;
+ height: 1em;
+}
+
/* Mona Font */
.aa {
font-family: Mona, "MS PGothic", "MS Pゴシック", sans-serif;
From dcede2e175de3b2ef4dbc4bf8f980eba11065785 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Sat, 12 Oct 2024 16:20:01 +0200
Subject: [PATCH 002/290] config.php: limit the number of dicerolls
---
inc/config.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/inc/config.php b/inc/config.php
index 746fcad6..ee1b9086 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -681,6 +681,9 @@
// with the modifier Z added, with the result displayed at the top of the post body.
$config['allow_roll'] = false;
+ // Maximum number of dice rolls per post.
+ $config['max_roll_count'] = 24;
+
// Use semantic URLs for threads, like /b/res/12345/daily-programming-thread.html
$config['slugify'] = false;
From 56ad753b769bdef838dcee42ddf0d5d007203ed9 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Sat, 12 Oct 2024 16:16:08 +0200
Subject: [PATCH 003/290] functions.php: add new dice function
---
inc/functions.php | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/inc/functions.php b/inc/functions.php
index 644cefbe..bca8d1d1 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2786,6 +2786,51 @@ function diceRoller($post) {
}
}
+/**
+ * Rolls a dice and generates the appropiate html from the markup.
+ * @param array $matches The array of the matches according to the default configuration.
+ * 1 -> The number of dices to roll.
+ * 3 -> The number faces of the dices.
+ * 4 -> The offset to apply to the dice.
+ * @param string $img_path Path to the image to use. Null if none.
+ * @return string The html to replace the original markup with.
+ */
+function handle_dice_roll_markup(array $matches, ?string $img_path): string {
+ function get_or_default(array $arr, int $index, int $default) {
+ return (isset($arr[$index]) && is_numeric($arr[$index])) ? (int)$arr[$index] : $default;
+ }
+ global $config;
+
+ $dice_count = get_or_default($matches, 1, 1);
+ $dice_faces = get_or_default($matches, 3, 6);
+ $dice_offset = get_or_default($matches, 4, 0);
+
+ // Clamp between 1 and max_roll_count.
+ $dice_count = max(min($dice_count, $config['max_roll_count']), 1);
+ // Must be at least 2.
+ if ($dice_faces < 2) {
+ $dice_faces = 6;
+ }
+
+ $acc = '';
+ $text = "$dice_count d $dice_faces + $dice_offset";
+ for ($i = 0; $i < $dice_count; $i++) {
+ $res = $dice_offset + mt_rand(0, $dice_faces);
+ if ($img_path === null) {
+ $fmt = "$text $res";
+ } else {
+ $fmt = "
$res";
+ }
+ if (empty($acc)) {
+ $acc = $fmt;
+ } else {
+ $acc .= " $fmt";
+ }
+ }
+
+ return $acc;
+}
+
function slugify($post) {
global $config;
From dcfd41c3acad58c3ffaff1d6d41f36c65ca5bf92 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Sat, 12 Oct 2024 18:35:29 +0200
Subject: [PATCH 004/290] style.css: use flex display for multiple files
---
stylesheets/style.css | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/stylesheets/style.css b/stylesheets/style.css
index b96755e8..63de8117 100644
--- a/stylesheets/style.css
+++ b/stylesheets/style.css
@@ -374,7 +374,8 @@ form table tr td div.center {
}
.files.multifile {
- float: left;
+ display: flex;
+ flex-wrap: wrap;
}
.file {
From 35f963a2b6f18c2b6ab54be6cf4df05799754e75 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Sun, 13 Oct 2024 23:31:50 +0200
Subject: [PATCH 005/290] faq: update git link
---
templates/themes/faq/index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/themes/faq/index.html b/templates/themes/faq/index.html
index 6423bd1f..66a8a88f 100644
--- a/templates/themes/faq/index.html
+++ b/templates/themes/faq/index.html
@@ -88,7 +88,7 @@
How can I suggest or submit fixes to the site ?
- There is a /meta/ thread for this, and our Gitea repo.
+ There is a /meta/ thread for this, and our Gitlab repo.
I don't trust Tor exit nodes. Do you have an .onion site ?
From 4077956d47f33ed7bd5b2b56cff345a441a2e257 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Sun, 13 Oct 2024 23:57:50 +0200
Subject: [PATCH 006/290] Add .mailmap
---
.mailmap | 1 +
1 file changed, 1 insertion(+)
create mode 100644 .mailmap
diff --git a/.mailmap b/.mailmap
new file mode 100644
index 00000000..69b1864e
--- /dev/null
+++ b/.mailmap
@@ -0,0 +1 @@
+Zankaria Auxa Zankaria
\ No newline at end of file
From f0a33d26c69579a9d7481226ea80e1945ee213e2 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Sat, 12 Oct 2024 16:15:53 +0200
Subject: [PATCH 007/290] config.php: refactor dice markup
---
inc/config.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/inc/config.php b/inc/config.php
index ee1b9086..16b14413 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -743,6 +743,9 @@
* ====================
*/
+ // Dice Roll Markup.
+ $config['markup'][] = [ "/!([-+]?\d+)?([d])([-+]?\d+)([-+]\d+)?/iu", fn($m) => handle_dice_roll_markup($m, 'static/d10.svg') ];
+
// "Wiki" markup syntax ($config['wiki_markup'] in pervious versions):
$config['markup'][] = array("/'''(.+?)'''/", "\$1");
$config['markup'][] = array("/''(.+?)''/", "\$1");
From f86f1c344bc349c837639824c81405881290ca09 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Sat, 12 Oct 2024 16:25:01 +0200
Subject: [PATCH 008/290] faq theme: add the dice rolling documentation to the
site's FAQs
---
templates/themes/faq/index.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/templates/themes/faq/index.html b/templates/themes/faq/index.html
index 6423bd1f..6a7a3436 100644
--- a/templates/themes/faq/index.html
+++ b/templates/themes/faq/index.html
@@ -77,6 +77,7 @@
==text== makes it a heading: text
**text** makes it spoiler: text
[code]text[/code] makes it code:
text
+ [dice:XdY+Z] rolls a X dices with Y faces, adding Z to the result: 
Why are my posts being changed / word-filtered ?
From acf358b157a69b6dae0dda7cedbaa1c641995643 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 00:26:59 +0200
Subject: [PATCH 009/290] config.php: use modern array syntax for markup
---
inc/config.php | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/inc/config.php b/inc/config.php
index 16b14413..ec73226d 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -743,14 +743,16 @@
* ====================
*/
- // Dice Roll Markup.
- $config['markup'][] = [ "/!([-+]?\d+)?([d])([-+]?\d+)([-+]\d+)?/iu", fn($m) => handle_dice_roll_markup($m, 'static/d10.svg') ];
- // "Wiki" markup syntax ($config['wiki_markup'] in pervious versions):
- $config['markup'][] = array("/'''(.+?)'''/", "\$1");
- $config['markup'][] = array("/''(.+?)''/", "\$1");
- $config['markup'][] = array("/\*\*(.+?)\*\*/", "\$1");
- $config['markup'][] = array("/==(.+?)==/", "\$1");
+ $config['markup'] = [
+ // Dice Roll Markup.
+ [ "/!([-+]?\d+)?([d])([-+]?\d+)([-+]\d+)?/iu", fn($m) => handle_dice_roll_markup($m, 'static/d10.svg') ],
+ // "Wiki" markup syntax ($config['wiki_markup'] in pervious versions):
+ [ "/'''(.+?)'''/", "\$1" ],
+ [ "/''(.+?)''/", "\$1" ],
+ [ "/\*\*(.+?)\*\*/", "\$1" ],
+ [ "/==(.+?)==/", "\$1" ]
+ ];
// Code markup. This should be set to a regular expression, using tags you want to use. Examples:
// "/\[code\](.*?)\[\/code\]/is"
From 70bb9fb2a73b3297b4a95ba4597164a86880f113 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 00:40:55 +0200
Subject: [PATCH 010/290] faq: fix dice roll syntax
---
templates/themes/faq/index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/themes/faq/index.html b/templates/themes/faq/index.html
index 6450fd21..ffa47872 100644
--- a/templates/themes/faq/index.html
+++ b/templates/themes/faq/index.html
@@ -77,7 +77,7 @@
==text== makes it a heading: text
**text** makes it spoiler: text
[code]text[/code] makes it code:
text
- [dice:XdY+Z] rolls a X dices with Y faces, adding Z to the result: 
+ !XdY+Z rolls a X dices with Y faces, adding Z to the result: 
Why are my posts being changed / word-filtered ?
From 3e857c16f6b4dc7495f565f8badd32ea70979f7a Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 01:06:31 +0200
Subject: [PATCH 011/290] functions.php: load image from the root in
handle_dice_roll_markup.
---
inc/functions.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inc/functions.php b/inc/functions.php
index bca8d1d1..d9fea0a5 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2819,7 +2819,7 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
if ($img_path === null) {
$fmt = "$text $res";
} else {
- $fmt = "
$res";
+ $fmt = "
$res";
}
if (empty($acc)) {
$acc = $fmt;
From a90b15d596a1877fb515f211f17930dea4d9ff2b Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 10:13:05 +0200
Subject: [PATCH 012/290] functions.php: dice minimum value set to 1
---
inc/functions.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inc/functions.php b/inc/functions.php
index d9fea0a5..b215023e 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2815,7 +2815,7 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
$acc = '';
$text = "$dice_count d $dice_faces + $dice_offset";
for ($i = 0; $i < $dice_count; $i++) {
- $res = $dice_offset + mt_rand(0, $dice_faces);
+ $res = $dice_offset + mt_rand(1, $dice_faces);
if ($img_path === null) {
$fmt = "$text $res";
} else {
From 22d76ad9f6f2585ea2f7963620ce0f5e4648a4cc Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 10:14:14 +0200
Subject: [PATCH 013/290] functions.php: fix re-definition of get_or_default
---
inc/functions.php | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/inc/functions.php b/inc/functions.php
index b215023e..06d1e015 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2786,6 +2786,10 @@ function diceRoller($post) {
}
}
+function get_or_default_int(array $arr, int $index, int $default) {
+ return (isset($arr[$index]) && is_numeric($arr[$index])) ? (int)$arr[$index] : $default;
+}
+
/**
* Rolls a dice and generates the appropiate html from the markup.
* @param array $matches The array of the matches according to the default configuration.
@@ -2796,14 +2800,11 @@ function diceRoller($post) {
* @return string The html to replace the original markup with.
*/
function handle_dice_roll_markup(array $matches, ?string $img_path): string {
- function get_or_default(array $arr, int $index, int $default) {
- return (isset($arr[$index]) && is_numeric($arr[$index])) ? (int)$arr[$index] : $default;
- }
global $config;
- $dice_count = get_or_default($matches, 1, 1);
- $dice_faces = get_or_default($matches, 3, 6);
- $dice_offset = get_or_default($matches, 4, 0);
+ $dice_count = get_or_default_int($matches, 1, 1);
+ $dice_faces = get_or_default_int($matches, 3, 6);
+ $dice_offset = get_or_default_int($matches, 4, 0);
// Clamp between 1 and max_roll_count.
$dice_count = max(min($dice_count, $config['max_roll_count']), 1);
From e6b345f8ccc0196a50cdfb6a3c3ffb140964f100 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 10:52:00 +0200
Subject: [PATCH 014/290] funtions.php: rework dice markup generation
---
inc/functions.php | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/inc/functions.php b/inc/functions.php
index 06d1e015..9c956cda 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2813,23 +2813,29 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
$dice_faces = 6;
}
- $acc = '';
- $text = "$dice_count d $dice_faces + $dice_offset";
- for ($i = 0; $i < $dice_count; $i++) {
- $res = $dice_offset + mt_rand(1, $dice_faces);
- if ($img_path === null) {
- $fmt = "$text $res";
- } else {
- $fmt = "
$res";
- }
- if (empty($acc)) {
- $acc = $fmt;
- } else {
- $acc .= " $fmt";
- }
+ if ($dice_offset === 0) {
+ $dice_offset_text = '';
+ } elseif ($dice_offset > 0) {
+ $dice_offset_text = "+{$dice_offset}";
+ } else {
+ $dice_offset_text = (string)$dice_offset;
}
- return $acc;
+ if ($img_path !== null) {
+ $text = "
";
+ } else {
+ $text = '';
+ }
+
+ $text .= " {$dice_count}d{$dice_faces}{$dice_offset_text} =";
+ for ($i = 0; $i < $dice_count; $i++) {
+ $res = $dice_offset + mt_rand(1, $dice_faces);
+ $text .= " $res";
+ }
+
+ $text .= '';
+
+ return $text;
}
function slugify($post) {
From f35f9d5d676674d1296a90d42748c149be5799f8 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 14:06:41 +0200
Subject: [PATCH 015/290] config.php: increase default max_roll_count
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inc/config.php b/inc/config.php
index ec73226d..20eaf03d 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -682,7 +682,7 @@
$config['allow_roll'] = false;
// Maximum number of dice rolls per post.
- $config['max_roll_count'] = 24;
+ $config['max_roll_count'] = 100;
// Use semantic URLs for threads, like /b/res/12345/daily-programming-thread.html
$config['slugify'] = false;
From 37d275468e08930db5090f363fa40431461c14aa Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 14:02:27 +0200
Subject: [PATCH 016/290] funtions.php: unify inline dice roll result
---
inc/functions.php | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/inc/functions.php b/inc/functions.php
index 9c956cda..72e6afaa 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2813,6 +2813,17 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
$dice_faces = 6;
}
+ $tot = $dice_offset;
+ for ($i = 0; $i < $dice_count; $i++) {
+ $tot += mt_rand(1, $dice_faces);
+ }
+
+ if ($img_path !== null) {
+ $img_text = "
";
+ } else {
+ $img_text = '';
+ }
+
if ($dice_offset === 0) {
$dice_offset_text = '';
} elseif ($dice_offset > 0) {
@@ -2821,21 +2832,7 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
$dice_offset_text = (string)$dice_offset;
}
- if ($img_path !== null) {
- $text = "
";
- } else {
- $text = '';
- }
-
- $text .= " {$dice_count}d{$dice_faces}{$dice_offset_text} =";
- for ($i = 0; $i < $dice_count; $i++) {
- $res = $dice_offset + mt_rand(1, $dice_faces);
- $text .= " $res";
- }
-
- $text .= '';
-
- return $text;
+ return "$img_text {$dice_count}d{$dice_faces}{$dice_offset_text} = $tot";
}
function slugify($post) {
From 22a8eae66648fd49fa189fc25f35d73a6b566ac9 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 22:31:50 +0200
Subject: [PATCH 017/290] mod.php: trim
---
mod.php | 39 +++++++++++++++++++--------------------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/mod.php b/mod.php
index d2c98343..c153b383 100644
--- a/mod.php
+++ b/mod.php
@@ -27,16 +27,16 @@ $pages = array(
'/' => 'dashboard', // dashboard
'/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
'/logout' => 'secure logout', // logout
-
+
'/users' => 'users', // manage users
'/users/(\d+)/(promote|demote)' => 'secure user_promote', // prmote/demote user
'/users/(\d+)' => 'secure_POST user', // edit user
'/users/new' => 'secure_POST user_new', // create a new user
-
+
'/new_PM/([^/]+)' => 'secure_POST new_pm', // create a new pm
'/PM/(\d+)(/reply)?' => 'pm', // read a pm
'/inbox' => 'inbox', // pm inbox
-
+
'/log' => 'log', // modlog
'/log/(\d+)' => 'log', // modlog
'/log:([^/:]+)' => 'user_log', // modlog
@@ -52,26 +52,26 @@ $pages = array(
'/edit_page/(\d+)' => 'secure_POST edit_page',
'/edit_pages/delete/([a-z0-9]+)' => 'secure delete_page',
'/edit_pages/delete/([a-z0-9]+)/(\%b)' => 'secure delete_page_board',
-
+
'/noticeboard' => 'secure_POST noticeboard', // view noticeboard
'/noticeboard/(\d+)' => 'secure_POST noticeboard', // view noticeboard
'/noticeboard/delete/(\d+)' => 'secure noticeboard_delete', // delete from noticeboard
-
+
'/edit/(\%b)' => 'secure_POST edit_board', // edit board details
'/new-board' => 'secure_POST new_board', // create a new board
-
+
'/rebuild' => 'secure_POST rebuild', // rebuild static files
'/reports' => 'reports', // report queue
'/reports/(\d+)/dismiss(all)?' => 'secure report_dismiss', // dismiss a report
-
+
'/IP/([\w.:]+)' => 'secure_POST ip', // view ip address
'/IP/([\w.:]+)/remove_note/(\d+)' => 'secure ip_remove_note', // remove note from ip address
-
+
'/ban' => 'secure_POST ban', // new ban
'/bans' => 'secure_POST bans', // ban list
'/bans.json' => 'secure bans_json', // ban list JSON
'/ban-appeals' => 'secure_POST ban_appeals', // view ban appeals
-
+
'/recent/(\d+)' => 'recent_posts', // view recent posts
'/recent/(\d+)/([\w,]+?)' => 'recent_posts', // view recent posts
'/recent/(\d+)/([\w,]+?)/(json)?' => 'recent_posts', // view recent posts JSON
@@ -94,21 +94,21 @@ $pages = array(
'/(\%b)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread
'/(\%b)/(un)?cycle/(\d+)' => 'secure cycle', // cycle thread
'/(\%b)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread
-
+
'/themes' => 'themes_list', // manage themes
'/themes/(\w+)' => 'secure_POST theme_configure', // configure/reconfigure theme
'/themes/(\w+)/rebuild' => 'secure theme_rebuild', // rebuild theme
'/themes/(\w+)/uninstall' => 'secure theme_uninstall', // uninstall theme
-
+
'/config' => 'secure_POST config', // config editor
'/config/(\%b)' => 'secure_POST config', // config editor
-
+
// these pages aren't listed in the dashboard without $config['debug']
'/debug/antispam' => 'debug_antispam',
'/debug/recent' => 'debug_recent_posts',
'/debug/apc' => 'debug_apc',
'/debug/sql' => 'secure_POST debug_sql',
-
+
// This should always be at the end:
'/(\%b)/' => 'view_board',
'/(\%b)/' . preg_quote($config['file_index'], '!') => 'view_board',
@@ -151,7 +151,7 @@ $pages = $new_pages;
foreach ($pages as $uri => $handler) {
if (preg_match($uri, $query, $matches)) {
$matches = array_slice($matches, 1);
-
+
if (isset($matches['board'])) {
$board_match = $matches['board'];
unset($matches['board']);
@@ -160,12 +160,12 @@ foreach ($pages as $uri => $handler) {
$matches[$key] = $board_match[1];
}
}
-
+
if (is_string($handler) && preg_match('/^secure(_POST)? /', $handler, $m)) {
$secure_post_only = isset($m[1]);
if (!$secure_post_only || $_SERVER['REQUEST_METHOD'] == 'POST') {
$token = isset($matches['token']) ? $matches['token'] : (isset($_POST['token']) ? $_POST['token'] : false);
-
+
if ($token === false) {
if ($secure_post_only)
error($config['error']['csrf']);
@@ -174,7 +174,7 @@ foreach ($pages as $uri => $handler) {
exit;
}
}
-
+
// CSRF-protected page; validate security token
$actual_query = preg_replace('!/([a-f0-9]{8})$!', '', $query);
if ($token != make_secure_link_token(substr($actual_query, 1))) {
@@ -183,7 +183,7 @@ foreach ($pages as $uri => $handler) {
}
$handler = preg_replace('/^secure(_POST)? /', '', $handler);
}
-
+
if ($config['debug']) {
$debug['mod_page'] = array(
'req' => $query,
@@ -213,10 +213,9 @@ foreach ($pages as $uri => $handler) {
} else {
error("Mod page '$handler' not a string, and not callable!");
}
-
+
exit;
}
}
error($config['error']['404']);
-
From 52759954c888450c4c0114679e2110a827f8c322 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 18:28:56 +0200
Subject: [PATCH 018/290] pages.php: add a basic cache layer for mod_page_ip
---
inc/mod/pages.php | 42 ++++++++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index dc870b79..1bbe60d0 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -897,15 +897,18 @@ function mod_page_ip($ip) {
$query->bindValue(':body', $_POST['note']);
$query->execute() or error(db_error($query));
+ Cache::delete("mod_page_ip_view_notes_$ip");
+
modLog("Added a note for {$ip}");
header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']);
return;
}
- $args = array();
- $args['ip'] = $ip;
- $args['posts'] = array();
+ $args = [
+ 'ip' => $ip,
+ 'posts' => []
+ ];
if ($config['mod']['dns_lookup'])
$args['hostname'] = rDNS($ip);
@@ -927,8 +930,9 @@ function mod_page_ip($ip) {
$po = new Post($post, '?/', $mod);
}
- if (!isset($args['posts'][$board['uri']]))
- $args['posts'][$board['uri']] = array('board' => $board, 'posts' => array());
+ if (!isset($args['posts'][$board['uri']])) {
+ $args['posts'][$board['uri']] = [ 'board' => $board, 'posts' => [] ];
+ }
$args['posts'][$board['uri']]['posts'][] = $po->build(true);
}
}
@@ -941,19 +945,29 @@ function mod_page_ip($ip) {
}
if (hasPermission($config['mod']['view_notes'])) {
- $query = prepare("SELECT ``ip_notes``.*, `username` FROM ``ip_notes`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `ip` = :ip ORDER BY `time` DESC");
- $query->bindValue(':ip', $ip);
- $query->execute() or error(db_error($query));
- $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
+ $ret = Cache::get("mod_page_ip_view_notes_$ip");
+ if (!$ret) {
+ $query = prepare("SELECT ``ip_notes``.*, `username` FROM ``ip_notes`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `ip` = :ip ORDER BY `time` DESC");
+ $query->bindValue(':ip', $ip);
+ $query->execute() or error(db_error($query));
+ $ret = $query->fetchAll(PDO::FETCH_ASSOC);
+ Cache::set("mod_page_ip_view_notes_$ip", $ret, 900);
+ }
+ $args['notes'] = $ret;
}
if (hasPermission($config['mod']['modlog_ip'])) {
- $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 50");
- $query->bindValue(':search', '%' . $ip . '%');
- $query->execute() or error(db_error($query));
- $args['logs'] = $query->fetchAll(PDO::FETCH_ASSOC);
+ $ret = Cache::get("mod_page_ip_modlog_ip_$ip");
+ if (!$ret) {
+ $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 50");
+ $query->bindValue(':search', '%' . $ip . '%');
+ $query->execute() or error(db_error($query));
+ $ret = $query->fetchAll(PDO::FETCH_ASSOC);
+ Cache::set("mod_page_ip_modlog_ip_$ip", $ret, 900);
+ }
+ $args['logs'] = $ret;
} else {
- $args['logs'] = array();
+ $args['logs'] = [];
}
$args['security_token'] = make_secure_link_token('IP/' . $ip);
From cc82987bb01047974e6742d8aabbbeba3e01d434 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Tue, 15 Oct 2024 19:30:54 +0200
Subject: [PATCH 019/290] database.php: minor format
---
inc/database.php | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/inc/database.php b/inc/database.php
index c2612493..380a0837 100644
--- a/inc/database.php
+++ b/inc/database.php
@@ -70,9 +70,9 @@ function sql_open() {
if (!empty($config['db']['dsn']))
$dsn .= ';' . $config['db']['dsn'];
try {
- $options = array(
+ $options = [
PDO::ATTR_TIMEOUT => $config['db']['timeout'],
- );
+ ];
if ($config['db']['type'] == "mysql")
$options[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true;
@@ -81,13 +81,11 @@ function sql_open() {
$options[PDO::ATTR_PERSISTENT] = true;
$pdo = new PDO($dsn, $config['db']['user'], $config['db']['password'], $options);
- if ($config['debug'])
+ if ($config['debug']) {
$debug['time']['db_connect'] = '~' . round((microtime(true) - $start) * 1000, 2) . 'ms';
- if ($config['db']['type'] == "mysql"){
- if (mysql_version() >= 50503)
- query('SET NAMES utf8mb4') or error(db_error());
- else
+ if ($config['db']['type'] == "mysql") {
query('SET NAMES utf8') or error(db_error());
+ }
}
return $pdo;
} catch(PDOException $e) {
From 585e5638fdda6ccfe9cbff8743a89e287e14fbdd Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Tue, 15 Oct 2024 21:10:00 +0200
Subject: [PATCH 020/290] functions.php: handle very large numbers with
handle_dice_roll_markup
---
inc/functions.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/inc/functions.php b/inc/functions.php
index 72e6afaa..2328c1b7 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2813,10 +2813,12 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
$dice_faces = 6;
}
- $tot = $dice_offset;
+ $tot = 0;
for ($i = 0; $i < $dice_count; $i++) {
$tot += mt_rand(1, $dice_faces);
}
+ // Ensure that final result is at least an integer.
+ $tot = abs((int)($dice_offset + $tot));
if ($img_path !== null) {
$img_text = "
";
From fa26f6e88f2124e57c6777e2361980b775f23e80 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 23:11:47 +0200
Subject: [PATCH 021/290] config.php: update configuration documentation for
ip_recentposts
---
inc/config.php | 2 +-
mod.php | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/inc/config.php b/inc/config.php
index 20eaf03d..b12227c0 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -1496,7 +1496,7 @@
// Do DNS lookups on IP addresses to get their hostname for the moderator IP pages (?/IP/x.x.x.x).
$config['mod']['dns_lookup'] = true;
- // How many recent posts, per board, to show in ?/IP/x.x.x.x.
+ // How many recent posts, per board, to show in each page of ?/IP/x.x.x.x.
$config['mod']['ip_recentposts'] = 5;
// Number of posts to display on the reports page.
diff --git a/mod.php b/mod.php
index c153b383..0851dfc6 100644
--- a/mod.php
+++ b/mod.php
@@ -65,6 +65,7 @@ $pages = array(
'/reports/(\d+)/dismiss(all)?' => 'secure report_dismiss', // dismiss a report
'/IP/([\w.:]+)' => 'secure_POST ip', // view ip address
+ '/IP/([\w.:]+)/cursor/([\w|-|_|.]+)' => 'secure_POST ip', // view ip address
'/IP/([\w.:]+)/remove_note/(\d+)' => 'secure ip_remove_note', // remove note from ip address
'/ban' => 'secure_POST ban', // new ban
From 92fee878b53fb2c331470c346b0e0d7a4006f9a5 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 23:12:27 +0200
Subject: [PATCH 022/290] net.php: add functions to encode and decode a typed
cursor over an url
---
inc/functions/net.php | 60 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/inc/functions/net.php b/inc/functions/net.php
index 4319a3f3..1384f651 100644
--- a/inc/functions/net.php
+++ b/inc/functions/net.php
@@ -15,3 +15,63 @@ function is_connection_https(): bool {
function is_connection_secure(): bool {
return is_connection_https() || (!empty($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] === '127.0.0.1');
}
+
+/**
+ * Encodes a string into a base64 variant without characters illegal in urls.
+ */
+function base64_url_encode(string $input): string {
+ return strtr(base64_encode($input), '+/=', '-_.');
+}
+
+/**
+ * Decodes a string from a base64 variant without characters illegal in urls.
+ */
+function base64_url_decode(string $input): string {
+ return base64_decode(strtr($input, '-_.', '+/='));
+}
+
+/**
+ * Encodes a typed cursor.
+ *
+ * @param string $type The type for the cursor. Only the first character is considered.
+ * @param array $map A map of key-value pairs to encode.
+ * @return string An encoded string that can be sent through urls. Empty if either parameter is empty.
+ */
+function encode_cursor(string $type, array $map): string {
+ if (empty($type) || empty($map)) {
+ return '';
+ }
+
+ $acc = $type[0];
+ foreach ($map as $key => $value) {
+ $acc .= "|$key#$value";
+ }
+ return base64_url_encode($acc);
+}
+
+/**
+ * Decodes a typed cursor.
+ *
+ * @param string $cursor A string emitted by `encode_cursor`.
+ * @return array An array with the type of the cursor and an array of key-value pairs. The type is null and the map
+ * empty if either there are no key-value pairs or the encoding is incorrect.
+ */
+function decode_cursor(string $cursor): array {
+ $map = [];
+ $type = '';
+ $acc = base64_url_decode($cursor);
+ if ($acc === false || empty($acc)) {
+ return [ null, [] ];
+ }
+
+ $type = $acc[0];
+ foreach (explode('|', substr($acc, 2)) as $pair) {
+ $pair = explode('#', $pair);
+ if (count($pair) >= 2) {
+ $key = $pair[0];
+ $value = $pair[1];
+ $map[$key] = $value;
+ }
+ }
+ return [ $type, $map ];
+}
From 82463bb720c68808725ae7e703c1d46757f56791 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Mon, 14 Oct 2024 23:13:04 +0200
Subject: [PATCH 023/290] mod.php: pass cursor to mod_page_ip
---
mod.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mod.php b/mod.php
index 0851dfc6..9587c8e1 100644
--- a/mod.php
+++ b/mod.php
@@ -65,7 +65,7 @@ $pages = array(
'/reports/(\d+)/dismiss(all)?' => 'secure report_dismiss', // dismiss a report
'/IP/([\w.:]+)' => 'secure_POST ip', // view ip address
- '/IP/([\w.:]+)/cursor/([\w|-|_|.]+)' => 'secure_POST ip', // view ip address
+ '/IP/([\w.:]+)/cursor/([\w|-|_|.]+)' => 'secure_POST ip', // view ip address
'/IP/([\w.:]+)/remove_note/(\d+)' => 'secure ip_remove_note', // remove note from ip address
'/ban' => 'secure_POST ban', // new ban
From b9081be4ace065abbf9d194e5f1eb32af3768796 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Tue, 15 Oct 2024 00:15:54 +0200
Subject: [PATCH 024/290] view_ip.html: add links to previous and next cursors
---
templates/mod/view_ip.html | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/templates/mod/view_ip.html b/templates/mod/view_ip.html
index d47e6d4f..78fce4a9 100644
--- a/templates/mod/view_ip.html
+++ b/templates/mod/view_ip.html
@@ -4,7 +4,7 @@
{% set notes_on_record = 'note' ~ (notes|count != 1 ? 's' : '') ~ ' on record' %}
-
+
{% if notes and notes|length > 0 %}
@@ -41,7 +41,7 @@
{% endfor %}
{% endif %}
-
+
{% if mod|hasPermission(config.mod.create_notes) %}