/** * Parse short codes * * @param $attributes * @param null $content * @param null $tag * @param ShortCodesProcessor $processor * * @return mixed|null|string */ private function parseShortCodes($attributes, $content = null, $tag = null, ShortCodesProcessor $processor = null) { $content = $this->shortCodesProcessor->parseContent($content); $backgroundColors = BackgroundColor::getMap(); $foregroundColors = ForegroundColor::getMap(); $textEffects = TextEffect::getMap(); $options = []; switch ($tag) { case "format": $backgroundColor = strtoupper(isset($attributes['background']) ? $attributes['background'] : 'system'); $foregroundColor = strtoupper(isset($attributes['foreground']) ? $attributes['foreground'] : 'system'); $effects = isset($attributes['effects']) ? explode(" ", $attributes['effects']) : array(); $options[] = $backgroundColors->get($backgroundColor)->getOrElse(BackgroundColor::SYSTEM); $options[] = $foregroundColors->get($foregroundColor)->getOrElse(ForegroundColor::SYSTEM); foreach ($effects as $effect) { $effect = strtoupper($effect); if ($textEffects->containsKey($effect)) { $options[] = $textEffects->get($effect)->get(); } } $options[] = TextReset::ALL; $content = StringTransformer::transformText($content, $options); break; case "center": $sizes = Bash::getScreenSizes(); $content = str_pad($content, $sizes['width'], " ", STR_PAD_BOTH); break; case "sideways": $sizes = Bash::getScreenSizes(); $content = str_replace("%MIDDLE%", str_repeat(" ", $sizes['width'] - strlen(Bash::removeStyles($content)) + 6), $content); break; case "success": $content = $processor->parseContent('[format foreground="green" effects="bold" background="black"][sideways] ' . $content . '%MIDDLE%[/sideways][/format]'); break; case "error": $content = $processor->parseContent('[format foreground="white" effects="bold" background="red"][sideways] ' . $content . '%MIDDLE%[/sideways][/format]'); break; case "info": $content = $processor->parseContent('[format foreground="white" effects="bold" background="blue"][sideways] ' . $content . '%MIDDLE%[/sideways][/format]'); break; } return $content; }