Implementing External Image URL Validation with Fallback in a-blog cms
Background
When dealing with external image URLs in a-blog cms — Amazon product images, for example — broken links can leave images blank without any warning.
I needed something that checks multiple URL candidates in priority order and returns the first one that actually exists. If all of them fail, it falls back to a placeholder image. Here’s how I implemented it.
A Note on the Official Docs
The official a-blog cms documentation mentioned that custom Corrector options should be written in extension/acms/Corrector.php.
…except the relevant page was returning 404 as of the time I wrote this (December 2025). It shows up in search results, but clicking through gives you nothing. This isn’t the first time. For a paid product, their documentation and reference materials really need some attention.
So I’m writing up what I actually verified to be working.
About extension/acms/Corrector.php
The extension/ directory is the customization zone — plugins are installed here too. The idea is that updates don’t overwrite this directory, so your customizations survive upgrades.
(I can’t say this for certain since the official docs are 404, but it’s safe to assume.)
Implementation
PHP side (extension/acms/Corrector.php)
Add the following method to extension/acms/Corrector.php:
/**
* Fetches a valid image URL from custom fields for a given EID.
* Returns a fallback image path if none of the URLs are accessible.
*/
public static function valid_image($eid, $args = []) {
$field = loadEntryField($eid);
$urls = [
$field->get('image_1'),
$field->get('image_2'),
$field->get('image_3'),
];
$valid_url = '';
foreach ($urls as $url) {
if (is_null($url) || empty($url) || $url === '') {
continue;
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code === 200) {
$valid_url = $url;
break;
}
}
if (!empty($valid_url)) {
return $valid_url;
}
// Fallback image (passed as argument)
if (count($args) > 0 && isset($args[0])) {
return $args[0];
}
return '';
}
Template side
Call it by passing the entry ID. Specify the fallback image path as an argument:
<img src="{eid}[valid_image('/path/to/noimage.png')]" alt="">
Inside an entry:loop:
<!-- BEGIN entry:loop -->
<img src="{entry:loop.eid}[valid_image('/path/to/noimage.png')]" alt="">
<!-- END entry:loop -->
Note: depending on where you’re using it — inside a loop or a module — escaping (\{eid\} etc.) may be required. If it doesn’t work, check the context you’re inserting it into.
Flow
- Load custom fields from the entry ID
- Check multiple image URL fields in priority order
- Send a HEAD request via curl; adopt the first URL that returns 200
- If all fail, return the fallback image from the argument
Caveats
- Each call makes an external HTTP request, so calling this in a large loop can hurt performance
- Consider adding a caching layer if needed (I flagged this at delivery, but was told their CDN would handle it)
By the way, does anyone actually use a-blog cms? I only learned it because a client project required it — I’ve never run into it anywhere else.