git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit e4f1c77d authored by mmn's avatar mmn

showAvatar functions deduplicated into Widget class

parent 10105a99
......@@ -359,6 +359,8 @@ class ShowprofiletagAction extends Action
class Peopletag extends PeopletagListItem
{
protected $avatarSize = AVATAR_PROFILE_SIZE;
function showStart()
{
$mode = $this->peopletag->private ? 'private' : 'public';
......@@ -370,9 +372,4 @@ class Peopletag extends PeopletagListItem
{
$this->out->elementEnd('div');
}
function showAvatar()
{
parent::showAvatar(AVATAR_PROFILE_SIZE);
}
}
......@@ -172,7 +172,7 @@ class SubscriptionsListItem extends SubscriptionListItem
function showProfile()
{
$this->startProfile();
$this->showAvatar();
$this->showAvatar($this->profile);
$this->showFullName();
$this->showLocation();
$this->showHomepage();
......
......@@ -63,11 +63,6 @@ class AccountProfileBlock extends ProfileBlock
}
}
function avatar()
{
return $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
}
function name()
{
return $this->profile->getBestName();
......
......@@ -52,12 +52,17 @@ class GroupProfileBlock extends ProfileBlock
{
parent::__construct($out);
$this->group = $group;
$this->profile = $this->group->getProfile();
}
function avatar()
{
return ($this->group->homepage_logo) ?
$this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
protected function showAvatar(Profile $profile, $size=null)
{
$avatar_url = $profile->getGroup()->homepage_logo ?: User_group::defaultLogo($size ?: $this->avatarSize());
$this->out->element('img', array('src' => $avatar_url,
'class' => 'avatar u-photo',
'width' => $this->avatarSize(),
'height' => $this->avatarSize(),
'alt' => $profile->getBestName()));
}
function name()
......
......@@ -218,9 +218,8 @@ class NoticeListItem extends Widget
'title' => $this->profile->nickname);
$this->out->elementStart('a', $attrs);
$this->showAvatar();
$this->out->text(' ');
$this->out->element('span',array('class' => 'fn'), $this->profile->getStreamName());
$this->showAvatar($this->profile);
$this->out->text($this->profile->getStreamName());
$this->out->elementEnd('a');
$this->out->elementEnd('span');
......@@ -275,35 +274,6 @@ class NoticeListItem extends Widget
return $this->notice->getReplyProfiles();
}
/**
* show the avatar of the notice's author
*
* This will use the default avatar if no avatar is assigned for the author.
* It makes a link to the author's profile.
*
* @return void
*/
function showAvatar()
{
$avatar_size = $this->avatarSize();
$avatarUrl = $this->profile->avatarUrl($avatar_size);
$this->out->element('img', array('src' => $avatarUrl,
'class' => 'avatar photo',
'width' => $avatar_size,
'height' => $avatar_size,
'alt' =>
($this->profile->fullname) ?
$this->profile->fullname :
$this->profile->nickname));
}
function avatarSize()
{
return AVATAR_STREAM_SIZE;
}
/**
* show the nickname of the author
*
......
......@@ -231,11 +231,8 @@ class PeopletagListItem extends Widget
$attrs['title'] = $this->profile->fullname . ' (' . $this->profile->nickname . ')';
}
$this->out->elementStart('a', $attrs);
$this->showAvatar();
$this->out->text(' ');
$this->out->element('span', 'nickname fn',
htmlspecialchars($this->profile->nickname));
$this->showAvatar($this->profile);
$this->out->text($this->profile->getNickname());
$this->out->elementEnd('a');
$this->out->elementEnd('span');
}
......@@ -272,29 +269,6 @@ class PeopletagListItem extends Widget
$this->out->elementEnd('span');
}
/**
* show the avatar of the peopletag's creator
*
* This will use the default avatar if no avatar is assigned for the author.
* It makes a link to the author's profile.
*
* @return void
*/
function showAvatar($size=AVATAR_STREAM_SIZE)
{
$avatarUrl = $this->profile->avatarUrl($size);
$this->out->element('img', array('src' => $avatarUrl,
'class' => 'avatar photo',
'width' => $size,
'height' => $size,
'alt' =>
($this->profile->fullname) ?
$this->profile->fullname :
$this->profile->nickname));
}
function showActions()
{
$this->out->elementStart('div', 'entity_actions');
......
......@@ -48,6 +48,8 @@ define('PEOPLETAGS_PER_SECTION', 6);
*/
class PeopletagSection extends Section
{
protected $avatarSize = AVATAR_MINI_SIZE;
function showContent()
{
$tags = $this->getPeopletags();
......@@ -135,9 +137,4 @@ class PeopletagSectionItem extends PeopletagListItem
htmlspecialchars($this->peopletag->tag));
$this->out->elementEnd('span');
}
function showAvatar()
{
parent::showAvatar(AVATAR_MINI_SIZE);
}
}
......@@ -47,7 +47,8 @@ if (!defined('STATUSNET')) {
abstract class ProfileBlock extends Widget
{
abstract function avatar();
protected $avatarSize = AVATAR_PROFILE_SIZE;
abstract function name();
abstract function url();
abstract function location();
......@@ -57,7 +58,7 @@ abstract class ProfileBlock extends Widget
function show()
{
$this->showActions();
$this->showAvatar();
$this->showAvatar($this->profile);
$this->showName();
$this->showLocation();
$this->showHomepage();
......@@ -66,22 +67,6 @@ abstract class ProfileBlock extends Widget
$this->showTags();
}
function showAvatar()
{
$size = $this->avatarSize();
$this->out->element(
'img',
array(
'src' => $this->avatar(),
'class' => 'ur_face',
'alt' => $this->name(),
'width' => $size,
'height' => $size
)
);
}
function showName()
{
$name = $this->name();
......@@ -161,11 +146,6 @@ abstract class ProfileBlock extends Widget
}
}
function avatarSize()
{
return AVATAR_PROFILE_SIZE;
}
function showTags()
{
}
......
......@@ -31,7 +31,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/widget.php';
require_once INSTALLDIR.'/lib/peopletags.php';
/**
......@@ -107,11 +106,6 @@ class ProfileList extends Widget
{
return PROFILES_PER_PAGE;
}
function avatarSize()
{
return AVATAR_STREAM_SIZE;
}
}
class ProfileListItem extends Widget
......@@ -157,7 +151,10 @@ class ProfileListItem extends Widget
$this->startProfile();
if (Event::handle('StartProfileListItemProfileElements', array($this))) {
if (Event::handle('StartProfileListItemAvatar', array($this))) {
$aAttrs = $this->linkAttributes();
$this->out->elementStart('a', $aAttrs);
$this->showAvatar();
$this->out->elementEnd('a');
Event::handle('EndProfileListItemAvatar', array($this));
}
if (Event::handle('StartProfileListItemFullName', array($this))) {
......@@ -190,26 +187,6 @@ class ProfileListItem extends Widget
$this->out->elementStart('div', 'entity_profile vcard entry-content');
}
function showAvatar()
{
$avatarUrl = $this->profile->avatarUrl(AVATAR_STREAM_SIZE);
$aAttrs = $this->linkAttributes();
$this->out->elementStart('a', $aAttrs);
$this->out->element('img', array('src' => $avatarUrl,
'class' => 'photo avatar',
'width' => AVATAR_STREAM_SIZE,
'height' => AVATAR_STREAM_SIZE,
'alt' =>
($this->profile->fullname) ? $this->profile->fullname :
$this->profile->nickname));
$this->out->text(' ');
$hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
$this->out->elementStart('span', $hasFN);
$this->out->raw($this->highlight($this->profile->nickname));
$this->out->elementEnd('span');
$this->out->elementEnd('a');
}
function showFullName()
{
if (!empty($this->profile->fullname)) {
......
......@@ -76,7 +76,7 @@ class SubscriptionListItem extends ProfileListItem
function showProfile()
{
$this->startProfile();
$this->showAvatar();
$this->showAvatar($this->profile);
$this->showFullName();
$this->showLocation();
$this->showHomepage();
......
......@@ -51,6 +51,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
class Widget
{
protected $avatarSize = AVATAR_STREAM_SIZE;
/**
* HTMLOutputter to use for output
*/
......@@ -105,4 +107,22 @@ class Widget
{
return call_user_func_array(array($this->out, $name), $arguments);
}
/**
* Default avatar size for this widget.
*/
public function avatarSize()
{
return $this->avatarSize;
}
protected function showAvatar(Profile $profile, $size=null)
{
$avatar_url = $profile->avatarUrl($size ?: $this->avatarSize());
$this->out->element('img', array('src' => $avatar_url,
'class' => 'avatar u-photo',
'width' => $this->avatarSize(),
'height' => $this->avatarSize(),
'alt' => $profile->getBestName()));
}
}
......@@ -167,37 +167,15 @@ class SortableGroupListItem extends SortableSubscriptionListItem
}
function showAvatar()
function showAvatar(Profile $profile, $size=null)
{
$logo = ($this->profile->stream_logo) ?
$this->profile->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE);
$this->out->elementStart(
'a',
array(
'href' => $this->profile->homeUrl(),
'class' => 'url entry-title',
'rel' => 'contact group'
)
);
$this->out->element(
'img',
array(
'src' => $logo,
'class' => 'photo avatar',
'width' => AVATAR_STREAM_SIZE,
'height' => AVATAR_STREAM_SIZE,
'alt' => ($this->profile->fullname)
? $this->profile->fullname : $this->profile->nickname
)
);
$logo = $profile->getGroup()->stream_logo ?: User_group::defaultLogo($size ?: $this->avatarSize());
$this->out->text(' ');
$hasFN = ($this->profile->fullname) ? 'nickname' : 'fn org nickname';
$this->out->elementStart('span', $hasFN);
$this->out->raw($this->highlight($this->profile->nickname));
$this->out->elementEnd('span');
$this->out->elementEnd('a');
$this->out->element('img', array('src' => $logo,
'class' => 'photo avatar',
'width' => AVATAR_STREAM_SIZE,
'height' => AVATAR_STREAM_SIZE,
'alt' => $profile->getBestName()));
}
function show()
......@@ -226,7 +204,17 @@ class SortableGroupListItem extends SortableSubscriptionListItem
function showProfile()
{
$this->startProfile();
$this->showAvatar();
$hasFN = ($this->profile->fullname) ? 'nickname' : 'fn org nickname';
$this->out->elementStart('a', array('href' => $this->profile->homeUrl(),
'class' => 'h-card org nickname',
'rel' => 'contact group'));
// getProfile here is because $this->profile is a User_group, which it should stop
// being by making sure the group listing runs a ->getGroup when it's necessary.
$this->showAvatar($this->profile->getProfile());
$this->out->text($this->profile->getNickname());
$this->out->elementEnd('a');
$this->showFullName();
$this->showLocation();
$this->showHomepage();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment