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

Is it possible to make this add-on?

Luxus

Well-known member
#1
XenForo/Model/Avatar.php

Code:
class XenForo_Model_Avatar extends XenForo_Model
{
	/**
	 * List of available avatar sizes. The largest must go first.
	 * Avatars of each size code (directory name) will be no bigger
	 * than the given pixel amount.
	 *
	 * @var array Format: [code] => max pixels
	 */
	protected static $_sizes = array(
		'l' => 192,
		'm' => 96,
		's' => 48
	);
You can directly change the l, m and s avatar sizes here. I just want to know if its possible to make an add-on for this so that you don't need to edit this file directly. I am trying to make this add-on with the help of this guide, but I see no function to extend. How to proceed?
 

digitalpoint

Well-known member
#5
You can edit them by extending the Avatar model, use a __construct() method there that sets self::$_sizes to what you want.

That will work for most things, but I ran into a problem in that there are 2 methods in the Avatar model that are called statically sometimes (not extended)...

So places that use these functions, will not reflect your updated sizes...

XenForo_Model_Avatar::getSizes();
XenForo_Model_Avatar::getSizeFromCode();

I ended up just needing to edit the XenForo_Model_Avatar class manually for the sizes unfortunately. Would be nice if they were settings/options or something.
 

Jon W

Well-known member
#6
So places that use these functions, will not reflect your updated sizes...

XenForo_Model_Avatar::getSizes();
XenForo_Model_Avatar::getSizeFromCode();

I ended up just needing to edit the XenForo_Model_Avatar class manually for the sizes unfortunately. Would be nice if they were settings/options or something.
They will only not reflect the updated sizes if the XenForo_Model_Avatar object is not created before the static functions are called. Not sure if this is the case anywhere in the core XenForo code.
 

digitalpoint

Well-known member
#7
They will only not reflect the updated sizes if the XenForo_Model_Avatar object is not created before the static functions are called. Not sure if this is the case anywhere in the core XenForo code.
There are a few places... for example when templates call the <xen:avatar> tag... that causes the XenForo_Template_Helper_Core::helperAvatarHtml() method to be called which calls the XenForo_Model_Avatar::getSizeFromCode() method without the Avatar model being initialized upstream.