How to inverse avatar_drivers?

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
Tarantino
Registered User
Posts: 874
Joined: Sat Feb 18, 2012 1:51 pm

How to inverse avatar_drivers?

Post by Tarantino »

Hi there,

on UCP, when we want to change avatars on the dropdown list where we've Upload Avatar option, my html uses "avatar_drivers" variable.

I want to know how can I inverse the order of that list. Right now its Ascending (a->z), I want to put Descending (z->a)

How can I acheive that?

It can be with core edits.
User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 52768
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: How to inverse avatar_drivers?

Post by stevemaury »

You mean you want those four options, which are all easily visible at once, to start with "Upload avatar" instead of "Gravatar"?
I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)
Tarantino
Registered User
Posts: 874
Joined: Sat Feb 18, 2012 1:51 pm

Re: How to inverse avatar_drivers?

Post by Tarantino »

Exactly.
User avatar
jackennils
Registered User
Posts: 229
Joined: Mon Jun 01, 2009 7:48 pm

Re: How to inverse avatar_drivers?

Post by jackennils »

Same here, would like to change the order as well.
Tarantino
Registered User
Posts: 874
Joined: Sat Feb 18, 2012 1:51 pm

Re: How to inverse avatar_drivers?

Post by Tarantino »

With core edits:

/includes/ucp/ucp_profile.php

Find: $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers();
Replace with: $avatar_drivers = array_reverse($phpbb_avatar_manager->get_enabled_drivers());
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to inverse avatar_drivers?

Post by 3Di »

Questions like this should be posted in the Custom Coding forum, created on purpose.

On a side note I don't see the above suggestion as the right one.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 52768
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: How to inverse avatar_drivers?

Post by stevemaury »

Can I ask why?
I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to inverse avatar_drivers?

Post by 3Di »

That list is managed elsewhere, see forumroot/phpbb/avatar/manager.php, function load_enabled_drivers() just to begin with, array indices should maintain their correlation with the array elements they are associated with, that's why uses asort().
That array_reverse() hack should be set to true at least.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Tarantino
Registered User
Posts: 874
Joined: Sat Feb 18, 2012 1:51 pm

Re: How to inverse avatar_drivers?

Post by Tarantino »

My edit worked.
And I don't see any post with a better solution.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to inverse avatar_drivers?

Post by 3Di »

Tarantino wrote: Sun Feb 25, 2018 4:37 am My edit worked.
And I don't see any post with a better solution.
The post of mine above yours is the better solution. Again..
3Di wrote: Sun Feb 25, 2018 1:53 am That list is managed elsewhere, see forumroot/phpbb/avatar/manager.php, function load_enabled_drivers() just to begin with, array indices should maintain their correlation with the array elements they are associated with, that's why uses asort().
And here is the function

Code: Select all

	/**
	* Load the list of enabled drivers
	* This is executed once and fills self::$enabled_drivers
	*/
	protected function load_enabled_drivers()
	{
		if (!empty($this->avatar_drivers))
		{
			self::$enabled_drivers = array();
			foreach ($this->avatar_drivers as $driver)
			{
				if ($this->is_enabled($driver))
				{
					self::$enabled_drivers[$driver->get_name()] = $driver->get_name();
				}
			}
			asort(self::$enabled_drivers);
		}
	}
The line to be changed is asort(self::$enabled_drivers);

Based on this list of possible PHP function to use in order to modify that line (which excludes array_reverse() ofcourse)..
https://www.w3schools.com/Php/php_arrays_sort.asp
.. what would it be the right one for your use case?
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Tarantino
Registered User
Posts: 874
Joined: Sat Feb 18, 2012 1:51 pm

Re: How to inverse avatar_drivers?

Post by Tarantino »

I see. arsort would be the case.

Thanks for pointing that out ;)
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to inverse avatar_drivers?

Post by 3Di »

Tarantino wrote: Wed Feb 28, 2018 6:48 pm I see. arsort would be the case.

Thanks for pointing that out ;)
Anytime.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Tarantino
Registered User
Posts: 874
Joined: Sat Feb 18, 2012 1:51 pm

Re: How to inverse avatar_drivers?

Post by Tarantino »

I've a new doubt related to this. The order is now inversed but how can I changed the default option?
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to inverse avatar_drivers?

Post by 3Di »

includes/ucp/ucp_profile.php

FIND

Code: Select all

$selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type']));
INLINE-FIND
$user->data['user_avatar_type']

INLINE-REPLACE-WITH
'avatar.driver.local' for Gallery

'avatar.driver.upload' for Upload

'avatar.driver.remote' for Remote avatar

like

Code: Select all

$selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', 'avatar.driver.local'));
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Post Reply

Return to “phpBB Custom Coding”