streams/Zotlabs/Module/Share.php

135 lines
2.8 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
namespace Zotlabs\Module;
2018-09-03 05:58:30 +00:00
use App;
use Zotlabs\Daemon\Master;
use Zotlabs\Lib\Libsync;
2016-04-19 03:38:38 +00:00
require_once('include/security.php');
require_once('include/bbcode.php');
class Share extends \Zotlabs\Web\Controller {
function init() {
$post_id = ((argc() > 1) ? intval(argv(1)) : 0);
if(! $post_id)
killme();
2018-09-03 03:16:04 +00:00
if(! local_channel()) {
killme();
}
2018-09-03 05:58:30 +00:00
$observer = App::get_observer();
2018-09-03 03:16:04 +00:00
2018-09-03 05:58:30 +00:00
$channel = App::get_channel();
2016-04-19 03:38:38 +00:00
$r = q("SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d LIMIT 1",
intval($post_id)
);
if(! $r)
killme();
2018-09-03 03:16:04 +00:00
2016-04-19 03:38:38 +00:00
if(($r[0]['item_private']) && ($r[0]['xchan_network'] !== 'rss'))
killme();
$sql_extra = item_permissions_sql($r[0]['uid']);
$r = q("select * from item where id = %d $sql_extra",
intval($post_id)
);
if(! $r)
killme();
/** @FIXME we only share bbcode */
if($r[0]['mimetype'] !== 'text/bbcode')
killme();
xchan_query($r);
2018-09-03 03:16:04 +00:00
$arr = [];
$item = $r[0];
$owner_uid = $r[0]['uid'];
$owner_aid = $r[0]['aid'];
$can_comment = false;
if((array_key_exists('owner',$item)) && intval($item['owner']['abook_self']))
$can_comment = perm_is_allowed($item['uid'],$observer['xchan_hash'],'post_comments');
else
$can_comment = can_comment_on_post($observer['xchan_hash'],$item);
if(! $can_comment) {
notice( t('Permission denied') . EOL);
killme();
2016-04-19 03:38:38 +00:00
}
2018-09-03 03:16:04 +00:00
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($item['owner_xchan'])
);
if($r)
$thread_owner = $r[0];
else
killme();
2016-04-19 03:38:38 +00:00
2018-09-03 03:16:04 +00:00
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($item['author_xchan'])
);
if($r)
$item_author = $r[0];
else
2016-04-19 03:38:38 +00:00
killme();
2018-09-03 03:16:04 +00:00
$arr['aid'] = $owner_aid;
$arr['uid'] = $owner_uid;
$arr['item_origin'] = 1;
2018-10-17 22:51:23 +00:00
$arr['item_wall'] = $item['item_wall'];
2018-09-03 03:16:04 +00:00
$arr['mid'] = item_message_id();
2018-10-17 23:08:43 +00:00
$arr['mid'] = str_replace('/item/','/activity/',$arr['mid']);
2018-10-17 22:51:23 +00:00
$arr['parent_mid'] = $item['mid'];
2018-09-03 03:16:04 +00:00
2018-10-17 23:08:43 +00:00
$mention = '@[zrl=' . $item['author']['xchan_url'] . ']' . $item['author']['xchan_name'] . '[/zrl]';
$arr['body'] = sprintf( t('&#x1f501; Repeated %1$s\'s %2$s'), $mention, $item['obj_type']);
2018-10-17 22:51:23 +00:00
$arr['author_xchan'] = $channel['channel_hash'];
$arr['owner_xchan'] = $item['author_xchan'];
2018-09-03 03:16:04 +00:00
$arr['obj'] = $item['obj'];
$arr['obj_type'] = $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);
2018-09-03 05:58:30 +00:00
info( t('Post repeated') . EOL);
2018-09-03 03:16:04 +00:00
2018-09-03 05:58:30 +00:00
$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) ] ]);
}
2018-09-03 03:16:04 +00:00
2018-09-03 05:58:30 +00:00
Master::Summon([ 'Notifier','like',$post_id ]);
2016-04-19 03:38:38 +00:00
2018-09-03 03:16:04 +00:00
killme();
2016-04-19 03:38:38 +00:00
}
}