File modules/cms/output/CssOutput.class.php
Last commit: Sat Oct 17 01:14:30 2026 +0200 Jan Dankert New: Using a structured class for the API-Response. The output for GET-Requests is now without the "output" layer.
1 <?php 2 3 namespace cms\output; 4 5 use cms\output\APIOutput; 6 use Exception; 7 use language\Messages; 8 use util\json\JSON; 9 use util\YAML; 10 11 /** 12 * CSS rendering. 13 */ 14 class CssOutput extends BaseOutput 15 { 16 public function getContentType(): string 17 { 18 return 'text/css'; 19 } 20 21 protected function outputData($request, $data): void 22 { 23 if ( DEVELOPMENT ) 24 echo "/* CSS Output\n\n".json_encode($data,JSON_PRETTY_PRINT)."\n*/\n"; 25 echo $this->renderCSSToString($data); 26 } 27 28 29 /** 30 * @param $text string Error Message 31 * @param $cause Exception 32 */ 33 protected function setError(string $text, Exception $cause): void 34 { 35 echo '/* CSS Output error: '.$cause->getMessage().' */'; 36 } 37 38 private function renderCSSToString($output,$i=0) 39 { 40 $iChar = DEVELOPMENT?' ':''; 41 $out = ''; 42 $pad = str_repeat($iChar,$i*2); 43 foreach ($output as $key=>$value) { 44 if ( is_string($value) || is_numeric($value) ) 45 $out .= $pad.$key.':'.$iChar.$value.';'.(DEVELOPMENT?"\n":''); 46 elseif (is_array($value)) 47 $out .= $pad.$key.$iChar.'{'.(DEVELOPMENT?"\n":'').$this->renderCSSToString($value,$i+1).$pad.'}'.(DEVELOPMENT?"\n":''); 48 else 49 throw new \LogicException("CSS value is of invalid type: ".gettype($value)); 50 } 51 return $out; 52 } 53 }
Downloadmodules/cms/output/CssOutput.class.php
History Sat, 17 Oct 2026 01:14:30 +0200 Jan Dankert New: Using a structured class for the API-Response. The output for GET-Requests is now without the "output" layer. Tue, 13 Oct 2026 00:22:21 +0200 Jan Dankert Refactoring: Fixing the flickering UI: Create CSS with dark/light-schemes, so the browser can decide which to use. Sat, 19 Mar 2022 01:29:19 +0100 dankert Fix: PreviewOutput should inherit from UIOutput. Sun, 6 Feb 2022 21:56:52 +0100 dankert New CssOutput which outputs the CSS in a cleaner way.