]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
ShowstreamAction fixes so it's not as horrible
authorMikael Nordfeldth <mmn@hethane.se>
Fri, 10 Jul 2015 10:34:06 +0000 (12:34 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Fri, 10 Jul 2015 10:34:06 +0000 (12:34 +0200)
actions/all.php
actions/replies.php
actions/showstream.php
lib/noticestreamaction.php
lib/profileaction.php
plugins/ExtendedProfile/actions/profiledetail.php

index 39041064f9225f5be34c18c1b0415549a6c751fa..19413076b57f89231ba72f8ca333da6d06e5b065 100644 (file)
@@ -39,8 +39,6 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 class AllAction extends ShowstreamAction
 {
-    var $notice;
-
     public function getStream()
     {
         if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
@@ -54,7 +52,7 @@ class AllAction extends ShowstreamAction
 
     function title()
     {
-        if (!empty($this->scoped) && $this->scoped->id == $this->target->id) {
+        if (!empty($this->scoped) && $this->scoped->sameAs($this->target)) {
             // TRANS: Title of a user's own start page.
             return _('Home timeline');
         } else {
@@ -71,44 +69,44 @@ class AllAction extends ShowstreamAction
                 common_local_url(
                     'ApiTimelineFriends', array(
                         'format' => 'as',
-                        'id' => $this->target->nickname
+                        'id' => $this->target->getNickname()
                     )
                 ),
                 // TRANS: %s is user nickname.
-                sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->target->nickname)),
+                sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->target->getNickname())),
             new Feed(Feed::RSS1,
                 common_local_url(
                     'allrss', array(
                         'nickname' =>
-                        $this->target->nickname)
+                        $this->target->getNickname())
                 ),
                 // TRANS: %s is user nickname.
-                sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->target->nickname)),
+                sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->target->getNickname())),
             new Feed(Feed::RSS2,
                 common_local_url(
                     'ApiTimelineFriends', array(
                         'format' => 'rss',
-                        'id' => $this->target->nickname
+                        'id' => $this->target->getNickname()
                     )
                 ),
                 // TRANS: %s is user nickname.
-                sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->target->nickname)),
+                sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->target->getNickname())),
             new Feed(Feed::ATOM,
                 common_local_url(
                     'ApiTimelineFriends', array(
                         'format' => 'atom',
-                        'id' => $this->target->nickname
+                        'id' => $this->target->getNickname()
                     )
                 ),
                 // TRANS: %s is user nickname.
-                sprintf(_('Feed for friends of %s (Atom)'), $this->target->nickname))
+                sprintf(_('Feed for friends of %s (Atom)'), $this->target->getNickname()))
         );
     }
 
     function showEmptyListMessage()
     {
         // TRANS: Empty list message. %s is a user nickname.
-        $message = sprintf(_('This is the timeline for %s and friends but no one has posted anything yet.'), $this->target->nickname) . ' ';
+        $message = sprintf(_('This is the timeline for %s and friends but no one has posted anything yet.'), $this->target->getNickname()) . ' ';
 
         if (common_logged_in()) {
             if ($this->target->id === $this->scoped->id) {
@@ -118,12 +116,12 @@ class AllAction extends ShowstreamAction
             } else {
                 // TRANS: %1$s is user nickname, %2$s is user nickname, %2$s is user nickname prefixed with "@".
                 // TRANS: This message contains Markdown links. Keep "](" together.
-                $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) from their profile or [post something to them](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->target->nickname, $this->target->nickname, '@' . $this->target->nickname);
+                $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) from their profile or [post something to them](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->target->getNickname(), $this->target->getNickname(), '@' . $this->target->getNickname());
             }
         } else {
             // TRANS: Encouragement displayed on empty timeline user pages for anonymous users.
             // TRANS: %s is a user nickname. This message contains Markdown links. Keep "](" together.
-            $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->nickname);
+            $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname());
         }
 
         $this->elementStart('div', 'guide');
@@ -134,19 +132,10 @@ class AllAction extends ShowstreamAction
     function showContent()
     {
         if (Event::handle('StartShowAllContent', array($this))) {
-
-            $profile = null;
-
-            $current_user = common_current_user();
-
-            if (!empty($current_user)) {
-                $profile = $current_user->getProfile();
-            }
-
-            if (!empty($current_user) && $current_user->streamModeOnly()) {
+            if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
                 $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
             } else {
-                $nl = new ThreadedNoticeList($this->notice, $this, $profile);
+                $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped);
             }
 
             $cnt = $nl->show();
@@ -157,7 +146,7 @@ class AllAction extends ShowstreamAction
 
             $this->pagination(
                 $this->page > 1, $cnt > NOTICES_PER_PAGE,
-                $this->page, 'all', array('nickname' => $this->target->nickname)
+                $this->page, 'all', array('nickname' => $this->target->getNickname())
             );
 
             Event::handle('EndShowAllContent', array($this));
index 8baf9d69e0af87410123c5af3cb5633c4c60dcc2..ae6ec90658dca67272bbbc39d1734012db92deee 100644 (file)
@@ -40,9 +40,6 @@ if (!defined('GNUSOCIAL')) { exit(1); }
  */
 class RepliesAction extends ShowstreamAction
 {
-    var $page = null;
-    var $notice;
-
     public function getStream()
     {
         return new ReplyNoticeStream($this->target->getID(), $this->scoped);
@@ -85,7 +82,7 @@ class RepliesAction extends ShowstreamAction
                               // TRANS: Link for feed with replies for a user.
                               // TRANS: %s is a user nickname.
                               sprintf(_('Replies feed for %s (Activity Streams JSON)'),
-                                      $this->user->nickname)),
+                                      $this->target->getNickname())),
                      new Feed(Feed::RSS1,
                               common_local_url('repliesrss',
                                                array('nickname' => $this->target->getNickname())),
index 6eccbd06bf49db0f33db1394df1ca3f828918f63..51384eb487534a5f508fa63b23573018bee3cffe 100644 (file)
@@ -47,16 +47,15 @@ if (!defined('GNUSOCIAL')) { exit(1); }
  */
 class ShowstreamAction extends NoticestreamAction
 {
-    var $notice;
+    protected $target = null;
 
     protected function doPreparation()
     {
         // showstream requires a nickname
-        $nickname_arg = $this->arg('nickname');
+        $nickname_arg = $this->trimmed('nickname');
         $nickname     = common_canonical_nickname($nickname_arg);
 
         // Permanent redirect on non-canonical nickname
-
         if ($nickname_arg != $nickname) {
             $args = array('nickname' => $nickname);
             if ($this->arg('page') && $this->arg('page') != 1) {
@@ -64,18 +63,20 @@ class ShowstreamAction extends NoticestreamAction
             }
             common_redirect(common_local_url($this->getActionName(), $args), 301);
         }
-        $this->user = User::getKV('nickname', $nickname);
 
-        if (!$this->user) {
+        try {
+            $user = User::getByNickname($nickname);
+        } catch (NoSuchUserException $e) {
             $group = Local_group::getKV('nickname', $nickname);
             if ($group instanceof Local_group) {
                 common_redirect($group->getProfile()->getUrl());
             }
-            // TRANS: Client error displayed when calling a profile action without specifying a user.
-            $this->clientError(_('No such user.'), 404);
+
+            // No user nor group found, throw the NoSuchUserException again
+            throw $e;
         }
 
-        $this->target = $this->user->getProfile();
+        $this->target = $user->getProfile();
     }
 
     public function getStream()
@@ -289,7 +290,7 @@ class ShowstreamAction extends NoticestreamAction
     {
         parent::showSections();
         if (!common_config('performance', 'high')) {
-            $cloud = new PersonalTagCloudSection($this, $this->user);
+            $cloud = new PersonalTagCloudSection($this->target, $this);
             $cloud->show();
         }
     }
@@ -298,7 +299,7 @@ class ShowstreamAction extends NoticestreamAction
     {
         $options = parent::noticeFormOptions();
 
-        if (!$this->scoped instanceof Profile || $this->scoped->id != $this->target->id) {
+        if (!$this->scoped instanceof Profile || !$this->scoped->sameAs($this->target)) {
             $options['to_profile'] =  $this->target;
         }
 
index 39c19d551f0500110f8c8d1520eb1a6233694d12..ed8921860efa40744845d6d5f0c32ed01b15d7bf 100644 (file)
@@ -4,6 +4,7 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 abstract class NoticestreamAction extends ProfileAction
 {
+    protected $notice = null;   // holds the stream result
 
     protected function prepare(array $args=array()) {
         parent::prepare($args);
index d98bcd7f7433387a45715ab706bfda5b4a1115a0..d08446afae61c5a6254b5ef1b2a921b6d5f1ecc3 100644 (file)
@@ -58,9 +58,6 @@ abstract class ProfileAction extends ManagedAction
             throw new ClientException(_('This profile has been silenced by site moderators'), 403);
         }
 
-        // backwards compatibility until all actions are fixed to use $this->target
-        $this->profile = $this->target;
-
         $this->tag = $this->trimmed('tag');
         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
         common_set_returnto($this->selfUrl());
index a777a28e031cacbab9a47b2335fc97ad12c689da..ea0b8ad6309ef263131b4e91835414dd1700da8f 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 class ProfileDetailAction extends ShowstreamAction
 {
-
     function isReadOnly($args)
     {
         return true;
@@ -31,7 +28,7 @@ class ProfileDetailAction extends ShowstreamAction
 
     function title()
     {
-        return $this->profile->getFancyName();
+        return $this->target->getFancyName();
     }
 
     function showStylesheets() {
@@ -43,7 +40,7 @@ class ProfileDetailAction extends ShowstreamAction
     function showContent()
     {
         $cur = common_current_user();
-        if ($cur && $cur->id == $this->profile->id) { // your own page
+        if ($this->scoped instanceof Profile && $this->scoped->sameAs($this->target)) {
             $this->elementStart('div', 'entity_actions');
             $this->elementStart('ul');
             $this->elementStart('li', 'entity_edit');
@@ -57,7 +54,7 @@ class ProfileDetailAction extends ShowstreamAction
             $this->elementEnd('div');
         }
 
-        $widget = new ExtendedProfileWidget($this, $this->profile);
+        $widget = new ExtendedProfileWidget($this, $this->target);
         $widget->show();
     }
 }