]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
don't reinsert existing bookmark
authorEvan Prodromou <evan@status.net>
Mon, 20 Dec 2010 18:38:24 +0000 (13:38 -0500)
committerEvan Prodromou <evan@status.net>
Mon, 20 Dec 2010 18:38:24 +0000 (13:38 -0500)
plugins/Bookmark/Notice_bookmark.php

index 679064dbe9f03d6588bc8035e8cf101ec4185a79..e816c45596cc5e8adc3c37d32506a82a235e6b0d 100644 (file)
@@ -116,8 +116,37 @@ class Notice_bookmark extends Memcached_DataObject
         return array(false, false, false);
     }
 
+       static function getByURL($user, $url)
+       {
+               $file = File::staticGet('url', $url);
+               if (!empty($file)) {
+                       $f2p = new File_to_post();
+                       $f2p->file_id = $file->id;
+                       if ($f2p->find()) {
+                               while ($f2p->fetch()) {
+                                       $n = Notice::staticGet('id', $f2p->post_id);
+                                       if (!empty($n)) {
+                                               if ($n->profile_id == $user->id) {
+                                                       $nb = Notice_bookmark::staticGet('notice_id', $n->id);
+                                                       if (!empty($nb)) {
+                                                               return $nb;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return null;
+       }
+
        static function saveNew($user, $title, $url, $rawtags, $description, $options=null)
        {
+               $nb = self::getByURL($user, $url);
+
+               if (!empty($nb)) {
+                       throw new ClientException(_('Bookmark already exists.'));
+               }
+
                if (empty($options)) {
                        $options = array();
                }