forked from Kunena/Kunena-Forum
/
avatar.php
76 lines (63 loc) · 2.39 KB
/
avatar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Kunena Component
* @package Kunena.Framework
* @subpackage Integration
*
* @copyright (C) 2008 - 2011 Kunena Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.kunena.org
**/
defined ( '_JEXEC' ) or die ();
require_once KPATH_ADMIN . '/libraries/integration/integration.php';
abstract class KunenaAvatar {
public $priority = 0;
public $avatarSizes = null;
protected $resize = false;
protected static $instance = false;
abstract public function __construct();
static public function getInstance($integration = null) {
if (self::$instance === false) {
$config = KunenaFactory::getConfig ();
if (! $integration)
$integration = $config->integration_avatar;
self::$instance = KunenaIntegration::initialize ( 'avatar', $integration );
}
return self::$instance;
}
public function load($userlist) {}
abstract public function getEditURL();
abstract protected function _getURL($user, $sizex, $sizey);
public function getSize($sizex=90, $sizey=90) {
$size = new StdClass();
$size->x = intval($sizex);
$size->y = intval($sizey);
if (!intval($sizex)) {
$template = KunenaFactory::getTemplate();
$name = ucfirst(strtolower($sizex));
$size->x = intval($template->params->get('avatarSizeX'.$name, 90));
$size->y = intval($template->params->get('avatarSizeY'.$name, 90));
}
return $size;
}
public function getURL($user, $sizex=90, $sizey=90) {
KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
$size = $this->getSize($sizex, $sizey);
if (!$size->x || !$size->y) return;
$result = $this->_getURL($user, $size->x, $size->y);
KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;
return $result;
}
public function getLink($user, $class='', $sizex=90, $sizey=90)
{
$size = $this->getSize($sizex, $sizey);
$avatar = $this->getURL($user, $size->x, $size->y);
if (!$avatar) return;
if ($class) $class=' class="'.$class.'"';
// Style is needed to resize avatar for JomSocial and other integration that do not have automatic resizing
if (!$this->resize) $style = 'style="max-width: '.$size->x.'px; max-height: '.$size->y.'px"';
else $style = '';
$link = '<img'.$class.' src="'.$avatar.'" alt="'.JText::sprintf('COM_KUNENA_LIB_AVATAR_TITLE', $user->getName()).'" '.$style.' />';
return $link;
}
}