Fix json_decode
This commit is contained in:
parent
e3086351e0
commit
0965ae459f
@ -96,11 +96,11 @@ class ActivityPubPlugin extends Plugin
|
||||
{
|
||||
/* Offline Grabbing */
|
||||
try {
|
||||
// Look for a know remote notice
|
||||
// Look for a known remote notice
|
||||
return Notice::getByUri($url);
|
||||
} catch (Exception $e) {
|
||||
// Look for a local notice (unfortunately GNU Social doesn't
|
||||
// provide this functionality)
|
||||
// provide this functionality natively)
|
||||
try {
|
||||
$candidate = Notice::getByID(intval(substr($url, strlen(common_local_url('shownotice', ['notice' => ''])))));
|
||||
if ($candidate->getUrl() == $url) { // Sanity check
|
||||
@ -119,7 +119,7 @@ class ActivityPubPlugin extends Plugin
|
||||
$headers[] = 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
|
||||
$headers[] = 'User-Agent: GNUSocialBot v0.1 - https://gnu.io/social';
|
||||
$response = $client->get($url, $headers);
|
||||
$res = json_decode($response->getBody());
|
||||
$res = json_decode($response->getBody(), true);
|
||||
$settings = [];
|
||||
try {
|
||||
Activitypub_notice::validate_remote_notice($res);
|
||||
|
@ -178,7 +178,7 @@ class Activitypub_notice extends Managed_DataObject
|
||||
|
||||
// Reject notice if it is too long (without the HTML)
|
||||
if (Notice::contentTooLong($content)) {
|
||||
throw new Exception('That\'s too long. Maximum notice size is %d character.');
|
||||
//throw new Exception('That\'s too long. Maximum notice size is %d character.');
|
||||
}
|
||||
|
||||
$options = ['source' => 'ActivityPub', 'uri' => $id, 'url' => $url];
|
||||
@ -201,38 +201,38 @@ class Activitypub_notice extends Managed_DataObject
|
||||
* Validates a remote notice.
|
||||
*
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @param StdClass $data
|
||||
* @param Array $data
|
||||
* @return boolean true in case of success
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function validate_remote_notice($data)
|
||||
{
|
||||
if (!isset($data->attributedTo)) {
|
||||
if (!isset($data['attributedTo'])) {
|
||||
common_debug('ActivityPub Notice Validator: Rejected because attributedTo was not specified.');
|
||||
throw new Exception('No attributedTo specified.');
|
||||
}
|
||||
if (!isset($data->id)) {
|
||||
if (!isset($data['id'])) {
|
||||
common_debug('ActivityPub Notice Validator: Rejected because Object ID was not specified.');
|
||||
throw new Exception('Object ID not specified.');
|
||||
} elseif (!filter_var($data->id, FILTER_VALIDATE_URL)) {
|
||||
} elseif (!filter_var($data['id'], FILTER_VALIDATE_URL)) {
|
||||
common_debug('ActivityPub Notice Validator: Rejected because Object ID is invalid.');
|
||||
throw new Exception('Invalid Object ID.');
|
||||
}
|
||||
if (!isset($data->type) || $data->type !== 'Note') {
|
||||
if (!isset($data['type']) || $data['type'] !== 'Note') {
|
||||
common_debug('ActivityPub Notice Validator: Rejected because of Type.');
|
||||
throw new Exception('Invalid Object type.');
|
||||
}
|
||||
if (!isset($data->content)) {
|
||||
if (!isset($data['content'])) {
|
||||
common_debug('ActivityPub Notice Validator: Rejected because Content was not specified.');
|
||||
throw new Exception('Object content was not specified.');
|
||||
}
|
||||
if (!isset($data->url)) {
|
||||
if (!isset($data['url'])) {
|
||||
throw new Exception('Object URL was not specified.');
|
||||
} elseif (!filter_var($data->url, FILTER_VALIDATE_URL)) {
|
||||
} elseif (!filter_var($data['url'], FILTER_VALIDATE_URL)) {
|
||||
common_debug('ActivityPub Notice Validator: Rejected because Object URL is invalid.');
|
||||
throw new Exception('Invalid Object URL.');
|
||||
}
|
||||
if (!isset($data->cc)) {
|
||||
if (!isset($data['cc'])) {
|
||||
common_debug('ActivityPub Notice Validator: Rejected because Object CC was not specified.');
|
||||
throw new Exception('Object CC was not specified.');
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ class Activitypub_explorer
|
||||
$headers[] = 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
|
||||
$headers[] = 'User-Agent: GNUSocialBot v0.1 - https://gnu.io/social';
|
||||
$response = $client->get($url, $headers);
|
||||
$res = json_decode($response->getBody(), JSON_UNESCAPED_SLASHES);
|
||||
$res = json_decode($response->getBody(), true);
|
||||
if (self::validate_remote_response($res)) {
|
||||
$this->temp_res = $res;
|
||||
return true;
|
||||
@ -210,7 +210,7 @@ class Activitypub_explorer
|
||||
$headers[] = 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
|
||||
$headers[] = 'User-Agent: GNUSocialBot v0.1 - https://gnu.io/social';
|
||||
$response = $client->get($url, $headers);
|
||||
$res = json_decode($response->getBody(), JSON_UNESCAPED_SLASHES);
|
||||
$res = json_decode($response->getBody(), true);
|
||||
} else {
|
||||
$res = $this->temp_res;
|
||||
unset($this->temp_res);
|
||||
@ -219,7 +219,7 @@ class Activitypub_explorer
|
||||
common_debug('ActivityPub Explorer: Found a collection of actors for '.$url);
|
||||
foreach ($res["orderedItems"] as $profile) {
|
||||
if ($this->_lookup($profile) == false) {
|
||||
common_debug('ActivityPub Explorer: Found an inavlid actor for '.$profile);
|
||||
common_debug('ActivityPub Explorer: Found an invalid actor for '.$profile);
|
||||
// TODO: Invalid actor found, fallback to OStatus
|
||||
}
|
||||
}
|
||||
@ -393,7 +393,7 @@ class Activitypub_explorer
|
||||
if (!$response->isOk()) {
|
||||
throw new Exception('Invalid Actor URL.');
|
||||
}
|
||||
$res = json_decode($response->getBody(), JSON_UNESCAPED_SLASHES);
|
||||
$res = json_decode($response->getBody(), true);
|
||||
if (self::validate_remote_response($res)) {
|
||||
return [
|
||||
'inbox' => $res['inbox'],
|
||||
|
Reference in New Issue
Block a user