The ShowNoticeAction subclasses were cut-n-pasting a lot of prepare() code from ShowNoticeAction, though the only part that's different is how we look up the notice. Broke that out to a getNotice() method, so only that needs to be copied. Avoids extra copies of permission checks and other common code in this spot.
StatusNet::setApi(true);
}
- $id = $this->arg('notice');
-
- $this->notice = Notice::staticGet('id', $id);
-
- if (empty($this->notice)) {
- // Did we used to have it, and it got deleted?
- $deleted = Deleted_notice::staticGet($id);
- if (!empty($deleted)) {
- // TRANS: Client error displayed trying to show a deleted notice.
- $this->clientError(_('Notice deleted.'), 410);
- } else {
- // TRANS: Client error displayed trying to show a non-existing notice.
- $this->clientError(_('No such notice.'), 404);
- }
- return false;
- }
+ $this->notice = $this->getNotice();
$cur = common_current_user();
return true;
}
+ /**
+ * Fetch the notice to show. This may be overridden by child classes to
+ * customize what we fetch without duplicating all of the prepare() method.
+ *
+ * @return Notice
+ */
+ function getNotice()
+ {
+ $id = $this->arg('notice');
+
+ $notice = Notice::staticGet('id', $id);
+
+ if (empty($notice)) {
+ // Did we used to have it, and it got deleted?
+ $deleted = Deleted_notice::staticGet($id);
+ if (!empty($deleted)) {
+ // TRANS: Client error displayed trying to show a deleted notice.
+ $this->clientError(_('Notice deleted.'), 410);
+ } else {
+ // TRANS: Client error displayed trying to show a non-existing notice.
+ $this->clientError(_('No such notice.'), 404);
+ }
+ return false;
+ }
+ return $notice;
+ }
+
/**
* Is this action read-only?
*
{
protected $bookmark = null;
- /**
- * For initializing members of the class.
- *
- * @param array $argarray misc. arguments
- *
- * @return boolean true
- */
- function prepare($argarray)
+ function getNotice()
{
- OwnerDesignAction::prepare($argarray);
$this->id = $this->trimmed('id');
throw new ClientException(_m('No such bookmark.'), 404);
}
- $this->notice = Notice::staticGet('uri', $this->bookmark->uri);
+ $notice = Notice::staticGet('uri', $this->bookmark->uri);
- if (empty($this->notice)) {
+ if (empty($notice)) {
// Did we used to have it, and it got deleted?
// TRANS: Client exception thrown when referring to a non-existing bookmark.
throw new ClientException(_m('No such bookmark.'), 404);
}
- if (!empty($cur)) {
- $curProfile = $cur->getProfile();
- } else {
- $curProfile = null;
- }
-
- if (!$this->notice->inScope($curProfile)) {
- // TRANS: Client exception thrown when referring to a bookmark the user has no access to.
- throw new ClientException(_m('Not available.'), 403);
- }
-
- $this->user = User::staticGet('id', $this->bookmark->profile_id);
-
- if (empty($this->user)) {
- // TRANS: Client exception thrown when referring to a bookmark for a non-existing user.
- throw new ClientException(_m('No such user.'), 404);
- }
-
- $this->profile = $this->user->getProfile();
-
- if (empty($this->profile)) {
- // TRANS: Client exception thrown when referring to a bookmark for a non-existing profile.
- throw new ServerException(_m('User without a profile.'));
- }
-
- $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
-
- return true;
+ return $notice;
}
/**
protected $id = null;
protected $event = null;
- /**
- * For initializing members of the class.
- *
- * @param array $argarray misc. arguments
- *
- * @return boolean true
- */
- function prepare($argarray)
+ function getNotice()
{
- OwnerDesignAction::prepare($argarray);
-
$this->id = $this->trimmed('id');
$this->event = Happening::staticGet('id', $this->id);
throw new ClientException(_m('No such event.'), 404);
}
- $this->notice = $this->event->getNotice();
+ $notice = $this->event->getNotice();
- if (empty($this->notice)) {
+ if (empty($notice)) {
// Did we used to have it, and it got deleted?
// TRANS: Client exception thrown when referring to a non-existing event.
throw new ClientException(_m('No such event.'), 404);
}
- $cur = common_current_user();
-
- if (!empty($cur)) {
- $curProfile = $cur->getProfile();
- } else {
- $curProfile = null;
- }
-
- if (!$this->notice->inScope($curProfile)) {
- // TRANS: Client exception thrown when referring to an event the user has no access to.
- throw new ClientException(_m('Not available.'), 403);
- }
-
- $this->user = User::staticGet('id', $this->event->profile_id);
-
- if (empty($this->user)) {
- // TRANS: Client exception thrown when referring to a non-existing user.
- throw new ClientException(_m('No such user.'), 404);
- }
-
- $this->profile = $this->user->getProfile();
-
- if (empty($this->profile)) {
- // TRANS: Server exception thrown when referring to a user without a profile.
- throw new ServerException(_m('User without a profile.'));
- }
-
- $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
-
- return true;
+ return $notice;
}
/**
protected $rsvp = null;
protected $event = null;
- /**
- * For initializing members of the class.
- *
- * @param array $argarray misc. arguments
- *
- * @return boolean true
- */
- function prepare($argarray)
+ function getNotice()
{
- OwnerDesignAction::prepare($argarray);
-
$this->id = $this->trimmed('id');
$this->rsvp = RSVP::staticGet('id', $this->id);
throw new ClientException(_m('No such Event.'), 404);
}
- $this->notice = $this->rsvp->getNotice();
+ $notice = $this->rsvp->getNotice();
- if (empty($this->notice)) {
+ if (empty($notice)) {
// Did we used to have it, and it got deleted?
// TRANS: Client exception thrown when referring to a non-existing RSVP.
// TRANS: RSVP stands for "Please reply".
throw new ClientException(_m('No such RSVP.'), 404);
}
- $cur = common_current_user();
-
- if (!empty($cur)) {
- $curProfile = $cur->getProfile();
- } else {
- $curProfile = null;
- }
-
- if (!$this->notice->inScope($curProfile)) {
- // TRANS: Client exception thrown when referring to an event the user has no access to.
- throw new ClientException(_m('Not available.'), 403);
- }
-
- $this->user = User::staticGet('id', $this->rsvp->profile_id);
-
- if (empty($this->user)) {
- // TRANS: Client exception thrown when referring to a non-existing user.
- throw new ClientException(_m('No such user.'), 404);
- }
-
- $this->profile = $this->user->getProfile();
-
- if (empty($this->profile)) {
- // TRANS: Server exception thrown when referring to a user without a profile.
- throw new ServerException(_m('User without a profile.'));
- }
-
- $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
-
- return true;
+ return $notice;
}
/**
{
protected $poll = null;
- /**
- * For initializing members of the class.
- *
- * @param array $argarray misc. arguments
- *
- * @return boolean true
- */
- function prepare($argarray)
+ function getNotice()
{
- OwnerDesignAction::prepare($argarray);
-
$this->id = $this->trimmed('id');
$this->poll = Poll::staticGet('id', $this->id);
throw new ClientException(_m('No such poll.'), 404);
}
- $this->notice = $this->poll->getNotice();
+ $notice = $this->poll->getNotice();
- if (empty($this->notice)) {
+ if (empty($notice)) {
// Did we used to have it, and it got deleted?
// TRANS: Client exception thrown trying to view a non-existing poll notice.
throw new ClientException(_m('No such poll notice.'), 404);
}
- $cur = common_current_user();
-
- if (!empty($cur)) {
- $curProfile = $cur->getProfile();
- } else {
- $curProfile = null;
- }
-
- if (!$this->notice->inScope($curProfile)) {
- throw new ClientException(_('Not available.'), 403);
- }
-
- $this->user = User::staticGet('id', $this->poll->profile_id);
-
- if (empty($this->user)) {
- // TRANS: Client exception thrown trying to view a poll of a non-existing user.
- throw new ClientException(_m('No such user.'), 404);
- }
-
- $this->profile = $this->user->getProfile();
-
- if (empty($this->profile)) {
- // TRANS: Server exception thrown trying to view a poll for a user for which the profile could not be loaded.
- throw new ServerException(_m('User without a profile.'));
- }
-
- $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
-
- return true;
+ return $notice;
}
/**