]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Notice_bookmark::saveNew() takes a Profile argument
authorEvan Prodromou <evan@status.net>
Wed, 22 Dec 2010 17:35:45 +0000 (12:35 -0500)
committerEvan Prodromou <evan@status.net>
Wed, 22 Dec 2010 17:35:45 +0000 (12:35 -0500)
plugins/Bookmark/Notice_bookmark.php
plugins/Bookmark/deliciousbookmarkimporter.php
plugins/Bookmark/newbookmark.php

index 622c641ede29a6168ba5b4518d218ffcfb70aba7..38e2890abe5a1ef7c4bacdd2ca87f007d4cb0e37 100644 (file)
@@ -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);
index 686e1a39c001234d7cc426afe996738b2f6c2f1c..22ad45882e27abc23793991922120e3557a379d3 100644 (file)
@@ -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,
index 94d8f3f4f002cf06a5b5bd3a1ba1a0b76d25cdf5..63944c817659cef3624755e48e9a014dbddee524 100644 (file)
@@ -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,