2011-03-07 04:15:34 +09:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2010, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package OStatusPlugin
|
|
|
|
*/
|
|
|
|
|
2015-01-13 21:43:18 +09:00
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
2011-03-07 04:15:34 +09:00
|
|
|
|
|
|
|
class PeopletagsalmonAction extends SalmonAction
|
|
|
|
{
|
|
|
|
var $peopletag = null;
|
|
|
|
|
2015-01-13 21:43:18 +09:00
|
|
|
protected function prepare(array $args=array())
|
2011-03-07 04:15:34 +09:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
$id = $this->trimmed('id');
|
|
|
|
|
|
|
|
if (!$id) {
|
2011-04-30 01:59:47 +09:00
|
|
|
// TRANS: Client error displayed trying to perform an action without providing an ID.
|
2011-04-11 07:39:27 +09:00
|
|
|
$this->clientError(_m('No ID.'));
|
2011-03-07 04:15:34 +09:00
|
|
|
}
|
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$this->peopletag = Profile_list::getKV('id', $id);
|
2011-03-07 04:15:34 +09:00
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
if (!$this->peopletag instanceof Profile_list) {
|
2011-04-30 01:59:47 +09:00
|
|
|
// TRANS: Client error displayed when referring to a non-existing list.
|
2011-04-13 17:15:25 +09:00
|
|
|
$this->clientError(_m('No such list.'));
|
2011-03-07 04:15:34 +09:00
|
|
|
}
|
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
$this->target = $this->peopletag;
|
2011-03-07 04:15:34 +09:00
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
$remote_list = Ostatus_profile::getKV('peopletag_id', $id);
|
|
|
|
|
|
|
|
if ($remote_list instanceof Ostatus_profile) {
|
2011-04-30 01:59:47 +09:00
|
|
|
// TRANS: Client error displayed when trying to send a message to a remote list.
|
2011-04-13 17:15:25 +09:00
|
|
|
$this->clientError(_m('Cannot accept remote posts for a remote list.'));
|
2011-03-07 04:15:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We've gotten a follow/subscribe notification from a remote user.
|
|
|
|
* Save a subscription relationship for them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Postel's law: consider a "follow" notification as a "join".
|
|
|
|
*/
|
|
|
|
function handleFollow()
|
|
|
|
{
|
|
|
|
$this->handleSubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Postel's law: consider an "unfollow" notification as a "unsubscribe".
|
|
|
|
*/
|
|
|
|
function handleUnfollow()
|
|
|
|
{
|
|
|
|
$this->handleUnsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A remote user subscribed.
|
|
|
|
* @fixme move permission checks and event call into common code,
|
|
|
|
* currently we're doing the main logic in joingroup action
|
|
|
|
* and so have to repeat it here.
|
|
|
|
*/
|
|
|
|
function handleSubscribe()
|
|
|
|
{
|
2014-06-29 03:33:09 +09:00
|
|
|
if ($this->oprofile->isGroup()) {
|
2011-04-30 01:59:47 +09:00
|
|
|
// TRANS: Client error displayed when trying to subscribe a group to a list.
|
2011-04-13 17:15:25 +09:00
|
|
|
$this->clientError(_m('Groups cannot subscribe to lists.'));
|
2011-03-07 04:15:34 +09:00
|
|
|
}
|
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
common_log(LOG_INFO, sprintf('Remote profile %s subscribing to local peopletag %s', $this->oprofile->getUri(), $this->peopletag->getBestName()));
|
|
|
|
if ($this->peopletag->hasSubscriber($this->actor)) {
|
2011-03-07 04:15:34 +09:00
|
|
|
// Already a member; we'll take it silently to aid in resolving
|
|
|
|
// inconsistencies on the other side.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// should we block those whom the tagger has blocked from listening to
|
|
|
|
// his own updates?
|
|
|
|
|
|
|
|
try {
|
2014-06-29 03:33:09 +09:00
|
|
|
Profile_tag_subscription::add($this->peopletag, $this->actor);
|
2011-03-07 04:15:34 +09:00
|
|
|
} catch (Exception $e) {
|
2011-04-30 01:59:47 +09:00
|
|
|
// TRANS: Server error displayed when subscribing a remote user to a list fails.
|
|
|
|
// TRANS: %1$s is a profile URI, %2$s is a list name.
|
2011-04-13 17:15:25 +09:00
|
|
|
$this->serverError(sprintf(_m('Could not subscribe remote user %1$s to list %2$s.'),
|
2014-06-29 03:33:09 +09:00
|
|
|
$this->oprofile->getUri(), $this->peopletag->getBestName()));
|
2011-03-07 04:15:34 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-30 01:59:47 +09:00
|
|
|
* A remote user unsubscribed from our list.
|
2014-05-20 01:07:38 +09:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @throws Exception through clientError and serverError
|
2011-03-07 04:15:34 +09:00
|
|
|
*/
|
|
|
|
function handleUnsubscribe()
|
|
|
|
{
|
2014-06-29 03:33:09 +09:00
|
|
|
if ($this->oprofile->isGroup()) {
|
2011-04-30 01:59:47 +09:00
|
|
|
// TRANS: Client error displayed when trying to unsubscribe a group from a list.
|
2011-04-13 17:15:25 +09:00
|
|
|
$this->clientError(_m('Groups cannot subscribe to lists.'));
|
2011-03-07 04:15:34 +09:00
|
|
|
}
|
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
common_log(LOG_INFO, sprintf('Remote profile %s unsubscribing from local peopletag %s', $this->oprofile->getUri(), $this->peopletag->getBestName()));
|
2011-03-07 04:15:34 +09:00
|
|
|
try {
|
2014-06-29 03:33:09 +09:00
|
|
|
Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $this->actor->id);
|
2011-03-07 04:15:34 +09:00
|
|
|
} catch (Exception $e) {
|
2011-04-30 01:59:47 +09:00
|
|
|
// TRANS: Client error displayed when trying to unsubscribe a remote user from a list fails.
|
|
|
|
// TRANS: %1$s is a profile URL, %2$s is a list name.
|
|
|
|
$this->serverError(sprintf(_m('Could not unsubscribe remote user %1$s from list %2$s.'),
|
2014-06-29 03:33:09 +09:00
|
|
|
$this->oprofile->getUri(), $this->peopletag->getBestName()));
|
2011-03-07 04:15:34 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|