Dirt Diglett
New member
Hey there! I've just started delving into developing for XenForo and need to overwrite the avatar helper... From everything I can read I am sure i've done everything right but the helper add-on is having no effect on XenForo as it still shows the stock standard avatars.
Can anybody please tell me what I've either done wrong or missed?
The Directory of the Addon is "/library/SteamAvatar/"
The listener is "/library/SteamAvatar/Listener.php" and contains this:
The Helper is "/library/SteamAvatar/Helpers.php" and contains this:
Can anyone tell me what I've missed?
Thanks everyone!
Can anybody please tell me what I've either done wrong or missed?
The Directory of the Addon is "/library/SteamAvatar/"
The listener is "/library/SteamAvatar/Listener.php" and contains this:
PHP:
<?php
class SteamAvatar_Listener {
public static function init(XenForo_Dependencies_Abstract $dependencies, array $data)
{
XenForo_Template_Helper_Core::$helperCallbacks += array(
'avatar' => array('SteamAvatar_Helpers', 'helperAvatarUrl'),
'avatarhtml' => array('SteamAvatar_Helpers', 'helperAvatarHtml')
);
}
}
?>
The Helper is "/library/SteamAvatar/Helpers.php" and contains this:
PHP:
<?php
class SteamAvatar_Helpers {
public static function helperAvatarHtml(array $user, $img, array $attributes = array(), $content = '')
{
if (!empty($attributes['size']))
{
$size = strtolower($attributes['size']);
switch ($size)
{
case 'l':
case 'm':
case 's':
break;
default:
$size = 'm';
}
}
else
{
$size = 'm';
}
// ~~~~~~~~~~ Manually set the $src for testing, to ensure the change is actually applied ~~~~~~~~~~~~
$src = "http://media.steampowered.com/steamcommunity/public/images/avatars/ea/eab718e53d77e95c02271015f63e896171ede756_full.jpg";
$href = self::getUserHref($user, $attributes);
unset($attributes['href']);
if ($img)
{
$username = htmlspecialchars($user['username']);
$dimension = XenForo_Model_Avatar::getSizeFromCode($size);
$image = "<img src=\"{$src}\" width=\"{$dimension}\" height=\"{$dimension}\" alt=\"{$username}\" />";
}
else
{
$text = (empty($attributes['text']) ? '' : htmlspecialchars($attributes['text']));
$image = "<span class=\"img {$size}\" style=\"background-image: url('{$src}')\">{$text}</span>";
}
$class = (empty($attributes['class']) ? '' : ' ' . htmlspecialchars($attributes['class']));
unset($attributes['user'], $attributes['size'], $attributes['img'], $attributes['text'], $attributes['class']);
$attribs = self::getAttributes($attributes);
if ($content !== '')
{
$content = " {$content}";
}
return "<a{$href} class=\"avatar Av{$user['user_id']}{$size}{$class}\"{$attribs} data-avatarhtml=\"true\">{$image}{$content}</a>";
}
public static function helperAvatarUrl($user, $size, $forceType = null, $canonical = false)
{
if (!is_array($user))
{
$user = array();
}
if ($forceType)
{
switch ($forceType)
{
case 'default':
case 'custom':
break;
default:
$forceType = null;
break;
}
}
// ~~~~~~~~~~ Manually set the $url for testing, to ensure the change is actually applied ~~~~~~~~~~~~
$url = "http://media.steampowered.com/steamcommunity/public/images/avatars/ea/eab718e53d77e95c02271015f63e896171ede756_full.jpg";
return htmlspecialchars($url);
}
public static function getAvatarUrls(array $user)
{
$urls = array();
foreach (XenForo_Model_Avatar::getSizes() AS $sizeCode => $maxDimensions)
{
$urls[$sizeCode] = self::getAvatarUrl($user, $sizeCode);
}
return $urls;
}
public static function getAvatarUrl(array $user, $size, $forceType = '')
{
// ~~~~~~~~~~ Manually set the $url for testing, to ensure the change is actually applied ~~~~~~~~~~~~
$url = "http://media.steampowered.com/steamcommunity/public/images/avatars/ea/eab718e53d77e95c02271015f63e896171ede756_full.jpg";
return $url;
}
}
?>
Can anyone tell me what I've missed?
Thanks everyone!