Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: NanoSector on February 11, 2013, 08:42:57 PM

Title: Rank Image Drop Down
Post by: NanoSector on February 11, 2013, 08:42:57 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=3635)

Rank Image Drop Down
If you need to report a bug, please do so on GitHub! (https://github.com/Yoshi2889/RankImageDropDown)

Please note this feature is included in SMF 2.1, this mod will not be updated to work on 2.1.

This mod replaces the default text box for entering the star name with a more convenient dropdown box in which you can select it.

Not all your images are showing up?
The mod filters out images bigger than 128x32 pixels. If this is a problem for you, please use the package with the suffix "-nofilter". That package will show all images.

Features:
- Loads all images in the /images directory of the default theme
- Keeps the preview function
- Filters out any images bigger than 128x32 pixels

Compatibility:
This mod should work on SMF 2.0 and later. 2.0.4 was tested.

Files modified:
- Sources/ManageMembergroups.php
- Themes/(theme)/ManageMembergroups.template.php

To-dos:
- Make the mod work in a recursive way

Changelog:
v1.0.1
! Fix a bug where the moderator suggest box was broken (thanks ♦ Ninja ZX-10RR ♦!)

v1.0
- Initial release

License:
This mod is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported license. (http://creativecommons.org/licenses/by-sa/3.0/)
Title: Re: Rank Image Drop Down
Post by: Arantor on February 11, 2013, 08:47:32 PM
Wait, you're caching the file listing in a single folder, only while in the admin panel, 'for performance'? Folder contents are already cached (more efficiently) by the operating system.

Remember: on systems that use proper caches, anything you put in risks pushing something else out. There is no point caching pretty much anything in the admin panel for this reason - it only gains the admin a performance boost, and risks pulling more useful stuff out of the cache.
Title: Re: Rank Image Drop Down
Post by: Matthew K. on February 11, 2013, 08:54:05 PM
Yep, and that was my suggestion. Furthermore, I don't like caching the results of a directory period because it's so subject to change whether the resource is still there or not, really doesn't save you too much in this case anyway as you already explained.

He removed the cache code as per my suggestion and just forgot to remove it from the desc and readme.
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 11, 2013, 09:01:06 PM
Yeah, I forgot to remove it from the readme, my bad, it's changed now :)
Title: Re: Rank Image Drop Down
Post by: Antechinus on February 12, 2013, 01:26:46 AM
Quite clever. Not a bad idea. :)
Title: Re: Rank Image Drop Down
Post by: vbgamer45 on February 12, 2013, 01:43:37 AM
Neat idea I like it. Could come in handy in some other areas as well.
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 12, 2013, 05:09:11 AM
Thanks both :)

vbgamer: Can you maybe name the areas? I might be able to modify them as well (in one big mod).
Title: Re: Rank Image Drop Down
Post by: 4Kstore on February 12, 2013, 08:30:31 AM
This is a great idea!!
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 12, 2013, 08:53:00 AM
Thanks 4Kstore! :)
Title: Re: Rank Image Drop Down
Post by: Jessica. on February 12, 2013, 11:29:56 AM
Great mod. Should be in SMF by default
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 12, 2013, 11:36:02 AM
Thanks Jessica :)

I don't think this will be included in SMF anytime soon, though, unfortunately.
Title: Re: Rank Image Drop Down
Post by: vbgamer45 on February 12, 2013, 01:02:21 PM
Quote from: Jessica. on February 12, 2013, 11:29:56 AM
Great mod. Should be in SMF by default
+1 Makes it a lot easier instead of having to check via ftp what files exist and can be used for stars.
Title: Re: Rank Image Drop Down
Post by: Arantor on February 12, 2013, 01:02:50 PM
So commit it already. SMF's on Github these days.
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 12, 2013, 01:14:55 PM
Quote from: Arantor on February 12, 2013, 01:02:50 PM
So commit it already. SMF's on Github these days.
I'll be more than glad to commit this, but I'd first like to add in the recursive function before committing this or even suggesting it as a core feature.
Title: Re: Rank Image Drop Down
Post by: Arantor on February 12, 2013, 01:28:24 PM
-sigh- Don't suggest it, just do it.

We live in a brave new world where things don't really need discussion as much as they used to - SMF's repository is publicly available for anyone who wants to, to submit features. Get it ready then just push it - the world was never changed by people sitting around talking about new things.
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 12, 2013, 01:33:56 PM
I'm more of a need-permission person, can't help it ;)

No but really, what do you think of moving all the stars/badges/whatever to a separate directory named "Themes/default/images/stars" or something? I can adapt this mod for that, and push it to 2.1, that'll save me the recursive-ness, plus unwanted images would get filtered out.
Title: Re: Rank Image Drop Down
Post by: Shambles on February 12, 2013, 01:36:04 PM
Amen (=> Arantor post). This guy thinks like me, which is not always a good thing  :o

This is a handy little function which, as VB45 says, obviates the need to do a manual directory search to list the available 'options'. Do your commits need sponsoring? I'd gladly sponsor it...
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 12, 2013, 01:38:28 PM
Quote from: Shambles on February 12, 2013, 01:36:04 PM
Amen (=> Arantor post). This guy thinks like me, which is not always a good thing  :o

This is a handy little function which, as VB45 says, obviates the need to do a manual directory search to list the available 'options'. Do your commits need sponsoring? I'd gladly sponsor it...
Sponsoring is always something that's appreciated :)
Title: Re: Rank Image Drop Down
Post by: Arantor on February 12, 2013, 01:40:16 PM
QuoteI'm more of a need-permission person, can't help it

Would it help if I said you had permission to offer it up to the repository? (No guarantee it will be accepted but I see no reason why not)

It would be a huge advantage if there were a single master folder for such things, you wouldn't need to recurse (which is ridiculously easy if you know you have access to SPL iterators)
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 12, 2013, 01:42:48 PM
Quote from: Arantor on February 12, 2013, 01:40:16 PM
QuoteI'm more of a need-permission person, can't help it

Would it help if I said you had permission to offer it up to the repository? (No guarantee it will be accepted but I see no reason why not)

It would be a huge advantage if there were a single master folder for such things, you wouldn't need to recurse (which is ridiculously easy if you know you have access to SPL iterators)
That helps :P

I'm porting it now, I moved the default "stars" to a directory named "stars", so that should work. Still need to adapt the code a bit more but that'll get fixed.
Title: Re: Rank Image Drop Down
Post by: vbgamer45 on February 12, 2013, 01:42:58 PM
Reminds me I did it long ago for SMF 1.1.x had a seperate folder for just ranks/star images instead of each theme having one
http://custom.simplemachines.org/mods/index.php?mod=335

Which can be helpful unless the ranks/stars don't blend well with the theme.
Title: Re: Rank Image Drop Down
Post by: Arantor on February 12, 2013, 01:44:04 PM
That's the only reason to keep per-theme images. But the practicality is that most people have one theme on a site and thus only need one set of rank images.
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 12, 2013, 08:01:42 PM
I committed this to GitHub, and it looks like Labradoodle wants to merge this into 2.1 :)
Title: Re: Rank Image Drop Down
Post by: Arantor on February 12, 2013, 08:02:52 PM
See? :)
Title: Re: Rank Image Drop Down
Post by: NanoSector on February 12, 2013, 08:12:03 PM
Yeah, I need to do more and ask less :P

Reminds me of the Joker, "I just do things..."
Title: Re: Rank Image Drop Down
Post by: impreza on February 13, 2013, 08:31:23 PM
Hundereds useful, simplifying the matter - thanks
Title: Re: Rank Image Drop Down
Post by: puw on March 22, 2013, 11:30:47 PM
Hi Yoshi, seems like a time-saving mod, but I have a few questions please.

I'm using 2.0.4 default curve.

What I am trying to work out is how to do the following:

Each member group earns rep/rank that is shown by "collecting" a new and different image to sit after the previous different image/s.

As your rep/rank increases, so do your images, retaining all previously earned images too. So, by the time you get to Hero rank, you have 5 different images to show your rep/rank.

Since the admin only allows one url related to an image per member's "star file image", the only way I can think of doing this is to make each rank's img a "growing in size" collection. This mod filters out anything above a certain size.

How can I make this work please?

For clarification, a new member joins a "football card collecting" forum. As he becomes more active, his rank/rep grows by him gaining new football card images, retaining and showing all previously earned card images.

Then he's asked to become a mod. He retains all the previous lower ranked images and starts to add new ones within the "mod" rank. And so on. By the time he's at a global mod level, he's got quite an array of football card images to "show off" to junior members. This then, because of the forum restriction that I can only add a single image url per level and so have to create each levels growing collection as a single image, grows outside of your filter.

Thx for any feedback on being able to use your mod in this way.
Title: Re: Rank Image Drop Down
Post by: Matthew K. on March 23, 2013, 12:48:59 AM
I'd imagine you could probably get rid of the size restraint, but Yoshi would have to be the one to show you how and verify that it'd work.
Title: Re: Rank Image Drop Down
Post by: NanoSector on March 23, 2013, 07:17:41 AM
Hey puw,

In Sources/ManageMembergroups.php, find:

// If the extension is not empty, and it is valid,
if (!empty($ext) && in_array($ext, $imageExts))
{
// Get the size of the image.
$image_info = getimagesize($settings['default_theme_dir'] . '/images/' . $value);

// If this is bigger than 128 in width or 32 in height, skip this one.
if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32)
continue;

// Else it's valid. Add it in.
else
$context['possibleStars'][] = $value;
}


Replace that with:
// If the extension is not empty, and it is valid,
if (!empty($ext) && in_array($ext, $imageExts))
$context['possibleStars'][] = $value;
Title: Re: Rank Image Drop Down
Post by: puw on March 23, 2013, 12:38:44 PM
Thanks for the fast reply Yoshi, will try it out now :)
Title: Re: Rank Image Drop Down
Post by: puw on March 23, 2013, 02:26:27 PM
I've installed the mod no problem. Looked in the membergroups modify to check it's there and working as a drop down - all good.

Now I go into the default theme main folder (which I think you refer to as Source) and I see an updated "ManageMembergroups.template.php". Using the browser search facility and using various terms from the code above, there's nothing like the code you mention above, and I do not have a "ManageMembergroups.php" file, only the above one.

Anyone any ideas please?
Title: Re: Rank Image Drop Down
Post by: Chalky on March 23, 2013, 02:29:36 PM
ManageMembergroups.php is in the Sources folder, not Themes  ;)
Title: Re: Rank Image Drop Down
Post by: puw on March 23, 2013, 04:34:11 PM
Thank you for your correct guidance.

I'm used to looking in and working through the modify themes etc.

Now I realise I need to ftp copy the source file, update and then ftp back over the server's copy.

Everything works as I need it to - thanks everyone.
Title: Re: Rank Image Drop Down
Post by: rumblecloud on October 27, 2013, 08:29:04 AM
Thought you might like to know it does not work with my SMF 2.0.6 or earlier 2.0.4.

I uninstalled. It doesn't show all the files included in the default. It is a nice feature though-- if it worked.

r
Title: Re: Rank Image Drop Down
Post by: Chalky on October 27, 2013, 08:31:39 AM
Yoshi, rumblecloud is referring to this topic  http://www.simplemachines.org/community/index.php?topic=513261  :)
Title: Re: Rank Image Drop Down
Post by: NanoSector on October 27, 2013, 09:10:15 AM
Thanks, I created a package with the filter removed. :)
Title: Re: Rank Image Drop Down
Post by: Chalky on October 27, 2013, 09:16:19 AM
Nice one Yosh, thanks  :)
Title: Re: Rank Image Drop Down
Post by: rumblecloud on October 28, 2013, 02:13:51 PM
Yes, for sure thank you.

I am still finding my way around the SMF forum and stepping on all the appropriate toes as I stumble through.

I do appreciate the support and work you guys do.

r
Title: Re: Rank Image Drop Down
Post by: NekoJonez on January 23, 2014, 04:48:11 AM
Suggestion for a future update of this mod. The possibility to upload an image on that page.

But works on 2.0.7
Title: Re: Rank Image Drop Down
Post by: NanoSector on January 23, 2014, 11:06:17 AM
That's definitely on my to-do list, and thanks for testing, marked it as 2.0.7 compatible.
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 08:06:46 AM
I have some questions.

1. My images are in images/badges, not in images/....is there a way I can specify that?

2. When you say default theme, you just mean it's loading from there, not that you're changing where they load from? Last I checked that was theme specific....so if I have different ones in each theme am I looking at loading only the defaults or is this only in the admin panel part?

3. Have you considered adding this to profiles?
Title: Re: Rank Image Drop Down
Post by: NanoSector on August 03, 2014, 08:15:29 AM
1. Sure, five edits will have to be applied.

1. Sources/ManageMembergroups.php
Find:
if ($files = scandir($settings['default_theme_dir'] . '/images'))
Replace:
if ($files = scandir($settings['default_theme_dir'] . '/images/badges'))

2. Sources/ManageMembergroups.php
Find:
$ext = pathinfo($settings['default_theme_dir'] . '/images/' . $value, PATHINFO_EXTENSION);
Replace:
$ext = pathinfo($settings['default_theme_dir'] . '/images/badges/' . $value, PATHINFO_EXTENSION);

3. Sources/ManageMembergroups.php
Find:
$image_info = getimagesize($settings['default_theme_dir'] . '/images/' . $value);
Replace:
$image_info = getimagesize($settings['default_theme_dir'] . '/images/badges/' . $value);

4. Themes/default/ManageMembergroups.template.php
Find:
<img id="star_preview" src="', $settings['images_url'], '/', $context['group']['star_image'] == '' ? 'blank.gif' : $context['group']['star_image'], '" alt="*" />
Replace:
<img id="star_preview" src="', $settings['images_url'], '/badges/', $context['group']['star_image'] == '' ? 'blank.gif' : $context['group']['star_image'], '" alt="*" />

5. Themes/default/scripts/ridd.js
Find:
[code]document.getElementById('star_preview').src = smf_default_theme_url + '/images/' + ((select_box.value && star_count.value > 0) ? select_box.value : 'blank.gif');

Replace:
document.getElementById('star_preview').src = smf_default_theme_url + '/images/badges/' + ((select_box.value && star_count.value > 0) ? select_box.value : 'blank.gif');

Let me know if that works, and take backups :)

2. It's loading the image names from the default theme. It's possibly a bug, but me doing it this way means that I hit a barrier during the development. I'll take another look, put on my to-do list.

3. Membergroup stars can be set by an admin only, what do you want on the profile?
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 08:33:12 AM
Works amazingly!! :D

Thanks so much!!!
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 08:35:05 AM
Wait it's not quite there, it's submitting the image url as /images not images/badges. Did I miss something?
Title: Re: Rank Image Drop Down
Post by: NanoSector on August 03, 2014, 08:43:10 AM
Eh, ups.

Themes/default/ManageMembergroups.template.php,
find:
<option value="', $star, '"', $context['group']['star_image'] == $star ? ' selected="selected"' : '', '>', $star, '</option>';

Replace with:
<option value="badges/', $star, '"', $context['group']['star_image'] == $star ? ' selected="selected"' : '', '>', $star, '</option>';

That should fix it.
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 08:54:58 AM
Now that's working and the preview is not ha ha.
Title: Re: Rank Image Drop Down
Post by: NanoSector on August 03, 2014, 08:56:28 AM
Ah, undo the change to Themes/default/scripts/ridd.js :)
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 09:17:13 AM
Perfect! You rock, thank you so so much!! :D

You just seriously cut my work in half almost. Or at least made it easier! :D :-*
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 09:26:52 AM
Okay I am so sorry to do this... it's not selecting the right image... so when I edit a group that has an image the image is always reset to the first image listed (in this case admin). Can I fix that?
Title: Re: Rank Image Drop Down
Post by: NanoSector on August 03, 2014, 09:32:18 AM
Any errors in your error log?
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 09:58:32 AM
Not one :)
Title: Re: Rank Image Drop Down
Post by: NanoSector on August 03, 2014, 10:02:05 AM
Does the image show correctly on profiles etc.?
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 10:08:21 AM
Yep, everywhere. It's just that the drop down is not taking into account that there was a image already picked I think?
Title: Re: Rank Image Drop Down
Post by: NanoSector on August 03, 2014, 10:52:17 AM
Aha.

Themes/default/ManageMembergroups.template.php
Find...
<option value="badges/', $star, '"', $context['group']['star_image'] == $star ? ' selected="selected"' : '', '>', $star, '</option>';
Replace:
<option value="badges/', $star, '"', ($context['group']['star_image'] == 'badges/' . $star ? ' selected="selected"' : ''), '>', $star, '</option>';

Now it should work. :P
Sorry for the many attempts.
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 10:57:23 AM
Hey it's not your fault, this is technical, and with all code it's basically trial and error ha ha.

It would be nice to consider a field for "where are badges kept" because I know some people keep them in the forum root...and I know a lot of people who keep them in folders like "badges" or "ranks". So yeah it may be worth investing in :D.
Title: Re: Rank Image Drop Down
Post by: Arantor on August 03, 2014, 10:58:23 AM
And is that a per-theme folder or not? Bear in mind you can use a single central folder for all badges in all themes without a mod if you're careful.
Title: Re: Rank Image Drop Down
Post by: Jade Elizabeth on August 03, 2014, 11:02:33 AM
Also another note, even before when it wasn't showing the right image....the image that shows when the page loads never previews right. Maybe to do with JS loading order or something? Anyway it shows a blank image when you edit, but it is working now otherwise. I am not worried too much I just thought I would let you know in case it happens with the regular version too :).

Quote from: ‽ on August 03, 2014, 10:58:23 AM
And is that a per-theme folder or not? Bear in mind you can use a single central folder for all badges in all themes without a mod if you're careful.

I'm not sure how to do that. TBH I really like it in the images folder in the themes. I don't like them anywhere else. Besides, what if I want a set of Christmas badges for my Christmas theme? (hint: I DO! :D)

It would be awesome to be able to specify it globally in SMF though, anywhere you wanted.
Title: Re: Rank Image Drop Down
Post by: Arantor on August 03, 2014, 11:04:00 AM
You can't have both, one or the other, and having 'options' for everything is never, ever the good idea people think it is.
Title: Re: Rank Image Drop Down
Post by: Ninja ZX-10RR on December 11, 2014, 08:57:03 AM
Got to file a bug report for this one... I am surprised that nobody did before O.o
When you install this mod the suggest.js file providing a dropdown list of possible moderators doesn't work anymore. I have been told by a very experienced guy that instead of assigning the function to window.onload directly in the js file, you should be using addLoadEvent and that would cure it.
I tried uninstalling it and the problem went away indeed, also I tried to install it on a clean forum and the problem was there as soon as I installed this.

Thanks in advance for any help :)
Title: Re: Rank Image Drop Down
Post by: NanoSector on December 11, 2014, 10:01:20 AM
Thanks - will fix this in a future release.

I'll add links to my Github repos in the mod descriptions while I'm at it. Might help :)
Title: Re: Rank Image Drop Down
Post by: Ninja ZX-10RR on December 11, 2014, 10:24:37 AM
Waiting for it then :D thanks :D
Title: Re: Rank Image Drop Down
Post by: NanoSector on December 11, 2014, 10:46:53 AM
Do you have a special area where you find this issue? When editing a board and entering a username in the Moderators box, this doesn't happen to me and suggestions show up fine. Fresh 2.0.9 installation with only this mod installed.
Title: Re: Rank Image Drop Down
Post by: Ninja ZX-10RR on December 11, 2014, 11:15:49 AM
It happens to me instead... :| on 2 different forums... One is my own heavily modified, but also another one which is mostly default, no additional javascript installed. As soon as I install this mod the error pops out, I can PM you an admin login in my test account if you want.
Title: Re: Rank Image Drop Down
Post by: NanoSector on December 11, 2014, 11:40:34 AM
Feel free to PM me to take a look, can't hurt I guess.
Title: Re: Rank Image Drop Down
Post by: Ninja ZX-10RR on December 11, 2014, 11:46:38 AM
PM sent :)
Title: Re: Rank Image Drop Down
Post by: NanoSector on December 11, 2014, 03:02:41 PM
Can you try and see if this package works for you?
Title: Re: Rank Image Drop Down
Post by: Ninja ZX-10RR on December 11, 2014, 03:14:14 PM
It works :D thanks :D out of curiosity, is that nofilter or filter?

As a footnote you could have tried it on the test forum, when I gave you admin access on my test site I meant that you were given the rights to edit it ;)
Title: Re: Rank Image Drop Down
Post by: NanoSector on December 11, 2014, 03:15:17 PM
That's with the filter. Glad to hear it works :)

Yeah, you mentioned that. But I don't really like doodling around on others' sites. :)

Consider 1.0.1 released. I'll make a -nofilter package in a minute, then upload both to the mod site.
Title: Re: Rank Image Drop Down
Post by: Ninja ZX-10RR on December 11, 2014, 03:18:19 PM
Yay! Thank you so much then :D I wanted it with filter so I won't change a thing :D Awesome!
Title: Re: Rank Image Drop Down
Post by: NanoSector on December 11, 2014, 03:28:23 PM
Not a problem, thank you for reporting the bug :)