*
* @return success flag
*/
- function prepare($args)
+ protected function prepare(array $args=array())
{
parent::prepare($args);
if ($this->boolean('ajax')) {
if (empty($this->profile)) {
// TRANS: Server error displayed trying to show a notice without a connected profile.
$this->serverError(_('Notice has no profile.'), 500);
- return false;
}
$this->user = User::getKV('id', $this->profile->id);
*
* @return Notice
*/
- function getNotice()
+ protected function getNotice()
{
$id = $this->arg('notice');
$notice = Notice::getKV('id', $id);
- if (empty($notice)) {
+ if (!$notice instanceof Notice) {
// Did we used to have it, and it got deleted?
$deleted = Deleted_notice::getKV($id);
- if (!empty($deleted)) {
+ if ($deleted instanceof Deleted_notice) {
// TRANS: Client error displayed trying to show a deleted notice.
$this->clientError(_('Notice deleted.'), 410);
} else {
*
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
if ($this->boolean('ajax')) {
$this->showAjax();
} else {
if ($this->notice->is_local == Notice::REMOTE) {
- if (!empty($this->notice->url)) {
- $target = $this->notice->url;
- } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
- // Old OMB posts saved the remote URL only into the URI field.
- $target = $this->notice->uri;
- } else {
- // Shouldn't happen.
- $target = false;
- }
- if ($target && $target != $this->selfUrl()) {
- common_redirect($target, 301);
- return false;
+ try {
+ $target = $this->notice->getUrl()
+ if ($target != $this->selfUrl()) {
+ common_redirect($target, 301);
+ }
+ } catch (InvalidUrlException $e) {
+ common_debug('ShownoticeAction could not redirect to remote notice with id='.$this->notice->id . '. Falling back to showPage().');
}
}
$this->showPage();