From 4674f44327fe400df39418ce85b750e65f0090a8 Mon Sep 17 00:00:00 2001 From: Lorenzo Yario Date: Mon, 29 Apr 2024 15:18:54 -0700 Subject: [PATCH 1/7] soyjak upstream for api changes --- inc/api.php | 69 ++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/inc/api.php b/inc/api.php index 0dd479ac..bdf20319 100644 --- a/inc/api.php +++ b/inc/api.php @@ -16,39 +16,42 @@ class Api { */ $this->config = $config; - $this->postFields = array( - 'id' => 'no', - 'thread' => 'resto', - 'subject' => 'sub', - 'body' => 'com', - 'email' => 'email', - 'name' => 'name', - 'trip' => 'trip', - 'capcode' => 'capcode', - 'time' => 'time', - 'omitted' => 'omitted_posts', - 'omitted_images' => 'omitted_images', - 'replies' => 'replies', - 'images' => 'images', - 'sticky' => 'sticky', - 'locked' => 'locked', - 'cycle' => 'cyclical', - 'bump' => 'last_modified', - 'embed' => 'embed', - ); - - $this->threadsPageFields = array( - 'id' => 'no', - 'bump' => 'last_modified' - ); - - $this->fileFields = array( - 'thumbheight' => 'tn_h', - 'thumbwidth' => 'tn_w', - 'height' => 'h', - 'width' => 'w', - 'size' => 'fsize', - ); + $this->postFields = array( + 'id' => 'no', + 'thread' => 'resto', + 'subject' => 'sub', + 'body' => 'com', + 'body_nomarkup' => '___body_nomarkup', + 'email' => 'email', + 'name' => 'name', + 'trip' => 'trip', + 'capcode' => 'capcode', + 'time' => 'time', + 'omitted' => 'omitted_posts', + 'omitted_images' => 'omitted_images', + 'replies' => 'replies', + 'images' => 'images', + 'sticky' => 'sticky', + 'locked' => 'locked', + 'cycle' => 'cyclical', + 'bump' => 'last_modified', + 'embed' => 'embed', + ); + + $this->threadsPageFields = array( + 'id' => 'no', + 'bump' => 'last_modified' + ); + + $this->fileFields = array( + 'thumbheight' => 'tn_h', + 'thumbwidth' => 'tn_w', + 'height' => 'h', + 'width' => 'w', + 'size' => 'fsize', + 'thumb' => 'thumb', + 'filename' => 'filename', + ); if (isset($config['api']['extra_fields']) && gettype($config['api']['extra_fields']) == 'array'){ $this->postFields = array_merge($this->postFields, $config['api']['extra_fields']); From 6cd11d546fd7e5401e51f7c55fe3754edc7a3175 Mon Sep 17 00:00:00 2001 From: Lorenzo Yario Date: Mon, 29 Apr 2024 15:20:17 -0700 Subject: [PATCH 2/7] undid to do a pr for it --- inc/api.php | 69 +++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/inc/api.php b/inc/api.php index bdf20319..0dd479ac 100644 --- a/inc/api.php +++ b/inc/api.php @@ -16,42 +16,39 @@ class Api { */ $this->config = $config; - $this->postFields = array( - 'id' => 'no', - 'thread' => 'resto', - 'subject' => 'sub', - 'body' => 'com', - 'body_nomarkup' => '___body_nomarkup', - 'email' => 'email', - 'name' => 'name', - 'trip' => 'trip', - 'capcode' => 'capcode', - 'time' => 'time', - 'omitted' => 'omitted_posts', - 'omitted_images' => 'omitted_images', - 'replies' => 'replies', - 'images' => 'images', - 'sticky' => 'sticky', - 'locked' => 'locked', - 'cycle' => 'cyclical', - 'bump' => 'last_modified', - 'embed' => 'embed', - ); - - $this->threadsPageFields = array( - 'id' => 'no', - 'bump' => 'last_modified' - ); - - $this->fileFields = array( - 'thumbheight' => 'tn_h', - 'thumbwidth' => 'tn_w', - 'height' => 'h', - 'width' => 'w', - 'size' => 'fsize', - 'thumb' => 'thumb', - 'filename' => 'filename', - ); + $this->postFields = array( + 'id' => 'no', + 'thread' => 'resto', + 'subject' => 'sub', + 'body' => 'com', + 'email' => 'email', + 'name' => 'name', + 'trip' => 'trip', + 'capcode' => 'capcode', + 'time' => 'time', + 'omitted' => 'omitted_posts', + 'omitted_images' => 'omitted_images', + 'replies' => 'replies', + 'images' => 'images', + 'sticky' => 'sticky', + 'locked' => 'locked', + 'cycle' => 'cyclical', + 'bump' => 'last_modified', + 'embed' => 'embed', + ); + + $this->threadsPageFields = array( + 'id' => 'no', + 'bump' => 'last_modified' + ); + + $this->fileFields = array( + 'thumbheight' => 'tn_h', + 'thumbwidth' => 'tn_w', + 'height' => 'h', + 'width' => 'w', + 'size' => 'fsize', + ); if (isset($config['api']['extra_fields']) && gettype($config['api']['extra_fields']) == 'array'){ $this->postFields = array_merge($this->postFields, $config['api']['extra_fields']); From b7eed34b832e70f45cdfa211e9601d177f5b0248 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 30 Apr 2024 12:32:40 +0200 Subject: [PATCH 3/7] functions: split off time formatting functions --- inc/bans.php | 3 ++- inc/functions.php | 36 ------------------------------------ inc/functions/format.php | 28 ++++++++++++++++++++++++++++ inc/mod/pages.php | 4 +++- inc/template.php | 4 ++-- post.php | 5 +++-- 6 files changed, 38 insertions(+), 42 deletions(-) create mode 100644 inc/functions/format.php diff --git a/inc/bans.php b/inc/bans.php index 8ea3b921..126d38b8 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -1,5 +1,6 @@ execute() or error(db_error($query)); if (isset($mod['id']) && $mod['id'] == $mod_id) { modLog('Created a new ' . - ($length > 0 ? preg_replace('/^(\d+) (\w+?)s?$/', '$1-$2', until($length)) : 'permanent') . + ($length > 0 ? preg_replace('/^(\d+) (\w+?)s?$/', '$1-$2', Format\until($length)) : 'permanent') . ' ban on ' . ($ban_board ? '/' . $ban_board . '/' : 'all boards') . ' for ' . diff --git a/inc/functions.php b/inc/functions.php index 71231203..c18ca57e 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -797,42 +797,6 @@ function listBoards($just_uri = false) { return $boards; } -function until($timestamp) { - $difference = $timestamp - time(); - switch(TRUE){ - case ($difference < 60): - return $difference . ' ' . ngettext('second', 'seconds', $difference); - case ($difference < 3600): //60*60 = 3600 - return ($num = round($difference/(60))) . ' ' . ngettext('minute', 'minutes', $num); - case ($difference < 86400): //60*60*24 = 86400 - return ($num = round($difference/(3600))) . ' ' . ngettext('hour', 'hours', $num); - case ($difference < 604800): //60*60*24*7 = 604800 - return ($num = round($difference/(86400))) . ' ' . ngettext('day', 'days', $num); - case ($difference < 31536000): //60*60*24*365 = 31536000 - return ($num = round($difference/(604800))) . ' ' . ngettext('week', 'weeks', $num); - default: - return ($num = round($difference/(31536000))) . ' ' . ngettext('year', 'years', $num); - } -} - -function ago($timestamp) { - $difference = time() - $timestamp; - switch(TRUE){ - case ($difference < 60) : - return $difference . ' ' . ngettext('second', 'seconds', $difference); - case ($difference < 3600): //60*60 = 3600 - return ($num = round($difference/(60))) . ' ' . ngettext('minute', 'minutes', $num); - case ($difference < 86400): //60*60*24 = 86400 - return ($num = round($difference/(3600))) . ' ' . ngettext('hour', 'hours', $num); - case ($difference < 604800): //60*60*24*7 = 604800 - return ($num = round($difference/(86400))) . ' ' . ngettext('day', 'days', $num); - case ($difference < 31536000): //60*60*24*365 = 31536000 - return ($num = round($difference/(604800))) . ' ' . ngettext('week', 'weeks', $num); - default: - return ($num = round($difference/(31536000))) . ' ' . ngettext('year', 'years', $num); - } -} - function displayBan($ban) { global $config, $board; diff --git a/inc/functions/format.php b/inc/functions/format.php new file mode 100644 index 00000000..79a71021 --- /dev/null +++ b/inc/functions/format.php @@ -0,0 +1,28 @@ + time() - $config['delete_time'] && (!$thread || $thread['password'] != $password)) { - error(sprintf($config['error']['delete_too_soon'], until($post['time'] + $config['delete_time']))); + error(sprintf($config['error']['delete_too_soon'], Format\until($post['time'] + $config['delete_time']))); } $ip = $_SERVER['REMOTE_ADDR']; From 687e8e078a6c72b79465ccf28ae2498d067f60e9 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 30 Apr 2024 12:34:39 +0200 Subject: [PATCH 4/7] Add format.php to autoload --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index b06ff6a1..0075d879 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "inc/lock.php", "inc/queue.php", "inc/functions.php", + "inc/functions/format.php", "inc/driver/http-driver.php", "inc/driver/log-driver.php", "inc/service/captcha-queries.php" From 7041cd13df0efcecd4223a11f5b83e67ffd36098 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 30 Apr 2024 12:46:26 +0200 Subject: [PATCH 5/7] functions: split off numeric functions --- inc/functions/num.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 inc/functions/num.php diff --git a/inc/functions/num.php b/inc/functions/num.php new file mode 100644 index 00000000..678312f3 --- /dev/null +++ b/inc/functions/num.php @@ -0,0 +1,33 @@ + $b) { + $a = $a+$b; + $b = $a-$b; + $a = $a-$b; + } + if ($b == (round($b / $a)) * $a) { + $gcd = $a; + } else { + for ($i = round($a / 2); $i; $i--) { + if ($a == round($a / $i) * $i && $b == round($b / $i) * $i) { + $gcd = $i; + $i = false; + } + } + } + + return $gcd; +} + +function fraction($numerator, $denominator, $sep) { + $gcf = hcf($numerator, $denominator); + $numerator = $numerator / $gcf; + $denominator = $denominator / $gcf; + + return "{$numerator}{$sep}{$denominator}"; +} From f6960b8b3a920ae3260981301e51ef47f6eec60a Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 30 Apr 2024 12:46:44 +0200 Subject: [PATCH 6/7] functions.php: format and trim --- inc/functions.php | 130 ++++++++++++++-------------------------------- 1 file changed, 40 insertions(+), 90 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index c18ca57e..1d98f9cf 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -21,9 +21,7 @@ loadConfig(); function init_locale($locale, $error='error') { if (extension_loaded('gettext')) { - if (setlocale(LC_ALL, $locale) === false) { - //$error('The specified locale (' . $locale . ') does not exist on your platform!'); - } + setlocale(LC_ALL, $locale); bindtextdomain('tinyboard', './inc/locale'); bind_textdomain_codeset('tinyboard', 'UTF-8'); textdomain('tinyboard'); @@ -55,8 +53,9 @@ function loadConfig() { if (isset($config['cache_config']) && - $config['cache_config'] && - $config = Cache::get('config_' . $boardsuffix ) ) { + $config['cache_config'] && + $config = Cache::get('config_' . $boardsuffix)) + { $events = Cache::get('events_' . $boardsuffix ); define_groups(); @@ -66,11 +65,10 @@ function loadConfig() { } if ($config['locale'] != $current_locale) { - $current_locale = $config['locale']; - init_locale($config['locale'], $error); - } - } - else { + $current_locale = $config['locale']; + init_locale($config['locale'], $error); + } + } else { $config = array(); reset_events(); @@ -180,8 +178,8 @@ function loadConfig() { '(' . str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . '|' . str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . '|' . - str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '/')) . '|' . - str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . + str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '/')) . '|' . + str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . ')' . '|' . preg_quote($config['file_mod'], '/') . '\?\/.+' . @@ -242,12 +240,13 @@ function loadConfig() { $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false; $config['version'] = $__version; - if ($config['allow_roll']) + if ($config['allow_roll']) { event_handler('post', 'diceRoller'); + } - if (in_array('webm', $config['allowed_ext_files']) || - in_array('mp4', $config['allowed_ext_files'])) + if (in_array('webm', $config['allowed_ext_files']) || in_array('mp4', $config['allowed_ext_files'])) { event_handler('post', 'postHandler'); + } } // Effectful config processing below: @@ -280,8 +279,7 @@ function loadConfig() { if ($config['cache']['enabled']) require_once 'inc/cache.php'; - if (in_array('webm', $config['allowed_ext_files']) || - in_array('mp4', $config['allowed_ext_files'])) + if (in_array('webm', $config['allowed_ext_files']) || in_array('mp4', $config['allowed_ext_files'])) require_once 'inc/lib/webm/posthandler.php'; event('load-config'); @@ -517,12 +515,11 @@ function mb_substr_replace($string, $replacement, $start, $length) { function setupBoard($array) { global $board, $config; - $board = array( + $board = [ 'uri' => $array['uri'], 'title' => $array['title'], 'subtitle' => $array['subtitle'], - #'indexed' => $array['indexed'], - ); + ]; // older versions $board['name'] = &$board['title']; @@ -720,8 +717,8 @@ function file_unlink($path) { $ret = @unlink($path); - if ($config['gzip_static']) { - $gzpath = "$path.gz"; + if ($config['gzip_static']) { + $gzpath = "$path.gz"; @unlink($gzpath); } @@ -1231,25 +1228,25 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { $query->bindValue(':board', $board['uri']); $query->execute() or error(db_error($query)); - // No need to run on OPs - if ($config['anti_bump_flood'] && isset($thread_id)) { - $query = prepare(sprintf("SELECT `sage` FROM ``posts_%s`` WHERE `id` = :thread", $board['uri'])); - $query->bindValue(':thread', $thread_id); - $query->execute() or error(db_error($query)); - $bumplocked = (bool)$query->fetchColumn(); + // No need to run on OPs + if ($config['anti_bump_flood'] && isset($thread_id)) { + $query = prepare(sprintf("SELECT `sage` FROM ``posts_%s`` WHERE `id` = :thread", $board['uri'])); + $query->bindValue(':thread', $thread_id); + $query->execute() or error(db_error($query)); + $bumplocked = (bool)$query->fetchColumn(); - if (!$bumplocked) { - $query = prepare(sprintf("SELECT `time` FROM ``posts_%s`` WHERE (`thread` = :thread AND NOT email <=> 'sage') OR `id` = :thread ORDER BY `time` DESC LIMIT 1", $board['uri'])); - $query->bindValue(':thread', $thread_id); - $query->execute() or error(db_error($query)); - $bump = $query->fetchColumn(); + if (!$bumplocked) { + $query = prepare(sprintf("SELECT `time` FROM ``posts_%s`` WHERE (`thread` = :thread AND NOT email <=> 'sage') OR `id` = :thread ORDER BY `time` DESC LIMIT 1", $board['uri'])); + $query->bindValue(':thread', $thread_id); + $query->execute() or error(db_error($query)); + $bump = $query->fetchColumn(); - $query = prepare(sprintf("UPDATE ``posts_%s`` SET `bump` = :bump WHERE `id` = :thread", $board['uri'])); - $query->bindValue(':bump', $bump); - $query->bindValue(':thread', $thread_id); - $query->execute() or error(db_error($query)); - } - } + $query = prepare(sprintf("UPDATE ``posts_%s`` SET `bump` = :bump WHERE `id` = :thread", $board['uri'])); + $query->bindValue(':bump', $bump); + $query->bindValue(':thread', $thread_id); + $query->execute() or error(db_error($query)); + } + } if (isset($rebuild) && $rebuild_after) { buildThread($rebuild); @@ -2536,35 +2533,6 @@ function generate_tripcode($name) { return array($name, $trip); } -// Highest common factor -function hcf($a, $b){ - $gcd = 1; - if ($a>$b) { - $a = $a+$b; - $b = $a-$b; - $a = $a-$b; - } - if ($b==(round($b/$a))*$a) - $gcd=$a; - else { - for ($i=round($a/2);$i;$i--) { - if ($a == round($a/$i)*$i && $b == round($b/$i)*$i) { - $gcd = $i; - $i = false; - } - } - } - return $gcd; -} - -function fraction($numerator, $denominator, $sep) { - $gcf = hcf($numerator, $denominator); - $numerator = $numerator / $gcf; - $denominator = $denominator / $gcf; - - return "{$numerator}{$sep}{$denominator}"; -} - function getPostByHash($hash) { global $board; $query = prepare(sprintf("SELECT `id`,`thread` FROM ``posts_%s`` WHERE `filehash` = :hash", $board['uri'])); @@ -2799,10 +2767,10 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false) if ($slug === false) { $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $b['uri'])); - $query->bindValue(':id', $id, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); - $thread = $query->fetch(PDO::FETCH_ASSOC); + $thread = $query->fetch(PDO::FETCH_ASSOC); $slug = $thread['slug']; @@ -2818,7 +2786,7 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false) } - if ( $page50 && $slug) $tpl = $config['file_page50_slug']; + if ( $page50 && $slug) $tpl = $config['file_page50_slug']; else if (!$page50 && $slug) $tpl = $config['file_page_slug']; else if ( $page50 && !$slug) $tpl = $config['file_page50']; else if (!$page50 && !$slug) $tpl = $config['file_page']; @@ -2830,24 +2798,6 @@ function prettify_textarea($s){ return str_replace("\t", ' ', str_replace("\n", ' ', htmlentities($s))); } -/*class HTMLPurifier_URIFilter_NoExternalImages extends HTMLPurifier_URIFilter { - public $name = 'NoExternalImages'; - public function filter(&$uri, $c, $context) { - global $config; - $ct = $context->get('CurrentToken'); - - if (!$ct || $ct->name !== 'img') return true; - - if (!isset($uri->host) && !isset($uri->scheme)) return true; - - if (!in_array($uri->scheme . '://' . $uri->host . '/', $config['allowed_offsite_urls'])) { - error('No off-site links in board announcement images.'); - } - - return true; - } -}*/ - function purify_html($s) { global $config; From 5bb1202def16d3f005ee069294dc21e8c5bb2d78 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 30 Apr 2024 12:48:02 +0200 Subject: [PATCH 7/7] Add num.php to autoloader --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 0075d879..a61b6ce7 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "inc/lock.php", "inc/queue.php", "inc/functions.php", + "inc/functions/num.php", "inc/functions/format.php", "inc/driver/http-driver.php", "inc/driver/log-driver.php",