X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FNotice.php;h=7311a257a618180d3cdb688fbf8f7d73ea996784;hb=27ed6b7db05bd2879841d6d95d9d8e273d7454b5;hp=d9bdbc4498a0d90199443908c3fcc2b35572c5a2;hpb=85b022246f55c7e26190c77a1fab2b67ad4c317c;p=quix0rs-gnu-social.git diff --git a/classes/Notice.php b/classes/Notice.php index d9bdbc4498..7311a257a6 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -210,17 +210,42 @@ class Notice extends Managed_DataObject return $this->uri; } + /* + * @param $root boolean If true, link to just the conversation root. + * + * @return URL to conversation + */ + public function getConversationUrl($anchor=true) + { + return Conversation::getUrlFromNotice($this, $anchor); + } + + /* + * Get the local representation URL of this notice. + */ + public function getLocalUrl() + { + return common_local_url('shownotice', array('notice' => $this->id), null, null, false); + } + + /* + * Get the original representation URL of this notice. + */ public function getUrl() { // The risk is we start having empty urls and non-http uris... // and we can't really handle any other protocol right now. 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; + 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): return $this->uri; default: - throw new ServerException('No URL available for notice.'); + common_debug('No URL available for notice: id='.$this->id); + throw new InvalidUrlException($this->url); } } @@ -427,7 +452,7 @@ class Notice extends Managed_DataObject if (!$notice->isLocal()) { // Only do these checks for non-local notices. Local notices will generate these values later. 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)) { throw new ServerException('No URI for remote notice. Cannot accept that.'); @@ -602,7 +627,9 @@ class Notice extends Managed_DataObject $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', TagURI::mint(), 'noticeId', $notice->id, @@ -610,11 +637,6 @@ class Notice extends Managed_DataObject $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 // the beginning of a new conversation. @@ -1471,7 +1493,7 @@ class Notice extends Managed_DataObject $act->id = $this->uri; $act->time = strtotime($this->created); - $act->link = $this->bestUrl(); + $act->link = $this->getUrl(); $act->content = common_xml_safe_str($this->rendered); $profile = $this->getProfile(); @@ -1519,8 +1541,8 @@ class Notice extends Managed_DataObject try { $reply = $this->getParent(); - $ctx->replyToID = $reply->uri; - $ctx->replyToUrl = $reply->bestUrl(); + $ctx->replyToID = $reply->getUri(); + $ctx->replyToUrl = $reply->getUrl(); } catch (Exception $e) { // This is not a reply to something } @@ -1696,19 +1718,6 @@ class Notice extends Managed_DataObject return $noun->asString('activity:' . $element); } - function bestUrl() - { - if (!empty($this->url)) { - return $this->url; - } else if (!empty($this->uri) && preg_match('/^https?:/', $this->uri)) { - return $this->uri; - } else { - return common_local_url('shownotice', - array('notice' => $this->id)); - } - } - - /** * Determine which notice, if any, a new notice is in reply to. *