From: Evan Prodromou Date: Sun, 19 Dec 2010 15:17:23 +0000 (-0500) Subject: Move notice bookmark creation to Notice_bookmark::saveNew() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cee93dd15d4b922f98529ccfe1eba450e6647be2;p=quix0rs-gnu-social.git Move notice bookmark creation to Notice_bookmark::saveNew() --- diff --git a/plugins/Bookmark/Notice_bookmark.php b/plugins/Bookmark/Notice_bookmark.php index 6a49421fb5..bff5df57d0 100644 --- a/plugins/Bookmark/Notice_bookmark.php +++ b/plugins/Bookmark/Notice_bookmark.php @@ -115,4 +115,76 @@ class Notice_bookmark extends Memcached_DataObject { return array(false, false, false); } + + static function saveNew($user, $title, $url, $rawtags, $description) + { + if (is_string($rawtags)) { + $rawtags = preg_split('/[\s,]+/', $rawtags); + } + + $tags = array(); + $replies = array(); + + // filter "for:nickname" tags + + foreach ($rawtags as $tag) { + if (strtolower(mb_substr($tag, 0, 4)) == 'for:') { + $nickname = mb_substr($tag, 4); + $other = common_relative_profile($user->getProfile(), + $nickname); + if (!empty($other)) { + $replies[] = $other->getUri(); + } + } else { + $tags[] = common_canonical_tag($tag); + } + } + + $hashtags = array(); + $taglinks = array(); + + foreach ($tags as $tag) { + $hashtags[] = '#'.$tag; + $attrs = array('href' => Notice_tag::url($tag), + 'rel' => $tag, + 'class' => 'tag'); + $taglinks[] = XMLStringer::estring('a', $attrs, $tag); + } + + $content = sprintf(_('"%s" %s %s %s'), + $title, + File_redirection::makeShort($url, $user), + $description, + implode(' ', $hashtags)); + + $rendered = sprintf(_(''. + '%s '. + '%s '. + '%s'. + ''), + htmlspecialchars($url), + htmlspecialchars($title), + htmlspecialchars($description), + implode(' ', $taglinks)); + + $options = array('urls' => array($url), + 'rendered' => $rendered, + 'tags' => $tags, + 'replies' => $replies); + + $saved = Notice::saveNew($user->id, + $content, + 'web', + $options); + + if (!empty($saved)) { + $nb = new Notice_bookmark(); + $nb->notice_id = $saved->id; + $nb->title = $title; + $nb->description = $description; + $nb->insert(); + } + + return $saved; + } }