Fixes to URI/URL handling for notices

This commit is contained in:
Mikael Nordfeldth 2014-04-18 23:53:16 +02:00
parent cecec3b088
commit 2c1dcc7f14

View File

@ -215,11 +215,15 @@ class Notice extends Managed_DataObject
// The risk is we start having empty urls and non-http uris... // The risk is we start having empty urls and non-http uris...
// and we can't really handle any other protocol right now. // and we can't really handle any other protocol right now.
switch (true) { switch (true) {
case common_valid_http_url($this->url): case common_valid_http_url($this->url): // should we allow non-http/https URLs?
return $this->url; return $this->url;
case $this->isLocal():
// let's generate a valid link to our locally available notice on demand
return common_local_url('shownotice', array('notice' => $this->id), null, null, false);
case common_valid_http_url($this->uri): case common_valid_http_url($this->uri):
return $this->uri; return $this->uri;
default: default:
common_debug('No URL available for notice: id='.$this->id);
throw new ServerException('No URL available for notice.'); throw new ServerException('No URL available for notice.');
} }
} }
@ -427,7 +431,7 @@ class Notice extends Managed_DataObject
if (!$notice->isLocal()) { if (!$notice->isLocal()) {
// Only do these checks for non-local notices. Local notices will generate these values later. // Only do these checks for non-local notices. Local notices will generate these values later.
if (!common_valid_http_url($url)) { if (!common_valid_http_url($url)) {
common_debug('Bad notice URL: ['.$url.'] Cannot link back to original!'); common_debug('Bad notice URL: ['.$url.'], URI: ['.$uri.']. Cannot link back to original! This is normal for shared notices etc.');
} }
if (empty($uri)) { if (empty($uri)) {
throw new ServerException('No URI for remote notice. Cannot accept that.'); throw new ServerException('No URI for remote notice. Cannot accept that.');
@ -602,7 +606,9 @@ class Notice extends Managed_DataObject
$changed = false; $changed = false;
if (empty($uri)) { // We can only get here if it's a local notice, since remote notices
// should've bailed out earlier due to lacking a URI.
if (empty($notice->uri)) {
$notice->uri = sprintf('%s%s=%d:%s=%s', $notice->uri = sprintf('%s%s=%d:%s=%s',
TagURI::mint(), TagURI::mint(),
'noticeId', $notice->id, 'noticeId', $notice->id,
@ -610,11 +616,6 @@ class Notice extends Managed_DataObject
$changed = true; $changed = true;
} }
if (empty($url)) {
$notice->url = common_local_url('shownotice', array('notice' => $notice->id), null, null, false);
$changed = true;
}
// If it's not part of a conversation, it's // If it's not part of a conversation, it's
// the beginning of a new conversation. // the beginning of a new conversation.