aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-08-20 19:40:37 -0700
committerzotlabs <mike@macgirvin.com>2017-08-20 19:40:37 -0700
commitf15d96bebe754d9cb38b1e043a30521d9fbcd668 (patch)
tree683a644d3c3b77f775a4abe99320d2fe53e7d4be /Zotlabs
parent18c57eeaa03fedf9156369a10abe17bf61179adb (diff)
downloadvolse-hubzilla-f15d96bebe754d9cb38b1e043a30521d9fbcd668.tar.gz
volse-hubzilla-f15d96bebe754d9cb38b1e043a30521d9fbcd668.tar.bz2
volse-hubzilla-f15d96bebe754d9cb38b1e043a30521d9fbcd668.zip
add namespaces to activitystreams parser
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Lib/ActivityStreams.php65
1 files changed, 53 insertions, 12 deletions
diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php
index 2b610c7a4..3bbe3b190 100644
--- a/Zotlabs/Lib/ActivityStreams.php
+++ b/Zotlabs/Lib/ActivityStreams.php
@@ -5,12 +5,14 @@ namespace Zotlabs\Lib;
class ActivityStreams {
public $data;
- public $valid = false;
- public $id = '';
- public $type = '';
- public $actor = null;
- public $obj = null;
- public $tgt = null;
+ public $valid = false;
+ public $id = '';
+ public $type = '';
+ public $actor = null;
+ public $obj = null;
+ public $tgt = null;
+ public $origin = null;
+ public $owner = null;
function __construct($string) {
@@ -26,6 +28,7 @@ class ActivityStreams {
$this->obj = $this->get_compound_property('object');
$this->tgt = $this->get_compound_property('target');
$this->origin = $this->get_compound_property('origin');
+ $this->owner = $this->get_compound_property('owner','','http://purl.org/zot/protocol');
if(($this->type === 'Note') && (! $this->obj)) {
$this->obj = $this->data;
@@ -38,9 +41,47 @@ class ActivityStreams {
return $this->valid;
}
- function get_property_obj($property,$base = '') {
+ function get_namespace($base,$namespace) {
+
+ $key = null;
+
+ foreach( [ $this->data, $base ] as $b ) {
+ if(! $b)
+ continue;
+ if(array_key_exists('@context',$b)) {
+ if(is_array($b['@context'])) {
+ foreach($b['@context'] as $ns) {
+ if(is_array($ns)) {
+ foreach($ns as $k => $v) {
+ if($namespace === $v)
+ $key = $k;
+ }
+ }
+ else {
+ if($namespace === $ns) {
+ $key = '';
+ }
+ }
+ }
+ }
+ else {
+ if($namespace === $b['@context']) {
+ $key = '';
+ }
+ }
+ }
+ }
+ return $key;
+ }
+
+
+ function get_property_obj($property,$base = '',$namespace = 'https://www.w3.org/ns/activitystreams') {
+ $prefix = $this->get_namespace($base,$namespace);
+ if($prefix === null)
+ return null;
$base = (($base) ? $base : $this->data);
- return ((array_key_exists($property,$base)) ? $base[$property] : null);
+ $propname = (($prefix) ? $prefix . ':' : '') . $property;
+ return ((array_key_exists($propname,$base)) ? $base[$propname] : null);
}
function fetch_property($url) {
@@ -57,8 +98,8 @@ class ActivityStreams {
return null;
}
- function get_compound_property($property,$base = '') {
- $x = $this->get_property_obj($property,$base);
+ function get_compound_property($property,$base = '',$namespace = 'https://www.w3.org/ns/activitystreams') {
+ $x = $this->get_property_obj($property,$base,$namespace);
if($this->is_url($x)) {
$x = $this->fetch_property($x);
}
@@ -72,10 +113,10 @@ class ActivityStreams {
return false;
}
- function get_primary_type($base = '') {
+ function get_primary_type($base = '',$namespace = 'https://www.w3.org/ns/activitystreams') {
if(! $base)
$base = $this->data;
- $x = $this->get_property_obj('type',$base);
+ $x = $this->get_property_obj('type',$base,$namespace);
if(is_array($x)) {
foreach($x as $y) {
if(strpos($y,':') === false) {