- if ($activity->verb != ActivityVerb::FAVORITE) {
- // TRANS: Client exception thrown when trying use an incorrect activity verb for the Atom pub method.
- throw new ClientException(_('Can only handle favorite activities.'));
- return;
- }
-
- $note = $activity->objects[0];
-
- if (!in_array($note->type, array(ActivityObject::NOTE,
- ActivityObject::BLOGENTRY,
- ActivityObject::STATUS))) {
- // TRANS: Client exception thrown when trying favorite an object that is not a notice.
- throw new ClientException(_('Can only fave notices.'));
- return;
- }
-
- $notice = Notice::getKV('uri', $note->id);
-
- if (empty($notice)) {
- // XXX: import from listed URL or something
- // TRANS: Client exception thrown when trying favorite a notice without content.
- throw new ClientException(_('Unknown notice.'));
- }
-
- $old = Fave::pkeyGet(array('user_id' => $this->auth_user->id,
- 'notice_id' => $notice->id));
-
- if (!empty($old)) {
- // TRANS: Client exception thrown when trying favorite an already favorited notice.
- throw new ClientException(_('Already a favorite.'));
- }
-
- $profile = $this->auth_user->getProfile();
-
- $fave = Fave::addNew($profile, $notice);
-
- if ($fave instanceof Fave) {
- Fave::blowCacheForProfileId($this->_profile->id);
- $this->notify($fave, $notice, $this->auth_user);
- }
-
- Event::handle('EndAtomPubNewActivity', array($activity, $fave));
- }
-
- if (!empty($fave)) {
- $act = $fave->asActivity();
-
- header('Content-Type: application/atom+xml; charset=utf-8');
- header('Content-Location: ' . $act->selfLink);