Fixed MaxCDN is Offline | Emojis stopped working

The Dark Wizard

Well-known member
Affected version
2.2.11
Hi,


Twemoji has stopped working due to MaxCDN going offline. I've tried testing it here on xenforo.com but I guess another option is being used?

In ACP, the twemoji examples are also gone:

1673394743750.webp
 
Last edited:
The following CDNs can be used as an alternative (though ACP will stay broken as MaxCDN is hardcoded there)

Code:
https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/
https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/
 
I changed maxcdn by cdnjs.cloudflare.com this in the file XF\Str\EmojiFormatter.php while waiting to have an official fix of XF, Otherwise, the quickest way is just to put the Cloudflare link in "Host from following location".

$config['path'] = $useCdn ? 'https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/' : $config['path'];

PHP:
protected function setTypeSpecificDefaults($config)
    {
        if ($config['style'] == 'native')
        {
            return $config;
        }

        $useCdn = ($config['source'] == 'cdn');

        if ($config['style'] == 'emojione')
        {
            $config['path'] = $useCdn ? 'https://cdn.jsdelivr.net/joypixels/assets/7.0/png/unicode/64/' : $config['path'];
            $config['uc_filename'] = self::UC_MATCH;
            $config['filename_formatter'] = function($filename) { return $filename; };
        }
        else if ($config['style'] == 'twemoji')
        {
            $config['path'] = $useCdn ? 'https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/' : $config['path'];
            $config['uc_filename'] = self::UC_OUTPUT;
            $config['filename_formatter'] = function($filename)
            {
                // Twemoji strips the leading zeros.
                if (strpos($filename, '00') === 0)
                {
                    $filename = preg_replace('/^(00)/', '', $filename);
                }

                // Some Twemoji symbols don't include the fe0f 'variant form' indicator
                if (strpos($filename, '-fe0f-') !== false)
                {
                    $filename = preg_replace('/^(\w{2})(?:-fe0f-)(.*)$/', '$1-$2', $filename);
                }

                /**
                 * Some Twemoji file names are different to what we would expect
                 * so handle those replacements manually based on a known list
                 */
                $filename = $this->getTwemojiReplacement($filename);

                return $filename;
            };
        }

        return $config;
    }
 
Last edited:
There is no need to patch the file to change the MaxCDN URL (unless you care that the example emojis are displayed in ACP), just changing the option to supply a working CDN URL manually is enough.
 
Top Bottom