Commit 5afc231d by Maiyannah Bishop

Move activity classes from /lib/ to /classes/activity

1 parent 6eaffa36
<?php
/* ============================================================================
* Title: ActivityContext
* Class abstraction for Activity verb contexts
*
* postActiv:
* the micro-blogging software
*
* Copyright:
* Copyright (C) 2016, Maiyannah Bishop
*
* Derived from code copyright various sources:
* o GNU Social (C) 2013-2016, Free Software Foundation, Inc
* o StatusNet (C) 2008-2012, StatusNet, Inc
* ----------------------------------------------------------------------------
* License:
* 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/>.
*
* <https://www.gnu.org/licenses/agpl.html>
* ----------------------------------------------------------------------------
* About:
* An activity verb in class form, and the related scaffolding.
*
* This file also now consolidates the ActivityContext, ActivityImporter,
* ActivityMover, ActivitySink, and ActivitySource classes, formerly at
* /lib/<class>.php
*
* o Activity abstracts the class for an activity verb.
* o ActivityContext contains information of the context of the activity verb.
* o ActivityImporter abstracts a means that is importing activity verbs
* into the system as part of a user's timeline.
* o ActivityMover abstracts the means to transport activity verbs.
* o ActivitySink abstracts a class to receive activity verbs.
* o ActivitySource abstracts a class to represent the source of a received
* activity verb.
*
* ActivityObject is a noun in the activity universe basically, from
* the original file:
* A noun-ish thing in the activity universe
*
* The activity streams spec talks about activity objects, while also
* having a tag activity:object, which is in fact an activity object.
* Aaaaaah!
*
* This is just a thing in the activity universe. Can be the subject,
* object, or indirect object (target!) of an activity verb. Rotten
* name, and I'm propagating it. *sigh*
* It's large enough that I've left it seperate in activityobject.php
*
* PHP version:
* Tested with PHP 5.6
* ----------------------------------------------------------------------------
* File Authors:
* o Zach Copley
* o Brion Vibber <brion@pobox.com>
* o James Walker <walkah@walkah.net>
* o Evan Prodromou
* o Siebrand Mazeland <s.mazeland@xs4all.nl>
* o Mikael Nordfeldth <mmn@hethane.se>
* o Chimo <chimo@chromic.org>
* o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
*
* Web:
* o postActiv <http://www.postactiv.com>
* o GNU social <https://www.gnu.org/s/social/>
* ============================================================================
*/
// This file is formatted so that it provides useful documentation output in
// NaturalDocs. Please be considerate of this before changing formatting.
if (!defined('POSTACTIV')) { exit(1); }
// ----------------------------------------------------------------------------
// Class: ActivityContext
class ActivityContext
{
public $replyToID;
public $replyToUrl;
public $location;
public $attention = array(); // 'uri' => 'type'
public $conversation;
public $scope;
const THR = 'http://purl.org/syndication/thread/1.0';
const GEORSS = 'http://www.georss.org/georss';
const OSTATUS = 'http://ostatus.org/schema/1.0';
const INREPLYTO = 'in-reply-to';
const REF = 'ref';
const HREF = 'href';
// OStatus element names with prefixes
const OBJECTTYPE = 'ostatus:object-type'; // FIXME: Undocumented!
const CONVERSATION = 'ostatus:conversation';
const POINT = 'point';
const MENTIONED = 'mentioned';
const ATTN_PUBLIC = 'http://activityschema.org/collection/public';
// -------------------------------------------------------------------------
// Function: __construct
// Class constructor
function __construct($element = null)
{
if (empty($element)) {
return;
}
$replyToEl = ActivityUtils::child($element, self::INREPLYTO, self::THR);
if (!empty($replyToEl)) {
$this->replyToID = $replyToEl->getAttribute(self::REF);
$this->replyToUrl = $replyToEl->getAttribute(self::HREF);
}
$this->location = $this->getLocation($element);
$convs = $element->getElementsByTagNameNS(self::OSTATUS, self::CONVERSATION);
foreach ($convs as $conv) {
$this->conversation = $conv->textContent;
}
if (empty($this->conversation)) {
// fallback to the atom:link rel="ostatus:conversation" element
$this->conversation = ActivityUtils::getLink($element, self::CONVERSATION);
}
// Multiple attention links allowed
$links = $element->getElementsByTagNameNS(ActivityUtils::ATOM, ActivityUtils::LINK);
for ($i = 0; $i < $links->length; $i++) {
$link = $links->item($i);
$linkRel = $link->getAttribute(ActivityUtils::REL);
$linkHref = $link->getAttribute(self::HREF);
if ($linkRel == self::MENTIONED && $linkHref !== '') {
$this->attention[$linkHref] = $link->getAttribute(ActivityContext::OBJECTTYPE);
}
}
}
// -------------------------------------------------------------------------
// Function: getLocation
// Parse location given as a GeoRSS-simple point, if provided.
// http://www.georss.org/simple
//
// Parameters:
// o feed item $entry
//
// Returns:
// o mixed Location or false
function getLocation($dom) {
$points = $dom->getElementsByTagNameNS(self::GEORSS, self::POINT);
for ($i = 0; $i < $points->length; $i++) {
$point = $points->item($i)->textContent;
return self::locationFromPoint($point);
}
return null;
}
// -------------------------------------------------------------------------
// Function: locationFromPoint
// XXX: Move to ActivityUtils or Location?
//
// Parameters:
// o point
static function locationFromPoint($point) {
$point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
$point = preg_replace('/\s+/', ' ', $point);
$point = trim($point);
$coords = explode(' ', $point);
if (count($coords) == 2) {
list($lat, $lon) = $coords;
if (is_numeric($lat) && is_numeric($lon)) {
common_log(LOG_INFO, "Looking up location for $lat $lon from georss point");
return Location::fromLatLon($lat, $lon);
}
}
common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
return null;
}
// -------------------------------------------------------------------------
// Function: asArray
// Returns context (StatusNet stuff) as an array suitable for serializing
// in JSON. Right now context stuff is an extension to Activity.
//
// Returns:
// o array the context
function asArray() {
$context = array();
$context['inReplyTo'] = $this->getInReplyToArray();
$context['conversation'] = $this->conversation;
return array_filter($context);
}
// -------------------------------------------------------------------------
// Function: getToArray
// Returns an array of arrays representing Activity Objects (intended to be
// serialized in JSON) that represent WHO the Activity is supposed to
// be received by. This is not really specified but appears in an example
// of the current spec as an extension. We might want to figure out a JSON
// serialization for OStatus and use that to express mentions instead.
//
// XXX: People's ideas on how to do this are all over the place
//
// Returns:
// o array the array of recipients
function getToArray() {
$tos = array();
foreach ($this->attention as $attnUrl => $attnType) {
$to = array(
'objectType' => $attnType, // can be empty
'id' => $attnUrl,);
$tos[] = $to;
}
return $tos;
}
// -------------------------------------------------------------------------
// Function: getInReplyToArray
// Return an array for the notices this notice is a reply to
// suitable for serializing as JSON note objects.
//
// Returns:
// o array the array of notes
function getInReplyToArray() {
if (empty($this->replyToID) && empty($this->replyToUrl)) {
return null;
}
$replyToObj = array('objectType' => 'note');
// XXX: Possibly shorten this to just the numeric ID?
// Currently, it's the full URI of the notice.
if (!empty($this->replyToID)) {
$replyToObj['id'] = $this->replyToID;
}
if (!empty($this->replyToUrl)) {
$replyToObj['url'] = $this->replyToUrl;
}
return $replyToObj;
}
}
// END OF FILE
// ============================================================================
?>
\ No newline at end of file
<?php
/* ============================================================================
* Title: ActivityMover
* Queue handler for exporting (federating) Activities
*
* postActiv:
* the micro-blogging software
*
* Copyright:
* Copyright (C) 2016, Maiyannah Bishop
*
* Derived from code copyright various sources:
* o GNU Social (C) 2013-2016, Free Software Foundation, Inc
* o StatusNet (C) 2008-2012, StatusNet, Inc
* ----------------------------------------------------------------------------
* License:
* 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/>.
*
* <https://www.gnu.org/licenses/agpl.html>
* ----------------------------------------------------------------------------
* About:
* An activity verb in class form, and the related scaffolding.
*
* This file also now consolidates the ActivityContext, ActivityImporter,
* ActivityMover, ActivitySink, and ActivitySource classes, formerly at
* /lib/<class>.php
*
* o Activity abstracts the class for an activity verb.
* o ActivityContext contains information of the context of the activity verb.
* o ActivityImporter abstracts a means that is importing activity verbs
* into the system as part of a user's timeline.
* o ActivityMover abstracts the means to transport activity verbs.
* o ActivitySink abstracts a class to receive activity verbs.
* o ActivitySource abstracts a class to represent the source of a received
* activity verb.
*
* ActivityObject is a noun in the activity universe basically, from
* the original file:
* A noun-ish thing in the activity universe
*
* The activity streams spec talks about activity objects, while also
* having a tag activity:object, which is in fact an activity object.
* Aaaaaah!
*
* This is just a thing in the activity universe. Can be the subject,
* object, or indirect object (target!) of an activity verb. Rotten
* name, and I'm propagating it. *sigh*
* It's large enough that I've left it seperate in activityobject.php
*
* PHP version:
* Tested with PHP 5.6
* ----------------------------------------------------------------------------
* File Authors:
* o Zach Copley
* o Brion Vibber <brion@pobox.com>
* o James Walker <walkah@walkah.net>
* o Evan Prodromou
* o Siebrand Mazeland <s.mazeland@xs4all.nl>
* o Mikael Nordfeldth <mmn@hethane.se>
* o Chimo <chimo@chromic.org>
* o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
*
* Web:
* o postActiv <http://www.postactiv.com>
* o GNU social <https://www.gnu.org/s/social/>
* ============================================================================
*/
// This file is formatted so that it provides useful documentation output in
// NaturalDocs. Please be considerate of this before changing formatting.
if (!defined('POSTACTIV')) { exit(1); }
class ActivityMover extends QueueHandler
{
// -------------------------------------------------------------------------
// Function: transport
function transport() {
return 'actmove';
}
// ------------------------------------------------------------------------
// Function: handle
//
// Parameters:
// o data
function handle($data) {
list ($act, $sink, $userURI, $remoteURI) = $data;
$user = User::getKV('uri', $userURI);
try {
$remote = Profile::fromUri($remoteURI);
} catch (UnknownUriException $e) {
// Don't retry. It's hard to tell whether it's because of
// lookup failures or because the URI is permanently gone.
// If we knew it was temporary, we'd return false here.
return true;
}
try {
$this->moveActivity($act, $sink, $user, $remote);
} catch (ClientException $cex) {
$this->log(LOG_WARNING,
$cex->getMessage());
// "don't retry me"
return true;
} catch (ServerException $sex) {
$this->log(LOG_WARNING,
$sex->getMessage());
// "retry me" (because we think the server might handle it next time)
return false;
} catch (Exception $ex) {
$this->log(LOG_WARNING,
$ex->getMessage());
// "don't retry me"
return true;
}
}
// -------------------------------------------------------------------------
// Function: moveActivity
//
// Parameters:
// o act
// o sink
// o user
// o remote
function moveActivity($act, $sink, $user, $remote) {
if (empty($user)) {
// TRANS: Exception thrown if a non-existing user is provided. %s is a user ID.
throw new Exception(sprintf(_('No such user "%s".'),$act->actor->id));
}
switch ($act->verb) {
/* case ActivityVerb::FAVORITE:
$this->log(LOG_INFO,
"Moving favorite of {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
// push it, then delete local
$sink->postActivity($act);
$notice = Notice::getKV('uri', $act->objects[0]->id);
if (!empty($notice)) {
$fave = Fave::pkeyGet(array('user_id' => $user->id,
'notice_id' => $notice->id));
$fave->delete();
}
break;*/
case ActivityVerb::POST:
$this->log(LOG_INFO,
"Moving notice {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
// XXX: send a reshare, not a post
$sink->postActivity($act);
$notice = Notice::getKV('uri', $act->objects[0]->id);
if (!empty($notice)) {
$notice->deleteAs($user->getProfile(), false);
}
break;
case ActivityVerb::JOIN:
$this->log(LOG_INFO,
"Moving group join of {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
$sink->postActivity($act);
$group = User_group::getKV('uri', $act->objects[0]->id);
if (!empty($group)) {
$user->leaveGroup($group);
}
break;
case ActivityVerb::FOLLOW:
if ($act->actor->id === $user->getUri()) {
$this->log(LOG_INFO,
"Moving subscription to {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
$sink->postActivity($act);
try {
$other = Profile::fromUri($act->objects[0]->id);
Subscription::cancel($user->getProfile(), $other);
} catch (UnknownUriException $e) {
// Can't cancel subscription if we don't know who to alert
}
} else {
$otherUser = User::getKV('uri', $act->actor->id);
if (!empty($otherUser)) {
$this->log(LOG_INFO,
"Changing sub to {$act->objects[0]->id}".
"by {$act->actor->id} to {$remote->nickname}.");
$otherProfile = $otherUser->getProfile();
Subscription::ensureStart($otherProfile, $remote);
Subscription::cancel($otherProfile, $user->getProfile());
} else {
$this->log(LOG_NOTICE,
"Not changing sub to {$act->objects[0]->id}".
"by remote {$act->actor->id} ".
"to {$remote->nickname}.");
}
}
break;
}
}
// -------------------------------------------------------------------------
// Function: log
// Log some data
//
// Add a header for our class so we know who did it.
//
// Parameters:
// o int $level - Log level, like LOG_ERR or LOG_INFO
// o string $message - Message to log
//
// Returns:
// o void
protected function log($level, $message) {
common_log($level, "ActivityMover: " . $message);
}
}
?>
\ No newline at end of file
<?php
/* ============================================================================
* postActiv - a fork of the GNU Social microblogging software
* Title: ActivityObject
* Class abstraction for the actual Activity object
*
* postActiv:
* the micro-blogging software
*
* Copyright:
* Copyright (C) 2016, Maiyannah Bishop
*
* Derived from code copyright various sources:
* GNU Social (C) 2013-2016, Free Software Foundation, Inc
* StatusNet (C) 2008-2012, StatusNet, Inc
* o GNU Social (C) 2013-2016, Free Software Foundation, Inc
* o StatusNet (C) 2008-2012, StatusNet, Inc
* ----------------------------------------------------------------------------
* License:
* 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
......@@ -18,26 +26,37 @@
*
* 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/>.
* ----------------------------------------------------------------------------
* PHP version 5
*
* <https://www.gnu.org/licenses/agpl.html>
* ----------------------------------------------------------------------------
* About:
* An activity
*
* @category Feed
* @package StatusNet
* @author Evan Prodromou
* @author Zach Copley
* @author Maiyannah Bishop <maiyannah.bishop@postactiv.com>
* @copyright 2010-2012 StatusNet, Inc.
* @copyright 2012-2016 Free Software Foundation, Inc
* @copyright 2016 Maiyannah Bishop
* @license https://www.gnu.org/licenses/agpl.html
* @link http://www.postactiv.com/
* PHP version:
* Tested with PHP 5.6
* ----------------------------------------------------------------------------
* File Authors:
* o Evan Prodromou
* o Brion Vibber <brion@pobox.com>
* o Zach Copley
* o Siebrand Mazeland <s.mazeland@xs4all.nl>
* o Sashi Gowda <connect2shashi@gmail.com>
* o Mikael Nordfeldth <mmn@hethane.se>
* o Joshua Judson Rosen <rozzin@geekspace.com>
* o Stephen Paul Weber <singpolyma@singpolyma.net>
* o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
*
* Web:
* o postActiv <http://www.postactiv.com>
* o GNU social <https://www.gnu.org/s/social/>
* ============================================================================
*/
// This file is formatted so that it provides useful documentation output in
// NaturalDocs. Please be considerate of this before changing formatting.
if (!defined('POSTACTIV')) { exit(1); }
require_once(INSTALLDIR.'/lib/activitystreamjsondocument.php');
/**
* A noun-ish thing in the activity universe
......
<?php
/* ============================================================================
* Title: ActivitySink
* A collection of Activities
*
* postActiv:
* the micro-blogging software
*
* Copyright:
* Copyright (C) 2016, Maiyannah Bishop
*
* Derived from code copyright various sources:
* o GNU Social (C) 2013-2016, Free Software Foundation, Inc
* o StatusNet (C) 2008-2012, StatusNet, Inc
* ----------------------------------------------------------------------------
* License:
* 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/>.
*
* <https://www.gnu.org/licenses/agpl.html>
* ----------------------------------------------------------------------------
* About:
* An activity verb in class form, and the related scaffolding.
*
* This file also now consolidates the ActivityContext, ActivityImporter,
* ActivityMover, ActivitySink, and ActivitySource classes, formerly at
* /lib/<class>.php
*
* o Activity abstracts the class for an activity verb.
* o ActivityContext contains information of the context of the activity verb.
* o ActivityImporter abstracts a means that is importing activity verbs
* into the system as part of a user's timeline.
* o ActivityMover abstracts the means to transport activity verbs.
* o ActivitySink abstracts a class to receive activity verbs.
* o ActivitySource abstracts a class to represent the source of a received
* activity verb.
*
* ActivityObject is a noun in the activity universe basically, from
* the original file:
* A noun-ish thing in the activity universe
*
* The activity streams spec talks about activity objects, while also
* having a tag activity:object, which is in fact an activity object.
* Aaaaaah!
*
* This is just a thing in the activity universe. Can be the subject,
* object, or indirect object (target!) of an activity verb. Rotten
* name, and I'm propagating it. *sigh*
* It's large enough that I've left it seperate in activityobject.php
*
* PHP version:
* Tested with PHP 5.6
* ----------------------------------------------------------------------------
* File Authors:
* o Zach Copley
* o Brion Vibber <brion@pobox.com>
* o James Walker <walkah@walkah.net>
* o Evan Prodromou
* o Siebrand Mazeland <s.mazeland@xs4all.nl>
* o Mikael Nordfeldth <mmn@hethane.se>
* o Chimo <chimo@chromic.org>
* o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
*
* Web:
* o postActiv <http://www.postactiv.com>
* o GNU social <https://www.gnu.org/s/social/>
* ============================================================================
*/
// This file is formatted so that it provides useful documentation output in
// NaturalDocs. Please be considerate of this before changing formatting.
if (!defined('POSTACTIV')) { exit(1); }
// ----------------------------------------------------------------------------
// Class: ActivitySink
// A collection of activities. In practice this allows us to use external
// ActivityStreams services.
//
// Variables:
// o svcDoxUrl
// o username
// o password
// o collections
class ActivitySink
{
protected $svcDocUrl = null;
protected $username = null;
protected $password = null;
protected $collections = array();
// -------------------------------------------------------------------------
// Function: __construct
// Constructor for the class object
//
// Parameters:
// o svcDocUrl
// o username
// o password
function __construct($svcDocUrl, $username, $password) {
$this->svcDocUrl = $svcDocUrl;
$this->username = $username;
$this->password = $password;
$this->_parseSvcDoc();
}
// -------------------------------------------------------------------------
// Function: _parseSvcDoc
private function _parseSvcDoc()
{
$client = new HTTPClient();
$response = $client->get($this->svcDocUrl);
if ($response->getStatus() != 200) {
throw new ServerException("Can't get {$this->svcDocUrl}; response status " . $response->getStatus());
}
$xml = $response->getBody();
$dom = new DOMDocument();
// We don't want to bother with white spaces
$dom->preserveWhiteSpace = false;
// Don't spew XML warnings to output
$old = error_reporting();
error_reporting($old & ~E_WARNING);
$ok = $dom->loadXML($xml);
error_reporting($old);
$path = new DOMXPath($dom);
$path->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
$path->registerNamespace('app', 'http://www.w3.org/2007/app');
$path->registerNamespace('activity', 'http://activitystrea.ms/spec/1.0/');
$collections = $path->query('//app:collection');
for ($i = 0; $i < $collections->length; $i++) {
$collection = $collections->item($i);
$url = $collection->getAttribute('href');
$takesEntries = false;
$accepts = $path->query('app:accept', $collection);
for ($j = 0; $j < $accepts->length; $j++) {
$accept = $accepts->item($j);
$acceptValue = $accept->nodeValue;
if (preg_match('#application/atom\+xml(;\s*type=entry)?#', $acceptValue)) {
$takesEntries = true;
break;
}
}
if (!$takesEntries) {
continue;
}
$verbs = $path->query('activity:verb', $collection);
if ($verbs->length == 0) {
$this->_addCollection(ActivityVerb::POST, $url);
} else {
for ($k = 0; $k < $verbs->length; $k++) {
$verb = $verbs->item($k);
$this->_addCollection($verb->nodeValue, $url);
}
}
}
}
// -------------------------------------------------------------------------
// Function: _addCollection
//
// Parameters:
// o verb
// o url
//
// Returns:
// o void
private function _addCollection($verb, $url) {
if (array_key_exists($verb, $this->collections)) {
$this->collections[$verb][] = $url;
} else {
$this->collections[$verb] = array($url);
}
return;
}
// -------------------------------------------------------------------------
// Function: postActivity
// Put an activity in the collection
function postActivity($activity)
{
if (!array_key_exists($activity->verb, $this->collections)) {
throw new Exception("No collection for verb {$activity->verb}");
} else {
if (count($this->collections[$activity->verb]) > 1) {
common_log(LOG_NOTICE, "More than one collection for verb {$activity->verb}");
}
$this->postToCollection($this->collections[$activity->verb][0], $activity);
}
}
// -------------------------------------------------------------------------
// Function: postToCollection
// Push an activity to a remote service
//
// Parameters:
// o url
// o activity
//
// Error states:
// o A variety of errors will be raised due to HTTP error codes if received.
function postToCollection($url, $activity) {
$client = new HTTPClient($url);
$client->setMethod('POST');
$client->setAuth($this->username, $this->password);
$client->setHeader('Content-Type', 'application/atom+xml;type=entry');
$client->setBody($activity->asString(true, true, true));
$response = $client->send();
$status = $response->getStatus();
$reason = $response->getReasonPhrase();
if ($status >= 200 && $status < 300) {
return true;
} else if ($status >= 400 && $status < 500) {
// TRANS: Client exception thrown when post to collection fails with a 400 status.
// TRANS: %1$s is a URL, %2$s is the status, %s$s is the fail reason.
throw new ClientException(sprintf(_m('URLSTATUSREASON','%1$s %2$s %3$s'), $url, $status, $reason));
} else if ($status >= 500 && $status < 600) {
// TRANS: Server exception thrown when post to collection fails with a 500 status.
// TRANS: %1$s is a URL, %2$s is the status, %s$s is the fail reason.
throw new ServerException(sprintf(_m('URLSTATUSREASON','%1$s %2$s %3$s'), $url, $status, $reason));
} else {
// That's unexpected.
// TRANS: Exception thrown when post to collection fails with a status that is not handled.
// TRANS: %1$s is a URL, %2$s is the status, %s$s is the fail reason.
throw new Exception(sprintf(_m('URLSTATUSREASON','%1$s %2$s %3$s'), $url, $status, $reason));
}
}
}
// END OF FILE
// ============================================================================
?>
\ No newline at end of file
<?php
/* ============================================================================
* Title: ActivitySource
* Class abstraction for Activity verb source
*
* postActiv:
* the micro-blogging software
*
* Copyright:
* Copyright (C) 2016, Maiyannah Bishop
*
* Derived from code copyright various sources:
* o GNU Social (C) 2013-2016, Free Software Foundation, Inc
* o StatusNet (C) 2008-2012, StatusNet, Inc
* ----------------------------------------------------------------------------
* License:
* 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/>.
*
* <https://www.gnu.org/licenses/agpl.html>
* ----------------------------------------------------------------------------
* About:
* An activity verb in class form, and the related scaffolding.
*
* This file also now consolidates the ActivityContext, ActivityImporter,
* ActivityMover, ActivitySink, and ActivitySource classes, formerly at
* /lib/<class>.php
*
* o Activity abstracts the class for an activity verb.
* o ActivityContext contains information of the context of the activity verb.
* o ActivityImporter abstracts a means that is importing activity verbs
* into the system as part of a user's timeline.
* o ActivityMover abstracts the means to transport activity verbs.
* o ActivitySink abstracts a class to receive activity verbs.
* o ActivitySource abstracts a class to represent the source of a received
* activity verb.
*
* ActivityObject is a noun in the activity universe basically, from
* the original file:
* A noun-ish thing in the activity universe
*
* The activity streams spec talks about activity objects, while also
* having a tag activity:object, which is in fact an activity object.
* Aaaaaah!