diff --git a/assets/typescript/.gitkeep b/assets/typescript/.gitkeep deleted file mode 100644 index 8b137891..00000000 --- a/assets/typescript/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/assets/typescript/CurrentUserInfo.ts b/assets/typescript/CurrentUserInfo.ts new file mode 100644 index 00000000..e3b6f45b --- /dev/null +++ b/assets/typescript/CurrentUserInfo.ts @@ -0,0 +1,6 @@ +export default interface CurrentUserInfo { + user_id: number; + username: string; + user_background_settings: number; + user_colour: number; +} diff --git a/assets/typescript/misuzu.ts b/assets/typescript/misuzu.ts new file mode 100644 index 00000000..3cc88aaf --- /dev/null +++ b/assets/typescript/misuzu.ts @@ -0,0 +1,22 @@ +import CurrentUserInfo from 'CurrentUserInfo'; + +declare const timeago: any; +declare const hljs: any; + +// Initialisation process. +window.addEventListener('load', () => { + console.log('a sardine grows from the soil'); + + timeago().render(document.querySelectorAll('time')); + hljs.initHighlighting(); + + const userInfoElement: HTMLDivElement = document.getElementById('user-info') as HTMLDivElement; + + // if userInfo isn't defined, just stop the initialisation process for now + if (!userInfoElement) + return; + + const userInfo: CurrentUserInfo = JSON.parse(userInfoElement.textContent) as CurrentUserInfo; + + console.log(userInfo); +}); diff --git a/build.php b/build.php index a37fd0cf..828859dc 100644 --- a/build.php +++ b/build.php @@ -45,8 +45,8 @@ define('CSS_DIR', PUBLIC_DIR . '/css'); define('JS_DIR', PUBLIC_DIR . '/js'); define('LESS_DEST', CSS_DIR . '/style.css'); -define('TS_DEST', JS_DIR . '/%s.js'); -define('DTS_DEST', TS_DIR . '/%s.d.ts'); +define('TS_DEST', JS_DIR . '/misuzu.js'); +define('TS_SRC', JS_DIR . '/misuzu/'); define('NODE_MODULES_DIR', __DIR__ . '/node_modules'); define('NODE_DEST_CSS', CSS_DIR . '/libraries.css'); @@ -120,6 +120,27 @@ function recursiveCopy(string $source, string $dest): bool return true; } +function recursiveConcat(string $source, string $existing = ''): string +{ + if (!is_dir($source)) { + return $existing . file_get_contents($source); + } + + $dir = dir($source); + + while (($entry = $dir->read()) !== false) { + if ($entry === '.' || $entry === '..') { + continue; + } + + $existing = recursiveConcat($source . DIRECTORY_SEPARATOR . $entry, $existing); + } + + $dir->close(); + + return $existing; +} + // Make sure we're running from the misuzu root directory. chdir(__DIR__); @@ -139,11 +160,6 @@ if (!is_file(LESS_DIR . LESS_ENTRY_POINT)) { system(sprintf(LESS_CMD, escapeshellarg(LESS_DIR . LESS_ENTRY_POINT), LESS_DEST)); } -// figure this out -misuzu_log(); -misuzu_log('Compiling TypeScript'); -misuzu_log(shell_exec('tsc --extendedDiagnostics -p tsconfig.json')); - misuzu_log(); misuzu_log('Importing libraries'); @@ -187,6 +203,13 @@ foreach (IMPORT_SEQ as $sequence) { file_put_contents($sequence['destination'], $contents); } +misuzu_log(); +misuzu_log('Compiling TypeScript'); +misuzu_log(shell_exec('tsc --extendedDiagnostics -p tsconfig.json')); +file_put_contents(TS_DEST, recursiveConcat(TS_SRC)); +deleteAllFilesInDir(TS_SRC, '*.js'); +rmdir(TS_SRC); + misuzu_log(); misuzu_log('Copying data...'); diff --git a/misuzu.php b/misuzu.php index 0e0dd299..f69acf63 100644 --- a/misuzu.php +++ b/misuzu.php @@ -304,7 +304,7 @@ MIG; WHERE `user_id` = :user_id '); $getUserDisplayInfo->bindValue('user_id', $mszUserId); - $userDisplayInfo = $getUserDisplayInfo->execute() ? $getUserDisplayInfo->fetch() : []; + $userDisplayInfo = $getUserDisplayInfo->execute() ? $getUserDisplayInfo->fetch(\PDO::FETCH_ASSOC) : []; } csrf_init( diff --git a/src/Parsers/BBCode/Tags/BoxTag.php b/src/Parsers/BBCode/Tags/BoxTag.php index 911391e1..4871da74 100644 --- a/src/Parsers/BBCode/Tags/BoxTag.php +++ b/src/Parsers/BBCode/Tags/BoxTag.php @@ -10,11 +10,10 @@ final class BoxTag extends BBCodeTag return preg_replace_callback( '/\[box(?:=(.*))?\](.*)\[\/box\]/', function ($matches) { - $randomId = 'toggle_' . bin2hex(random_bytes(8)); $title = strlen($matches[1]) ? $matches[1] : 'Spoiler'; // restyle this entirely - return '