XF 2.2 externalDataUrl and non-friendly, friendly, and Cloudflare R2

AndrewSimm

Well-known member
I have an articles add-on that I use and plan to release next year and I am having a bit of an issue making the articles image seamless.

Here are the 3 scenarios:

1) Non-friendly URLs

2) Friendly URLs

3) External URL (i.e. Cloudflare R2)

The linke for my image is: {$xf.app.config.externalDataUrl}/articles/{$article.image_url}

This link works in the scenario where I am either using Non-friendly URLs or Cloudflare (https://data.example.com) but does not work when I am using Friendly URLs and not Cloudflare. I can make it work if I set
PHP:
$config ['externalDataUrl'] = '/data';

What I want to do is not have the user have to update their config file for this to work. How can externalDataUrl add a / in front of data when friendly?

Here is what my link looks like: {$xf.app.config.externalDataUrl}/articles/{$article.image_url}
 
PHP:
$url = \XF::app()->applyExternalDataUrl('some/file.jpg');
 
Last edited:
Yeah, something like:

PHP:
public function getExternalImageUrl(bool $canonical = false)
{
    return $this->app()->applyExternalDataUrl('articles/' . $this->image_url, $canonical);
}
 
Top Bottom