aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2018-02-13 20:09:55 -0800
committerzotlabs <mike@macgirvin.com>2018-02-13 20:09:55 -0800
commit24da5d82db8316a54ccb41616e0e2acb5d73fc84 (patch)
treea6fb39d3c1d8d79401db5832b5c44bffeea5113a /Zotlabs
parent6ca3442ba381a3c5b98cd04f4f9e87e48c55b072 (diff)
parent64809dd2777ae0064addaff765450cf3f05c3bc4 (diff)
downloadvolse-hubzilla-24da5d82db8316a54ccb41616e0e2acb5d73fc84.tar.gz
volse-hubzilla-24da5d82db8316a54ccb41616e0e2acb5d73fc84.tar.bz2
volse-hubzilla-24da5d82db8316a54ccb41616e0e2acb5d73fc84.zip
Merge branch 'share'
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Lib/Share.php141
-rw-r--r--Zotlabs/Module/Item.php17
-rw-r--r--Zotlabs/Module/Share.php4
3 files changed, 161 insertions, 1 deletions
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 @@
+<?php
+
+namespace Zotlabs\Lib;
+
+
+class Share {
+
+ private $item = null;
+
+
+ public function __construct($post_id) {
+
+ if(! $post_id)
+ return;
+
+ if(! (local_channel() || remote_channel()))
+ return;
+
+ $r = q("SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d LIMIT 1",
+ intval($post_id)
+ );
+ if(! $r)
+ return;
+
+ if(($r[0]['item_private']) && ($r[0]['xchan_network'] !== 'rss'))
+ return;
+
+ $sql_extra = item_permissions_sql($r[0]['uid']);
+
+ $r = q("select * from item where id = %d $sql_extra",
+ intval($post_id)
+ );
+ if(! $r)
+ return;
+
+ if($r[0]['mimetype'] !== 'text/bbcode')
+ return;
+
+ /** @FIXME eventually we want to post remotely via rpost on your home site */
+ // When that works remove this next bit:
+
+ if(! local_channel())
+ return;
+
+ xchan_query($r);
+
+ $this->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
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index db2d64d70..3f857030b 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -39,6 +39,7 @@ class Item extends \Zotlabs\Web\Controller {
$uid = local_channel();
$channel = null;
$observer = null;
+ $datarray = [];
/**
@@ -619,6 +620,21 @@ class Item extends \Zotlabs\Web\Controller {
$i++;
}
}
+
+
+ if(preg_match_all('/(\[share=(.*?)\](.*?)\[\/share\])/',$body,$match)) {
+ // process share by id
+
+ $verb = ACTIVITY_SHARE;
+ $i = 0;
+ foreach($match[2] as $mtch) {
+ $reshare = new \Zotlabs\Lib\Share($mtch);
+ $datarray['obj'] = $reshare->obj();
+ $datarray['obj_type'] = $datarray['obj']['type'];
+ $body = str_replace($match[1][$i],$reshare->bbcode(),$body);
+ $i++;
+ }
+ }
}
@@ -720,7 +736,6 @@ class Item extends \Zotlabs\Web\Controller {
if(!$thr_parent)
$thr_parent = $mid;
- $datarray = array();
$item_thread_top = ((! $parent) ? 1 : 0);
diff --git a/Zotlabs/Module/Share.php b/Zotlabs/Module/Share.php
index 5c4811c59..7f4d8b1eb 100644
--- a/Zotlabs/Module/Share.php
+++ b/Zotlabs/Module/Share.php
@@ -14,6 +14,10 @@ class Share extends \Zotlabs\Web\Controller {
if(! $post_id)
killme();
+
+ echo '[share=' . $post_id . '][/share]';
+ killme();
+
if(! (local_channel() || remote_channel()))
killme();