Example #1
0
 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $profile = AnonymousFavePlugin::getAnonProfile();
     if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
         // TRANS: Client error.
         $this->clientError(_m('Could not favor notice! Please make sure your browser has cookies enabled.'));
     }
     $id = $this->trimmed('notice');
     $notice = Notice::getKV($id);
     $token = $this->checkSessionToken();
     // Throws exception
     $stored = Fave::addNew($profile, $notice);
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title.
         $this->element('title', null, _m('Disfavor favorite'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new AnonDisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->endHTML();
     } else {
         $this->returnToPrevious();
     }
 }
Example #2
0
 function handle($channel)
 {
     $notice = $this->getNotice($this->other);
     try {
         $fave = Fave::addNew($this->user->getProfile(), $notice);
     } catch (Exception $e) {
         $channel->error($this->user, $e->getMessage());
         return;
     }
     // TRANS: Text shown when a notice has been marked as favourite successfully.
     $channel->output($this->user, _('Notice marked as fave.'));
 }
Example #3
0
 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     if ($user->hasFave($notice)) {
         // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
         $this->clientError(_('This notice is already a favorite!'));
         return;
     }
     $fave = Fave::addNew($user->getProfile(), $notice);
     if (!$fave) {
         // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
         $this->serverError(_('Could not create favorite.'));
         return;
     }
     $this->notify($notice, $user);
     $user->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title for page on which favorite notices can be unfavourited.
         $this->element('title', null, _('Disfavor favorite.'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new DisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)), 303);
     }
 }
Example #4
0
 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $profile = AnonymousFavePlugin::getAnonProfile();
     if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
         // TRANS: Client error.
         $this->clientError(_m('Could not favor notice! Please make sure your browser has cookies enabled.'));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error.
         $this->clientError(_m('There was a problem with your session token. Try again, please.'));
         return;
     }
     if ($profile->hasFave($notice)) {
         // TRANS: Client error.
         $this->clientError(_m('This notice is already a favorite!'));
         return;
     }
     $fave = Fave::addNew($profile, $notice);
     if (!$fave) {
         // TRANS: Server error.
         $this->serverError(_m('Could not create favorite.'));
         return;
     }
     $profile->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title.
         $this->element('title', null, _m('Disfavor favorite'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new AnonDisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         $this->returnToPrevious();
     }
 }
Example #5
0
 /**
  * Class handler.
  * 
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         $this->clientError(_("There was a problem with your session token. Try again, please."));
         return;
     }
     if ($user->hasFave($notice)) {
         $this->clientError(_('This notice is already a favorite!'));
         return;
     }
     $fave = Fave::addNew($user, $notice);
     if (!$fave) {
         $this->serverError(_('Could not create favorite.'));
         return;
     }
     $this->notify($notice, $user);
     $user->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         $this->element('title', null, _('Disfavor favorite'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new DisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
     }
 }
 protected function handle()
 {
     parent::handle();
     if (!in_array($this->format, array('xml', 'json'))) {
         $this->clientError(_('API method not found.'), 404, $this->format);
     }
     if (empty($this->notice)) {
         $this->clientError(_('No status found with that ID.'), 404, $this->format);
     }
     try {
         $stored = Fave::addNew($this->scoped, $this->notice);
     } catch (AlreadyFulfilledException $e) {
         // Note: Twitter lets you fave things repeatedly via API.
         $this->clientError($e->getMessage(), 403);
     }
     if ($this->format == 'xml') {
         $this->showSingleXmlStatus($this->notice);
     } elseif ($this->format == 'json') {
         $this->show_single_json_status($this->notice);
     }
 }
Example #7
0
 function execute($channel)
 {
     $recipient = common_relative_profile($this->user, common_canonical_nickname($this->other));
     if (!$recipient) {
         $channel->error($this->user, _('No such user.'));
         return;
     }
     $notice = $recipient->getCurrentNotice();
     if (!$notice) {
         $channel->error($this->user, _('User has no last notice'));
         return;
     }
     $fave = Fave::addNew($this->user, $notice);
     if (!$fave) {
         $channel->error($this->user, _('Could not create favorite.'));
         return;
     }
     $other = User::staticGet('id', $recipient->id);
     if ($other && $other->id != $user->id) {
         if ($other->email && $other->emailnotifyfav) {
             mail_notify_fave($other, $this->user, $notice);
         }
     }
     $this->user->blowFavesCache();
     $channel->output($this->user, _('Notice marked as fave.'));
 }
 protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
 {
     switch (true) {
         case ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
             Fave::addNew($scoped, $target);
             break;
         case ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)):
             Fave::removeEntry($scoped, $target);
             break;
         default:
             throw new ServerException('ActivityVerb POST not handled by plugin that was supposed to do it.');
     }
     return false;
 }
 function handle($channel)
 {
     $notice = $this->getNotice($this->other);
     $fave = Fave::addNew($this->user->getProfile(), $notice);
     if (!$fave) {
         $channel->error($this->user, _('Could not create favorite.'));
         return;
     }
     // @fixme favorite notification should be triggered
     // at a lower level
     $other = User::staticGet('id', $notice->profile_id);
     if ($other && $other->id != $user->id) {
         if ($other->email && $other->emailnotifyfav) {
             mail_notify_fave($other, $this->user, $notice);
         }
     }
     $this->user->blowFavesCache();
     $channel->output($this->user, _('Notice marked as fave.'));
 }
Example #10
0
 /**
  * Load or create an imported notice from Yammer data.
  *
  * @param object $item loaded JSON data for Yammer importer
  * @return Notice
  */
 function importNotice($item)
 {
     $data = $this->prepNotice($item);
     $noticeId = $this->findImportedNotice($data['orig_id']);
     if ($noticeId) {
         return Notice::staticGet('id', $noticeId);
     } else {
         $notice = Notice::staticGet('uri', $data['options']['uri']);
         $content = $data['content'];
         $user = User::staticGet($data['profile']);
         // Fetch file attachments and add the URLs...
         $uploads = array();
         foreach ($data['attachments'] as $url) {
             try {
                 $upload = $this->saveAttachment($url, $user);
                 $content .= ' ' . $upload->shortUrl();
                 $uploads[] = $upload;
             } catch (Exception $e) {
                 common_log(LOG_ERR, "Error importing Yammer attachment: " . $e->getMessage());
             }
         }
         // Here's the meat! Actually save the dang ol' notice.
         $notice = Notice::saveNew($user->id, $content, $data['source'], $data['options']);
         // Save "likes" as favorites...
         foreach ($data['faves'] as $nickname) {
             $user = User::staticGet('nickname', $nickname);
             if ($user) {
                 Fave::addNew($user->getProfile(), $notice);
             }
         }
         // And finally attach the upload records...
         foreach ($uploads as $upload) {
             $upload->attachToNotice($notice);
         }
         $this->recordImportedNotice($data['orig_id'], $notice->id);
         return $notice;
     }
 }
Example #11
0
 function handle($channel)
 {
     $notice = $this->getNotice($this->other);
     $fave = Fave::addNew($this->user->getProfile(), $notice);
     if (!$fave) {
         // TRANS: Error message text shown when a favorite could not be set.
         $channel->error($this->user, _('Could not create favorite.'));
         return;
     }
     // @fixme favorite notification should be triggered
     // at a lower level
     $other = User::staticGet('id', $notice->profile_id);
     if ($other && $other->id != $user->id) {
         if ($other->email && $other->emailnotifyfav) {
             mail_notify_fave($other, $this->user, $notice);
         }
     }
     $this->user->blowFavesCache();
     // TRANS: Text shown when a notice has been marked as favourite successfully.
     $channel->output($this->user, _('Notice marked as fave.'));
 }
 /**
  * add a new favorite
  *
  * @return void
  */
 function addFavorite()
 {
     // XXX: Refactor this; all the same for atompub
     if (empty($this->auth_user) || $this->auth_user->id != $this->_profile->id) {
         // TRANS: Client exception thrown when trying to set a favorite for another user.
         throw new ClientException(_("Cannot add someone else's" . " subscription."), 403);
     }
     $xml = file_get_contents('php://input');
     $dom = DOMDocument::loadXML($xml);
     if ($dom->documentElement->namespaceURI != Activity::ATOM || $dom->documentElement->localName != 'entry') {
         // TRANS: Client error displayed when not using an Atom entry.
         throw new ClientException(_('Atom post must be an Atom entry.'));
         return;
     }
     $activity = new Activity($dom->documentElement);
     $fave = null;
     if (Event::handle('StartAtomPubNewActivity', array(&$activity))) {
         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::staticGet('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 note.'));
         }
         $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 (!empty($fave)) {
             $this->_profile->blowFavesCache();
             $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);
         $this->startXML();
         $this->raw($act->asString(true, true, true));
         $this->endXML();
     }
 }
Example #13
0
 /**
  * Handle the request
  *
  * Check the format and show the user info
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_('This method requires a POST.'), 400, $this->format);
         return;
     }
     if (!in_array($this->format, array('xml', 'json'))) {
         $this->clientError(_('API method not found.'), 404, $this->format);
         return;
     }
     if (empty($this->notice)) {
         $this->clientError(_('No status found with that ID.'), 404, $this->format);
         return;
     }
     // Note: Twitter lets you fave things repeatedly via API.
     if ($this->user->hasFave($this->notice)) {
         $this->clientError(_('This status is already a favorite.'), 403, $this->format);
         return;
     }
     $fave = Fave::addNew($this->user->getProfile(), $this->notice);
     if (empty($fave)) {
         $this->clientError(_('Could not create favorite.'), 403, $this->format);
         return;
     }
     $this->notify($fave, $this->notice, $this->user);
     $this->user->blowFavesCache();
     if ($this->format == 'xml') {
         $this->showSingleXmlStatus($this->notice);
     } elseif ($this->format == 'json') {
         $this->show_single_json_status($this->notice);
     }
 }
Example #14
0
 /**
  * Remote user likes one of our posts.
  * Confirm the post is ours, and save a local favorite event.
  */
 function handleFavorite()
 {
     $notice = $this->getNotice($this->act->objects[0]);
     $profile = $this->ensureProfile()->localProfile();
     $old = Fave::pkeyGet(array('user_id' => $profile->id, 'notice_id' => $notice->id));
     if (!empty($old)) {
         throw new ClientException("We already know that's a fave!");
     }
     if (!Fave::addNew($profile, $notice)) {
         throw new ClientException("Could not save new favorite.");
     }
 }
Example #15
0
 function create($args, $apidata)
 {
     parent::handle($args);
     // Check for RESTfulness
     if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
         // XXX: Twitter just prints the err msg, no XML / JSON.
         $this->clientError(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
         return;
     }
     if (!in_array($apidata['content-type'], array('xml', 'json'))) {
         $this->clientError(_('API method not found!'), $code = 404);
         return;
     }
     $this->auth_user = $apidata['user'];
     $user = $this->auth_user;
     $notice_id = $apidata['api_arg'];
     $notice = Notice::staticGet($notice_id);
     if (!$notice) {
         $this->clientError(_('No status found with that ID.'), 404, $apidata['content-type']);
         return;
     }
     // XXX: Twitter lets you fave things repeatedly via api.
     if ($user->hasFave($notice)) {
         $this->clientError(_('This notice is already a favorite!'), 403, $apidata['content-type']);
         return;
     }
     $fave = Fave::addNew($user, $notice);
     if (!$fave) {
         $this->serverError(_('Could not create favorite.'));
         return;
     }
     $this->notify($fave, $notice, $user);
     $user->blowFavesCache();
     if ($apidata['content-type'] == 'xml') {
         $this->show_single_xml_status($notice);
     } elseif ($apidata['content-type'] == 'json') {
         $this->show_single_json_status($notice);
     }
 }
 public function testNoticeInfoFave()
 {
     $notice = $this->_fakeNotice();
     $fave = Fave::addNew($this->author2->getProfile(), $notice);
     // Should be set if user has faved
     $entry = $notice->asAtomEntry(false, false, false, $this->author2);
     $element = $this->_entryToElement($entry, true);
     $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
     $this->assertEquals('true', $noticeInfo->getAttribute('favorite'));
     // Shouldn't be set if user has not faved
     $entry = $notice->asAtomEntry(false, false, false, $this->targetUser1);
     $element = $this->_entryToElement($entry, true);
     $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
     $this->assertEquals('false', $noticeInfo->getAttribute('favorite'));
 }
Example #17
0
 /**
  * Remote user likes one of our posts.
  * Confirm the post is ours, and save a local favorite event.
  */
 function handleFavorite()
 {
     $notice = $this->getNotice($this->activity->objects[0]);
     $profile = $this->ensureProfile()->localProfile();
     $old = Fave::pkeyGet(array('user_id' => $profile->id, 'notice_id' => $notice->id));
     if (!empty($old)) {
         // TRANS: Client exception.
         throw new ClientException(_('This is already a favorite.'));
     }
     if (!Fave::addNew($profile, $notice)) {
         // TRANS: Client exception.
         throw new ClientException(_m('Could not save new favorite.'));
     }
 }