From d3d810ee9ca3b175ec01da0cfc0aca9e69734dc8 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 4 Mar 2024 20:08:56 +0200 Subject: [PATCH] update view mode construction --- src/server.php | 238 +++++++++++++++++++++++++------------------------ 1 file changed, 120 insertions(+), 118 deletions(-) diff --git a/src/server.php b/src/server.php index 53a0794..b13041c 100644 --- a/src/server.php +++ b/src/server.php @@ -392,149 +392,151 @@ $server->setHandler( ) { if ($record['transaction'] == $attribute[1]) { - // Raw mode - if ('raw' == $request->getQuery()) + // View mode + switch ($request->getQuery()) { - // Transaction ID - $result[] = null; - $result[] = sprintf( - '# %s', - $record['transaction'] - ); + case 'raw': - $result[] = null; - $result[] = sprintf( - '## %s', - $config->geminiapp->string->data - ); + // Transaction ID + $result[] = null; + $result[] = sprintf( + '# %s', + $record['transaction'] + ); - // Key - $result[] = null; - $result[] = sprintf( - '### %s', - $config->geminiapp->string->key - ); + $result[] = null; + $result[] = sprintf( + '## %s', + $config->geminiapp->string->data + ); + + // Key + $result[] = null; + $result[] = sprintf( + '### %s', + $config->geminiapp->string->key + ); - $result[] = '```'; + $result[] = '```'; - $lines = []; + $lines = []; - foreach ((array) explode(PHP_EOL, (string) $record['key']) as $line) - { - $lines[] = preg_replace( - '/^```/', - ' ```', - $line + foreach ((array) explode(PHP_EOL, (string) $record['key']) as $line) + { + $lines[] = preg_replace( + '/^```/', + ' ```', + $line + ); + } + + $result[] = implode( + PHP_EOL, + $lines ); - } - $result[] = implode( - PHP_EOL, - $lines - ); + $result[] = '```'; - $result[] = '```'; + // Value + $result[] = null; + $result[] = sprintf( + '### %s', + $config->geminiapp->string->value + ); - // Value - $result[] = null; - $result[] = sprintf( - '### %s', - $config->geminiapp->string->value - ); + $result[] = '```'; - $result[] = '```'; + $lines = []; - $lines = []; + foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line) + { + $lines[] = preg_replace( + '/^```/', + ' ```', + $line + ); + } - foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line) - { - $lines[] = preg_replace( - '/^```/', - ' ```', - $line + $result[] = implode( + PHP_EOL, + $lines ); - } - $result[] = implode( - PHP_EOL, - $lines - ); + $result[] = '```'; - $result[] = '```'; + // Meta + $result[] = null; + $result[] = sprintf( + '## %s', + $config->geminiapp->string->meta + ); - // Meta - $result[] = null; - $result[] = sprintf( - '## %s', - $config->geminiapp->string->meta - ); + // Time + $result[] = null; + $result[] = sprintf( + '### %s', + $config->geminiapp->string->time + ); - // Time - $result[] = null; - $result[] = sprintf( - '### %s', - $config->geminiapp->string->time - ); + $result[] = null; + $result[] = date( + 'Y-m-d', + $record['time'] + ); - $result[] = null; - $result[] = date( - 'Y-m-d', - $record['time'] - ); + // Block + $result[] = null; + $result[] = sprintf( + '### %s', + $config->geminiapp->string->block + ); - // Block - $result[] = null; - $result[] = sprintf( - '### %s', - $config->geminiapp->string->block - ); + $result[] = null; + $result[] = $record['block']; - $result[] = null; - $result[] = $record['block']; - } + break; - // Reader mode - else - { - // Key - $result[] = null; - $result[] = sprintf( - '# %s', - trim( - preg_replace( // single-line - '/[\s]+/', - ' ', - $record['key'] + default: + + // Key + $result[] = null; + $result[] = sprintf( + '# %s', + trim( + preg_replace( // single-line + '/[\s]+/', + ' ', + $record['key'] + ) ) - ) - ); + ); - // Value - $result[] = null; - $result[] = trim( - preg_replace( - [ - '/(^|\s+)(#|\*|```|=>)/', // escape gemini text - '/[\n\r]{3,}/', // remove extra breaks - ], - [ - '$1 $2', - PHP_EOL . PHP_EOL, - ], - $record['value'] - ) - ); + // Value + $result[] = null; + $result[] = trim( + preg_replace( + [ + '/(^|\s+)(#|\*|```|=>)/', // escape gemini text + '/[\n\r]{3,}/', // remove extra breaks + ], + [ + '$1 $2', + PHP_EOL . PHP_EOL, + ], + $record['value'] + ) + ); - // Time - $result[] = null; - $result[] = sprintf( - '%s in %d', - date( - 'Y-m-d', - $record['time'] - ), - $record['block'] - ); + // Time + $result[] = null; + $result[] = sprintf( + '%s in %d', + date( + 'Y-m-d', + $record['time'] + ), + $record['block'] + ); } // Footer