Firefox PHP

Module: Custom Attachment Icons

Posted by Joe Curia 
Module: Custom Attachment Icons
October 08, 2008 10:59PM
This module allows the admin to replace the normal attachment icon with icons relating to the type of the attachments or link in the post. Each supported type has a language entry for Alt/Title display. The module also searches for [ img ], [ video ], and [ mp3 ] bbcode tags and the extensions of http links inside the body of messages as they are posted. Thanks go to Maurice Makaay for his regex coding to detect the image and video links.

Installation and Usage:
In order to use this module, you must first install and enable it like any other module. Then you must edit your list.tpl, list_threads.tpl, or read_threads.tpl file to utilize the additional icons. For example, in the Emerald template you should change:
{IF MESSAGES->meta->attachments}<img src="{URL->TEMPLATE}/images/attach.png" class="icon1616" title="{LANG->Attachments}"  alt="{LANG->Attachments}" /> {/IF}
to read:
{INCLUDE "custom_attachment_icons::list_icons"}
A notice will be posted at the top of the forum for admin if the template edits have not been made. This mainly serves as a reminder if a future upgrade overwrites the template edits you mad while installing this module, and can be disabled from the settings page if needed.

If you are not installing this module as a part of a new phorum installation, you will want to run the script to check past posts for bbcode and url links to count as attachments. This option can be found on the settings page.

At this time, if you want to customize the icons or add more file types, you can edit the mime_types.php file. Please note that any customized icons should be placed in the images folder, should be 16px by 16px, and should have a counterpart with a "multi_" prefix if you want to show a different icon when more than one attachment of a single type is attached (ie. two pictures).

Support for the Recent Messages module has been added, with two edits needed:
First, the ./mods/recent_messages/recent_messages.php file must be edited to add these lines (I have included the three existing lines as a reference point for where to place the new code):
    // ----------------------------------------------------------------------
    // Setup template data.
    // ----------------------------------------------------------------------
    // run list mods
       if (isset($PHORUM["hooks"]["list"]))
        $messages = phorum_hook("list",$messages);

Next, the ./mods/recent_messages/templates/emerald/render_message_row.tpl file must be edited to add this line (again with existing code for reference):
<h4><a {IF subjectclass}class="{subjectclass}"{/IF}
           href="{MESSAGE->URL->READ}">{MESSAGE->subject}</a>
           {INCLUDE "custom_attachment_icons::recent_messages_icons"}
</h4>

Todo:
- Find a way to avoid template editing if at all possible (not looking good)

- Allow the admin to customize or add type icons from the settings page

- Add further features as requested or as they pop into my head


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald




Edited 5 time(s). Last edit at 05/04/2009 12:05AM by Joe Curia.


Attachments:
open | download - custom_attachment_icons_v5_2_1_05.zip (28.6 KB)
Re: Module: Custom Attachment Icons
October 09, 2008 03:28AM
Chapeau!

*scratches this one of his list* :)

I'll answer the question from the other thread where you posted in here, since this seems the correct place for discussing the mod (the question was about updating all messages in the database).

Using the recent messages code would not be a good way to go over all messages. That code works best for the most recent messages. The queries and indexes are fine-tuned to that. The further you go into the historic messages, the slower the function will do its work.

You need to write a custom query to go over all messages. You can keep the query extremely simple and use api functions to get to the data. The idea is like this:

Language: PHP
$res = phorum_db_interact( DB_RETURN_RES, "SELECT message_id FROM {$PHORUM[';message_table';]}" );   while ($row = phorum_db_fetch_row($res, DB_RETURN_ROW)) { $message_id = $row[0]; // ... from here on you can do the processing for the // ... the message_id. }

For processing all users, we already built something into the db layer (phorum_db_user_get_all()). It might be nice to have the same function for messages as well, so that can be used to loop over the messages without having to revert to custom queries.

When building an admin panel for rebuilding all icons, the most important thing to take care or are large message databases. The user needs some visual feedback to know that processing is going on and care has to be taken to not let PHP stop the script because it is running too long. It's a bit like the rebuilding of display names (admin panel, database integrity). There I did some poor man's solution to do the processing in multiple page loads, while showing the progress. Maybe you can fetch some ideas from that code. Of course, an Ajaxy system could make it somewhat nicer.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce



Edited 1 time(s). Last edit at 10/09/2008 03:48AM by Maurice Makaay.
Re: Module: Custom Attachment Icons
October 09, 2008 09:05AM
Quote
Maurice Makaay
Using the recent messages code would not be a good way to go over all messages. That code works best for the most recent messages. The queries and indexes are fine-tuned to that. The further you go into the historic messages, the slower the function will do its work.
I knew there had to be a better way.

Quote
Maurice Makaay
You need to write a custom query to go over all messages. You can keep the query extremely simple and use api functions to get to the data.
And I knew you would be the man to show me the way. Thanks for the code example!

Quote
Maurice Makaay
When building an admin panel for rebuilding all icons, the most important thing to take care or are large message databases. The user needs some visual feedback to know that processing is going on and care has to be taken to not let PHP stop the script because it is running too long. It's a bit like the rebuilding of display names (admin panel, database integrity). There I did some poor man's solution to do the processing in multiple page loads, while showing the progress. Maybe you can fetch some ideas from that code. Of course, an Ajaxy system could make it somewhat nicer.
One of the things I need to wrap my head around is programming for more than the few thousand messages my forums ever generate. Thanks for pointing me in the right direction again.


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Re: Module: Custom Attachment Icons
October 09, 2008 09:48AM
Programming for the millions (of messages).
That's what this all is about. Glad to be of help.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Module: Custom Attachment Icons v5.2.1.01 - Script for processing past messages
October 10, 2008 09:48AM
I have completed v5.2.1.01 of this mod with the following changes:

- added the ability to run a script to check past posts for bbcode and url links to count as attachments. Big thanks go to Maurice Makaay for his guidance and previous code work on this.

- separated the code for checking message bodies for bbcode and url links to count as attachments so that it can be accessed from multiple places.

- added a notification to the top of the forum index, list, and read pages if an admin is logged in and the template has not been edited to show the custom attachment icons.

- fixed the english.php lang file to include all of the mime types supported by default.


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Re: Module: Custom Attachment Icons
October 13, 2008 01:32PM
Thank you sir! So far it looks like it worked great.

We are pressuring our host to migrate us ASAP. We are on the list, we're just trying to get bumped up that list. I believe we have a couple other mods that do not work also for this reason. The move will also get us Aspell so I can finally activate that module as well.

Thank you again for all the support here.
Module: Custom Attachment Icons v5.2.1.02 - Mostly Bugfixes
October 15, 2008 12:56AM
I have completed v5.2.1.02 of this module with the following changes:

- Bugfix: Still more preg_match fine tuning. The extension should now be anything after the last "." in the url and before the first non-AlphaNum character if extant.

- Enhancement: Added the swf Flash Movie extension to the list of supported mime types.

- Bugfix: Further refinement of the regex for finding and processing url's in message bodies.

- Bugfix: removed unnecessary check for message_id as a message_id is not always available.

- Bugfix: "readthreads" hook was not used to display icons on the read_threads.tpl

- Bugfix: The scan wasn't able to process capitalized bbcode tags and html images.

- Replaced PHP5 specific stripos() with preg_match() to allow for use in a PHP4 environment.


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Re: Module: Custom Attachment Icons
October 21, 2008 07:40PM
Awwwww now I cannot pest Maurice about doing this mod no more cuz someone else did it .... 8-(

Just kidding!!

Thank for doing this module! It one of the module I been dreaming and waiting for! I wish I had your programming skill but thank you so much making this module possible!

Now I have a question ..
I wanted to add some custom icon for some file extension that are uploaded in forums so looking over this module php files, I assume I need to edit mime_types.php and add more icons for certain file extension in there?

My forum is a hobby forum and we share files and one of the file are a pattern file which ends with a .ptrn extension and we have a icon for that file and I want to add it so they know someone uploaded a pattern file in their post.


Thanks again!
Bill
Re: Module: Custom Attachment Icons
October 21, 2008 07:53PM
I noticed that film icon is not visible when youtube video that are imbedded into post by one of maurice module which automatically detects and embed the youtube video just from it URLs into posts however it doesn't seem to be detected by this module to include a film icon on subject line.

Any way to fix this?

Thank you
Bill
Re: Module: Custom Attachment Icons
October 21, 2008 07:59PM
Had I been thinking when I first started coding this module, I would have simply copied large swaths of code from Maurice's embedding modules for the detection of media. I will look into how to get video detected properly (by means of the afore-mentioned copying most likely :-P)

EDIT: Yes, editing the mime_types.php file is how you can add new icons/types. You would first add:
$PHORUM["phorum_mod_custom_attachment_icons"]["extension_mime_types"] = array (
"ptrn" => "pattern",
Then:
$PHORUM["phorum_mod_custom_attachment_icons"]["mime_types"] = array (
"pattern" => "pattern.png",
Finally, upload pattern.png, and (if you want a different icon for multiple patterns in one post) multi_pattern.png to the images folder.


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald




Edited 1 time(s). Last edit at 10/21/2008 08:07PM by Azumandias.
Sorry, only registered users may post in this forum.

Click here to login