diff --git a/example/config.json b/example/config.json index 5b91172..6457656 100644 --- a/example/config.json +++ b/example/config.json @@ -28,7 +28,16 @@ "results":"Results", "older":"Older", "newer":"Newer", - "nothing":"Nothing" + "nothing":"Nothing", + "block":"Block", + "time":"Time", + "data":"Data", + "meta":"Meta", + "view": + { + "raw":"Raw data", + "reader":"Reader" + } } }, "manticore": diff --git a/src/server.php b/src/server.php index 563f5d5..37fd879 100644 --- a/src/server.php +++ b/src/server.php @@ -273,34 +273,28 @@ $server->setHandler( // Key $result[] = sprintf( '### %s', - $record['key'] + trim( + preg_replace( // single-line + '/[\s]+/', + ' ', + $record['key'] + ) + ) ); // Value - $result[] = sprintf( - '``` %s', - $config->geminiapp->string->value - ); - - $lines = []; - - foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line) - { - $lines[] = preg_replace( - '/^```/', - ' ```', - $line - ); - } - - $result[] = implode( - PHP_EOL, - $lines + $result[] = null; + $result[] = trim( + preg_replace( // remove extra breaks + '/[\n\r]{3,}/', + PHP_EOL . PHP_EOL, + $record['value'] + ) ); - $result[] = '```'; - // Link + $result[] = null; + $result[] = sprintf( '=> /%s %s in %d', $record['transaction'], @@ -415,44 +409,134 @@ $server->setHandler( ) { if ($record['transaction'] == $attribute[1]) { - // Header - $result[] = sprintf( - '# %s', - $record['key'] - ); + // Raw mode + if ('raw' == $request->getQuery()) + { + // Transaction ID + $result[] = sprintf( + '# %s', + $record['transaction'] + ); - // Body - $result[] = sprintf( - '``` %s', - $config->geminiapp->string->value - ); + $result[] = sprintf( + '## %s', + $config->geminiapp->string->data + ); - $lines = []; + // Key + $result[] = sprintf( + '### %s', + $config->geminiapp->string->key + ); - foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line) - { - $lines[] = preg_replace( - '/^```/', - ' ```', - $line + $result[] = '```'; + + $lines = []; + + 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[] = sprintf( + '### %s', + $config->geminiapp->string->value + ); - $result[] = sprintf( - '%s in %d', - date( + $result[] = '```'; + + $lines = []; + + foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line) + { + $lines[] = preg_replace( + '/^```/', + ' ```', + $line + ); + } + + $result[] = implode( + PHP_EOL, + $lines + ); + + $result[] = '```'; + + // Meta + $result[] = sprintf( + '## %s', + $config->geminiapp->string->meta + ); + + // Time + $result[] = sprintf( + '### %s', + $config->geminiapp->string->time + ); + + $result[] = date( 'Y-m-d', $record['time'] - ), - $record['block'] - ); + ); + + // Block + $result[] = sprintf( + '### %s', + $config->geminiapp->string->block + ); + + $result[] = $record['block']; + } + + // Reader mode + else + { + // Key + $result[] = sprintf( + '# %s', + trim( + preg_replace( // single-line + '/[\s]+/', + ' ', + $record['key'] + ) + ) + ); + + // Value + $result[] = trim( + preg_replace( // remove extra breaks + '/[\n\r]{3,}/', + PHP_EOL . PHP_EOL, + $record['value'] + ) + ); + + // Time + $result[] = null; + + $result[] = sprintf( + '%s in %d', + date( + 'Y-m-d', + $record['time'] + ), + $record['block'] + ); + } // Footer $result[] = sprintf( @@ -460,6 +544,24 @@ $server->setHandler( $config->geminiapp->string->navigation ); + if ('raw' == $request->getQuery()) + { + $result[] = sprintf( + '=> /%s %s', + $record['transaction'], + $config->geminiapp->string->view->reader + ); + } + + else + { + $result[] = sprintf( + '=> /%s?raw %s', + $record['transaction'], + $config->geminiapp->string->view->raw + ); + } + $result[] = sprintf( '=> /%s %s', $record['namespace'],