From cee93dd15d4b922f98529ccfe1eba450e6647be2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 19 Dec 2010 10:17:23 -0500 Subject: [PATCH] Move notice bookmark creation to Notice_bookmark::saveNew() --- plugins/Bookmark/Notice_bookmark.php | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) 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; + } }