]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
showAvatar functions deduplicated into Widget class
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 21 Jun 2014 21:22:41 +0000 (23:22 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 21 Jun 2014 21:25:50 +0000 (23:25 +0200)
12 files changed:
actions/showprofiletag.php
actions/subscriptions.php
lib/accountprofileblock.php
lib/groupprofileblock.php
lib/noticelistitem.php
lib/peopletaglist.php
lib/peopletagsection.php
lib/profileblock.php
lib/profilelist.php
lib/subscriptionlist.php
lib/widget.php
plugins/Directory/lib/sortablegrouplist.php

index 4524e4aa8c23a8e71482bbf826b7977fe21e0336..6b1bc5e5b5dd289b5dd75bb76d210f3dab536fd4 100644 (file)
@@ -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);
-    }
 }
index c4dda3f627843e962951bd0d5e5f71eb02321ccb..733823d21b423058ef20d4f8d7f8a0e99e78e075 100644 (file)
@@ -172,7 +172,7 @@ class SubscriptionsListItem extends SubscriptionListItem
     function showProfile()
     {
         $this->startProfile();
-        $this->showAvatar();
+        $this->showAvatar($this->profile);
         $this->showFullName();
         $this->showLocation();
         $this->showHomepage();
index 5d4aba9558cf84d349599d7b6ec6cb61a456826b..143675063cb1f996c5c74681784c1516aa5d186c 100644 (file)
@@ -63,11 +63,6 @@ class AccountProfileBlock extends ProfileBlock
         }
     }
 
-    function avatar()
-    {
-        return $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
-    }
-
     function name()
     {
         return $this->profile->getBestName();
index 87ec174dc6f336c0a9ef1d6efc7575e573331fd5..1a15c34bb1c4259ba4810e17ce869b31bdb28fa0 100644 (file)
@@ -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()
index 75a1bdaab5469ccd539554dc89c3c8a539431b6d..0687a4d9313ec92ca90f7f8c3eff7fa0fca2ae6c 100644 (file)
@@ -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
      *
index 5c027d75869f6a9b539b54377e998d16cc4d4ddc..7fa26c56c14e498a0d136b2fe0929da839903ddb 100644 (file)
@@ -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');
index ccceb71a63475d7ced1323eb7c4ab610039bac8e..09953945160833adc519d10920d44f13cbecc2d0 100644 (file)
@@ -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);
-    }
 }
index 8edc5d9ba1b8ecbbe06b1a4c570d426fcd0a4941..65c4fa99d2c51ac980eae7ef32079478c7fd014f 100644 (file)
@@ -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()
     {
     }
index 11ed8945e9b0c60195561b15ffa8bec15351bab4..4478a50795bc6765354f5c9a01a6481cd987a90d 100644 (file)
@@ -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)) {
index 36dcbf65f81227681a22ae875a9b9a4b8080c946..09a660052c8150e240b4a517080d193f4f279e89 100644 (file)
@@ -76,7 +76,7 @@ class SubscriptionListItem extends ProfileListItem
     function showProfile()
     {
         $this->startProfile();
-        $this->showAvatar();
+        $this->showAvatar($this->profile);
         $this->showFullName();
         $this->showLocation();
         $this->showHomepage();
index 11f4d08cb8ed1b484d8ad1c0bbe1bdabfdf2e8fe..78472dd4d8d557594df45b8c84f6eff235898abf 100644 (file)
@@ -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()));
+    }
 }
index 37642e9b9c19b58b5945b649d63c1361829865ff..9c826539e87a59a28fa80edc9741038f1b27cbd7 100644 (file)
@@ -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();