2018-02-14 04:07:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zotlabs\Lib;
|
|
|
|
|
2020-12-14 23:03:28 +00:00
|
|
|
use App;
|
|
|
|
use Zotlabs\Daemon\Run;
|
|
|
|
use Zotlabs\Lib\Libsync;
|
2018-02-14 04:07:57 +00:00
|
|
|
|
|
|
|
class Share {
|
|
|
|
|
|
|
|
private $item = null;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($post_id) {
|
|
|
|
|
2020-12-14 23:03:28 +00:00
|
|
|
if (! $post_id) {
|
2018-02-14 04:07:57 +00:00
|
|
|
return;
|
2020-12-14 23:03:28 +00:00
|
|
|
}
|
2018-02-14 04:07:57 +00:00
|
|
|
|
2020-12-14 23:03:28 +00:00
|
|
|
if (is_array($post_id)) {
|
2019-04-19 21:34:47 +00:00
|
|
|
$this->item = $post_id;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-14 23:03:28 +00:00
|
|
|
if (! (local_channel() || remote_channel())) {
|
2018-02-14 04:07:57 +00:00
|
|
|
return;
|
2020-12-14 23:03:28 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 04:07:57 +00:00
|
|
|
$r = q("SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d LIMIT 1",
|
|
|
|
intval($post_id)
|
|
|
|
);
|
2020-12-14 23:03:28 +00:00
|
|
|
if (! $r) {
|
2018-02-14 04:07:57 +00:00
|
|
|
return;
|
2020-12-14 23:03:28 +00:00
|
|
|
}
|
2018-02-14 04:07:57 +00:00
|
|
|
|
2020-12-14 23:03:28 +00:00
|
|
|
if (($r[0]['item_private']) && ($r[0]['xchan_network'] !== 'rss')) {
|
2018-02-14 04:07:57 +00:00
|
|
|
return;
|
2020-12-14 23:03:28 +00:00
|
|
|
}
|
2018-02-14 04:07:57 +00:00
|
|
|
|
|
|
|
$sql_extra = item_permissions_sql($r[0]['uid']);
|
|
|
|
|
|
|
|
$r = q("select * from item where id = %d $sql_extra",
|
|
|
|
intval($post_id)
|
|
|
|
);
|
2020-12-14 23:03:28 +00:00
|
|
|
if (! $r) {
|
2018-02-14 04:07:57 +00:00
|
|
|
return;
|
2020-12-14 23:03:28 +00:00
|
|
|
}
|
2018-02-14 04:07:57 +00:00
|
|
|
|
2021-03-08 05:32:28 +00:00
|
|
|
if (! in_array($r[0]['mimetype'], [ 'text/bbcode', 'text/x-multicode' ])) {
|
2018-02-14 04:07:57 +00:00
|
|
|
return;
|
2020-12-14 23:03:28 +00:00
|
|
|
}
|
2018-02-14 04:07:57 +00:00
|
|
|
|
|
|
|
/** @FIXME eventually we want to post remotely via rpost on your home site */
|
|
|
|
// When that works remove this next bit:
|
|
|
|
|
2020-12-14 23:03:28 +00:00
|
|
|
if (! local_channel()) {
|
2018-02-14 04:07:57 +00:00
|
|
|
return;
|
2020-12-14 23:03:28 +00:00
|
|
|
}
|
2018-02-14 04:07:57 +00:00
|
|
|
|
|
|
|
xchan_query($r);
|
|
|
|
|
2020-12-14 23:03:28 +00:00
|
|
|
$this->item = array_shift($r);
|
|
|
|
|
|
|
|
$arr = [];
|
|
|
|
|
|
|
|
$owner_uid = $this->item['uid'];
|
|
|
|
$owner_aid = $this->item['aid'];
|
|
|
|
|
|
|
|
$channel = channelx_by_n($this->item['uid']);
|
|
|
|
$observer = App::get_observer();
|
|
|
|
|
|
|
|
$can_comment = false;
|
|
|
|
if ((array_key_exists('owner',$this->item)) && intval($this->item['owner']['abook_self'])) {
|
|
|
|
$can_comment = perm_is_allowed($this->item['uid'],$observer['xchan_hash'],'post_comments');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$can_comment = can_comment_on_post($observer['xchan_hash'],$this->item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $can_comment) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
|
|
|
|
dbesc($this->item['owner_xchan'])
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($r) {
|
|
|
|
$thread_owner = array_shift($r);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
|
|
|
|
dbesc($this->item['author_xchan'])
|
|
|
|
);
|
|
|
|
if ($r) {
|
|
|
|
$item_author = array_shift($r);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item_author['network'] === 'activitypub') {
|
|
|
|
|
|
|
|
// for Mastodon compatibility, send back an ActivityPub Announce activity.
|
|
|
|
// We don't need or want these on our own network as there is no mechanism for providing
|
|
|
|
// a fair-use defense to copyright claims and frivolous lawsuits.
|
|
|
|
|
|
|
|
$arr['aid'] = $owner_aid;
|
|
|
|
$arr['uid'] = $owner_uid;
|
|
|
|
|
|
|
|
$arr['item_origin'] = 1;
|
|
|
|
$arr['item_wall'] = $this->item['item_wall'];
|
|
|
|
$arr['uuid'] = new_uuid();
|
|
|
|
$arr['mid'] = z_root() . '/item/' . $arr['uuid'];
|
|
|
|
$arr['mid'] = str_replace('/item/','/activity/',$arr['mid']);
|
|
|
|
$arr['parent_mid'] = $this->item['mid'];
|
|
|
|
|
|
|
|
$mention = '@[zrl=' . $this->item['author']['xchan_url'] . ']' . $this->item['author']['xchan_name'] . '[/zrl]';
|
|
|
|
$arr['body'] = sprintf( t('🔁 Repeated %1$s\'s %2$s'), $mention, $this->item['obj_type']);
|
|
|
|
|
|
|
|
$arr['author_xchan'] = $observer['xchan_hash'];
|
|
|
|
$arr['owner_xchan'] = $this->item['author_xchan'];
|
|
|
|
$arr['obj'] = $this->item['obj'];
|
|
|
|
$arr['obj_type'] = $this->item['obj_type'];
|
|
|
|
$arr['verb'] = 'Announce';
|
|
|
|
|
|
|
|
$post = item_store($arr);
|
|
|
|
|
|
|
|
$post_id = $post['item_id'];
|
|
|
|
|
|
|
|
$arr['id'] = $post_id;
|
|
|
|
|
|
|
|
call_hooks('post_local_end', $arr);
|
|
|
|
|
|
|
|
$r = q("select * from item where id = %d",
|
|
|
|
intval($post_id)
|
|
|
|
);
|
|
|
|
if ($r) {
|
|
|
|
xchan_query($r);
|
|
|
|
$sync_item = fetch_post_tags($r);
|
|
|
|
Libsync::build_sync_packet($channel['channel_id'], [ 'item' => [ encode_item($sync_item[0],true) ] ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Run::Summon([ 'Notifier','like',$post_id ]);
|
|
|
|
}
|
|
|
|
|
2018-02-14 04:07:57 +00:00
|
|
|
return;
|
2020-12-14 23:03:28 +00:00
|
|
|
|
2018-02-14 04:07:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function obj() {
|
|
|
|
$obj = [];
|
|
|
|
|
|
|
|
if(! $this->item)
|
|
|
|
return $obj;
|
|
|
|
|
|
|
|
$obj['type'] = $this->item['obj_type'];
|
|
|
|
$obj['id'] = $this->item['mid'];
|
2019-01-30 05:26:52 +00:00
|
|
|
$obj['content'] = bbcode($this->item['body']);
|
|
|
|
$obj['source'] = [
|
|
|
|
'mediaType' => $this->item['mimetype'],
|
2019-05-14 03:28:56 +00:00
|
|
|
'content' => $this->item['body']
|
2018-02-14 04:07:57 +00:00
|
|
|
];
|
|
|
|
|
2019-01-30 05:26:52 +00:00
|
|
|
$obj['name'] = $this->item['title'];
|
|
|
|
$obj['published'] = $this->item['created'];
|
|
|
|
$obj['updated'] = $this->item['edited'];
|
|
|
|
$obj['attributedTo'] = ((strpos($this->item['author']['xchan_hash'],'http') === 0)
|
|
|
|
? $this->item['author']['xchan_hash']
|
|
|
|
: $this->item['author']['xchan_url']);
|
2018-02-14 04:07:57 +00:00
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bbcode() {
|
2018-06-10 15:04:34 +00:00
|
|
|
$bb = EMPTY_STR;
|
2018-02-14 04:07:57 +00:00
|
|
|
|
2019-04-19 21:34:47 +00:00
|
|
|
if (! $this->item)
|
2018-02-14 04:07:57 +00:00
|
|
|
return $bb;
|
|
|
|
|
2019-04-19 21:34:47 +00:00
|
|
|
if (! $this->item['author']) {
|
|
|
|
$author = q("select * from xchan where xchan_hash = '%s' limit 1",
|
|
|
|
dbesc($this->item['author_xchan'])
|
|
|
|
);
|
|
|
|
if ($author) {
|
|
|
|
$this->item['author'] = array_shift($author);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 01:50:23 +00:00
|
|
|
$special_object = (in_array($this->item['obj_type'], [ ACTIVITY_OBJ_PHOTO, 'Event', 'Question' ]) ? true : false);
|
|
|
|
if($special_object) {
|
2018-02-14 04:07:57 +00:00
|
|
|
$object = json_decode($this->item['obj'],true);
|
2021-09-29 01:50:23 +00:00
|
|
|
$special = (($object['source']) ? $object['source']['content'] : $object['body']);
|
2018-02-14 04:07:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($this->item['body'], "[/share]") !== false) {
|
|
|
|
$pos = strpos($this->item['body'], "[share");
|
|
|
|
$bb = substr($this->item['body'], $pos);
|
|
|
|
} else {
|
2019-05-14 03:28:56 +00:00
|
|
|
$bb = "[share author='" . urlencode($this->item['author']['xchan_name']).
|
|
|
|
"' profile='" . $this->item['author']['xchan_url'] .
|
|
|
|
"' portable_id='" . $this->item['author']['xchan_hash'] .
|
|
|
|
"' avatar='" . $this->item['author']['xchan_photo_s'] .
|
|
|
|
"' link='" . $this->item['plink'] .
|
2019-08-30 04:19:00 +00:00
|
|
|
"' auth='" . (($this->item['author']['network'] === 'zot6') ? 'true' : 'false') .
|
2019-05-14 03:28:56 +00:00
|
|
|
"' posted='" . $this->item['created'] .
|
|
|
|
"' message_id='" . $this->item['mid'] .
|
2018-03-16 00:51:24 +00:00
|
|
|
"']";
|
2021-07-13 20:34:07 +00:00
|
|
|
if ($this->item['title']) {
|
2018-02-14 04:07:57 +00:00
|
|
|
$bb .= '[b]'.$this->item['title'].'[/b]'."\r\n";
|
2021-07-13 20:34:07 +00:00
|
|
|
}
|
|
|
|
if ($this->item['summary']) {
|
|
|
|
$bb .= $this->item['summary'] . "\r\n";
|
|
|
|
}
|
|
|
|
|
2021-09-29 01:50:23 +00:00
|
|
|
$bb .= (($special_object) ? $special . "\r\n" . $this->item['body'] : $this->item['body']);
|
2018-02-14 04:07:57 +00:00
|
|
|
$bb .= "[/share]";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $bb;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-10 15:04:34 +00:00
|
|
|
}
|