/** * Handle the data * * @param array $data associative array of user & bookmark info from DeliciousBackupImporter::importBookmark() * * @return boolean success value */ function handle($data) { $profile = Profile::staticGet('id', $data['profile_id']); try { $saved = Bookmark::saveNew($profile, $data['title'], $data['url'], $data['tags'], $data['description'], array('created' => $data['created'], 'distribute' => false)); } catch (ClientException $e) { // Most likely a duplicate -- continue on with the rest! common_log(LOG_ERR, "Error importing delicious bookmark to {$data['url']}: " . $e->getMessage()); return true; } return true; }
/** * Handle the data * * @param array $data associative array of user & bookmark info from DeliciousBackupImporter::importBookmark() * * @return boolean success value */ function handle($data) { $profile = Profile::getKV('id', $data['profile_id']); try { $saved = Bookmark::saveNew($profile, $data['title'], $data['url'], $data['tags'], $data['description'], array('created' => $data['created'], 'distribute' => false)); } catch (ClientException $ce) { // Most likely a duplicate -- continue on with the rest! common_log(LOG_ERR, "Error importing delicious bookmark to {$data['url']}: " . $ce->getMessage()); return true; } catch (Exception $ex) { if (preg_match("/DB Error: already exists/", $ex->getMessage())) { common_log(LOG_ERR, "Error importing delicious bookmark to {$data['url']}: " . $ce->getMessage()); return true; } else { throw $ex; } } return true; }
/** * Save a bookmark from an activity * * @param Activity $activity Activity to save * @param Profile $actor Profile to use as author * @param array $options Options to pass to bookmark-saving code * * @return Notice resulting notice */ function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options = array()) { $bookmark = $activity->objects[0]; $relLinkEls = ActivityUtils::getLinks($bookmark->element, 'related'); if (count($relLinkEls) < 1) { // TRANS: Client exception thrown when a bookmark is formatted incorrectly. throw new ClientException(_m('Expected exactly 1 link ' . 'rel=related in a Bookmark.')); } if (count($relLinkEls) > 1) { common_log(LOG_WARNING, "Got too many link rel=related in a Bookmark."); } $linkEl = $relLinkEls[0]; $url = $linkEl->getAttribute('href'); $tags = array(); foreach ($activity->categories as $category) { $tags[] = common_canonical_tag($category->term); } if (!empty($activity->time)) { $options['created'] = common_sql_date($activity->time); } // Fill in location if available $location = $activity->context->location; if ($location) { $options['lat'] = $location->lat; $options['lon'] = $location->lon; if ($location->location_id) { $options['location_ns'] = $location->location_ns; $options['location_id'] = $location->location_id; } } $options['groups'] = array(); $options['replies'] = array(); // TODO: context->attention foreach ($activity->context->attention as $attnUrl => $type) { try { $other = Profile::fromUri($attnUrl); if ($other->isGroup()) { $options['groups'][] = $other->id; } else { $options['replies'][] = $attnUrl; } } catch (UnknownUriException $e) { // We simply don't know this URI, despite lookup attempts. } } // Maintain direct reply associations // @fixme what about conversation ID? if (!empty($activity->context->replyToID)) { $orig = Notice::getKV('uri', $activity->context->replyToID); if (!empty($orig)) { $options['reply_to'] = $orig->id; } } return Bookmark::saveNew($actor, $bookmark->title, $url, $tags, $bookmark->summary, $options); }
/** * Save a bookmark from an activity * * @param Activity $activity Activity to save * @param Profile $profile Profile to use as author * @param array $options Options to pass to bookmark-saving code * * @return Notice resulting notice */ function saveNoticeFromActivity($activity, $profile, $options = array()) { $bookmark = $activity->objects[0]; $relLinkEls = ActivityUtils::getLinks($bookmark->element, 'related'); if (count($relLinkEls) < 1) { // TRANS: Client exception thrown when a bookmark is formatted incorrectly. throw new ClientException(_m('Expected exactly 1 link ' . 'rel=related in a Bookmark.')); } if (count($relLinkEls) > 1) { common_log(LOG_WARNING, "Got too many link rel=related in a Bookmark."); } $linkEl = $relLinkEls[0]; $url = $linkEl->getAttribute('href'); $tags = array(); foreach ($activity->categories as $category) { $tags[] = common_canonical_tag($category->term); } if (!empty($activity->time)) { $options['created'] = common_sql_date($activity->time); } // Fill in location if available $location = $activity->context->location; if ($location) { $options['lat'] = $location->lat; $options['lon'] = $location->lon; if ($location->location_id) { $options['location_ns'] = $location->location_ns; $options['location_id'] = $location->location_id; } } $replies = $activity->context->attention; $options['groups'] = array(); $options['replies'] = array(); foreach ($replies as $replyURI) { $other = Profile::fromURI($replyURI); if (!empty($other)) { $options['replies'][] = $replyURI; } else { $group = User_group::staticGet('uri', $replyURI); if (!empty($group)) { $options['groups'][] = $replyURI; } } } // Maintain direct reply associations // @fixme what about conversation ID? if (!empty($activity->context->replyToID)) { $orig = Notice::staticGet('uri', $activity->context->replyToID); if (!empty($orig)) { $options['reply_to'] = $orig->id; } } return Bookmark::saveNew($profile, $bookmark->title, $url, $tags, $bookmark->summary, $options); }
/** * Add a new bookmark * * @return void */ function newBookmark() { try { if (empty($this->title)) { // TRANS: Client exception thrown when trying to create a new bookmark without a title. throw new ClientException(_m('Bookmark must have a title.')); } if (empty($this->url)) { // TRANS: Client exception thrown when trying to create a new bookmark without a URL. throw new ClientException(_m('Bookmark must have an URL.')); } $options = array(); ToSelector::fillOptions($this, $options); $saved = Bookmark::saveNew($this->user->getProfile(), $this->title, $this->url, $this->tags, $this->description, $options); } catch (ClientException $ce) { if ($this->boolean('ajax')) { throw $ce; } else { $this->error = $ce->getMessage(); $this->showPage(); return; } } if ($this->boolean('ajax')) { header('Content-Type: text/xml;charset=utf-8'); $this->xw->startDocument('1.0', 'UTF-8'); $this->elementStart('html'); $this->elementStart('head'); // TRANS: Page title after posting a bookmark. $this->element('title', null, _m('Bookmark posted')); $this->elementEnd('head'); $this->elementStart('body'); $this->showNotice($saved); $this->elementEnd('body'); $this->elementEnd('html'); } else { common_redirect($saved->bestUrl(), 303); } }
/** * Add a new bookmark * * @return void */ function newBookmark() { try { if (empty($this->title)) { throw new ClientException(_('Bookmark must have a title.')); } if (empty($this->url)) { throw new ClientException(_('Bookmark must have an URL.')); } $saved = Bookmark::saveNew($this->user->getProfile(), $this->title, $this->url, $this->tags, $this->description); } catch (ClientException $ce) { $this->error = $ce->getMessage(); $this->showPage(); return; } common_redirect($saved->bestUrl(), 303); }