1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

RM 1.2 Add resource icons according to file type

Discussion in 'Resource Manager Support' started by Alfa1, Mar 9, 2016.

  1. Alfa1

    Alfa1 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?
  2. Chris D

    Chris D XenForo Developer Staff Member

    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.


    You would just need to do something like this in the importer:
    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.
    Alfa1 likes this.
  3. Alfa1

    Alfa1 Well-Known Member

    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.
  4. Chris D

    Chris D XenForo Developer Staff Member

    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.
    Alfa1 likes this.
  5. Sadik B

    Sadik B Well-Known Member

  6. Sadik B

    Sadik B Well-Known Member

    Alfa1 likes this.
  7. Alfa1

    Alfa1 Well-Known Member

    Awesome. Thanks again!

Share This Page