From 64809dd2777ae0064addaff765450cf3f05c3bc4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Feb 2018 20:07:57 -0800 Subject: turn shares into activities - make certain to pull addons or JSON-LD will chuck a wobbly --- Zotlabs/Lib/Share.php | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 Zotlabs/Lib/Share.php (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Share.php b/Zotlabs/Lib/Share.php new file mode 100644 index 000000000..b5341e662 --- /dev/null +++ b/Zotlabs/Lib/Share.php @@ -0,0 +1,141 @@ +item = $r[0]; + return; + } + + public function obj() { + $obj = []; + + if(! $this->item) + return $obj; + + $obj['type'] = $this->item['obj_type']; + $obj['id'] = $this->item['mid']; + $obj['content'] = $this->item['body']; + $obj['content_type'] = $this->item['mimetype']; + $obj['title'] = $this->item['title']; + $obj['created'] = $this->item['created']; + $obj['edited'] = $this->item['edited']; + $obj['author'] = [ + 'name' => $this->item['author']['xchan_name'], + 'address' => $this->item['author']['xchan_addr'], + 'network' => $this->item['author']['xchan_network'], + 'link' => [ + [ + 'rel' => 'alternate', + 'type' => 'text/html', + 'href' => $this->item['author']['xchan_url'] + ], + [ + 'rel' => 'photo', + 'type' => $this->item['author']['xchan_photo_mimetype'], + 'href' => $this->item['author']['xchan_photo_m'] + ] + ] + ]; + + $obj['owner'] = [ + 'name' => $this->item['owner']['xchan_name'], + 'address' => $this->item['owner']['xchan_addr'], + 'network' => $this->item['owner']['xchan_network'], + 'link' => [ + [ + 'rel' => 'alternate', + 'type' => 'text/html', + 'href' => $this->item['owner']['xchan_url'] + ], + [ + 'rel' => 'photo', + 'type' => $this->item['owner']['xchan_photo_mimetype'], + 'href' => $this->item['owner']['xchan_photo_m'] + ] + ] + ]; + + $obj['link'] = [ + 'rel' => 'alternate', + 'type' => 'text/html', + 'href' => $this->item['plink'] + ]; + + return $obj; + } + + public function bbcode() { + $bb = NULL_STR; + + if(! $this->item) + return $bb; + + $is_photo = (($this->item['obj_type'] === ACTIVITY_OBJ_PHOTO) ? true : false); + if($is_photo) { + $object = json_decode($this->item['obj'],true); + $photo_bb = $object['body']; + } + + if (strpos($this->item['body'], "[/share]") !== false) { + $pos = strpos($this->item['body'], "[share"); + $bb = substr($this->item['body'], $pos); + } else { + $bb = "[share author='".urlencode($this->item['author']['xchan_name']). + "' profile='".$this->item['author']['xchan_url'] . + "' avatar='".$this->item['author']['xchan_photo_s']. + "' link='".$this->item['plink']. + "' posted='".$this->item['created']. + "' message_id='".$this->item['mid']."']"; + if($this->item['title']) + $bb .= '[b]'.$this->item['title'].'[/b]'."\r\n"; + $bb .= (($is_photo) ? $photo_bb . "\r\n" . $this->item['body'] : $this->item['body']); + $bb .= "[/share]"; + } + + return $bb; + + } + +} \ No newline at end of file -- cgit v1.2.3