From 73dccdd7f5760ff88955a2e67df53c987ca3a6a6 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 22 Dec 2010 12:35:45 -0500 Subject: [PATCH] Notice_bookmark::saveNew() takes a Profile argument --- plugins/Bookmark/Notice_bookmark.php | 37 +++++++++++-------- .../Bookmark/deliciousbookmarkimporter.php | 2 +- plugins/Bookmark/newbookmark.php | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/plugins/Bookmark/Notice_bookmark.php b/plugins/Bookmark/Notice_bookmark.php index 622c641ede..38e2890abe 100644 --- a/plugins/Bookmark/Notice_bookmark.php +++ b/plugins/Bookmark/Notice_bookmark.php @@ -119,13 +119,13 @@ class Notice_bookmark extends Memcached_DataObject /** * Get the bookmark that a user made for an URL * - * @param User $user User to check for - * @param string $url URL to check for + * @param Profile $profile Profile to check for + * @param string $url URL to check for * * @return Notice_bookmark bookmark found or null */ - static function getByURL($user, $url) + static function getByURL($profile, $url) { $file = File::staticGet('url', $url); if (!empty($file)) { @@ -136,7 +136,7 @@ class Notice_bookmark extends Memcached_DataObject while ($f2p->fetch()) { $n = Notice::staticGet('id', $f2p->post_id); if (!empty($n)) { - if ($n->profile_id == $user->id) { + if ($n->profile_id == $profile->id) { $nb = Notice_bookmark::staticGet('notice_id', $n->id); if (!empty($nb)) { return $nb; @@ -152,20 +152,20 @@ class Notice_bookmark extends Memcached_DataObject /** * Save a new notice bookmark * - * @param User $user To save the bookmark for - * @param string $title Title of the bookmark - * @param string $url URL of the bookmark - * @param mixed $rawtags array of tags or string - * @param string $description Description of the bookmark - * @param array $options Options for the Notice::saveNew() + * @param Profile $profile To save the bookmark for + * @param string $title Title of the bookmark + * @param string $url URL of the bookmark + * @param mixed $rawtags array of tags or string + * @param string $description Description of the bookmark + * @param array $options Options for the Notice::saveNew() * * @return Notice saved notice */ - static function saveNew($user, $title, $url, $rawtags, $description, + static function saveNew($profile, $title, $url, $rawtags, $description, $options=null) { - $nb = self::getByURL($user, $url); + $nb = self::getByURL($profile, $url); if (!empty($nb)) { throw new ClientException(_('Bookmark already exists.')); @@ -187,7 +187,7 @@ class Notice_bookmark extends Memcached_DataObject foreach ($rawtags as $tag) { if (strtolower(mb_substr($tag, 0, 4)) == 'for:') { $nickname = mb_substr($tag, 4); - $other = common_relative_profile($user->getProfile(), + $other = common_relative_profile($profile, $nickname); if (!empty($other)) { $replies[] = $other->getUri(); @@ -208,9 +208,16 @@ class Notice_bookmark extends Memcached_DataObject $taglinks[] = XMLStringer::estring('a', $attrs, $tag); } + // Use user's preferences for short URLs, if possible + + $user = User::staticGet('id', $profile->id); + + $shortUrl = File_redirection::makeShort($url, + empty($user) ? null : $user); + $content = sprintf(_('"%s" %s %s %s'), $title, - File_redirection::makeShort($url, $user), + $shortUrl, $description, implode(' ', $hashtags)); @@ -229,7 +236,7 @@ class Notice_bookmark extends Memcached_DataObject 'tags' => $tags, 'replies' => $replies)); - $saved = Notice::saveNew($user->id, + $saved = Notice::saveNew($profile->id, $content, 'web', $options); diff --git a/plugins/Bookmark/deliciousbookmarkimporter.php b/plugins/Bookmark/deliciousbookmarkimporter.php index 686e1a39c0..22ad45882e 100644 --- a/plugins/Bookmark/deliciousbookmarkimporter.php +++ b/plugins/Bookmark/deliciousbookmarkimporter.php @@ -96,7 +96,7 @@ class DeliciousBookmarkImporter extends QueueHandler $addDate = $a->getAttribute('add_date'); $created = common_sql_date(intval($addDate)); - $saved = Notice_bookmark::saveNew($user, + $saved = Notice_bookmark::saveNew($user->getProfile(), $title, $url, $tags, diff --git a/plugins/Bookmark/newbookmark.php b/plugins/Bookmark/newbookmark.php index 94d8f3f4f0..63944c8176 100644 --- a/plugins/Bookmark/newbookmark.php +++ b/plugins/Bookmark/newbookmark.php @@ -135,7 +135,7 @@ class NewbookmarkAction extends Action } - $saved = Notice_bookmark::saveNew($this->user, + $saved = Notice_bookmark::saveNew($this->user->getProfile(), $this->title, $this->url, $this->tags,