RM 1.2 Add resource icons according to file type

Alpha1

Well-known member
I am importing 11k files into XFRM. Most of these are documents like PDF and DOC. I would like to add an icon to these files according to the file type. So that PDF's get a PDF icon, DOC files get a DOC icon, etc.

Is there a way to do this? Maybe with a query?
 
Resource icons are just stored on the file system, e.g. data/resource_icons/1/1001.jpg where 1001 is the resource_id and the 1 is the resource_id / 1000 rounded down to the nearest whole number.

The database isn't really involved, though at the very least you ought to set the icon_date to be > 0 (this is generally just used as a cache buster, but also the general indicator for whether a resource has an icon or not).

I think the best way to handle this might be in the import itself, if that's possible. I would expect it should only be a few additional lines of code.

Assuming you had a list of icons based on extensions, e.g.

/var/www/public_html/icons/pdf.jpg
/var/www/public_html/icons/doc.jpg

You would just need to do something like this in the importer:
PHP:
if ($extension == 'pdf' OR $extension == 'doc')
{
    $model = XenForo_Model::create('XenResource_Model_Resource');
    $model->applyResourceIcon($resourceId, '/var/www/public_html/icons/' . $extension . '.jpg');
}

That would handle everything automatically.
 
That would work for the imported files and is probably the best way to start off, but it does not work for any new files added by my members. There is no way that people will take the effort to find a PDF icon with their PDF upload. etc.

I think that it would need something to insert it at creation or a way for me to batch update the icons of new entries.
 
My only other suggestion is an add-on that exposes the file extension to the resource_list_item template. If you had that, you could literally do it all with template conditionals.
 
Top Bottom