Fixed Discord embed fail to parse theme-color with rgb() components

Xon

Well-known member
Affected version
2.2.6
Previous parse_less_color would render the to #xxyyzz format which Discord would read and use to tint the embed.

As a result of this change; https://xenforo.com/community/threads/inefficient-code-in-page_container.193322/ this no longer works.

This sort of regex looks able to extract and convert things as required without requiring a full LESS parser.
PHP:
if (\preg_match('/^\s*(?:rgb|rgba)\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d{1,3})\s*)?\)\s*$/i', $value, $matches))
{
    $r = $matches[2];
    $g = $matches[3];
    $b = $matches[4];
    $a = $matches[5] ?? '';

    if ($a === '')
    {
        return \sprintf("#%02x%02x%02x", $r, $g, $b);
    }
    else
    {
        return \sprintf("#%02x%02x%02x%02x", $r, $g, $b, $a);
    }
}
 
Derp off 1 by on my regex indexes.

should be;
Code:
    $r = $matches[1];
    $g = $matches[2];
    $b = $matches[3];
    $a = $matches[4] ?? '';
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.7).

Change log:
When parsing a color string (such as for the metaThemeColor property usage) normalize the color to its hex value by default.
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom