I've been browsing the module department, but was unable to find what I'm looking for. Perhaps I've overlooked, but what I need is: a module that checks if uploaded images are used ANYWHERE (being in a node, .js or .css file) in the site. I would like to see where on my site an image is being used, and if it is being used, deleting or renaming the image should not be possible.
I've started with a proof-of-concept setup, before creating an actual module like this, but ran into a problem. Please read on. I added the following to my .htaccess:
RewriteRule ^/?image\/(.+)$ modules/image/image.php?q=$1 [L,QSA]
All images would be served through php. This rule rewrites site.com/image/britney.png to modules/image/image.php?q=britney.png. image.php looks like this:
$image = IMG_PATH . $_GET['q'];
if (empty($image) || !file_exists($image)) {
exit;
}
if (isset($_SERVER['HTTP_REFERER'])) {
db_query("INSERT INTO {images_nodes} (referer, image) VALUES ('%s',
'%s')",
$_SERVER['HTTP_REFERER'], $_GET['q']
);
}
$fp = fopen($image, 'rb');
header("Content-Type: " . mime_content_type($image));
header("Content-Length: " . filesize($image));
fpassthru($fp);
exit;
If I place the following HTML on page site.com/singers/britney, $_SERVER['HTTP_REFERER'] then contains value "http://site.com/singers/britney", which is as it should work:
Britney is somewhat hot again:
<img src="image/britney.png">
Now my problem: this doesn't work with an included css or js file. In example, if I create a css file that I call on site.com/singers/britney, the HTTP_REFERER still carrier the value of http://site.com/zangeressen/britney instead of http://site.com/style.css:
// site.com/style.css
#britney {
background: url(image/britney.png);
}
// site.com/singers/britney
<link rel="stylesheet" href="style.css" type="text/css">
<div id="britney">
Britney is somewhat hot again
</div>
How could I determine that in the above case "britney.png" is being called by style.css? I tried all the $_SERVER variables but none of them work. I'm hoping for some very clever people out here, because I'm stuck. Perhaps I should make more modifications to the .htaccess? I think a module like this would be very helpfull to a lot of people, but I need some brilliant insights :-)