Notice_bookmark::saveNew() takes a Profile argument
This commit is contained in:
		@@ -119,13 +119,13 @@ class Notice_bookmark extends Memcached_DataObject
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Get the bookmark that a user made for an URL
 | 
					     * Get the bookmark that a user made for an URL
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param User   $user User to check for
 | 
					     * @param Profile $profile Profile to check for
 | 
				
			||||||
     * @param string $url  URL to check for
 | 
					     * @param string  $url     URL to check for
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return Notice_bookmark bookmark found or null
 | 
					     * @return Notice_bookmark bookmark found or null
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
     
 | 
					     
 | 
				
			||||||
    static function getByURL($user, $url)
 | 
					    static function getByURL($profile, $url)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $file = File::staticGet('url', $url);
 | 
					        $file = File::staticGet('url', $url);
 | 
				
			||||||
        if (!empty($file)) {
 | 
					        if (!empty($file)) {
 | 
				
			||||||
@@ -136,7 +136,7 @@ class Notice_bookmark extends Memcached_DataObject
 | 
				
			|||||||
                while ($f2p->fetch()) {
 | 
					                while ($f2p->fetch()) {
 | 
				
			||||||
                    $n = Notice::staticGet('id', $f2p->post_id);
 | 
					                    $n = Notice::staticGet('id', $f2p->post_id);
 | 
				
			||||||
                    if (!empty($n)) {
 | 
					                    if (!empty($n)) {
 | 
				
			||||||
                        if ($n->profile_id == $user->id) {
 | 
					                        if ($n->profile_id == $profile->id) {
 | 
				
			||||||
                            $nb = Notice_bookmark::staticGet('notice_id', $n->id);
 | 
					                            $nb = Notice_bookmark::staticGet('notice_id', $n->id);
 | 
				
			||||||
                            if (!empty($nb)) {
 | 
					                            if (!empty($nb)) {
 | 
				
			||||||
                                return $nb;
 | 
					                                return $nb;
 | 
				
			||||||
@@ -152,20 +152,20 @@ class Notice_bookmark extends Memcached_DataObject
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Save a new notice bookmark
 | 
					     * Save a new notice bookmark
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param User   $user        To save the bookmark for
 | 
					     * @param Profile $profile     To save the bookmark for
 | 
				
			||||||
     * @param string $title       Title of the bookmark
 | 
					     * @param string  $title       Title of the bookmark
 | 
				
			||||||
     * @param string $url         URL of the bookmark
 | 
					     * @param string  $url         URL of the bookmark
 | 
				
			||||||
     * @param mixed  $rawtags     array of tags or string
 | 
					     * @param mixed   $rawtags     array of tags or string
 | 
				
			||||||
     * @param string $description Description of the bookmark
 | 
					     * @param string  $description Description of the bookmark
 | 
				
			||||||
     * @param array  $options     Options for the Notice::saveNew()
 | 
					     * @param array   $options     Options for the Notice::saveNew()
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return Notice saved notice
 | 
					     * @return Notice saved notice
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static function saveNew($user, $title, $url, $rawtags, $description,
 | 
					    static function saveNew($profile, $title, $url, $rawtags, $description,
 | 
				
			||||||
                            $options=null)
 | 
					                            $options=null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $nb = self::getByURL($user, $url);
 | 
					        $nb = self::getByURL($profile, $url);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!empty($nb)) {
 | 
					        if (!empty($nb)) {
 | 
				
			||||||
            throw new ClientException(_('Bookmark already exists.'));
 | 
					            throw new ClientException(_('Bookmark already exists.'));
 | 
				
			||||||
@@ -187,7 +187,7 @@ class Notice_bookmark extends Memcached_DataObject
 | 
				
			|||||||
        foreach ($rawtags as $tag) {
 | 
					        foreach ($rawtags as $tag) {
 | 
				
			||||||
            if (strtolower(mb_substr($tag, 0, 4)) == 'for:') {
 | 
					            if (strtolower(mb_substr($tag, 0, 4)) == 'for:') {
 | 
				
			||||||
                $nickname = mb_substr($tag, 4);
 | 
					                $nickname = mb_substr($tag, 4);
 | 
				
			||||||
                $other    = common_relative_profile($user->getProfile(),
 | 
					                $other    = common_relative_profile($profile,
 | 
				
			||||||
                                                    $nickname);
 | 
					                                                    $nickname);
 | 
				
			||||||
                if (!empty($other)) {
 | 
					                if (!empty($other)) {
 | 
				
			||||||
                    $replies[] = $other->getUri();
 | 
					                    $replies[] = $other->getUri();
 | 
				
			||||||
@@ -208,9 +208,16 @@ class Notice_bookmark extends Memcached_DataObject
 | 
				
			|||||||
            $taglinks[] = XMLStringer::estring('a', $attrs, $tag);
 | 
					            $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'),
 | 
					        $content = sprintf(_('"%s" %s %s %s'),
 | 
				
			||||||
                           $title,
 | 
					                           $title,
 | 
				
			||||||
                           File_redirection::makeShort($url, $user),
 | 
					                           $shortUrl,
 | 
				
			||||||
                           $description,
 | 
					                           $description,
 | 
				
			||||||
                           implode(' ', $hashtags));
 | 
					                           implode(' ', $hashtags));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -229,7 +236,7 @@ class Notice_bookmark extends Memcached_DataObject
 | 
				
			|||||||
                                               'tags' => $tags,
 | 
					                                               'tags' => $tags,
 | 
				
			||||||
                                               'replies' => $replies));
 | 
					                                               'replies' => $replies));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $saved = Notice::saveNew($user->id,
 | 
					        $saved = Notice::saveNew($profile->id,
 | 
				
			||||||
                                 $content,
 | 
					                                 $content,
 | 
				
			||||||
                                 'web',
 | 
					                                 'web',
 | 
				
			||||||
                                 $options);
 | 
					                                 $options);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -96,7 +96,7 @@ class DeliciousBookmarkImporter extends QueueHandler
 | 
				
			|||||||
        $addDate = $a->getAttribute('add_date');
 | 
					        $addDate = $a->getAttribute('add_date');
 | 
				
			||||||
        $created = common_sql_date(intval($addDate));
 | 
					        $created = common_sql_date(intval($addDate));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $saved = Notice_bookmark::saveNew($user,
 | 
					        $saved = Notice_bookmark::saveNew($user->getProfile(),
 | 
				
			||||||
                                          $title,
 | 
					                                          $title,
 | 
				
			||||||
                                          $url,
 | 
					                                          $url,
 | 
				
			||||||
                                          $tags,
 | 
					                                          $tags,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -135,7 +135,7 @@ class NewbookmarkAction extends Action
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $saved = Notice_bookmark::saveNew($this->user,
 | 
					            $saved = Notice_bookmark::saveNew($this->user->getProfile(),
 | 
				
			||||||
                                              $this->title,
 | 
					                                              $this->title,
 | 
				
			||||||
                                              $this->url,
 | 
					                                              $this->url,
 | 
				
			||||||
                                              $this->tags,
 | 
					                                              $this->tags,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user