Action: Colorbox

Compatible with: R6.x
Current version:
Credits: WikiAdmin

visualize color sets as boxes, not thought as infoboxes


{{colorbox}}


/action/colorbox.php

<?php
 
/*
 
visualize color sets as boxes
 
{{colorbox background_color="#FDFEB8" border_color="#FFBB00"}}
    $background_color    - background color
    $border_color        - border color
    $text                - description
    $text_color            - text color
    $border_width        - border width
    $width                - width
    $spec                - show color values
*/
 
if (!isset($text))                $text    = null;
if (!isset($border_width))        $border_width        = '1px';
if (!isset($background_color))    $background_color        = '#ffa';
if (!isset($border_color))        $border_color        = '#000000';
if (!isset($text_color))        $text_color        = '#000000';
if (!isset($width))                $width    = '200px';
if (!isset($spec))                $spec    = 1;
 
$sanitize = function($value, $filter)
{
    switch ($filter)
    {
        case 'color':
            if (preg_match('/^(
                (\#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}))|        # color value
                (rgb\(([0-9]{1,3}%?,){2}[0-9]{1,3}%?\))        # rgb triplet
                )$/x', $value))
            {
                return $value;
            }
            break;
        case 'width':
            if (preg_match('/^\d*\.?\d+(%|px|em|ex|pt|cm|mm|pi|in)$/', $value))
            {
                return $value;
            }
            break;
        case 'class':
            if (preg_match('/[^A-Za-z0-9_-]/', $value))
            {
                return $value;
            }
            break;
    }
};
 
echo '<div style="
    background-color: '    . $sanitize($background_color, 'color') . ';
    border: '            . $sanitize($border_width, 'width') . ' solid ' . $sanitize($border_color, 'color') . ';
    width: '             . $sanitize($width, 'width') . ';
    clear: both;
    margin: 10px 0;
    padding: 10px;
    color: ' . $sanitize($text_color, 'color') . ';
    float: left;">' .
    $this->format($text) . ''.
    ($spec
        ? '<br>' .
          'background: '    . $sanitize($background_color, 'color') . '<br>' .
          'border: '        . $sanitize($border_color, 'color') . '<br>' .
          'color: '            . $sanitize($text_color, 'color') . ''
        : ''
    ) . "</div>\n";

info
background: #FFFFE0
border: #E6DB55
color: #000000

success
background: #C3FF88
border: #8DFF1C
color: #000000

ok
background: #FFEC8B
border: #FFCC00
color: #000000

error
background: #FFB78C
border: #FF853C
color: #000000

error
background: #FFA0A0
border: #F04040
color: #000000

info
background: #FFFBCC
border: #E6DB55
color: #000000

message
background: #DDFFDD
border: #BBFFBB
color: #000000

info
background: #DDEEFF
border: #99CCFF
color: #000000

warning
background: #FDFEB8
border: #FFBB00
color: #000000

error
background: #FFDDDD
border: #FFBBBB
color: #000000