Merge branch 'config' into defer-javascript

This commit is contained in:
nonmakina 2021-07-11 11:23:03 +02:00 committed by GitHub
commit b992a926cc
19 changed files with 129 additions and 77 deletions

View file

@ -45,8 +45,9 @@ class Api {
);
$this->fileFields = array(
'thumbheight' => 'tn_h',
'thumbwidth' => 'tn_w',
'file_id' => 'id',
'type' => 'mime',
'extension' => 'ext',
'height' => 'h',
'width' => 'w',
'size' => 'fsize',
@ -90,13 +91,12 @@ class Api {
}
private function translateFile($file, $post, &$apiPost) {
global $config;
$this->translateFields($this->fileFields, $file, $apiPost);
$apiPost['filename'] = @substr($file->name, 0, strrpos($file->name, '.'));
$dotPos = strrpos($file->file, '.');
$apiPost['ext'] = substr($file->file, $dotPos);
$apiPost['tim'] = substr($file->file, 0, $dotPos);
if (isset ($file->thumb) && $file->thumb) {
$apiPost['spoiler'] = $file->thumb === 'spoiler' ? 1 : 0;
$apiPost['spoiler'] = $file->thumb === 'spoiler';
}
if (isset ($file->hash) && $file->hash) {
$apiPost['md5'] = base64_encode(hex2bin($file->hash));
@ -104,6 +104,25 @@ class Api {
else if (isset ($post->filehash) && $post->filehash) {
$apiPost['md5'] = base64_encode(hex2bin($post->filehash));
}
$apiPost['file_path'] = $config['uri_img'] . $file->file;
// Pick the correct thumbnail
if (isset($file->thumb) && $file->thumb === 'spoiler') {
// Spoiler
$apiPost['thumb_path'] = $config['root'] . $config['spoiler_image'];
} else if (!isset($file->thumb) || $file->thumb === 'file') {
// Default file format image
$thumbFile = $config['file_icons']['default'];
if (isset($file->extension) && isset($config['file_icons'][$file->extension])) {
$thumbFile = $config['file_icons'][$file->extension];
}
$apiPost['thumb_path'] = $config['root'] . sprintf($config['file_thumb'], $thumbFile);
} else {
// The file's own thumbnail
$apiPost['thumb_path'] = $config['uri_thumb'] . $file->thumb;
}
}
private function translatePost($post, $threadsPage = false) {
@ -115,6 +134,11 @@ class Api {
if (isset($config['poster_ids']) && $config['poster_ids']) $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']);
if ($threadsPage) return $apiPost;
// Load board info
if (isset($post->board)) {
openBoard($post->board);
}
// Handle special fields
if (isset($post->body_nomarkup) && ($this->config['country_flags'] || $this->config['user_flag'])) {
$modifiers = extract_modifiers($post->body_nomarkup);
@ -138,21 +162,13 @@ class Api {
}
// Handle files
// Note: 4chan only supports one file, so only the first file is taken into account for 4chan-compatible API.
if (isset($post->files) && $post->files && !$threadsPage) {
$file = $post->files[0];
$this->translateFile($file, $post, $apiPost);
if (sizeof($post->files) > 1) {
$extra_files = array();
foreach ($post->files as $i => $f) {
if ($i == 0) continue;
$apiPost['files'] = [];
foreach ($post->files as $f) {
$file = array();
$this->translateFile($f, $post, $file);
$extra_file = array();
$this->translateFile($f, $post, $extra_file);
$extra_files[] = $extra_file;
}
$apiPost['extra_files'] = $extra_files;
$apiPost['files'][] = $file;
}
}

View file

@ -484,8 +484,11 @@
// Strip superfluous new lines at the end of a post.
$config['strip_superfluous_returns'] = true;
// Strip combining characters from Unicode strings (eg. "Zalgo").
// Strip combining characters from Unicode strings (eg. "Zalgo"). This will impact some non-English languages.
$config['strip_combining_chars'] = true;
// Maximum number of combining characters in a row allowed in Unicode strings so that they can still be used in moderation.
// Requires $config['strip_combining_chars'] = true;
$config['max_combining_chars'] = 0;
// Maximum post body length.
$config['max_body'] = 1800;

View file

@ -2196,8 +2196,8 @@ function markup(&$body, $track_cites = false, $op = false) {
$code = rtrim(ltrim($code, "\r\n"));
$code = "<pre class='code lang-$code_lang'>".str_replace(array("\n","\t"), array("&#10;","&#9;"), htmlspecialchars($code))."</pre>";
$code = "<pre class='code lang-$code_lang'>".str_replace(array("\n","\t"), array("&#10;","&#9;"), htmlspecialchars($code, ENT_COMPAT, "UTF-8", false))."</pre>";
$body = str_replace("<code $id>", $code, $body);
}
}
@ -2257,19 +2257,11 @@ function ordutf8($string, &$offset) {
return $code;
}
// Limit Non_Spacing_Mark and Enclosing_Mark characters
function strip_combining_chars($str) {
$chars = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
$str = '';
foreach ($chars as $char) {
$o = 0;
$ord = ordutf8($char, $o);
if ( ($ord >= 768 && $ord <= 879) || ($ord >= 1536 && $ord <= 1791) || ($ord >= 3655 && $ord <= 3659) || ($ord >= 7616 && $ord <= 7679) || ($ord >= 8400 && $ord <= 8447) || ($ord >= 65056 && $ord <= 65071))
continue;
$str .= $char;
}
return $str;
global $config;
$limit = strval($config['max_combining_chars']+1);
return preg_replace('/(\p{Me}|\p{Mn}){'.$limit.',}/u','', $str);
}
function buildThread($id, $return = false, $mod = false) {

View file

@ -106,6 +106,10 @@ $config['threads_preview'] = 5;
$config['root'] = '/';
$config['secure_trip_salt'] = 'ODQ2NDM0ODlmMmRhNzk2M2EyNjJlOW';
$config['strip_combining_chars'] = true;
// Maximum number of combining characters in a row allowed so that they can still be used in moderation.
$config['max_combining_chars'] = 3;
//Banners
$config['url_banner'] = '/banners.php';
@ -273,6 +277,7 @@ $config['user_flags'] = array (
'ndfp' => 'NDFP',
'palestine' => 'Palestine',
'pan-africanism' => 'Pan-Africanism',
'cenzopapa' => 'Papież',
'phrygian_cap' => 'Phrygian Cap',
'pirate' => 'Pirate',
'porky' => 'Porky',
@ -439,6 +444,8 @@ $config['markup'][] = array("/~~(.+?)~~/", "<span class=\"strikethrough\">\$1</s
// $config['wordfilters'][] = array('/nigger/i', 'uyghur', true);
// $config['wordfilters'][] = array('/nigg/i', 'uygh', true);
$config['wordfilters'][] = array('/chud/i', 'FAGGOT', true);
/*
* Traditional word filters. Expires 31-12-2021.
*