gnu-social/plugins/OStatus/actions/peopletagsalmon.php
Mikael Nordfeldth 2a4dc77a63 The overloaded DB_DataObject function staticGet is now called getKV
I used this hacky sed-command (run it from your GNU Social root, or change the first grep's path to where it actually lies) to do a rough fix on all ::staticGet calls and rename them to ::getKV

   sed -i -s -e '/DataObject::staticGet/I!s/::staticGet/::getKV/Ig' $(grep -R ::staticGet `pwd`/* | grep -v -e '^extlib' | grep -v DataObject:: |grep -v "function staticGet"|cut -d: -f1 |sort |uniq)

If you're applying this, remember to change the Managed_DataObject and Memcached_DataObject function definitions of staticGet to getKV!

This might of course take some getting used to, or modification fo StatusNet plugins, but the result is that all the static calls (to staticGet) are now properly made without breaking PHP Strict Standards. Standards are there to be followed (and they caused some very bad confusion when used with get_called_class)

Reasonably any plugin or code that tests for the definition of 'GNUSOCIAL' or similar will take this change into consideration.
2013-08-18 13:13:56 +02:00

151 lines
5.2 KiB
PHP

<?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
*/
if (!defined('STATUSNET')) {
exit(1);
}
class PeopletagsalmonAction extends SalmonAction
{
var $peopletag = null;
function prepare($args)
{
parent::prepare($args);
$id = $this->trimmed('id');
if (!$id) {
// TRANS: Client error displayed trying to perform an action without providing an ID.
$this->clientError(_m('No ID.'));
}
$this->peopletag = Profile_list::getKV('id', $id);
if (empty($this->peopletag)) {
// TRANS: Client error displayed when referring to a non-existing list.
$this->clientError(_m('No such list.'));
}
$oprofile = Ostatus_profile::getKV('peopletag_id', $id);
if (!empty($oprofile)) {
// TRANS: Client error displayed when trying to send a message to a remote list.
$this->clientError(_m('Cannot accept remote posts for a remote list.'));
}
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()
{
$oprofile = $this->ensureProfile();
if (!$oprofile) {
// TRANS: Client error displayed when referring to a non-existing remote list.
$this->clientError(_m('Cannot read profile to set up list subscription.'));
}
if ($oprofile->isGroup()) {
// TRANS: Client error displayed when trying to subscribe a group to a list.
$this->clientError(_m('Groups cannot subscribe to lists.'));
}
common_log(LOG_INFO, "Remote profile {$oprofile->uri} subscribing to local peopletag ".$this->peopletag->getBestName());
$profile = $oprofile->localProfile();
if ($this->peopletag->hasSubscriber($profile)) {
// 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 {
Profile_tag_subscription::add($this->peopletag, $profile);
} catch (Exception $e) {
// 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.
$this->serverError(sprintf(_m('Could not subscribe remote user %1$s to list %2$s.'),
$oprofile->uri, $this->peopletag->getBestName()));
}
}
/**
* A remote user unsubscribed from our list.
*/
function handleUnsubscribe()
{
$oprofile = $this->ensureProfile();
if (!$oprofile) {
// TRANS: Client error displayed when trying to unsubscribe from non-existing list.
$this->clientError(_m('Cannot read profile to cancel list subscription.'));
}
if ($oprofile->isGroup()) {
// TRANS: Client error displayed when trying to unsubscribe a group from a list.
$this->clientError(_m('Groups cannot subscribe to lists.'));
}
common_log(LOG_INFO, "Remote profile {$oprofile->uri} unsubscribing from local peopletag ".$this->peopletag->getBestName());
$profile = $oprofile->localProfile();
try {
Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id);
} catch (Exception $e) {
// 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.'),
$oprofile->uri, $this->peopletag->getBestName()));
return;
}
}
}